libpurple/protocols/myspace/myspace.c

Thu, 05 Jul 2007 03:13:34 +0000

author
Jeff Connelly <jeff2@soc.pidgin.im>
date
Thu, 05 Jul 2007 03:13:34 +0000
branch
soc.2007.msimprpl
changeset 18026
dec27c05ae89
parent 18025
a5e208acc0be
child 18028
85ed2582be94
permissions
-rw-r--r--

Set status to current status when signing on. This makes the "Sign in as
hidden" option no longer needed.

18026
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1 /* MySpaceIM Protocol Plugin
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3 * \author Jeff Connelly
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
4 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
6 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
7 * Based on Purple's "C Plugin HOWTO" hello world example.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
8 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
9 * Code also drawn from mockprpl:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
10 * http://snarfed.org/space/purple+mock+protocol+plugin
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
11 * Copyright (C) 2004-2007, Ryan Barrett <mockprpl@ryanb.org>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
12 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
13 * and some constructs also based on existing Purple plugins, which are:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
14 * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
15 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
16 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
17 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
18 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
19 * This program is free software; you can redistribute it and/or modify
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
20 * it under the terms of the GNU General Public License as published by
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
21 * the Free Software Foundation; either version 2 of the License, or
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
22 * (at your option) any later version.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
23 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
24 * This program is distributed in the hope that it will be useful,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
27 * GNU General Public License for more details.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
28 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
29 * You should have received a copy of the GNU General Public License
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
30 * along with this program; if not, write to the Free Software
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
32 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
33
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
34 #define PURPLE_PLUGIN
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
35
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
36 #include "message.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
37 #include "persist.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
38 #include "myspace.h"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
39
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
40 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
41 * Load the plugin.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
42 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
43 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
44 msim_load(PurplePlugin *plugin)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
45 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
46 /* If compiled to use RC4 from libpurple, check if it is really there. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
47 if (!purple_ciphers_find_cipher("rc4"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
48 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
49 purple_debug_error("msim", "rc4 not in libpurple, but it is required - not loading MySpaceIM plugin!\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
50 purple_notify_error(plugin, _("Missing Cipher"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
51 _("The RC4 cipher could not be found"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
52 _("Upgrade "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
53 "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
54 "plugin will not be loaded."));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
55 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
56 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
57 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
58 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
59
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
60 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
61 * Get possible user status types. Based on mockprpl.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
62 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
63 * @return GList of status types.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
64 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
65 GList *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
66 msim_status_types(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
67 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
68 GList *types;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
69 PurpleStatusType *status;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
70
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
71 purple_debug_info("myspace", "returning status types\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
72
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
73 types = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
74
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
75 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, NULL, NULL, FALSE, TRUE, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
76 types = g_list_append(types, status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
77
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
78 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, NULL, NULL, FALSE, TRUE, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
79 types = g_list_append(types, status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
80
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
81 status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
82 types = g_list_append(types, status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
83
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
84 status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, NULL, NULL, FALSE, TRUE, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
85 types = g_list_append(types, status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
86
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
87 return types;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
88 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
89
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
90 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
91 * Return the icon name for a buddy and account.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
92 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
93 * @param acct The account to find the icon for, or NULL for protocol icon.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
94 * @param buddy The buddy to find the icon for, or NULL for the account icon.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
95 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
96 * @return The base icon name string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
97 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
98 const gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
99 msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
100 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
101 /* Use a MySpace icon submitted by hbons at
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
102 * http://developer.pidgin.im/wiki/MySpaceIM. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
103 return "myspace";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
104 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
105
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
106 /* Replacement codes to be replaced with associated replacement text,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
107 * used for protocol message escaping / unescaping. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
108 static gchar* msim_replacement_code[] = { "/1", "/2", NULL };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
109 static gchar* msim_replacement_text[] = { "/", "\\", NULL };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
110
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
111 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
112 * Unescape or escape a protocol message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
113 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
114 * @param msg The message to be unescaped or escaped. WILL BE FREED.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
115 * @param escape TRUE to escape, FALSE to unescape.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
116 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
117 * @return The unescaped or escaped message. Caller must g_free().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
118 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
119 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
120 msim_unescape_or_escape(gchar *msg, gboolean escape)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
121 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
122 gchar *tmp, *code, *text;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
123 guint i;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
124
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
125 /* Replace each code in msim_replacement_code with
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
126 * corresponding entry in msim_replacement_text. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
127 for (i = 0; (code = msim_replacement_code[i])
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
128 && (text = msim_replacement_text[i]); ++i)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
129 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
130 if (escape)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
131 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
132 tmp = str_replace(msg, text, code);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
133 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
134 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
135 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
136 tmp = str_replace(msg, code, text);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
137 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
138 g_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
139 msg = tmp;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
140 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
141
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
142 return msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
143 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
144
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
145 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
146 * Escape a protocol message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
147 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
148 * @return The escaped message. Caller must g_free().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
149 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
150 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
151 msim_escape(const gchar *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
152 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
153 return msim_unescape_or_escape(g_strdup(msg), TRUE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
154 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
155
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
156 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
157 msim_unescape(const gchar *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
158 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
159 return msim_unescape_or_escape(g_strdup(msg), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
160 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
161
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
162 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
163 * Replace 'old' with 'new' in 'str'.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
164 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
165 * @param str The original string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
166 * @param old The substring of 'str' to replace.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
167 * @param new The replacement for 'old' within 'str'.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
168 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
169 * @return A _new_ string, based on 'str', with 'old' replaced
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
170 * by 'new'. Must be g_free()'d by caller.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
171 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
172 * This string replace method is based on
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
173 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
174 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
175 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
176 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
177 str_replace(const gchar *str, const gchar *old, const gchar *new)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
178 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
179 gchar **items;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
180 gchar *ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
181
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
182 items = g_strsplit(str, old, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
183 ret = g_strjoinv(new, items);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
184 g_free(items);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
185 return ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
186 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
187
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
188 #ifdef MSIM_DEBUG_MSG
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
189 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
190 print_hash_item(gpointer key, gpointer value, gpointer user_data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
191 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
192 purple_debug_info("msim", "%s=%s\n", (gchar *)key, (gchar *)value);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
193 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
194 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
195
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
196 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
197 * Send raw data (given as a NUL-terminated string) to the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
198 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
199 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
200 * @param msg The raw data to send, in a NUL-terminated string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
201 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
202 * @return TRUE if succeeded, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
203 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
204 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
205 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
206 msim_send_raw(MsimSession *session, const gchar *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
207 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
208 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
209
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
210 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
211 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
212
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
213 return msim_send_really_raw(session->gc, msg, strlen(msg)) ==
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
214 strlen(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
215 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
216
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
217 /** Send raw data to the server, possibly with embedded NULs.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
218 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
219 * Used in prpl_info struct, so that plugins can have the most possible
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
220 * control of what is sent over the connection. Inside this prpl,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
221 * msim_send_raw() is used, since it sends NUL-terminated strings (easier).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
222 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
223 * @param gc PurpleConnection
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
224 * @param buf Buffer to send
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
225 * @param total_bytes Size of buffer to send
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
226 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
227 * @return Bytes successfully sent, or -1 on error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
228 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
229 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
230 msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
231 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
232 int total_bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
233 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
234
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
235 g_return_val_if_fail(gc != NULL, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
236 g_return_val_if_fail(buf != NULL, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
237 g_return_val_if_fail(total_bytes >= 0, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
238
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
239 session = (MsimSession *)(gc->proto_data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
240
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
241 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
242
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
243 /* Loop until all data is sent, or a failure occurs. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
244 total_bytes_sent = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
245 do
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
246 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
247 int bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
248
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
249 bytes_sent = send(session->fd, buf + total_bytes_sent,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
250 total_bytes - total_bytes_sent, 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
251
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
252 if (bytes_sent < 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
253 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
254 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
255 buf, g_strerror(errno));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
256 return total_bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
257 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
258 total_bytes_sent += bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
259
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
260 } while(total_bytes_sent < total_bytes);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
261
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
262 return total_bytes_sent;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
263 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
264
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
265
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
266 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
267 * Start logging in to the MSIM servers.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
268 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
269 * @param acct Account information to use to login.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
270 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
271 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
272 msim_login(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
273 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
274 PurpleConnection *gc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
275 const gchar *host;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
276 int port;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
277
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
278 g_return_if_fail(acct != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
279 g_return_if_fail(acct->username != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
280
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
281 purple_debug_info("myspace", "logging in %s\n", acct->username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
282
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
283 gc = purple_account_get_connection(acct);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
284 gc->proto_data = msim_session_new(acct);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
285
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
286 /* Passwords are limited in length. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
287 if (strlen(acct->password) > MSIM_MAX_PASSWORD_LENGTH)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
288 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
289 gchar *str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
290
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
291 str = g_strdup_printf(
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
292 _("Sorry, passwords over %d characters in length (yours is "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
293 "%d) are not supported by the MySpaceIM plugin."),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
294 MSIM_MAX_PASSWORD_LENGTH,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
295 (int)strlen(acct->password));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
296
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
297 /* Notify an error message also, because this is important! */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
298 purple_notify_error(acct, g_strdup(_("MySpaceIM Error")), str, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
299
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
300 purple_connection_error(gc, str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
301
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
302 g_free(str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
303 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
304
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
305 /* 1. connect to server */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
306 purple_connection_update_progress(gc, _("Connecting"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
307 0, /* which connection step this is */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
308 4); /* total number of steps */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
309
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
310 host = purple_account_get_string(acct, "server", MSIM_SERVER);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
311 port = purple_account_get_int(acct, "port", MSIM_PORT);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
312
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
313 /* From purple.sf.net/api:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
314 * """Note that this function name can be misleading--although it is called
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
315 * "proxy connect," it is used for establishing any outgoing TCP connection,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
316 * whether through a proxy or not.""" */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
317
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
318 /* Calls msim_connect_cb when connected. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
319 if (purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc) == NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
320 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
321 /* TODO: try other ports if in auto mode, then save
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
322 * working port and try that first next time. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
323 purple_connection_error(gc, _("Couldn't create socket"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
324 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
325 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
326 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
327
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
328 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
329 * Process a login challenge, sending a response.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
330 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
331 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
332 * @param msg Login challenge message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
333 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
334 * @return TRUE if successful, FALSE if not
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
335 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
336 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
337 msim_login_challenge(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
338 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
339 PurpleAccount *account;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
340 const gchar *response;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
341 guint response_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
342 gchar *nc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
343 gsize nc_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
344
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
345 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
346 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
347
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
348 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
349
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
350 account = session->account;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
351
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
352 g_return_val_if_fail(account != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
353
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
354 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
355
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
356 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
357
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
358 if (nc_len != 0x40)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
359 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
360 purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
361 purple_connection_error(session->gc, _("Unexpected challenge length from server"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
362 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
363 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
364
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
365 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
366
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
367 response = msim_compute_login_response(nc, account->username, account->password, &response_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
368
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
369 g_free(nc);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
370
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
371 return msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
372 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
373 /* This is actually user's email address. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
374 "username", MSIM_TYPE_STRING, g_strdup(account->username),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
375 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
376 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
377 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
378 "reconn", MSIM_TYPE_INTEGER, 0,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
379 "status", MSIM_TYPE_INTEGER, 100,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
380 "id", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
381 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
382 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
383
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
384 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
385 * Compute the base64'd login challenge response based on username, password, nonce, and IPs.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
386 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
387 * @param nonce The base64 encoded nonce ('nc') field from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
388 * @param email User's email address (used as login name).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
389 * @param password User's cleartext password.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
390 * @param response_len Will be written with response length.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
391 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
392 * @return Binary login challenge response, ready to send to the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
393 * Must be g_free()'d when finished. NULL if error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
394 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
395 const gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
396 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE],
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
397 const gchar *email, const gchar *password, guint *response_len)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
398 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
399 PurpleCipherContext *key_context;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
400 PurpleCipher *sha1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
401 PurpleCipherContext *rc4;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
402
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
403 guchar hash_pw[HASH_SIZE];
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
404 guchar key[HASH_SIZE];
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
405 gchar *password_utf16le;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
406 guchar *data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
407 guchar *data_out;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
408 size_t data_len, data_out_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
409 gsize conv_bytes_read, conv_bytes_written;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
410 GError *conv_error;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
411 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
412 int i;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
413 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
414
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
415 g_return_val_if_fail(nonce != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
416 g_return_val_if_fail(email != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
417 g_return_val_if_fail(password != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
418 g_return_val_if_fail(response_len != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
419
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
420 /* Convert ASCII password to UTF16 little endian */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
421 purple_debug_info("msim", "converting password to UTF-16LE\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
422 conv_error = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
423 password_utf16le = g_convert(password, -1, "UTF-16LE", "UTF-8",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
424 &conv_bytes_read, &conv_bytes_written, &conv_error);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
425
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
426 g_return_val_if_fail(conv_bytes_read == strlen(password), NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
427
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
428 if (conv_error != NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
429 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
430 purple_debug_error("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
431 "g_convert password UTF8->UTF16LE failed: %s",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
432 conv_error->message);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
433 g_error_free(conv_error);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
434 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
435 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
436
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
437 /* Compute password hash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
438 purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
439 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
440 g_free(password_utf16le);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
441
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
442 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
443 purple_debug_info("msim", "pwhash = ");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
444 for (i = 0; i < sizeof(hash_pw); i++)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
445 purple_debug_info("msim", "%.2x ", hash_pw[i]);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
446 purple_debug_info("msim", "\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
447 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
448
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
449 /* key = sha1(sha1(pw) + nonce2) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
450 sha1 = purple_ciphers_find_cipher("sha1");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
451 key_context = purple_cipher_context_new(sha1, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
452 purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
453 purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
454 purple_cipher_context_digest(key_context, sizeof(key), key, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
455
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
456 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
457 purple_debug_info("msim", "key = ");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
458 for (i = 0; i < sizeof(key); i++)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
459 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
460 purple_debug_info("msim", "%.2x ", key[i]);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
461 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
462 purple_debug_info("msim", "\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
463 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
464
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
465 rc4 = purple_cipher_context_new_by_name("rc4", NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
466
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
467 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
468 * but only first 0x10 used for the RC4 key. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
469 purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
470 purple_cipher_context_set_key(rc4, key);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
471
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
472 /* TODO: obtain IPs of network interfaces */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
473
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
474 /* rc4 encrypt:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
475 * nonce1+email+IP list */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
476
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
477 data_len = NONCE_SIZE + strlen(email) + MSIM_LOGIN_IP_LIST_LEN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
478 data = g_new0(guchar, data_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
479 memcpy(data, nonce, NONCE_SIZE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
480 memcpy(data + NONCE_SIZE, email, strlen(email));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
481 memcpy(data + NONCE_SIZE + strlen(email), MSIM_LOGIN_IP_LIST, MSIM_LOGIN_IP_LIST_LEN);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
482
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
483 data_out = g_new0(guchar, data_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
484
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
485 purple_cipher_context_encrypt(rc4, (const guchar *)data,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
486 data_len, data_out, &data_out_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
487 purple_cipher_context_destroy(rc4);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
488
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
489 g_assert(data_out_len == data_len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
490
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
491 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
492 purple_debug_info("msim", "response=<%s>\n", data_out);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
493 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
494
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
495 *response_len = data_out_len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
496
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
497 return (const gchar *)data_out;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
498 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
499
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
500 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
501 * Schedule an IM to be sent once the user ID is looked up.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
502 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
503 * @param gc Connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
504 * @param who A user id, email, or username to send the message to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
505 * @param message Instant message text to send.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
506 * @param flags Flags.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
507 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
508 * @return 1 if successful or postponed, -1 if failed
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
509 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
510 * Allows sending to a user by username, email address, or userid. If
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
511 * a username or email address is given, the userid must be looked up.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
512 * This function does that by calling msim_postprocess_outgoing().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
513 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
514 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
515 msim_send_im(PurpleConnection *gc, const gchar *who, const gchar *message,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
516 PurpleMessageFlags flags)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
517 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
518 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
519
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
520 g_return_val_if_fail(gc != NULL, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
521 g_return_val_if_fail(who != NULL, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
522 g_return_val_if_fail(message != NULL, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
523
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
524 /* 'flags' has many options, not used here. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
525
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
526 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
527
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
528 g_return_val_if_fail(MSIM_SESSION_VALID(session), -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
529
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
530 if (msim_send_bm(session, who, message, MSIM_BM_INSTANT))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
531 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
532 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
533 * return 1 even if the message could not be sent, since I don't know if
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
534 * it has failed yet--because the IM is only sent after the userid is
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
535 * retrieved from the server (which happens after this function returns).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
536 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
537 /* TODO: maybe if message is delayed, don't echo to conv window,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
538 * but do echo it to conv window manually once it is actually
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
539 * sent? Would be complicated. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
540 return 1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
541 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
542 return -1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
543 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
544 /*
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
545 * In MySpace, you login with your email address, but don't talk to other
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
546 * users using their email address. So there is currently an asymmetry in the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
547 * IM windows when using this plugin:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
548 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
549 * you@example.com: hello
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
550 * some_other_user: what's going on?
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
551 * you@example.com: just coding a prpl
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
552 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
553 * TODO: Make the sent IM's appear as from the user's username, instead of
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
554 * their email address. Purple uses the login (in MSIM, the email)--change this.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
555 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
556 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
557
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
558 /** Send a buddy message of a given type.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
559 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
560 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
561 * @param who Username to send message to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
562 * @param text Message text to send. Not freed; will be copied.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
563 * @param type A MSIM_BM_* constant.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
564 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
565 * @return TRUE if success, FALSE if fail.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
566 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
567 * Buddy messages ('bm') include instant messages, action messages, status messages, etc.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
568 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
569 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
570 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
571 msim_send_bm(MsimSession *session, const gchar *who, const gchar *text,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
572 int type)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
573 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
574 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
575 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
576 const gchar *from_username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
577
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
578 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
579 g_return_val_if_fail(who != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
580 g_return_val_if_fail(text != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
581
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
582 from_username = session->account->username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
583
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
584 purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
585 type, from_username, who, text);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
586
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
587 msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
588 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
589 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
590 /* 't' will be inserted here */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
591 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
592 "msg", MSIM_TYPE_STRING, g_strdup(text),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
593 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
594
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
595 rc = msim_postprocess_outgoing(session, msg, who, "t", "cv");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
596
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
597 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
598
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
599 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
600 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
601
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
602
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
603 #ifdef MSIM_FONT_SIZE_WORKS
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
604 /** Convert a msim markup font height to points. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
605 static guint
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
606 msim_font_height_to_point(guint height)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
607 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
608 /* See also: libpurple/protocols/bonjour/jabber.c
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
609 * _font_size_ichat_to_purple */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
610 switch (height)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
611 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
612 case 11: return 8;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
613 case 12: return 9;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
614 case 13: return 10;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
615 case 14:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
616 case 15: return 11;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
617 case 16: return 12;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
618 case 17:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
619 case 18: return 13;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
620 case 19: return 14;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
621 case 20: return 15;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
622 case 21: return 16;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
623 default: return 12;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
624 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
625 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
626 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
627
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
628 /** Convert the msim markup <f> (font) tag into HTML. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
629 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
630 msim_markup_f_to_html(xmlnode *root, gchar **begin, gchar **end)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
631 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
632 const gchar *face, *height_str, *decor_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
633 GString *gs_end, *gs_begin;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
634 guint decor, height;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
635
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
636 face = xmlnode_get_attrib(root, "f");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
637 height_str = xmlnode_get_attrib(root, "h");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
638 decor_str = xmlnode_get_attrib(root, "s");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
639
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
640 if (height_str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
641 height = atol(height_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
642 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
643 height = 12;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
644
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
645 if (decor_str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
646 decor = atol(decor_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
647 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
648 decor = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
649
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
650 gs_begin = g_string_new("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
651 #ifdef MSIM_FONT_SIZE_WORKS
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
652 /* TODO: get font size working */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
653 if (!face)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
654 g_string_printf(gs_begin, "<font size='%d'>",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
655 msim_font_height_to_point(height));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
656 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
657 g_string_printf(gs_begin, "<font face='%s' size='%d'>", face,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
658 msim_font_height_to_point(height));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
659 #else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
660 if (face)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
661 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
662 g_string_printf(gs_begin, "<font face='%s'>", face);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
663 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
664 g_string_printf(gs_begin, "<font>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
665 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
666 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
667
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
668
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
669 /* No support for font-size CSS? */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
670 /* g_string_printf(gs_begin, "<span style='font-family: %s; font-size: %dpt'>", face,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
671 msim_font_height_to_point(height)); */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
672
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
673 gs_end = g_string_new("</font>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
674
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
675 if (decor & MSIM_TEXT_BOLD)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
676 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
677 g_string_append(gs_begin, "<b>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
678 g_string_prepend(gs_end, "</b>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
679 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
680
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
681 if (decor & MSIM_TEXT_ITALICS)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
682 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
683 g_string_append(gs_begin, "<i>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
684 g_string_append(gs_end, "</i>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
685 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
686
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
687 if (decor & MSIM_TEXT_UNDERLINE)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
688 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
689 g_string_append(gs_begin, "<u>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
690 g_string_append(gs_end, "</u>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
691 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
692
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
693
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
694 *begin = gs_begin->str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
695 *end = gs_end->str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
696 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
697
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
698 /** Convert a msim markup color to a color suitable for libpurple.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
699 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
700 * @param msim Either a color name, or an rgb(x,y,z) code.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
701 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
702 * @return A new string, either a color name or #rrggbb code. Must g_free().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
703 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
704 static char *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
705 msim_color_to_purple(const char *msim)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
706 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
707 guint red, green, blue;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
708
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
709 if (!msim)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
710 return g_strdup("black");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
711
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
712 if (sscanf(msim, "rgb(%d,%d,%d)", &red, &green, &blue) != 3)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
713 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
714 /* Color name. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
715 return g_strdup(msim);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
716 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
717 /* TODO: rgba (alpha). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
718
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
719 return g_strdup_printf("#%.2x%.2x%.2x", red, green, blue);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
720 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
721
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
722 /** Convert the msim markup <p> (paragraph) tag into HTML. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
723 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
724 msim_markup_p_to_html(xmlnode *root, gchar **begin, gchar **end)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
725 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
726 /* Just pass through unchanged.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
727 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
728 * Note: attributes currently aren't passed, if there are any. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
729 *begin = g_strdup("<p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
730 *end = g_strdup("</p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
731 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
732
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
733 /** Convert the msim markup <c> tag (text color) into HTML. TODO: Test */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
734 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
735 msim_markup_c_to_html(xmlnode *root, gchar **begin, gchar **end)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
736 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
737 const gchar *color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
738 gchar *purple_color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
739
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
740 color = xmlnode_get_attrib(root, "v");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
741 if (!color)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
742 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
743 purple_debug_info("msim", "msim_markup_c_to_html: <c> tag w/o v attr");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
744 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
745 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
746 /* TODO: log as unrecognized */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
747 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
748 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
749
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
750 purple_color = msim_color_to_purple(color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
751
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
752 *begin = g_strdup_printf("<font color='%s'>", purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
753
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
754 g_free(purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
755
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
756 /* *begin = g_strdup_printf("<span style='color: %s'>", color); */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
757 *end = g_strdup("</font>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
758 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
759
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
760 /** Convert the msim markup <b> tag (background color) into HTML. TODO: Test */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
761 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
762 msim_markup_b_to_html(xmlnode *root, gchar **begin, gchar **end)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
763 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
764 const gchar *color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
765 gchar *purple_color;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
766
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
767 color = xmlnode_get_attrib(root, "v");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
768 if (!color)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
769 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
770 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
771 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
772 purple_debug_info("msim", "msim_markup_b_to_html: <b> w/o v attr");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
773 /* TODO: log as unrecognized. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
774 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
775 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
776
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
777 purple_color = msim_color_to_purple(color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
778
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
779 /* TODO: find out how to set background color. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
780 *begin = g_strdup_printf("<span style='background-color: %s'>",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
781 purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
782 g_free(purple_color);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
783
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
784 *end = g_strdup("</p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
785 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
786
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
787 /** Convert the msim markup <i> tag (emoticon image) into HTML. TODO: Test */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
788 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
789 msim_markup_i_to_html(xmlnode *root, gchar **begin, gchar **end)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
790 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
791 const gchar *name;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
792
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
793 name = xmlnode_get_attrib(root, "n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
794 if (!name)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
795 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
796 purple_debug_info("msim", "msim_markup_i_to_html: <i> w/o n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
797 *begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
798 *end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
799 /* TODO: log as unrecognized */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
800 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
801 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
802
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
803 /* TODO: Support these emoticons:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
804 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
805 * bigsmile growl mad scared tongue devil happy messed sidefrown upset
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
806 * frazzled heart nerd sinister wink geek laugh oops smirk worried
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
807 * googles mohawk pirate straight kiss
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
808 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
809
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
810 *begin = g_strdup_printf("<img id='%s'>", name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
811 *end = g_strdup("</p>");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
812 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
813
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
814
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
815 /** Convert an xmlnode of msim markup to an HTML string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
816 * @return An HTML string. Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
817 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
818 static gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
819 msim_markup_xmlnode_to_html(xmlnode *root)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
820 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
821 xmlnode *node;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
822 gchar *begin, *inner, *end;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
823 gchar *final;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
824
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
825 if (!root || !root->name)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
826 return g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
827
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
828 purple_debug_info("msim", "msim_markup_xmlnode_to_html: got root=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
829 root->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
830
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
831 begin = inner = end = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
832
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
833 if (!strcmp(root->name, "f"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
834 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
835 msim_markup_f_to_html(root, &begin, &end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
836 } else if (!strcmp(root->name, "p")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
837 msim_markup_p_to_html(root, &begin, &end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
838 } else if (!strcmp(root->name, "c")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
839 msim_markup_c_to_html(root, &begin, &end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
840 } else if (!strcmp(root->name, "b")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
841 msim_markup_b_to_html(root, &begin, &end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
842 } else if (!strcmp(root->name, "i")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
843 msim_markup_i_to_html(root, &begin, &end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
844 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
845 purple_debug_info("msim", "msim_markup_xmlnode_to_html: "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
846 "unknown tag name=%s, ignoring", root->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
847 begin = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
848 end = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
849 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
850
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
851 /* Loop over all child nodes. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
852 for (node = root->child; node != NULL; node = node->next)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
853 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
854 switch (node->type)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
855 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
856 case XMLNODE_TYPE_ATTRIB:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
857 /* Attributes handled above. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
858 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
859
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
860 case XMLNODE_TYPE_TAG:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
861 /* A tag or tag with attributes. Recursively descend. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
862 inner = msim_markup_xmlnode_to_html(node);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
863 g_return_val_if_fail(inner != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
864
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
865 purple_debug_info("msim", " ** node name=%s\n", node->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
866 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
867
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
868 case XMLNODE_TYPE_DATA:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
869 /* Literal text. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
870 inner = g_new0(char, node->data_sz + 1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
871 strncpy(inner, node->data, node->data_sz);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
872 inner[node->data_sz + 1] = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
873
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
874 purple_debug_info("msim", " ** node data=%s\n", inner);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
875 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
876
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
877 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
878 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
879 "msim_markup_xmlnode_to_html: strange node\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
880 inner = g_strdup("");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
881 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
882 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
883
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
884 final = g_strconcat(begin, inner, end, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
885 g_free(begin);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
886 g_free(inner);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
887 g_free(end);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
888
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
889 purple_debug_info("msim", "msim_markup_xmlnode_to_gtkhtml: RETURNING %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
890 final);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
891
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
892 return final;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
893 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
894
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
895 /** Convert MySpaceIM markup to Purple (HTML) markup.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
896 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
897 * @return Purple markup string, must be g_free()'d. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
898 gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
899 msim_markup_to_html(const gchar *raw)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
900 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
901 xmlnode *root;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
902 gchar *str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
903
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
904 root = xmlnode_from_str(raw, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
905 if (!root)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
906 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
907 purple_debug_info("msim", "msim_markup_to_html: couldn't parse "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
908 "%s as XML, returning raw\n", raw);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
909 return g_strdup(raw);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
910 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
911
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
912 str = msim_markup_xmlnode_to_html(root);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
913 purple_debug_info("msim", "msim_markup_to_html: returning %s\n", str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
914
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
915 xmlnode_free(root);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
916
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
917 return g_strdup(str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
918 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
919
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
920 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
921 * Handle an incoming instant message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
922 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
923 * @param session The session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
924 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
925 * Should also contain username in _username from preprocessing.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
926 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
927 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
928 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
929 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
930 msim_incoming_im(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
931 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
932 gchar *username, *msg_msim_markup, *msg_purple_markup;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
933
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
934 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
935 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
936
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
937 username = msim_msg_get_string(msg, "_username");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
938 g_return_val_if_fail(username != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
939
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
940 msg_msim_markup = msim_msg_get_string(msg, "msg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
941 g_return_val_if_fail(msg_msim_markup != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
942
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
943 msg_purple_markup = msim_markup_to_html(msg_msim_markup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
944 g_free(msg_msim_markup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
945
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
946 serv_got_im(session->gc, username, msg_purple_markup,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
947 PURPLE_MESSAGE_RECV, time(NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
948
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
949 g_free(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
950 g_free(msg_purple_markup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
951
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
952 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
953 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
954
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
955 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
956 * Process unrecognized information.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
957 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
958 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
959 * @param msg An MsimMessage that was unrecognized, or NULL.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
960 * @param note Information on what was unrecognized, or NULL.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
961 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
962 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
963 msim_unrecognized(MsimSession *session, MsimMessage *msg, gchar *note)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
964 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
965 /* TODO: Some more context, outwardly equivalent to a backtrace,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
966 * for helping figure out what this msg is for. What was going on?
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
967 * But not too much information so that a user
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
968 * posting this dump reveals confidential information.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
969 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
970
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
971 /* TODO: dump unknown msgs to file, so user can send them to me
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
972 * if they wish, to help add support for new messages (inspired
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
973 * by Alexandr Shutko, who maintains OSCAR protocol documentation). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
974
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
975 purple_debug_info("msim", "Unrecognized data on account for %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
976 session->account->username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
977 if (note)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
978 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
979 purple_debug_info("msim", "(Note: %s)\n", note);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
980 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
981
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
982 if (msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
983 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
984 msim_msg_dump("Unrecognized message dump: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
985 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
986 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
987
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
988 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
989 * Handle an incoming action message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
990 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
991 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
992 * @param msg
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
993 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
994 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
995 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
996 * UNTESTED
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
997 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
998 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
999 msim_incoming_action(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1000 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1001 gchar *msg_text, *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1002 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1003
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1004 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1005 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1006
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1007 msg_text = msim_msg_get_string(msg, "msg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1008 g_return_val_if_fail(msg_text != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1009
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1010 username = msim_msg_get_string(msg, "_username");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1011 g_return_val_if_fail(username != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1012
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1013 purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1014 msg_text, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1015
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1016 if (strcmp(msg_text, "%typing%") == 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1017 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1018 /* TODO: find out if msim repeatedly sends typing messages, so we can
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1019 * give it a timeout. Right now, there does seem to be an inordinately
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1020 * amount of time between typing stopped-typing notifications. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1021 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1022 rc = TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1023 } else if (strcmp(msg_text, "%stoptyping%") == 0) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1024 serv_got_typing_stopped(session->gc, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1025 rc = TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1026 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1027 msim_unrecognized(session, msg,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1028 "got to msim_incoming_action but unrecognized value for 'msg'");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1029 rc = FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1030 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1031
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1032 g_free(msg_text);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1033 g_free(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1034
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1035 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1036 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1037
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1038 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1039 * Handle when our user starts or stops typing to another user.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1040 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1041 * @param gc
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1042 * @param name The buddy name to which our user is typing to
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1043 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1044 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1045 * @return 0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1046 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1047 unsigned int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1048 msim_send_typing(PurpleConnection *gc, const gchar *name,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1049 PurpleTypingState state)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1050 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1051 const gchar *typing_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1052 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1053
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1054 g_return_val_if_fail(gc != NULL, 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1055 g_return_val_if_fail(name != NULL, 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1056
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1057 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1058
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1059 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1060
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1061 switch (state)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1062 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1063 case PURPLE_TYPING:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1064 typing_str = "%typing%";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1065 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1066
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1067 case PURPLE_TYPED:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1068 case PURPLE_NOT_TYPING:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1069 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1070 typing_str = "%stoptyping%";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1071 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1072 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1073
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1074 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1075 msim_send_bm(session, name, typing_str, MSIM_BM_ACTION);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1076 return 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1077 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1078
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1079 /** Callback for msim_get_info(), for when user info is received. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1080 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1081 msim_get_info_cb(MsimSession *session, MsimMessage *user_info_msg, gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1082 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1083 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1084 gchar *body_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1085 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1086 gchar *user;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1087 PurpleNotifyUserInfo *user_info;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1088 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1089 const gchar *str, *str2;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1090
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1091 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1092
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1093 /* Get user{name,id} from msim_get_info, passed as an MsimMessage for
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1094 orthogonality. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1095 msg = (MsimMessage *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1096 g_return_if_fail(msg != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1097
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1098 user = msim_msg_get_string(msg, "user");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1099 if (!user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1100 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1101 purple_debug_info("msim", "msim_get_info_cb: no 'user' in msg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1102 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1103 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1104
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1105 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1106 purple_debug_info("msim", "msim_get_info_cb: got for user: %s\n", user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1107
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1108 body_str = msim_msg_get_string(user_info_msg, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1109 g_return_if_fail(body_str != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1110 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1111 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1112
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1113 buddy = purple_find_buddy(session->account, user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1114 /* Note: don't assume buddy is non-NULL; will be if lookup random user
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1115 * not on blist. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1116
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1117 user_info = purple_notify_user_info_new();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1118
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1119 /* Identification */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1120 purple_notify_user_info_add_pair(user_info, _("User"), user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1121
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1122 /* note: g_hash_table_lookup does not create a new string! */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1123 str = g_hash_table_lookup(body, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1124 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1125 purple_notify_user_info_add_pair(user_info, _("User ID"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1126 g_strdup(str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1127
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1128 /* a/s/l...the vitals */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1129 str = g_hash_table_lookup(body, "Age");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1130 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1131 purple_notify_user_info_add_pair(user_info, _("Age"), g_strdup(str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1132
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1133 str = g_hash_table_lookup(body, "Gender");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1134 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1135 purple_notify_user_info_add_pair(user_info, _("Gender"), g_strdup(str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1136
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1137 str = g_hash_table_lookup(body, "Location");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1138 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1139 purple_notify_user_info_add_pair(user_info, _("Location"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1140 g_strdup(str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1141
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1142 /* Other information */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1143
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1144 /* Headline comes from buddy status messages */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1145 if (buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1146 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1147 str = purple_blist_node_get_string(&buddy->node, "Headline");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1148 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1149 purple_notify_user_info_add_pair(user_info, "Headline", str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1150 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1151
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1152
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1153 str = g_hash_table_lookup(body, "BandName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1154 str2 = g_hash_table_lookup(body, "SongName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1155 if (str || str2)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1156 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1157 purple_notify_user_info_add_pair(user_info, _("Song"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1158 g_strdup_printf("%s - %s",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1159 str ? str : "Unknown Artist",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1160 str2 ? str2 : "Unknown Song"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1161 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1162
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1163
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1164 /* Total friends only available if looked up by uid, not username. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1165 str = g_hash_table_lookup(body, "TotalFriends");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1166 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1167 purple_notify_user_info_add_pair(user_info, _("Total Friends"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1168 g_strdup(str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1169
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1170 purple_notify_userinfo(session->gc, user, user_info, NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1171 purple_debug_info("msim", "msim_get_info_cb: username=%s\n", user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1172 //purple_notify_user_info_destroy(user_info);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1173 /* Do not free username, since it will be used by user_info. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1174
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1175 //g_hash_table_destroy(body);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1176 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1177
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1178 /** Retrieve a user's profile. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1179 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1180 msim_get_info(PurpleConnection *gc, const gchar *user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1181 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1182 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1183 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1184 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1185 gchar *user_to_lookup;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1186 MsimMessage *user_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1187
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1188 g_return_if_fail(gc != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1189 g_return_if_fail(user != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1190
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1191 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1192
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1193 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1194
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1195 /* Obtain uid of buddy. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1196 buddy = purple_find_buddy(session->account, user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1197 if (buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1198 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1199 uid = purple_blist_node_get_int(&buddy->node, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1200 if (!uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1201 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1202 PurpleNotifyUserInfo *user_info;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1203
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1204 user_info = purple_notify_user_info_new();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1205 purple_notify_user_info_add_pair(user_info, NULL,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1206 _("This buddy appears to not have a userid stored in the buddy list, can't look up. Is the user really on the buddy list?"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1207
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1208 purple_notify_userinfo(session->gc, user, user_info, NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1209 purple_notify_user_info_destroy(user_info);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1210 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1211 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1212
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1213 user_to_lookup = g_strdup_printf("%d", uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1214 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1215
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1216 /* Looking up buddy not on blist. Lookup by whatever user entered. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1217 user_to_lookup = g_strdup(user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1218 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1219
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1220 /* Pass the username to msim_get_info_cb(), because since we lookup
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1221 * by userid, the userinfo message will only contain the uid (not
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1222 * the username).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1223 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1224 user_msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1225 "user", MSIM_TYPE_STRING, g_strdup(user),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1226 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1227 purple_debug_info("msim", "msim_get_info, setting up lookup, user=%s\n", user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1228
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1229 msim_lookup_user(session, user_to_lookup, msim_get_info_cb, user_msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1230
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1231 g_free(user_to_lookup);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1232 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1233
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1234 /** Set your status - callback for when user manually sets it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1235 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1236 msim_set_status(PurpleAccount *account, PurpleStatus *status)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1237 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1238 PurpleStatusType *type;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1239 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1240 guint status_code;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1241
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1242 session = (MsimSession *)account->gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1243
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1244 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1245
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1246 type = purple_status_get_type(status);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1247
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1248 switch (purple_status_type_get_primitive(type))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1249 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1250 case PURPLE_STATUS_AVAILABLE:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1251 status_code = MSIM_STATUS_CODE_ONLINE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1252 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1253
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1254 case PURPLE_STATUS_INVISIBLE:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1255 status_code = MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1256 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1257
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1258 case PURPLE_STATUS_AWAY:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1259 status_code = MSIM_STATUS_CODE_AWAY;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1260 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1261
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1262 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1263 purple_debug_info("msim", "msim_set_status: unknown "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1264 "status interpreting as online");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1265 status_code = MSIM_STATUS_CODE_ONLINE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1266 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1267 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1268
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1269
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1270 msim_set_status_code(session, status_code);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1271 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1272
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1273 /** Go idle. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1274 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1275 msim_set_idle(PurpleConnection *gc, int time)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1276 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1277 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1278
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1279 g_return_if_fail(gc != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1280
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1281 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1282
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1283 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1284
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1285 if (time == 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1286 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1287 /* Going back from idle. In msim, idle is mutually exclusive
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1288 * from the other states (you can only be away or idle, but not
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1289 * both, for example), so by going non-idle I go online.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1290 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1291 msim_set_status_code(session, MSIM_STATUS_CODE_ONLINE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1292 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1293 /* msim doesn't support idle time, so just go idle */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1294 msim_set_status_code(session, MSIM_STATUS_CODE_IDLE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1295 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1296 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1297
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1298 /** Set status using an MSIM_STATUS_CODE_* value. (TODO: also set message) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1299 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1300 msim_set_status_code(MsimSession *session, guint status_code)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1301 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1302 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1303
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1304 if (!msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1305 "status", MSIM_TYPE_INTEGER, status_code,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1306 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1307 "statstring", MSIM_TYPE_STRING, g_strdup(""),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1308 "locstring", MSIM_TYPE_STRING, g_strdup("")))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1309 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1310 purple_debug_info("msim", "msim_set_status: failed to set status");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1311 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1312
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1313 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1314
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1315 /** After a uid is resolved to username, tag it with the username and submit for processing.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1316 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1317 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1318 * @param userinfo Response messsage to resolving request.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1319 * @param data MsimMessage *, the message to attach information to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1320 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1321 static void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1322 msim_incoming_resolved(MsimSession *session, MsimMessage *userinfo,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1323 gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1324 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1325 gchar *body_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1326 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1327 gchar *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1328 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1329
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1330 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1331 g_return_if_fail(userinfo != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1332
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1333 body_str = msim_msg_get_string(userinfo, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1334 g_return_if_fail(body_str != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1335 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1336 g_return_if_fail(body != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1337 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1338
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1339 username = g_hash_table_lookup(body, "UserName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1340 g_return_if_fail(username != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1341
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1342 msg = (MsimMessage *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1343 g_return_if_fail(msg != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1344
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1345 /* Special elements name beginning with '_', we'll use internally within the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1346 * program (did not come from the wire). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1347 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1348
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1349 msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1350
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1351 /* TODO: Free copy cloned from msim_preprocess_incoming(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1352 //XXX msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1353 g_hash_table_destroy(body);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1354 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1355
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1356 #if 0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1357 /* Lookup a username by userid, from buddy list.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1358 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1359 * @param wanted_uid
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1360 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1361 * @return Username of wanted_uid, if on blist, or NULL. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1362 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1363 * XXX WARNING: UNKNOWN MEMORY CORRUPTION HERE!
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1364 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1365 static const gchar *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1366 msim_uid2username_from_blist(MsimSession *session, guint wanted_uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1367 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1368 GSList *buddies, *cur;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1369
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1370 buddies = purple_find_buddies(session->account, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1371
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1372 if (!buddies)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1373 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1374 purple_debug_info("msim", "msim_uid2username_from_blist: no buddies?");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1375 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1376 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1377
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1378 for (cur = buddies; cur != NULL; cur = g_slist_next(cur))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1379 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1380 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1381 //PurpleBlistNode *node;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1382 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1383 const gchar *name;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1384
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1385
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1386 /* See finch/gnthistory.c */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1387 buddy = cur->data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1388 //node = cur->data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1389
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1390 uid = purple_blist_node_get_int(&buddy->node, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1391 //uid = purple_blist_node_get_int(node, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1392
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1393 /* name = buddy->name; */ /* crash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1394 /* name = PURPLE_BLIST_NODE_NAME(&buddy->node); */ /* crash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1395
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1396 /* XXX Is this right? Memory corruption here somehow. Happens only
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1397 * when return one of these values. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1398 name = purple_buddy_get_name(buddy); /* crash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1399 //name = purple_buddy_get_name((PurpleBuddy *)node); /* crash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1400 /* return name; */ /* crash (with above) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1401
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1402 /* name = NULL; */ /* no crash */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1403 /* return NULL; */ /* no crash (with anything) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1404
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1405 /* crash =
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1406 *** glibc detected *** pidgin: realloc(): invalid pointer: 0x0000000000d2aec0 ***
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1407 ======= Backtrace: =========
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1408 /lib/libc.so.6(__libc_realloc+0x323)[0x2b7bfc012e03]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1409 /usr/lib/libglib-2.0.so.0(g_realloc+0x31)[0x2b7bfba79a41]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1410 /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_path_append_index+0x3a)[0x2b7bfa110d5a]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1411 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa1287dc]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1412 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa128e56]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1413 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa128efd]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1414 /usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x1b4)[0x2b7bfba72c84]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1415 /usr/lib/libglib-2.0.so.0[0x2b7bfba75acd]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1416 /usr/lib/libglib-2.0.so.0(g_main_loop_run+0x1ca)[0x2b7bfba75dda]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1417 /usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xa3)[0x2b7bfa0475f3]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1418 pidgin(main+0x8be)[0x46b45e]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1419 /lib/libc.so.6(__libc_start_main+0xf4)[0x2b7bfbfbf0c4]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1420 pidgin(gtk_widget_grab_focus+0x39)[0x429ab9]
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1421
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1422 or:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1423 *** glibc detected *** /usr/local/bin/pidgin: malloc(): memory corruption (fast): 0x0000000000c10076 ***
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1424 (gdb) bt
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1425 #0 0x00002b4074ecd47b in raise () from /lib/libc.so.6
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1426 #1 0x00002b4074eceda0 in abort () from /lib/libc.so.6
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1427 #2 0x00002b4074f0453b in __fsetlocking () from /lib/libc.so.6
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1428 #3 0x00002b4074f0c810 in free () from /lib/libc.so.6
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1429 #4 0x00002b4074f0d6dd in malloc () from /lib/libc.so.6
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1430 #5 0x00002b4074974b5b in g_malloc () from /usr/lib/libglib-2.0.so.0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1431 #6 0x00002b40749868bf in g_strdup () from /usr/lib/libglib-2.0.so.0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1432 #7 0x00002b407810969f in msim_parse (
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1433 raw=0xd2a910 "\\bm\\100\\f\\3656574\\msg\\|s|0|ss|Offline")
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1434 at message.c:648
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1435 #8 0x00002b407810889c in msim_input_cb (gc_uncasted=0xcf92c0,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1436 source=<value optimized out>, cond=<value optimized out>) at myspace.c:1478
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1437
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1438
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1439 Why is it crashing in msim_parse()'s g_strdup()?
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1440 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1441 purple_debug_info("msim", "msim_uid2username_from_blist: %s's uid=%d (want %d)\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1442 name, uid, wanted_uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1443
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1444 if (uid == wanted_uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1445 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1446 gchar *ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1447
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1448 ret = g_strdup(name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1449
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1450 g_slist_free(buddies);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1451
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1452 return ret;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1453 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1454 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1455
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1456 g_slist_free(buddies);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1457 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1458 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1459 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1460
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1461 /** Preprocess incoming messages, resolving as needed, calling msim_process() when ready to process.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1462 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1463 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1464 * @param msg MsimMessage *, freed by caller.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1465 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1466 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1467 msim_preprocess_incoming(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1468 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1469 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1470 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1471
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1472 if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1473 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1474 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1475 const gchar *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1476
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1477 /* 'f' = userid message is from, in buddy messages */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1478 uid = msim_msg_get_integer(msg, "f");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1479
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1480 /* TODO: Make caching work. Currently it is commented out because
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1481 * it crashes for unknown reasons, memory realloc error. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1482 #if 0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1483 username = msim_uid2username_from_blist(session, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1484 #else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1485 username = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1486 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1487
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1488 if (username)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1489 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1490 /* Know username already, use it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1491 purple_debug_info("msim", "msim_preprocess_incoming: tagging with _username=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1492 username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1493 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1494 return msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1495
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1496 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1497 gchar *from;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1498
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1499 /* Send lookup request. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1500 /* XXX: where is msim_msg_get_string() freed? make _strdup and _nonstrdup. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1501 purple_debug_info("msim", "msim_incoming: sending lookup, setting up callback\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1502 from = msim_msg_get_string(msg, "f");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1503 msim_lookup_user(session, from, msim_incoming_resolved, msim_msg_clone(msg));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1504 g_free(from);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1505
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1506 /* indeterminate */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1507 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1508 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1509 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1510 /* Nothing to resolve - send directly to processing. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1511 return msim_process(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1512 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1513 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1514
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1515 /** Check if the connection is still alive, based on last communication. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1516 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1517 msim_check_alive(gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1518 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1519 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1520 time_t delta;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1521 gchar *errmsg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1522
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1523 session = (MsimSession *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1524
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1525 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1526
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1527 delta = time(NULL) - session->last_comm;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1528 purple_debug_info("msim", "msim_check_alive: delta=%d\n", delta);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1529 if (delta >= MSIM_KEEPALIVE_INTERVAL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1530 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1531 errmsg = g_strdup_printf(_("Connection to server lost (no data received within %d seconds)"), delta);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1532
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1533 purple_debug_info("msim", "msim_check_alive: %s > interval of %d, presumed dead\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1534 errmsg, MSIM_KEEPALIVE_INTERVAL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1535 purple_connection_error(session->gc, errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1536
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1537 purple_notify_error(session->gc, NULL, errmsg, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1538
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1539 g_free(errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1540
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1541 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1542 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1543
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1544 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1545 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1546
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1547 /** Called when the session key arrives. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1548 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1549 msim_we_are_logged_on(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1550 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1551 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1552 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1553
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1554 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1555
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1556 session->sesskey = msim_msg_get_integer(msg, "sesskey");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1557 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1558
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1559 /* Comes with: proof,profileid,userid,uniquenick -- all same values
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1560 * some of the time, but can vary. This is our own user ID. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1561 session->userid = msim_msg_get_integer(msg, "userid");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1562
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1563 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1564
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1565 /* We now know are our own username, only after we're logged in..
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1566 * which is weird, but happens because you login with your email
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1567 * address and not username. Will be freed in msim_session_destroy(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1568 session->username = msim_msg_get_string(msg, "uniquenick");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1569
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1570 #ifdef MSIM_FAKE_SELF_ONLINE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1571 /* Fake our self coming online. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1572 purple_prpl_got_user_status(session->account, session->username, purple_primitive_get_id_from_type(PURPLE_STATUS_AVAILABLE), NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1573 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1574
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1575
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1576 /* Set status to current status. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1577 msim_set_status(session->account,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1578 purple_account_get_active_status(session->account));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1579
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1580 purple_timeout_add(MSIM_KEEPALIVE_INTERVAL_CHECK, msim_check_alive, session);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1581
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1582 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1583 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1584
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1585 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1586 * Process a message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1587 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1588 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1589 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1590 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1591 * @return TRUE if successful. FALSE if processing failed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1592 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1593 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1594 msim_process(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1595 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1596 g_return_val_if_fail(session != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1597 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1598
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1599 #ifdef MSIM_DEBUG_MSG
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1600 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1601 msim_msg_dump("ready to process: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1602 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1603 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1604
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1605 if (msim_msg_get(msg, "nc"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1606 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1607 return msim_login_challenge(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1608 } else if (msim_msg_get(msg, "sesskey")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1609 return msim_we_are_logged_on(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1610 } else if (msim_msg_get(msg, "bm")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1611 guint bm;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1612
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1613 bm = msim_msg_get_integer(msg, "bm");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1614 switch (bm)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1615 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1616 case MSIM_BM_STATUS:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1617 return msim_status(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1618 case MSIM_BM_INSTANT:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1619 return msim_incoming_im(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1620 case MSIM_BM_ACTION:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1621 return msim_incoming_action(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1622 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1623 /* Not really an IM, but show it for informational
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1624 * purposes during development. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1625 return msim_incoming_im(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1626 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1627 } else if (msim_msg_get(msg, "rid")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1628 return msim_process_reply(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1629 } else if (msim_msg_get(msg, "error")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1630 return msim_error(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1631 } else if (msim_msg_get(msg, "ka")) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1632 /* TODO: Setup a timer, if keep-alive is not received within ~3 minutes, then
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1633 * disconnect the user. As it stands, if Internet connection goes out (this
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1634 * just happened here), msimprpl will appear to be connected forever, while
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1635 * other plugins (oscar, etc.) will time out. Msimprpl should timeout too. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1636 purple_debug_info("msim", "msim_process: got keep alive\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1637 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1638 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1639 msim_unrecognized(session, msg, "in msim_process");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1640 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1641 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1642 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1643
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1644 /** Store an field of information about a buddy. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1645 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1646 msim_store_buddy_info_each(gpointer key, gpointer value, gpointer user_data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1647 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1648 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1649 gchar *key_str, *value_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1650
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1651 buddy = (PurpleBuddy *)user_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1652 key_str = (gchar *)key;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1653 value_str = (gchar *)value;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1654
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1655 if (strcmp(key_str, "UserID") == 0 ||
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1656 strcmp(key_str, "Age") == 0 ||
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1657 strcmp(key_str, "TotalFriends") == 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1658 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1659 /* Certain fields get set as integers, instead of strings, for
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1660 * convenience. May not be the best way to do it, but having at least
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1661 * UserID as an integer is convenient...until it overflows! */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1662 purple_blist_node_set_int(&buddy->node, key_str, atol(value_str));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1663 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1664 purple_blist_node_set_string(&buddy->node, key_str, value_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1665 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1666 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1667
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1668 /** Save buddy information to the buddy list from a user info reply message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1669 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1670 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1671 * @param msg The user information reply, with any amount of information.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1672 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1673 * The information is saved to the buddy's blist node, which ends up in blist.xml.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1674 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1675 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1676 msim_store_buddy_info(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1677 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1678 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1679 gchar *username, *body_str, *uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1680 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1681 guint rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1682
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1683 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1684 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1685
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1686 rid = msim_msg_get_integer(msg, "rid");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1687
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1688 g_return_val_if_fail(rid != 0, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1689
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1690 body_str = msim_msg_get_string(msg, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1691 g_return_val_if_fail(body_str != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1692 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1693 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1694
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1695 /* TODO: implement a better hash-like interface, and use it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1696 username = g_hash_table_lookup(body, "UserName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1697
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1698 if (!username)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1699 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1700 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1701 "msim_process_reply: not caching body, no UserName\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1702 return FALSE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1703 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1704
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1705 uid = g_hash_table_lookup(body, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1706 g_return_val_if_fail(uid, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1707
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1708 purple_debug_info("msim", "associating uid %d with username %s\n", uid, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1709
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1710 buddy = purple_find_buddy(session->account, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1711 if (buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1712 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1713 g_hash_table_foreach(body, msim_store_buddy_info_each, buddy);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1714 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1715
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1716 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1717 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1718
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1719 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1720 * Process a persistance message reply from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1721 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1722 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1723 * @param msg Message reply from server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1724 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1725 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1726 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1727 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1728 msim_process_reply(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1729 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1730 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1731 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1732
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1733 if (msim_msg_get(msg, "rid")) /* msim_lookup_user sets callback for here */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1734 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1735 MSIM_USER_LOOKUP_CB cb;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1736 gpointer data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1737 guint rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1738
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1739 msim_store_buddy_info(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1740
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1741 rid = msim_msg_get_integer(msg, "rid");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1742
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1743 /* If a callback is registered for this userid lookup, call it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1744 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1745 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1746
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1747 if (cb)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1748 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1749 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1750 "msim_process_body: calling callback now\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1751 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1752 cb(session, msim_msg_clone(msg), data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1753 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1754 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1755 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1756 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1757 "msim_process_body: no callback for rid %d\n", rid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1758 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1759 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1760
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1761 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1762 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1763
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1764 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1765 * Handle an error from the server.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1766 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1767 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1768 * @param msg The message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1769 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1770 * @return TRUE if successfully reported error.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1771 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1772 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1773 msim_error(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1774 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1775 gchar *errmsg, *full_errmsg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1776 guint err;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1777
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1778 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1779 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1780
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1781 err = msim_msg_get_integer(msg, "err");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1782 errmsg = msim_msg_get_string(msg, "errmsg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1783
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1784 full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1785 errmsg ? errmsg : "no 'errmsg' given");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1786
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1787 g_free(errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1788
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1789 purple_debug_info("msim", "msim_error: %s\n", full_errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1790
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1791 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1792 full_errmsg, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1793
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1794 /* Destroy session if fatal. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1795 if (msim_msg_get(msg, "fatal"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1796 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1797 purple_debug_info("msim", "fatal error, closing\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1798 purple_connection_error(session->gc, full_errmsg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1799 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1800
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1801 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1802 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1803
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1804 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1805 * Process incoming status messages.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1806 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1807 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1808 * @param msg Status update message. Caller frees.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1809 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1810 * @return TRUE if successful.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1811 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1812 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1813 msim_status(MsimSession *session, MsimMessage *msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1814 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1815 PurpleBuddyList *blist;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1816 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1817 //PurpleStatus *status;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1818 gchar **status_array;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1819 GList *list;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1820 gchar *status_headline;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1821 gchar *status_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1822 gint i, status_code, purple_status_code;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1823 gchar *username;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1824
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1825 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1826 g_return_val_if_fail(msg != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1827
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1828 status_str = msim_msg_get_string(msg, "msg");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1829 g_return_val_if_fail(status_str != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1830
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1831 msim_msg_dump("msim_status msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1832
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1833 /* Helpfully looked up by msim_incoming_resolve() for us. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1834 username = msim_msg_get_string(msg, "_username");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1835 /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1836 * the buddy list, if the UserID was stored along with it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1837
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1838 if (username == NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1839 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1840 g_free(status_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1841 g_return_val_if_fail(NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1842 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1843
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1844 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1845 "msim_status: updating status for <%s> to <%s>\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1846 username, status_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1847
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1848 /* TODO: generic functions to split into a GList, part of MsimMessage */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1849 status_array = g_strsplit(status_str, "|", 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1850 for (list = NULL, i = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1851 status_array[i];
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1852 i++)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1853 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1854 /* Note: this adds the 0th ordinal too, which might not be a value
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1855 * at all (the 0 in the 0|1|2|3... status fields, but 0 always appears blank).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1856 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1857 list = g_list_append(list, status_array[i]);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1858 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1859
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1860 /* Example fields:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1861 * |s|0|ss|Offline
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1862 * |s|1|ss|:-)|ls||ip|0|p|0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1863 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1864 * TODO: write list support in MsimMessage, and use it here.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1865 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1866
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1867 status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1868 purple_debug_info("msim", "msim_status: %s's status code = %d\n", username, status_code);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1869 status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1870
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1871 blist = purple_get_blist();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1872
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1873 /* Add buddy if not found */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1874 buddy = purple_find_buddy(session->account, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1875 if (!buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1876 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1877 purple_debug_info("msim",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1878 "msim_status: making new buddy for %s\n", username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1879 buddy = purple_buddy_new(session->account, username, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1880
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1881 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1882
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1883 /* All buddies on list should have 'uid' integer associated with them. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1884 purple_blist_node_set_int(&buddy->node, "UserID", msim_msg_get_integer(msg, "f"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1885
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1886 msim_store_buddy_info(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1887 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1888 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1889 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1890
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1891 purple_blist_node_set_string(&buddy->node, "Headline", status_headline);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1892
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1893 /* Set user status */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1894 switch (status_code)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1895 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1896 case MSIM_STATUS_CODE_OFFLINE_OR_HIDDEN:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1897 purple_status_code = PURPLE_STATUS_OFFLINE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1898 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1899
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1900 case MSIM_STATUS_CODE_ONLINE:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1901 purple_status_code = PURPLE_STATUS_AVAILABLE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1902 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1903
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1904 case MSIM_STATUS_CODE_AWAY:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1905 purple_status_code = PURPLE_STATUS_AWAY;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1906 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1907
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1908 case MSIM_STATUS_CODE_IDLE:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1909 /* will be handled below */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1910 purple_status_code = -1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1911 break;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1912
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1913 default:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1914 purple_debug_info("msim", "msim_status for %s, unknown status code %d, treating as available\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1915 username, status_code);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1916 purple_status_code = PURPLE_STATUS_AVAILABLE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1917 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1918
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1919 #ifdef MSIM_FAKE_SELF_ONLINE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1920 if (!strcmp(username, session->username) && purple_status_code == PURPLE_STATUS_OFFLINE)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1921 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1922 /* Hack to ignore offline status notices on self. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1923 } else if (status_code != MSIM_STATUS_CODE_IDLE) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1924 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1925 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1926 #ifdef MSIM_FAKE_SELF_ONLINE
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1927 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1928 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1929
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1930 if (status_code == MSIM_STATUS_CODE_IDLE)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1931 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1932 purple_debug_info("msim", "msim_status: got idle: %s\n", username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1933 purple_prpl_got_user_idle(session->account, username, TRUE, time(NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1934 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1935 /* All other statuses indicate going back to non-idle. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1936 purple_prpl_got_user_idle(session->account, username, FALSE, time(NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1937 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1938
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1939 g_strfreev(status_array);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1940 g_free(status_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1941 g_free(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1942 g_list_free(list);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1943
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1944 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1945 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1946
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1947 /** Add a buddy to user's buddy list. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1948 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1949 msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1950 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1951 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1952 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1953 /* MsimMessage *msg_blocklist; */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1954
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1955 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1956 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", buddy->name,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1957 group ? group->name : "(no group)");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1958
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1959 msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1960 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1961 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1962 /* "newprofileid" will be inserted here with uid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1963 "reason", MSIM_TYPE_STRING, g_strdup(""),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1964 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1965
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1966 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason"))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1967 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1968 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed."));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1969 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1970 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1971 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1972 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1973
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1974 /* TODO: if addbuddy fails ('error' message is returned), delete added buddy from
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1975 * buddy list since Purple adds it locally. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1976
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1977 /* TODO: Update blocklist. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1978 #if 0
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1979 msg_blocklist = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1980 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1981 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1982 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1983 "dsn", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_DSN,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1984 "lid", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_LID,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1985 /* TODO: Use msim_new_reply_callback to get rid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1986 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1987 "body", MSIM_TYPE_STRING,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1988 g_strdup_printf("ContactID=<uid>\034"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1989 "GroupName=%s\034"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1990 "Position=1000\034"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1991 "Visibility=1\034"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1992 "NickName=\034"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1993 "NameSelect=0",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1994 "Friends" /*group->name*/ ));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1995
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1996 if (!msim_postprocess_outgoing(session, msg, buddy->name, "body", NULL))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1997 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1998 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
1999 msim_msg_free(msg_blocklist);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2000 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2001 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2002 msim_msg_free(msg_blocklist);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2003 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2004 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2005
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2006 /** Perform actual postprocessing on a message, adding userid as specified.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2007 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2008 * @param msg The message to postprocess.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2009 * @param uid_before Name of field where to insert new field before, or NULL for end.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2010 * @param uid_field_name Name of field to add uid to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2011 * @param uid The userid to insert.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2012 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2013 * If the field named by uid_field_name already exists, then its string contents will
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2014 * be used for the field, except "<uid>" will be replaced by the userid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2015 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2016 * If the field named by uid_field_name does not exist, it will be added before the
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2017 * field named by uid_before, as an integer, with the userid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2018 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2019 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing().
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2020 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2021 MsimMessage *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2022 msim_do_postprocessing(MsimMessage *msg, const gchar *uid_before,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2023 const gchar *uid_field_name, guint uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2024 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2025 purple_debug_info("msim", "msim_do_postprocessing called with ufn=%s, ub=%s, uid=%d\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2026 uid_field_name, uid_before, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2027 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2028
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2029 /* First, check - if the field already exists, treat it as a format string. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2030 if (msim_msg_get(msg, uid_field_name))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2031 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2032 MsimMessageElement *elem;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2033 gchar *fmt_string;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2034 gchar *uid_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2035
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2036 /* Warning: this probably violates the encapsulation of MsimMessage */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2037
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2038 elem = msim_msg_get(msg, uid_field_name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2039 g_return_val_if_fail(elem->type == MSIM_TYPE_STRING, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2040
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2041 /* Get the raw string, not with msim_msg_get_string() since that copies it.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2042 * Want the original string so can free it. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2043 fmt_string = (gchar *)(elem->data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2044
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2045 uid_str = g_strdup_printf("%d", uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2046 elem->data = str_replace(fmt_string, "<uid>", uid_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2047 g_free(uid_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2048 g_free(fmt_string);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2049
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2050 purple_debug_info("msim", "msim_postprocess_outgoing_cb: formatted new string, %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2051 elem->data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2052
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2053 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2054 /* Otherwise, insert new field into outgoing message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2055 msg = msim_msg_insert_before(msg, uid_before, uid_field_name, MSIM_TYPE_INTEGER, GUINT_TO_POINTER(uid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2056 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2057
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2058 return msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2059 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2060
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2061 /** Callback for msim_postprocess_outgoing() to add a userid to a message, and send it (once receiving userid).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2062 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2063 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2064 * @param userinfo The user information reply message, containing the user ID
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2065 * @param data The message to postprocess and send.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2066 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2067 * The data message should contain these fields:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2068 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2069 * _uid_field_name: string, name of field to add with userid from userinfo message
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2070 * _uid_before: string, name of field before field to insert, or NULL for end
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2071 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2072 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2073 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2074 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2075 msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2076 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2077 gchar *body_str;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2078 GHashTable *body;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2079 gchar *uid, *uid_field_name, *uid_before;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2080 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2081
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2082 msg = (MsimMessage *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2083
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2084 msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2085
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2086 /* Obtain userid from userinfo message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2087 body_str = msim_msg_get_string(userinfo, "body");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2088 g_return_if_fail(body_str != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2089 body = msim_parse_body(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2090 g_free(body_str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2091
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2092 uid = g_strdup(g_hash_table_lookup(body, "UserID"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2093 g_hash_table_destroy(body);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2094
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2095 uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2096 uid_before = msim_msg_get_string(msg, "_uid_before");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2097
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2098 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, atol(uid));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2099
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2100 /* Send */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2101 if (!msim_msg_send(session, msg))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2102 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2103 purple_debug_info("msim", "msim_postprocess_outgoing_cb: sending failed for message: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2104 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2105
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2106
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2107 /* Free field names AFTER sending message, because MsimMessage does NOT copy
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2108 * field names - instead, treats them as static strings (which they usually are).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2109 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2110 g_free(uid_field_name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2111 g_free(uid_before);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2112
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2113 //msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2114 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2115
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2116 /** Postprocess and send a message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2117 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2118 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2119 * @param msg Message to postprocess. Will NOT be freed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2120 * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2121 * @param uid_field_name Name of new field to add, containing uid of username. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2122 * @param uid_before Name of existing field to insert username field before. Static string.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2123 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2124 * @return Postprocessed message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2125 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2126 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2127 msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2128 const gchar *username, const gchar *uid_field_name,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2129 const gchar *uid_before)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2130 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2131 PurpleBuddy *buddy;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2132 guint uid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2133 gboolean rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2134
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2135 /* Store information for msim_postprocess_outgoing_cb(). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2136 purple_debug_info("msim", "msim_postprocess_outgoing(u=%s,ufn=%s,ub=%s)\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2137 username, uid_field_name, uid_before);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2138 msim_msg_dump("msim_postprocess_outgoing: msg before=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2139 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2140 msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2141 msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2142
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2143 /* First, try the most obvious. If numeric userid is given, use that directly. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2144 if (msim_is_userid(username))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2145 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2146 uid = atol(username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2147 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2148 /* Next, see if on buddy list and know uid. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2149 buddy = purple_find_buddy(session->account, username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2150 if (buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2151 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2152 uid = purple_blist_node_get_int(&buddy->node, "UserID");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2153 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2154 uid = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2155 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2156
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2157 if (!buddy || !uid)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2158 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2159 /* Don't have uid offhand - need to ask for it, and wait until hear back before sending. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2160 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2161 username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2162 msim_msg_dump("msim_postprocess_outgoing - scheduling lookup, msg=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2163 /* TODO: where is cloned message freed? Should be in _cb. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2164 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2165 return TRUE; /* not sure of status yet - haven't sent! */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2166 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2167 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2168
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2169 /* Already have uid, postprocess and send msg immediately. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2170 purple_debug_info("msim", "msim_postprocess_outgoing: found username %s has uid %d\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2171 username, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2172
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2173 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, uid);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2174
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2175 msim_msg_dump("msim_postprocess_outgoing: msg after (uid immediate)=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2176
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2177 rc = msim_msg_send(session, msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2178
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2179 //msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2180
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2181 return rc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2182 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2183
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2184 /** Remove a buddy from the user's buddy list. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2185 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2186 msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2187 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2188 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2189 MsimMessage *delbuddy_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2190 MsimMessage *persist_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2191 MsimMessage *blocklist_msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2192
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2193 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2194
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2195 delbuddy_msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2196 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2197 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2198 /* 'delprofileid' with uid will be inserted here. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2199 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2200 /* TODO: free msg */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2201 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2202 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2203 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2204 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2205 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2206
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2207 persist_msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2208 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2209 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2210 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2211 "dsn", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_DSN,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2212 "lid", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_LID,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2213 "uid", MSIM_TYPE_INTEGER, session->userid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2214 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2215 /* <uid> will be replaced by postprocessing */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2216 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2217 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2218
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2219 /* TODO: free msg */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2220 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2221 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2222 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2223 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2224 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2225
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2226 blocklist_msg = msim_msg_new(TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2227 "blocklist", MSIM_TYPE_BOOLEAN, TRUE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2228 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2229 /* TODO: MsimMessage lists */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2230 "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2231 NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2232
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2233 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2234 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2235 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2236 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2237 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2238 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2239
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2240 /** Return whether the buddy can be messaged while offline.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2241 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2242 * The protocol supports offline messages in just the same way as online
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2243 * messages.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2244 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2245 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2246 msim_offline_message(const PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2247 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2248 return TRUE;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2249 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2250
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2251 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2252 * Callback when input available.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2253 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2254 * @param gc_uncasted A PurpleConnection pointer.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2255 * @param source File descriptor.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2256 * @param cond PURPLE_INPUT_READ
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2257 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2258 * Reads the input, and calls msim_preprocess_incoming() to handle it.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2259 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2260 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2261 msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2262 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2263 PurpleConnection *gc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2264 PurpleAccount *account;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2265 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2266 gchar *end;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2267 int n;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2268
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2269 g_return_if_fail(gc_uncasted != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2270 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2271
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2272 gc = (PurpleConnection *)(gc_uncasted);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2273 account = purple_connection_get_account(gc);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2274 session = gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2275
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2276 g_return_if_fail(cond == PURPLE_INPUT_READ);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2277 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2278
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2279 /* Mark down that we got data, so don't timeout. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2280 session->last_comm = time(NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2281
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2282 /* Only can handle so much data at once...
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2283 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2284 * Should be large enough to hold the largest protocol message.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2285 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2286 if (session->rxoff == MSIM_READ_BUF_SIZE)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2287 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2288 purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2289 MSIM_READ_BUF_SIZE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2290 purple_connection_error(gc, _("Read buffer full"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2291 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2292 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2293
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2294 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2295 session->rxoff, MSIM_READ_BUF_SIZE,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2296 MSIM_READ_BUF_SIZE - session->rxoff);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2297
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2298 /* Read into buffer. On Win32, need recv() not read(). session->fd also holds
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2299 * the file descriptor, but it sometimes differs from the 'source' parameter.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2300 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2301 n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2302
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2303 if (n < 0 && errno == EAGAIN)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2304 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2305 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2306 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2307 else if (n < 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2308 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2309 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2310 "error=%s, source=%d, fd=%d (%X))\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2311 n, strerror(errno), source, session->fd, session->fd);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2312 purple_connection_error(gc, _("Read error"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2313 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2314 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2315 else if (n == 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2316 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2317 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2318 purple_connection_error(gc, _("Server has disconnected"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2319 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2320 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2321
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2322 /* Null terminate */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2323 session->rxbuf[session->rxoff + n] = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2324
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2325 #ifdef MSIM_CHECK_EMBEDDED_NULLS
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2326 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2327 if (strlen(session->rxbuf + session->rxoff) != n)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2328 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2329 /* Occurs after login, but it is not a null byte. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2330 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2331 "--null byte encountered?\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2332 strlen(session->rxbuf + session->rxoff), n);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2333 //purple_connection_error(gc, "Invalid message - null byte on input");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2334 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2335 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2336 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2337
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2338 session->rxoff += n;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2339 purple_debug_info("msim", "msim_input_cb: read=%d\n", n);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2340
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2341 #ifdef MSIM_DEBUG_RXBUF
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2342 purple_debug_info("msim", "buf=<%s>\n", session->rxbuf);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2343 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2344
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2345 /* Look for \\final\\ end markers. If found, process message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2346 while((end = strstr(session->rxbuf, MSIM_FINAL_STRING)))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2347 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2348 MsimMessage *msg;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2349
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2350 #ifdef MSIM_DEBUG_RXBUF
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2351 purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2352 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2353 *end = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2354 msg = msim_parse(g_strdup(session->rxbuf));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2355 if (!msg)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2356 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2357 purple_debug_info("msim", "msim_input_cb: couldn't parse <%s>\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2358 session->rxbuf);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2359 purple_connection_error(gc, _("Unparseable message"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2360 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2361 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2362 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2363 /* Process message and then free it (processing function should
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2364 * clone message if it wants to keep it afterwards.) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2365 if (!msim_preprocess_incoming(session, msg))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2366 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2367 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2368 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2369 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2370 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2371
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2372 /* Move remaining part of buffer to beginning. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2373 session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2374 memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2375 MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2376
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2377 /* Clear end of buffer */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2378 //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2379 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2380 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2381
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2382 /* Setup a callback, to be called when a reply is received with the returned rid.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2383 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2384 * @param cb The callback, an MSIM_USER_LOOKUP_CB.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2385 * @param data Arbitrary user data to be passed to callback (probably an MsimMessage *).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2386 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2387 * @return The request/reply ID, used to link replies with requests. Put the rid in your request.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2388 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2389 * TODO: Make more generic and more specific:
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2390 * 1) MSIM_USER_LOOKUP_CB - make it for PERSIST_REPLY, not just user lookup
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2391 * 2) data - make it an MsimMessage?
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2392 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2393 guint
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2394 msim_new_reply_callback(MsimSession *session, MSIM_USER_LOOKUP_CB cb,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2395 gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2396 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2397 guint rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2398
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2399 rid = session->next_rid++;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2400
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2401 g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2402 g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2403
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2404 return rid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2405 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2406
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2407 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2408 * Callback when connected. Sets up input handlers.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2409 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2410 * @param data A PurpleConnection pointer.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2411 * @param source File descriptor.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2412 * @param error_message
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2413 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2414 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2415 msim_connect_cb(gpointer data, gint source, const gchar *error_message)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2416 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2417 PurpleConnection *gc;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2418 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2419
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2420 g_return_if_fail(data != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2421
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2422 gc = (PurpleConnection *)data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2423 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2424
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2425 if (source < 0)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2426 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2427 purple_connection_error(gc, _("Couldn't connect to host"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2428 purple_connection_error(gc, g_strdup_printf(
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2429 _("Couldn't connect to host: %s (%d)"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2430 error_message ? error_message : "no message given",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2431 source));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2432 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2433 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2434
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2435 session->fd = source;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2436
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2437 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2438
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2439
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2440 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2441
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2442 /* Session methods */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2443
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2444 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2445 * Create a new MSIM session.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2446 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2447 * @param acct The account to create the session from.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2448 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2449 * @return Pointer to a new session. Free with msim_session_destroy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2450 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2451 MsimSession *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2452 msim_session_new(PurpleAccount *acct)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2453 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2454 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2455
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2456 g_return_val_if_fail(acct != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2457
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2458 session = g_new0(MsimSession, 1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2459
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2460 session->magic = MSIM_SESSION_STRUCT_MAGIC;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2461 session->account = acct;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2462 session->gc = purple_account_get_connection(acct);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2463 session->sesskey = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2464 session->userid = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2465 session->username = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2466 session->fd = -1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2467
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2468 /* TODO: Remove. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2469 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2470 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2471 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2472 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2473 they could be integers inside gpointers
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2474 or strings, so I don't freed them.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2475 Figure this out, once free cache. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2476 session->rxoff = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2477 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2478 session->next_rid = 1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2479 session->last_comm = time(NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2480
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2481 return session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2482 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2483
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2484 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2485 * Free a session.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2486 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2487 * @param session The session to destroy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2488 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2489 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2490 msim_session_destroy(MsimSession *session)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2491 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2492 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2493
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2494 session->magic = -1;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2495
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2496 g_free(session->rxbuf);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2497 g_free(session->username);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2498
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2499 /* TODO: Remove. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2500 g_hash_table_destroy(session->user_lookup_cb);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2501 g_hash_table_destroy(session->user_lookup_cb_data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2502
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2503 g_free(session);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2504 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2505
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2506 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2507 * Close the connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2508 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2509 * @param gc The connection.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2510 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2511 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2512 msim_close(PurpleConnection *gc)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2513 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2514 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2515
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2516 if (gc == NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2517 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2518
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2519 session = (MsimSession *)gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2520 if (session == NULL)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2521 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2522
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2523 gc->proto_data = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2524
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2525 if (!MSIM_SESSION_VALID(session))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2526 return;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2527
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2528 if (session->gc->inpa)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2529 purple_input_remove(session->gc->inpa);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2530
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2531 msim_session_destroy(session);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2532 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2533
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2534
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2535 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2536 * Check if a string is a userid (all numeric).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2537 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2538 * @param user The user id, email, or name.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2539 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2540 * @return TRUE if is userid, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2541 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2542 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2543 msim_is_userid(const gchar *user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2544 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2545 g_return_val_if_fail(user != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2546
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2547 return strspn(user, "0123456789") == strlen(user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2548 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2549
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2550 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2551 * Check if a string is an email address (contains an @).
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2552 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2553 * @param user The user id, email, or name.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2554 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2555 * @return TRUE if is an email, FALSE if not.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2556 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2557 * This function is not intended to be used as a generic
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2558 * means of validating email addresses, but to distinguish
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2559 * between a user represented by an email address from
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2560 * other forms of identification.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2561 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2562 gboolean
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2563 msim_is_email(const gchar *user)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2564 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2565 g_return_val_if_fail(user != NULL, FALSE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2566
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2567 return strchr(user, '@') != NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2568 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2569
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2570
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2571 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2572 * Asynchronously lookup user information, calling callback when receive result.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2573 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2574 * @param session
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2575 * @param user The user id, email address, or username. Not freed.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2576 * @param cb Callback, called with user information when available.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2577 * @param data An arbitray data pointer passed to the callback.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2578 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2579 /* TODO: change to not use callbacks */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2580 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2581 msim_lookup_user(MsimSession *session, const gchar *user,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2582 MSIM_USER_LOOKUP_CB cb, gpointer data)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2583 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2584 gchar *field_name;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2585 guint rid, cmd, dsn, lid;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2586
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2587 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2588 g_return_if_fail(user != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2589 g_return_if_fail(cb != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2590
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2591 purple_debug_info("msim", "msim_lookup_userid: "
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2592 "asynchronously looking up <%s>\n", user);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2593
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2594 msim_msg_dump("msim_lookup_user: data=%s\n", (MsimMessage *)data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2595
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2596 /* Setup callback. Response will be associated with request using 'rid'. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2597 rid = msim_new_reply_callback(session, cb, data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2598
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2599 /* Send request */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2600
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2601 cmd = MSIM_CMD_GET;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2602
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2603 if (msim_is_userid(user))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2604 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2605 field_name = "UserID";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2606 dsn = MG_MYSPACE_INFO_BY_ID_DSN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2607 lid = MG_MYSPACE_INFO_BY_ID_LID;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2608 } else if (msim_is_email(user)) {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2609 field_name = "Email";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2610 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2611 lid = MG_MYSPACE_INFO_BY_STRING_LID;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2612 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2613 field_name = "UserName";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2614 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2615 lid = MG_MYSPACE_INFO_BY_STRING_LID;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2616 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2617
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2618
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2619 g_return_if_fail(msim_send(session,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2620 "persist", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2621 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2622 "cmd", MSIM_TYPE_INTEGER, 1,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2623 "dsn", MSIM_TYPE_INTEGER, dsn,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2624 "uid", MSIM_TYPE_INTEGER, session->userid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2625 "lid", MSIM_TYPE_INTEGER, lid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2626 "rid", MSIM_TYPE_INTEGER, rid,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2627 /* TODO: dictionary field type */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2628 "body", MSIM_TYPE_STRING,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2629 g_strdup_printf("%s=%s", field_name, user),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2630 NULL));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2631 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2632
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2633
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2634 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2635 * Obtain the status text for a buddy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2636 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2637 * @param buddy The buddy to obtain status text for.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2638 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2639 * @return Status text, or NULL if error. Caller g_free()'s.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2640 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2641 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2642 char *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2643 msim_status_text(PurpleBuddy *buddy)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2644 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2645 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2646 const gchar *display_name, *headline;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2647
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2648 g_return_val_if_fail(buddy != NULL, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2649
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2650 session = (MsimSession *)buddy->account->gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2651 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2652
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2653 display_name = headline = NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2654
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2655 /* Retrieve display name and/or headline, depending on user preference. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2656 if (purple_account_get_bool(session->account, "show_display_name", TRUE))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2657 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2658 display_name = purple_blist_node_get_string(&buddy->node, "DisplayName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2659 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2660
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2661 if (purple_account_get_bool(session->account, "show_headline", FALSE))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2662 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2663 headline = purple_blist_node_get_string(&buddy->node, "Headline");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2664 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2665
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2666 /* Return appropriate combination of display name and/or headline, or neither. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2667
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2668 if (display_name && headline)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2669 return g_strconcat(display_name, " ", headline, NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2670
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2671 if (display_name)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2672 return g_strdup(display_name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2673
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2674 if (headline)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2675 return g_strdup(headline);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2676
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2677 return NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2678 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2679
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2680 /**
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2681 * Obtain the tooltip text for a buddy.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2682 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2683 * @param buddy Buddy to obtain tooltip text on.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2684 * @param user_info Variable modified to have the tooltip text.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2685 * @param full TRUE if should obtain full tooltip text.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2686 *
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2687 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2688 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2689 msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2690 gboolean full)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2691 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2692 const gchar *str, *str2;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2693 gint n;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2694
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2695 g_return_if_fail(buddy != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2696 g_return_if_fail(user_info != NULL);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2697
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2698 if (PURPLE_BUDDY_IS_ONLINE(buddy))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2699 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2700 MsimSession *session;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2701
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2702 session = (MsimSession *)buddy->account->gc->proto_data;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2703
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2704 g_return_if_fail(MSIM_SESSION_VALID(session));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2705
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2706 /* TODO: if (full), do something different */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2707
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2708 /* Useful to identify the account the tooltip refers to.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2709 * Other prpls show this. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2710 str = purple_blist_node_get_string(&buddy->node, "UserName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2711 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2712 purple_notify_user_info_add_pair(user_info, _("User Name"), str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2713
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2714 /* a/s/l...the vitals */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2715 n = purple_blist_node_get_int(&buddy->node, "Age");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2716 if (n)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2717 purple_notify_user_info_add_pair(user_info, _("Age"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2718 g_strdup_printf("%d", n));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2719
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2720 str = purple_blist_node_get_string(&buddy->node, "Gender");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2721 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2722 purple_notify_user_info_add_pair(user_info, _("Gender"), str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2723
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2724 str = purple_blist_node_get_string(&buddy->node, "Location");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2725 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2726 purple_notify_user_info_add_pair(user_info, _("Location"), str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2727
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2728 /* Other information */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2729 str = purple_blist_node_get_string(&buddy->node, "Headline");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2730 if (str)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2731 purple_notify_user_info_add_pair(user_info, _("Headline"), str);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2732
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2733 str = purple_blist_node_get_string(&buddy->node, "BandName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2734 str2 = purple_blist_node_get_string(&buddy->node, "SongName");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2735 if (str || str2)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2736 purple_notify_user_info_add_pair(user_info, _("Song"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2737 g_strdup_printf("%s - %s",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2738 str ? str : _("Unknown Artist"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2739 str2 ? str2 : _("Unknown Song")));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2740
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2741 n = purple_blist_node_get_int(&buddy->node, "TotalFriends");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2742 if (n)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2743 purple_notify_user_info_add_pair(user_info, _("Total Friends"),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2744 g_strdup_printf("%d", n));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2745
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2746 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2747 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2748
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2749 /** Callbacks called by Purple, to access this plugin. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2750 PurplePluginProtocolInfo prpl_info =
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2751 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2752 /* options */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2753 OPT_PROTO_USE_POINTSIZE /* specify font size in sane point size */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2754 /* | OPT_PROTO_MAIL_CHECK - TODO: myspace will notify of mail */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2755 /* | OPT_PROTO_IM_IMAGE - TODO: direct images. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2756 ,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2757 NULL, /* user_splits */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2758 NULL, /* protocol_options */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2759 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2760 msim_list_icon, /* list_icon */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2761 NULL, /* list_emblems */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2762 msim_status_text, /* status_text */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2763 msim_tooltip_text, /* tooltip_text */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2764 msim_status_types, /* status_types */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2765 NULL, /* blist_node_menu */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2766 NULL, /* chat_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2767 NULL, /* chat_info_defaults */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2768 msim_login, /* login */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2769 msim_close, /* close */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2770 msim_send_im, /* send_im */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2771 NULL, /* set_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2772 msim_send_typing, /* send_typing */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2773 msim_get_info, /* get_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2774 msim_set_status, /* set_status */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2775 msim_set_idle, /* set_idle */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2776 NULL, /* change_passwd */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2777 msim_add_buddy, /* add_buddy */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2778 NULL, /* add_buddies */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2779 msim_remove_buddy, /* remove_buddy */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2780 NULL, /* remove_buddies */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2781 NULL, /* add_permit */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2782 NULL, /* add_deny */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2783 NULL, /* rem_permit */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2784 NULL, /* rem_deny */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2785 NULL, /* set_permit_deny */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2786 NULL, /* join_chat */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2787 NULL, /* reject chat invite */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2788 NULL, /* get_chat_name */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2789 NULL, /* chat_invite */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2790 NULL, /* chat_leave */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2791 NULL, /* chat_whisper */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2792 NULL, /* chat_send */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2793 NULL, /* keepalive */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2794 NULL, /* register_user */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2795 NULL, /* get_cb_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2796 NULL, /* get_cb_away */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2797 NULL, /* alias_buddy */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2798 NULL, /* group_buddy */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2799 NULL, /* rename_group */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2800 NULL, /* buddy_free */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2801 NULL, /* convo_closed */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2802 NULL, /* normalize */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2803 NULL, /* set_buddy_icon */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2804 NULL, /* remove_group */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2805 NULL, /* get_cb_real_name */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2806 NULL, /* set_chat_topic */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2807 NULL, /* find_blist_chat */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2808 NULL, /* roomlist_get_list */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2809 NULL, /* roomlist_cancel */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2810 NULL, /* roomlist_expand_category */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2811 NULL, /* can_receive_file */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2812 NULL, /* send_file */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2813 NULL, /* new_xfer */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2814 msim_offline_message, /* offline_message */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2815 NULL, /* whiteboard_prpl_ops */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2816 msim_send_really_raw, /* send_raw */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2817 NULL, /* roomlist_room_serialize */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2818 NULL, /* _purple_reserved1 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2819 NULL, /* _purple_reserved2 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2820 NULL, /* _purple_reserved3 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2821 NULL /* _purple_reserved4 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2822 };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2823
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2824
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2825
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2826 /** Based on MSN's plugin info comments. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2827 PurplePluginInfo info =
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2828 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2829 PURPLE_PLUGIN_MAGIC,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2830 PURPLE_MAJOR_VERSION,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2831 PURPLE_MINOR_VERSION,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2832 PURPLE_PLUGIN_PROTOCOL, /**< type */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2833 NULL, /**< ui_requirement */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2834 0, /**< flags */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2835 NULL, /**< dependencies */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2836 PURPLE_PRIORITY_DEFAULT, /**< priority */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2837
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2838 "prpl-myspace", /**< id */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2839 "MySpaceIM", /**< name */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2840 "0.10", /**< version */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2841 /** summary */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2842 "MySpaceIM Protocol Plugin",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2843 /** description */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2844 "MySpaceIM Protocol Plugin",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2845 "Jeff Connelly <jeff2@soc.pidgin.im>", /**< author */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2846 "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2847
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2848 msim_load, /**< load */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2849 NULL, /**< unload */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2850 NULL, /**< destroy */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2851 NULL, /**< ui_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2852 &prpl_info, /**< extra_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2853 NULL, /**< prefs_info */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2854
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2855 /* msim_actions */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2856 NULL,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2857
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2858 NULL, /**< reserved1 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2859 NULL, /**< reserved2 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2860 NULL, /**< reserved3 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2861 NULL /**< reserved4 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2862 };
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2863
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2864
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2865 #ifdef MSIM_SELF_TEST
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2866 /** Test functions.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2867 * Used to test or try out the internal workings of msimprpl. If you're reading
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2868 * this code for the first time, these functions can be instructive in how
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2869 * msimprpl is architected.
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2870 */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2871 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2872 msim_test_all(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2873 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2874 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2875
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2876
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2877 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2878 failures += msim_test_xml();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2879 failures += msim_test_msg();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2880 failures += msim_test_escaping();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2881
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2882 if (failures)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2883 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2884 purple_debug_info("msim", "msim_test_all HAD FAILURES: %d\n", failures);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2885 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2886 else
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2887 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2888 purple_debug_info("msim", "msim_test_all - all tests passed!\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2889 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2890 exit(0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2891 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2892
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2893 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2894 msim_test_xml(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2895 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2896 gchar *msg_text;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2897 xmlnode *root, *n;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2898 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2899 char *s;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2900 int len;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2901
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2902 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2903
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2904 msg_text = "<p><f n=\"Arial\" h=\"12\">woo!</f>xxx<c v='black'>yyy</c></p>";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2905
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2906 purple_debug_info("msim", "msim_test_xml: msg_text=%s\n", msg_text);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2907
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2908 root = xmlnode_from_str(msg_text, -1);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2909 if (!root)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2910 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2911 purple_debug_info("msim", "there is no root\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2912 exit(0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2913 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2914
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2915 purple_debug_info("msim", "root name=%s, child name=%s\n", root->name,
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2916 root->child->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2917
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2918 purple_debug_info("msim", "last child name=%s\n", root->lastchild->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2919 purple_debug_info("msim", "Root xml=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2920 xmlnode_to_str(root, &len));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2921 purple_debug_info("msim", "Child xml=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2922 xmlnode_to_str(root->child, &len));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2923 purple_debug_info("msim", "Lastchild xml=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2924 xmlnode_to_str(root->lastchild, &len));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2925 purple_debug_info("msim", "Next xml=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2926 xmlnode_to_str(root->next, &len));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2927 purple_debug_info("msim", "Next data=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2928 xmlnode_get_data(root->next));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2929 purple_debug_info("msim", "Child->next xml=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2930 xmlnode_to_str(root->child->next, &len));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2931
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2932 for (n = root->child; n; n = n->next)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2933 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2934 if (n->name)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2935 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2936 purple_debug_info("msim", " ** n=%s\n",n->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2937 } else {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2938 purple_debug_info("msim", " ** n data=%s\n", n->data);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2939 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2940 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2941
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2942 purple_debug_info("msim", "root data=%s, child data=%s, child 'h'=%s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2943 xmlnode_get_data(root),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2944 xmlnode_get_data(root->child),
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2945 xmlnode_get_attrib(root->child, "h"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2946
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2947
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2948 for (n = root->child;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2949 n != NULL;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2950 n = n->next)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2951 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2952 purple_debug_info("msim", "next name=%s\n", n->name);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2953 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2954
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2955 s = xmlnode_to_str(root, &len);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2956 s[len] = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2957
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2958 purple_debug_info("msim", "str: %s\n", s);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2959 g_free(s);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2960
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2961 xmlnode_free(root);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2962
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2963 exit(0);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2964
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2965 return failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2966 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2967
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2968 /** Test MsimMessage for basic functionality. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2969 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2970 msim_test_msg(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2971 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2972 MsimMessage *msg, *msg_cloned;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2973 gchar *packed, *packed_expected, *packed_cloned;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2974 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2975
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2976 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2977
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2978 purple_debug_info("msim", "\n\nTesting MsimMessage\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2979 msg = msim_msg_new(FALSE); /* Create a new, empty message. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2980
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2981 /* Append some new elements. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2982 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2983 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2984 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2985 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2986 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2987 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7"));
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2988 msim_msg_dump("msg debug str=%s\n", msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2989 packed = msim_msg_pack(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2990
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2991 purple_debug_info("msim", "msg packed=%s\n", packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2992
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2993 packed_expected = "\\bx\\WFhY\\k1\\v1\\k1\\42\\k1"
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2994 "\\v43\\k1\\v52/1xxx/2yyy\\k1\\v7\\final\\";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2995
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2996 if (0 != strcmp(packed, packed_expected))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2997 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2998 purple_debug_info("msim", "!!!(%d), msim_msg_pack not what expected: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
2999 ++failures, packed, packed_expected);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3000 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3001
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3002
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3003 msg_cloned = msim_msg_clone(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3004 packed_cloned = msim_msg_pack(msg_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3005
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3006 purple_debug_info("msim", "msg cloned=%s\n", packed_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3007 if (0 != strcmp(packed, packed_cloned))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3008 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3009 purple_debug_info("msim", "!!!(%d), msim_msg_pack on cloned message not equal to original: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3010 ++failures, packed_cloned, packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3011 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3012
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3013 g_free(packed);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3014 g_free(packed_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3015 msim_msg_free(msg_cloned);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3016 msim_msg_free(msg);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3017
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3018 return failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3019 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3020
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3021 /** Test protocol-level escaping/unescaping. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3022 int
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3023 msim_test_escaping(void)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3024 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3025 guint failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3026 gchar *raw, *escaped, *unescaped, *expected;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3027
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3028 failures = 0;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3029
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3030 purple_debug_info("msim", "\n\nTesting escaping\n");
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3031
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3032 raw = "hello/world\\hello/world";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3033
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3034 escaped = msim_escape(raw);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3035 purple_debug_info("msim", "msim_test_escaping: raw=%s, escaped=%s\n", raw, escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3036 expected = "hello/1world/2hello/1world";
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3037 if (0 != strcmp(escaped, expected))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3038 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3039 purple_debug_info("msim", "!!!(%d), msim_escape failed: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3040 ++failures, escaped, expected);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3041 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3042
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3043
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3044 unescaped = msim_unescape(escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3045 g_free(escaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3046 purple_debug_info("msim", "msim_test_escaping: unescaped=%s\n", unescaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3047 if (0 != strcmp(raw, unescaped))
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3048 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3049 purple_debug_info("msim", "!!!(%d), msim_unescape failed: %s != %s\n",
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3050 ++failures, raw, unescaped);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3051 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3052
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3053 return failures;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3054 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3055 #endif
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3056
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3057 /** Initialize plugin. */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3058 void
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3059 init_plugin(PurplePlugin *plugin)
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3060 {
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3061 PurpleAccountOption *option;
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3062 #ifdef MSIM_SELF_TEST
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3063 msim_test_all();
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3064 #endif /* MSIM_SELF_TEST */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3065
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3066 /* TODO: default to automatically try different ports. Make the user be
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3067 * able to set the first port to try (like LastConnectedPort in Windows client). */
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3068 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3069 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3070
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3071 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3072 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3073
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3074 option = purple_account_option_bool_new(_("Show display name in status text"), "show_display_name", TRUE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3075 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3076
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3077 option = purple_account_option_bool_new(_("Show headline in status text"), "show_headline", TRUE);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3078 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3079 }
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3080
dec27c05ae89 Set status to current status when signing on. This makes the "Sign in as
Jeff Connelly <jeff2@soc.pidgin.im>
parents: 18025
diff changeset
3081 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);

mercurial