Mercurial > pidgin
comparison libpurple/protocols/oscar/family_locate.c @ 17369:f80f7e1047be
Cleanup and simplification of some tlvlist stuff in the oscar protocol.
No functionality change.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Tue, 29 May 2007 09:51:51 +0000 |
parents | 1927f4ead3ca |
children | 2f99cf09d912 |
comparison
equal
deleted
inserted
replaced
17368:b31f53796f3b | 17369:f80f7e1047be |
---|---|
928 * Inverse of aim_info_extract() | 928 * Inverse of aim_info_extract() |
929 */ | 929 */ |
930 int | 930 int |
931 aim_putuserinfo(ByteStream *bs, aim_userinfo_t *info) | 931 aim_putuserinfo(ByteStream *bs, aim_userinfo_t *info) |
932 { | 932 { |
933 aim_tlvlist_t *tlvlist = NULL; | 933 GSList *tlvlist = NULL; |
934 | 934 |
935 if (!bs || !info) | 935 if (!bs || !info) |
936 return -EINVAL; | 936 return -EINVAL; |
937 | 937 |
938 byte_stream_put8(bs, strlen(info->sn)); | 938 byte_stream_put8(bs, strlen(info->sn)); |
963 aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities); | 963 aim_tlvlist_add_caps(&tlvlist, 0x000d, info->capabilities); |
964 | 964 |
965 if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) | 965 if (info->present & AIM_USERINFO_PRESENT_SESSIONLEN) |
966 aim_tlvlist_add_32(&tlvlist, (guint16)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); | 966 aim_tlvlist_add_32(&tlvlist, (guint16)((info->flags & AIM_FLAG_AOL) ? 0x0010 : 0x000f), info->sessionlen); |
967 | 967 |
968 byte_stream_put16(bs, aim_tlvlist_count(&tlvlist)); | 968 byte_stream_put16(bs, aim_tlvlist_count(tlvlist)); |
969 aim_tlvlist_write(bs, &tlvlist); | 969 aim_tlvlist_write(bs, &tlvlist); |
970 aim_tlvlist_free(&tlvlist); | 970 aim_tlvlist_free(tlvlist); |
971 | 971 |
972 return 0; | 972 return 0; |
973 } | 973 } |
974 | 974 |
975 /* | 975 /* |
1048 * t(0004) - short - unknown (value = 2048) [ICQ only?] | 1048 * t(0004) - short - unknown (value = 2048) [ICQ only?] |
1049 */ | 1049 */ |
1050 static int | 1050 static int |
1051 rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | 1051 rights(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
1052 { | 1052 { |
1053 aim_tlvlist_t *tlvlist; | 1053 GSList *tlvlist; |
1054 aim_rxcallback_t userfunc; | 1054 aim_rxcallback_t userfunc; |
1055 int ret = 0; | 1055 int ret = 0; |
1056 guint16 maxsiglen = 0; | 1056 guint16 maxsiglen = 0; |
1057 | 1057 |
1058 tlvlist = aim_tlvlist_read(bs); | 1058 tlvlist = aim_tlvlist_read(bs); |
1061 maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1); | 1061 maxsiglen = aim_tlv_get16(tlvlist, 0x0001, 1); |
1062 | 1062 |
1063 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) | 1063 if ((userfunc = aim_callhandler(od, snac->family, snac->subtype))) |
1064 ret = userfunc(od, conn, frame, maxsiglen); | 1064 ret = userfunc(od, conn, frame, maxsiglen); |
1065 | 1065 |
1066 aim_tlvlist_free(&tlvlist); | 1066 aim_tlvlist_free(tlvlist); |
1067 | 1067 |
1068 return ret; | 1068 return ret; |
1069 } | 1069 } |
1070 | 1070 |
1071 /* | 1071 /* |
1094 const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len) | 1094 const char *awaymsg_encoding, const gchar *awaymsg, const int awaymsg_len) |
1095 { | 1095 { |
1096 FlapConnection *conn; | 1096 FlapConnection *conn; |
1097 FlapFrame *frame; | 1097 FlapFrame *frame; |
1098 aim_snacid_t snacid; | 1098 aim_snacid_t snacid; |
1099 aim_tlvlist_t *tl = NULL; | 1099 GSList *tlvlist = NULL; |
1100 char *encoding; | 1100 char *encoding; |
1101 static const char defencoding[] = {"text/aolrtf; charset=\"%s\""}; | 1101 static const char defencoding[] = {"text/aolrtf; charset=\"%s\""}; |
1102 | 1102 |
1103 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) | 1103 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) |
1104 return -EINVAL; | 1104 return -EINVAL; |
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 = g_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(&tlvlist, 0x0001, encoding); |
1119 aim_tlvlist_add_raw(&tl, 0x0002, profile_len, (const guchar *)profile); | 1119 aim_tlvlist_add_raw(&tlvlist, 0x0002, profile_len, (const guchar *)profile); |
1120 g_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: |
1130 */ | 1130 */ |
1131 if (awaymsg) { | 1131 if (awaymsg) { |
1132 if (awaymsg_len) { | 1132 if (awaymsg_len) { |
1133 encoding = g_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(&tlvlist, 0x0003, encoding); |
1136 aim_tlvlist_add_raw(&tl, 0x0004, awaymsg_len, (const guchar *)awaymsg); | 1136 aim_tlvlist_add_raw(&tlvlist, 0x0004, awaymsg_len, (const guchar *)awaymsg); |
1137 g_free(encoding); | 1137 g_free(encoding); |
1138 } else | 1138 } else |
1139 aim_tlvlist_add_noval(&tl, 0x0004); | 1139 aim_tlvlist_add_noval(&tlvlist, 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(tlvlist)); |
1143 | 1143 |
1144 snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0); | 1144 snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0); |
1145 aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid); | 1145 aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid); |
1146 | 1146 |
1147 aim_tlvlist_write(&frame->data, &tl); | 1147 aim_tlvlist_write(&frame->data, &tlvlist); |
1148 aim_tlvlist_free(&tl); | 1148 aim_tlvlist_free(tlvlist); |
1149 | 1149 |
1150 flap_connection_send(conn, frame); | 1150 flap_connection_send(conn, frame); |
1151 | 1151 |
1152 return 0; | 1152 return 0; |
1153 } | 1153 } |
1159 aim_locate_setcaps(OscarData *od, guint32 caps) | 1159 aim_locate_setcaps(OscarData *od, guint32 caps) |
1160 { | 1160 { |
1161 FlapConnection *conn; | 1161 FlapConnection *conn; |
1162 FlapFrame *frame; | 1162 FlapFrame *frame; |
1163 aim_snacid_t snacid; | 1163 aim_snacid_t snacid; |
1164 aim_tlvlist_t *tl = NULL; | 1164 GSList *tlvlist = NULL; |
1165 | 1165 |
1166 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) | 1166 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) |
1167 return -EINVAL; | 1167 return -EINVAL; |
1168 | 1168 |
1169 aim_tlvlist_add_caps(&tl, 0x0005, caps); | 1169 aim_tlvlist_add_caps(&tlvlist, 0x0005, caps); |
1170 | 1170 |
1171 frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(&tl)); | 1171 frame = flap_frame_new(od, 0x02, 10 + aim_tlvlist_size(tlvlist)); |
1172 | 1172 |
1173 snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0); | 1173 snacid = aim_cachesnac(od, 0x0002, 0x0004, 0x0000, NULL, 0); |
1174 aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid); | 1174 aim_putsnac(&frame->data, 0x0002, 0x004, 0x0000, snacid); |
1175 | 1175 |
1176 aim_tlvlist_write(&frame->data, &tl); | 1176 aim_tlvlist_write(&frame->data, &tlvlist); |
1177 aim_tlvlist_free(&tl); | 1177 aim_tlvlist_free(tlvlist); |
1178 | 1178 |
1179 flap_connection_send(conn, frame); | 1179 flap_connection_send(conn, frame); |
1180 | 1180 |
1181 return 0; | 1181 return 0; |
1182 } | 1182 } |
1219 userinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) | 1219 userinfo(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
1220 { | 1220 { |
1221 int ret = 0; | 1221 int ret = 0; |
1222 aim_rxcallback_t userfunc; | 1222 aim_rxcallback_t userfunc; |
1223 aim_userinfo_t *userinfo, *userinfo2; | 1223 aim_userinfo_t *userinfo, *userinfo2; |
1224 aim_tlvlist_t *tlvlist; | 1224 GSList *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 *)g_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); |
1250 ByteStream cbs; | 1250 ByteStream cbs; |
1251 byte_stream_init(&cbs, tlv->value, tlv->length); | 1251 byte_stream_init(&cbs, tlv->value, tlv->length); |
1252 userinfo->capabilities = aim_locate_getcaps(od, &cbs, tlv->length); | 1252 userinfo->capabilities = aim_locate_getcaps(od, &cbs, tlv->length); |
1253 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES; | 1253 userinfo->present = AIM_USERINFO_PRESENT_CAPABILITIES; |
1254 } | 1254 } |
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 g_free(userinfo); | 1260 g_free(userinfo); |
1282 int aim_locate_setdirinfo(OscarData *od, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy) | 1282 int aim_locate_setdirinfo(OscarData *od, const char *first, const char *middle, const char *last, const char *maiden, const char *nickname, const char *street, const char *city, const char *state, const char *zip, int country, guint16 privacy) |
1283 { | 1283 { |
1284 FlapConnection *conn; | 1284 FlapConnection *conn; |
1285 FlapFrame *frame; | 1285 FlapFrame *frame; |
1286 aim_snacid_t snacid; | 1286 aim_snacid_t snacid; |
1287 aim_tlvlist_t *tl = NULL; | 1287 GSList *tlvlist = NULL; |
1288 | 1288 |
1289 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) | 1289 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) |
1290 return -EINVAL; | 1290 return -EINVAL; |
1291 | 1291 |
1292 aim_tlvlist_add_16(&tl, 0x000a, privacy); | 1292 aim_tlvlist_add_16(&tlvlist, 0x000a, privacy); |
1293 | 1293 |
1294 if (first) | 1294 if (first) |
1295 aim_tlvlist_add_str(&tl, 0x0001, first); | 1295 aim_tlvlist_add_str(&tlvlist, 0x0001, first); |
1296 if (last) | 1296 if (last) |
1297 aim_tlvlist_add_str(&tl, 0x0002, last); | 1297 aim_tlvlist_add_str(&tlvlist, 0x0002, last); |
1298 if (middle) | 1298 if (middle) |
1299 aim_tlvlist_add_str(&tl, 0x0003, middle); | 1299 aim_tlvlist_add_str(&tlvlist, 0x0003, middle); |
1300 if (maiden) | 1300 if (maiden) |
1301 aim_tlvlist_add_str(&tl, 0x0004, maiden); | 1301 aim_tlvlist_add_str(&tlvlist, 0x0004, maiden); |
1302 | 1302 |
1303 if (state) | 1303 if (state) |
1304 aim_tlvlist_add_str(&tl, 0x0007, state); | 1304 aim_tlvlist_add_str(&tlvlist, 0x0007, state); |
1305 if (city) | 1305 if (city) |
1306 aim_tlvlist_add_str(&tl, 0x0008, city); | 1306 aim_tlvlist_add_str(&tlvlist, 0x0008, city); |
1307 | 1307 |
1308 if (nickname) | 1308 if (nickname) |
1309 aim_tlvlist_add_str(&tl, 0x000c, nickname); | 1309 aim_tlvlist_add_str(&tlvlist, 0x000c, nickname); |
1310 if (zip) | 1310 if (zip) |
1311 aim_tlvlist_add_str(&tl, 0x000d, zip); | 1311 aim_tlvlist_add_str(&tlvlist, 0x000d, zip); |
1312 | 1312 |
1313 if (street) | 1313 if (street) |
1314 aim_tlvlist_add_str(&tl, 0x0021, street); | 1314 aim_tlvlist_add_str(&tlvlist, 0x0021, street); |
1315 | 1315 |
1316 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(&tl)); | 1316 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(tlvlist)); |
1317 | 1317 |
1318 snacid = aim_cachesnac(od, 0x0002, 0x0009, 0x0000, NULL, 0); | 1318 snacid = aim_cachesnac(od, 0x0002, 0x0009, 0x0000, NULL, 0); |
1319 | 1319 |
1320 aim_putsnac(&frame->data, 0x0002, 0x0009, 0x0000, snacid); | 1320 aim_putsnac(&frame->data, 0x0002, 0x0009, 0x0000, snacid); |
1321 aim_tlvlist_write(&frame->data, &tl); | 1321 aim_tlvlist_write(&frame->data, &tlvlist); |
1322 aim_tlvlist_free(&tl); | 1322 aim_tlvlist_free(tlvlist); |
1323 | 1323 |
1324 flap_connection_send(conn, frame); | 1324 flap_connection_send(conn, frame); |
1325 | 1325 |
1326 return 0; | 1326 return 0; |
1327 } | 1327 } |
1363 aim_locate_setinterests(OscarData *od, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy) | 1363 aim_locate_setinterests(OscarData *od, const char *interest1, const char *interest2, const char *interest3, const char *interest4, const char *interest5, guint16 privacy) |
1364 { | 1364 { |
1365 FlapConnection *conn; | 1365 FlapConnection *conn; |
1366 FlapFrame *frame; | 1366 FlapFrame *frame; |
1367 aim_snacid_t snacid; | 1367 aim_snacid_t snacid; |
1368 aim_tlvlist_t *tl = NULL; | 1368 GSList *tlvlist = NULL; |
1369 | 1369 |
1370 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) | 1370 if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_LOCATE))) |
1371 return -EINVAL; | 1371 return -EINVAL; |
1372 | 1372 |
1373 /* ?? privacy ?? */ | 1373 /* ?? privacy ?? */ |
1374 aim_tlvlist_add_16(&tl, 0x000a, privacy); | 1374 aim_tlvlist_add_16(&tlvlist, 0x000a, privacy); |
1375 | 1375 |
1376 if (interest1) | 1376 if (interest1) |
1377 aim_tlvlist_add_str(&tl, 0x0000b, interest1); | 1377 aim_tlvlist_add_str(&tlvlist, 0x0000b, interest1); |
1378 if (interest2) | 1378 if (interest2) |
1379 aim_tlvlist_add_str(&tl, 0x0000b, interest2); | 1379 aim_tlvlist_add_str(&tlvlist, 0x0000b, interest2); |
1380 if (interest3) | 1380 if (interest3) |
1381 aim_tlvlist_add_str(&tl, 0x0000b, interest3); | 1381 aim_tlvlist_add_str(&tlvlist, 0x0000b, interest3); |
1382 if (interest4) | 1382 if (interest4) |
1383 aim_tlvlist_add_str(&tl, 0x0000b, interest4); | 1383 aim_tlvlist_add_str(&tlvlist, 0x0000b, interest4); |
1384 if (interest5) | 1384 if (interest5) |
1385 aim_tlvlist_add_str(&tl, 0x0000b, interest5); | 1385 aim_tlvlist_add_str(&tlvlist, 0x0000b, interest5); |
1386 | 1386 |
1387 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(&tl)); | 1387 frame = flap_frame_new(od, 0x02, 10+aim_tlvlist_size(tlvlist)); |
1388 | 1388 |
1389 snacid = aim_cachesnac(od, 0x0002, 0x000f, 0x0000, NULL, 0); | 1389 snacid = aim_cachesnac(od, 0x0002, 0x000f, 0x0000, NULL, 0); |
1390 | 1390 |
1391 aim_putsnac(&frame->data, 0x0002, 0x000f, 0x0000, 0); | 1391 aim_putsnac(&frame->data, 0x0002, 0x000f, 0x0000, 0); |
1392 aim_tlvlist_write(&frame->data, &tl); | 1392 aim_tlvlist_write(&frame->data, &tlvlist); |
1393 aim_tlvlist_free(&tl); | 1393 aim_tlvlist_free(tlvlist); |
1394 | 1394 |
1395 flap_connection_send(conn, frame); | 1395 flap_connection_send(conn, frame); |
1396 | 1396 |
1397 return 0; | 1397 return 0; |
1398 } | 1398 } |