comparison libpurple/protocols/oscar/family_locate.c @ 25925:6e1967b0f90b

Change "screen name" to "username" or "buddy name" in a whole bunch of places in the code. I've been using the definitions from the jabber specs, where "user" is me and "buddy" is someone on my buddy list.
author Mark Doliner <mark@kingant.net>
date Mon, 26 Jan 2009 09:12:04 +0000
parents 584063555949
children f1b92f2ea41f 5391094529c6
comparison
equal deleted inserted replaced
25924:584063555949 25925:6e1967b0f90b
251 { 251 {
252 aim_userinfo_t *cur; 252 aim_userinfo_t *cur;
253 FlapConnection *conn; 253 FlapConnection *conn;
254 aim_rxcallback_t userfunc; 254 aim_rxcallback_t userfunc;
255 255
256 cur = aim_locate_finduserinfo(od, userinfo->sn); 256 cur = aim_locate_finduserinfo(od, userinfo->bn);
257 257
258 if (cur == NULL) { 258 if (cur == NULL) {
259 cur = (aim_userinfo_t *)g_new0(aim_userinfo_t, 1); 259 cur = (aim_userinfo_t *)g_new0(aim_userinfo_t, 1);
260 cur->sn = g_strdup(userinfo->sn); 260 cur->bn = g_strdup(userinfo->bn);
261 cur->next = od->locate.userinfo; 261 cur->next = od->locate.userinfo;
262 od->locate.userinfo = cur; 262 od->locate.userinfo = cur;
263 } 263 }
264 264
265 cur->warnlevel = userinfo->warnlevel; 265 cur->warnlevel = userinfo->warnlevel;
364 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_LOCATE, SNAC_SUBTYPE_LOCATE_GOTINFOBLOCK))) 364 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_LOCATE, SNAC_SUBTYPE_LOCATE_GOTINFOBLOCK)))
365 userfunc(od, conn, NULL, cur); 365 userfunc(od, conn, NULL, cur);
366 } 366 }
367 367
368 /** 368 /**
369 * Remove this screen name from our queue. If this info was requested 369 * Remove this buddy name from our queue. If this info was requested
370 * by our info request queue, then pop the next element off of the queue. 370 * by our info request queue, then pop the next element off of the queue.
371 * 371 *
372 * @param od The aim session. 372 * @param od The aim session.
373 * @param sn Screen name of the info we just received. 373 * @param bn Buddy name of the info we just received.
374 * @return True if the request was explicit (client requested the info), 374 * @return True if the request was explicit (client requested the info),
375 * false if the request was implicit (libfaim request the info). 375 * false if the request was implicit (libfaim request the info).
376 */ 376 */
377 static int 377 static int
378 aim_locate_gotuserinfo(OscarData *od, FlapConnection *conn, const char *sn) 378 aim_locate_gotuserinfo(OscarData *od, FlapConnection *conn, const char *bn)
379 { 379 {
380 struct userinfo_node *cur, *del; 380 struct userinfo_node *cur, *del;
381 int was_explicit = TRUE; 381 int was_explicit = TRUE;
382 382
383 while ((od->locate.requested != NULL) && (aim_sncmp(sn, od->locate.requested->sn) == 0)) { 383 while ((od->locate.requested != NULL) && (oscar_util_name_compare(bn, od->locate.requested->bn) == 0)) {
384 del = od->locate.requested; 384 del = od->locate.requested;
385 od->locate.requested = del->next; 385 od->locate.requested = del->next;
386 was_explicit = FALSE; 386 was_explicit = FALSE;
387 g_free(del->sn); 387 g_free(del->bn);
388 g_free(del); 388 g_free(del);
389 } 389 }
390 390
391 cur = od->locate.requested; 391 cur = od->locate.requested;
392 while ((cur != NULL) && (cur->next != NULL)) { 392 while ((cur != NULL) && (cur->next != NULL)) {
393 if (aim_sncmp(sn, cur->next->sn) == 0) { 393 if (oscar_util_name_compare(bn, cur->next->bn) == 0) {
394 del = cur->next; 394 del = cur->next;
395 cur->next = del->next; 395 cur->next = del->next;
396 was_explicit = FALSE; 396 was_explicit = FALSE;
397 g_free(del->sn); 397 g_free(del->bn);
398 g_free(del); 398 g_free(del);
399 } else 399 } else
400 cur = cur->next; 400 cur = cur->next;
401 } 401 }
402 402
403 return was_explicit; 403 return was_explicit;
404 } 404 }
405 405
406 void 406 void
407 aim_locate_autofetch_away_message(OscarData *od, const char *sn) 407 aim_locate_autofetch_away_message(OscarData *od, const char *bn)
408 { 408 {
409 struct userinfo_node *cur; 409 struct userinfo_node *cur;
410 410
411 /* Make sure we haven't already made an info request for this buddy */ 411 /* Make sure we haven't already made an info request for this buddy */
412 for (cur = od->locate.requested; cur != NULL; cur = cur->next) 412 for (cur = od->locate.requested; cur != NULL; cur = cur->next)
413 if (aim_sncmp(sn, cur->sn) == 0) 413 if (oscar_util_name_compare(bn, cur->bn) == 0)
414 return; 414 return;
415 415
416 /* Add a new node to our request queue */ 416 /* Add a new node to our request queue */
417 cur = (struct userinfo_node *)g_malloc(sizeof(struct userinfo_node)); 417 cur = (struct userinfo_node *)g_malloc(sizeof(struct userinfo_node));
418 cur->sn = g_strdup(sn); 418 cur->bn = g_strdup(bn);
419 cur->next = od->locate.requested; 419 cur->next = od->locate.requested;
420 od->locate.requested = cur; 420 od->locate.requested = cur;
421 421
422 aim_locate_getinfoshort(od, cur->sn, 0x00000002); 422 aim_locate_getinfoshort(od, cur->bn, 0x00000002);
423 } 423 }
424 424
425 aim_userinfo_t *aim_locate_finduserinfo(OscarData *od, const char *sn) { 425 aim_userinfo_t *aim_locate_finduserinfo(OscarData *od, const char *bn) {
426 aim_userinfo_t *cur = NULL; 426 aim_userinfo_t *cur = NULL;
427 427
428 if (sn == NULL) 428 if (bn == NULL)
429 return NULL; 429 return NULL;
430 430
431 cur = od->locate.userinfo; 431 cur = od->locate.userinfo;
432 432
433 while (cur != NULL) { 433 while (cur != NULL) {
434 if (aim_sncmp(cur->sn, sn) == 0) 434 if (oscar_util_name_compare(cur->bn, bn) == 0)
435 return cur; 435 return cur;
436 cur = cur->next; 436 cur = cur->next;
437 } 437 }
438 438
439 return NULL; 439 return NULL;
550 #endif 550 #endif
551 551
552 void 552 void
553 aim_info_free(aim_userinfo_t *info) 553 aim_info_free(aim_userinfo_t *info)
554 { 554 {
555 g_free(info->sn); 555 g_free(info->bn);
556 g_free(info->iconcsum); 556 g_free(info->iconcsum);
557 g_free(info->info); 557 g_free(info->info);
558 g_free(info->info_encoding); 558 g_free(info->info_encoding);
559 g_free(info->status); 559 g_free(info->status);
560 g_free(info->status_encoding); 560 g_free(info->status_encoding);
570 */ 570 */
571 int 571 int
572 aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *outinfo) 572 aim_info_extract(OscarData *od, ByteStream *bs, aim_userinfo_t *outinfo)
573 { 573 {
574 int curtlv, tlvcnt; 574 int curtlv, tlvcnt;
575 guint8 snlen; 575 guint8 bnlen;
576 576
577 if (!bs || !outinfo) 577 if (!bs || !outinfo)
578 return -EINVAL; 578 return -EINVAL;
579 579
580 /* Clear out old data first */ 580 /* Clear out old data first */
581 memset(outinfo, 0x00, sizeof(aim_userinfo_t)); 581 memset(outinfo, 0x00, sizeof(aim_userinfo_t));
582 582
583 /* 583 /*
584 * Screen name. Stored as an unterminated string prepended with a 584 * Username. Stored as an unterminated string prepended with a
585 * byte containing its length. 585 * byte containing its length.
586 */ 586 */
587 snlen = byte_stream_get8(bs); 587 bnlen = byte_stream_get8(bs);
588 outinfo->sn = byte_stream_getstr(bs, snlen); 588 outinfo->bn = byte_stream_getstr(bs, bnlen);
589 589
590 /* 590 /*
591 * Warning Level. Stored as an unsigned short. 591 * Warning Level. Stored as an unsigned short.
592 */ 592 */
593 outinfo->warnlevel = byte_stream_get16(bs); 593 outinfo->warnlevel = byte_stream_get16(bs);
879 * recovery. 879 * recovery.
880 * 880 *
881 */ 881 */
882 #ifdef LOG_UNKNOWN_TLV 882 #ifdef LOG_UNKNOWN_TLV
883 purple_debug_misc("oscar", "userinfo: **warning: unexpected TLV:\n"); 883 purple_debug_misc("oscar", "userinfo: **warning: unexpected TLV:\n");
884 purple_debug_misc("oscar", "userinfo: sn =%s\n", outinfo->sn); 884 purple_debug_misc("oscar", "userinfo: bn =%s\n", outinfo->bn);
885 dumptlv(od, type, bs, length); 885 dumptlv(od, type, bs, length);
886 #endif 886 #endif
887 } 887 }
888 888
889 /* Save ourselves. */ 889 /* Save ourselves. */
904 GSList *tlvlist = NULL; 904 GSList *tlvlist = NULL;
905 905
906 if (!bs || !info) 906 if (!bs || !info)
907 return -EINVAL; 907 return -EINVAL;
908 908
909 byte_stream_put8(bs, strlen(info->sn)); 909 byte_stream_put8(bs, strlen(info->bn));
910 byte_stream_putstr(bs, info->sn); 910 byte_stream_putstr(bs, info->bn);
911 911
912 byte_stream_put16(bs, info->warnlevel); 912 byte_stream_put16(bs, info->warnlevel);
913 913
914 if (info->present & AIM_USERINFO_PRESENT_FLAGS) 914 if (info->present & AIM_USERINFO_PRESENT_FLAGS)
915 aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags); 915 aim_tlvlist_add_16(&tlvlist, 0x0001, info->flags);
920 if (info->present & AIM_USERINFO_PRESENT_IDLE) 920 if (info->present & AIM_USERINFO_PRESENT_IDLE)
921 aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime); 921 aim_tlvlist_add_16(&tlvlist, 0x0004, info->idletime);
922 922
923 /* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */ 923 /* XXX - So, ICQ_OSCAR_SUPPORT is never defined anywhere... */
924 #ifdef ICQ_OSCAR_SUPPORT 924 #ifdef ICQ_OSCAR_SUPPORT
925 if (atoi(info->sn) != 0) { 925 if (atoi(info->bn) != 0) {
926 if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS) 926 if (info->present & AIM_USERINFO_PRESENT_ICQEXTSTATUS)
927 aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status); 927 aim_tlvlist_add_16(&tlvlist, 0x0006, info->icqinfo.status);
928 if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR) 928 if (info->present & AIM_USERINFO_PRESENT_ICQIPADDR)
929 aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr); 929 aim_tlvlist_add_32(&tlvlist, 0x000a, info->icqinfo.ipaddr);
930 } 930 }
951 { 951 {
952 int ret = 0; 952 int ret = 0;
953 aim_rxcallback_t userfunc; 953 aim_rxcallback_t userfunc;
954 aim_snac_t *snac2; 954 aim_snac_t *snac2;
955 guint16 reason; 955 guint16 reason;
956 char *sn; 956 char *bn;
957 int was_explicit; 957 int was_explicit;
958 958
959 if (!(snac2 = aim_remsnac(od, snac->id))) { 959 if (!(snac2 = aim_remsnac(od, snac->id))) {
960 purple_debug_misc("oscar", "faim: locate.c, error(): received response from unknown request!\n"); 960 purple_debug_misc("oscar", "locate error: received response from unknown request!\n");
961 return 0; 961 return 0;
962 } 962 }
963 963
964 if ((snac2->family != SNAC_FAMILY_LOCATE) && (snac2->type != 0x0015)) { 964 if ((snac2->family != SNAC_FAMILY_LOCATE) && (snac2->type != 0x0015)) {
965 purple_debug_misc("oscar", "faim: locate.c, error(): received response from invalid request! %d\n", snac2->family); 965 purple_debug_misc("oscar", "locate error: received response from invalid request! %d\n", snac2->family);
966 return 0; 966 return 0;
967 } 967 }
968 968
969 if (!(sn = snac2->data)) { 969 if (!(bn = snac2->data)) {
970 purple_debug_misc("oscar", "faim: locate.c, error(): received response from request without a screen name!\n"); 970 purple_debug_misc("oscar", "locate error: received response from request without a buddy name!\n");
971 return 0; 971 return 0;
972 } 972 }
973 973
974 reason = byte_stream_get16(bs); 974 reason = byte_stream_get16(bs);
975 975
976 /* 976 /*
977 * Remove this screen name from our queue. If the client requested 977 * Remove this buddy name from our queue. If the client requested
978 * this buddy's info explicitly, then notify them that we do not have 978 * this buddy's info explicitly, then notify them that we do not have
979 * info for this buddy. 979 * info for this buddy.
980 */ 980 */
981 was_explicit = aim_locate_gotuserinfo(od, conn, sn); 981 was_explicit = aim_locate_gotuserinfo(od, conn, bn);
982 if (was_explicit == TRUE) 982 if (was_explicit == TRUE)
983 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) 983 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
984 ret = userfunc(od, conn, frame, reason, sn); 984 ret = userfunc(od, conn, frame, reason, bn);
985 985
986 if (snac2) 986 if (snac2)
987 g_free(snac2->data); 987 g_free(snac2->data);
988 g_free(snac2); 988 g_free(snac2);
989 989
1155 } 1155 }
1156 1156
1157 /* 1157 /*
1158 * Subtype 0x0005 - Request info of another AIM user. 1158 * Subtype 0x0005 - Request info of another AIM user.
1159 * 1159 *
1160 * @param sn The screenname whose info you wish to request. 1160 * @param bn The buddy name whose info you wish to request.
1161 * @param infotype The type of info you wish to request. 1161 * @param infotype The type of info you wish to request.
1162 * 0x0001 - Info/profile 1162 * 0x0001 - Info/profile
1163 * 0x0003 - Away message 1163 * 0x0003 - Away message
1164 * 0x0004 - Capabilities 1164 * 0x0004 - Capabilities
1165 */ 1165 */
1166 int 1166 int
1167 aim_locate_getinfo(OscarData *od, const char *sn, guint16 infotype) 1167 aim_locate_getinfo(OscarData *od, const char *bn, guint16 infotype)
1168 { 1168 {
1169 FlapConnection *conn; 1169 FlapConnection *conn;
1170 ByteStream bs; 1170 ByteStream bs;
1171 aim_snacid_t snacid; 1171 aim_snacid_t snacid;
1172 1172
1173 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn) 1173 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !bn)
1174 return -EINVAL; 1174 return -EINVAL;
1175 1175
1176 byte_stream_new(&bs, 2+1+strlen(sn)); 1176 byte_stream_new(&bs, 2+1+strlen(bn));
1177 1177
1178 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, NULL, 0); 1178 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, NULL, 0);
1179 1179
1180 byte_stream_put16(&bs, infotype); 1180 byte_stream_put16(&bs, infotype);
1181 byte_stream_put8(&bs, strlen(sn)); 1181 byte_stream_put8(&bs, strlen(bn));
1182 byte_stream_putstr(&bs, sn); 1182 byte_stream_putstr(&bs, bn);
1183 1183
1184 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, snacid, &bs); 1184 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x0005, 0x0000, snacid, &bs);
1185 1185
1186 byte_stream_destroy(&bs); 1186 byte_stream_destroy(&bs);
1187 1187
1227 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES; 1227 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES;
1228 } 1228 }
1229 aim_tlvlist_free(tlvlist); 1229 aim_tlvlist_free(tlvlist);
1230 1230
1231 aim_locate_adduserinfo(od, userinfo); 1231 aim_locate_adduserinfo(od, userinfo);
1232 userinfo2 = aim_locate_finduserinfo(od, userinfo->sn); 1232 userinfo2 = aim_locate_finduserinfo(od, userinfo->bn);
1233 aim_info_free(userinfo); 1233 aim_info_free(userinfo);
1234 g_free(userinfo); 1234 g_free(userinfo);
1235 1235
1236 /* 1236 /*
1237 * Remove this screen name from our queue. If the client requested 1237 * Remove this buddy name from our queue. If the client requested
1238 * this buddy's info explicitly, then notify them that we have info 1238 * this buddy's info explicitly, then notify them that we have info
1239 * for this buddy. 1239 * for this buddy.
1240 */ 1240 */
1241 if (userinfo2 != NULL) 1241 if (userinfo2 != NULL)
1242 { 1242 {
1243 was_explicit = aim_locate_gotuserinfo(od, conn, userinfo2->sn); 1243 was_explicit = aim_locate_gotuserinfo(od, conn, userinfo2->bn);
1244 if (was_explicit == TRUE) 1244 if (was_explicit == TRUE)
1245 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) 1245 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype)))
1246 ret = userfunc(od, conn, frame, userinfo2); 1246 ret = userfunc(od, conn, frame, userinfo2);
1247 } 1247 }
1248 1248
1305 } 1305 }
1306 1306
1307 /* 1307 /*
1308 * Subtype 0x000b - Huh? What is this? 1308 * Subtype 0x000b - Huh? What is this?
1309 */ 1309 */
1310 int aim_locate_000b(OscarData *od, const char *sn) 1310 int aim_locate_000b(OscarData *od, const char *bn)
1311 { 1311 {
1312 FlapConnection *conn; 1312 FlapConnection *conn;
1313 ByteStream bs; 1313 ByteStream bs;
1314 aim_snacid_t snacid; 1314 aim_snacid_t snacid;
1315 1315
1316 return -EINVAL; 1316 return -EINVAL;
1317 1317
1318 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn) 1318 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !bn)
1319 return -EINVAL; 1319 return -EINVAL;
1320 1320
1321 byte_stream_new(&bs, 1+strlen(sn)); 1321 byte_stream_new(&bs, 1+strlen(bn));
1322 1322
1323 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x000b, 0x0000, NULL, 0); 1323 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x000b, 0x0000, NULL, 0);
1324 1324
1325 byte_stream_put8(&bs, strlen(sn)); 1325 byte_stream_put8(&bs, strlen(bn));
1326 byte_stream_putstr(&bs, sn); 1326 byte_stream_putstr(&bs, bn);
1327 1327
1328 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x000b, 0x0000, snacid, &bs); 1328 flap_connection_send_snac(od, conn, SNAC_FAMILY_LOCATE, 0x000b, 0x0000, snacid, &bs);
1329 1329
1330 byte_stream_destroy(&bs); 1330 byte_stream_destroy(&bs);
1331 1331
1378 1378
1379 /* 1379 /*
1380 * Subtype 0x0015 - Request the info of a user using the short method. This is 1380 * Subtype 0x0015 - Request the info of a user using the short method. This is
1381 * what iChat uses. It normally is VERY leniently rate limited. 1381 * what iChat uses. It normally is VERY leniently rate limited.
1382 * 1382 *
1383 * @param sn The screen name whose info you wish to request. 1383 * @param bn The buddy name whose info you wish to request.
1384 * @param flags The bitmask which specifies the type of info you wish to request. 1384 * @param flags The bitmask which specifies the type of info you wish to request.
1385 * 0x00000001 - Info/profile. 1385 * 0x00000001 - Info/profile.
1386 * 0x00000002 - Away message. 1386 * 0x00000002 - Away message.
1387 * 0x00000004 - Capabilities. 1387 * 0x00000004 - Capabilities.
1388 * 0x00000008 - Certification. 1388 * 0x00000008 - Certification.
1389 * @return Return 0 if no errors, otherwise return the error number. 1389 * @return Return 0 if no errors, otherwise return the error number.
1390 */ 1390 */
1391 int 1391 int
1392 aim_locate_getinfoshort(OscarData *od, const char *sn, guint32 flags) 1392 aim_locate_getinfoshort(OscarData *od, const char *bn, guint32 flags)
1393 { 1393 {
1394 FlapConnection *conn; 1394 FlapConnection *conn;
1395 ByteStream bs; 1395 ByteStream bs;
1396 aim_snacid_t snacid; 1396 aim_snacid_t snacid;
1397 1397
1398 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !sn) 1398 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE)) || !bn)
1399 return -EINVAL; 1399 return -EINVAL;
1400 1400
1401 byte_stream_new(&bs, 4 + 1 + strlen(sn)); 1401 byte_stream_new(&bs, 4 + 1 + strlen(bn));
1402 byte_stream_put32(&bs, flags); 1402 byte_stream_put32(&bs, flags);
1403 byte_stream_put8(&bs, strlen(sn)); 1403 byte_stream_put8(&bs, strlen(bn));
1404 byte_stream_putstr(&bs, sn); 1404 byte_stream_putstr(&bs, bn);
1405 1405
1406 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0015, 0x0000, sn, strlen(sn)+1); 1406 snacid = aim_cachesnac(od, SNAC_FAMILY_LOCATE, 0x0015, 0x0000, bn, strlen(bn)+1);
1407 flap_connection_send_snac_with_priority(od, conn, SNAC_FAMILY_LOCATE, 0x0015, 0x0000, snacid, &bs, FALSE); 1407 flap_connection_send_snac_with_priority(od, conn, SNAC_FAMILY_LOCATE, 0x0015, 0x0000, snacid, &bs, FALSE);
1408 1408
1409 byte_stream_destroy(&bs); 1409 byte_stream_destroy(&bs);
1410 1410
1411 return 0; 1411 return 0;