Mercurial > pidgin
comparison libpurple/protocols/oscar/family_locate.c @ 17191:1927f4ead3ca
Make all the oscar memory allocations and frees use the glib functions to avoid problems when mixing C runtimes.
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Tue, 22 May 2007 18:56:09 +0000 |
parents | 1560f28cb854 |
children | f80f7e1047be |
comparison
equal
deleted
inserted
replaced
17190:12d0ad970a15 | 17191:1927f4ead3ca |
---|---|
236 aim_rxcallback_t userfunc; | 236 aim_rxcallback_t userfunc; |
237 | 237 |
238 cur = aim_locate_finduserinfo(od, userinfo->sn); | 238 cur = aim_locate_finduserinfo(od, userinfo->sn); |
239 | 239 |
240 if (cur == NULL) { | 240 if (cur == NULL) { |
241 cur = (aim_userinfo_t *)calloc(1, sizeof(aim_userinfo_t)); | 241 cur = (aim_userinfo_t *)g_new0(aim_userinfo_t, 1); |
242 cur->sn = strdup(userinfo->sn); | 242 cur->sn = g_strdup(userinfo->sn); |
243 cur->next = od->locate.userinfo; | 243 cur->next = od->locate.userinfo; |
244 od->locate.userinfo = cur; | 244 od->locate.userinfo = cur; |
245 } | 245 } |
246 | 246 |
247 cur->warnlevel = userinfo->warnlevel; | 247 cur->warnlevel = userinfo->warnlevel; |
259 if (userinfo->capabilities != 0) | 259 if (userinfo->capabilities != 0) |
260 cur->capabilities = userinfo->capabilities; | 260 cur->capabilities = userinfo->capabilities; |
261 cur->present |= userinfo->present; | 261 cur->present |= userinfo->present; |
262 | 262 |
263 if (userinfo->iconcsumlen > 0) { | 263 if (userinfo->iconcsumlen > 0) { |
264 free(cur->iconcsum); | 264 g_free(cur->iconcsum); |
265 cur->iconcsum = (guint8 *)malloc(userinfo->iconcsumlen); | 265 cur->iconcsum = (guint8 *)g_malloc(userinfo->iconcsumlen); |
266 memcpy(cur->iconcsum, userinfo->iconcsum, userinfo->iconcsumlen); | 266 memcpy(cur->iconcsum, userinfo->iconcsum, userinfo->iconcsumlen); |
267 cur->iconcsumlen = userinfo->iconcsumlen; | 267 cur->iconcsumlen = userinfo->iconcsumlen; |
268 } | 268 } |
269 | 269 |
270 if (userinfo->info != NULL) { | 270 if (userinfo->info != NULL) { |
271 free(cur->info); | 271 g_free(cur->info); |
272 free(cur->info_encoding); | 272 g_free(cur->info_encoding); |
273 if (userinfo->info_len > 0) { | 273 if (userinfo->info_len > 0) { |
274 cur->info = (char *)malloc(userinfo->info_len); | 274 cur->info = (char *)g_malloc(userinfo->info_len); |
275 memcpy(cur->info, userinfo->info, userinfo->info_len); | 275 memcpy(cur->info, userinfo->info, userinfo->info_len); |
276 } else | 276 } else |
277 cur->info = NULL; | 277 cur->info = NULL; |
278 cur->info_encoding = strdup(userinfo->info_encoding); | 278 cur->info_encoding = g_strdup(userinfo->info_encoding); |
279 cur->info_len = userinfo->info_len; | 279 cur->info_len = userinfo->info_len; |
280 } | 280 } |
281 | 281 |
282 if (userinfo->status != NULL) { | 282 if (userinfo->status != NULL) { |
283 free(cur->status); | 283 g_free(cur->status); |
284 free(cur->status_encoding); | 284 g_free(cur->status_encoding); |
285 if (userinfo->status_len > 0) { | 285 if (userinfo->status_len > 0) { |
286 cur->status = (char *)malloc(userinfo->status_len); | 286 cur->status = (char *)g_malloc(userinfo->status_len); |
287 memcpy(cur->status, userinfo->status, userinfo->status_len); | 287 memcpy(cur->status, userinfo->status, userinfo->status_len); |
288 } else | 288 } else |
289 cur->status = NULL; | 289 cur->status = NULL; |
290 if (userinfo->status_encoding != NULL) | 290 if (userinfo->status_encoding != NULL) |
291 cur->status_encoding = strdup(userinfo->status_encoding); | 291 cur->status_encoding = g_strdup(userinfo->status_encoding); |
292 else | 292 else |
293 cur->status_encoding = NULL; | 293 cur->status_encoding = NULL; |
294 cur->status_len = userinfo->status_len; | 294 cur->status_len = userinfo->status_len; |
295 } | 295 } |
296 | 296 |
297 if (userinfo->itmsurl != NULL) { | 297 if (userinfo->itmsurl != NULL) { |
298 free(cur->itmsurl); | 298 g_free(cur->itmsurl); |
299 free(cur->itmsurl_encoding); | 299 g_free(cur->itmsurl_encoding); |
300 if (userinfo->itmsurl_len > 0) { | 300 if (userinfo->itmsurl_len > 0) { |
301 cur->itmsurl = (char *)malloc(userinfo->itmsurl_len); | 301 cur->itmsurl = (char *)g_malloc(userinfo->itmsurl_len); |
302 memcpy(cur->itmsurl, userinfo->itmsurl, userinfo->itmsurl_len); | 302 memcpy(cur->itmsurl, userinfo->itmsurl, userinfo->itmsurl_len); |
303 } else | 303 } else |
304 cur->itmsurl = NULL; | 304 cur->itmsurl = NULL; |
305 if (userinfo->itmsurl_encoding != NULL) | 305 if (userinfo->itmsurl_encoding != NULL) |
306 cur->itmsurl_encoding = strdup(userinfo->itmsurl_encoding); | 306 cur->itmsurl_encoding = g_strdup(userinfo->itmsurl_encoding); |
307 else | 307 else |
308 cur->itmsurl_encoding = NULL; | 308 cur->itmsurl_encoding = NULL; |
309 cur->itmsurl_len = userinfo->itmsurl_len; | 309 cur->itmsurl_len = userinfo->itmsurl_len; |
310 } | 310 } |
311 | 311 |
312 if (userinfo->away != NULL) { | 312 if (userinfo->away != NULL) { |
313 free(cur->away); | 313 g_free(cur->away); |
314 free(cur->away_encoding); | 314 g_free(cur->away_encoding); |
315 if (userinfo->away_len > 0) { | 315 if (userinfo->away_len > 0) { |
316 cur->away = (char *)malloc(userinfo->away_len); | 316 cur->away = (char *)g_malloc(userinfo->away_len); |
317 memcpy(cur->away, userinfo->away, userinfo->away_len); | 317 memcpy(cur->away, userinfo->away, userinfo->away_len); |
318 } else | 318 } else |
319 cur->away = NULL; | 319 cur->away = NULL; |
320 cur->away_encoding = strdup(userinfo->away_encoding); | 320 cur->away_encoding = g_strdup(userinfo->away_encoding); |
321 cur->away_len = userinfo->away_len; | 321 cur->away_len = userinfo->away_len; |
322 | 322 |
323 } else if (!(userinfo->flags & AIM_FLAG_AWAY)) { | 323 } else if (!(userinfo->flags & AIM_FLAG_AWAY)) { |
324 /* | 324 /* |
325 * We don't have an away message specified in this user_info block. | 325 * We don't have an away message specified in this user_info block. |
326 * If the user is not away, clear any cached away message now. | 326 * If the user is not away, clear any cached away message now. |
327 */ | 327 */ |
328 if (cur->away) { | 328 if (cur->away) { |
329 free(cur->away); | 329 g_free(cur->away); |
330 cur->away = NULL; | 330 cur->away = NULL; |
331 } | 331 } |
332 if (cur->away_encoding) { | 332 if (cur->away_encoding) { |
333 free(cur->away_encoding); | 333 g_free(cur->away_encoding); |
334 cur->away_encoding = NULL; | 334 cur->away_encoding = NULL; |
335 } | 335 } |
336 cur->away_len = 0; | 336 cur->away_len = 0; |
337 } | 337 } |
338 | 338 |
399 | 399 |
400 while ((od->locate.requested != NULL) && (aim_sncmp(sn, od->locate.requested->sn) == 0)) { | 400 while ((od->locate.requested != NULL) && (aim_sncmp(sn, od->locate.requested->sn) == 0)) { |
401 del = od->locate.requested; | 401 del = od->locate.requested; |
402 od->locate.requested = del->next; | 402 od->locate.requested = del->next; |
403 was_explicit = FALSE; | 403 was_explicit = FALSE; |
404 free(del->sn); | 404 g_free(del->sn); |
405 free(del); | 405 g_free(del); |
406 } | 406 } |
407 | 407 |
408 cur = od->locate.requested; | 408 cur = od->locate.requested; |
409 while ((cur != NULL) && (cur->next != NULL)) { | 409 while ((cur != NULL) && (cur->next != NULL)) { |
410 if (aim_sncmp(sn, cur->next->sn) == 0) { | 410 if (aim_sncmp(sn, cur->next->sn) == 0) { |
411 del = cur->next; | 411 del = cur->next; |
412 cur->next = del->next; | 412 cur->next = del->next; |
413 was_explicit = FALSE; | 413 was_explicit = FALSE; |
414 free(del->sn); | 414 g_free(del->sn); |
415 free(del); | 415 g_free(del); |
416 } else | 416 } else |
417 cur = cur->next; | 417 cur = cur->next; |
418 } | 418 } |
419 | 419 |
420 if (!was_explicit) { | 420 if (!was_explicit) { |
445 return; | 445 return; |
446 cur = cur->next; | 446 cur = cur->next; |
447 } | 447 } |
448 | 448 |
449 /* Add a new node to our request queue */ | 449 /* Add a new node to our request queue */ |
450 cur = (struct userinfo_node *)malloc(sizeof(struct userinfo_node)); | 450 cur = (struct userinfo_node *)g_malloc(sizeof(struct userinfo_node)); |
451 cur->sn = strdup(sn); | 451 cur->sn = g_strdup(sn); |
452 cur->next = od->locate.torequest; | 452 cur->next = od->locate.torequest; |
453 od->locate.torequest = cur; | 453 od->locate.torequest = cur; |
454 | 454 |
455 /* Actually request some info up in this piece */ | 455 /* Actually request some info up in this piece */ |
456 aim_locate_dorequest(od); | 456 aim_locate_dorequest(od); |
500 cap[6], cap[7], | 500 cap[6], cap[7], |
501 cap[8], cap[9], | 501 cap[8], cap[9], |
502 cap[10], cap[11], cap[12], cap[13], | 502 cap[10], cap[11], cap[12], cap[13], |
503 cap[14], cap[15]); | 503 cap[14], cap[15]); |
504 | 504 |
505 free(cap); | 505 g_free(cap); |
506 } | 506 } |
507 | 507 |
508 return flags; | 508 return flags; |
509 } | 509 } |
510 | 510 |
529 } | 529 } |
530 | 530 |
531 if (!identified) | 531 if (!identified) |
532 purple_debug_misc("oscar", "unknown short capability: {%02x%02x}\n", cap[0], cap[1]); | 532 purple_debug_misc("oscar", "unknown short capability: {%02x%02x}\n", cap[0], cap[1]); |
533 | 533 |
534 free(cap); | 534 g_free(cap); |
535 } | 535 } |
536 | 536 |
537 return flags; | 537 return flags; |
538 } | 538 } |
539 | 539 |
584 #endif | 584 #endif |
585 | 585 |
586 void | 586 void |
587 aim_info_free(aim_userinfo_t *info) | 587 aim_info_free(aim_userinfo_t *info) |
588 { | 588 { |
589 free(info->sn); | 589 g_free(info->sn); |
590 free(info->iconcsum); | 590 g_free(info->iconcsum); |
591 free(info->info); | 591 g_free(info->info); |
592 free(info->info_encoding); | 592 g_free(info->info_encoding); |
593 free(info->status); | 593 g_free(info->status); |
594 free(info->status_encoding); | 594 g_free(info->status_encoding); |
595 free(info->itmsurl); | 595 g_free(info->itmsurl); |
596 free(info->itmsurl_encoding); | 596 g_free(info->itmsurl_encoding); |
597 free(info->away); | 597 g_free(info->away); |
598 free(info->away_encoding); | 598 g_free(info->away_encoding); |
599 } | 599 } |
600 | 600 |
601 /* | 601 /* |
602 * AIM is fairly regular about providing user info. This is a generic | 602 * AIM is fairly regular about providing user info. This is a generic |
603 * routine to extract it in its standard form. | 603 * routine to extract it in its standard form. |
827 byte_stream_advance(bs, length2); | 827 byte_stream_advance(bs, length2); |
828 } break; | 828 } break; |
829 | 829 |
830 case 0x0001: { /* A buddy icon checksum */ | 830 case 0x0001: { /* A buddy icon checksum */ |
831 if ((length2 > 0) && ((number == 0x00) || (number == 0x01))) { | 831 if ((length2 > 0) && ((number == 0x00) || (number == 0x01))) { |
832 free(outinfo->iconcsum); | 832 g_free(outinfo->iconcsum); |
833 outinfo->iconcsumtype = number; | 833 outinfo->iconcsumtype = number; |
834 outinfo->iconcsum = byte_stream_getraw(bs, length2); | 834 outinfo->iconcsum = byte_stream_getraw(bs, length2); |
835 outinfo->iconcsumlen = length2; | 835 outinfo->iconcsumlen = length2; |
836 } else | 836 } else |
837 byte_stream_advance(bs, length2); | 837 byte_stream_advance(bs, length2); |
838 } break; | 838 } break; |
839 | 839 |
840 case 0x0002: { /* A status/available message */ | 840 case 0x0002: { /* A status/available message */ |
841 free(outinfo->status); | 841 g_free(outinfo->status); |
842 free(outinfo->status_encoding); | 842 g_free(outinfo->status_encoding); |
843 if (length2 >= 4) { | 843 if (length2 >= 4) { |
844 outinfo->status_len = byte_stream_get16(bs); | 844 outinfo->status_len = byte_stream_get16(bs); |
845 outinfo->status = byte_stream_getstr(bs, outinfo->status_len); | 845 outinfo->status = byte_stream_getstr(bs, outinfo->status_len); |
846 if (byte_stream_get16(bs) == 0x0001) { /* We have an encoding */ | 846 if (byte_stream_get16(bs) == 0x0001) { /* We have an encoding */ |
847 byte_stream_get16(bs); | 847 byte_stream_get16(bs); |
857 outinfo->status_encoding = NULL; | 857 outinfo->status_encoding = NULL; |
858 } | 858 } |
859 } break; | 859 } break; |
860 | 860 |
861 case 0x0009: { /* An iTunes Music Store link */ | 861 case 0x0009: { /* An iTunes Music Store link */ |
862 free(outinfo->itmsurl); | 862 g_free(outinfo->itmsurl); |
863 free(outinfo->itmsurl_encoding); | 863 g_free(outinfo->itmsurl_encoding); |
864 if (length2 >= 4) { | 864 if (length2 >= 4) { |
865 outinfo->itmsurl_len = byte_stream_get16(bs); | 865 outinfo->itmsurl_len = byte_stream_get16(bs); |
866 outinfo->itmsurl = byte_stream_getstr(bs, outinfo->itmsurl_len); | 866 outinfo->itmsurl = byte_stream_getstr(bs, outinfo->itmsurl_len); |
867 if (byte_stream_get16(bs) == 0x0001) { | 867 if (byte_stream_get16(bs) == 0x0001) { |
868 /* We have an encoding */ | 868 /* We have an encoding */ |
1011 if (was_explicit == TRUE) | 1011 if (was_explicit == TRUE) |
1012 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | 1012 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
1013 ret = userfunc(od, conn, frame, reason, sn); | 1013 ret = userfunc(od, conn, frame, reason, sn); |
1014 | 1014 |
1015 if (snac2) | 1015 if (snac2) |
1016 free(snac2->data); | 1016 g_free(snac2->data); |
1017 free(snac2); | 1017 g_free(snac2); |
1018 | 1018 |
1019 return ret; | 1019 return ret; |
1020 } | 1020 } |
1021 | 1021 |
1022 /* | 1022 /* |
1111 } | 1111 } |
1112 | 1112 |
1113 /* Build the packet first to get real length */ | 1113 /* Build the packet first to get real length */ |
1114 if (profile) { | 1114 if (profile) { |
1115 /* no + 1 here because of %s */ | 1115 /* no + 1 here because of %s */ |
1116 encoding = malloc(strlen(defencoding) + strlen(profile_encoding)); | 1116 encoding = g_malloc(strlen(defencoding) + strlen(profile_encoding)); |
1117 snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding); | 1117 snprintf(encoding, strlen(defencoding) + strlen(profile_encoding), defencoding, profile_encoding); |
1118 aim_tlvlist_add_str(&tl, 0x0001, encoding); | 1118 aim_tlvlist_add_str(&tl, 0x0001, encoding); |
1119 aim_tlvlist_add_raw(&tl, 0x0002, profile_len, (const guchar *)profile); | 1119 aim_tlvlist_add_raw(&tl, 0x0002, profile_len, (const guchar *)profile); |
1120 free(encoding); | 1120 g_free(encoding); |
1121 } | 1121 } |
1122 | 1122 |
1123 /* | 1123 /* |
1124 * So here's how this works: | 1124 * So here's how this works: |
1125 * - You are away when you have a non-zero-length type 4 TLV stored. | 1125 * - You are away when you have a non-zero-length type 4 TLV stored. |
1128 * - If you do not send the type 4 TLV, your status does not change | 1128 * - If you do not send the type 4 TLV, your status does not change |
1129 * (that is, if you were away, you'll remain away). | 1129 * (that is, if you were away, you'll remain away). |
1130 */ | 1130 */ |
1131 if (awaymsg) { | 1131 if (awaymsg) { |
1132 if (awaymsg_len) { | 1132 if (awaymsg_len) { |
1133 encoding = malloc(strlen(defencoding) + strlen(awaymsg_encoding)); | 1133 encoding = g_malloc(strlen(defencoding) + strlen(awaymsg_encoding)); |
1134 snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding); | 1134 snprintf(encoding, strlen(defencoding) + strlen(awaymsg_encoding), defencoding, awaymsg_encoding); |
1135 aim_tlvlist_add_str(&tl, 0x0003, encoding); | 1135 aim_tlvlist_add_str(&tl, 0x0003, encoding); |
1136 aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, (const guchar *)awaymsg); | 1136 aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, (const guchar *)awaymsg); |
1137 free(encoding); | 1137 g_free(encoding); |
1138 } else | 1138 } else |
1139 aim_tlvlist_add_noval(&tl, 0x0004); | 1139 aim_tlvlist_add_noval(&tl, 0x0004); |
1140 } | 1140 } |
1141 | 1141 |
1142 frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(&tl)); | 1142 frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(&tl)); |
1223 aim_userinfo_t *userinfo, *userinfo2; | 1223 aim_userinfo_t *userinfo, *userinfo2; |
1224 aim_tlvlist_t *tlvlist; | 1224 aim_tlvlist_t *tlvlist; |
1225 aim_tlv_t *tlv = NULL; | 1225 aim_tlv_t *tlv = NULL; |
1226 int was_explicit; | 1226 int was_explicit; |
1227 | 1227 |
1228 userinfo = (aim_userinfo_t *)malloc(sizeof(aim_userinfo_t)); | 1228 userinfo = (aim_userinfo_t *)g_malloc(sizeof(aim_userinfo_t)); |
1229 aim_info_extract(od, bs, userinfo); | 1229 aim_info_extract(od, bs, userinfo); |
1230 tlvlist = aim_tlvlist_read(bs); | 1230 tlvlist = aim_tlvlist_read(bs); |
1231 | 1231 |
1232 /* Profile will be 1 and 2 */ | 1232 /* Profile will be 1 and 2 */ |
1233 userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1); | 1233 userinfo->info_encoding = aim_tlv_getstr(tlvlist, 0x0001, 1); |
1234 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) { | 1234 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0002, 1))) { |
1235 userinfo->info = (char *)malloc(tlv->length); | 1235 userinfo->info = (char *)g_malloc(tlv->length); |
1236 memcpy(userinfo->info, tlv->value, tlv->length); | 1236 memcpy(userinfo->info, tlv->value, tlv->length); |
1237 userinfo->info_len = tlv->length; | 1237 userinfo->info_len = tlv->length; |
1238 } | 1238 } |
1239 | 1239 |
1240 /* Away message will be 3 and 4 */ | 1240 /* Away message will be 3 and 4 */ |
1241 userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1); | 1241 userinfo->away_encoding = aim_tlv_getstr(tlvlist, 0x0003, 1); |
1242 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) { | 1242 if ((tlv = aim_tlv_gettlv(tlvlist, 0x0004, 1))) { |
1243 userinfo->away = (char *)malloc(tlv->length); | 1243 userinfo->away = (char *)g_malloc(tlv->length); |
1244 memcpy(userinfo->away, tlv->value, tlv->length); | 1244 memcpy(userinfo->away, tlv->value, tlv->length); |
1245 userinfo->away_len = tlv->length; | 1245 userinfo->away_len = tlv->length; |
1246 } | 1246 } |
1247 | 1247 |
1248 /* Caps will be 5 */ | 1248 /* Caps will be 5 */ |
1255 aim_tlvlist_free(&tlvlist); | 1255 aim_tlvlist_free(&tlvlist); |
1256 | 1256 |
1257 aim_locate_adduserinfo(od, userinfo); | 1257 aim_locate_adduserinfo(od, userinfo); |
1258 userinfo2 = aim_locate_finduserinfo(od, userinfo->sn); | 1258 userinfo2 = aim_locate_finduserinfo(od, userinfo->sn); |
1259 aim_info_free(userinfo); | 1259 aim_info_free(userinfo); |
1260 free(userinfo); | 1260 g_free(userinfo); |
1261 | 1261 |
1262 /* | 1262 /* |
1263 * Remove this screen name from our queue. If the client requested | 1263 * Remove this screen name from our queue. If the client requested |
1264 * this buddy's info explicitly, then notify them that we have info | 1264 * this buddy's info explicitly, then notify them that we have info |
1265 * for this buddy. | 1265 * for this buddy. |
1452 | 1452 |
1453 while (od->locate.userinfo) { | 1453 while (od->locate.userinfo) { |
1454 del = od->locate.userinfo; | 1454 del = od->locate.userinfo; |
1455 od->locate.userinfo = od->locate.userinfo->next; | 1455 od->locate.userinfo = od->locate.userinfo->next; |
1456 aim_info_free(del); | 1456 aim_info_free(del); |
1457 free(del); | 1457 g_free(del); |
1458 } | 1458 } |
1459 } | 1459 } |
1460 | 1460 |
1461 int | 1461 int |
1462 locate_modfirst(OscarData *od, aim_module_t *mod) | 1462 locate_modfirst(OscarData *od, aim_module_t *mod) |