comparison src/protocols/msn/user.c @ 19785:852b32710df0

[gaim-migrate @ 16507] add the contact list retrieve and dump contact list to server currently can do chanllenge successfully But can't get the buddy list done by MaYuan<mayuan2006@gmail.com> committer: Ethan Blanton <elb@pidgin.im>
author Ma Yuan <mayuan2006@gmail.com>
date Mon, 17 Jul 2006 12:22:37 +0000
parents 967ef719cb62
children b99512bd6d85
comparison
equal deleted inserted replaced
19784:bc30c6270d9f 19785:852b32710df0
23 */ 23 */
24 #include "msn.h" 24 #include "msn.h"
25 #include "user.h" 25 #include "user.h"
26 #include "slp.h" 26 #include "slp.h"
27 27
28 /*new a user object*/
28 MsnUser * 29 MsnUser *
29 msn_user_new(MsnUserList *userlist, const char *passport, 30 msn_user_new(MsnUserList *userlist, const char *passport,
30 const char *store_name) 31 const char *store_name)
31 { 32 {
32 MsnUser *user; 33 MsnUser *user;
48 #endif 49 #endif
49 50
50 return user; 51 return user;
51 } 52 }
52 53
54 /*destroy a user object*/
53 void 55 void
54 msn_user_destroy(MsnUser *user) 56 msn_user_destroy(MsnUser *user)
55 { 57 {
56 g_return_if_fail(user != NULL); 58 g_return_if_fail(user != NULL);
57 59
65 msn_object_destroy(user->msnobj); 67 msn_object_destroy(user->msnobj);
66 68
67 g_free(user->passport); 69 g_free(user->passport);
68 g_free(user->friendly_name); 70 g_free(user->friendly_name);
69 g_free(user->store_name); 71 g_free(user->store_name);
72 g_free(user->uid);
70 g_free(user->phone.home); 73 g_free(user->phone.home);
71 g_free(user->phone.work); 74 g_free(user->phone.work);
72 g_free(user->phone.mobile); 75 g_free(user->phone.mobile);
73 76
74 g_free(user); 77 g_free(user);
142 g_free(user->store_name); 145 g_free(user->store_name);
143 user->store_name = g_strdup(name); 146 user->store_name = g_strdup(name);
144 } 147 }
145 148
146 void 149 void
150 msn_user_set_uid(MsnUser *user, const char *uid)
151 {
152 g_return_if_fail(user != NULL);
153
154 g_free(user->uid);
155 user->uid = g_strdup(uid);
156 }
157
158 void
159 msn_user_set_type(MsnUser *user,int type)
160 {
161 g_return_if_fail(user != NULL);
162
163 user->type = type;
164 }
165
166 void
147 msn_user_set_buddy_icon(MsnUser *user, const char *filename) 167 msn_user_set_buddy_icon(MsnUser *user, const char *filename)
148 { 168 {
149 struct stat st; 169 struct stat st;
150 FILE *fp; 170 FILE *fp;
151 MsnObject *msnobj = msn_user_get_object(user); 171 MsnObject *msnobj = msn_user_get_object(user);
152 172
153 g_return_if_fail(user != NULL); 173 g_return_if_fail(user != NULL);
154 174
155 if (filename == NULL || g_stat(filename, &st) == -1) 175 if (filename == NULL || g_stat(filename, &st) == -1){
156 {
157 msn_user_set_object(user, NULL); 176 msn_user_set_object(user, NULL);
158 } 177 }else if ((fp = g_fopen(filename, "rb")) != NULL){
159 else if ((fp = g_fopen(filename, "rb")) != NULL)
160 {
161 GaimCipherContext *ctx; 178 GaimCipherContext *ctx;
162 char *buf; 179 char *buf;
163 gsize len; 180 gsize len;
164 char *base64; 181 char *base64;
165 unsigned char digest[20]; 182 unsigned char digest[20];
166 183
167 if (msnobj == NULL) 184 if (msnobj == NULL) {
168 {
169 msnobj = msn_object_new(); 185 msnobj = msn_object_new();
170 msn_object_set_local(msnobj); 186 msn_object_set_local(msnobj);
171 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE); 187 msn_object_set_type(msnobj, MSN_OBJECT_USERTILE);
172 msn_object_set_location(msnobj, "TFR2C2.tmp"); 188 msn_object_set_location(msnobj, "TFR2C2.tmp");
173 msn_object_set_creator(msnobj, msn_user_get_passport(user)); 189 msn_object_set_creator(msnobj, msn_user_get_passport(user));
215 g_free(buf); 231 g_free(buf);
216 232
217 base64 = gaim_base64_encode(digest, sizeof(digest)); 233 base64 = gaim_base64_encode(digest, sizeof(digest));
218 msn_object_set_sha1c(msnobj, base64); 234 msn_object_set_sha1c(msnobj, base64);
219 g_free(base64); 235 g_free(base64);
220 } 236 }else{
221 else
222 {
223 gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename); 237 gaim_debug_error("msn", "Unable to open buddy icon %s!\n", filename);
224 msn_user_set_object(user, NULL); 238 msn_user_set_object(user, NULL);
225 } 239 }
226 } 240 }
227 241
228 void 242 /*add group id to User object*/
229 msn_user_add_group_id(MsnUser *user, int id) 243 void
244 msn_user_add_group_id(MsnUser *user, const char* id)
230 { 245 {
231 MsnUserList *userlist; 246 MsnUserList *userlist;
232 GaimAccount *account; 247 GaimAccount *account;
233 GaimBuddy *b; 248 GaimBuddy *b;
234 GaimGroup *g; 249 GaimGroup *g;
235 const char *passport; 250 const char *passport;
236 const char *group_name; 251 const char *group_name;
237 252
238 g_return_if_fail(user != NULL); 253 g_return_if_fail(user != NULL);
239 g_return_if_fail(id >= 0); 254 g_return_if_fail(id != NULL);
240 255
241 user->group_ids = g_list_append(user->group_ids, GINT_TO_POINTER(id)); 256 user->group_ids = g_list_append(user->group_ids,id);
242 257
243 userlist = user->userlist; 258 userlist = user->userlist;
244 account = userlist->session->account; 259 account = userlist->session->account;
245 passport = msn_user_get_passport(user); 260 passport = msn_user_get_passport(user);
246 261
247 group_name = msn_userlist_find_group_name(userlist, id); 262 group_name = msn_userlist_find_group_name(userlist, id);
248 263
249 g = gaim_find_group(group_name); 264 g = gaim_find_group(group_name);
250 265
251 if ((id == 0) && (g == NULL)) 266 if ((id == 0) && (g == NULL)){
252 {
253 g = gaim_group_new(group_name); 267 g = gaim_group_new(group_name);
254 gaim_blist_add_group(g, NULL); 268 gaim_blist_add_group(g, NULL);
255 } 269 }
256 270
257 b = gaim_find_buddy_in_group(account, passport, g); 271 b = gaim_find_buddy_in_group(account, passport, g);
258 272
259 if (b == NULL) 273 if (b == NULL){
260 {
261 b = gaim_buddy_new(account, passport, NULL); 274 b = gaim_buddy_new(account, passport, NULL);
262 275
263 gaim_blist_add_buddy(b, NULL, g, NULL); 276 gaim_blist_add_buddy(b, NULL, g, NULL);
264 } 277 }
265 278
266 b->proto_data = user; 279 b->proto_data = user;
267 } 280 }
268 281
269 void 282 void
270 msn_user_remove_group_id(MsnUser *user, int id) 283 msn_user_remove_group_id(MsnUser *user, const char * id)
271 { 284 {
272 g_return_if_fail(user != NULL); 285 g_return_if_fail(user != NULL);
273 g_return_if_fail(id >= 0); 286 g_return_if_fail(id != NULL);
274 287
275 user->group_ids = g_list_remove(user->group_ids, GINT_TO_POINTER(id)); 288 user->group_ids = g_list_remove(user->group_ids, id);
276 } 289 }
277 290
278 void 291 void
279 msn_user_set_home_phone(MsnUser *user, const char *number) 292 msn_user_set_home_phone(MsnUser *user, const char *number)
280 { 293 {