Wed, 09 May 2007 04:43:24 +0000
Check for RC4 in libpurple on plugin initialization.
| 16322 | 1 | /* MySpaceIM Protocol Plugin |
| 2 | * | |
| 3 | * \author Jeff Connelly | |
| 4 | * | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
5 | * Copyright (C) 2007, Jeff Connelly <jeff2@homing.pidgin.im> |
| 16322 | 6 | * |
| 16324 | 7 | * Based on Purple's "C Plugin HOWTO" hello world example. |
| 16322 | 8 | * |
| 9 | * Code also drawn from myspace: | |
| 16324 | 10 | * http://snarfed.org/space/purple+mock+protocol+plugin |
| 16322 | 11 | * Copyright (C) 2004-2007, Ryan Barrett <mockprpl@ryanb.org> |
| 12 | * | |
| 16324 | 13 | * and some constructs also based on existing Purple plugins, which are: |
| 14 | * Copyright (C) 2003, Robbert Haarman <purple@inglorion.net> | |
| 16322 | 15 | * Copyright (C) 2003, Ethan Blanton <eblanton@cs.purdue.edu> |
| 16 | * Copyright (C) 2000-2003, Rob Flynn <rob@tgflinux.com> | |
| 17 | * Copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
| 18 | * | |
| 19 | * This program is free software; you can redistribute it and/or modify | |
| 20 | * it under the terms of the GNU General Public License as published by | |
| 21 | * the Free Software Foundation; either version 2 of the License, or | |
| 22 | * (at your option) any later version. | |
| 23 | * | |
| 24 | * This program is distributed in the hope that it will be useful, | |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 27 | * GNU General Public License for more details. | |
| 28 | * | |
| 29 | * You should have received a copy of the GNU General Public License | |
| 30 | * along with this program; if not, write to the Free Software | |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 32 | */ | |
| 33 | ||
| 16324 | 34 | #define PURPLE_PLUGIN |
| 16322 | 35 | |
| 36 | #include <string.h> | |
| 37 | #include <errno.h> /* for EAGAIN */ | |
| 38 | ||
| 39 | #include <glib.h> | |
| 40 | ||
| 41 | #ifdef _WIN32 | |
| 42 | #include "win32dep.h" | |
| 43 | #else | |
| 44 | /* For recv() and send(); needed to match Win32 */ | |
| 45 | #include <sys/types.h> | |
| 46 | #include <sys/socket.h> | |
| 47 | #endif | |
| 48 | ||
| 16324 | 49 | #include "internal.h" |
| 50 | ||
| 16322 | 51 | #include "notify.h" |
| 52 | #include "plugin.h" | |
| 53 | #include "version.h" | |
| 54 | #include "cipher.h" /* for SHA-1 */ | |
| 55 | #include "util.h" /* for base64 */ | |
| 16324 | 56 | #include "debug.h" /* for purple_debug_info */ |
| 57 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
58 | #include "myspace.h" |
| 16322 | 59 | |
| 16324 | 60 | static void init_plugin(PurplePlugin *plugin) |
| 16322 | 61 | { |
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
62 | } |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
63 | |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
64 | /** |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
65 | * Load the plugin. |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
66 | */ |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
67 | static gboolean msim_load(PurplePlugin *plugin) |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
68 | { |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
69 | #ifdef MSIM_USE_PURPLE_RC4 |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
70 | /* If compiled to use RC4 from libpurple, check if it is really there. */ |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
71 | if (!purple_ciphers_find_cipher("rc4")) |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
72 | { |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
73 | purple_debug_error("msim", "compiled with MSIM_USE_PURPLE_RC4 but rc4 not in libpurple - not loading MySpaceIM plugin!\n"); |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
74 | purple_notify_error(plugin, "Missing Cipher", "The RC4 cipher could not be found", |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
75 | "Recompile without MSIM_USE_PURPLE_RC4, or upgrade to a libpurple with RC4 support. MySpaceIM plugin will not be loaded."); |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
76 | return FALSE; |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
77 | } |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
78 | #endif |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
79 | return TRUE; |
| 16322 | 80 | } |
| 81 | ||
| 82 | /** | |
| 83 | * Get possible user status types. Based on mockprpl. | |
| 84 | * | |
| 85 | * @return GList of status types. | |
| 86 | */ | |
| 16324 | 87 | static GList *msim_status_types(PurpleAccount *acct) |
| 16322 | 88 | { |
| 89 | GList *types; | |
| 16324 | 90 | PurpleStatusType *type; |
| 16322 | 91 | |
| 16324 | 92 | purple_debug_info("myspace", "returning status types for %s: %s, %s, %s\n", |
| 16322 | 93 | acct->username, |
| 94 | MSIM_STATUS_ONLINE, MSIM_STATUS_AWAY, MSIM_STATUS_OFFLINE, MSIM_STATUS_INVISIBLE); | |
| 95 | ||
| 96 | ||
| 97 | types = NULL; | |
| 98 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
99 | /* TODO: Clean up - I don't like all this repetition */ |
| 16324 | 100 | type = purple_status_type_new(PURPLE_STATUS_AVAILABLE, MSIM_STATUS_ONLINE, |
| 16322 | 101 | MSIM_STATUS_ONLINE, TRUE); |
| 16324 | 102 | purple_status_type_add_attr(type, "message", "Online", |
| 103 | purple_value_new(PURPLE_TYPE_STRING)); | |
| 16322 | 104 | types = g_list_append(types, type); |
| 105 | ||
| 16324 | 106 | type = purple_status_type_new(PURPLE_STATUS_AWAY, MSIM_STATUS_AWAY, |
| 16322 | 107 | MSIM_STATUS_AWAY, TRUE); |
| 16324 | 108 | purple_status_type_add_attr(type, "message", "Away", |
| 109 | purple_value_new(PURPLE_TYPE_STRING)); | |
| 16322 | 110 | types = g_list_append(types, type); |
| 111 | ||
| 16324 | 112 | type = purple_status_type_new(PURPLE_STATUS_OFFLINE, MSIM_STATUS_OFFLINE, |
| 16322 | 113 | MSIM_STATUS_OFFLINE, TRUE); |
| 16324 | 114 | purple_status_type_add_attr(type, "message", "Offline", |
| 115 | purple_value_new(PURPLE_TYPE_STRING)); | |
| 16322 | 116 | types = g_list_append(types, type); |
| 117 | ||
| 16324 | 118 | type = purple_status_type_new(PURPLE_STATUS_INVISIBLE, MSIM_STATUS_INVISIBLE, |
| 16322 | 119 | MSIM_STATUS_INVISIBLE, TRUE); |
| 16324 | 120 | purple_status_type_add_attr(type, "message", "Invisible", |
| 121 | purple_value_new(PURPLE_TYPE_STRING)); | |
| 16322 | 122 | types = g_list_append(types, type); |
| 123 | ||
| 124 | return types; | |
| 125 | } | |
| 126 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
127 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
128 | * Return the icon name for a buddy and account. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
129 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
130 | * @param acct The account to find the icon for, or NULL for protocol icon. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
131 | * @param buddy The buddy to find the icon for, or NULL for the account icon. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
132 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
133 | * @return The base icon name string. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
134 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
135 | static const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
136 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
137 | /* TODO: use a MySpace icon. hbons submitted one to |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
138 | * http://developer.pidgin.im/wiki/MySpaceIM - tried placing in |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
139 | * C:\cygwin\home\Jeff\purple-2.0.0beta6\gtk\pixmaps\status\default |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
140 | * and returning "myspace" but icon shows up blank. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
141 | */ |
|
16334
ff6947265141
Add and use MySpaceIM icon uploaded by hbons (48x48 original and resized 22x22 and 16x16 versions).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16333
diff
changeset
|
142 | return "myspace"; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
143 | } |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
144 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
145 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
146 | * Unescape a protocol message. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
147 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
148 | * @param msg The message to unescape. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
149 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
150 | * @return The unescaped message. Caller must g_free(). |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
151 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
152 | * Messages should be unescaped after being received, as part of |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
153 | * the parsing process. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
154 | */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
155 | static gchar *msim_unescape(const gchar *msg) |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
156 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
157 | /* TODO: make more elegant, refactor with msim_escape */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
158 | gchar *tmp, *ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
159 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
160 | tmp = str_replace(msg, "/1", "/"); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
161 | ret = str_replace(tmp, "/2", "\\"); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
162 | g_free(tmp); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
163 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
164 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
165 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
166 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
167 | * Escape a protocol message. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
168 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
169 | * @param msg The message to escape. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
170 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
171 | * @return The escaped message. Caller must g_free(). |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
172 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
173 | * Messages should be escaped before sending. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
174 | */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
175 | static gchar *msim_escape(const gchar *msg) |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
176 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
177 | /* TODO: make more elegant, refactor with msim_unescape */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
178 | gchar *tmp, *ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
179 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
180 | tmp = str_replace(msg, "/", "/1"); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
181 | ret = str_replace(tmp, "\\", "/2"); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
182 | g_free(tmp); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
183 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
184 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
185 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
186 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
187 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
188 | * Replace 'old' with 'new' in 'str'. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
189 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
190 | * @param str The original string. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
191 | * @param old The substring of 'str' to replace. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
192 | * @param new The replacement for 'old' within 'str'. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
193 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
194 | * @return A _new_ string, based on 'str', with 'old' replaced |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
195 | * by 'new'. Must be g_free()'d by caller. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
196 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
197 | * This string replace method is based on |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
198 | * http://mail.gnome.org/archives/gtk-app-devel-list/2000-July/msg00201.html |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
199 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
200 | */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
201 | static gchar *str_replace(const gchar* str, const gchar *old, const gchar *new) |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
202 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
203 | char **items; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
204 | char *ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
205 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
206 | items = g_strsplit(str, old, -1); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
207 | ret = g_strjoinv(new, items); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
208 | g_free(items); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
209 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
210 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
211 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
212 | |
| 16322 | 213 | /** |
| 214 | * Parse a MySpaceIM protocol message into a hash table. | |
| 215 | * | |
| 216 | * @param msg The message string to parse, will be g_free()'d. | |
| 217 | * | |
| 218 | * @return Hash table of message. Caller should destroy with | |
| 219 | * g_hash_table_destroy() when done. | |
| 220 | */ | |
| 221 | static GHashTable* msim_parse(gchar* msg) | |
| 222 | { | |
| 223 | GHashTable *table; | |
| 224 | gchar *token; | |
| 225 | gchar **tokens; | |
| 226 | gchar *key; | |
| 227 | gchar *value; | |
| 228 | int i; | |
| 229 | ||
| 230 | g_return_val_if_fail(msg != NULL, NULL); | |
| 231 | ||
| 16324 | 232 | purple_debug_info("msim", "msim_parse: got <%s>\n", msg); |
| 16322 | 233 | |
| 234 | key = NULL; | |
| 235 | ||
| 236 | /* All messages begin with a \ */ | |
| 237 | if (msg[0] != '\\' || msg[1] == 0) | |
| 238 | { | |
| 16324 | 239 | purple_debug_info("msim", "msim_parse: incomplete/bad msg, " |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
240 | "missing initial backslash: <%s>\n", msg); |
| 16322 | 241 | /* XXX: Should we try to recover, and read to first backslash? */ |
| 242 | ||
| 243 | g_free(msg); | |
| 244 | return NULL; | |
| 245 | } | |
| 246 | ||
| 247 | /* Create table of strings, set to call g_free on destroy. */ | |
| 248 | table = g_hash_table_new_full((GHashFunc)g_str_hash, | |
| 249 | (GEqualFunc)g_str_equal, g_free, g_free); | |
| 250 | ||
| 251 | for (tokens = g_strsplit(msg + 1, "\\", 0), i = 0; | |
| 252 | (token = tokens[i]); | |
| 253 | i++) | |
| 254 | { | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
255 | #ifdef MSIM_DEBUG_PARSE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
256 | purple_debug_info("msim", "tok=<%s>, i%2=%d\n", token, i % 2); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
257 | #endif |
| 16322 | 258 | if (i % 2) |
| 259 | { | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
260 | /* Odd-numbered ordinal is a value */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
261 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
262 | /* Note: returns a new string */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
263 | value = msim_unescape(token); |
| 16322 | 264 | |
| 265 | /* Check if key already exists */ | |
| 266 | if (g_hash_table_lookup(table, key) == NULL) | |
| 267 | { | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
268 | #ifdef MSIM_DEBUG_PARSE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
269 | purple_debug_info("msim", "insert: |%s|=|%s|\n", key, value); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
270 | #endif |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
271 | /* Insert - strdup 'key' because it will be g_strfreev'd (as 'tokens'), |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
272 | * but do not strdup 'value' because it was newly allocated by |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
273 | * msim_unescape(). |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
274 | */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
275 | g_hash_table_insert(table, g_strdup(key), value); |
| 16322 | 276 | } else { |
| 277 | /* TODO: Some dictionaries have multiple values for the same | |
| 278 | * key. Should append to a GList to handle this case. */ | |
| 16324 | 279 | purple_debug_info("msim", "msim_parse: key %s already exists, " |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
280 | "not overwriting or replacing; ignoring new value %s\n", key, |
| 16322 | 281 | value); |
| 282 | } | |
| 283 | } else { | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
284 | /* Even numbered index is a key name */ |
| 16322 | 285 | key = token; |
| 286 | } | |
| 287 | } | |
| 288 | g_strfreev(tokens); | |
| 289 | ||
| 290 | /* Can free now since all data was copied to hash key/values */ | |
| 291 | g_free(msg); | |
| 292 | ||
| 293 | return table; | |
| 294 | } | |
| 295 | ||
| 296 | /** | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
297 | * Parse a \x1c-separated "dictionary" of key=value pairs into a hash table. |
| 16322 | 298 | * |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
299 | * @param body_str The text of the dictionary to parse. Often the |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
300 | * value for the 'body' field. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
301 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
302 | * @return Hash table of the keys and values. Must g_hash_table_destroy() when done. |
| 16322 | 303 | */ |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
304 | static GHashTable *msim_parse_body(const gchar *body_str) |
| 16322 | 305 | { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
306 | GHashTable *table; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
307 | gchar *item; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
308 | gchar **items; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
309 | gchar **elements; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
310 | guint i; |
| 16322 | 311 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
312 | g_return_val_if_fail(body_str != NULL, NULL); |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
313 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
314 | table = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
315 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
316 | for (items = g_strsplit(body_str, "\x1c", 0), i = 0; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
317 | (item = items[i]); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
318 | i++) |
| 16322 | 319 | { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
320 | gchar *key, *value; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
321 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
322 | elements = g_strsplit(item, "=", 2); |
| 16322 | 323 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
324 | key = elements[0]; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
325 | if (!key) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
326 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
327 | purple_debug_info("msim", "msim_parse_body(%s): null key\n", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
328 | body_str); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
329 | g_strfreev(elements); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
330 | break; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
331 | } |
| 16322 | 332 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
333 | value = elements[1]; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
334 | if (!value) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
335 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
336 | purple_debug_info("msim", "msim_parse_body(%s): null value\n", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
337 | body_str); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
338 | g_strfreev(elements); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
339 | break; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
340 | } |
| 16322 | 341 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
342 | #ifdef MSIM_DEBUG_PARSE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
343 | purple_debug_info("msim", "-- %s: %s\n", key, value); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
344 | #endif |
| 16322 | 345 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
346 | /* XXX: This overwrites duplicates. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
347 | /* TODO: make the GHashTable values be GList's, and append to the list if |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
348 | * there is already a value of the same key name. This is important for |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
349 | * the WebChallenge message. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
350 | g_hash_table_insert(table, g_strdup(key), g_strdup(value)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
351 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
352 | g_strfreev(elements); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
353 | } |
|
16328
5142c7747d06
Use Purple Cipher API for RC4.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16324
diff
changeset
|
354 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
355 | g_strfreev(items); |
| 16322 | 356 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
357 | return table; |
| 16322 | 358 | } |
| 359 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
360 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
361 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
362 | #ifdef MSIM_DEBUG_MSG |
| 16322 | 363 | static void print_hash_item(gpointer key, gpointer value, gpointer user_data) |
| 364 | { | |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
365 | purple_debug_info("msim", "%s=%s\n", (char*)key, (char*)value); |
| 16322 | 366 | } |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
367 | #endif |
| 16322 | 368 | |
| 369 | /** | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
370 | * Send raw data to the server. |
| 16322 | 371 | * |
| 372 | * @param session | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
373 | * @param msg The raw data to send. |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
374 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
375 | * @return TRUE if succeeded, FALSE if not. |
| 16322 | 376 | * |
| 377 | */ | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
378 | static gboolean msim_send_raw(MsimSession *session, const gchar *msg) |
| 16322 | 379 | { |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
380 | int total_bytes_sent, total_bytes; |
| 16322 | 381 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
382 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
383 | g_return_val_if_fail(msg != NULL, FALSE); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
384 | |
| 16324 | 385 | purple_debug_info("msim", "msim_send: writing <%s>\n", msg); |
| 16322 | 386 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
387 | /* Loop until all data is sent, or a failure occurs. */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
388 | total_bytes_sent = 0; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
389 | total_bytes = strlen(msg); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
390 | do |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
391 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
392 | int bytes_sent; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
393 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
394 | bytes_sent = send(session->fd, msg + total_bytes_sent, |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
395 | total_bytes - total_bytes_sent, 0); |
| 16322 | 396 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
397 | if (bytes_sent < 0) |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
398 | { |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
399 | purple_debug_info("msim", "msim_send_raw(%s): send() failed: %s\n", |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
400 | msg, g_strerror(errno)); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
401 | return FALSE; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
402 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
403 | total_bytes_sent += bytes_sent; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
404 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
405 | } while(total_bytes_sent < total_bytes); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
406 | return TRUE; |
| 16322 | 407 | } |
| 408 | ||
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
409 | /** |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
410 | * Send a message to the server. |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
411 | * |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
412 | * @param session |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
413 | * @param ... A sequence of gchar* key/value pairs, terminated with NULL |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
414 | */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
415 | static gboolean msim_send(MsimSession *session, ...) |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
416 | { |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
417 | /* TODO: implement this */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
418 | } |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
419 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
420 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
421 | * Start logging in to the MSIM servers. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
422 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
423 | * @param acct Account information to use to login. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
424 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
425 | static void msim_login(PurpleAccount *acct) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
426 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
427 | PurpleConnection *gc; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
428 | const char *host; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
429 | int port; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
430 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
431 | g_return_if_fail(acct != NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
432 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
433 | purple_debug_info("myspace", "logging in %s\n", acct->username); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
434 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
435 | gc = purple_account_get_connection(acct); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
436 | gc->proto_data = msim_session_new(acct); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
437 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
438 | /* 1. connect to server */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
439 | purple_connection_update_progress(gc, "Connecting", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
440 | 0, /* which connection step this is */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
441 | 4); /* total number of steps */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
442 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
443 | /* TODO: GUI option to be user-modifiable. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
444 | host = purple_account_get_string(acct, "server", MSIM_SERVER); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
445 | port = purple_account_get_int(acct, "port", MSIM_PORT); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
446 | /* TODO: connect */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
447 | /* From purple.sf.net/api: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
448 | * """Note that this function name can be misleading--although it is called |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
449 | * "proxy connect," it is used for establishing any outgoing TCP connection, |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
450 | * whether through a proxy or not.""" */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
451 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
452 | /* Calls msim_connect_cb when connected. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
453 | if (purple_proxy_connect(gc, acct, host, port, msim_connect_cb, gc) == NULL) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
454 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
455 | /* TODO: try other ports if in auto mode, then save |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
456 | * working port and try that first next time. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
457 | purple_connection_error(gc, "Couldn't create socket"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
458 | return; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
459 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
460 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
461 | } |
| 16322 | 462 | /** |
| 463 | * Process a login challenge, sending a response. | |
| 464 | * | |
| 465 | * @param session | |
| 466 | * @param table Hash table of login challenge message. | |
| 467 | * | |
| 468 | * @return 0, since the 'table' parameter is no longer needed. | |
| 469 | */ | |
| 470 | static int msim_login_challenge(MsimSession *session, GHashTable *table) | |
| 471 | { | |
| 16324 | 472 | PurpleAccount *account; |
| 16322 | 473 | gchar *nc_str; |
| 474 | guchar *nc; | |
| 475 | gchar *response_str; | |
| 476 | gsize nc_len; | |
| 477 | gchar *buf; | |
| 478 | ||
| 479 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 480 | g_return_val_if_fail(table != NULL, 0); | |
| 481 | ||
| 482 | nc_str = g_hash_table_lookup(table, "nc"); | |
| 483 | ||
| 484 | account = session->account; | |
| 485 | //assert(account); | |
| 486 | ||
| 16324 | 487 | purple_connection_update_progress(session->gc, "Reading challenge", 1, 4); |
| 16322 | 488 | |
| 16324 | 489 | purple_debug_info("msim", "nc=<%s>\n", nc_str); |
| 16322 | 490 | |
| 16324 | 491 | nc = (guchar*)purple_base64_decode(nc_str, &nc_len); |
| 492 | purple_debug_info("msim", "base64 decoded to %d bytes\n", nc_len); | |
| 16322 | 493 | if (nc_len != 0x40) |
| 494 | { | |
| 16324 | 495 | purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len); |
| 496 | purple_connection_error(session->gc, "Unexpected challenge length from server"); | |
| 16322 | 497 | return 0; |
| 498 | } | |
| 499 | ||
| 16324 | 500 | purple_connection_update_progress(session->gc, "Logging in", 2, 4); |
| 16322 | 501 | |
| 502 | response_str = msim_compute_login_response(nc, account->username, account->password); | |
| 503 | ||
| 504 | g_free(nc); | |
| 505 | ||
| 506 | /* Reply */ | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
507 | /* TODO: escape values. A response_str with a / in it (\ is not in base64) will |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
508 | * cause a login failure! / must be encoded as /1. */ |
| 16322 | 509 | buf = g_strdup_printf("\\login2\\%d\\username\\%s\\response\\%s\\clientver\\%d\\reconn\\%d\\status\\%d\\id\\1\\final\\", |
| 510 | 196610, account->username, response_str, MSIM_CLIENT_VERSION, 0, 100); | |
| 511 | ||
| 512 | g_free(response_str); | |
| 513 | ||
| 16324 | 514 | purple_debug_info("msim", "response=<%s>\n", buf); |
| 16322 | 515 | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
516 | msim_send_raw(session, buf); |
| 16322 | 517 | |
| 518 | g_free(buf); | |
| 519 | ||
| 520 | return 0; | |
| 521 | } | |
| 522 | ||
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
523 | #ifndef MSIM_USE_PURPLE_RC4 |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
524 | /* No RC4 in this version of libpurple, so bring our own. */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
525 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
526 | /* |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
527 | Unix SMB/CIFS implementation. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
528 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
529 | a partial implementation of RC4 designed for use in the |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
530 | SMB authentication protocol |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
531 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
532 | Copyright (C) Andrew Tridgell 1998 |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
533 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
534 | $Id: crypt-rc4.c 12116 2004-09-27 23:29:22Z guy $ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
535 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
536 | This program is free software; you can redistribute it and/or modify |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
537 | it under the terms of the GNU General Public License as published by |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
538 | the Free Software Foundation; either version 2 of the License, or |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
539 | (at your option) any later version. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
540 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
541 | This program is distributed in the hope that it will be useful, |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
542 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
543 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
544 | GNU General Public License for more details. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
545 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
546 | You should have received a copy of the GNU General Public License |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
547 | along with this program; if not, write to the Free Software |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
548 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
549 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
550 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
551 | Modified by Jeff Connelly for MySpaceIM Gaim plugin. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
552 | */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
553 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
554 | #include <glib.h> |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
555 | #include <string.h> |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
556 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
557 | /* Perform RC4 on a block of data using specified key. "data" is a pointer |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
558 | to the block to be processed. Output is written to same memory as input, |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
559 | so caller may need to make a copy before calling this function, since |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
560 | the input will be overwritten. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
561 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
562 | Taken from Samba source code. Modified to allow us to maintain state |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
563 | between calls to crypt_rc4. |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
564 | */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
565 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
566 | void crypt_rc4_init(rc4_state_struct *rc4_state, |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
567 | const unsigned char *key, int key_len) |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
568 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
569 | int ind; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
570 | unsigned char j = 0; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
571 | unsigned char *s_box; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
572 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
573 | memset(rc4_state, 0, sizeof(rc4_state_struct)); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
574 | s_box = rc4_state->s_box; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
575 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
576 | for (ind = 0; ind < 256; ind++) |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
577 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
578 | s_box[ind] = (unsigned char)ind; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
579 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
580 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
581 | for( ind = 0; ind < 256; ind++) |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
582 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
583 | unsigned char tc; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
584 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
585 | j += (s_box[ind] + key[ind%key_len]); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
586 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
587 | tc = s_box[ind]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
588 | s_box[ind] = s_box[j]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
589 | s_box[j] = tc; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
590 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
591 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
592 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
593 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
594 | void crypt_rc4(rc4_state_struct *rc4_state, unsigned char *data, int data_len) |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
595 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
596 | unsigned char *s_box; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
597 | unsigned char index_i; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
598 | unsigned char index_j; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
599 | int ind; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
600 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
601 | /* retrieve current state from the state struct (so we can resume where |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
602 | we left off) */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
603 | index_i = rc4_state->index_i; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
604 | index_j = rc4_state->index_j; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
605 | s_box = rc4_state->s_box; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
606 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
607 | for( ind = 0; ind < data_len; ind++) |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
608 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
609 | unsigned char tc; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
610 | unsigned char t; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
611 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
612 | index_i++; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
613 | index_j += s_box[index_i]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
614 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
615 | tc = s_box[index_i]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
616 | s_box[index_i] = s_box[index_j]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
617 | s_box[index_j] = tc; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
618 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
619 | t = s_box[index_i] + s_box[index_j]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
620 | data[ind] = data[ind] ^ s_box[t]; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
621 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
622 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
623 | /* Store the updated state */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
624 | rc4_state->index_i = index_i; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
625 | rc4_state->index_j = index_j; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
626 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
627 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
628 | #endif /* !MSIM_USE_PURPLE_RC4 */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
629 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
630 | |
| 16322 | 631 | /** |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
632 | * Compute the base64'd login challenge response based on username, password, nonce, and IPs. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
633 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
634 | * @param nonce The base64 encoded nonce ('nc') field from the server. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
635 | * @param email User's email address (used as login name). |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
636 | * @param password User's cleartext password. |
| 16322 | 637 | * |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
638 | * @return Encoded login challenge response, ready to send to the server. Must be g_free()'d |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
639 | * when finished. |
| 16322 | 640 | */ |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
641 | static gchar* msim_compute_login_response(guchar nonce[2*NONCE_SIZE], |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
642 | gchar* email, gchar* password) |
| 16322 | 643 | { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
644 | PurpleCipherContext *key_context; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
645 | PurpleCipher *sha1; |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
646 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
647 | PurpleCipherContext *rc4; |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
648 | #else |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
649 | rc4_state_struct rc4; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
650 | #endif |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
651 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
652 | guchar hash_pw[HASH_SIZE]; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
653 | guchar key[HASH_SIZE]; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
654 | gchar* password_utf16le; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
655 | guchar* data; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
656 | guchar* data_out; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
657 | gchar* response; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
658 | size_t data_len, data_out_len; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
659 | gsize conv_bytes_read, conv_bytes_written; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
660 | GError* conv_error; |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
661 | #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
662 | int i; |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
663 | #endif |
| 16322 | 664 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
665 | //memset(nonce, 0, NONCE_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
666 | //memset(nonce + NONCE_SIZE, 1, NONCE_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
667 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
668 | /* Convert ASCII password to UTF16 little endian */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
669 | purple_debug_info("msim", "converting password to UTF-16LE\n"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
670 | conv_error = NULL; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
671 | password_utf16le = g_convert(password, -1, "UTF-16LE", "UTF-8", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
672 | &conv_bytes_read, &conv_bytes_written, &conv_error); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
673 | g_assert(conv_bytes_read == strlen(password)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
674 | if (conv_error != NULL) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
675 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
676 | purple_debug_error("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
677 | "g_convert password UTF8->UTF16LE failed: %s", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
678 | conv_error->message); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
679 | g_error_free(conv_error); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
680 | } |
| 16322 | 681 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
682 | /* Compute password hash */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
683 | purple_cipher_digest_region("sha1", (guchar*)password_utf16le, |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
684 | conv_bytes_written, sizeof(hash_pw), hash_pw, NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
685 | g_free(password_utf16le); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
686 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
687 | #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
688 | purple_debug_info("msim", "pwhash = "); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
689 | for (i = 0; i < sizeof(hash_pw); i++) |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
690 | purple_debug_info("msim", "%.2x ", hash_pw[i]); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
691 | purple_debug_info("msim", "\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
692 | #endif |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
693 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
694 | /* key = sha1(sha1(pw) + nonce2) */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
695 | sha1 = purple_ciphers_find_cipher("sha1"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
696 | key_context = purple_cipher_context_new(sha1, NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
697 | purple_cipher_context_append(key_context, hash_pw, HASH_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
698 | purple_cipher_context_append(key_context, nonce + NONCE_SIZE, NONCE_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
699 | purple_cipher_context_digest(key_context, sizeof(key), key, NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
700 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
701 | #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
702 | purple_debug_info("msim", "key = "); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
703 | for (i = 0; i < sizeof(key); i++) |
| 16322 | 704 | { |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
705 | purple_debug_info("msim", "%.2x ", key[i]); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
706 | } |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
707 | purple_debug_info("msim", "\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
708 | #endif |
| 16322 | 709 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
710 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
711 | rc4 = purple_cipher_context_new_by_name("rc4", NULL); |
| 16322 | 712 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
713 | /* Note: 'key' variable is 0x14 bytes (from SHA-1 hash), |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
714 | * but only first 0x10 used for the RC4 key. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
715 | purple_cipher_context_set_option(rc4, "key_len", (gpointer)0x10); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
716 | purple_cipher_context_set_key(rc4, key); |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
717 | #endif |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
718 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
719 | /* TODO: obtain IPs of network interfaces. This is not immediately |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
720 | * important because you can still connect and perform basic |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
721 | * functions of the protocol. There is also a high chance that the addreses |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
722 | * are RFC1918 private, so the servers couldn't do anything with them |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
723 | * anyways except make note of that fact. Probably important for any |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
724 | * kind of direct connection, or file transfer functionality. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
725 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
726 | /* rc4 encrypt: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
727 | * nonce1+email+IP list */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
728 | data_len = NONCE_SIZE + strlen(email) + 25; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
729 | data = g_new0(guchar, data_len); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
730 | memcpy(data, nonce, NONCE_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
731 | memcpy(data + NONCE_SIZE, email, strlen(email)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
732 | memcpy(data + NONCE_SIZE + strlen(email), |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
733 | /* TODO: IP addresses of network interfaces */ |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
734 | "\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); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
735 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
736 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
737 | data_out = g_new0(guchar, data_len); |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
738 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
739 | purple_cipher_context_encrypt(rc4, (const guchar*)data, |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
740 | data_len, data_out, &data_out_len); |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
741 | purple_cipher_context_destroy(rc4); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
742 | #else |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
743 | /* Use our own RC4 code */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
744 | purple_debug_info("msim", "Using non-purple RC4 cipher code in this version\n"); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
745 | crypt_rc4_init(&rc4, key, 0x10); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
746 | crypt_rc4(&rc4, data, data_len); |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
747 | data_out_len = data_len; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
748 | data_out = data; |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
749 | #endif |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
750 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
751 | g_assert(data_out_len == data_len); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
752 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
753 | response = purple_base64_encode(data_out, data_out_len); |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
754 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
755 | g_free(data_out); |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
756 | #endif |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
757 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
758 | #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
759 | purple_debug_info("msim", "response=<%s>\n", response); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
760 | #endif |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
761 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
762 | return response; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
763 | } |
| 16322 | 764 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
765 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
766 | * Schedule an IM to be sent once the user ID is looked up. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
767 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
768 | * @param gc Connection. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
769 | * @param who A user id, email, or username to send the message to. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
770 | * @param message Instant message text to send. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
771 | * @param flags Flags. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
772 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
773 | * @return 1 in all cases, even if the message delivery is destined to fail. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
774 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
775 | * Allows sending to a user by username, email address, or userid. If |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
776 | * a username or email address is given, the userid must be looked up. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
777 | * This function does that by calling msim_lookup_user(), setting up |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
778 | * a msim_send_im_by_userid_cb() callback function called when the userid |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
779 | * response is received from the server. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
780 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
781 | * The callback function calls msim_send_im_by_userid() to send the actual |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
782 | * instant message. If a userid is specified directly, this function is called |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
783 | * immediately here. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
784 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
785 | static int msim_send_im(PurpleConnection *gc, const char *who, |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
786 | const char *message, PurpleMessageFlags flags) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
787 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
788 | MsimSession *session; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
789 | const char *from_username = gc->account->username; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
790 | send_im_cb_struct *cbinfo; |
| 16322 | 791 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
792 | g_return_val_if_fail(gc != NULL, 0); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
793 | g_return_val_if_fail(who != NULL, 0); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
794 | g_return_val_if_fail(message != NULL, 0); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
795 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
796 | purple_debug_info("msim", "sending message from %s to %s: %s\n", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
797 | from_username, who, message); |
| 16322 | 798 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
799 | session = gc->proto_data; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
800 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
801 | /* If numeric ID, can send message immediately without userid lookup */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
802 | if (msim_is_userid(who)) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
803 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
804 | purple_debug_info("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
805 | "msim_send_im: numeric 'who' detected, sending asap\n"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
806 | msim_send_im_by_userid(session, who, message, flags); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
807 | return 1; |
| 16322 | 808 | } |
| 809 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
810 | /* Otherwise, add callback to IM when userid of destination is available */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
811 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
812 | /* Setup a callback for when the userid is available */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
813 | cbinfo = g_new0(send_im_cb_struct, 1); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
814 | cbinfo->who = g_strdup(who); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
815 | cbinfo->message = g_strdup(message); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
816 | cbinfo->flags = flags; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
817 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
818 | /* Send the request to lookup the userid */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
819 | msim_lookup_user(session, who, msim_send_im_by_userid_cb, cbinfo); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
820 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
821 | /* msim_send_im_by_userid_cb will now be called once userid is looked up */ |
| 16322 | 822 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
823 | /* Return 1 to have Purple show this IM as being sent, 0 to not. I always |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
824 | * return 1 even if the message could not be sent, since I don't know if |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
825 | * it has failed yet--because the IM is only sent after the userid is |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
826 | * retrieved from the server (which happens after this function returns). |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
827 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
828 | * TODO: In MySpace, you login with your email address, but don't talk to other |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
829 | * users using their email address. So there is currently an asymmetry in the |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
830 | * IM windows when using this plugin: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
831 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
832 | * you@example.com: hello |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
833 | * some_other_user: what's going on? |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
834 | * you@example.com: just coding a prpl |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
835 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
836 | * TODO: Make the sent IM's appear as from the user's username, instead of |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
837 | * their email address. Purple uses the login (in MSIM, the email)--change this. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
838 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
839 | return 1; |
| 16322 | 840 | } |
| 841 | ||
| 842 | /** | |
| 843 | * Immediately send an IM to a user, by their numeric user ID. | |
| 844 | * | |
| 845 | * @param session | |
| 846 | * @param userid ASCII numeric userid. | |
| 847 | * @param message Text of message to send. | |
| 16324 | 848 | * @param flags Purple instant message flags. |
| 16322 | 849 | * |
| 850 | * @return 0, since the 'table' parameter is no longer needed. | |
| 851 | * | |
| 852 | */ | |
| 16324 | 853 | static int msim_send_im_by_userid(MsimSession *session, const gchar *userid, const gchar *message, PurpleMessageFlags flags) |
| 16322 | 854 | { |
| 855 | gchar *msg_string; | |
| 856 | ||
| 857 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 858 | g_return_val_if_fail(userid != NULL, 0); | |
| 859 | g_return_val_if_fail(msim_is_userid(userid) == TRUE, 0); | |
| 860 | g_return_val_if_fail(message != NULL, 0); | |
| 861 | ||
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
862 | /* XXX: delete after escape each value */ |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
863 | message = msim_escape(message); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
864 | |
| 16322 | 865 | /* TODO: constants for bm types */ |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
866 | /* TODO: escape values */ |
| 16322 | 867 | msg_string = g_strdup_printf("\\bm\\121\\sesskey\\%s\\t\\%s\\cv\\%d\\msg\\%s\\final\\", |
| 868 | session->sesskey, userid, MSIM_CLIENT_VERSION, message); | |
| 869 | ||
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
870 | /* XXX: delete after escape each value */ |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
871 | g_free((char*)message); |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
872 | |
| 16324 | 873 | purple_debug_info("msim", "going to write: %s\n", msg_string); |
| 16322 | 874 | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
875 | msim_send_raw(session, msg_string); |
| 16322 | 876 | |
| 16324 | 877 | /* TODO: notify Purple that we sent the IM. */ |
| 16322 | 878 | |
| 879 | /* Not needed since sending messages to yourself is allowed by MSIM! */ | |
| 880 | /*if (strcmp(from_username, who) == 0) | |
| 16324 | 881 | serv_got_im(gc, from_username, message, PURPLE_MESSAGE_RECV, time(NULL)); |
| 16322 | 882 | */ |
| 883 | ||
| 884 | return 0; | |
| 885 | } | |
| 886 | ||
| 887 | ||
| 888 | /** | |
| 889 | * Callback called when ready to send an IM by userid (the userid has been looked up). | |
| 890 | * Calls msim_send_im_by_userid. | |
| 891 | * | |
| 892 | * @param session | |
| 893 | * @param userinfo User info message from server containing a 'body' field | |
| 894 | * with a 'UserID' key. This is where the user ID is taken from. | |
| 895 | * @param data A send_im_cb_struct* of information on the IM to send. | |
| 896 | * | |
| 897 | */ | |
| 898 | static void msim_send_im_by_userid_cb(MsimSession *session, GHashTable *userinfo, gpointer data) | |
| 899 | { | |
| 900 | send_im_cb_struct *s; | |
| 901 | gchar *userid; | |
| 902 | GHashTable *body; | |
| 903 | ||
| 904 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 905 | g_return_if_fail(userinfo != NULL); | |
| 906 | ||
| 907 | body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); | |
| 908 | g_assert(body); | |
| 909 | ||
| 910 | userid = g_hash_table_lookup(body, "UserID"); | |
| 911 | ||
| 912 | s = (send_im_cb_struct*)data; | |
| 913 | msim_send_im_by_userid(session, userid, s->message, s->flags); | |
| 914 | ||
| 915 | g_hash_table_destroy(body); | |
| 916 | g_hash_table_destroy(userinfo); | |
| 917 | g_free(s->message); | |
| 918 | g_free(s->who); | |
| 919 | } | |
| 920 | ||
| 921 | /** | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
922 | * Callback to handle incoming messages, after resolving userid. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
923 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
924 | * @param session |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
925 | * @param userinfo Message from server on user's info, containing UserName. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
926 | * @param data A gchar* of the incoming instant message's text. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
927 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
928 | static void msim_incoming_im_cb(MsimSession *session, GHashTable *userinfo, gpointer data) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
929 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
930 | gchar *msg; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
931 | gchar *username; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
932 | GHashTable *body; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
933 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
934 | g_return_if_fail(MSIM_SESSION_VALID(session)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
935 | g_return_if_fail(userinfo != NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
936 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
937 | body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
938 | g_assert(body != NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
939 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
940 | username = g_hash_table_lookup(body, "UserName"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
941 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
942 | msg = (gchar*)data; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
943 | serv_got_im(session->gc, username, msg, PURPLE_MESSAGE_RECV, time(NULL)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
944 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
945 | g_hash_table_destroy(body); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
946 | g_hash_table_destroy(userinfo); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
947 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
948 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
949 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
950 | * Handle an incoming message. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
951 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
952 | * @param session The session |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
953 | * @param table Message from the server, containing 'f' (userid from) and 'msg'. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
954 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
955 | * @return 0, since table can be freed. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
956 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
957 | static int msim_incoming_im(MsimSession *session, GHashTable *table) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
958 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
959 | gchar *userid; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
960 | gchar *msg; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
961 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
962 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
963 | g_return_val_if_fail(table != NULL, 0); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
964 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
965 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
966 | userid = g_hash_table_lookup(table, "f"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
967 | msg = g_hash_table_lookup(table, "msg"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
968 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
969 | purple_debug_info("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
970 | "msim_incoming_im: got msg <%s> from <%s>, resolving username\n", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
971 | msg, userid); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
972 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
973 | msim_lookup_user(session, userid, msim_incoming_im_cb, g_strdup(msg)); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
974 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
975 | return 0; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
976 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
977 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
978 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
979 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
980 | * Process a message. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
981 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
982 | * @param gc Connection. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
983 | * @param table Any message from the server. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
984 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
985 | * @return The return value of the function used to process the message, or -1 if |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
986 | * called with invalid parameters. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
987 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
988 | static int msim_process(PurpleConnection *gc, GHashTable *table) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
989 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
990 | MsimSession *session; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
991 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
992 | g_return_val_if_fail(gc != NULL, -1); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
993 | g_return_val_if_fail(table != NULL, -1); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
994 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
995 | session = (MsimSession*)gc->proto_data; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
996 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
997 | #ifdef MSIM_DEBUG_MSG |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
998 | purple_debug_info("msim", "-------- message -------------\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
999 | g_hash_table_foreach(table, print_hash_item, NULL); |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1000 | purple_debug_info("msim", "------------------------------\n"); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1001 | #endif |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1002 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1003 | if (g_hash_table_lookup(table, "nc")) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1004 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1005 | return msim_login_challenge(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1006 | } else if (g_hash_table_lookup(table, "sesskey")) { |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1007 | purple_debug_info("msim", "SESSKEY=<%s>\n", (gchar*)g_hash_table_lookup(table, "sesskey")); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1008 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1009 | purple_connection_update_progress(gc, "Connected", 3, 4); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1010 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1011 | session->sesskey = g_strdup(g_hash_table_lookup(table, "sesskey")); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1012 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1013 | /* Comes with: proof,profileid,userid,uniquenick -- all same values |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1014 | * (at least for me). */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1015 | session->userid = g_strdup(g_hash_table_lookup(table, "userid")); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1016 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1017 | purple_connection_set_state(gc, PURPLE_CONNECTED); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1018 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1019 | return 0; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1020 | } else if (g_hash_table_lookup(table, "bm")) { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1021 | guint bm; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1022 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1023 | bm = atoi(g_hash_table_lookup(table, "bm")); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1024 | switch (bm) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1025 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1026 | case MSIM_BM_STATUS: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1027 | return msim_status(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1028 | case MSIM_BM_INSTANT: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1029 | return msim_incoming_im(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1030 | default: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1031 | /* Not really an IM, but show it for informational |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1032 | * purposes during development. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1033 | return msim_incoming_im(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1034 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1035 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1036 | if (bm == MSIM_BM_STATUS) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1037 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1038 | return msim_status(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1039 | } else { /* else if strcmp(bm, "1") == 0) */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1040 | return msim_incoming_im(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1041 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1042 | } else if (g_hash_table_lookup(table, "rid")) { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1043 | return msim_process_reply(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1044 | } else if (g_hash_table_lookup(table, "error")) { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1045 | return msim_error(session, table); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1046 | } else if (g_hash_table_lookup(table, "ka")) { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1047 | purple_debug_info("msim", "msim_process: got keep alive\n"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1048 | return 0; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1049 | } else { |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1050 | /* TODO: dump unknown msgs to file, so user can send them to me |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1051 | * if they wish, to help add support for new messages (inspired |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1052 | * by Alexandr Shutko, who maintains OSCAR protocol documentation). */ |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1053 | purple_debug_info("msim", "msim_process: unhandled message\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1054 | return 0; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1055 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1056 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1057 | /** |
| 16322 | 1058 | * Process a message reply from the server. |
| 1059 | * | |
| 1060 | * @param session | |
| 1061 | * @param table Message reply from server. | |
| 1062 | * | |
| 1063 | * @return 0, since the 'table' field is no longer needed. | |
| 1064 | */ | |
| 1065 | static int msim_process_reply(MsimSession *session, GHashTable *table) | |
| 1066 | { | |
| 1067 | gchar *rid_str; | |
| 1068 | ||
| 1069 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 1070 | g_return_val_if_fail(table != NULL, 0); | |
| 1071 | ||
| 1072 | rid_str = g_hash_table_lookup(table, "rid"); | |
| 1073 | ||
| 1074 | if (rid_str) /* msim_lookup_user sets callback for here */ | |
| 1075 | { | |
| 1076 | MSIM_USER_LOOKUP_CB cb; | |
| 1077 | gpointer data; | |
| 1078 | guint rid; | |
| 1079 | ||
| 1080 | GHashTable *body; | |
| 1081 | gchar *username; | |
| 1082 | ||
| 1083 | rid = atol(rid_str); | |
| 1084 | ||
| 1085 | /* Cache the user info. Currently, the GHashTable of user info in | |
| 1086 | * this cache never expires so is never freed. TODO: expire and destroy | |
| 1087 | * | |
| 1088 | * Some information never changes (username->userid map), some does. | |
| 1089 | * TODO: Cache what doesn't change only | |
| 1090 | */ | |
| 1091 | body = msim_parse_body(g_hash_table_lookup(table, "body")); | |
| 1092 | username = g_hash_table_lookup(body, "UserName"); | |
| 1093 | if (username) | |
| 1094 | { | |
| 1095 | g_hash_table_insert(session->user_lookup_cache, g_strdup(username), body); | |
| 1096 | } else { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1097 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1098 | "msim_process_reply: not caching <%s>, no UserName\n", |
| 16322 | 1099 | g_hash_table_lookup(table, "body")); |
| 1100 | } | |
| 1101 | ||
| 1102 | /* If a callback is registered for this userid lookup, call it. */ | |
| 1103 | ||
| 1104 | cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); | |
| 1105 | data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); | |
| 1106 | ||
| 1107 | if (cb) | |
| 1108 | { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1109 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1110 | "msim_process_body: calling callback now\n"); |
| 16322 | 1111 | cb(session, table, data); |
| 1112 | g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); | |
| 1113 | g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); | |
| 1114 | ||
| 1115 | /* Return 1 to tell caller of msim_process (msim_input_cb) to | |
| 1116 | * not destroy 'table'; allow 'cb' to hang on to it and destroy | |
| 1117 | * it when it wants. */ | |
| 1118 | return 1; | |
| 1119 | } else { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1120 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1121 | "msim_process_body: no callback for rid %d\n", rid); |
| 16322 | 1122 | } |
| 1123 | } | |
| 1124 | return 0; | |
| 1125 | } | |
| 1126 | ||
| 1127 | /** | |
| 1128 | * Handle an error from the server. | |
| 1129 | * | |
| 1130 | * @param session | |
| 1131 | * @param table The message. | |
| 1132 | * | |
| 1133 | * @return 0, since 'table' can be freed. | |
| 1134 | */ | |
| 1135 | static int msim_error(MsimSession *session, GHashTable *table) | |
| 1136 | { | |
| 1137 | gchar *err, *errmsg, *full_errmsg; | |
| 1138 | ||
| 1139 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 1140 | g_return_val_if_fail(table != NULL, 0); | |
| 1141 | ||
| 1142 | err = g_hash_table_lookup(table, "err"); | |
| 1143 | errmsg = g_hash_table_lookup(table, "errmsg"); | |
| 1144 | ||
| 1145 | full_errmsg = g_strdup_printf("Protocol error, code %s: %s", err, errmsg); | |
| 1146 | ||
| 16324 | 1147 | purple_debug_info("msim", "msim_error: %s\n", full_errmsg); |
| 16322 | 1148 | |
| 1149 | /* TODO: check 'fatal' and die if asked to. | |
| 1150 | * TODO: do something with the error # (localization of errmsg?) */ | |
| 16324 | 1151 | purple_notify_error(session->account, g_strdup("MySpaceIM Error"), |
| 16322 | 1152 | full_errmsg, NULL); |
| 1153 | ||
| 1154 | if (g_hash_table_lookup(table, "fatal")) | |
| 1155 | { | |
| 16324 | 1156 | purple_debug_info("msim", "fatal error, destroy session\n"); |
| 1157 | purple_connection_error(session->gc, full_errmsg); | |
| 16322 | 1158 | close(session->fd); |
| 1159 | //msim_session_destroy(session); | |
| 1160 | } | |
| 1161 | ||
| 1162 | return 0; | |
| 1163 | } | |
| 1164 | ||
| 1165 | #if 0 | |
| 1166 | /* Not sure about this */ | |
| 1167 | static void msim_status_now(gchar *who, gpointer data) | |
| 1168 | { | |
| 1169 | printf("msim_status_now: %s\n", who); | |
| 1170 | } | |
| 1171 | #endif | |
| 1172 | ||
| 1173 | /** | |
| 1174 | * Callback to update incoming status messages, after looked up username. | |
| 1175 | * | |
| 1176 | * @param session | |
| 1177 | * @param userinfo Looked up user information from server. | |
| 1178 | * @param data gchar* status string. | |
| 1179 | * | |
| 1180 | */ | |
| 1181 | static void msim_status_cb(MsimSession *session, GHashTable *userinfo, gpointer data) | |
| 1182 | { | |
| 16324 | 1183 | PurpleBuddyList *blist; |
| 1184 | PurpleBuddy *buddy; | |
| 1185 | PurplePresence *presence; | |
| 16322 | 1186 | GHashTable *body; |
| 16324 | 1187 | //PurpleStatus *status; |
| 16322 | 1188 | gchar **status_array; |
| 1189 | GList *list; | |
| 1190 | gchar *status_text, *status_code; | |
| 1191 | gchar *status_str; | |
| 1192 | gint i; | |
| 1193 | gchar *username; | |
| 1194 | ||
| 1195 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1196 | g_return_if_fail(userinfo != NULL); | |
| 1197 | ||
| 1198 | status_str = (gchar*)data; | |
| 1199 | ||
| 1200 | body = msim_parse_body(g_hash_table_lookup(userinfo, "body")); | |
| 1201 | g_assert(body); | |
| 1202 | ||
| 1203 | username = g_hash_table_lookup(body, "UserName"); | |
| 1204 | /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on | |
| 1205 | * the buddy list, if the UserID was stored along with it. */ | |
| 1206 | ||
| 1207 | if (!username) | |
| 1208 | { | |
| 16324 | 1209 | purple_debug_info("msim", "msim_status_cb: no username?!\n"); |
| 16322 | 1210 | return; |
| 1211 | } | |
| 1212 | ||
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1213 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1214 | "msim_status_cb: updating status for <%s> to <%s>\n", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1215 | username, status_str); |
| 16322 | 1216 | |
| 1217 | /* TODO: generic functions to split into a GList */ | |
| 1218 | status_array = g_strsplit(status_str, "|", 0); | |
| 1219 | for (list = NULL, i = 0; | |
| 1220 | status_array[i]; | |
| 1221 | i++) | |
| 1222 | { | |
| 1223 | list = g_list_append(list, status_array[i]); | |
| 1224 | } | |
| 1225 | ||
| 1226 | /* Example fields: |s|0|ss|Offline */ | |
| 1227 | status_code = g_list_nth_data(list, 2); | |
| 1228 | status_text = g_list_nth_data(list, 4); | |
| 1229 | ||
| 16324 | 1230 | blist = purple_get_blist(); |
| 16322 | 1231 | |
| 1232 | /* Add buddy if not found */ | |
| 16324 | 1233 | buddy = purple_find_buddy(session->account, username); |
| 16322 | 1234 | if (!buddy) |
| 1235 | { | |
| 16324 | 1236 | /* TODO: purple aliases, userids and usernames */ |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1237 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1238 | "msim_status: making new buddy for %s\n", username); |
| 16324 | 1239 | buddy = purple_buddy_new(session->account, username, NULL); |
| 16322 | 1240 | |
| 1241 | /* TODO: sometimes (when click on it), buddy list disappears. Fix. */ | |
| 16324 | 1242 | purple_blist_add_buddy(buddy, NULL, NULL, NULL); |
| 16322 | 1243 | } else { |
| 16324 | 1244 | purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
| 16322 | 1245 | } |
| 1246 | ||
| 1247 | /* For now, always set status to online. | |
| 1248 | * TODO: make status reflect reality | |
| 1249 | * TODO: show headline */ | |
| 16324 | 1250 | presence = purple_presence_new_for_buddy(buddy); |
| 1251 | purple_presence_set_status_active(presence, MSIM_STATUS_ONLINE, TRUE); | |
| 16322 | 1252 | |
| 1253 | g_strfreev(status_array); | |
| 1254 | g_list_free(list); | |
| 1255 | g_hash_table_destroy(body); | |
| 1256 | g_hash_table_destroy(userinfo); | |
| 1257 | /* Do not free status_str - it will be freed by g_hash_table_destroy on session->userid_lookup_cb_data */ | |
| 1258 | } | |
| 1259 | ||
| 1260 | /** | |
| 1261 | * Process incoming status messages. | |
| 1262 | * | |
| 1263 | * @param session | |
| 1264 | * @param table Status update message. | |
| 1265 | * | |
| 1266 | * @return 0, since 'table' can be freed. | |
| 1267 | */ | |
| 1268 | static int msim_status(MsimSession *session, GHashTable *table) | |
| 1269 | { | |
| 1270 | gchar *status_str; | |
| 1271 | gchar *userid; | |
| 1272 | ||
| 1273 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 1274 | g_return_val_if_fail(table != NULL, 0); | |
| 1275 | ||
| 1276 | status_str = g_hash_table_lookup(table, "msg"); | |
| 1277 | if (!status_str) | |
| 1278 | { | |
| 16324 | 1279 | purple_debug_info("msim", "msim_status: bm=100 but no status msg\n"); |
| 16322 | 1280 | return 0; |
| 1281 | } | |
| 1282 | ||
| 1283 | userid = g_hash_table_lookup(table, "f"); | |
| 1284 | if (!userid) | |
| 1285 | { | |
| 16324 | 1286 | purple_debug_info("msim", "msim_status: bm=100 but no f field\n"); |
| 16322 | 1287 | return 0; |
| 1288 | } | |
| 1289 | ||
| 1290 | /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup | |
| 1291 | * before updating the status! Much more efficient. */ | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1292 | purple_debug_info("msim", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1293 | "msim_status: got status msg <%s> for <%s>, scheduling lookup\n", |
| 16322 | 1294 | status_str, userid); |
| 1295 | ||
| 1296 | /* Actually update status once obtain username */ | |
| 1297 | msim_lookup_user(session, userid, msim_status_cb, g_strdup(status_str)); | |
| 1298 | ||
| 1299 | return 0; | |
| 1300 | } | |
| 1301 | ||
| 1302 | ||
| 1303 | ||
| 1304 | /** | |
| 1305 | * Callback when input available. | |
| 1306 | * | |
| 16324 | 1307 | * @param gc_uncasted A PurpleConnection pointer. |
| 16322 | 1308 | * @param source File descriptor. |
| 16324 | 1309 | * @param cond PURPLE_INPUT_READ |
| 16322 | 1310 | * |
| 1311 | * Reads the input, and dispatches calls msim_process to handle it. | |
| 1312 | */ | |
| 16324 | 1313 | static void msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond) |
| 16322 | 1314 | { |
| 16324 | 1315 | PurpleConnection *gc; |
| 1316 | PurpleAccount *account; | |
| 16322 | 1317 | MsimSession *session; |
| 1318 | gchar *end; | |
| 1319 | int n; | |
| 1320 | ||
| 1321 | g_return_if_fail(gc_uncasted != NULL); | |
| 1322 | g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ | |
| 1323 | ||
| 16324 | 1324 | gc = (PurpleConnection*)(gc_uncasted); |
| 1325 | account = purple_connection_get_account(gc); | |
| 16322 | 1326 | session = gc->proto_data; |
| 1327 | ||
| 1328 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1329 | ||
| 16324 | 1330 | g_assert(cond == PURPLE_INPUT_READ); |
| 16322 | 1331 | |
| 1332 | /* Only can handle so much data at once... | |
| 1333 | * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. | |
| 1334 | * Should be large enough to hold the largest protocol message. | |
| 1335 | */ | |
| 1336 | if (session->rxoff == MSIM_READ_BUF_SIZE) | |
| 1337 | { | |
| 16324 | 1338 | purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n", |
| 16322 | 1339 | MSIM_READ_BUF_SIZE); |
| 16324 | 1340 | purple_connection_error(gc, "Read buffer full"); |
| 16322 | 1341 | /* TODO: fix 100% CPU after closing */ |
| 1342 | close(source); | |
| 1343 | return; | |
| 1344 | } | |
| 1345 | ||
| 16324 | 1346 | purple_debug_info("msim", "buffer at %d (max %d), reading up to %d\n", |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1347 | session->rxoff, MSIM_READ_BUF_SIZE, |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1348 | MSIM_READ_BUF_SIZE - session->rxoff); |
| 16322 | 1349 | |
| 1350 | /* Read into buffer. On Win32, need recv() not read(). session->fd also holds | |
| 1351 | * the file descriptor, but it sometimes differs from the 'source' parameter. | |
| 1352 | */ | |
| 1353 | n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0); | |
| 1354 | ||
| 1355 | if (n < 0 && errno == EAGAIN) | |
| 1356 | { | |
| 1357 | return; | |
| 1358 | } | |
| 1359 | else if (n < 0) | |
| 1360 | { | |
| 16324 | 1361 | purple_connection_error(gc, "Read error"); |
| 1362 | purple_debug_error("msim", "msim_input_cb: read error, ret=%d, " | |
| 16322 | 1363 | "error=%s, source=%d, fd=%d (%X))\n", |
| 1364 | n, strerror(errno), source, session->fd, session->fd); | |
| 1365 | close(source); | |
| 1366 | return; | |
| 1367 | } | |
| 1368 | else if (n == 0) | |
| 1369 | { | |
| 16324 | 1370 | purple_debug_info("msim", "msim_input_cb: server disconnected\n"); |
| 1371 | purple_connection_error(gc, "Server has disconnected"); | |
| 16322 | 1372 | return; |
| 1373 | } | |
| 1374 | ||
| 1375 | /* Null terminate */ | |
| 1376 | session->rxbuf[session->rxoff + n] = 0; | |
| 1377 | ||
| 1378 | /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */ | |
| 1379 | if (strlen(session->rxbuf + session->rxoff) != n) | |
| 1380 | { | |
| 1381 | /* Occurs after login, but it is not a null byte. */ | |
| 16324 | 1382 | purple_debug_info("msim", "msim_input_cb: strlen=%d, but read %d bytes" |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1383 | "--null byte encountered?\n", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1384 | strlen(session->rxbuf + session->rxoff), n); |
| 16324 | 1385 | //purple_connection_error(gc, "Invalid message - null byte on input"); |
| 16322 | 1386 | return; |
| 1387 | } | |
| 1388 | ||
| 1389 | session->rxoff += n; | |
| 16324 | 1390 | purple_debug_info("msim", "msim_input_cb: read=%d\n", n); |
| 16322 | 1391 | |
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
1392 | #ifdef MSIM_DEBUG_RXBUF |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1393 | purple_debug_info("msim", "buf=<%s>\n", session->rxbuf); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1394 | #endif |
| 16322 | 1395 | |
| 1396 | /* Look for \\final\\ end markers. If found, process message. */ | |
| 1397 | while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) | |
| 1398 | { | |
| 1399 | GHashTable *table; | |
| 1400 | ||
|
17892
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
1401 | #ifdef MSIM_DEBUG_RXBUF |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1402 | purple_debug_info("msim", "in loop: buf=<%s>\n", session->rxbuf); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1403 | #endif |
| 16322 | 1404 | *end = 0; |
| 1405 | table = msim_parse(g_strdup(session->rxbuf)); | |
| 1406 | if (!table) | |
| 1407 | { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1408 | purple_debug_info("msim", "msim_input_cb: couldn't parse <%s>\n", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1409 | session->rxbuf); |
| 16324 | 1410 | purple_connection_error(gc, "Unparseable message"); |
| 16322 | 1411 | } |
| 1412 | else | |
| 1413 | { | |
| 1414 | /* Process message. Returns 0 to free */ | |
| 1415 | if (msim_process(gc, table) == 0) | |
| 1416 | g_hash_table_destroy(table); | |
| 1417 | } | |
| 1418 | ||
| 1419 | /* Move remaining part of buffer to beginning. */ | |
| 1420 | session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING); | |
| 1421 | memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING), | |
| 1422 | MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf)); | |
| 1423 | ||
| 1424 | /* Clear end of buffer */ | |
| 1425 | //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf)); | |
| 1426 | } | |
| 1427 | } | |
| 1428 | ||
| 1429 | /** | |
| 1430 | * Callback when connected. Sets up input handlers. | |
| 1431 | * | |
| 16324 | 1432 | * @param data A PurpleConnection pointer. |
| 16322 | 1433 | * @param source File descriptor. |
| 1434 | * @param error_message | |
| 1435 | */ | |
| 1436 | static void msim_connect_cb(gpointer data, gint source, const gchar *error_message) | |
| 1437 | { | |
| 16324 | 1438 | PurpleConnection *gc; |
| 16322 | 1439 | MsimSession *session; |
| 1440 | ||
| 1441 | g_return_if_fail(data != NULL); | |
| 1442 | ||
| 16324 | 1443 | gc = (PurpleConnection*)data; |
| 16322 | 1444 | session = gc->proto_data; |
| 1445 | ||
| 1446 | if (source < 0) | |
| 1447 | { | |
| 16324 | 1448 | purple_connection_error(gc, "Couldn't connect to host"); |
| 1449 | purple_connection_error(gc, g_strdup_printf("Couldn't connect to host: %s (%d)", | |
| 16322 | 1450 | error_message, source)); |
| 1451 | return; | |
| 1452 | } | |
| 1453 | ||
| 1454 | session->fd = source; | |
| 1455 | ||
| 16324 | 1456 | gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); |
| 16322 | 1457 | } |
| 1458 | ||
| 1459 | /* Session methods */ | |
| 1460 | ||
| 1461 | /** | |
| 1462 | * Create a new MSIM session. | |
| 1463 | * | |
| 1464 | * @param acct The account to create the session from. | |
| 1465 | * | |
| 1466 | * @return Pointer to a new session. Free with msim_session_destroy. | |
| 1467 | */ | |
| 16324 | 1468 | static MsimSession *msim_session_new(PurpleAccount *acct) |
| 16322 | 1469 | { |
| 1470 | MsimSession *session; | |
| 1471 | ||
| 1472 | g_return_val_if_fail(acct != NULL, NULL); | |
| 1473 | ||
| 1474 | session = g_new0(MsimSession, 1); | |
| 1475 | ||
| 1476 | session->magic = MSIM_SESSION_STRUCT_MAGIC; | |
| 1477 | session->account = acct; | |
| 16324 | 1478 | session->gc = purple_account_get_connection(acct); |
| 16322 | 1479 | session->fd = -1; |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1480 | session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1481 | g_direct_equal, NULL, NULL); /* do NOT free function pointers! */ |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1482 | session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1483 | g_direct_equal, NULL, g_free); |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1484 | session->user_lookup_cache = g_hash_table_new_full(g_str_hash, g_str_equal, |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1485 | g_free, (GDestroyNotify)g_hash_table_destroy); |
| 16322 | 1486 | session->rxoff = 0; |
| 1487 | session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); | |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1488 | session->next_rid = 1; |
| 16322 | 1489 | |
| 1490 | return session; | |
| 1491 | } | |
| 1492 | ||
| 1493 | /** | |
| 1494 | * Free a session. | |
| 1495 | * | |
| 1496 | * @param session The session to destroy. | |
| 1497 | */ | |
| 1498 | static void msim_session_destroy(MsimSession *session) | |
| 1499 | { | |
| 1500 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1501 | ||
| 1502 | session->magic = -1; | |
| 1503 | ||
| 1504 | g_free(session->rxbuf); | |
| 1505 | g_free(session->userid); | |
| 1506 | g_free(session->sesskey); | |
| 1507 | ||
| 1508 | g_free(session); | |
| 1509 | } | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1510 | |
| 16322 | 1511 | |
| 1512 | ||
| 1513 | /** | |
| 1514 | * Close the connection. | |
| 1515 | * | |
| 1516 | * @param gc The connection. | |
| 1517 | */ | |
| 16324 | 1518 | static void msim_close(PurpleConnection *gc) |
| 16322 | 1519 | { |
| 1520 | g_return_if_fail(gc != NULL); | |
| 1521 | ||
| 1522 | msim_session_destroy(gc->proto_data); | |
| 1523 | } | |
| 1524 | ||
| 1525 | ||
| 1526 | /** | |
| 1527 | * Check if a string is a userid (all numeric). | |
| 1528 | * | |
| 1529 | * @param user The user id, email, or name. | |
| 1530 | * | |
| 1531 | * @return TRUE if is userid, FALSE if not. | |
| 1532 | */ | |
| 1533 | static inline gboolean msim_is_userid(const gchar *user) | |
| 1534 | { | |
| 1535 | g_return_val_if_fail(user != NULL, FALSE); | |
| 1536 | ||
| 1537 | return strspn(user, "0123456789") == strlen(user); | |
| 1538 | } | |
| 1539 | ||
| 1540 | /** | |
| 1541 | * Check if a string is an email address (contains an @). | |
| 1542 | * | |
| 1543 | * @param user The user id, email, or name. | |
| 1544 | * | |
| 1545 | * @return TRUE if is an email, FALSE if not. | |
| 1546 | * | |
| 1547 | * This function is not intended to be used as a generic | |
| 1548 | * means of validating email addresses, but to distinguish | |
| 1549 | * between a user represented by an email address from | |
| 1550 | * other forms of identification. | |
| 1551 | */ | |
| 1552 | static inline gboolean msim_is_email(const gchar *user) | |
| 1553 | { | |
| 1554 | g_return_val_if_fail(user != NULL, FALSE); | |
| 1555 | ||
| 1556 | return strchr(user, '@') != NULL; | |
| 1557 | } | |
| 1558 | ||
| 1559 | ||
| 1560 | /** | |
| 1561 | * Asynchronously lookup user information, calling callback when receive result. | |
| 1562 | * | |
| 1563 | * @param session | |
| 1564 | * @param user The user id, email address, or username. | |
| 1565 | * @param cb Callback, called with user information when available. | |
| 1566 | * @param data An arbitray data pointer passed to the callback. | |
| 1567 | */ | |
| 1568 | static void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data) | |
| 1569 | { | |
| 1570 | gchar *field_name; | |
| 1571 | gchar *msg_string; | |
| 1572 | guint rid, cmd, dsn, lid; | |
| 1573 | ||
| 1574 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1575 | g_return_if_fail(user != NULL); | |
| 1576 | g_return_if_fail(cb != NULL); | |
| 1577 | ||
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1578 | purple_debug_info("msim", "msim_lookup_userid", |
|
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1579 | "asynchronously looking up <%s>\n", user); |
| 16322 | 1580 | |
| 1581 | /* TODO: check if this user's info was cached and fresh; if so return immediately */ | |
| 1582 | #if 0 | |
| 1583 | /* If already know userid, then call callback immediately */ | |
| 1584 | cached_userid = g_hash_table_lookup(session->userid_cache, who); | |
| 1585 | if (cached_userid && !by_userid) | |
| 1586 | { | |
| 1587 | cb(cached_userid, NULL, NULL, data); | |
| 1588 | return; | |
| 1589 | } | |
| 1590 | #endif | |
| 1591 | ||
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1592 | rid = session->next_rid; |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1593 | ++session->next_rid; |
| 16322 | 1594 | |
| 1595 | /* Setup callback. Response will be associated with request using 'rid'. */ | |
| 1596 | g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb); | |
| 1597 | g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data); | |
| 1598 | ||
| 1599 | /* Send request */ | |
| 1600 | ||
| 1601 | cmd = 1; | |
| 1602 | ||
| 1603 | if (msim_is_userid(user)) | |
| 1604 | { | |
| 1605 | /* TODO: document cmd,dsn,lid */ | |
| 1606 | field_name = "UserID"; | |
| 1607 | dsn = 4; | |
| 1608 | lid = 3; | |
| 1609 | } else if (msim_is_email(user)) { | |
| 1610 | field_name = "Email"; | |
| 1611 | dsn = 5; | |
| 1612 | lid = 7; | |
| 1613 | } else { | |
| 1614 | field_name = "UserName"; | |
| 1615 | dsn = 5; | |
| 1616 | lid = 7; | |
| 1617 | } | |
| 1618 | ||
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
1619 | /* TODO: escape values */ |
| 16322 | 1620 | msg_string = g_strdup_printf("\\persist\\1\\sesskey\\%s\\cmd\\1\\dsn\\%d\\uid\\%s\\lid\\%d\\rid\\%d\\body\\%s=%s\\final\\", |
| 1621 | session->sesskey, dsn, session->userid, lid, rid, field_name, user); | |
| 1622 | ||
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1623 | msim_send_raw(session, msg_string); |
| 16322 | 1624 | } |
| 1625 | ||
| 1626 | ||
| 1627 | /** | |
| 1628 | * Obtain the status text for a buddy. | |
| 1629 | * | |
| 1630 | * @param buddy The buddy to obtain status text for. | |
| 1631 | * | |
| 1632 | * @return Status text. | |
| 1633 | * | |
| 1634 | * Currently returns the display name. | |
| 1635 | */ | |
| 16324 | 1636 | static char *msim_status_text(PurpleBuddy *buddy) |
| 16322 | 1637 | { |
| 1638 | MsimSession *session; | |
| 1639 | GHashTable *userinfo; | |
| 1640 | gchar *display_name; | |
| 1641 | ||
| 1642 | g_return_val_if_fail(buddy != NULL, NULL); | |
| 1643 | ||
| 1644 | session = (MsimSession*)buddy->account->gc->proto_data; | |
| 1645 | g_assert(MSIM_SESSION_VALID(session)); | |
| 1646 | g_assert(session->user_lookup_cache != NULL); | |
| 1647 | ||
| 1648 | userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | |
| 1649 | if (!userinfo) | |
| 1650 | { | |
| 1651 | return g_strdup(""); | |
| 1652 | } | |
| 1653 | ||
| 1654 | display_name = g_hash_table_lookup(userinfo, "DisplayName"); | |
| 1655 | g_assert(display_name != NULL); | |
| 1656 | ||
| 1657 | return g_strdup(display_name); | |
| 1658 | } | |
| 1659 | ||
| 1660 | /** | |
| 1661 | * Obtain the tooltip text for a buddy. | |
| 1662 | * | |
| 1663 | * @param buddy Buddy to obtain tooltip text on. | |
| 1664 | * @param user_info Variable modified to have the tooltip text. | |
| 1665 | * @param full TRUE if should obtain full tooltip text. | |
| 1666 | * | |
| 1667 | */ | |
| 16324 | 1668 | static void msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full) |
| 16322 | 1669 | { |
| 1670 | g_return_if_fail(buddy != NULL); | |
| 1671 | g_return_if_fail(user_info != NULL); | |
| 1672 | ||
| 16324 | 1673 | if (PURPLE_BUDDY_IS_ONLINE(buddy)) |
| 16322 | 1674 | { |
| 1675 | MsimSession *session; | |
| 1676 | GHashTable *userinfo; | |
| 1677 | ||
| 1678 | session = (MsimSession*)buddy->account->gc->proto_data; | |
| 1679 | ||
| 1680 | g_assert(MSIM_SESSION_VALID(session)); | |
| 1681 | g_assert(session->user_lookup_cache); | |
| 1682 | ||
| 1683 | userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | |
| 1684 | ||
| 1685 | g_assert(userinfo != NULL); | |
| 1686 | ||
| 1687 | // TODO: if (full), do something different | |
| 16324 | 1688 | purple_notify_user_info_add_pair(user_info, "User ID", g_hash_table_lookup(userinfo, "UserID")); |
| 1689 | purple_notify_user_info_add_pair(user_info, "Display Name", g_hash_table_lookup(userinfo, "DisplayName")); | |
| 1690 | purple_notify_user_info_add_pair(user_info, "User Name", g_hash_table_lookup(userinfo, "UserName")); | |
| 1691 | purple_notify_user_info_add_pair(user_info, "Total Friends", g_hash_table_lookup(userinfo, "TotalFriends")); | |
| 1692 | purple_notify_user_info_add_pair(user_info, "Song", | |
| 16322 | 1693 | g_strdup_printf("%s - %s", |
| 1694 | (gchar*)g_hash_table_lookup(userinfo, "BandName"), | |
| 1695 | (gchar*)g_hash_table_lookup(userinfo, "SongName"))); | |
| 1696 | } | |
| 1697 | } | |
| 1698 | ||
| 16324 | 1699 | /** Callbacks called by Purple, to access this plugin. */ |
| 1700 | static PurplePluginProtocolInfo prpl_info = | |
| 16322 | 1701 | { |
| 1702 | OPT_PROTO_MAIL_CHECK,/* options - TODO: myspace will notify of mail */ | |
| 1703 | NULL, /* user_splits */ | |
| 1704 | NULL, /* protocol_options */ | |
| 1705 | NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */ | |
| 1706 | msim_list_icon, /* list_icon */ | |
| 1707 | NULL, /* list_emblems */ | |
| 1708 | msim_status_text, /* status_text */ | |
| 1709 | msim_tooltip_text, /* tooltip_text */ | |
| 1710 | msim_status_types, /* status_types */ | |
| 1711 | NULL, /* blist_node_menu */ | |
| 1712 | NULL, /* chat_info */ | |
| 1713 | NULL, /* chat_info_defaults */ | |
| 1714 | msim_login, /* login */ | |
| 1715 | msim_close, /* close */ | |
| 1716 | msim_send_im, /* send_im */ | |
| 1717 | NULL, /* set_info */ | |
| 1718 | NULL, /* send_typing */ | |
| 1719 | NULL, /* get_info */ | |
| 1720 | NULL, /* set_away */ | |
| 1721 | NULL, /* set_idle */ | |
| 1722 | NULL, /* change_passwd */ | |
| 1723 | NULL, /* add_buddy */ | |
| 1724 | NULL, /* add_buddies */ | |
| 1725 | NULL, /* remove_buddy */ | |
| 1726 | NULL, /* remove_buddies */ | |
| 1727 | NULL, /* add_permit */ | |
| 1728 | NULL, /* add_deny */ | |
| 1729 | NULL, /* rem_permit */ | |
| 1730 | NULL, /* rem_deny */ | |
| 1731 | NULL, /* set_permit_deny */ | |
| 1732 | NULL, /* join_chat */ | |
| 1733 | NULL, /* reject chat invite */ | |
| 1734 | NULL, /* get_chat_name */ | |
| 1735 | NULL, /* chat_invite */ | |
| 1736 | NULL, /* chat_leave */ | |
| 1737 | NULL, /* chat_whisper */ | |
| 1738 | NULL, /* chat_send */ | |
| 1739 | NULL, /* keepalive */ | |
| 1740 | NULL, /* register_user */ | |
| 1741 | NULL, /* get_cb_info */ | |
| 1742 | NULL, /* get_cb_away */ | |
| 1743 | NULL, /* alias_buddy */ | |
| 1744 | NULL, /* group_buddy */ | |
| 1745 | NULL, /* rename_group */ | |
| 1746 | NULL, /* buddy_free */ | |
| 1747 | NULL, /* convo_closed */ | |
| 1748 | NULL, /* normalize */ | |
| 1749 | NULL, /* set_buddy_icon */ | |
| 1750 | NULL, /* remove_group */ | |
| 1751 | NULL, /* get_cb_real_name */ | |
| 1752 | NULL, /* set_chat_topic */ | |
| 1753 | NULL, /* find_blist_chat */ | |
| 1754 | NULL, /* roomlist_get_list */ | |
| 1755 | NULL, /* roomlist_cancel */ | |
| 1756 | NULL, /* roomlist_expand_category */ | |
| 1757 | NULL, /* can_receive_file */ | |
| 1758 | NULL, /* send_file */ | |
| 1759 | NULL, /* new_xfer */ | |
| 1760 | NULL, /* offline_message */ | |
| 1761 | NULL, /* whiteboard_prpl_ops */ | |
| 1762 | NULL, /* send_raw */ | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1763 | NULL, /* roomlist_room_serialize */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1764 | NULL, /* _purple_reserved1 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1765 | NULL, /* _purple_reserved2 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1766 | NULL, /* _purple_reserved3 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1767 | NULL /* _purple_reserved4 */ |
| 16322 | 1768 | }; |
| 1769 | ||
| 1770 | ||
| 1771 | ||
| 1772 | /** Based on MSN's plugin info comments. */ | |
| 16324 | 1773 | static PurplePluginInfo info = |
| 16322 | 1774 | { |
| 16324 | 1775 | PURPLE_PLUGIN_MAGIC, |
| 1776 | PURPLE_MAJOR_VERSION, | |
| 1777 | PURPLE_MINOR_VERSION, | |
| 1778 | PURPLE_PLUGIN_PROTOCOL, /**< type */ | |
| 16322 | 1779 | NULL, /**< ui_requirement */ |
| 1780 | 0, /**< flags */ | |
| 1781 | NULL, /**< dependencies */ | |
| 16324 | 1782 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 16322 | 1783 | |
| 1784 | "prpl-myspace", /**< id */ | |
| 1785 | "MySpaceIM", /**< name */ | |
| 1786 | "0.4", /**< version */ | |
| 1787 | /** summary */ | |
| 1788 | "MySpaceIM Protocol Plugin", | |
| 1789 | /** description */ | |
| 1790 | "MySpaceIM Protocol Plugin", | |
| 1791 | "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */ | |
| 1792 | "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */ | |
| 1793 | ||
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
1794 | msim_load, /**< load */ |
| 16322 | 1795 | NULL, /**< unload */ |
| 1796 | NULL, /**< destroy */ | |
| 1797 | NULL, /**< ui_info */ | |
| 1798 | &prpl_info, /**< extra_info */ | |
| 1799 | NULL, /**< prefs_info */ | |
| 1800 | ||
| 1801 | /* msim_actions */ | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1802 | NULL, |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1803 | |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1804 | NULL, /**< reserved1 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1805 | NULL, /**< reserved2 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1806 | NULL, /**< reserved3 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1807 | NULL /**< reserved4 */ |
| 16322 | 1808 | }; |
| 1809 | ||
| 1810 | ||
| 16324 | 1811 | PURPLE_INIT_PLUGIN(myspace, init_plugin, info); |