Mercurial > pidgin.yaz
comparison libpurple/protocols/jabber/caps.c @ 25749:b5dbf1d9930b
Whitespace, formatting, and // -> /* */
author | Paul Aurich <paul@darkrain42.org> |
---|---|
date | Fri, 21 Nov 2008 17:52:56 +0000 |
parents | 8789b9202c06 |
children | 30a686c079d5 |
comparison
equal
deleted
inserted
replaced
25748:8789b9202c06 | 25749:b5dbf1d9930b |
---|---|
85 | 85 |
86 while(valuestruct->forms) { | 86 while(valuestruct->forms) { |
87 g_free(valuestruct->forms->data); | 87 g_free(valuestruct->forms->data); |
88 valuestruct->forms = g_list_delete_link(valuestruct->forms,valuestruct->forms); | 88 valuestruct->forms = g_list_delete_link(valuestruct->forms,valuestruct->forms); |
89 } | 89 } |
90 //g_hash_table_destroy(valuestruct->ext); | 90 /* g_hash_table_destroy(valuestruct->ext); */ |
91 g_free(valuestruct); | 91 g_free(valuestruct); |
92 } | 92 } |
93 | 93 |
94 #if 0 | 94 #if 0 |
95 static void jabber_caps_ext_destroy_value(gpointer value) { | 95 static void jabber_caps_ext_destroy_value(gpointer value) { |
429 jabber_caps_cbplususerdata *userdata = data; | 429 jabber_caps_cbplususerdata *userdata = data; |
430 | 430 |
431 /* TODO: Better error checking! */ | 431 /* TODO: Better error checking! */ |
432 if (!strcmp(xmlnode_get_attrib(packet, "type"), "error"))return; | 432 if (!strcmp(xmlnode_get_attrib(packet, "type"), "error"))return; |
433 if (query) { | 433 if (query) { |
434 // check hash | 434 /* check hash */ |
435 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); | 435 JabberCapsClientInfo *info = jabber_caps_parse_client_info(query); |
436 gchar *hash = 0; | 436 gchar *hash = 0; |
437 JabberCapsValue *value; | 437 JabberCapsValue *value; |
438 JabberCapsKey *key; | 438 JabberCapsKey *key; |
439 xmlnode *child; | 439 xmlnode *child; |
441 if (!strcmp(userdata->hash, "sha-1")) { | 441 if (!strcmp(userdata->hash, "sha-1")) { |
442 hash = jabber_caps_calculate_hash(info, "sha1"); | 442 hash = jabber_caps_calculate_hash(info, "sha1"); |
443 } else if (!strcmp(userdata->hash, "md5")) { | 443 } else if (!strcmp(userdata->hash, "md5")) { |
444 hash = jabber_caps_calculate_hash(info, "md5"); | 444 hash = jabber_caps_calculate_hash(info, "md5"); |
445 } else { | 445 } else { |
446 // clean up | 446 /* TODO: clean up */ |
447 return; | 447 return; |
448 } | 448 } |
449 | 449 |
450 printf("\n\tfrom: %s", xmlnode_get_attrib(packet, "from")); | 450 printf("\n\tfrom: %s", xmlnode_get_attrib(packet, "from")); |
451 printf("\n\tnode: %s", xmlnode_get_attrib(query, "node")); | 451 printf("\n\tnode: %s", xmlnode_get_attrib(query, "node")); |
664 | 664 |
665 JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) { | 665 JabberCapsClientInfo *jabber_caps_parse_client_info(xmlnode *query) { |
666 xmlnode *child; | 666 xmlnode *child; |
667 JabberCapsClientInfo *info; | 667 JabberCapsClientInfo *info; |
668 | 668 |
669 if (!query) return 0; | 669 if (!query || strcmp(query->xmlns, "http://jabber.org/protocol/disco#info")) |
670 if (strcmp(query->xmlns,"http://jabber.org/protocol/disco#info")) return 0; | 670 return 0; |
671 | 671 |
672 info = g_new0(JabberCapsClientInfo, 1); | 672 info = g_new0(JabberCapsClientInfo, 1); |
673 | 673 |
674 for(child = query->child; child; child = child->next) { | 674 for(child = query->child; child; child = child->next) { |
675 if (!strcmp(child->name,"identity")) { | 675 if (!strcmp(child->name,"identity")) { |
738 verification = g_strconcat(verification_string, string, "<", NULL); | 738 verification = g_strconcat(verification_string, string, "<", NULL); |
739 g_free(verification_string); | 739 g_free(verification_string); |
740 return verification; | 740 return verification; |
741 } | 741 } |
742 | 742 |
743 gchar *jabber_caps_calculate_hash(JabberCapsClientInfo *info, const char *hash) { | 743 gchar *jabber_caps_calculate_hash(JabberCapsClientInfo *info, const char *hash) |
744 { | |
744 GList *identities; | 745 GList *identities; |
745 GList *features; | 746 GList *features; |
746 GList *xdata; | 747 GList *xdata; |
747 gchar *verification = 0; | 748 gchar *verification = 0; |
748 gchar *feature_string; | 749 gchar *feature_string; |
749 gchar *free_verification; | 750 gchar *free_verification; |
750 gchar *identity_string; | 751 gchar *identity_string; |
751 PurpleCipherContext *context; | 752 PurpleCipherContext *context; |
752 guint8 checksum[20]; | 753 guint8 checksum[20]; |
753 gsize checksum_size = 20; | 754 gsize checksum_size = 20; |
754 | 755 |
755 if (!info) return 0; | 756 if (!info) |
756 | 757 return 0; |
758 | |
757 /* sort identities, features and x-data forms */ | 759 /* sort identities, features and x-data forms */ |
758 info->identities = g_list_sort(info->identities, jabber_caps_jabber_identity_compare); | 760 info->identities = g_list_sort(info->identities, jabber_caps_jabber_identity_compare); |
759 info->features = g_list_sort(info->features, (GCompareFunc)strcmp); | 761 info->features = g_list_sort(info->features, (GCompareFunc)strcmp); |
760 info->forms = g_list_sort(info->forms, jabber_caps_jabber_xdata_compare); | 762 info->forms = g_list_sort(info->forms, jabber_caps_jabber_xdata_compare); |
761 | 763 |
762 /* concat identities to the verification string */ | 764 /* concat identities to the verification string */ |
763 for(identities = info->identities; identities; identities = identities->next) { | 765 for(identities = info->identities; identities; identities = identities->next) { |
764 JabberIdentity *ident = (JabberIdentity*)identities->data; | 766 JabberIdentity *ident = (JabberIdentity*)identities->data; |
765 identity_string = g_strdup_printf("%s/%s//%s<", ident->category, ident->type, ident->name); | 767 identity_string = g_strdup_printf("%s/%s//%s<", ident->category, ident->type, ident->name); |
766 free_verification = verification; | 768 free_verification = verification; |
767 if(verification == 0) verification = g_strdup(identity_string); | 769 if(verification == 0) |
768 else verification = g_strconcat(verification, identity_string, NULL); | 770 verification = g_strdup(identity_string); |
771 else | |
772 verification = g_strconcat(verification, identity_string, NULL); | |
769 g_free(identity_string); | 773 g_free(identity_string); |
770 g_free(free_verification); | 774 g_free(free_verification); |
771 } | 775 } |
772 | 776 |
773 /* concat features to the verification string */ | 777 /* concat features to the verification string */ |
774 for(features = info->features; features; features = features->next) { | 778 for(features = info->features; features; features = features->next) { |
775 feature_string = g_strdup_printf("%s", (gchar*)features->data); | 779 feature_string = g_strdup_printf("%s", (gchar*)features->data); |
776 verification = jabber_caps_verification_append(verification, feature_string); | 780 verification = jabber_caps_verification_append(verification, feature_string); |
777 g_free(feature_string); | 781 g_free(feature_string); |
778 } | 782 } |
779 | 783 |
780 /* concat x-data forms to the verification string */ | 784 /* concat x-data forms to the verification string */ |
781 for(xdata = info->forms; xdata; xdata = xdata->next) { | 785 for(xdata = info->forms; xdata; xdata = xdata->next) { |
782 gchar *formtype = 0; | 786 gchar *formtype = 0; |
783 GList *fields; | 787 GList *fields; |
784 /* append FORM_TYPE's field value to the verification string */ | 788 /* append FORM_TYPE's field value to the verification string */ |
803 g_free(field->var); | 807 g_free(field->var); |
804 g_list_free(field->values); | 808 g_list_free(field->values); |
805 } | 809 } |
806 g_list_free(fields); | 810 g_list_free(fields); |
807 } | 811 } |
808 | 812 |
809 /* generate hash */ | 813 /* generate hash */ |
810 context = purple_cipher_context_new_by_name(hash, NULL); | 814 context = purple_cipher_context_new_by_name(hash, NULL); |
811 if (context == NULL) { | 815 if (context == NULL) { |
812 //purple_debug_error("jabber", "Could not find cipher\n"); | 816 /* purple_debug_error("jabber", "Could not find cipher\n"); */ |
813 return 0; | 817 return 0; |
814 } | 818 } |
815 purple_cipher_context_append(context, (guchar*)verification, strlen(verification)); | 819 purple_cipher_context_append(context, (guchar*)verification, strlen(verification)); |
816 | 820 |
817 if (!purple_cipher_context_digest(context, strlen(verification), checksum, &checksum_size)) { | 821 if (!purple_cipher_context_digest(context, strlen(verification), checksum, &checksum_size)) { |
818 //purple_debug_error("util", "Failed to get digest.\n"); | 822 /* purple_debug_error("util", "Failed to get digest.\n"); */ |
819 } | 823 } |
820 purple_cipher_context_destroy(context); | 824 purple_cipher_context_destroy(context); |
821 | 825 |
822 /* apply Base64 on hash */ | 826 /* apply Base64 on hash */ |
823 | 827 |
824 g_free(verification); | 828 g_free(verification); |
825 verification = purple_base64_encode(checksum, checksum_size); | 829 verification = purple_base64_encode(checksum, checksum_size); |
826 | 830 |
827 return verification; | 831 return verification; |
828 } | 832 } |
829 | 833 |
830 void jabber_caps_calculate_own_hash(JabberStream *js) { | 834 void jabber_caps_calculate_own_hash(JabberStream *js) { |
831 JabberCapsClientInfo *info; | 835 JabberCapsClientInfo *info; |