annotate libpurple/protocols/myspace/myspace.c @ 17319:4cb842e0649c

Make msim_remove_buddy() functional. It now sends the delbuddy, persist, and blocklist commands, each using msim_postprocess_outgoing(). Tested by removing a buddy, restarting Pidgin, and ensuring it did not reappear. msim_postprocess_outgoing() and msim_postprocess_outgoing_cb() now both use msim_do_postprocessing() to do the actual postprocessing -- insertion of the uid into the message. msim_postprocess_outgoing() calls msim_do_postprocessing() if the uid is immediately available (for example, from the buddy list), while msim_postprocess_outgoing_cb() calls it when the uid was looked up from the server. The new function avoids code duplication, which is important now because of the additional feature of having "<uid>" within a string replaced with the uid, i instead of adding a new integer field of the uid. msim_remove_buddy uses this to insert the uid into the "body" field.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Wed, 13 Jun 2007 22:57:54 +0000
parents e9dfd3a5d4b6
children 0f0738f9839a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1 /* MySpaceIM Protocol Plugin
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
3 * \author Jeff Connelly
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
4 *
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im>
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
6 *
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
7 * Based on Purple's "C Plugin HOWTO" hello world example.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
8 *
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
9 * Code also drawn from mockprpl:
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
10 * http://snarfed.org/space/purple+mock+protocol+plugin
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
11 * Copyright (C) 2004-2007, Ryan Barrett <mockprpl@ryanb.org>
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
12 *
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
13 * and some constructs also based on existing Purple plugins, which are:
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
14 * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net>
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
15 * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu>
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
16 * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com>
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
17 * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net>
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
18 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
19 * This program is free software; you can redistribute it and/or modify
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
20 * it under the terms of the GNU General Public License as published by
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
21 * the Free Software Foundation; either version 2 of the License, or
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
22 * (at your option) any later version.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
23 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
24 * This program is distributed in the hope that it will be useful,
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
27 * GNU General Public License for more details.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
28 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
29 * You should have received a copy of the GNU General Public License
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
30 * along with this program; if not, write to the Free Software
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
32 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
33
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
34 #define PURPLE_PLUGIN
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
35
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
36 #include "message.h"
17286
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
37 #include "persist.h"
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
38 #include "myspace.h"
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
39
16726
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
40 /**
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
41 * Load the plugin.
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
42 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
43 gboolean msim_load(PurplePlugin *plugin)
16726
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
44 {
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
45 #ifdef MSIM_USE_PURPLE_RC4
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
46 /* If compiled to use RC4 from libpurple, check if it is really there. */
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
47 if (!purple_ciphers_find_cipher("rc4"))
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
48 {
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
49 purple_debug_error("msim", "compiled with MSIM_USE_PURPLE_RC4 but rc4 not in libpurple - not loading MySpaceIM plugin!\n");
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
50 purple_notify_error(plugin, _("Missing Cipher"),
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
51 _("The RC4 cipher could not be found"),
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
52 _("Recompile without MSIM_USE_PURPLE_RC4, or upgrade "
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
53 "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
54 "plugin will not be loaded."));
16726
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
55 return FALSE;
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
56 }
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
57 #endif
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
58 return TRUE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
59 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
60
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
61 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
62 * Get possible user status types. Based on mockprpl.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
63 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
64 * @return GList of status types.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
65 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
66 GList *msim_status_types(PurpleAccount *acct)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
67 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
68 GList *types;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
69 PurpleStatusType *status;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
70
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
71 purple_debug_info("myspace", "returning status types\n");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
72
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
73 types = NULL;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
74
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
75 /* TODO: Fix these:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
76 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
77 * g_log: purple_presence_get_active_status: assertion `presence != NULL' failed
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
78 * g_log: purple_status_get_name: assertion `status != NULL' failed
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
79 * [...]
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
80 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
81 * and
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
82 * g_log: purple_presence_set_status_active: assertion `status != NULL' failed
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
83 * [...]
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
84 */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
85 status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, NULL, NULL, FALSE, TRUE, FALSE);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
86 types = g_list_append(types, status);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
87
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
88 status = purple_status_type_new_full(PURPLE_STATUS_AWAY, NULL, NULL, FALSE, TRUE, FALSE);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
89 types = g_list_append(types, status);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
90
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
91 status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
92 types = g_list_append(types, status);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
93
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
94 status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, NULL, NULL, FALSE, TRUE, FALSE);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
95 types = g_list_append(types, status);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
96
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
97 return types;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
98 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
99
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
100 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
101 * Return the icon name for a buddy and account.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
102 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
103 * @param acct The account to find the icon for, or NULL for protocol icon.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
104 * @param buddy The buddy to find the icon for, or NULL for the account icon.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
105 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
106 * @return The base icon name string.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
107 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
108 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
109 {
16733
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
110 /* Use a MySpace icon submitted by hbons submitted one at
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
111 * http://developer.pidgin.im/wiki/MySpaceIM. */
16406
f62023eddfc6 Add and use MySpaceIM icon uploaded by hbons (48x48 original and resized 22x22 and 16x16 versions).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
112 return "myspace";
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
113 }
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
114
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
115 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
116 * Unescape a protocol message.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
117 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
118 * @return The unescaped message. Caller must g_free().
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
119 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
120 gchar *msim_unescape(const gchar *msg)
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
121 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
122 /* TODO: make more elegant, refactor with msim_escape */
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
123 gchar *tmp, *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
124
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
125 tmp = str_replace(msg, "/1", "/");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
126 ret = str_replace(tmp, "/2", "\\");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
127 g_free(tmp);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
128 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
129 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
130
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
131 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
132 * Escape a protocol message.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
133 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
134 * @return The escaped message. Caller must g_free().
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
135 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
136 gchar *msim_escape(const gchar *msg)
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
137 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
138 /* TODO: make more elegant, refactor with msim_unescape */
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
139 gchar *tmp, *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
140
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
141 tmp = str_replace(msg, "/", "/1");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
142 ret = str_replace(tmp, "\\", "/2");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
143 g_free(tmp);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
144
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
145 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
146 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
147
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
148 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
149 * Replace 'old' with 'new' in 'str'.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
150 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
151 * @param str The original string.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
152 * @param old The substring of 'str' to replace.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
153 * @param new The replacement for 'old' within 'str'.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
154 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
155 * @return A _new_ string, based on 'str', with 'old' replaced
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
156 * by 'new'. Must be g_free()'d by caller.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
157 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
158 * This string replace method is based on
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
159 * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
160 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
161 */
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
162 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new)
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
163 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
164 char **items;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
165 char *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
166
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
167 items = g_strsplit(str, old, -1);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
168 ret = g_strjoinv(new, items);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
169 g_free(items);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
170 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
171 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
172
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
173
16735
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
174
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
175
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
176 #ifdef MSIM_DEBUG_MSG
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
177 void print_hash_item(gpointer key, gpointer value, gpointer user_data)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
178 {
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
179 purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
180 }
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
181 #endif
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
182
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
183 /**
16723
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
184 * Send raw data to the server.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
185 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
186 * @param session
16723
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
187 * @param msg The raw data to send.
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
188 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
189 * @return TRUE if succeeded, FALSE if not.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
190 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
191 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
192 gboolean msim_send_raw(MsimSession *session, const gchar *msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
193 {
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
194 int total_bytes_sent, total_bytes;
16730
a2e9890a57e0 Implement msim_pack(), msim_sendh(), msim_send().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16729
diff changeset
195
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
196 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
197
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
198 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
199 g_return_val_if_fail(msg != NULL, FALSE);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
200
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
201
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
202 /* Loop until all data is sent, or a failure occurs. */
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
203 total_bytes_sent = 0;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
204 total_bytes = strlen(msg);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
205 do
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
206 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
207 int bytes_sent;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
208
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
209 bytes_sent = send(session->fd, msg + total_bytes_sent,
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
210 total_bytes - total_bytes_sent, 0);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
211
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
212 if (bytes_sent < 0)
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
213 {
16723
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
214 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
16409
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
215 msg, g_strerror(errno));
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
216 return FALSE;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
217 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
218 total_bytes_sent += bytes_sent;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
219
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
220 } while(total_bytes_sent < total_bytes);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
221 return TRUE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
222 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
223
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
224 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
225 * Start logging in to the MSIM servers.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
226 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
227 * @param acct Account information to use to login.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
228 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
229 void msim_login(PurpleAccount *acct)
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
230 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
231 PurpleConnection *gc;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
232 const char *host;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
233 int port;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
234
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
235 g_return_if_fail(acct != NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
236
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
237 purple_debug_info("myspace", "logging in %s\n", acct->username);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
238
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
239 gc = purple_account_get_connection(acct);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
240 gc->proto_data = msim_session_new(acct);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
241
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
242 /* 1. connect to server */
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
243 purple_connection_update_progress(gc, _("Connecting"),
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
244 0, /* which connection step this is */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
245 4); /* total number of steps */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
246
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
247 host = purple_account_get_string(acct, "server", MSIM_SERVER);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
248 port = purple_account_get_int(acct, "port", MSIM_PORT);
16733
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
249
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
250 /* From purple.sf.net/api:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
251 * """Note that this function name can be misleading--although it is called
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
252 * "proxy connect," it is used for establishing any outgoing TCP connection,
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
253 * whether through a proxy or not.""" */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
254
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
255 /* Calls msim_connect_cb when connected. */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
256 if (purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc) == NULL)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
257 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
258 /* TODO: try other ports if in auto mode, then save
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
259 * working port and try that first next time. */
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
260 purple_connection_error(gc, _("Couldn't create socket"));
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
261 return;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
262 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
263 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
264 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
265 * Process a login challenge, sending a response.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
266 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
267 * @param session
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
268 * @param msg Login challenge message.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
269 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
270 * @return TRUE if successful, FALSE if not
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
271 */
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
272 gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
273 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
274 PurpleAccount *account;
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
275 gchar *response;
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
276 guint response_len;
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
277 gchar *nc;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
278 gsize nc_len;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
279
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
280 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
281 g_return_val_if_fail(msg != NULL, FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
282
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
283 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
284
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
285 account = session->account;
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
286
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
287 g_return_val_if_fail(account != NULL, FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
288
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
289 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
290
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
291 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
292
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
293 if (nc_len != 0x40)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
294 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
295 purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len);
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
296 purple_connection_error(session->gc, _("Unexpected challenge length from server"));
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
297 return FALSE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
298 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
299
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
300 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
301
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
302 response = msim_compute_login_response(nc, account->username, account->password, &response_len);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
303
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
304 g_free(nc);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
305
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
306 return msim_send(session,
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
307 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
308 /* This is actually user's email address. */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
309 "username", MSIM_TYPE_STRING, g_strdup(account->username),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
310 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
311 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
312 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
313 "reconn", MSIM_TYPE_INTEGER, 0,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
314 "status", MSIM_TYPE_INTEGER, 100,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
315 "id", MSIM_TYPE_INTEGER, 1,
16731
2e0bd3e6f2c7 Incomplete attempt at using msim_send() instead of msim_send_raw().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16730
diff changeset
316 NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
317 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
318
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
319 #ifndef MSIM_USE_PURPLE_RC4
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
320 /* No RC4 in this version of libpurple, so bring our own. */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
321
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
322 /*
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
323 Unix SMB/CIFS implementation.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
324
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
325 a partial implementation of RC4 designed for use in the
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
326 SMB authentication protocol
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
327
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
328 Copyright (C) Andrew Tridgell 1998
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
329
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
330 $Id: crypt-rc4.c 12116 2004-09-27 23:29:22Z guy $
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
331
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
332 This program is free software; you can redistribute it and/or modify
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
333 it under the terms of the GNU General Public License as published by
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
334 the Free Software Foundation; either version 2 of the License, or
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
335 (at your option) any later version.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
336
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
337 This program is distributed in the hope that it will be useful,
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
338 but WITHOUT ANY WARRANTY; without even the implied warranty of
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
339 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
340 GNU General Public License for more details.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
341
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
342 You should have received a copy of the GNU General Public License
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
343 along with this program; if not, write to the Free Software
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
344 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
345
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
346
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
347 Modified by Jeff Connelly for MySpaceIM Gaim plugin.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
348 */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
349
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
350 #include <glib.h>
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
351 #include <string.h>
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
352
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
353 /* Perform RC4 on a block of data using specified key. "data" is a pointer
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
354 to the block to be processed. Output is written to same memory as input,
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
355 so caller may need to make a copy before calling this function, since
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
356 the input will be overwritten.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
357
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
358 Taken from Samba source code. Modified to allow us to maintain state
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
359 between calls to crypt_rc4.
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
360 */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
361
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
362 void crypt_rc4_init(rc4_state_struct *rc4_state,
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
363 const unsigned char *key, int key_len)
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
364 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
365 int ind;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
366 unsigned char j = 0;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
367 unsigned char *s_box;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
368
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
369 memset(rc4_state, 0, sizeof(rc4_state_struct));
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
370 s_box = rc4_state->s_box;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
371
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
372 for (ind = 0; ind < 256; ind++)
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
373 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
374 s_box[ind] = (unsigned char)ind;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
375 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
376
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
377 for( ind = 0; ind < 256; ind++)
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
378 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
379 unsigned char tc;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
380
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
381 j += (s_box[ind] + key[ind%key_len]);
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
382
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
383 tc = s_box[ind];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
384 s_box[ind] = s_box[j];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
385 s_box[j] = tc;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
386 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
387
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
388 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
389
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
390 void crypt_rc4(rc4_state_struct *rc4_state, unsigned char *data, int data_len)
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
391 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
392 unsigned char *s_box;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
393 unsigned char index_i;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
394 unsigned char index_j;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
395 int ind;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
396
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
397 /* retrieve current state from the state struct (so we can resume where
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
398 we left off) */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
399 index_i = rc4_state->index_i;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
400 index_j = rc4_state->index_j;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
401 s_box = rc4_state->s_box;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
402
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
403 for( ind = 0; ind < data_len; ind++)
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
404 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
405 unsigned char tc;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
406 unsigned char t;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
407
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
408 index_i++;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
409 index_j += s_box[index_i];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
410
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
411 tc = s_box[index_i];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
412 s_box[index_i] = s_box[index_j];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
413 s_box[index_j] = tc;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
414
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
415 t = s_box[index_i] + s_box[index_j];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
416 data[ind] = data[ind] ^ s_box[t];
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
417 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
418
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
419 /* Store the updated state */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
420 rc4_state->index_i = index_i;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
421 rc4_state->index_j = index_j;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
422 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
423
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
424 #endif /* !MSIM_USE_PURPLE_RC4 */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
425
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
426
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
427 /**
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
428 * Compute the base64'd login challenge response based on username, password, nonce, and IPs.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
429 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
430 * @param nonce The base64 encoded nonce ('nc') field from the server.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
431 * @param email User's email address (used as login name).
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
432 * @param password User's cleartext password.
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
433 * @param response_len Will be written with response length.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
434 *
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
435 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
436 * when finished.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
437 */
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
438 gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE],
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
439 gchar *email, gchar *password, guint *response_len)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
440 {
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
441 PurpleCipherContext *key_context;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
442 PurpleCipher *sha1;
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
443 #ifdef MSIM_USE_PURPLE_RC4
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
444 PurpleCipherContext *rc4;
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
445 #else
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
446 rc4_state_struct rc4;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
447 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
448
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
449 guchar hash_pw[HASH_SIZE];
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
450 guchar key[HASH_SIZE];
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
451 gchar *password_utf16le;
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
452 guchar *data;
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
453 guchar *data_out;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
454 size_t data_len, data_out_len;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
455 gsize conv_bytes_read, conv_bytes_written;
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
456 GError *conv_error;
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
457 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
458 int i;
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
459 #endif
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
460
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
461 /* Convert ASCII password to UTF16 little endian */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
462 purple_debug_info("msim", "converting password to UTF-16LE\n");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
463 conv_error = NULL;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
464 password_utf16le = g_convert(password, -1, "UTF-16LE", "UTF-8",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
465 &conv_bytes_read, &conv_bytes_written, &conv_error);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
466 g_assert(conv_bytes_read == strlen(password));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
467 if (conv_error != NULL)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
468 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
469 purple_debug_error("msim",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
470 "g_convert password UTF8->UTF16LE failed: %s",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
471 conv_error->message);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
472 g_error_free(conv_error);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
473 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
474
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
475 /* Compute password hash */
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
476 purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
477 conv_bytes_written, sizeof(hash_pw), hash_pw, NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
478 g_free(password_utf16le);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
479
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
480 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
481 purple_debug_info("msim", "pwhash = ");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
482 for (i = 0; i < sizeof(hash_pw); i++)
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
483 purple_debug_info("msim", "%.2x ", hash_pw[i]);
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
484 purple_debug_info("msim", "\n");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
485 #endif
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
486
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
487 /* key = sha1(sha1(pw) + nonce2) */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
488 sha1 = purple_ciphers_find_cipher("sha1");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
489 key_context = purple_cipher_context_new(sha1, NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
490 purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
491 purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
492 purple_cipher_context_digest(key_context, sizeof(key), key, NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
493
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
494 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
495 purple_debug_info("msim", "key = ");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
496 for (i = 0; i < sizeof(key); i++)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
497 {
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
498 purple_debug_info("msim", "%.2x ", key[i]);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
499 }
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
500 purple_debug_info("msim", "\n");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
501 #endif
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
502
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
503 #ifdef MSIM_USE_PURPLE_RC4
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
504 rc4 = purple_cipher_context_new_by_name("rc4", NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
505
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
506 /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash),
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
507 * but only first 0x10 used for the RC4 key. */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
508 purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
509 purple_cipher_context_set_key(rc4, key);
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
510 #endif
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
511
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
512 /* TODO: obtain IPs of network interfaces. This is not immediately
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
513 * important because you can still connect and perform basic
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
514 * functions of the protocol. There is also a high chance that the addreses
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
515 * are RFC1918 private, so the servers couldn't do anything with them
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
516 * anyways except make note of that fact. Probably important for any
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
517 * kind of direct connection, or file transfer functionality.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
518 */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
519 /* rc4 encrypt:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
520 * nonce1+email+IP list */
16734
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16733
diff changeset
521 data_len = NONCE_SIZE + strlen(email)
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16733
diff changeset
522 /* TODO: change to length of IP list */
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16733
diff changeset
523 + 25;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
524 data = g_new0(guchar, data_len);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
525 memcpy(data, nonce, NONCE_SIZE);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
526 memcpy(data + NONCE_SIZE, email, strlen(email));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
527 memcpy(data + NONCE_SIZE + strlen(email),
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
528 /* TODO: IP addresses of network interfaces */
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
529 "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
530
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
531 #ifdef MSIM_USE_PURPLE_RC4
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
532 data_out = g_new0(guchar, data_len);
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
533
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
534 purple_cipher_context_encrypt(rc4, (const guchar *)data,
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
535 data_len, data_out, &data_out_len);
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
536 purple_cipher_context_destroy(rc4);
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
537 #else
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
538 /* Use our own RC4 code */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
539 purple_debug_info("msim", "Using non-purple RC4 cipher code in this version\n");
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
540 crypt_rc4_init(&rc4, key, 0x10);
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
541 crypt_rc4(&rc4, data, data_len);
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
542 data_out_len = data_len;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
543 data_out = data;
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
544 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
545
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
546 g_assert(data_out_len == data_len);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
547
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
548 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
549 purple_debug_info("msim", "response=<%s>\n", data_out);
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
550 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
551
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
552 *response_len = data_out_len;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
553
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
554 return (gchar *)data_out;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
555 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
556
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
557 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
558 * Schedule an IM to be sent once the user ID is looked up.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
559 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
560 * @param gc Connection.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
561 * @param who A user id, email, or username to send the message to.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
562 * @param message Instant message text to send.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
563 * @param flags Flags.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
564 *
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
565 * @return 1 if successful or postponed, -1 if failed
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
566 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
567 * Allows sending to a user by username, email address, or userid. If
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
568 * a username or email address is given, the userid must be looked up.
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
569 * This function does that by calling msim_postprocess_outgoing().
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
570 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
571 int msim_send_im(PurpleConnection *gc, const char *who,
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
572 const char *message, PurpleMessageFlags flags)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
573 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
574 MsimSession *session;
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
575
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
576 g_return_val_if_fail(gc != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
577 g_return_val_if_fail(who != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
578 g_return_val_if_fail(message != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
579
17300
176b1ba4bafe Remove 'flags' from send_im_cb_struct - it was never needed.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17299
diff changeset
580 /* 'flags' has many options, not used here. */
176b1ba4bafe Remove 'flags' from send_im_cb_struct - it was never needed.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17299
diff changeset
581
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
582 session = gc->proto_data;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
583
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
584 /* TODO: const-correctness */
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
585 if (msim_send_bm(session, (char *)who, (char *)message, MSIM_BM_INSTANT))
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
586 {
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
587 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
588 * return 1 even if the message could not be sent, since I don't know if
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
589 * it has failed yet--because the IM is only sent after the userid is
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
590 * retrieved from the server (which happens after this function returns).
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
591 */
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
592 return 1;
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
593 } else {
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
594 return -1;
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
595 }
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
596 /*
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
597 * TODO: In MySpace, you login with your email address, but don't talk to other
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
598 * users using their email address. So there is currently an asymmetry in the
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
599 * IM windows when using this plugin:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
600 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
601 * you@example.com: hello
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
602 * some_other_user: what's going on?
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
603 * you@example.com: just coding a prpl
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
604 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
605 * TODO: Make the sent IM's appear as from the user's username, instead of
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
606 * their email address. Purple uses the login (in MSIM, the email)--change this.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
607 */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
608 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
609
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
610 /** Send a buddy message of a given type.
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
611 *
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
612 * @param session
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
613 * @param who Username to send message to.
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
614 * @param text Message text to send. Not freed; will be copied.
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
615 * @param type A MSIM_BM_* constant.
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
616 *
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
617 * Buddy messages ('bm') include instant messages, action messages, status messages, etc.
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
618 */
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
619 gboolean msim_send_bm(MsimSession *session, gchar *who, gchar *text, int type)
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
620 {
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
621 gboolean rc;
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
622 MsimMessage *msg;
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
623 const char *from_username = session->account->username;
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
624
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
625 purple_debug_info("msim", "sending %d message from %s to %s: %s\n",
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
626 type, from_username, who, text);
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
627
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
628 msg = msim_msg_new(TRUE,
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
629 "bm", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(type),
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
630 "sesskey", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(session->sesskey),
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
631 /* 't' will be inserted here */
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
632 "cv", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(MSIM_CLIENT_VERSION),
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
633 "msg", MSIM_TYPE_STRING, g_strdup(text),
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
634 NULL);
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
635
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
636 rc = msim_postprocess_outgoing(session, msg, (char *)who, "t", "cv");
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
637
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
638 msim_msg_free(msg);
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
639
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
640 return rc;
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
641 }
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
642
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
643 /**
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
644 * Handle an incoming instant message.
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
645 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
646 * @param session The session
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
647 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
648 * Should also contain username in _username from preprocessing.
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
649 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
650 * @return TRUE if successful.
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
651 */
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
652 gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg)
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
653 {
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
654 gchar *username;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
655
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
656 username = msim_msg_get_string(msg, "_username");
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
657
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
658 serv_got_im(session->gc, username, msim_msg_get_string(msg, "msg"), PURPLE_MESSAGE_RECV, time(NULL));
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
659
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
660 g_free(username);
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
661 /* TODO: Free copy cloned from msim_incoming_im(). */
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
662 //msim_msg_free(msg);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
663
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
664 return TRUE;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
665 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
666
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
667 /**
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
668 * Handle an incoming action message.
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
669 *
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
670 * @param session
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
671 * @param msg
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
672 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
673 * @return TRUE if successful.
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
674 *
17308
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
675 * UNTESTED
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
676 */
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
677 gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg)
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
678 {
17308
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
679 gchar *msg_text, *username;
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
680 gboolean rc;
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
681
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
682 msg_text = msim_msg_get_string(msg, "msg");
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
683 username = msim_msg_get_string(msg, "_username");
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
684
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
685 purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n", msg_text, username);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
686
17308
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
687 if (strcmp(msg_text, "%typing%") == 0)
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
688 {
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
689 /* TODO: find out if msim repeatedly sends typing messages, so we can give it a timeout. */
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
690 serv_got_typing(session->gc, username, 0, PURPLE_TYPING);
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
691 rc = TRUE;
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
692 } else if (strcmp(msg_text, "%stoptyping%") == 0) {
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
693 serv_got_typing_stopped(session->gc, username);
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
694 rc = TRUE;
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
695 } else {
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
696 /* TODO: make a function, msim_unrecognized(), that logs all unhandled msgs to file. */
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
697 purple_debug_info("msim", "msim_incoming_action: for %s, unknown msg %s\n",
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
698 username, msg_text);
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
699 rc = FALSE;
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
700 }
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
701
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
702
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
703 g_free(msg_text);
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
704 g_free(username);
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
705
1277a0f82304 Add untested implementation of msim_incoming_action().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17307
diff changeset
706 return rc;
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
707 }
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
708
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
709 /**
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
710 * Handle when our user starts or stops typing to another user.
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
711 *
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
712 * @param gc
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
713 * @param name The buddy name to which our user is typing to
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
714 * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
715 *
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
716 * NOT CURRENTLY USED OR COMPLETE
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
717 */
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
718 unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state)
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
719 {
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
720 char *typing_str;
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
721 MsimSession *session;
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
722
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
723 session = (MsimSession *)gc->proto_data;
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
724
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
725 switch (state)
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
726 {
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
727 case PURPLE_TYPING:
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
728 typing_str = "%typing%";
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
729 break;
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
730
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
731 case PURPLE_TYPED:
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
732 case PURPLE_NOT_TYPING:
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
733 default:
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
734 typing_str = "%stoptyping%";
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
735 break;
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
736 }
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
737
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
738 purple_debug_info("msim", "msim_send_typing(%s): %d (%s)\n", name, state, typing_str);
17315
d9aaccef8721 Send typing notifications (tested).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17314
diff changeset
739 msim_send_bm(session, (gchar *)name, typing_str, MSIM_BM_ACTION);
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
740 return 0;
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
741 }
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
742
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
743 /** After a uid is resolved to username, tag it with the username and submit for processing.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
744 *
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
745 * @param session
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
746 * @param userinfo Response messsage to resolving request.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
747 * @param data MsimMessage *, the message to attach information to.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
748 */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
749 static void msim_incoming_resolved(MsimSession *session, MsimMessage *userinfo, gpointer data)
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
750 {
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
751 gchar *body_str;
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
752 GHashTable *body;
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
753 gchar *username;
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
754 MsimMessage *msg;
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
755
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
756 body_str = msim_msg_get_string(userinfo, "body");
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
757 g_return_if_fail(body_str != NULL);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
758 body = msim_parse_body(body_str);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
759 g_return_if_fail(body != NULL);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
760 g_free(body_str);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
761
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
762 username = g_hash_table_lookup(body, "UserName");
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
763 g_return_if_fail(username != NULL);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
764
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
765 msg = (MsimMessage *)data;
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
766 /* Special elements name beginning with '_', we'll use internally within the
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
767 * program (did not come from the wire). */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
768 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
769
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
770 msim_process(session, msg);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
771
17307
e64bcff3b674 Transition msim_incoming_im() to the callbackless infrastructure. Remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17306
diff changeset
772 /* TODO: Free copy cloned from msim_preprocess_incoming(). */
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
773 //XXX msim_msg_free(msg);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
774 g_hash_table_destroy(body);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
775 }
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
776
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
777 #ifdef _MSIM_UID2USERNAME_WORKS
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
778 /* Lookup a username by userid, from buddy list.
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
779 *
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
780 * @param wanted_uid
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
781 *
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
782 * @return Username of wanted_uid, if on blist, or NULL. Static string.
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
783 *
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
784 * XXX WARNING: UNKNOWN MEMORY CORRUPTION HERE!
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
785 */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
786 static const gchar *msim_uid2username_from_blist(MsimSession *session, guint wanted_uid)
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
787 {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
788 GSList *buddies, *buddies_head;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
789
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
790 for (buddies = buddies_head = purple_find_buddies(session->account, NULL);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
791 buddies;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
792 buddies = g_slist_next(buddies))
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
793 {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
794 PurpleBuddy *buddy;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
795 guint uid;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
796 gchar *name;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
797
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
798 buddy = buddies->data;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
799
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
800 uid = purple_blist_node_get_int(&buddy->node, "uid");
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
801
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
802 /* name = buddy->name; */ /* crash */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
803 /* name = PURPLE_BLIST_NODE_NAME(&buddy->node); */ /* crash */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
804
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
805 /* XXX Is this right? Memory corruption here somehow. Happens only
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
806 * when return one of these values. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
807 name = purple_buddy_get_name(buddy); /* crash */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
808 /* return name; */ /* crash (with above) */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
809
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
810 /* name = NULL; */ /* no crash */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
811 /* return NULL; */ /* no crash (with anything) */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
812
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
813 /* crash =
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
814 *** glibc detected *** pidgin: realloc(): invalid pointer: 0x0000000000d2aec0 ***
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
815 ======= Backtrace: =========
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
816 /lib/libc.so.6(__libc_realloc+0x323)[0x2b7bfc012e03]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
817 /usr/lib/libglib-2.0.so.0(g_realloc+0x31)[0x2b7bfba79a41]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
818 /usr/lib/libgtk-x11-2.0.so.0(gtk_tree_path_append_index+0x3a)[0x2b7bfa110d5a]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
819 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa1287dc]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
820 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa128e56]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
821 /usr/lib/libgtk-x11-2.0.so.0[0x2b7bfa128efd]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
822 /usr/lib/libglib-2.0.so.0(g_main_context_dispatch+0x1b4)[0x2b7bfba72c84]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
823 /usr/lib/libglib-2.0.so.0[0x2b7bfba75acd]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
824 /usr/lib/libglib-2.0.so.0(g_main_loop_run+0x1ca)[0x2b7bfba75dda]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
825 /usr/lib/libgtk-x11-2.0.so.0(gtk_main+0xa3)[0x2b7bfa0475f3]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
826 pidgin(main+0x8be)[0x46b45e]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
827 /lib/libc.so.6(__libc_start_main+0xf4)[0x2b7bfbfbf0c4]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
828 pidgin(gtk_widget_grab_focus+0x39)[0x429ab9]
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
829
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
830 or:
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
831 *** glibc detected *** /usr/local/bin/pidgin: malloc(): memory corruption (fast): 0x0000000000c10076 ***
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
832 (gdb) bt
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
833 #0 0x00002b4074ecd47b in raise () from /lib/libc.so.6
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
834 #1 0x00002b4074eceda0 in abort () from /lib/libc.so.6
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
835 #2 0x00002b4074f0453b in __fsetlocking () from /lib/libc.so.6
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
836 #3 0x00002b4074f0c810 in free () from /lib/libc.so.6
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
837 #4 0x00002b4074f0d6dd in malloc () from /lib/libc.so.6
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
838 #5 0x00002b4074974b5b in g_malloc () from /usr/lib/libglib-2.0.so.0
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
839 #6 0x00002b40749868bf in g_strdup () from /usr/lib/libglib-2.0.so.0
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
840 #7 0x00002b407810969f in msim_parse (
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
841 raw=0xd2a910 "\\bm\\100\\f\\3656574\\msg\\|s|0|ss|Offline")
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
842 at message.c:648
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
843 #8 0x00002b407810889c in msim_input_cb (gc_uncasted=0xcf92c0,
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
844 source=<value optimized out>, cond=<value optimized out>) at myspace.c:1478
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
845
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
846
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
847 Why is it crashing in msim_parse()'s g_strdup()?
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
848 */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
849
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
850
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
851 purple_debug_info("msim", "msim_uid2username_from_blist: %s's uid=%d (want %d)\n",
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
852 name, uid, wanted_uid);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
853
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
854 if (uid == wanted_uid)
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
855 {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
856 g_slist_free(buddies_head);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
857
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
858 return name;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
859 }
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
860 }
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
861
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
862 g_slist_free(buddies_head);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
863 return NULL;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
864 }
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
865
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
866 #endif
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
867
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
868 /** Preprocess incoming messages, resolving as needed, calling msim_process() when ready to process.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
869 *
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
870 * TODO: if no uid to resolve, process immediately. if uid, check if know username,
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
871 * if so, tag and process immediately, if not, queue, send resolve msg, and process
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
872 * once get username.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
873 *
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
874 * @param session
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
875 * @param msg MsimMessage *, freed by caller.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
876 */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
877 gboolean msim_preprocess_incoming(MsimSession *session, MsimMessage *msg)
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
878 {
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
879 if (msim_msg_get(msg, "bm") && msim_msg_get(msg, "f"))
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
880 {
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
881 guint uid;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
882 const gchar *username;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
883
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
884 /* 'f' = userid message is from, in buddy messages */
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
885 uid = msim_msg_get_integer(msg, "f");
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
886
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
887 /* TODO: Make caching work. Currently it is commented out because
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
888 * it crashes for unknown reasons, memory realloc error. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
889 //#define _MSIM_UID2USERNAME_WORKS
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
890 #ifdef _MSIM_UID2USERNAME_WORKS
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
891 username = msim_uid2username_from_blist(session, uid);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
892 #else
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
893 username = NULL;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
894 #endif
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
895
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
896 if (username)
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
897 {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
898 /* Know username already, use it. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
899 purple_debug_info("msim", "msim_preprocess_incoming: tagging with _username=%s\n",
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
900 username);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
901 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
902 return msim_process(session, msg);
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
903
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
904 } else {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
905 /* Send lookup request. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
906 /* XXX: where is msim_msg_get_string() freed? make _strdup and _nonstrdup. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
907 purple_debug_info("msim", "msim_incoming: sending lookup, setting up callback\n");
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
908 msim_lookup_user(session, msim_msg_get_string(msg, "f"), msim_incoming_resolved, msim_msg_clone(msg));
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
909
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
910 /* indeterminate */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
911 return TRUE;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
912 }
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
913 } else {
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
914 /* Nothing to resolve - send directly to processing. */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
915 return msim_process(session, msg);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
916 }
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
917 }
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
918
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
919 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
920 * Process a message.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
921 *
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
922 * @param session
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
923 * @param msg A message from the server, ready for processing (possibly with resolved username information attached). Caller frees.
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
924 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
925 * @return TRUE if successful. FALSE if processing failed.
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
926 */
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
927 gboolean msim_process(MsimSession *session, MsimMessage *msg)
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
928 {
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
929 g_return_val_if_fail(session != NULL, -1);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
930 g_return_val_if_fail(msg != NULL, -1);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
931
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
932 #ifdef MSIM_DEBUG_MSG
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
933 {
17298
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17297
diff changeset
934 msim_msg_dump("ready to process: %s\n", msg);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
935 }
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
936 #endif
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
937
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
938 if (msim_msg_get(msg, "nc"))
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
939 {
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
940 return msim_login_challenge(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
941 } else if (msim_msg_get(msg, "sesskey")) {
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
942
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
943 purple_connection_update_progress(session->gc, _("Connected"), 3, 4);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
944
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
945 session->sesskey = msim_msg_get_integer(msg, "sesskey");
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
946 purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
947
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
948 /* Comes with: proof,profileid,userid,uniquenick -- all same values
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
949 * some of the time, but can vary. */
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
950 session->userid = msim_msg_get_integer(msg, "userid");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
951
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
952 purple_connection_set_state(session->gc, PURPLE_CONNECTED);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
953
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
954 return TRUE;
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
955 } else if (msim_msg_get(msg, "bm")) {
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
956 guint bm;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
957
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
958 bm = msim_msg_get_integer(msg, "bm");
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
959 switch (bm)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
960 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
961 case MSIM_BM_STATUS:
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
962 return msim_status(session, msg);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
963 case MSIM_BM_INSTANT:
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
964 return msim_incoming_im(session, msg);
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
965 case MSIM_BM_ACTION:
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
966 return msim_incoming_action(session, msg);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
967 default:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
968 /* Not really an IM, but show it for informational
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
969 * purposes during development. */
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
970 return msim_incoming_im(session, msg);
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
971 }
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
972 } else if (msim_msg_get(msg, "rid")) {
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
973 return msim_process_reply(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
974 } else if (msim_msg_get(msg, "error")) {
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
975 return msim_error(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
976 } else if (msim_msg_get(msg, "ka")) {
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
977 purple_debug_info("msim", "msim_process: got keep alive\n");
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
978 return TRUE;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
979 } else {
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
980 /* TODO: dump unknown msgs to file, so user can send them to me
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
981 * if they wish, to help add support for new messages (inspired
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
982 * by Alexandr Shutko, who maintains OSCAR protocol documentation). */
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
983 purple_debug_info("msim", "msim_process: unhandled message\n");
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
984 return FALSE;
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
985 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
986 }
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
987
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
988 /**
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
989 * Process a persistance message reply from the server.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
990 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
991 * @param session
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
992 * @param msg Message reply from server.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
993 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
994 * @return TRUE if successful.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
995 */
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
996 gboolean msim_process_reply(MsimSession *session, MsimMessage *msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
997 {
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
998 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
999 g_return_val_if_fail(msg != NULL, FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1000
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1001 if (msim_msg_get(msg, "rid")) /* msim_lookup_user sets callback for here */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1002 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1003 MSIM_USER_LOOKUP_CB cb;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1004 gpointer data;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1005 guint rid;
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1006 GHashTable *body;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1007 gchar *username, *body_str;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1008
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1009 rid = msim_msg_get_integer(msg, "rid");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1010
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1011 /* Cache the user info. Currently, the GHashTable of user info in
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1012 * this cache never expires so is never freed. TODO: expire and destroy
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1013 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1014 * Some information never changes (username->userid map), some does.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1015 * TODO: Cache what doesn't change only
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1016 */
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1017 body_str = msim_msg_get_string(msg, "body");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1018 body = msim_parse_body(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1019 g_free(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1020
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1021
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1022 /* TODO: implement a better hash-like interface, and use it. */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1023 username = g_hash_table_lookup(body, "UserName");
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1024
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1025 /* TODO: Save user info reply for msim_tooltip_text. */
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1026 /* TODO: get rid of user_lookup_cache, and find another way to
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1027 * pass the relevant information to msim_tooltip_text. */
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1028 /* g_hash_table_insert(session->user_lookup_cache, username, body); */
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1029
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1030 if (username)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1031 {
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1032 PurpleBuddy *buddy;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1033 gchar *uid;
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1034
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1035 uid = g_hash_table_lookup(body, "UserID");
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1036 g_assert(uid);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1037
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1038 /* Associate uid with user on buddy list. This is saved to blist.xml. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1039
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1040 purple_debug_info("msim", "associating %d with %s\n", uid, username);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1041
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1042 buddy = purple_find_buddy(session->account, username);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1043 if (buddy)
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1044 {
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1045 purple_blist_node_set_int(&buddy->node, "uid", atoi(uid));
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1046 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1047 } else {
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1048 purple_debug_info("msim",
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1049 "msim_process_reply: not caching body, no UserName\n");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1050 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1051
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1052 /* If a callback is registered for this userid lookup, call it. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1053 cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1054 data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1055
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1056 if (cb)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1057 {
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1058 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1059 "msim_process_body: calling callback now\n");
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1060 /* Clone message, so that the callback 'cb' can use it (needs to free it also). */
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1061 cb(session, msim_msg_clone(msg), data);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1062 g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1063 g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1064 } else {
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1065 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1066 "msim_process_body: no callback for rid %d\n", rid);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1067 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1068 }
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1069
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1070 return TRUE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1071 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1072
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1073 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1074 * Handle an error from the server.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1075 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1076 * @param session
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1077 * @param msg The message.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1078 *
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1079 * @return TRUE if successfully reported error.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1080 */
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1081 gboolean msim_error(MsimSession *session, MsimMessage *msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1082 {
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1083 gchar *errmsg, *full_errmsg;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1084 guint err;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1085
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1086 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1087 g_return_val_if_fail(msg != NULL, FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1088
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1089 err = msim_msg_get_integer(msg, "err");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1090 errmsg = msim_msg_get_string(msg, "errmsg");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1091
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1092 full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err, errmsg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1093
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1094 g_free(errmsg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1095
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1096 purple_debug_info("msim", "msim_error: %s\n", full_errmsg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1097
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1098 /* TODO: do something with the error # (localization of errmsg?) */
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1099 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1100 full_errmsg, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1101
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1102 /* Destroy session if fatal. */
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1103 if (msim_msg_get(msg, "fatal"))
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1104 {
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1105 purple_debug_info("msim", "fatal error, closing\n");
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1106 purple_connection_error(session->gc, full_errmsg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1107 close(session->fd);
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1108 /* Do not call msim_session_destroy(session) - called in msim_close(). */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1109 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1110
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1111 return TRUE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1112 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1113
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1114 /**
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1115 * Process incoming status messages.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1116 *
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1117 * @param session
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1118 * @param msg Status update message. Caller frees.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1119 *
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1120 * @return TRUE if successful.
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1121 */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1122 gboolean msim_status(MsimSession *session, MsimMessage *msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1123 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1124 PurpleBuddyList *blist;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1125 PurpleBuddy *buddy;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1126 //PurpleStatus *status;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1127 gchar **status_array;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1128 GList *list;
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1129 gchar *status_headline;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1130 gchar *status_str;
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1131 gint i, status_code, purple_status_code;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1132 gchar *username;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1133
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1134 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1135 g_return_val_if_fail(msg != NULL, FALSE);
17305
6476a55a9542 msim_status_cb() now takes a MsimMessage *, just like msim_send_im_cb() and
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17304
diff changeset
1136
6476a55a9542 msim_status_cb() now takes a MsimMessage *, just like msim_send_im_cb() and
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17304
diff changeset
1137 status_str = msim_msg_get_string(msg, "msg");
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1138 g_return_val_if_fail(status_str != NULL, FALSE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1139
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1140 msim_msg_dump("msim_status msg=%s\n", msg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1141
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1142 /* Helpfully looked up by msim_incoming_resolve() for us. */
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1143 username = msim_msg_get_string(msg, "_username");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1144 /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1145 * the buddy list, if the UserID was stored along with it. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1146
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1147 if (username == NULL)
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1148 {
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1149 g_free(status_str);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1150 g_return_val_if_fail(NULL, FALSE);
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1151 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1152
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1153 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1154 "msim_status_cb: updating status for <%s> to <%s>\n",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1155 username, status_str);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1156
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1157 /* TODO: generic functions to split into a GList, part of MsimMessage */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1158 status_array = g_strsplit(status_str, "|", 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1159 for (list = NULL, i = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1160 status_array[i];
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1161 i++)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1162 {
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1163 /* Note: this adds the 0th ordinal too, which might not be a value
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1164 * at all (the 0 in the 0|1|2|3... status fields, but 0 always appears blank).
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1165 */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1166 list = g_list_append(list, status_array[i]);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1167 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1168
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1169 /* Example fields:
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1170 * |s|0|ss|Offline
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1171 * |s|1|ss|:-)|ls||ip|0|p|0
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1172 *
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1173 * TODO: write list support in MsimMessage, and use it here.
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1174 */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1175
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1176 status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1177 purple_debug_info("msim", "msim_status_cb: %s's status code = %d\n", username, status_code);
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1178 status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1179
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1180 blist = purple_get_blist();
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1181
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1182 /* Add buddy if not found */
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1183 buddy = purple_find_buddy(session->account, username);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1184 if (!buddy)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1185 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1186 /* TODO: purple aliases, userids and usernames */
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1187 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1188 "msim_status: making new buddy for %s\n", username);
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1189 buddy = purple_buddy_new(session->account, username, NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1190
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1191 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
17299
c6305f8845d8 Add TODOs about username/email->userid resolution, use g_return_if_fail() in a few places.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1192 /* All buddies on list should have 'uid' integer associated with them. */
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1193 purple_blist_node_set_int(&buddy->node, "uid", msim_msg_get_integer(msg, "f"));
17299
c6305f8845d8 Add TODOs about username/email->userid resolution, use g_return_if_fail() in a few places.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1194 purple_debug_info("msim", "UID=%d\n", purple_blist_node_get_int(&buddy->node, "uid"));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1195 } else {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1196 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1197 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1198
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1199 /* TODO: show headline */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1200
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1201 /* Set user status */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1202 switch (status_code)
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1203 {
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1204 case 1: purple_status_code = PURPLE_STATUS_AVAILABLE;
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1205 break;
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1206 case 0: purple_status_code = PURPLE_STATUS_OFFLINE;
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1207 break;
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1208 default:
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1209 purple_debug_info("msim", "msim_status_cb for %s, unknown status code %d\n",
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1210 username, status_code);
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1211 purple_status_code = PURPLE_STATUS_AVAILABLE;
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1212 }
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
1213 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1214
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1215 g_strfreev(status_array);
17305
6476a55a9542 msim_status_cb() now takes a MsimMessage *, just like msim_send_im_cb() and
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17304
diff changeset
1216 g_free(status_str);
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1217 g_free(username);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1218 g_list_free(list);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1219
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1220 return TRUE;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1221 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1222
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1223 /** Add a buddy to user's buddy list. TODO: make work. Should receive statuses from added buddy. */
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1224 void msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1225 {
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1226 MsimSession *session;
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1227 MsimMessage *msg;
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1228
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1229 session = (MsimSession *)gc->proto_data;
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1230 purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", buddy->name,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1231 group ? group->name : "(no group)");
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1232
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1233 msg = msim_msg_new(TRUE,
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1234 "addbuddy", MSIM_TYPE_BOOLEAN, TRUE,
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
1235 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1236 /* "newprofileid" will be inserted here with uid. */
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1237 "reason", MSIM_TYPE_STRING, g_strdup(""),
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1238 NULL);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1239
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1240 if (!msim_postprocess_outgoing(session, msg, buddy->name, "newprofileid", "reason"))
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1241 {
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1242 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed."));
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1243 msim_msg_free(msg);
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1244 return;
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1245 }
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1246 msim_msg_free(msg);
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1247
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1248 /* TODO: update blocklist */
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1249
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1250 #if 0
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1251 /* TODO */
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1252 if (!msim_send(session,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1253 "persist", MSIM_TYPE_INTEGER, 1,
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
1254 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1255 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1256 "dsn", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_DSN,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1257 "lid", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_LID,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1258 /* TODO: msim_send_persist, to handle all this rid business */
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1259 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1260 "body", MSIM_TYPE_STRING,
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1261 g_strdup_printf("ContactID=%s\034"
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1262 "GroupName=%s\034"
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1263 "Position=1000\034"
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1264 "Visibility=1\034"
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1265 "NickName=\034"
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1266 "NameSelect=0",
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1267 buddy->name, group->name),
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1268 NULL))
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1269 {
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1270 purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed"));
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1271 return;
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1272 }
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1273 #endif
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1274 }
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1275
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1276 /** Perform actual postprocessing on a message, adding userid as specified.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1277 *
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1278 * @param msg The message to postprocess.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1279 * @param uid_before Name of field where to insert new field before, or NULL for end.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1280 * @param uid_field_name Name of field to add uid to.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1281 * @param uid The userid to insert.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1282 *
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1283 * If the field named by uid_field_name already exists, then its string contents will
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1284 * be used for the field, except "<uid>" will be replaced by the userid.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1285 *
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1286 * If the field named by uid_field_name does not exist, it will be added before the
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1287 * field named by uid_before, as an integer, with the userid.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1288 *
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1289 * Does not handle sending, or scheduling userid lookup. For that, see msim_postprocess_outgoing().
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1290 */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1291 MsimMessage *msim_do_postprocessing(MsimMessage *msg, gchar *uid_before, gchar *uid_field_name, guint uid)
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1292 {
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1293 purple_debug_info("msim", "msim_do_postprocessing called with ufn=%s, ub=%s, uid=%d\n",
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1294 uid_field_name, uid_before, uid);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1295 msim_msg_dump("msim_do_postprocessing msg: %s\n", msg);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1296
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1297 /* First, check - if the field already exists, treat it as a format string. */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1298 if (msim_msg_get(msg, uid_field_name))
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1299 {
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1300 MsimMessageElement *elem;
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1301 gchar *fmt_string;
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1302 gchar *uid_str;
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1303
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1304 /* Warning: this probably violates the encapsulation of MsimMessage */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1305
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1306 elem = msim_msg_get(msg, uid_field_name);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1307 g_return_val_if_fail(elem->type == MSIM_TYPE_STRING, NULL);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1308
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1309 /* Get the raw string, not with msim_msg_get_string() since that copies it.
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1310 * Want the original string so can free it. */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1311 fmt_string = (gchar *)(elem->data);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1312
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1313 uid_str = g_strdup_printf("%d", uid);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1314 elem->data = str_replace(fmt_string, "<uid>", uid_str);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1315 g_free(uid_str);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1316 g_free(fmt_string);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1317
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1318 purple_debug_info("msim", "msim_postprocess_outgoing_cb: formatted new string, %s\n",
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1319 elem->data);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1320
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1321 } else {
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1322 /* Otherwise, insert new field into outgoing message. */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1323 msg = msim_msg_insert_before(msg, uid_before, uid_field_name, MSIM_TYPE_INTEGER, GUINT_TO_POINTER(uid));
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1324 }
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1325
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1326 return msg;
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1327 }
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1328
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1329 /** Callback for msim_postprocess_outgoing() to add a userid to a message, and send it (once receiving userid).
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1330 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1331 * @param session
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1332 * @param userinfo The user information reply message, containing the user ID
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1333 * @param data The message to postprocess and send.
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1334 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1335 * The data message should contain these fields:
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1336 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1337 * _uid_field_name: string, name of field to add with userid from userinfo message
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1338 * _uid_before: string, name of field before field to insert, or NULL for end
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1339 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1340 *
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1341 */
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1342 void msim_postprocess_outgoing_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1343 {
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1344 gchar *body_str;
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1345 GHashTable *body;
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1346 gchar *uid, *uid_field_name, *uid_before;
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1347 MsimMessage *msg;
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1348
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1349 msg = (MsimMessage *)data;
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1350
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1351 msim_msg_dump("msim_postprocess_outgoing_cb() got msg=%s\n", msg);
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1352
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1353 /* Obtain userid from userinfo message. */
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1354 body_str = msim_msg_get_string(userinfo, "body");
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1355 g_return_if_fail(body_str != NULL);
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1356 body = msim_parse_body(body_str);
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1357 g_free(body_str);
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1358
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1359 uid = g_strdup(g_hash_table_lookup(body, "UserID"));
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1360 g_hash_table_destroy(body);
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1361
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1362 uid_field_name = msim_msg_get_string(msg, "_uid_field_name");
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1363 uid_before = msim_msg_get_string(msg, "_uid_before");
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1364
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1365 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, atol(uid));
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1366
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1367 /* Send */
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1368 if (!msim_msg_send(session, msg))
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1369 {
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1370 purple_debug_info("msim", "msim_postprocess_outgoing_cb: sending failed for message: %s\n", msg);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1371 }
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1372
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1373
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1374 /* Free field names AFTER sending message, because MsimMessage does NOT copy
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1375 * field names - instead, treats them as static strings (which they usually are).
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1376 */
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1377 g_free(uid_field_name);
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1378 g_free(uid_before);
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1379
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1380 //msim_msg_free(msg);
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1381 }
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1382
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1383 /** Postprocess and send a message.
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1384 *
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1385 * @param session
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1386 * @param msg Message to postprocess. Will NOT be freed.
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1387 * @param username Username to resolve. Assumed to be a static string (will not be freed or copied).
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1388 * @param uid_field_name Name of new field to add, containing uid of username. Static string.
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1389 * @param uid_before Name of existing field to insert username field before. Static string.
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1390 *
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1391 * @return Postprocessed message.
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1392 */
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1393 gboolean msim_postprocess_outgoing(MsimSession *session, MsimMessage *msg, gchar *username,
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1394 gchar *uid_field_name, gchar *uid_before)
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1395 {
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1396 PurpleBuddy *buddy;
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1397 guint uid;
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1398 gboolean rc;
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1399
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1400 /* Store information for msim_postprocess_outgoing_cb(). */
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1401 purple_debug_info("msim", "msim_postprocess_outgoing(u=%s,ufn=%s,ub=%s)\n",
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1402 username, uid_field_name, uid_before);
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1403 msim_msg_dump("msim_postprocess_outgoing: msg before=%s\n", msg);
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1404 msg = msim_msg_append(msg, "_username", MSIM_TYPE_STRING, g_strdup(username));
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1405 msg = msim_msg_append(msg, "_uid_field_name", MSIM_TYPE_STRING, g_strdup(uid_field_name));
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1406 msg = msim_msg_append(msg, "_uid_before", MSIM_TYPE_STRING, g_strdup(uid_before));
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1407
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1408 /* First, try the most obvious. If numeric userid is given, use that directly. */
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1409 if (msim_is_userid(username))
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1410 {
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1411 uid = atol(username);
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1412 } else {
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1413 /* Next, see if on buddy list and know uid. */
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1414 buddy = purple_find_buddy(session->account, username);
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1415 if (buddy)
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1416 {
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1417 uid = purple_blist_node_get_int(&buddy->node, "uid");
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1418 } else {
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1419 uid = 0;
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1420 }
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1421
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1422 if (!buddy || !uid)
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1423 {
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1424 /* Don't have uid offhand - need to ask for it, and wait until hear back before sending. */
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1425 purple_debug_info("msim", ">>> msim_postprocess_outgoing: couldn't find username %s in blist\n",
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1426 username);
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1427 msim_msg_dump("msim_postprocess_outgoing - scheduling lookup, msg=%s\n", msg);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1428 /* TODO: where is cloned message freed? Should be in _cb. */
17311
3720176bdac6 Pass postprocessing parameters inside MsimMessage * instead of in a new struct.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17310
diff changeset
1429 msim_lookup_user(session, username, msim_postprocess_outgoing_cb, msim_msg_clone(msg));
17310
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1430 return TRUE; /* not sure of status yet - haven't sent! */
05723949f75d Change msim_send_im() to use msim_postprocess_outgoing(), eliminating the
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17309
diff changeset
1431 }
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1432 }
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1433
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1434 /* Already have uid, postprocess and send msg immediately. */
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1435 purple_debug_info("msim", "msim_postprocess_outgoing: found username %s has uid %d\n",
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1436 username, uid);
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1437
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1438 msg = msim_do_postprocessing(msg, uid_before, uid_field_name, uid);
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1439
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1440 msim_msg_dump("msim_postprocess_outgoing: msg after (uid immediate)=%s\n", msg);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1441
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1442 rc = msim_msg_send(session, msg);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1443
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1444 //msim_msg_free(msg);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1445
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1446 return rc;
17309
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1447 }
25a55b52855a Add, but do not use, two new functions to postprocess outgoing messages
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17308
diff changeset
1448
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1449 /** Remove a buddy from the user's buddy list. */
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1450 void msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1451 {
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1452 MsimSession *session;
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1453 MsimMessage *delbuddy_msg;
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1454 MsimMessage *persist_msg;
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1455 MsimMessage *blocklist_msg;
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1456
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1457 session = (MsimSession *)gc->proto_data;
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1458
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1459 delbuddy_msg = msim_msg_new(TRUE,
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1460 "delbuddy", MSIM_TYPE_BOOLEAN, TRUE,
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
1461 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1462 /* 'delprofileid' with uid will be inserted here. */
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1463 NULL);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1464 /* TODO: free msg */
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1465 if (!msim_postprocess_outgoing(session, delbuddy_msg, buddy->name, "delprofileid", NULL))
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1466 {
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1467 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed"));
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1468 return;
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1469 }
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1470
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1471 persist_msg = msim_msg_new(TRUE,
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1472 "persist", MSIM_TYPE_INTEGER, 1,
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
1473 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1474 "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE,
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1475 "dsn", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_DSN,
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1476 "lid", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_LID,
17317
e9dfd3a5d4b6 Remove msim_get_own_uid{,_cb}() - it is not needed, since the login
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17316
diff changeset
1477 "uid", MSIM_TYPE_INTEGER, session->userid,
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1478 "rid", MSIM_TYPE_INTEGER, session->next_rid++,
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1479 /* <uid> will be replaced by postprocessing */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1480 "body", MSIM_TYPE_STRING, g_strdup("ContactID=<uid>"),
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1481 NULL);
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1482
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1483 /* TODO: free msg */
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1484 if (!msim_postprocess_outgoing(session, persist_msg, buddy->name, "body", NULL))
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1485 {
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1486 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed"));
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1487 return;
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1488 }
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1489
17319
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1490 blocklist_msg = msim_msg_new(TRUE,
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1491 "blocklist", MSIM_TYPE_BOOLEAN, TRUE,
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1492 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1493 /* TODO: MsimMessage lists */
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1494 "idlist", MSIM_TYPE_STRING, g_strdup("a-|<uid>|b-|<uid>"),
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1495 NULL);
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1496
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1497 if (!msim_postprocess_outgoing(session, blocklist_msg, buddy->name, "idlist", NULL))
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1498 {
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1499 purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("blocklist command failed"));
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1500 return;
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1501 }
4cb842e0649c Make msim_remove_buddy() functional. It now sends the delbuddy, persist,
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17317
diff changeset
1502
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1503 /* TODO: update blocklist */
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1504 }
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1505
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1506
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1507
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1508 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1509 * Callback when input available.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1510 *
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1511 * @param gc_uncasted A PurpleConnection pointer.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1512 * @param source File descriptor.
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1513 * @param cond PURPLE_INPUT_READ
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1514 *
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1515 * Reads the input, and calls msim_preprocess_incoming() to handle it.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1516 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1517 void msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1518 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1519 PurpleConnection *gc;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1520 PurpleAccount *account;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1521 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1522 gchar *end;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1523 int n;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1524
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1525 g_return_if_fail(gc_uncasted != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1526 g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1527
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1528 gc = (PurpleConnection *)(gc_uncasted);
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1529 account = purple_connection_get_account(gc);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1530 session = gc->proto_data;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1531
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1532 g_return_if_fail(cond == PURPLE_INPUT_READ);
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1533 /* TODO: fix bug #193, crash when re-login */
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1534 g_return_if_fail(MSIM_SESSION_VALID(session));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1535
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1536 /* Only can handle so much data at once...
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1537 * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1538 * Should be large enough to hold the largest protocol message.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1539 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1540 if (session->rxoff == MSIM_READ_BUF_SIZE)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1541 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1542 purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n",
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1543 MSIM_READ_BUF_SIZE);
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1544 purple_connection_error(gc, _("Read buffer full"));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1545 /* TODO: fix 100% CPU after closing */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1546 close(source);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1547 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1548 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1549
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1550 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1551 session->rxoff, MSIM_READ_BUF_SIZE,
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1552 MSIM_READ_BUF_SIZE - session->rxoff);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1553
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1554 /* Read into buffer. On Win32, need recv() not read(). session->fd also holds
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1555 * the file descriptor, but it sometimes differs from the 'source' parameter.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1556 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1557 n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1558
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1559 if (n < 0 && errno == EAGAIN)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1560 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1561 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1562 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1563 else if (n < 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1564 {
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1565 purple_connection_error(gc, _("Read error"));
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1566 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1567 "error=%s, source=%d, fd=%d (%X))\n",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1568 n, strerror(errno), source, session->fd, session->fd);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1569 close(source);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1570 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1571 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1572 else if (n == 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1573 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1574 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1575 purple_connection_error(gc, _("Server has disconnected"));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1576 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1577 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1578
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1579 /* Null terminate */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1580 session->rxbuf[session->rxoff + n] = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1581
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1582 /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1583 if (strlen(session->rxbuf + session->rxoff) != n)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1584 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1585 /* Occurs after login, but it is not a null byte. */
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1586 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1587 "--null byte encountered?\n",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1588 strlen(session->rxbuf + session->rxoff), n);
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1589 //purple_connection_error(gc, "Invalid message - null byte on input");
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1590 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1591 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1592
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1593 session->rxoff += n;
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1594 purple_debug_info("msim", "msim_input_cb: read=%d\n", n);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1595
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
1596 #ifdef MSIM_DEBUG_RXBUF
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1597 purple_debug_info("msim", "buf=<%s>\n", session->rxbuf);
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1598 #endif
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1599
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1600 /* Look for \\final\\ end markers. If found, process message. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1601 while((end = strstr(session->rxbuf, MSIM_FINAL_STRING)))
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1602 {
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1603 MsimMessage *msg;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1604
16725
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16723
diff changeset
1605 #ifdef MSIM_DEBUG_RXBUF
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1606 purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf);
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1607 #endif
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1608 *end = 0;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1609 msg = msim_parse(g_strdup(session->rxbuf));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1610 if (!msg)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1611 {
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1612 purple_debug_info("msim", "msim_input_cb: couldn't parse <%s>\n",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1613 session->rxbuf);
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1614 purple_connection_error(gc, _("Unparseable message"));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1615 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1616 else
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1617 {
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1618 /* Process message and then free it (processing function should
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1619 * clone message if it wants to keep it afterwards.) */
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1620 if (!msim_preprocess_incoming(session, msg))
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1621 {
17306
3a02e7db91c7 Add message preprocessing in msim_preprocess_incoming(), to resolve
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17305
diff changeset
1622 msim_msg_dump("msim_input_cb: preprocessing message failed on msg: %s\n", msg);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1623 }
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1624 msim_msg_free(msg);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1625 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1626
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1627 /* Move remaining part of buffer to beginning. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1628 session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1629 memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING),
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1630 MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1631
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1632 /* Clear end of buffer */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1633 //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1634 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1635 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1636
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1637 /* Setup a callback, to be called when a reply is received with the returned rid.
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1638 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1639 * @param cb The callback, an MSIM_USER_LOOKUP_CB.
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1640 * @param data Arbitrary user data to be passed to callback (probably an MsimMessage *).
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1641 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1642 * @return The request/reply ID, used to link replies with requests. Put the rid in your request.
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1643 *
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1644 * TODO: Make more generic and more specific:
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1645 * 1) MSIM_USER_LOOKUP_CB - make it for PERSIST_REPLY, not just user lookup
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1646 * 2) data - make it an MsimMessage?
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1647 */
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1648 guint msim_new_reply_callback(MsimSession *session, MSIM_USER_LOOKUP_CB cb, gpointer data)
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1649 {
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1650 guint rid;
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1651
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1652 rid = session->next_rid++;
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1653
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1654 g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1655 g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data);
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1656
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1657 return rid;
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1658 }
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1659
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1660 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1661 * Callback when connected. Sets up input handlers.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1662 *
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1663 * @param data A PurpleConnection pointer.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1664 * @param source File descriptor.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1665 * @param error_message
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1666 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1667 void msim_connect_cb(gpointer data, gint source, const gchar *error_message)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1668 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1669 PurpleConnection *gc;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1670 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1671
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1672 g_return_if_fail(data != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1673
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1674 gc = (PurpleConnection *)data;
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1675 session = (MsimSession *)gc->proto_data;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1676
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1677 if (source < 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1678 {
16728
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1679 purple_connection_error(gc, _("Couldn't connect to host"));
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16727
diff changeset
1680 purple_connection_error(gc, g_strdup_printf(_("Couldn't connect to host: %s (%d)"),
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1681 error_message, source));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1682 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1683 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1684
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1685 session->fd = source;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1686
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1687 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1688 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1689
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1690 /* Session methods */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1691
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1692 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1693 * Create a new MSIM session.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1694 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1695 * @param acct The account to create the session from.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1696 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1697 * @return Pointer to a new session. Free with msim_session_destroy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1698 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1699 MsimSession *msim_session_new(PurpleAccount *acct)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1700 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1701 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1702
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1703 g_return_val_if_fail(acct != NULL, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1704
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1705 session = g_new0(MsimSession, 1);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1706
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1707 session->magic = MSIM_SESSION_STRUCT_MAGIC;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1708 session->account = acct;
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1709 session->gc = purple_account_get_connection(acct);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1710 session->fd = -1;
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1711
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1712 /* TODO: Remove. */
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1713 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1714 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1715 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
17303
ceba4fc06c41 Change msim_send_im_by_userid_cb() to msim_send_im_cb(), and remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17300
diff changeset
1716 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1717 they could be integers inside gpointers
17303
ceba4fc06c41 Change msim_send_im_by_userid_cb() to msim_send_im_cb(), and remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17300
diff changeset
1718 or strings, so I don't freed them.
17280
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17266
diff changeset
1719 Figure this out, once free cache. */
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1720 session->user_lookup_cache = g_hash_table_new_full(g_str_hash, g_str_equal,
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1721 g_free, (GDestroyNotify)g_hash_table_destroy);
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1722
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1723 session->rxoff = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1724 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
16407
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
1725 session->next_rid = 1;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1726
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1727 return session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1728 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1729
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1730 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1731 * Free a session.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1732 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1733 * @param session The session to destroy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1734 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1735 void msim_session_destroy(MsimSession *session)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1736 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1737 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1738
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1739 session->magic = -1;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1740
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1741 g_free(session->rxbuf);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1742
17313
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1743 /* TODO: Remove. */
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1744 g_hash_table_destroy(session->user_lookup_cb);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1745 g_hash_table_destroy(session->user_lookup_cb_data);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1746 g_hash_table_destroy(session->user_lookup_cache);
7a0061f4845d Add msim_uid2username_from_blist() to lookup a username by userid, by
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17312
diff changeset
1747
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1748 g_free(session);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1749 }
16405
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16404
diff changeset
1750
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1751
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1752
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1753 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1754 * Close the connection.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1755 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1756 * @param gc The connection.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1757 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1758 void msim_close(PurpleConnection *gc)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1759 {
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1760 MsimSession *session;
17293
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1761
bfda36bd957a Add incomplete msim_add_buddy() implementation.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17291
diff changeset
1762 purple_debug_info("msim", "msim_close: destroying session\n");
17314
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1763
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1764 session = (MsimSession *)gc->proto_data;
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1765
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1766 g_return_if_fail(gc != NULL);
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1767 g_return_if_fail(session != NULL);
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1768 g_return_if_fail(MSIM_SESSION_VALID(session));
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1769
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1770
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1771 purple_input_remove(session->fd);
948373cbba1c Add TODO in order to fix msim_tooltip_text.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17313
diff changeset
1772 msim_session_destroy(session);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1773 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1774
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1775
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1776 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1777 * Check if a string is a userid (all numeric).
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1778 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1779 * @param user The user id, email, or name.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1780 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1781 * @return TRUE if is userid, FALSE if not.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1782 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1783 gboolean msim_is_userid(const gchar *user)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1784 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1785 g_return_val_if_fail(user != NULL, FALSE);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1786
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1787 return strspn(user, "0123456789") == strlen(user);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1788 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1789
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1790 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1791 * Check if a string is an email address (contains an @).
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1792 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1793 * @param user The user id, email, or name.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1794 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1795 * @return TRUE if is an email, FALSE if not.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1796 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1797 * This function is not intended to be used as a generic
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1798 * means of validating email addresses, but to distinguish
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1799 * between a user represented by an email address from
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1800 * other forms of identification.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1801 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1802 gboolean msim_is_email(const gchar *user)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1803 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1804 g_return_val_if_fail(user != NULL, FALSE);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1805
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1806 return strchr(user, '@') != NULL;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1807 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1808
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1809
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1810 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1811 * Asynchronously lookup user information, calling callback when receive result.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1812 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1813 * @param session
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1814 * @param user The user id, email address, or username.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1815 * @param cb Callback, called with user information when available.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1816 * @param data An arbitray data pointer passed to the callback.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1817 */
17299
c6305f8845d8 Add TODOs about username/email->userid resolution, use g_return_if_fail() in a few places.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17298
diff changeset
1818 /* TODO: change to not use callbacks */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1819 void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1820 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1821 gchar *field_name;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1822 guint rid, cmd, dsn, lid;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1823
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1824 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1825 g_return_if_fail(user != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1826 g_return_if_fail(cb != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1827
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1828 purple_debug_info("msim", "msim_lookup_userid: "
16404
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16402
diff changeset
1829 "asynchronously looking up <%s>\n", user);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1830
17312
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1831 msim_msg_dump("msim_lookup_user: data=%s\n", (MsimMessage *)data);
962edb051146 Use msim_postprocess_outgoing() to resolve uid for adding and deleting buddies.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17311
diff changeset
1832
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1833 /* TODO: check if this user's info was cached and fresh; if so return immediately */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1834 #if 0
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1835 /* If already know userid, then call callback immediately */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1836 cached_userid = g_hash_table_lookup(session->userid_cache, who);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1837 if (cached_userid && !by_userid)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1838 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1839 cb(cached_userid, NULL, NULL, data);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1840 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1841 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1842 #endif
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1843
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1844 /* Setup callback. Response will be associated with request using 'rid'. */
17316
2aff11bb5e72 Several small changes to work towards a working msim_remove_buddy():
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17315
diff changeset
1845 rid = msim_new_reply_callback(session, cb, data);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1846
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1847 /* Send request */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1848
17286
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1849 cmd = MSIM_CMD_GET;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1850
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1851 if (msim_is_userid(user))
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1852 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1853 field_name = "UserID";
17286
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1854 dsn = MG_MYSPACE_INFO_BY_ID_DSN;
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1855 lid = MG_MYSPACE_INFO_BY_ID_LID;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1856 } else if (msim_is_email(user)) {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1857 field_name = "Email";
17286
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1858 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1859 lid = MG_MYSPACE_INFO_BY_STRING_LID;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1860 } else {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1861 field_name = "UserName";
17286
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1862 dsn = MG_MYSPACE_INFO_BY_STRING_DSN;
58b4d103a5b8 Use symbolic constants for persist messages.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17285
diff changeset
1863 lid = MG_MYSPACE_INFO_BY_STRING_LID;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1864 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1865
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1866
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1867 g_return_if_fail(msim_send(session,
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1868 "persist", MSIM_TYPE_INTEGER, 1,
17297
c2208b64bffb Change MsimSession.sesskey to an integer (used to be a string), now that
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17296
diff changeset
1869 "sesskey", MSIM_TYPE_INTEGER, session->sesskey,
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1870 "cmd", MSIM_TYPE_INTEGER, 1,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1871 "dsn", MSIM_TYPE_INTEGER, dsn,
17317
e9dfd3a5d4b6 Remove msim_get_own_uid{,_cb}() - it is not needed, since the login
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17316
diff changeset
1872 "uid", MSIM_TYPE_INTEGER, session->userid,
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1873 "lid", MSIM_TYPE_INTEGER, lid,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1874 "rid", MSIM_TYPE_INTEGER, rid,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1875 /* TODO: dictionary field type */
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1876 "body", MSIM_TYPE_STRING, g_strdup_printf("%s=%s", field_name, user),
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
1877 NULL));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1878 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1879
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1880
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1881 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1882 * Obtain the status text for a buddy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1883 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1884 * @param buddy The buddy to obtain status text for.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1885 *
16727
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1886 * @return Status text, or NULL if error.
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1887 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1888 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1889 char *msim_status_text(PurpleBuddy *buddy)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1890 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1891 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1892 GHashTable *userinfo;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1893 gchar *display_name;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1894
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1895 g_return_val_if_fail(buddy != NULL, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1896
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1897 session = (MsimSession *)buddy->account->gc->proto_data;
16727
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1898 g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL);
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1899 g_return_val_if_fail(session->user_lookup_cache != NULL, NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1900
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1901 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1902 if (!userinfo)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1903 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1904 return g_strdup("");
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1905 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1906
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1907 display_name = g_hash_table_lookup(userinfo, "DisplayName");
16727
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1908 g_return_val_if_fail(display_name != NULL, NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1909
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1910 return g_strdup(display_name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1911 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1912
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1913 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1914 * Obtain the tooltip text for a buddy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1915 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1916 * @param buddy Buddy to obtain tooltip text on.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1917 * @param user_info Variable modified to have the tooltip text.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1918 * @param full TRUE if should obtain full tooltip text.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1919 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1920 */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1921 void msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full)
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1922 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1923 g_return_if_fail(buddy != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1924 g_return_if_fail(user_info != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1925
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1926 if (PURPLE_BUDDY_IS_ONLINE(buddy))
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1927 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1928 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1929 GHashTable *userinfo;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1930
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1931 session = (MsimSession *)buddy->account->gc->proto_data;
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1932
16727
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1933 g_return_if_fail(MSIM_SESSION_VALID(session));
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1934 g_return_if_fail(session->user_lookup_cache);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1935
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1936 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1937
16727
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16726
diff changeset
1938 g_return_if_fail(userinfo != NULL);
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1939
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1940 // TODO: if (full), do something different
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1941 purple_notify_user_info_add_pair(user_info, "User ID", g_hash_table_lookup(userinfo, "UserID"));
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1942 purple_notify_user_info_add_pair(user_info, "Display Name", g_hash_table_lookup(userinfo, "DisplayName"));
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1943 purple_notify_user_info_add_pair(user_info, "User Name", g_hash_table_lookup(userinfo, "UserName"));
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1944 purple_notify_user_info_add_pair(user_info, "Total Friends", g_hash_table_lookup(userinfo, "TotalFriends"));
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1945 purple_notify_user_info_add_pair(user_info, "Song",
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1946 g_strdup_printf("%s - %s",
16738
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1947 (gchar *)g_hash_table_lookup(userinfo, "BandName"),
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1948 (gchar *)g_hash_table_lookup(userinfo, "SongName")));
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1949 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1950 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1951
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
1952 /** Callbacks called by Purple, to access this plugin. */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
1953 PurplePluginProtocolInfo prpl_info =
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1954 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1955 OPT_PROTO_MAIL_CHECK,/* options - TODO: myspace will notify of mail */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1956 NULL, /* user_splits */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1957 NULL, /* protocol_options */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1958 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1959 msim_list_icon, /* list_icon */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1960 NULL, /* list_emblems */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1961 msim_status_text, /* status_text */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1962 msim_tooltip_text, /* tooltip_text */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1963 msim_status_types, /* status_types */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1964 NULL, /* blist_node_menu */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1965 NULL, /* chat_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1966 NULL, /* chat_info_defaults */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1967 msim_login, /* login */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1968 msim_close, /* close */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1969 msim_send_im, /* send_im */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1970 NULL, /* set_info */
17290
aa8e70fa1edc Add, but do not use, incomplete functions for using typing notifications.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17289
diff changeset
1971 msim_send_typing, /* send_typing */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1972 NULL, /* get_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1973 NULL, /* set_away */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1974 NULL, /* set_idle */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1975 NULL, /* change_passwd */
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1976 msim_add_buddy, /* add_buddy */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1977 NULL, /* add_buddies */
17296
1905859d7a3b Add (incomplete) msim_remove_buddy().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17293
diff changeset
1978 msim_remove_buddy, /* remove_buddy */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1979 NULL, /* remove_buddies */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1980 NULL, /* add_permit */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1981 NULL, /* add_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1982 NULL, /* rem_permit */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1983 NULL, /* rem_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1984 NULL, /* set_permit_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1985 NULL, /* join_chat */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1986 NULL, /* reject chat invite */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1987 NULL, /* get_chat_name */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1988 NULL, /* chat_invite */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1989 NULL, /* chat_leave */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1990 NULL, /* chat_whisper */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1991 NULL, /* chat_send */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1992 NULL, /* keepalive */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1993 NULL, /* register_user */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1994 NULL, /* get_cb_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1995 NULL, /* get_cb_away */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1996 NULL, /* alias_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1997 NULL, /* group_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1998 NULL, /* rename_group */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1999 NULL, /* buddy_free */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2000 NULL, /* convo_closed */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2001 NULL, /* normalize */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2002 NULL, /* set_buddy_icon */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2003 NULL, /* remove_group */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2004 NULL, /* get_cb_real_name */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2005 NULL, /* set_chat_topic */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2006 NULL, /* find_blist_chat */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2007 NULL, /* roomlist_get_list */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2008 NULL, /* roomlist_cancel */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2009 NULL, /* roomlist_expand_category */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2010 NULL, /* can_receive_file */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2011 NULL, /* send_file */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2012 NULL, /* new_xfer */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2013 NULL, /* offline_message */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2014 NULL, /* whiteboard_prpl_ops */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2015 NULL, /* send_raw */
16723
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2016 NULL, /* roomlist_room_serialize */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2017 NULL, /* _purple_reserved1 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2018 NULL, /* _purple_reserved2 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2019 NULL, /* _purple_reserved3 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2020 NULL /* _purple_reserved4 */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2021 };
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2022
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2023
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2024
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2025 /** Based on MSN's plugin info comments. */
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
2026 PurplePluginInfo info =
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2027 {
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
2028 PURPLE_PLUGIN_MAGIC,
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
2029 PURPLE_MAJOR_VERSION,
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
2030 PURPLE_MINOR_VERSION,
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2031 PURPLE_PLUGIN_PROTOCOL, /**< type */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2032 NULL, /**< ui_requirement */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2033 0, /**< flags */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2034 NULL, /**< dependencies */
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2035 PURPLE_PRIORITY_DEFAULT, /**< priority */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2036
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2037 "prpl-myspace", /**< id */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2038 "MySpaceIM", /**< name */
17289
73720427b132 Show online buddies on buddy list as online.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17287
diff changeset
2039 "0.6", /**< version */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2040 /** summary */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2041 "MySpaceIM Protocol Plugin",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2042 /** description */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2043 "MySpaceIM Protocol Plugin",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2044 "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2045 "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2046
16726
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16725
diff changeset
2047 msim_load, /**< load */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2048 NULL, /**< unload */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2049 NULL, /**< destroy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2050 NULL, /**< ui_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2051 &prpl_info, /**< extra_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2052 NULL, /**< prefs_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2053
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2054 /* msim_actions */
16723
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2055 NULL,
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2056
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2057 NULL, /**< reserved1 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2058 NULL, /**< reserved2 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2059 NULL, /**< reserved3 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16409
diff changeset
2060 NULL /**< reserved4 */
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2061 };
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2062
16736
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16735
diff changeset
2063 void init_plugin(PurplePlugin *plugin)
16733
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2064 {
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2065 PurpleAccountOption *option;
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2066 #ifdef _TEST_MSIM_MSG
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2067 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2068 MsimMessage *msg;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2069
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2070 purple_debug_info("msim", "testing MsimMessage\n");
17303
ceba4fc06c41 Change msim_send_im_by_userid_cb() to msim_send_im_cb(), and remove
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17300
diff changeset
2071 msg = msim_msg_new(FALSE);
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2072 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2073 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1"));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2074 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2075 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43"));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2076 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy"));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2077 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7"));
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
2078 purple_debug_info("msim", "msg debug str=%s\n", msim_msg_debug_string(msg));
17298
9c5b1dc7404f Change msim_msg_debug_string() to msim_msg_dump(), which prints the string
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17297
diff changeset
2079 msim_msg_debug_dump("msg debug str=%s\n", msg);
17291
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
2080 purple_debug_info("msim", "msg packed=%s\n", msim_msg_pack(msg));
d8903e1320a9 Previously, the return value of the processing function and msim_process() told
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17290
diff changeset
2081 purple_debug_info("msim", "msg cloned=%s\n", msim_msg_pack(msim_msg_clone(msg)));
17266
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2082 msim_msg_free(msg);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2083 exit(0);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
2084 }
16735
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
2085 #endif
16733
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2086
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2087 /* TODO: default to automatically try different ports. Make the user be
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2088 * able to set the first port to try (like LastConnectedPort in Windows client). */
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2089 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2090 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2091
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2092 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2093 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16731
diff changeset
2094 }
16394
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
2095
16396
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16394
diff changeset
2096 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);