comparison libpurple/protocols/jabber/caps.c @ 25741:1225f3dcf5ab

Fix compilation errors and many warnings
author Paul Aurich <paul@darkrain42.org>
date Thu, 20 Nov 2008 23:58:17 +0000
parents 9ab681f23007
children 4040da08a733
comparison
equal deleted inserted replaced
25740:9ab681f23007 25741:1225f3dcf5ab
23 23
24 #include <glib.h> 24 #include <glib.h>
25 #include "caps.h" 25 #include "caps.h"
26 #include "cipher.h" 26 #include "cipher.h"
27 #include <string.h> 27 #include <string.h>
28 #include "internal.h" 28 #include "iq.h"
29 #include "presence.h"
29 #include "util.h" 30 #include "util.h"
30 #include "iq.h"
31 31
32 #define JABBER_CAPS_FILENAME "xmpp-caps.xml" 32 #define JABBER_CAPS_FILENAME "xmpp-caps.xml"
33 33
34 GHashTable *capstable = NULL; /* JabberCapsKey -> JabberCapsValue */ 34 GHashTable *capstable = NULL; /* JabberCapsKey -> JabberCapsValue */
35 static gchar *caps_hash = NULL; 35 static gchar *caps_hash = NULL;
88 } 88 }
89 //g_hash_table_destroy(valuestruct->ext); 89 //g_hash_table_destroy(valuestruct->ext);
90 g_free(valuestruct); 90 g_free(valuestruct);
91 } 91 }
92 92
93 #if 0
93 static void jabber_caps_ext_destroy_value(gpointer value) { 94 static void jabber_caps_ext_destroy_value(gpointer value) {
94 JabberCapsValueExt *valuestruct = value; 95 JabberCapsValueExt *valuestruct = value;
95 while(valuestruct->identities) { 96 while(valuestruct->identities) {
96 JabberCapsIdentity *id = valuestruct->identities->data; 97 JabberCapsIdentity *id = valuestruct->identities->data;
97 g_free(id->category); 98 g_free(id->category);
105 g_free(valuestruct->features->data); 106 g_free(valuestruct->features->data);
106 valuestruct->features = g_list_delete_link(valuestruct->features,valuestruct->features); 107 valuestruct->features = g_list_delete_link(valuestruct->features,valuestruct->features);
107 } 108 }
108 g_free(valuestruct); 109 g_free(valuestruct);
109 } 110 }
111 #endif
110 112
111 static void jabber_caps_load(void); 113 static void jabber_caps_load(void);
112 114
113 void jabber_caps_init(void) { 115 void jabber_caps_init(void) {
114 capstable = g_hash_table_new_full(jabber_caps_hash, jabber_caps_compare, jabber_caps_destroy_key, jabber_caps_destroy_value); 116 capstable = g_hash_table_new_full(jabber_caps_hash, jabber_caps_compare, jabber_caps_destroy_key, jabber_caps_destroy_value);
115 jabber_caps_load(); 117 jabber_caps_load();
116 jabber_caps_calculate_own_hash();
117 } 118 }
118 119
119 static void jabber_caps_load(void) { 120 static void jabber_caps_load(void) {
120 xmlnode *capsdata = purple_util_read_xml_from_file(JABBER_CAPS_FILENAME, "XMPP capabilities cache"); 121 xmlnode *capsdata = purple_util_read_xml_from_file(JABBER_CAPS_FILENAME, "XMPP capabilities cache");
121 xmlnode *client; 122 xmlnode *client;
234 xmlnode_free(root); 235 xmlnode_free(root);
235 purple_util_write_data_to_file(JABBER_CAPS_FILENAME, str, length); 236 purple_util_write_data_to_file(JABBER_CAPS_FILENAME, str, length);
236 g_free(str); 237 g_free(str);
237 } 238 }
238 239
240 #if 0
239 /* this function assumes that all information is available locally */ 241 /* this function assumes that all information is available locally */
240 static JabberCapsClientInfo *jabber_caps_collect_info(const char *node, const char *ver, GList *ext) { 242 static JabberCapsClientInfo *jabber_caps_collect_info(const char *node, const char *ver, GList *ext) {
241 JabberCapsClientInfo *result; 243 JabberCapsClientInfo *result;
242 JabberCapsKey *key = g_new0(JabberCapsKey, 1); 244 JabberCapsKey *key = g_new0(JabberCapsKey, 1);
243 JabberCapsValue *caps; 245 JabberCapsValue *caps;
296 } 298 }
297 } 299 }
298 #endif 300 #endif
299 return result; 301 return result;
300 } 302 }
303 #endif
301 304
302 void jabber_caps_free_clientinfo(JabberCapsClientInfo *clientinfo) { 305 void jabber_caps_free_clientinfo(JabberCapsClientInfo *clientinfo) {
303 if(!clientinfo) 306 if(!clientinfo)
304 return; 307 return;
305 while(clientinfo->identities) { 308 while(clientinfo->identities) {
413 g_free(extuserdata->node); 416 g_free(extuserdata->node);
414 g_free(extuserdata); 417 g_free(extuserdata);
415 jabber_caps_get_info_check_completion(userdata); 418 jabber_caps_get_info_check_completion(userdata);
416 } 419 }
417 #endif 420 #endif
421
418 static void jabber_caps_client_iqcb(JabberStream *js, xmlnode *packet, gpointer data) { 422 static void jabber_caps_client_iqcb(JabberStream *js, xmlnode *packet, gpointer data) {
419 /* collect data and fetch all exts */ 423 /* collect data and fetch all exts */
420 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query", 424 xmlnode *query = xmlnode_get_child_with_namespace(packet, "query",
421 "http://jabber.org/protocol/disco#info"); 425 "http://jabber.org/protocol/disco#info");
422 jabber_caps_cbplususerdata *userdata = data; 426 jabber_caps_cbplususerdata *userdata = data;
425 if (!strcmp(xmlnode_get_attrib(packet, "type"), "error"))return; 429 if (!strcmp(xmlnode_get_attrib(packet, "type"), "error"))return;
426 if (query) { 430 if (query) {
427 // check hash 431 // check hash
428 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); 432 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query);
429 gchar *hash = 0; 433 gchar *hash = 0;
434 JabberCapsValue *value;
435 JabberCapsKey *key;
436 xmlnode *child;
437
430 if (!strcmp(userdata->hash, "sha-1")) { 438 if (!strcmp(userdata->hash, "sha-1")) {
431 hash = jabber_caps_calcualte_hash(info, "sha1"); 439 hash = jabber_caps_calculate_hash(info, "sha1");
432 } else if (!strcmp(userdata->hash, "md5")) { 440 } else if (!strcmp(userdata->hash, "md5")) {
433 hash = jabber_caps_calcualte_hash(info, "md5"); 441 hash = jabber_caps_calculate_hash(info, "md5");
434 } else { 442 } else {
435 // clean up 443 // clean up
436 return; 444 return;
437 } 445 }
438 446
449 return; 457 return;
450 } 458 }
451 459
452 g_free(hash); 460 g_free(hash);
453 461
454 JabberCapsValue *value = g_new0(JabberCapsValue, 1); 462 value = g_new0(JabberCapsValue, 1);
455 JabberCapsKey *key = g_new0(JabberCapsKey, 1); 463 key = g_new0(JabberCapsKey, 1);
456 xmlnode *child; 464
457 GList *iter;
458 #if 0 465 #if 0
459 value->ext = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, jabber_caps_ext_destroy_value); 466 value->ext = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, jabber_caps_ext_destroy_value);
460 #endif 467 #endif
461 key->node = g_strdup(userdata->node); 468 key->node = g_strdup(userdata->node);
462 key->ver = g_strdup(userdata->ver); 469 key->ver = g_strdup(userdata->ver);
521 /* Don't wait for the ext discoveries; they aren't going to happen */ 528 /* Don't wait for the ext discoveries; they aren't going to happen */
522 userdata->extOutstanding = 0; 529 userdata->extOutstanding = 0;
523 530
524 jabber_caps_get_info_check_completion(userdata); 531 jabber_caps_get_info_check_completion(userdata);
525 #endif 532 #endif
533 }
526 } 534 }
527 535
528 void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *hash, jabber_caps_get_info_cb cb, gpointer user_data) { 536 void jabber_caps_get_info(JabberStream *js, const char *who, const char *node, const char *ver, const char *hash, jabber_caps_get_info_cb cb, gpointer user_data) {
529 JabberCapsValue *client; 537 JabberCapsValue *client;
530 JabberCapsKey *key = g_new0(JabberCapsKey, 1); 538 JabberCapsKey *key = g_new0(JabberCapsKey, 1);
610 } else { 618 } else {
611 return cat_cmp; 619 return cat_cmp;
612 } 620 }
613 } 621 }
614 622
623 #if 0
615 static gint jabber_caps_jabber_feature_compare(gconstpointer a, gconstpointer b) { 624 static gint jabber_caps_jabber_feature_compare(gconstpointer a, gconstpointer b) {
616 const JabberFeature *ac; 625 const JabberFeature *ac;
617 const JabberFeature *bc; 626 const JabberFeature *bc;
618 627
619 ac = a; 628 ac = a;
620 bc = b; 629 bc = b;
621 630
622 return strcmp(ac->namespace, bc->namespace); 631 return strcmp(ac->namespace, bc->namespace);
623 } 632 }
633 #endif
624 634
625 static gint jabber_caps_string_compare(gconstpointer a, gconstpointer b) { 635 static gint jabber_caps_string_compare(gconstpointer a, gconstpointer b) {
626 const gchar *ac; 636 const gchar *ac;
627 const gchar *bc; 637 const gchar *bc;
628 638
630 bc = b; 640 bc = b;
631 641
632 return strcmp(ac, bc); 642 return strcmp(ac, bc);
633 } 643 }
634 644
635 gchar *jabber_caps_get_formtype(const xmlnode *x) { 645 static gchar *jabber_caps_get_formtype(const xmlnode *x) {
636 xmlnode *formtypefield; 646 xmlnode *formtypefield;
637 formtypefield = xmlnode_get_child(x, "field"); 647 formtypefield = xmlnode_get_child(x, "field");
638 while (formtypefield && strcmp(xmlnode_get_attrib(formtypefield, "var"), "FORM_TYPE")) formtypefield = xmlnode_get_next_twin(formtypefield); 648 while (formtypefield && strcmp(xmlnode_get_attrib(formtypefield, "var"), "FORM_TYPE")) formtypefield = xmlnode_get_next_twin(formtypefield);
639 formtypefield = xmlnode_get_child(formtypefield, "value"); 649 formtypefield = xmlnode_get_child(formtypefield, "value");
640 return xmlnode_get_data(formtypefield);; 650 return xmlnode_get_data(formtypefield);;
656 return result; 666 return result;
657 } 667 }
658 668
659 JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) { 669 JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) {
660 xmlnode *child; 670 xmlnode *child;
661 671 JabberCapsClientInfo *info;
672
662 if (!query) return 0; 673 if (!query) return 0;
663 if (strcmp(query->xmlns,"http://jabber.org/protocol/disco#info")) return 0; 674 if (strcmp(query->xmlns,"http://jabber.org/protocol/disco#info")) return 0;
664 675
665 JabberCapsClientInfo *info = g_new0(JabberCapsClientInfo, 1); 676 info = g_new0(JabberCapsClientInfo, 1);
666 677
667 for(child = query->child; child; child = child->next) { 678 for(child = query->child; child; child = child->next) {
668 if (!strcmp(child->name,"identity")) { 679 if (!strcmp(child->name,"identity")) {
669 /* parse identity */ 680 /* parse identity */
670 const char *category = xmlnode_get_attrib(child, "category"); 681 const char *category = xmlnode_get_attrib(child, "category");
702 bc = b; 713 bc = b;
703 714
704 return strcmp(ac->var, bc->var); 715 return strcmp(ac->var, bc->var);
705 } 716 }
706 717
707 GList *jabber_caps_xdata_get_fields(const xmlnode *x) { 718 static GList *jabber_caps_xdata_get_fields(const xmlnode *x) {
708 GList *fields = 0; 719 GList *fields = 0;
709 xmlnode *field; 720 xmlnode *field;
710 xmlnode *value; 721 xmlnode *value;
711 JabberDataFormField *xdatafield; 722 JabberDataFormField *xdatafield;
712 723
724 } 735 }
725 fields = g_list_sort(fields, jabber_caps_xdata_field_compare); 736 fields = g_list_sort(fields, jabber_caps_xdata_field_compare);
726 return fields; 737 return fields;
727 } 738 }
728 739
729 gchar *jabber_caps_verification_append(gchar *verification_string, gchar *string) { 740 static gchar *jabber_caps_verification_append(gchar *verification_string, gchar *string) {
730 gchar *verification; 741 gchar *verification;
731 verification = g_strconcat(verification_string, string, "<", NULL); 742 verification = g_strconcat(verification_string, string, "<", NULL);
732 g_free(verification_string); 743 g_free(verification_string);
733 return verification; 744 return verification;
734 } 745 }
735 746
736 gchar *jabber_caps_calcualte_hash(JabberCapsClientInfo *info, const char *hash) { 747 gchar *jabber_caps_calculate_hash(JabberCapsClientInfo *info, const char *hash) {
737 GList *identities; 748 GList *identities;
738 GList *features; 749 GList *features;
739 GList *xdata; 750 GList *xdata;
740 gchar *verification = 0; 751 gchar *verification = 0;
741 gchar *feature_string; 752 gchar *feature_string;
841 info->features = features; 852 info->features = features;
842 info->identities = jabber_identities; 853 info->identities = jabber_identities;
843 info->forms = 0; 854 info->forms = 0;
844 855
845 if (caps_hash) g_free(caps_hash); 856 if (caps_hash) g_free(caps_hash);
846 caps_hash = jabber_caps_calcualte_hash(info, "sha1"); 857 caps_hash = jabber_caps_calculate_hash(info, "sha1");
847 g_free(info); 858 g_free(info);
848 g_list_free(features); 859 g_list_free(features);
849 } 860 }
850 861
851 const gchar* jabber_caps_get_own_hash() { 862 const gchar* jabber_caps_get_own_hash() {