comparison libpurple/protocols/msn/user.c @ 31176:0c090a41522c

Add ref/unref support to MsnUser.
author masca@cpw.pidgin.im
date Wed, 26 May 2010 23:25:39 +0000
parents 02dc01aa8c07
children 417899347f8a
comparison
equal deleted inserted replaced
31175:1ba9f3167de0 31176:0c090a41522c
44 user->userlist = userlist; 44 user->userlist = userlist;
45 45
46 msn_user_set_passport(user, passport); 46 msn_user_set_passport(user, passport);
47 msn_user_set_friendly_name(user, friendly_name); 47 msn_user_set_friendly_name(user, friendly_name);
48 48
49 return user; 49 return msn_user_ref(user);
50 } 50 }
51 51
52 /*destroy a user object*/ 52 /*destroy a user object*/
53 void 53 void
54 msn_user_destroy(MsnUser *user) 54 msn_user_destroy(MsnUser *user)
55 { 55 {
56 g_return_if_fail(user != NULL); 56 g_return_if_fail(user != NULL);
57
58 if (user->refcount > 1) {
59 msn_user_unref(user);
60 return;
61 }
57 62
58 while (user->endpoints != NULL) { 63 while (user->endpoints != NULL) {
59 free_user_endpoint(user->endpoints->data); 64 free_user_endpoint(user->endpoints->data);
60 user->endpoints = g_slist_delete_link(user->endpoints, user->endpoints); 65 user->endpoints = g_slist_delete_link(user->endpoints, user->endpoints);
61 } 66 }
90 } 95 }
91 g_free(user->statusline); 96 g_free(user->statusline);
92 g_free(user->invite_message); 97 g_free(user->invite_message);
93 98
94 g_free(user); 99 g_free(user);
100 }
101
102 MsnUser *
103 msn_user_ref(MsnUser *user)
104 {
105 g_return_val_if_fail(user != NULL, NULL);
106
107 user->refcount++;
108
109 return user;
110 }
111
112 void
113 msn_user_unref(MsnUser *user)
114 {
115 g_return_if_fail(user != NULL);
116
117 user->refcount--;
118
119 if(user->refcount == 0)
120 msn_user_destroy(user);
95 } 121 }
96 122
97 void 123 void
98 msn_user_update(MsnUser *user) 124 msn_user_update(MsnUser *user)
99 { 125 {