comparison libpurple/protocols/myspace/myspace.c @ 18879:e0cac5db762b

In msim_msg_pack_element_dict(), separate keys and values with '=' for the MSIM_TYPE_DICTIONARY type. This should allow the dictionary type to work with MySpace's servers. Tested in msim_test_msg(). Also removed msim_test_xml(), since it was more of a playground than a formal test of anything. MsimMessage's dictionary type is now thought to be fully-functional, but it is not yet used anywhere.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Tue, 07 Aug 2007 02:11:15 +0000
parents b2d81d13f015
children 3ec39ff6b407
comparison
equal deleted inserted replaced
18878:eeaf5afc8940 18879:e0cac5db762b
3080 { 3080 {
3081 MsimSession *session; 3081 MsimSession *session;
3082 MsimMessage *delbuddy_msg; 3082 MsimMessage *delbuddy_msg;
3083 MsimMessage *persist_msg; 3083 MsimMessage *persist_msg;
3084 MsimMessage *blocklist_msg; 3084 MsimMessage *blocklist_msg;
3085 GList *blocklist_updates;
3085 3086
3086 session = (MsimSession *)gc->proto_data; 3087 session = (MsimSession *)gc->proto_data;
3087 3088
3088 delbuddy_msg = msim_msg_new(TRUE, 3089 delbuddy_msg = msim_msg_new(TRUE,
3089 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, 3090 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
3117 msim_msg_free(persist_msg); 3118 msim_msg_free(persist_msg);
3118 return; 3119 return;
3119 } 3120 }
3120 msim_msg_free(persist_msg); 3121 msim_msg_free(persist_msg);
3121 3122
3123 blocklist_updates = NULL;
3124
3122 blocklist_msg = msim_msg_new(TRUE, 3125 blocklist_msg = msim_msg_new(TRUE,
3123 "blocklist", MSIM_TYPE_BOOLEAN, TRUE, 3126 "blocklist", MSIM_TYPE_BOOLEAN, TRUE,
3124 "sesskey", MSIM_TYPE_INTEGER, session->sesskey, 3127 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
3125 /* TODO: MsimMessage lists */ 3128 /* TODO: MsimMessage lists. Currently <uid> isn't replaced in lists. */
3126 "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"), 3129 "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"),
3127 NULL); 3130 NULL);
3128 3131
3129 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL)) 3132 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL))
3130 { 3133 {
3816 { 3819 {
3817 guint failures; 3820 guint failures;
3818 3821
3819 3822
3820 failures = 0; 3823 failures = 0;
3821 failures += msim_test_xml();
3822 failures += msim_test_msg(); 3824 failures += msim_test_msg();
3823 failures += msim_test_escaping(); 3825 failures += msim_test_escaping();
3824 3826
3825 if (failures) 3827 if (failures)
3826 { 3828 {
3829 else 3831 else
3830 { 3832 {
3831 purple_debug_info("msim", "msim_test_all - all tests passed!\n"); 3833 purple_debug_info("msim", "msim_test_all - all tests passed!\n");
3832 } 3834 }
3833 exit(0); 3835 exit(0);
3834 }
3835
3836 int
3837 msim_test_xml(void)
3838 {
3839 gchar *msg_text;
3840 xmlnode *root, *n;
3841 guint failures;
3842 char *s;
3843 int len;
3844
3845 failures = 0;
3846
3847 msg_text = "<p><f n=\"Arial\" h=\"12\">woo!</f>xxx<c v='black'>yyy</c></p>";
3848
3849 purple_debug_info("msim", "msim_test_xml: msg_text=%s\n", msg_text);
3850
3851 root = xmlnode_from_str(msg_text, -1);
3852 if (!root)
3853 {
3854 purple_debug_info("msim", "there is no root\n");
3855 exit(0);
3856 }
3857
3858 purple_debug_info("msim", "root name=%s, child name=%s\n", root->name,
3859 root->child->name);
3860
3861 purple_debug_info("msim", "last child name=%s\n", root->lastchild->name);
3862 purple_debug_info("msim", "Root xml=%s\n",
3863 xmlnode_to_str(root, &len));
3864 purple_debug_info("msim", "Child xml=%s\n",
3865 xmlnode_to_str(root->child, &len));
3866 purple_debug_info("msim", "Lastchild xml=%s\n",
3867 xmlnode_to_str(root->lastchild, &len));
3868 purple_debug_info("msim", "Next xml=%s\n",
3869 xmlnode_to_str(root->next, &len));
3870 purple_debug_info("msim", "Next data=%s\n",
3871 xmlnode_get_data(root->next));
3872 purple_debug_info("msim", "Child->next xml=%s\n",
3873 xmlnode_to_str(root->child->next, &len));
3874
3875 for (n = root->child; n; n = n->next)
3876 {
3877 if (n->name)
3878 {
3879 purple_debug_info("msim", " ** n=%s\n",n->name);
3880 } else {
3881 purple_debug_info("msim", " ** n data=%s\n", n->data);
3882 }
3883 }
3884
3885 purple_debug_info("msim", "root data=%s, child data=%s, child 'h'=%s\n",
3886 xmlnode_get_data(root),
3887 xmlnode_get_data(root->child),
3888 xmlnode_get_attrib(root->child, "h"));
3889
3890
3891 for (n = root->child;
3892 n != NULL;
3893 n = n->next)
3894 {
3895 purple_debug_info("msim", "next name=%s\n", n->name);
3896 }
3897
3898 s = xmlnode_to_str(root, &len);
3899 s[len] = 0;
3900
3901 purple_debug_info("msim", "str: %s\n", s);
3902 g_free(s);
3903
3904 xmlnode_free(root);
3905
3906 exit(0);
3907
3908 return failures;
3909 } 3836 }
3910 3837
3911 /** Test MsimMessage for basic functionality. */ 3838 /** Test MsimMessage for basic functionality. */
3912 int 3839 int
3913 msim_test_msg(void) 3840 msim_test_msg(void)
3914 { 3841 {
3915 MsimMessage *msg, *msg_cloned; 3842 MsimMessage *msg, *msg_cloned, *msg2;
3843 GList *list;
3916 gchar *packed, *packed_expected, *packed_cloned; 3844 gchar *packed, *packed_expected, *packed_cloned;
3917 guint failures; 3845 guint failures;
3918 3846
3919 failures = 0; 3847 failures = 0;
3920 3848
3956 g_free(packed); 3884 g_free(packed);
3957 g_free(packed_cloned); 3885 g_free(packed_cloned);
3958 msim_msg_free(msg_cloned); 3886 msim_msg_free(msg_cloned);
3959 msim_msg_free(msg); 3887 msim_msg_free(msg);
3960 3888
3889 /* Try some of the more advanced functionality */
3890 list = NULL;
3891
3892 list = g_list_prepend(list, "item3");
3893 list = g_list_prepend(list, "item2");
3894 list = g_list_prepend(list, "item1");
3895 list = g_list_prepend(list, "item0");
3896
3897 msg = msim_msg_new(FALSE);
3898 msg = msim_msg_append(msg, "string", MSIM_TYPE_STRING, g_strdup("string value"));
3899 msg = msim_msg_append(msg, "raw", MSIM_TYPE_RAW, g_strdup("raw value"));
3900 msg = msim_msg_append(msg, "integer", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(3140));
3901 msg = msim_msg_append(msg, "boolean", MSIM_TYPE_BOOLEAN, GUINT_TO_POINTER(FALSE));
3902 msg = msim_msg_append(msg, "list", MSIM_TYPE_LIST, list);
3903
3904 msim_msg_dump("msg with list=%s\n", msg);
3905 purple_debug_info("msim", "msg with list packed=%s\n", msim_msg_pack(msg));
3906
3907 msg2 = msim_msg_new(FALSE);
3908 msg2 = msim_msg_append(msg2, "outer", MSIM_TYPE_STRING, g_strdup("outer value"));
3909 msg2 = msim_msg_append(msg2, "body", MSIM_TYPE_DICTIONARY, msg);
3910 msim_msg_dump("msg with dict=%s\n", msg2); /* msg2 now 'owns' msg */
3911 purple_debug_info("msim", "msg with dict packed=%s\n", msim_msg_pack(msg2));
3912
3913 msim_msg_free(msg2);
3914
3961 return failures; 3915 return failures;
3962 } 3916 }
3963 3917
3964 /** Test protocol-level escaping/unescaping. */ 3918 /** Test protocol-level escaping/unescaping. */
3965 int 3919 int