equal
deleted
inserted
replaced
1 #include "irc_user.h" |
1 #include "irc_user.h" |
|
2 #include "log.h" |
2 |
3 |
3 #include <stdlib.h> |
4 #include <stdlib.h> |
4 #include <string.h> |
5 #include <string.h> |
|
6 #include <assert.h> |
|
7 |
|
8 // XXX: prototype of function from irc_net |
|
9 void irc_net_remove_user (struct irc_net *net, struct irc_user *user); |
5 |
10 |
6 err_t irc_user_create (struct irc_user **user_ptr, struct irc_net *net, const char *nickname) |
11 err_t irc_user_create (struct irc_user **user_ptr, struct irc_net *net, const char *nickname) |
7 { |
12 { |
8 struct irc_user *user; |
13 struct irc_user *user; |
|
14 |
|
15 (void) net; |
9 |
16 |
10 // allocate |
17 // allocate |
11 if ((user = calloc(1, sizeof(*user))) == NULL) |
18 if ((user = calloc(1, sizeof(*user))) == NULL) |
12 return ERR_CALLOC; |
19 return ERR_CALLOC; |
13 |
20 |
14 // copy nickname |
21 // init |
15 if ((user->nickname = strdup(nickname)) == NULL) |
22 if ((user->nickname = strdup(nickname)) == NULL) |
16 return ERR_STRDUP; |
23 return ERR_STRDUP; |
|
24 |
|
25 user->refcount = 0; |
17 |
26 |
18 // ok |
27 // ok |
19 *user_ptr = user; |
28 *user_ptr = user; |
20 |
29 |
21 return SUCCESS; |
30 return SUCCESS; |
22 } |
31 } |
23 |
32 |
24 void irc_user_destroy (struct irc_user *user) |
33 void irc_user_destroy (struct irc_user *user) |
25 { |
34 { |
|
35 if (user->refcount > 0) |
|
36 log_warn("refcount=%zu", user->refcount); |
|
37 |
26 free(user->nickname); |
38 free(user->nickname); |
27 free(user); |
39 free(user); |
28 } |
40 } |
29 |
41 |