userList = calloc(VALID_NICK_CHARS_FIRST_LEN+1, sizeof(*userList));
}
+void free_UserNode() {
+ //kamikaze free all users
+ //chanusers will be destroyed in free_ChanNode()
+ int i;
+ struct UserNode *user, *next;
+ for(i = 0; i < VALID_NICK_CHARS_FIRST_LEN+1; i++) {
+ for(user = userList[i]; user; user = next) {
+ next = user->next;
+ free(user);
+ }
+ }
+ free(userList);
+}
+
int is_valid_nick(const char *nick) {
unsigned int i;
//first char must be one of: a-zA-Z{|}~[\]^_`
strcpy(user->ident, &cmask[ii]);
ii = i+1;
} else if(cmask[i] == '\0') {
- if(user == NULL) return NULL;
+ if(user == NULL) {
+ //nick only
+ user = malloc(sizeof(*user));
+ if (!user)
+ {
+ perror("malloc() failed");
+ return NULL;
+ }
+ strcpy(user->nick, cmask);
+ user->created = time(0);
+ user->ident[0] = 0;
+ user->host[0] = 0;
+ user->realname[0] = 0;
+ user->flags = 0;
+ user->channel = NULL;
+ return user;
+ }
strcpy(user->host, &cmask[ii]);
}
}