Mercurial > pidgin
comparison libpurple/protocols/jabber/caps.c @ 30256:067ad74c7523
jabber: Minor cleanup (formatting + strcmp->g_str_equal) of caps
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Sat, 10 Jul 2010 00:35:52 +0000 |
parents | 502b9d2f2d7a |
children | 7fb775b4465b |
comparison
equal
deleted
inserted
replaced
30255:502b9d2f2d7a | 30256:067ad74c7523 |
---|---|
43 | 43 |
44 /* Free a GList of allocated char* */ | 44 /* Free a GList of allocated char* */ |
45 static void | 45 static void |
46 free_string_glist(GList *list) | 46 free_string_glist(GList *list) |
47 { | 47 { |
48 g_list_foreach(list, (GFunc)g_free, NULL); | 48 while (list) { |
49 g_list_free(list); | 49 g_free(list->data); |
50 list = g_list_delete_link(list, list); | |
51 } | |
50 } | 52 } |
51 | 53 |
52 static JabberCapsNodeExts* | 54 static JabberCapsNodeExts* |
53 jabber_caps_node_exts_ref(JabberCapsNodeExts *exts) | 55 jabber_caps_node_exts_ref(JabberCapsNodeExts *exts) |
54 { | 56 { |
228 xmlnode *client; | 230 xmlnode *client; |
229 | 231 |
230 if(!capsdata) | 232 if(!capsdata) |
231 return; | 233 return; |
232 | 234 |
233 if (strcmp(capsdata->name, "capabilities") != 0) { | 235 if (!g_str_equal(capsdata->name, "capabilities")) { |
234 xmlnode_free(capsdata); | 236 xmlnode_free(capsdata); |
235 return; | 237 return; |
236 } | 238 } |
237 | 239 |
238 for(client = capsdata->child; client; client = client->next) { | 240 for (client = capsdata->child; client; client = client->next) { |
239 if(client->type != XMLNODE_TYPE_TAG) | 241 if (client->type != XMLNODE_TYPE_TAG) |
240 continue; | 242 continue; |
241 if(!strcmp(client->name, "client")) { | 243 if (g_str_equal(client->name, "client")) { |
242 JabberCapsClientInfo *value = g_new0(JabberCapsClientInfo, 1); | 244 JabberCapsClientInfo *value = g_new0(JabberCapsClientInfo, 1); |
243 JabberCapsTuple *key = (JabberCapsTuple*)&value->tuple; | 245 JabberCapsTuple *key = (JabberCapsTuple*)&value->tuple; |
244 xmlnode *child; | 246 xmlnode *child; |
245 JabberCapsNodeExts *exts = NULL; | 247 JabberCapsNodeExts *exts = NULL; |
246 key->node = g_strdup(xmlnode_get_attrib(client,"node")); | 248 key->node = g_strdup(xmlnode_get_attrib(client,"node")); |
249 | 251 |
250 /* v1.3 capabilities */ | 252 /* v1.3 capabilities */ |
251 if (key->hash == NULL) | 253 if (key->hash == NULL) |
252 exts = jabber_caps_find_exts_by_node(key->node); | 254 exts = jabber_caps_find_exts_by_node(key->node); |
253 | 255 |
254 for(child = client->child; child; child = child->next) { | 256 for (child = client->child; child; child = child->next) { |
255 if(child->type != XMLNODE_TYPE_TAG) | 257 if (child->type != XMLNODE_TYPE_TAG) |
256 continue; | 258 continue; |
257 if(!strcmp(child->name,"feature")) { | 259 if (g_str_equal(child->name, "feature")) { |
258 const char *var = xmlnode_get_attrib(child, "var"); | 260 const char *var = xmlnode_get_attrib(child, "var"); |
259 if(!var) | 261 if(!var) |
260 continue; | 262 continue; |
261 value->features = g_list_append(value->features,g_strdup(var)); | 263 value->features = g_list_append(value->features,g_strdup(var)); |
262 } else if(!strcmp(child->name,"identity")) { | 264 } else if (g_str_equal(child->name, "identity")) { |
263 const char *category = xmlnode_get_attrib(child, "category"); | 265 const char *category = xmlnode_get_attrib(child, "category"); |
264 const char *type = xmlnode_get_attrib(child, "type"); | 266 const char *type = xmlnode_get_attrib(child, "type"); |
265 const char *name = xmlnode_get_attrib(child, "name"); | 267 const char *name = xmlnode_get_attrib(child, "name"); |
266 const char *lang = xmlnode_get_attrib(child, "lang"); | 268 const char *lang = xmlnode_get_attrib(child, "lang"); |
267 JabberIdentity *id; | 269 JabberIdentity *id; |
274 id->type = g_strdup(type); | 276 id->type = g_strdup(type); |
275 id->name = g_strdup(name); | 277 id->name = g_strdup(name); |
276 id->lang = g_strdup(lang); | 278 id->lang = g_strdup(lang); |
277 | 279 |
278 value->identities = g_list_append(value->identities,id); | 280 value->identities = g_list_append(value->identities,id); |
279 } else if(!strcmp(child->name,"x")) { | 281 } else if (g_str_equal(child->name, "x")) { |
280 /* TODO: See #7814 -- this might cause problems if anyone | 282 /* TODO: See #7814 -- this might cause problems if anyone |
281 * ever actually specifies forms. In fact, for this to | 283 * ever actually specifies forms. In fact, for this to |
282 * work properly, that bug needs to be fixed in | 284 * work properly, that bug needs to be fixed in |
283 * xmlnode_from_str, not the output version... */ | 285 * xmlnode_from_str, not the output version... */ |
284 value->forms = g_list_append(value->forms, xmlnode_copy(child)); | 286 value->forms = g_list_append(value->forms, xmlnode_copy(child)); |
285 } else if (!strcmp(child->name, "ext") && key->hash != NULL) { | 287 } else if (g_str_equal(child->name, "ext") && key->hash != NULL) { |
286 purple_debug_warning("jabber", "Ignoring exts when reading new-style caps\n"); | 288 purple_debug_warning("jabber", "Ignoring exts when reading new-style caps\n"); |
287 } else if (!strcmp(child->name, "ext")) { | 289 } else if (g_str_equal(child->name, "ext")) { |
288 /* TODO: Do we care about reading in the identities listed here? */ | 290 /* TODO: Do we care about reading in the identities listed here? */ |
289 const char *identifier = xmlnode_get_attrib(child, "identifier"); | 291 const char *identifier = xmlnode_get_attrib(child, "identifier"); |
290 xmlnode *node; | 292 xmlnode *node; |
291 GList *features = NULL; | 293 GList *features = NULL; |
292 | 294 |
294 continue; | 296 continue; |
295 | 297 |
296 for (node = child->child; node; node = node->next) { | 298 for (node = child->child; node; node = node->next) { |
297 if (node->type != XMLNODE_TYPE_TAG) | 299 if (node->type != XMLNODE_TYPE_TAG) |
298 continue; | 300 continue; |
299 if (!strcmp(node->name, "feature")) { | 301 if (g_str_equal(node->name, "feature")) { |
300 const char *var = xmlnode_get_attrib(node, "var"); | 302 const char *var = xmlnode_get_attrib(node, "var"); |
301 if (!var) | 303 if (!var) |
302 continue; | 304 continue; |
303 features = g_list_prepend(features, g_strdup(var)); | 305 features = g_list_prepend(features, g_strdup(var)); |
304 } | 306 } |
453 /* | 455 /* |
454 * TODO: If you add *any* hash here, make sure the checksum buffer | 456 * TODO: If you add *any* hash here, make sure the checksum buffer |
455 * size in jabber_caps_calculate_hash is large enough. The cipher API | 457 * size in jabber_caps_calculate_hash is large enough. The cipher API |
456 * doesn't seem to offer a "Get the hash size" function(?). | 458 * doesn't seem to offer a "Get the hash size" function(?). |
457 */ | 459 */ |
458 if (!strcmp(userdata->hash, "sha-1")) { | 460 if (g_str_equal(userdata->hash, "sha-1")) { |
459 hash = jabber_caps_calculate_hash(info, "sha1"); | 461 hash = jabber_caps_calculate_hash(info, "sha1"); |
460 } else if (!strcmp(userdata->hash, "md5")) { | 462 } else if (g_str_equal(userdata->hash, "md5")) { |
461 hash = jabber_caps_calculate_hash(info, "md5"); | 463 hash = jabber_caps_calculate_hash(info, "md5"); |
462 } | 464 } |
463 | 465 |
464 if (!hash || strcmp(hash, userdata->ver)) { | 466 if (!hash || !g_str_equal(hash, userdata->ver)) { |
465 purple_debug_warning("jabber", "Could not validate caps info from " | 467 purple_debug_warning("jabber", "Could not validate caps info from " |
466 "%s. Expected %s, got %s\n", | 468 "%s. Expected %s, got %s\n", |
467 xmlnode_get_attrib(packet, "from"), | 469 xmlnode_get_attrib(packet, "from"), |
468 userdata->ver, hash ? hash : "(null)"); | 470 userdata->ver, hash ? hash : "(null)"); |
469 | 471 |
768 info = g_new0(JabberCapsClientInfo, 1); | 770 info = g_new0(JabberCapsClientInfo, 1); |
769 | 771 |
770 for(child = query->child; child; child = child->next) { | 772 for(child = query->child; child; child = child->next) { |
771 if (child->type != XMLNODE_TYPE_TAG) | 773 if (child->type != XMLNODE_TYPE_TAG) |
772 continue; | 774 continue; |
773 if (!strcmp(child->name,"identity")) { | 775 if (g_str_equal(child->name, "identity")) { |
774 /* parse identity */ | 776 /* parse identity */ |
775 const char *category = xmlnode_get_attrib(child, "category"); | 777 const char *category = xmlnode_get_attrib(child, "category"); |
776 const char *type = xmlnode_get_attrib(child, "type"); | 778 const char *type = xmlnode_get_attrib(child, "type"); |
777 const char *name = xmlnode_get_attrib(child, "name"); | 779 const char *name = xmlnode_get_attrib(child, "name"); |
778 const char *lang = xmlnode_get_attrib(child, "lang"); | 780 const char *lang = xmlnode_get_attrib(child, "lang"); |
786 id->type = g_strdup(type); | 788 id->type = g_strdup(type); |
787 id->name = g_strdup(name); | 789 id->name = g_strdup(name); |
788 id->lang = g_strdup(lang); | 790 id->lang = g_strdup(lang); |
789 | 791 |
790 info->identities = g_list_append(info->identities, id); | 792 info->identities = g_list_append(info->identities, id); |
791 } else if (!strcmp(child->name, "feature")) { | 793 } else if (g_str_equal(child->name, "feature")) { |
792 /* parse feature */ | 794 /* parse feature */ |
793 const char *var = xmlnode_get_attrib(child, "var"); | 795 const char *var = xmlnode_get_attrib(child, "var"); |
794 if (var) | 796 if (var) |
795 info->features = g_list_prepend(info->features, g_strdup(var)); | 797 info->features = g_list_prepend(info->features, g_strdup(var)); |
796 } else if (!strcmp(child->name, "x")) { | 798 } else if (g_str_equal(child->name, "x")) { |
797 if (child->xmlns && !strcmp(child->xmlns, "jabber:x:data")) { | 799 if (purple_strequal(child->xmlns, "jabber:x:data")) { |
798 /* x-data form */ | 800 /* x-data form */ |
799 xmlnode *dataform = xmlnode_copy(child); | 801 xmlnode *dataform = xmlnode_copy(child); |
800 info->forms = g_list_append(info->forms, dataform); | 802 info->forms = g_list_append(info->forms, dataform); |
801 } | 803 } |
802 } | 804 } |
983 GList *node, *accounts = purple_accounts_get_all_active(); | 985 GList *node, *accounts = purple_accounts_get_all_active(); |
984 | 986 |
985 for (node = accounts; node; node = node->next) { | 987 for (node = accounts; node; node = node->next) { |
986 PurpleAccount *account = node->data; | 988 PurpleAccount *account = node->data; |
987 const char *prpl_id = purple_account_get_protocol_id(account); | 989 const char *prpl_id = purple_account_get_protocol_id(account); |
988 if (!strcmp("prpl-jabber", prpl_id) && purple_account_is_connected(account)) { | 990 if (g_str_equal("prpl-jabber", prpl_id) && purple_account_is_connected(account)) { |
989 PurpleConnection *gc = purple_account_get_connection(account); | 991 PurpleConnection *gc = purple_account_get_connection(account); |
990 jabber_presence_send(gc->proto_data, TRUE); | 992 jabber_presence_send(gc->proto_data, TRUE); |
991 } | 993 } |
992 } | 994 } |
993 | 995 |