annotate libpurple/protocols/myspace/myspace.c @ 17337:d3e17c9d16e9

Use MsimMessage for receiving messages everywhere, instead of GHashTable.
author Jeffrey Connelly <jaconnel@calpoly.edu>
date Fri, 01 Jun 2007 06:09:32 +0000
parents 793301c04e3a
children 9ecd2bb0ecc1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16395
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 *
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
5 * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im>
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
6 *
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
7 * Based on Purple's "C Plugin HOWTO" hello world example.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
8 *
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
9 * Code also drawn from mockprpl:
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
10 * http://snarfed.org/space/purple+mock+protocol+plugin
16395
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 *
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
13 * and some constructs also based on existing Purple plugins, which are:
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
14 * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net>
16395
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
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
34 #define PURPLE_PLUGIN
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
35
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
36 #include "message.h"
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
37 #include "myspace.h"
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
38
16737
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
39 /**
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
40 * Load the plugin.
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
41 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
42 gboolean msim_load(PurplePlugin *plugin)
16737
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
43 {
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
44 #ifdef MSIM_USE_PURPLE_RC4
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
45 /* 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: 16736
diff changeset
46 if (!purple_ciphers_find_cipher("rc4"))
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
47 {
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
48 purple_debug_error("msim", "compiled with MSIM_USE_PURPLE_RC4 but rc4 not in libpurple - not loading MySpaceIM plugin!\n");
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
49 purple_notify_error(plugin, _("Missing Cipher"),
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
50 _("The RC4 cipher could not be found"),
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
51 _("Recompile without MSIM_USE_PURPLE_RC4, or upgrade "
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
52 "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM "
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
53 "plugin will not be loaded."));
16737
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
54 return FALSE;
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
55 }
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
56 #endif
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
57 return TRUE;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
58 }
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 * Get possible user status types. Based on mockprpl.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
62 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
63 * @return GList of status types.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
64 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
65 GList *msim_status_types(PurpleAccount *acct)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
66 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
67 GList *types;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
68 PurpleStatusType *status;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
69
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
70 purple_debug_info("myspace", "returning status types\n");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
71
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
72 types = NULL;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
73
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
74 /* TODO: Fix these:
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
75 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
76 * 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: 16749
diff changeset
77 * 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: 16749
diff changeset
78 * [...]
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
79 *
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
80 * and
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
81 * 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: 16749
diff changeset
82 * [...]
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
83 */
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
84 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: 16749
diff changeset
85 types = g_list_append(types, status);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
86
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
87 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: 16749
diff changeset
88 types = g_list_append(types, status);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
89
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
90 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: 16749
diff changeset
91 types = g_list_append(types, status);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
92
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
93 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: 16749
diff changeset
94 types = g_list_append(types, status);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
95
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
96 return types;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
97 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
98
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
99 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
100 * Return the icon name for a buddy and account.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
101 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
102 * @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: 16405
diff changeset
103 * @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: 16405
diff changeset
104 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
105 * @return The base icon name string.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
106 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
107 const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy)
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
108 {
16744
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
109 /* Use a MySpace icon submitted by hbons submitted one at
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
110 * http://developer.pidgin.im/wiki/MySpaceIM. */
16407
f62023eddfc6 Add and use MySpaceIM icon uploaded by hbons (48x48 original and resized 22x22 and 16x16 versions).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16406
diff changeset
111 return "myspace";
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
112 }
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
113
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
114 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
115 * Unescape a protocol message.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
116 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
117 * @return The unescaped message. Caller must g_free().
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
118 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
119 gchar *msim_unescape(const gchar *msg)
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
120 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
121 /* TODO: make more elegant, refactor with msim_escape */
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
122 gchar *tmp, *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
123
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
124 tmp = str_replace(msg, "/1", "/");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
125 ret = str_replace(tmp, "/2", "\\");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
126 g_free(tmp);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
127 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
128 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
129
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
130 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
131 * Escape a protocol message.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
132 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
133 * @return The escaped message. Caller must g_free().
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
134 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
135 gchar *msim_escape(const gchar *msg)
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
136 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
137 /* TODO: make more elegant, refactor with msim_unescape */
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
138 gchar *tmp, *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
139
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
140 tmp = str_replace(msg, "/", "/1");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
141 ret = str_replace(tmp, "\\", "/2");
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
142 g_free(tmp);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
143
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
144 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
145 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
146
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
147 /**
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
148 * Replace 'old' with 'new' in 'str'.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
149 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
150 * @param str The original string.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
151 * @param old The substring of 'str' to replace.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
152 * @param new The replacement for 'old' within 'str'.
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
153 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
154 * @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: 16408
diff changeset
155 * 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: 16408
diff changeset
156 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
157 * This string replace method is based on
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
158 * 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: 16408
diff changeset
159 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
160 */
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
161 gchar *str_replace(const gchar *str, const gchar *old, const gchar *new)
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
162 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
163 char **items;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
164 char *ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
165
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
166 items = g_strsplit(str, old, -1);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
167 ret = g_strjoinv(new, items);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
168 g_free(items);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
169 return ret;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
170 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
171
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
172
16746
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16745
diff changeset
173
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
174
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
175 #ifdef MSIM_DEBUG_MSG
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
176 void print_hash_item(gpointer key, gpointer value, gpointer user_data)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
177 {
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
178 purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
179 }
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
180 #endif
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
181
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
182 /**
16734
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
183 * Send raw data to the server.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
184 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
185 * @param session
16734
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
186 * @param msg The raw data to send.
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
187 *
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
188 * @return TRUE if succeeded, FALSE if not.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
189 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
190 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
191 gboolean msim_send_raw(MsimSession *session, const gchar *msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
192 {
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
193 int total_bytes_sent, total_bytes;
16741
a2e9890a57e0 Implement msim_pack(), msim_sendh(), msim_send().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16740
diff changeset
194
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
195 purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
196
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
197 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: 16408
diff changeset
198 g_return_val_if_fail(msg != NULL, FALSE);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
199
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
200
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
201 /* 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: 16408
diff changeset
202 total_bytes_sent = 0;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
203 total_bytes = strlen(msg);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
204 do
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
205 {
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
206 int bytes_sent;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
207
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
208 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: 16408
diff changeset
209 total_bytes - total_bytes_sent, 0);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
210
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
211 if (bytes_sent < 0)
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
212 {
16734
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
213 purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n",
16410
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
214 msg, g_strerror(errno));
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
215 return FALSE;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
216 }
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
217 total_bytes_sent += bytes_sent;
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
218
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
219 } while(total_bytes_sent < total_bytes);
1aa62f7368ca Add escaping and unescaping functions (for /1 and /2).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16408
diff changeset
220 return TRUE;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
221 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
222
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
223 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
224 * Start logging in to the MSIM servers.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
225 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
226 * @param acct Account information to use to login.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
227 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
228 void msim_login(PurpleAccount *acct)
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
229 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
230 PurpleConnection *gc;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
231 const char *host;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
232 int port;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
233
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
234 g_return_if_fail(acct != NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
235
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
236 purple_debug_info("myspace", "logging in %s\n", acct->username);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
237
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
238 gc = purple_account_get_connection(acct);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
239 gc->proto_data = msim_session_new(acct);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
240
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
241 /* 1. connect to server */
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
242 purple_connection_update_progress(gc, _("Connecting"),
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
243 0, /* which connection step this is */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
244 4); /* total number of steps */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
245
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
246 host = purple_account_get_string(acct, "server", MSIM_SERVER);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
247 port = purple_account_get_int(acct, "port", MSIM_PORT);
16744
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
248
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
249 /* From purple.sf.net/api:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
250 * """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: 16405
diff changeset
251 * "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: 16405
diff changeset
252 * whether through a proxy or not.""" */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
253
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
254 /* Calls msim_connect_cb when connected. */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
255 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: 16405
diff changeset
256 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
257 /* TODO: try other ports if in auto mode, then save
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
258 * working port and try that first next time. */
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
259 purple_connection_error(gc, _("Couldn't create socket"));
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
260 return;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
261 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
262
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
263 }
16395
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
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
268 * @param msg Login challenge message.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
269 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
270 * @return 0, since the 'msg' parameter is no longer needed.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
271 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
272 int msim_login_challenge(MsimSession *session, MsimMessage *msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
273 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
274 PurpleAccount *account;
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
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: 16746
diff changeset
276 guint response_len;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
277 gchar *nc;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
278 gsize nc_len;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
279
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
280 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
281 g_return_val_if_fail(msg != NULL, 0);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
282
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
283 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), 0);
16395
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;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
286 //assert(account);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
287
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
288 purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
289
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
290 purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
291
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
292 if (nc_len != 0x40)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
293 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
294 purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len);
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
295 purple_connection_error(session->gc, _("Unexpected challenge length from server"));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
296 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
297 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
298
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
299 purple_connection_update_progress(session->gc, _("Logging in"), 2, 4);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
300
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
301 response = msim_compute_login_response(nc, account->username, account->password, &response_len);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
302
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
303 g_free(nc);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
304
16742
2e0bd3e6f2c7 Incomplete attempt at using msim_send() instead of msim_send_raw().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16741
diff changeset
305 msim_send(session,
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
306 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
307 "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: 16746
diff changeset
308 /* 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: 16746
diff changeset
309 "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: 16746
diff changeset
310 "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: 16746
diff changeset
311 "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: 16746
diff changeset
312 "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: 16746
diff changeset
313 "id", MSIM_TYPE_INTEGER, 1,
16742
2e0bd3e6f2c7 Incomplete attempt at using msim_send() instead of msim_send_raw().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16741
diff changeset
314 NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
315
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
316 return 0;
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
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
321
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
322 /*
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
324
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
327
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
329
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
331
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
336
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
341
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
diff changeset
345
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
346
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
348 */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
349
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
352
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
357
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
360 */
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
361
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
364 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
diff changeset
368
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
371
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
373 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
375 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
376
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
378 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
380
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
382
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
diff changeset
386 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
387
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
388 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
389
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
391 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
396
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
402
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
404 {
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
407
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
410
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
diff changeset
414
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
diff changeset
417 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
418
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
diff changeset
422 }
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
423
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
425
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
426
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
427 /**
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
429 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
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: 16405
diff changeset
432 * @param password User's cleartext password.
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
433 * @param response_len Will be written with response length.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
434 *
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
435 * @return Binary login challenge response, ready to send to the server. Must be g_free()'d
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
436 * when finished.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
437 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
438 gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE],
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
439 gchar *email, gchar *password, guint *response_len)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
440 {
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
441 PurpleCipherContext *key_context;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
442 PurpleCipher *sha1;
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
443 #ifdef MSIM_USE_PURPLE_RC4
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
444 PurpleCipherContext *rc4;
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
445 #else
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
447 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
448
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
449 guchar hash_pw[HASH_SIZE];
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
450 guchar key[HASH_SIZE];
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
451 gchar *password_utf16le;
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
452 guchar *data;
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
453 guchar *data_out;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
454 size_t data_len, data_out_len;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
455 gsize conv_bytes_read, conv_bytes_written;
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
456 GError *conv_error;
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
457 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
458 int i;
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
459 #endif
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
460
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
461 /* Convert ASCII password to UTF16 little endian */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
463 conv_error = NULL;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
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: 16405
diff changeset
466 g_assert(conv_bytes_read == strlen(password));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
467 if (conv_error != NULL)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
468 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
469 purple_debug_error("msim",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
470 "g_convert password UTF8->UTF16LE failed: %s",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
471 conv_error->message);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
472 g_error_free(conv_error);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
473 }
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
474
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
475 /* Compute password hash */
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
476 purple_cipher_digest_region("sha1", (guchar *)password_utf16le,
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
478 g_free(password_utf16le);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
479
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
480 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
481 purple_debug_info("msim", "pwhash = ");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
482 for (i = 0; i < sizeof(hash_pw); i++)
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
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: 16407
diff changeset
484 purple_debug_info("msim", "\n");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
485 #endif
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
486
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
487 /* key = sha1(sha1(pw) + nonce2) */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
488 sha1 = purple_ciphers_find_cipher("sha1");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
490 purple_cipher_context_append(key_context, hash_pw, HASH_SIZE);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
491 purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
493
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
494 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
495 purple_debug_info("msim", "key = ");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
496 for (i = 0; i < sizeof(key); i++)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
497 {
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
498 purple_debug_info("msim", "%.2x ", key[i]);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
499 }
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
500 purple_debug_info("msim", "\n");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
501 #endif
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
502
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
503 #ifdef MSIM_USE_PURPLE_RC4
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
504 rc4 = purple_cipher_context_new_by_name("rc4", NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
505
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
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: 16405
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: 16405
diff changeset
509 purple_cipher_context_set_key(rc4, key);
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
510 #endif
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
511
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
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: 16405
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: 16405
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: 16405
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: 16405
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: 16405
diff changeset
518 */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
519 /* rc4 encrypt:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
520 * nonce1+email+IP list */
16745
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16744
diff changeset
521 data_len = NONCE_SIZE + strlen(email)
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16744
diff changeset
522 /* TODO: change to length of IP list */
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16744
diff changeset
523 + 25;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
524 data = g_new0(guchar, data_len);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
525 memcpy(data, nonce, NONCE_SIZE);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
526 memcpy(data + NONCE_SIZE, email, strlen(email));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
527 memcpy(data + NONCE_SIZE + strlen(email),
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
528 /* TODO: IP addresses of network interfaces */
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
530
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
531 #ifdef MSIM_USE_PURPLE_RC4
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
532 data_out = g_new0(guchar, data_len);
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
533
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
534 purple_cipher_context_encrypt(rc4, (const guchar *)data,
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
535 data_len, data_out, &data_out_len);
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
diff changeset
537 #else
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
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: 16734
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: 16734
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: 16734
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: 16734
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: 16734
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: 16734
diff changeset
544 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
545
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
546 g_assert(data_out_len == data_len);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
547
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
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: 16746
diff changeset
549 purple_debug_info("msim", "response=<%s>\n", data_out);
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
550 #endif
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
551
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
552 *response_len = data_out_len;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
553
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
554 return (gchar *)data_out;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
555 }
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
556
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
557 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
559 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
560 * @param gc Connection.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
562 * @param message Instant message text to send.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
563 * @param flags Flags.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
564 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
565 * @return 1 in all cases, even if the message delivery is destined to fail.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
566 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
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: 16405
diff changeset
568 * a username or email address is given, the userid must be looked up.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
569 * This function does that by calling msim_lookup_user(), setting up
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
570 * a msim_send_im_by_userid_cb() callback function called when the userid
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
571 * response is received from the server.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
572 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
573 * The callback function calls msim_send_im_by_userid() to send the actual
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
574 * instant message. If a userid is specified directly, this function is called
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
575 * immediately here.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
576 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
577 int msim_send_im(PurpleConnection *gc, const char *who,
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
578 const char *message, PurpleMessageFlags flags)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
579 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
580 MsimSession *session;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
581 const char *from_username = gc->account->username;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
582 send_im_cb_struct *cbinfo;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
583
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
584 g_return_val_if_fail(gc != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
585 g_return_val_if_fail(who != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
586 g_return_val_if_fail(message != NULL, 0);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
587
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
588 purple_debug_info("msim", "sending message from %s to %s: %s\n",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
589 from_username, who, message);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
590
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
591 session = gc->proto_data;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
592
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
593 /* If numeric ID, can send message immediately without userid lookup */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
594 if (msim_is_userid(who))
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
595 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
596 purple_debug_info("msim",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
597 "msim_send_im: numeric 'who' detected, sending asap\n");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
598 msim_send_im_by_userid(session, who, message, flags);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
599 return 1;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
600 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
601
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
602 /* Otherwise, add callback to IM when userid of destination is available */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
603
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
604 /* Setup a callback for when the userid is available */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
605 cbinfo = g_new0(send_im_cb_struct, 1);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
606 cbinfo->who = g_strdup(who);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
607 cbinfo->message = g_strdup(message);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
608 cbinfo->flags = flags;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
609
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
610 /* Send the request to lookup the userid */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
611 msim_lookup_user(session, who, msim_send_im_by_userid_cb, cbinfo);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
612
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
613 /* msim_send_im_by_userid_cb will now be called once userid is looked up */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
614
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
615 /* Return 1 to have Purple show this IM as being sent, 0 to not. I always
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
616 * return 1 even if the message could not be sent, since I don't know if
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
617 * it has failed yet--because the IM is only sent after the userid is
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
618 * retrieved from the server (which happens after this function returns).
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
619 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
620 * 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: 16405
diff changeset
621 * 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: 16405
diff changeset
622 * IM windows when using this plugin:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
623 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
624 * you@example.com: hello
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
625 * some_other_user: what's going on?
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
626 * you@example.com: just coding a prpl
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
627 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
628 * 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: 16405
diff changeset
629 * 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: 16405
diff changeset
630 */
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
631 return 1;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
632 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
633
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
634 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
635 * Immediately send an IM to a user, by their numeric user ID.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
636 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
637 * @param session
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
638 * @param userid ASCII numeric userid.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
639 * @param message Text of message to send.
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
640 * @param flags Purple instant message flags.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
641 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
642 * @return 0
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
643 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
644 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
645 int msim_send_im_by_userid(MsimSession *session, const gchar *userid, const gchar *message, PurpleMessageFlags flags)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
646 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
647 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
648 g_return_val_if_fail(userid != NULL, 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
649 g_return_val_if_fail(msim_is_userid(userid) == TRUE, 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
650 g_return_val_if_fail(message != NULL, 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
651
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
652 msim_send(session,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
653 "bm", MSIM_TYPE_INTEGER, MSIM_BM_INSTANT,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
654 "sesskey", MSIM_TYPE_STRING, g_strdup(session->sesskey),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
655 "t", MSIM_TYPE_STRING, g_strdup(userid),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
656 "cv", 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: 16746
diff changeset
657 "msg", MSIM_TYPE_STRING, g_strdup(message),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
658 NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
659
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
660 /* Not needed since sending messages to yourself is allowed by MSIM! */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
661 /*if (strcmp(from_username, who) == 0)
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
662 serv_got_im(gc, from_username, message, PURPLE_MESSAGE_RECV, time(NULL));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
663 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
664
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
665 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
666 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
667
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
668
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
669 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
670 * Callback called when ready to send an IM by userid (the userid has been looked up).
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
671 * Calls msim_send_im_by_userid.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
672 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
673 * @param session
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
674 * @param userinfo User info message from server containing a 'body' field
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
675 * with a 'UserID' key. This is where the user ID is taken from.
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
676 * Will be destroyed after use.
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
677 * @param data A send_im_cb_struct * of information on the IM to send.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
678 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
679 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
680 void msim_send_im_by_userid_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
681 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
682 send_im_cb_struct *s;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
683 gchar *userid;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
684 GHashTable *body;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
685 gchar *body_str;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
686
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
687 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
688 g_return_if_fail(userinfo != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
689
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
690 body_str = msim_msg_get_string(userinfo, "body");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
691 body = msim_parse_body(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
692 g_free(body_str);
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
693 g_return_if_fail(body != NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
694
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
695 userid = g_hash_table_lookup(body, "UserID");
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
696
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
697 s = (send_im_cb_struct *)data;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
698 msim_send_im_by_userid(session, userid, s->message, s->flags);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
699
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
700 g_hash_table_destroy(body);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
701 /* g_hash_table_destroy(userinfo); */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
702 /* TODO: do we need to free userinfo here? */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
703 msim_msg_free(userinfo);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
704 g_free(s->message);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
705 g_free(s->who);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
706 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
707
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
708 /**
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
709 * Callback to handle incoming messages, after resolving userid.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
710 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
711 * @param session
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
712 * @param userinfo Message from server on user's info, containing UserName.
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
713 * @param data A gchar * of the incoming instant message's text.
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
714 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
715 void msim_incoming_im_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
716 {
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
717 gchar *msg, *username, *body_str;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
718 GHashTable *body;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
719
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
720 g_return_if_fail(MSIM_SESSION_VALID(session));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
721 g_return_if_fail(userinfo != NULL);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
722
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
723 body_str = msim_msg_get_string(userinfo, "body");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
724 body = msim_parse_body(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
725 g_free(body);
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
726 g_return_if_fail(body != NULL);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
727
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
728 username = g_hash_table_lookup(body, "UserName");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
729
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
730 msg = (gchar *)data;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
731 serv_got_im(session->gc, username, msg, PURPLE_MESSAGE_RECV, time(NULL));
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
732
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
733 msim_msg_free(userinfo); /* TODO: Should we? */
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
734 g_hash_table_destroy(body);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
735 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
736
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
737 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
738 * Handle an incoming message.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
739 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
740 * @param session The session
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
741 * @param msg Message from the server, containing 'f' (userid from) and 'msg'.
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
742 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
743 * @return 0, since msg can be freed.
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
744 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
745 int msim_incoming_im(MsimSession *session, MsimMessage *msg)
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
746 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
747 gchar *userid;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
748 gchar *msg_text;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
749
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
750 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
751 g_return_val_if_fail(msg != NULL, 0);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
752
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
753 /* TODO: where freed? */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
754 userid = msim_msg_get_string(msg, "f");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
755 msg_text = msim_msg_get_string(msg, "msg");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
756
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
757 purple_debug_info("msim",
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
758 "msim_incoming_im: got msg <%s> from <%s>, resolving username\n",
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
759 msg_text, userid);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
760
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
761 msim_lookup_user(session, userid, msim_incoming_im_cb, msg_text);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
762
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
763 return 0;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
764 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
765
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
766
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
767 /**
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
768 * Process a message.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
769 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
770 * @param gc Connection.
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
771 * @param msg Any message from the server.
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
772 *
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
773 * @return The return value of the function used to process the message, or -1 if
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
774 * called with invalid parameters.
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
775 */
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
776 int msim_process(PurpleConnection *gc, MsimMessage *msg)
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
777 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
778 MsimSession *session;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
779
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
780 g_return_val_if_fail(gc != NULL, -1);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
781 g_return_val_if_fail(msg != NULL, -1);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
782
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
783 session = (MsimSession *)gc->proto_data;
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
784
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
785 #ifdef MSIM_DEBUG_MSG
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
786 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
787 gchar *debug_msg;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
788
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
789 purple_debug_info("msim", "-------- message -------------\n");
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
790
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
791 debug_msg = msim_msg_debug_string(msg);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
792 purple_debug_info("msim", debug_msg);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
793 g_free(debug_msg);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
794
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
795 purple_debug_info("msim", "------------------------------\n");
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
796 }
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
797 #endif
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
798
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
799 if (msim_msg_get(msg, "nc"))
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
800 {
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
801 return msim_login_challenge(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
802 } else if (msim_msg_get(msg, "sesskey")) {
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
803
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
804 purple_connection_update_progress(gc, _("Connected"), 3, 4);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
805
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
806 /* Freed in msim_session_destroy */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
807 session->sesskey = msim_msg_get_string(msg, "sesskey");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
808 purple_debug_info("msim", "SESSKEY=<%s>\n", session->sesskey);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
809
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
810 /* Comes with: proof,profileid,userid,uniquenick -- all same values
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
811 * (at least for me). */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
812 /* Freed in msim_session_destroy */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
813 session->userid = msim_msg_get_string(msg, "userid");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
814
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
815 purple_connection_set_state(gc, PURPLE_CONNECTED);
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
816
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
817 return 0;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
818 } else if (msim_msg_get(msg, "bm")) {
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
819 guint bm;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
820
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
821 bm = msim_msg_get_integer(msg, "bm");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
822 switch (bm)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
823 {
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
824 case MSIM_BM_STATUS:
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
825 return msim_status(session, msg);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
826 case MSIM_BM_INSTANT:
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
827 return msim_incoming_im(session, msg);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
828 default:
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
829 /* Not really an IM, but show it for informational
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
830 * purposes during development. */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
831 return msim_incoming_im(session, msg);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
832 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
833
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
834 if (bm == MSIM_BM_STATUS)
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
835 {
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
836 return msim_status(session, msg);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
837 } else { /* else if strcmp(bm, "1") == 0) */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
838 return msim_incoming_im(session, msg);
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
839 }
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
840 } else if (msim_msg_get(msg, "rid")) {
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
841 return msim_process_reply(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
842 } else if (msim_msg_get(msg, "error")) {
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
843 return msim_error(session, msg);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
844 } else if (msim_msg_get(msg, "ka")) {
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
845 purple_debug_info("msim", "msim_process: got keep alive\n");
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
846 return 0;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
847 } else {
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
848 /* 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: 16407
diff changeset
849 * 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: 16407
diff changeset
850 * by Alexandr Shutko, who maintains OSCAR protocol documentation). */
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
851 purple_debug_info("msim", "msim_process: unhandled message\n");
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
852 return 0;
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
853 }
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
854 }
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
855
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
856 /**
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
857 * Process a message reply from the server.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
858 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
859 * @param session
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
860 * @param msg Message reply from server.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
861 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
862 * @return 0, since the 'msg' field is no longer needed.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
863 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
864 int msim_process_reply(MsimSession *session, MsimMessage *msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
865 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
866 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
867 g_return_val_if_fail(msg != NULL, 0);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
868
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
869 if (msim_msg_get(msg, "rid")) /* msim_lookup_user sets callback for here */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
870 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
871 MSIM_USER_LOOKUP_CB cb;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
872 gpointer data;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
873 guint rid;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
874 GHashTable *body;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
875 gchar *username, *body_str;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
876
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
877 rid = msim_msg_get_integer(msg, "rid");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
878
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
879 /* Cache the user info. Currently, the GHashTable of user info in
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
880 * 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
881 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
882 * Some information never changes (username->userid map), some does.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
883 * TODO: Cache what doesn't change only
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
884 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
885 body_str = msim_msg_get_string(msg, "body");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
886 body = msim_parse_body(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
887 g_free(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
888
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
889 /* TODO: implement a better hash-like interface, and use it. */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
890 username = g_hash_table_lookup(body, "UserName");
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
891 if (username)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
892 {
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
893 /* TODO: permanently associated with blist item, if in buddy in blist */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
894 g_hash_table_insert(session->user_lookup_cache, g_strdup(username), body);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
895 } else {
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
896 purple_debug_info("msim",
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
897 "msim_process_reply: not caching body, no UserName\n");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
898 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
899
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
900 /* If a callback is registered for this userid lookup, call it. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
901 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
902 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
903
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
904 if (cb)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
905 {
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
906 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
907 "msim_process_body: calling callback now\n");
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
908 cb(session, msg, data);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
909 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
910 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
911
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
912 /* Return 1 to tell caller of msim_process (msim_input_cb) to
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
913 * not destroy 'msg'; allow 'cb' to hang on to it and destroy
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
914 * it when it wants. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
915 return 1;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
916 } else {
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
917 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
918 "msim_process_body: no callback for rid %d\n", rid);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
919 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
920 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
921 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
922 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
923
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
924 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
925 * Handle an error from the server.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
926 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
927 * @param session
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
928 * @param msg The message.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
929 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
930 * @return 0, since 'msg' can be freed.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
931 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
932 int msim_error(MsimSession *session, MsimMessage *msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
933 {
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
934 gchar *errmsg, *full_errmsg;
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
935 guint err;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
936
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
937 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
938 g_return_val_if_fail(msg != NULL, 0);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
939
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
940 err = msim_msg_get_integer(msg, "err");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
941 errmsg = msim_msg_get_string(msg, "errmsg");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
942
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
943 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: 17323
diff changeset
944
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
945 g_free(errmsg);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
946
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
947 purple_debug_info("msim", "msim_error: %s\n", full_errmsg);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
948
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
949 /* TODO: check 'fatal' and die if asked to.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
950 * TODO: do something with the error # (localization of errmsg?) */
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
951 purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")),
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
952 full_errmsg, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
953
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
954 if (msim_msg_get(msg, "fatal"))
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
955 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
956 purple_debug_info("msim", "fatal error, destroy session\n");
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
957 purple_connection_error(session->gc, full_errmsg);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
958 close(session->fd);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
959 //msim_session_destroy(session);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
960 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
961
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
962 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
963 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
964
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
965 #if 0
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
966 /* Not sure about this */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
967 void msim_status_now(gchar *who, gpointer data)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
968 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
969 printf("msim_status_now: %s\n", who);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
970 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
971 #endif
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
972
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
973 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
974 * Callback to update incoming status messages, after looked up username.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
975 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
976 * @param session
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
977 * @param userinfo Looked up user information from server.
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
978 * @param data gchar * status string, will be freed.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
979 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
980 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
981 void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
982 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
983 PurpleBuddyList *blist;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
984 PurpleBuddy *buddy;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
985 PurplePresence *presence;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
986 GHashTable *body;
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
987 gchar *body_str;
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
988 //PurpleStatus *status;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
989 gchar **status_array;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
990 GList *list;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
991 gchar *status_text, *status_code;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
992 gchar *status_str;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
993 gint i;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
994 gchar *username;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
995
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
996 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
997 g_return_if_fail(userinfo != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
998
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
999 status_str = (gchar *)data;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1000
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1001 body_str = msim_msg_get_string(userinfo, "body");
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1002 body = msim_parse_body(body_str);
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1003 g_free(body_str);
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1004 g_return_if_fail(body != NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1005
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1006 username = g_hash_table_lookup(body, "UserName");
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1007 /* 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
1008 * the buddy list, if the UserID was stored along with it. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1009
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1010 if (!username)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1011 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1012 purple_debug_info("msim", "msim_status_cb: no username?!\n");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1013 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1014 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1015
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1016 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1017 "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: 16403
diff changeset
1018 username, status_str);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1019
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1020 /* TODO: generic functions to split into a GList */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1021 status_array = g_strsplit(status_str, "|", 0);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1022 for (list = NULL, i = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1023 status_array[i];
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1024 i++)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1025 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1026 list = g_list_append(list, status_array[i]);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1027 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1028
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1029 /* Example fields: |s|0|ss|Offline */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1030 status_code = g_list_nth_data(list, 2);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1031 status_text = g_list_nth_data(list, 4);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1032
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1033 blist = purple_get_blist();
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1034
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1035 /* Add buddy if not found */
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1036 buddy = purple_find_buddy(session->account, username);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1037 if (!buddy)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1038 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1039 /* TODO: purple aliases, userids and usernames */
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1040 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1041 "msim_status: making new buddy for %s\n", username);
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1042 buddy = purple_buddy_new(session->account, username, NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1043
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1044 /* TODO: sometimes (when click on it), buddy list disappears. Fix. */
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1045 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1046 } else {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1047 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1048 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1049
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1050 /* For now, always set status to online.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1051 * TODO: make status reflect reality
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1052 * TODO: show headline */
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1053 presence = purple_presence_new_for_buddy(buddy);
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1054 /* purple_presence_set_status_active(presence, PURPLE_STATUS_AVAILABLE, TRUE); */
16395
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 g_strfreev(status_array);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1057 g_list_free(list);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1058 g_hash_table_destroy(body);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1059 msim_msg_free(userinfo); /* TODO: right? */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1060 /* Do not free status_str - it will currently be freed by g_hash_table_destroy
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1061 * on session->user_lookup_cb_data. But this is questionable (TODO: unask) since
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1062 * sometimes user_lookup_cb_data stores integers in gpointers, and sometimes
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1063 * real gpointers that need to be freed, like our status_str.
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1064 */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1065 /* g_free(status_str); */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1066 }
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 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1069 * Process incoming status messages.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1070 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1071 * @param session
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1072 * @param msg Status update message.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1073 *
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1074 * @return 0, since 'msg' can be freed.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1075 */
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1076 int msim_status(MsimSession *session, MsimMessage *msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1077 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1078 gchar *status_str;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1079 gchar *userid;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1080
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1081 g_return_val_if_fail(MSIM_SESSION_VALID(session), 0);
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1082 g_return_val_if_fail(msg != NULL, 0);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1083
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1084 /* TODO: free */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1085 status_str = msim_msg_get_string(msg, "msg");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1086 if (!status_str)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1087 {
16745
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16744
diff changeset
1088 purple_debug_info("msim", "msim_status: bm is status but no status msg\n");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1089 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1090 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1091
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1092 /* TODO: free */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1093 userid = msim_msg_get_string(msg, "f");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1094 if (!userid)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1095 {
16745
3f53f8f502b2 Replacement magic numbers by symbolic constants.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16744
diff changeset
1096 purple_debug_info("msim", "msim_status: bm is status but no f field\n");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1097 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1098 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1099
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1100 /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1101 * before updating the status! Much more efficient. */
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1102 purple_debug_info("msim",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1103 "msim_status: got status msg <%s> for <%s>, scheduling lookup\n",
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1104 status_str, userid);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1105
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1106 /* Actually update status, once username is obtained.
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1107 * status_str() will currently be freed by g_hash_table_destroy() on
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1108 * user_lookup_cb_data (TODO: this is questionable, since it can also
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1109 * store gpointers. Fix this, and the 2 other TODOs of the same problem.)
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1110 */
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1111 msim_lookup_user(session, userid, msim_status_cb, status_str);
16395
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 return 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1114 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1115
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1116
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1117
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1118 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1119 * Callback when input available.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1120 *
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1121 * @param gc_uncasted A PurpleConnection pointer.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1122 * @param source File descriptor.
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1123 * @param cond PURPLE_INPUT_READ
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1124 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1125 * Reads the input, and dispatches calls msim_process to handle it.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1126 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1127 void msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1128 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1129 PurpleConnection *gc;
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1130 PurpleAccount *account;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1131 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1132 gchar *end;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1133 int n;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1134
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1135 g_return_if_fail(gc_uncasted != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1136 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
1137
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
1138 gc = (PurpleConnection *)(gc_uncasted);
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1139 account = purple_connection_get_account(gc);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1140 session = gc->proto_data;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1141
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1142 g_return_if_fail(cond == PURPLE_INPUT_READ);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1143 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1144
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1145 /* Only can handle so much data at once...
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1146 * 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
1147 * Should be large enough to hold the largest protocol message.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1148 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1149 if (session->rxoff == MSIM_READ_BUF_SIZE)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1150 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1151 purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n",
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1152 MSIM_READ_BUF_SIZE);
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1153 purple_connection_error(gc, _("Read buffer full"));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1154 /* TODO: fix 100% CPU after closing */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1155 close(source);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1156 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1157 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1158
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1159 purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n",
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1160 session->rxoff, MSIM_READ_BUF_SIZE,
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1161 MSIM_READ_BUF_SIZE - session->rxoff);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1162
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1163 /* 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
1164 * the file descriptor, but it sometimes differs from the 'source' parameter.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1165 */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1166 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
1167
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1168 if (n < 0 && errno == EAGAIN)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1169 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1170 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1171 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1172 else if (n < 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1173 {
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1174 purple_connection_error(gc, _("Read error"));
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1175 purple_debug_error("msim", "msim_input_cb: read error, ret=%d, "
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1176 "error=%s, source=%d, fd=%d (%X))\n",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1177 n, strerror(errno), source, session->fd, session->fd);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1178 close(source);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1179 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1180 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1181 else if (n == 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1182 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1183 purple_debug_info("msim", "msim_input_cb: server disconnected\n");
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1184 purple_connection_error(gc, _("Server has disconnected"));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1185 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1186 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1187
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1188 /* Null terminate */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1189 session->rxbuf[session->rxoff + n] = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1190
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1191 /* 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
1192 if (strlen(session->rxbuf + session->rxoff) != n)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1193 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1194 /* Occurs after login, but it is not a null byte. */
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1195 purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes"
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1196 "--null byte encountered?\n",
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1197 strlen(session->rxbuf + session->rxoff), n);
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1198 //purple_connection_error(gc, "Invalid message - null byte on input");
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1199 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1200 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1201
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1202 session->rxoff += n;
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1203 purple_debug_info("msim", "msim_input_cb: read=%d\n", n);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1204
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
1205 #ifdef MSIM_DEBUG_RXBUF
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1206 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: 16407
diff changeset
1207 #endif
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1208
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1209 /* Look for \\final\\ end markers. If found, process message. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1210 while((end = strstr(session->rxbuf, MSIM_FINAL_STRING)))
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1211 {
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1212 MsimMessage *msg;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1213
16736
58cd11fcd84f Re-add RC4 code from Samba, whose use is enabled by not defining
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16734
diff changeset
1214 #ifdef MSIM_DEBUG_RXBUF
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1215 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: 16407
diff changeset
1216 #endif
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1217 *end = 0;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1218 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: 16749
diff changeset
1219 if (!msg)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1220 {
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1221 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: 16403
diff changeset
1222 session->rxbuf);
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1223 purple_connection_error(gc, _("Unparseable message"));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1224 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1225 else
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1226 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1227 /* Process message. Returns 0 to free */
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1228 if (msim_process(gc, msg) == 0)
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1229 msim_msg_free(msg);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1230 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1231
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1232 /* Move remaining part of buffer to beginning. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1233 session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1234 memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING),
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1235 MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1236
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1237 /* Clear end of buffer */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1238 //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1239 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1240 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1241
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1242 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1243 * Callback when connected. Sets up input handlers.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1244 *
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1245 * @param data A PurpleConnection pointer.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1246 * @param source File descriptor.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1247 * @param error_message
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1248 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1249 void msim_connect_cb(gpointer data, gint source, const gchar *error_message)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1250 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1251 PurpleConnection *gc;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1252 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1253
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1254 g_return_if_fail(data != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1255
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
1256 gc = (PurpleConnection *)data;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1257 session = gc->proto_data;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1258
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1259 if (source < 0)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1260 {
16739
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1261 purple_connection_error(gc, _("Couldn't connect to host"));
8f6dcd5e9298 Use _ for translations in msimprpl. See #648.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16738
diff changeset
1262 purple_connection_error(gc, g_strdup_printf(_("Couldn't connect to host: %s (%d)"),
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1263 error_message, source));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1264 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1265 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1266
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1267 session->fd = source;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1268
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1269 gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1270 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1271
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1272 /* Session methods */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1273
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1274 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1275 * Create a new MSIM session.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1276 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1277 * @param acct The account to create the session from.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1278 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1279 * @return Pointer to a new session. Free with msim_session_destroy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1280 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1281 MsimSession *msim_session_new(PurpleAccount *acct)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1282 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1283 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1284
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1285 g_return_val_if_fail(acct != NULL, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1286
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1287 session = g_new0(MsimSession, 1);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1288
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1289 session->magic = MSIM_SESSION_STRUCT_MAGIC;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1290 session->account = acct;
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1291 session->gc = purple_account_get_connection(acct);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1292 session->fd = -1;
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1293 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1294 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1295 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
17337
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1296 g_direct_equal, NULL, g_free);/* TODO: we don't know what the values are,
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1297 they could be integers inside gpointers
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1298 or strings, but we free them anyway.
d3e17c9d16e9 Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 17323
diff changeset
1299 Figure this out, once free cache. */
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1300 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: 16407
diff changeset
1301 g_free, (GDestroyNotify)g_hash_table_destroy);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1302 session->rxoff = 0;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1303 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE);
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1304 session->next_rid = 1;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1305
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1306 return session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1307 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1308
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1309 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1310 * Free a session.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1311 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1312 * @param session The session to destroy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1313 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1314 void msim_session_destroy(MsimSession *session)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1315 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1316 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1317
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1318 session->magic = -1;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1319
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1320 g_free(session->rxbuf);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1321 g_free(session->userid);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1322 g_free(session->sesskey);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1323
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1324 g_free(session);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1325 }
16406
8063f163f411 Add MySpaceIM header file and reorganize functions.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16405
diff changeset
1326
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1327
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1328
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1329 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1330 * Close the connection.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1331 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1332 * @param gc The connection.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1333 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1334 void msim_close(PurpleConnection *gc)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1335 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1336 g_return_if_fail(gc != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1337
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1338 msim_session_destroy(gc->proto_data);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1339 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1340
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1341
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1342 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1343 * Check if a string is a userid (all numeric).
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1344 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1345 * @param user The user id, email, or name.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1346 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1347 * @return TRUE if is userid, FALSE if not.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1348 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1349 gboolean msim_is_userid(const gchar *user)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1350 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1351 g_return_val_if_fail(user != NULL, FALSE);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1352
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1353 return strspn(user, "0123456789") == strlen(user);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1354 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1355
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1356 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1357 * Check if a string is an email address (contains an @).
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1358 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1359 * @param user The user id, email, or name.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1360 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1361 * @return TRUE if is an email, FALSE if not.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1362 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1363 * This function is not intended to be used as a generic
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1364 * means of validating email addresses, but to distinguish
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1365 * between a user represented by an email address from
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1366 * other forms of identification.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1367 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1368 gboolean msim_is_email(const gchar *user)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1369 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1370 g_return_val_if_fail(user != NULL, FALSE);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1371
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1372 return strchr(user, '@') != NULL;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1373 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1374
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1375
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1376 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1377 * Asynchronously lookup user information, calling callback when receive result.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1378 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1379 * @param session
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1380 * @param user The user id, email address, or username.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1381 * @param cb Callback, called with user information when available.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1382 * @param data An arbitray data pointer passed to the callback.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1383 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1384 void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1385 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1386 gchar *field_name;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1387 guint rid, cmd, dsn, lid;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1388
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1389 g_return_if_fail(MSIM_SESSION_VALID(session));
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1390 g_return_if_fail(user != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1391 g_return_if_fail(cb != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1392
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1393 purple_debug_info("msim", "msim_lookup_userid: "
16405
47e07438f01c Use g_convert for UTF-16LE conversion instead of converting manually.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16403
diff changeset
1394 "asynchronously looking up <%s>\n", user);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1396 /* 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
1397 #if 0
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1398 /* If already know userid, then call callback immediately */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1399 cached_userid = g_hash_table_lookup(session->userid_cache, who);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1400 if (cached_userid && !by_userid)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1401 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1402 cb(cached_userid, NULL, NULL, data);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1403 return;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1404 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1405 #endif
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1406
16408
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1407 rid = session->next_rid;
bb649c52fc19 Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16407
diff changeset
1408 ++session->next_rid;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1409
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1410 /* Setup callback. Response will be associated with request using 'rid'. */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1411 g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1412 g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1413
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1414 /* Send request */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1415
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1416 cmd = 1;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1417
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1418 if (msim_is_userid(user))
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1419 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1420 /* TODO: document cmd,dsn,lid */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1421 field_name = "UserID";
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1422 dsn = 4;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1423 lid = 3;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1424 } else if (msim_is_email(user)) {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1425 field_name = "Email";
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1426 dsn = 5;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1427 lid = 7;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1428 } else {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1429 field_name = "UserName";
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1430 dsn = 5;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1431 lid = 7;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1432 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1433
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1434
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1435 msim_send(session,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1436 "persist", 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: 16746
diff changeset
1437 "sesskey", MSIM_TYPE_STRING, g_strdup(session->sesskey),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1438 "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: 16746
diff changeset
1439 "dsn", MSIM_TYPE_INTEGER, dsn,
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1440 "uid", MSIM_TYPE_STRING, g_strdup(session->userid),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1441 "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: 16746
diff changeset
1442 "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: 16746
diff changeset
1443 /* 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: 16746
diff changeset
1444 "body", MSIM_TYPE_STRING, g_strdup_printf("%s=%s", field_name, user),
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1445 NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1446 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1447
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1448
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1449 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1450 * Obtain the status text for a buddy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1451 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1452 * @param buddy The buddy to obtain status text for.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1453 *
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1454 * @return Status text, or NULL if error.
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1455 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1456 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1457 char *msim_status_text(PurpleBuddy *buddy)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1458 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1459 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1460 GHashTable *userinfo;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1461 gchar *display_name;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1462
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1463 g_return_val_if_fail(buddy != NULL, NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1464
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
1465 session = (MsimSession *)buddy->account->gc->proto_data;
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1466 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: 16737
diff changeset
1467 g_return_val_if_fail(session->user_lookup_cache != NULL, NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1468
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1469 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1470 if (!userinfo)
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1471 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1472 return g_strdup("");
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1473 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1474
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1475 display_name = g_hash_table_lookup(userinfo, "DisplayName");
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1476 g_return_val_if_fail(display_name != NULL, NULL);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1477
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1478 return g_strdup(display_name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1479 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1480
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1481 /**
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1482 * Obtain the tooltip text for a buddy.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1483 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1484 * @param buddy Buddy to obtain tooltip text on.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1485 * @param user_info Variable modified to have the tooltip text.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1486 * @param full TRUE if should obtain full tooltip text.
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1487 *
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1488 */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1489 void msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full)
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1490 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1491 g_return_if_fail(buddy != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1492 g_return_if_fail(user_info != NULL);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1493
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1494 if (PURPLE_BUDDY_IS_ONLINE(buddy))
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1495 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1496 MsimSession *session;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1497 GHashTable *userinfo;
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1498
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
1499 session = (MsimSession *)buddy->account->gc->proto_data;
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1500
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1501 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: 16737
diff changeset
1502 g_return_if_fail(session->user_lookup_cache);
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1503
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1504 userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name);
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1505
16738
cd4a6bd9f69e Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16737
diff changeset
1506 g_return_if_fail(userinfo != NULL);
16395
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 // TODO: if (full), do something different
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1509 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: 16395
diff changeset
1510 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: 16395
diff changeset
1511 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: 16395
diff changeset
1512 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: 16395
diff changeset
1513 purple_notify_user_info_add_pair(user_info, "Song",
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1514 g_strdup_printf("%s - %s",
16749
0fa4a3e9b318 Stylistic improvements - use type *name instead of type* name for pointers
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16747
diff changeset
1515 (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: 16747
diff changeset
1516 (gchar *)g_hash_table_lookup(userinfo, "SongName")));
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1517 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1518 }
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1519
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1520 /** Callbacks called by Purple, to access this plugin. */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1521 PurplePluginProtocolInfo prpl_info =
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1522 {
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1523 OPT_PROTO_MAIL_CHECK,/* options - TODO: myspace will notify of mail */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1524 NULL, /* user_splits */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1525 NULL, /* protocol_options */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1526 NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1527 msim_list_icon, /* list_icon */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1528 NULL, /* list_emblems */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1529 msim_status_text, /* status_text */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1530 msim_tooltip_text, /* tooltip_text */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1531 msim_status_types, /* status_types */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1532 NULL, /* blist_node_menu */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1533 NULL, /* chat_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1534 NULL, /* chat_info_defaults */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1535 msim_login, /* login */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1536 msim_close, /* close */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1537 msim_send_im, /* send_im */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1538 NULL, /* set_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1539 NULL, /* send_typing */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1540 NULL, /* get_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1541 NULL, /* set_away */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1542 NULL, /* set_idle */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1543 NULL, /* change_passwd */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1544 NULL, /* add_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1545 NULL, /* add_buddies */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1546 NULL, /* remove_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1547 NULL, /* remove_buddies */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1548 NULL, /* add_permit */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1549 NULL, /* add_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1550 NULL, /* rem_permit */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1551 NULL, /* rem_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1552 NULL, /* set_permit_deny */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1553 NULL, /* join_chat */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1554 NULL, /* reject chat invite */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1555 NULL, /* get_chat_name */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1556 NULL, /* chat_invite */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1557 NULL, /* chat_leave */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1558 NULL, /* chat_whisper */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1559 NULL, /* chat_send */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1560 NULL, /* keepalive */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1561 NULL, /* register_user */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1562 NULL, /* get_cb_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1563 NULL, /* get_cb_away */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1564 NULL, /* alias_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1565 NULL, /* group_buddy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1566 NULL, /* rename_group */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1567 NULL, /* buddy_free */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1568 NULL, /* convo_closed */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1569 NULL, /* normalize */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1570 NULL, /* set_buddy_icon */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1571 NULL, /* remove_group */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1572 NULL, /* get_cb_real_name */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1573 NULL, /* set_chat_topic */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1574 NULL, /* find_blist_chat */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1575 NULL, /* roomlist_get_list */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1576 NULL, /* roomlist_cancel */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1577 NULL, /* roomlist_expand_category */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1578 NULL, /* can_receive_file */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1579 NULL, /* send_file */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1580 NULL, /* new_xfer */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1581 NULL, /* offline_message */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1582 NULL, /* whiteboard_prpl_ops */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1583 NULL, /* send_raw */
16734
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1584 NULL, /* roomlist_room_serialize */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1585 NULL, /* _purple_reserved1 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1586 NULL, /* _purple_reserved2 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1587 NULL, /* _purple_reserved3 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1588 NULL /* _purple_reserved4 */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1589 };
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1590
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 /** Based on MSN's plugin info comments. */
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1594 PurplePluginInfo info =
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1595 {
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1596 PURPLE_PLUGIN_MAGIC,
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1597 PURPLE_MAJOR_VERSION,
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1598 PURPLE_MINOR_VERSION,
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1599 PURPLE_PLUGIN_PROTOCOL, /**< type */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1600 NULL, /**< ui_requirement */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1601 0, /**< flags */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1602 NULL, /**< dependencies */
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1603 PURPLE_PRIORITY_DEFAULT, /**< priority */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1604
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1605 "prpl-myspace", /**< id */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1606 "MySpaceIM", /**< name */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1607 "0.4", /**< version */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1608 /** summary */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1609 "MySpaceIM Protocol Plugin",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1610 /** description */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1611 "MySpaceIM Protocol Plugin",
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1612 "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1613 "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1614
16737
fc80e7b2540d Check for RC4 in libpurple on plugin initialization.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16736
diff changeset
1615 msim_load, /**< load */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1616 NULL, /**< unload */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1617 NULL, /**< destroy */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1618 NULL, /**< ui_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1619 &prpl_info, /**< extra_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1620 NULL, /**< prefs_info */
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1621
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1622 /* msim_actions */
16734
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1623 NULL,
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1624
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1625 NULL, /**< reserved1 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1626 NULL, /**< reserved2 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1627 NULL, /**< reserved3 */
3b5037a93807 Add initializers for reserved fields in plugin and prpl structures.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16410
diff changeset
1628 NULL /**< reserved4 */
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1629 };
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1630
16746
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16745
diff changeset
1631 #include "message.h"
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16745
diff changeset
1632
16747
496855295bd7 Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16746
diff changeset
1633 void init_plugin(PurplePlugin *plugin)
16744
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1634 {
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1635 PurpleAccountOption *option;
17323
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1636 #ifdef _TEST_MSIM_MSG
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1637 {
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1638 MsimMessage *msg;
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1639
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1640 purple_debug_info("msim", "testing MsimMessage\n");
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1641 msg = msim_msg_new();
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1642 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: 16749
diff changeset
1643 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: 16749
diff changeset
1644 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: 16749
diff changeset
1645 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: 16749
diff changeset
1646 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: 16749
diff changeset
1647 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7"));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1648 purple_debug_info("msim", "msg=%s\n", msim_msg_debug_string(msg));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1649 purple_debug_info("msim", "msg=%s\n", msim_msg_pack(msg));
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1650 msim_msg_free(msg);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1651 exit(0);
793301c04e3a (Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16749
diff changeset
1652 }
16746
52357f6392a4 Add partial implementation of MsimMessage (not used anywhere yet).
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16745
diff changeset
1653 #endif
16744
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1654
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1655 /* TODO: default to automatically try different ports. Make the user be
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1656 * 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: 16742
diff changeset
1657 option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1658 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: 16742
diff changeset
1659
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1660 option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT);
a8e8482a2dc6 Clean up a few TODO's.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16742
diff changeset
1661 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: 16742
diff changeset
1662 }
16395
05e2df434077 Import msimprpl 0.4.
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
diff changeset
1663
16397
70c069168459 Gaim -> Purple
Jeffrey Connelly <jaconnel@calpoly.edu>
parents: 16395
diff changeset
1664 PURPLE_INIT_PLUGIN(myspace, init_plugin, info);