Sun, 03 Jun 2007 05:50:11 +0000
Change MsimSession.sesskey to an integer (used to be a string), now that
we have MsimMessage to handle parsing/packing integer fields for us.
| 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 | * |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
9 | * Code also drawn from mockprpl: |
| 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 | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
36 | #include "message.h" |
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
37 | #include "persist.h" |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
38 | #include "myspace.h" |
| 16322 | 39 | |
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
40 | /** |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
41 | * Load the plugin. |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
42 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
43 | gboolean msim_load(PurplePlugin *plugin) |
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
44 | { |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
45 | #ifdef MSIM_USE_PURPLE_RC4 |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
46 | /* 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
|
47 | 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
|
48 | { |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
49 | purple_debug_error("msim", "compiled with MSIM_USE_PURPLE_RC4 but rc4 not in libpurple - not loading MySpaceIM plugin!\n"); |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
50 | purple_notify_error(plugin, _("Missing Cipher"), |
|
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
51 | _("The RC4 cipher could not be found"), |
|
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
52 | _("Recompile without MSIM_USE_PURPLE_RC4, or upgrade " |
|
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
53 | "to a libpurple with RC4 support (>= 2.0.1). MySpaceIM " |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
54 | "plugin will not be loaded.")); |
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
55 | return FALSE; |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
56 | } |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
57 | #endif |
|
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
58 | return TRUE; |
| 16322 | 59 | } |
| 60 | ||
| 61 | /** | |
| 62 | * Get possible user status types. Based on mockprpl. | |
| 63 | * | |
| 64 | * @return GList of status types. | |
| 65 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
66 | GList *msim_status_types(PurpleAccount *acct) |
| 16322 | 67 | { |
| 68 | GList *types; | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
69 | PurpleStatusType *status; |
| 16322 | 70 | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
71 | purple_debug_info("myspace", "returning status types\n"); |
| 16322 | 72 | |
| 73 | types = NULL; | |
| 74 | ||
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
75 | /* TODO: Fix these: |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
76 | * |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
77 | * g_log: purple_presence_get_active_status: assertion `presence != NULL' failed |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
78 | * g_log: purple_status_get_name: assertion `status != NULL' failed |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
79 | * [...] |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
80 | * |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
81 | * and |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
82 | * g_log: purple_presence_set_status_active: assertion `status != NULL' failed |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
83 | * [...] |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
84 | */ |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
85 | status = purple_status_type_new_full(PURPLE_STATUS_AVAILABLE, NULL, NULL, FALSE, TRUE, FALSE); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
86 | types = g_list_append(types, status); |
| 16322 | 87 | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
88 | status = purple_status_type_new_full(PURPLE_STATUS_AWAY, NULL, NULL, FALSE, TRUE, FALSE); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
89 | types = g_list_append(types, status); |
| 16322 | 90 | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
91 | status = purple_status_type_new_full(PURPLE_STATUS_OFFLINE, NULL, NULL, FALSE, TRUE, FALSE); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
92 | types = g_list_append(types, status); |
| 16322 | 93 | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
94 | status = purple_status_type_new_full(PURPLE_STATUS_INVISIBLE, NULL, NULL, FALSE, TRUE, FALSE); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
95 | types = g_list_append(types, status); |
| 16322 | 96 | |
| 97 | return types; | |
| 98 | } | |
| 99 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
100 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
101 | * 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
|
102 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
103 | * @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
|
104 | * @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
|
105 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
106 | * @return The base icon name string. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
107 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
108 | const gchar *msim_list_icon(PurpleAccount *acct, PurpleBuddy *buddy) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
109 | { |
|
17900
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
110 | /* Use a MySpace icon submitted by hbons submitted one at |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
111 | * http://developer.pidgin.im/wiki/MySpaceIM. */ |
|
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
|
112 | return "myspace"; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
113 | } |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
114 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
115 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
116 | * Unescape a protocol message. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
117 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
118 | * @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
|
119 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
120 | gchar *msim_unescape(const gchar *msg) |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
121 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
122 | /* 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
|
123 | gchar *tmp, *ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
124 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
125 | 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
|
126 | 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
|
127 | g_free(tmp); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
128 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
129 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
130 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
131 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
132 | * Escape a protocol message. |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
133 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
134 | * @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
|
135 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
136 | gchar *msim_escape(const gchar *msg) |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
137 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
138 | /* 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
|
139 | gchar *tmp, *ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
140 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
141 | 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
|
142 | 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
|
143 | g_free(tmp); |
|
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 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
146 | } |
|
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 | /** |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
149 | * 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
|
150 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
151 | * @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
|
152 | * @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
|
153 | * @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
|
154 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
155 | * @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
|
156 | * 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
|
157 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
158 | * 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
|
159 | * 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
|
160 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
161 | */ |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
162 | gchar *str_replace(const gchar *str, const gchar *old, const gchar *new) |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
163 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
164 | char **items; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
165 | char *ret; |
|
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 | 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
|
168 | 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
|
169 | g_free(items); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
170 | return ret; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
171 | } |
|
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 | |
|
17902
8e0b1d066efb
Add partial implementation of MsimMessage (not used anywhere yet).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17901
diff
changeset
|
174 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
175 | |
|
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
|
176 | #ifdef MSIM_DEBUG_MSG |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
177 | void print_hash_item(gpointer key, gpointer value, gpointer user_data) |
| 16322 | 178 | { |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
179 | purple_debug_info("msim", "%s=%s\n", (char *)key, (char *)value); |
| 16322 | 180 | } |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
181 | #endif |
| 16322 | 182 | |
| 183 | /** | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
184 | * Send raw data to the server. |
| 16322 | 185 | * |
| 186 | * @param session | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
187 | * @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
|
188 | * |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
189 | * @return TRUE if succeeded, FALSE if not. |
| 16322 | 190 | * |
| 191 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
192 | gboolean msim_send_raw(MsimSession *session, const gchar *msg) |
| 16322 | 193 | { |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
194 | int total_bytes_sent, total_bytes; |
|
17897
8f844632f315
Implement msim_pack(), msim_sendh(), msim_send().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17896
diff
changeset
|
195 | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
196 | purple_debug_info("msim", "msim_send_raw: writing <%s>\n", msg); |
| 16322 | 197 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
198 | 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
|
199 | 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
|
200 | |
| 16322 | 201 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
202 | /* 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
|
203 | total_bytes_sent = 0; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
204 | total_bytes = strlen(msg); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
205 | do |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
206 | { |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
207 | int bytes_sent; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
208 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
209 | 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
|
210 | total_bytes - total_bytes_sent, 0); |
| 16322 | 211 | |
|
16337
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
212 | if (bytes_sent < 0) |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
213 | { |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
214 | 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
|
215 | msg, g_strerror(errno)); |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
216 | return FALSE; |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
217 | } |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
218 | 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
|
219 | |
|
ba0ded418e6a
Add escaping and unescaping functions (for /1 and /2).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16335
diff
changeset
|
220 | } 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
|
221 | return TRUE; |
| 16322 | 222 | } |
| 223 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
224 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
225 | * 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
|
226 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
227 | * @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
|
228 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
229 | void msim_login(PurpleAccount *acct) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
230 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
231 | PurpleConnection *gc; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
232 | const char *host; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
233 | int port; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
234 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
235 | g_return_if_fail(acct != NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
236 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
237 | 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
|
238 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
239 | gc = purple_account_get_connection(acct); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
240 | 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
|
241 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
242 | /* 1. connect to server */ |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
243 | purple_connection_update_progress(gc, _("Connecting"), |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
244 | 0, /* which connection step this is */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
245 | 4); /* total number of steps */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
246 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
247 | 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
|
248 | port = purple_account_get_int(acct, "port", MSIM_PORT); |
|
17900
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
249 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
250 | /* From purple.sf.net/api: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
251 | * """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
|
252 | * "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
|
253 | * whether through a proxy or not.""" */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
254 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
255 | /* Calls msim_connect_cb when connected. */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
256 | 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
|
257 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
258 | /* 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
|
259 | * working port and try that first next time. */ |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
260 | purple_connection_error(gc, _("Couldn't create socket")); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
261 | return; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
262 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
263 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
264 | } |
| 16322 | 265 | /** |
| 266 | * Process a login challenge, sending a response. | |
| 267 | * | |
| 268 | * @param session | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
269 | * @param msg Login challenge message. |
| 16322 | 270 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
271 | * @return TRUE if successful, FALSE if not |
| 16322 | 272 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
273 | gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg) |
| 16322 | 274 | { |
| 16324 | 275 | PurpleAccount *account; |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
276 | gchar *response; |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
277 | guint response_len; |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
278 | gchar *nc; |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
279 | gsize nc_len; |
| 16322 | 280 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
281 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
282 | g_return_val_if_fail(msg != NULL, FALSE); |
| 16322 | 283 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
284 | g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE); |
| 16322 | 285 | |
| 286 | account = session->account; | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
287 | |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
288 | g_return_val_if_fail(account != NULL, FALSE); |
| 16322 | 289 | |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
290 | purple_connection_update_progress(session->gc, _("Reading challenge"), 1, 4); |
| 16322 | 291 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
292 | purple_debug_info("msim", "nc is %d bytes, decoded\n", nc_len); |
| 16322 | 293 | |
| 294 | if (nc_len != 0x40) | |
| 295 | { | |
| 16324 | 296 | purple_debug_info("msim", "bad nc length: %x != 0x40\n", nc_len); |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
297 | purple_connection_error(session->gc, _("Unexpected challenge length from server")); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
298 | return FALSE; |
| 16322 | 299 | } |
| 300 | ||
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
301 | purple_connection_update_progress(session->gc, _("Logging in"), 2, 4); |
| 16322 | 302 | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
303 | response = msim_compute_login_response(nc, account->username, account->password, &response_len); |
| 16322 | 304 | |
| 305 | g_free(nc); | |
| 306 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
307 | return msim_send(session, |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
308 | "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
309 | "username", MSIM_TYPE_STRING, g_strdup(account->username), |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
310 | /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */ |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
311 | "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
312 | "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
313 | "reconn", MSIM_TYPE_INTEGER, 0, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
314 | "status", MSIM_TYPE_INTEGER, 100, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
315 | "id", MSIM_TYPE_INTEGER, 1, |
|
17898
d08d6d221276
Incomplete attempt at using msim_send() instead of msim_send_raw().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17897
diff
changeset
|
316 | NULL); |
| 16322 | 317 | } |
| 318 | ||
|
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
|
319 | #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
|
320 | /* 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
|
321 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
322 | /* |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
323 | 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
|
324 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
325 | 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
|
326 | 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
|
327 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
328 | 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
|
329 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
330 | $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
|
331 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
332 | 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
|
333 | 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
|
334 | 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
|
335 | (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
|
336 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
337 | 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
|
338 | 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
|
339 | 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
|
340 | 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
|
341 | |
|
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 | 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
|
343 | 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
|
344 | 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
|
345 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
346 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
347 | 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
|
348 | */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
349 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
350 | #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
|
351 | #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
|
352 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
353 | /* 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
|
354 | 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
|
355 | 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
|
356 | 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
|
357 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
358 | 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
|
359 | 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
|
360 | */ |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
361 | |
|
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 | 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
|
363 | 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
|
364 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
365 | 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
|
366 | 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
|
367 | 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
|
368 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
369 | 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
|
370 | 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
|
371 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
372 | 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
|
373 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
374 | 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
|
375 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
376 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
377 | 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
|
378 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
379 | 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
|
380 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
381 | 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
|
382 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
383 | 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
|
384 | 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
|
385 | 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
|
386 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
387 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
388 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
389 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
390 | 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
|
391 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
392 | 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
|
393 | 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
|
394 | 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
|
395 | 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
|
396 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
397 | /* 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
|
398 | 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
|
399 | 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
|
400 | 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
|
401 | 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
|
402 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
403 | 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
|
404 | { |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
405 | 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
|
406 | 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
|
407 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
408 | 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
|
409 | 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
|
410 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
411 | 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
|
412 | 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
|
413 | 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
|
414 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
415 | 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
|
416 | 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
|
417 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
418 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
419 | /* 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
|
420 | 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
|
421 | 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
|
422 | } |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
423 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
424 | #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
|
425 | |
|
66984c1aac79
Re-add RC4 code from Samba, whose use is enabled by not defining
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17890
diff
changeset
|
426 | |
| 16322 | 427 | /** |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
428 | * 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
|
429 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
430 | * @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
|
431 | * @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
|
432 | * @param password User's cleartext password. |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
433 | * @param response_len Will be written with response length. |
| 16322 | 434 | * |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
435 | * @return Binary login challenge response, ready to send to the server. Must be g_free()'d |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
436 | * when finished. |
| 16322 | 437 | */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
438 | gchar *msim_compute_login_response(gchar nonce[2 * NONCE_SIZE], |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
439 | gchar *email, gchar *password, guint *response_len) |
| 16322 | 440 | { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
441 | PurpleCipherContext *key_context; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
442 | 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
|
443 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
444 | 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
|
445 | #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
|
446 | 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
|
447 | #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
|
448 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
449 | guchar hash_pw[HASH_SIZE]; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
450 | guchar key[HASH_SIZE]; |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
451 | gchar *password_utf16le; |
|
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
452 | guchar *data; |
|
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
453 | guchar *data_out; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
454 | 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
|
455 | gsize conv_bytes_read, conv_bytes_written; |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
456 | 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
|
457 | #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
|
458 | int i; |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
459 | #endif |
| 16322 | 460 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
461 | /* 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
|
462 | 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
|
463 | conv_error = NULL; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
464 | 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
|
465 | &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
|
466 | 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
|
467 | if (conv_error != NULL) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
468 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
469 | purple_debug_error("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
470 | "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
|
471 | conv_error->message); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
472 | g_error_free(conv_error); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
473 | } |
| 16322 | 474 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
475 | /* Compute password hash */ |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
476 | purple_cipher_digest_region("sha1", (guchar *)password_utf16le, |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
477 | 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
|
478 | g_free(password_utf16le); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
479 | |
|
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
|
480 | #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
|
481 | purple_debug_info("msim", "pwhash = "); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
482 | 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
|
483 | 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
|
484 | purple_debug_info("msim", "\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
485 | #endif |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
486 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
487 | /* key = sha1(sha1(pw) + nonce2) */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
488 | sha1 = purple_ciphers_find_cipher("sha1"); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
489 | 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
|
490 | purple_cipher_context_append(key_context, hash_pw, HASH_SIZE); |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
491 | purple_cipher_context_append(key_context, (guchar *)(nonce + NONCE_SIZE), NONCE_SIZE); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
492 | 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
|
493 | |
|
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
|
494 | #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
|
495 | purple_debug_info("msim", "key = "); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
496 | for (i = 0; i < sizeof(key); i++) |
| 16322 | 497 | { |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
498 | 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
|
499 | } |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
500 | purple_debug_info("msim", "\n"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
501 | #endif |
| 16322 | 502 | |
|
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
|
503 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
504 | rc4 = purple_cipher_context_new_by_name("rc4", NULL); |
| 16322 | 505 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
506 | /* 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
|
507 | * 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
|
508 | 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
|
509 | 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
|
510 | #endif |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
511 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
512 | /* 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
|
513 | * 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
|
514 | * 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
|
515 | * 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
|
516 | * 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
|
517 | * 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
|
518 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
519 | /* rc4 encrypt: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
520 | * nonce1+email+IP list */ |
|
17901
ecaeb5f6e531
Replacement magic numbers by symbolic constants.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17900
diff
changeset
|
521 | data_len = NONCE_SIZE + strlen(email) |
|
ecaeb5f6e531
Replacement magic numbers by symbolic constants.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17900
diff
changeset
|
522 | /* TODO: change to length of IP list */ |
|
ecaeb5f6e531
Replacement magic numbers by symbolic constants.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17900
diff
changeset
|
523 | + 25; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
524 | data = g_new0(guchar, data_len); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
525 | memcpy(data, nonce, NONCE_SIZE); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
526 | 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
|
527 | 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
|
528 | /* 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
|
529 | "\x00\x00\x00\x00\x05\x7f\x00\x00\x01\x00\x00\x00\x00\x0a\x00\x00\x40\xc0\xa8\x58\x01\xc0\xa8\x3c\x01", 25); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
530 | |
|
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
|
531 | #ifdef MSIM_USE_PURPLE_RC4 |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
532 | 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
|
533 | |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
534 | purple_cipher_context_encrypt(rc4, (const guchar *)data, |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
535 | 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
|
536 | 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
|
537 | #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
|
538 | /* 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
|
539 | 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
|
540 | 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
|
541 | 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
|
542 | 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
|
543 | 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
|
544 | #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
|
545 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
546 | 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
|
547 | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
548 | #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
549 | purple_debug_info("msim", "response=<%s>\n", 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
|
550 | #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
|
551 | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
552 | *response_len = data_out_len; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
553 | |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
554 | return (gchar *)data_out; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
555 | } |
| 16322 | 556 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
557 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
558 | * 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
|
559 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
560 | * @param gc Connection. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
561 | * @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
|
562 | * @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
|
563 | * @param flags Flags. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
564 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
565 | * @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
|
566 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
567 | * 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
|
568 | * 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
|
569 | * 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
|
570 | * 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
|
571 | * response is received from the server. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
572 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
573 | * 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
|
574 | * 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
|
575 | * immediately here. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
576 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
577 | int msim_send_im(PurpleConnection *gc, const char *who, |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
578 | const char *message, PurpleMessageFlags flags) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
579 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
580 | MsimSession *session; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
581 | 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
|
582 | send_im_cb_struct *cbinfo; |
| 16322 | 583 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
584 | 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
|
585 | 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
|
586 | 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
|
587 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
588 | 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
|
589 | from_username, who, message); |
| 16322 | 590 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
591 | session = gc->proto_data; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
592 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
593 | /* 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
|
594 | if (msim_is_userid(who)) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
595 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
596 | purple_debug_info("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
597 | "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
|
598 | 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
|
599 | return 1; |
| 16322 | 600 | } |
| 601 | ||
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
602 | /* 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
|
603 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
604 | /* 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
|
605 | 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
|
606 | cbinfo->who = g_strdup(who); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
607 | cbinfo->message = g_strdup(message); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
608 | cbinfo->flags = flags; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
609 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
610 | /* 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
|
611 | 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
|
612 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
613 | /* msim_send_im_by_userid_cb will now be called once userid is looked up */ |
| 16322 | 614 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
615 | /* 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
|
616 | * 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
|
617 | * 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
|
618 | * 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
|
619 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
620 | * 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
|
621 | * 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
|
622 | * IM windows when using this plugin: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
623 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
624 | * you@example.com: hello |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
625 | * 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
|
626 | * 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
|
627 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
628 | * 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
|
629 | * 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
|
630 | */ |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
631 | return 1; |
| 16322 | 632 | } |
| 633 | ||
| 634 | /** | |
| 635 | * Immediately send an IM to a user, by their numeric user ID. | |
| 636 | * | |
| 637 | * @param session | |
| 638 | * @param userid ASCII numeric userid. | |
| 639 | * @param message Text of message to send. | |
| 16324 | 640 | * @param flags Purple instant message flags. |
| 16322 | 641 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
642 | * @return TRUE if successful. |
| 16322 | 643 | * |
| 644 | */ | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
645 | gboolean msim_send_im_by_userid(MsimSession *session, const gchar *userid, const gchar *message, PurpleMessageFlags flags) |
| 16322 | 646 | { |
| 647 | g_return_val_if_fail(MSIM_SESSION_VALID(session), 0); | |
| 648 | g_return_val_if_fail(userid != NULL, 0); | |
| 649 | g_return_val_if_fail(msim_is_userid(userid) == TRUE, 0); | |
| 650 | g_return_val_if_fail(message != NULL, 0); | |
| 651 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
652 | return msim_send(session, |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
653 | "bm", MSIM_TYPE_INTEGER, MSIM_BM_INSTANT, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
654 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
655 | "t", MSIM_TYPE_STRING, g_strdup(userid), |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
656 | "cv", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
657 | "msg", MSIM_TYPE_STRING, g_strdup(message), |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
658 | NULL); |
| 16322 | 659 | |
| 660 | /* Not needed since sending messages to yourself is allowed by MSIM! */ | |
| 661 | /*if (strcmp(from_username, who) == 0) | |
| 16324 | 662 | serv_got_im(gc, from_username, message, PURPLE_MESSAGE_RECV, time(NULL)); |
| 16322 | 663 | */ |
| 664 | } | |
| 665 | ||
| 666 | ||
| 667 | /** | |
| 668 | * Callback called when ready to send an IM by userid (the userid has been looked up). | |
| 669 | * Calls msim_send_im_by_userid. | |
| 670 | * | |
| 671 | * @param session | |
| 672 | * @param userinfo User info message from server containing a 'body' field | |
| 673 | * with a 'UserID' key. This is where the user ID is taken from. | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
674 | * Will be destroyed after use. |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
675 | * @param data A send_im_cb_struct * of information on the IM to send. |
| 16322 | 676 | * |
| 677 | */ | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
678 | void msim_send_im_by_userid_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) |
| 16322 | 679 | { |
| 680 | send_im_cb_struct *s; | |
| 681 | gchar *userid; | |
| 682 | GHashTable *body; | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
683 | gchar *body_str; |
| 16322 | 684 | |
| 685 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 686 | g_return_if_fail(userinfo != NULL); | |
| 687 | ||
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
688 | body_str = msim_msg_get_string(userinfo, "body"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
689 | body = msim_parse_body(body_str); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
690 | g_free(body_str); |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
691 | g_return_if_fail(body != NULL); |
| 16322 | 692 | |
| 693 | userid = g_hash_table_lookup(body, "UserID"); | |
| 694 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
695 | s = (send_im_cb_struct *)data; |
| 16322 | 696 | msim_send_im_by_userid(session, userid, s->message, s->flags); |
| 697 | ||
| 698 | g_hash_table_destroy(body); | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
699 | /* g_hash_table_destroy(userinfo); */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
700 | /* TODO: do we need to free userinfo here? */ |
|
17927
ba45a8cbae1b
Fix double-free crash when sending messages (typo). Works again.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17924
diff
changeset
|
701 | /* msim_msg_free(userinfo); */ |
| 16322 | 702 | g_free(s->message); |
| 703 | g_free(s->who); | |
| 704 | } | |
| 705 | ||
| 706 | /** | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
707 | * 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
|
708 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
709 | * @param session |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
710 | * @param userinfo Message from server on user's info, containing UserName. |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
711 | * @param data A gchar * of the incoming instant message's text. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
712 | */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
713 | void msim_incoming_im_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
714 | { |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
715 | gchar *msg, *username, *body_str; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
716 | GHashTable *body; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
717 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
718 | 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
|
719 | g_return_if_fail(userinfo != NULL); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
720 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
721 | body_str = msim_msg_get_string(userinfo, "body"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
722 | body = msim_parse_body(body_str); |
|
17927
ba45a8cbae1b
Fix double-free crash when sending messages (typo). Works again.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17924
diff
changeset
|
723 | g_free(body_str); |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
724 | g_return_if_fail(body != NULL); |
|
16333
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 | 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
|
727 | |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
728 | msg = (gchar *)data; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
729 | 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
|
730 | |
|
17927
ba45a8cbae1b
Fix double-free crash when sending messages (typo). Works again.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17924
diff
changeset
|
731 | /* msim_msg_free(userinfo); */ /* TODO: Should we? */ |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
732 | g_hash_table_destroy(body); |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
733 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
734 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
735 | /** |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
736 | * Handle an incoming instant message. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
737 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
738 | * @param session The session |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
739 | * @param msg Message from the server, containing 'f' (userid from) and 'msg'. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
740 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
741 | * @return TRUE if successful. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
742 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
743 | gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
744 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
745 | gchar *userid; |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
746 | gchar *msg_text; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
747 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
748 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
749 | g_return_val_if_fail(msg != NULL, FALSE); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
750 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
751 | /* TODO: where freed? */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
752 | userid = msim_msg_get_string(msg, "f"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
753 | msg_text = msim_msg_get_string(msg, "msg"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
754 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
755 | purple_debug_info("msim", |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
756 | "msim_incoming_im: got msg <%s> from <%s>, resolving username\n", |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
757 | msg_text, userid); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
758 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
759 | msim_lookup_user(session, userid, msim_incoming_im_cb, msg_text); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
760 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
761 | return TRUE; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
762 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
763 | |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
764 | /** |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
765 | * Handle an incoming action message. |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
766 | * |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
767 | * @param session |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
768 | * @param msg |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
769 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
770 | * @return TRUE if successful. |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
771 | * |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
772 | * INCOMPLETE |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
773 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
774 | gboolean msim_incoming_action(MsimSession *session, MsimMessage *msg) |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
775 | { |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
776 | /* TODO: process */ |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
777 | purple_debug_info("msim", "msim_incoming_action: action <%s> from <%d>\n", |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
778 | msim_msg_get_string(msg, "msg"), msim_msg_get_integer(msg, "f")); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
779 | |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
780 | return FALSE; |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
781 | } |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
782 | |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
783 | /** |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
784 | * Handle when our user starts or stops typing to another user. |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
785 | * |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
786 | * @param gc |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
787 | * @param name The buddy name to which our user is typing to |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
788 | * @param state PURPLE_TYPING, PURPLE_TYPED, PURPLE_NOT_TYPING |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
789 | * |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
790 | * NOT CURRENTLY USED OR COMPLETE |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
791 | */ |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
792 | unsigned int msim_send_typing(PurpleConnection *gc, const char *name, PurpleTypingState state) |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
793 | { |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
794 | char *typing_str; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
795 | |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
796 | switch (state) |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
797 | { |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
798 | case PURPLE_TYPING: |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
799 | typing_str = "%typing%"; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
800 | break; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
801 | |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
802 | case PURPLE_TYPED: |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
803 | case PURPLE_NOT_TYPING: |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
804 | default: |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
805 | typing_str = "%stoptyping%"; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
806 | break; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
807 | } |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
808 | |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
809 | purple_debug_info("msim", "msim_send_typing(%s): %d\n", name, state); |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
810 | //msim_send_action(name, typing_str); |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
811 | return 0; |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
812 | } |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
813 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
814 | /** |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
815 | * Process a message. |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
816 | * |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
817 | * @param gc Connection. |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
818 | * @param msg Any message from the server. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
819 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
820 | * @return TRUE if successful. FALSE if processing failed. |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
821 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
822 | gboolean msim_process(PurpleConnection *gc, MsimMessage *msg) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
823 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
824 | MsimSession *session; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
825 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
826 | g_return_val_if_fail(gc != NULL, -1); |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
827 | g_return_val_if_fail(msg != NULL, -1); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
828 | |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
829 | session = (MsimSession *)gc->proto_data; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
830 | |
|
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
|
831 | #ifdef MSIM_DEBUG_MSG |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
832 | { |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
833 | gchar *debug_msg; |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
834 | |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
835 | debug_msg = msim_msg_debug_string(msg); |
|
17929
124c360364a8
Cosmetic improvement to MsimMessage debug output.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17927
diff
changeset
|
836 | purple_debug_info("msim", "%s\n", debug_msg); |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
837 | g_free(debug_msg); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
838 | } |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
839 | #endif |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
840 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
841 | if (msim_msg_get(msg, "nc")) |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
842 | { |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
843 | return msim_login_challenge(session, msg); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
844 | } else if (msim_msg_get(msg, "sesskey")) { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
845 | |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
846 | purple_connection_update_progress(gc, _("Connected"), 3, 4); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
847 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
848 | /* Freed in msim_session_destroy */ |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
849 | session->sesskey = msim_msg_get_integer(msg, "sesskey"); |
|
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
850 | purple_debug_info("msim", "SESSKEY=<%d>\n", session->sesskey); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
851 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
852 | /* 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
|
853 | * (at least for me). */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
854 | /* Freed in msim_session_destroy */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
855 | session->userid = msim_msg_get_string(msg, "userid"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
856 | |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
857 | 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
|
858 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
859 | return TRUE; |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
860 | } else if (msim_msg_get(msg, "bm")) { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
861 | guint bm; |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
862 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
863 | bm = msim_msg_get_integer(msg, "bm"); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
864 | switch (bm) |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
865 | { |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
866 | case MSIM_BM_STATUS: |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
867 | return msim_status(session, msg); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
868 | case MSIM_BM_INSTANT: |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
869 | return msim_incoming_im(session, msg); |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
870 | case MSIM_BM_ACTION: |
|
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
871 | return msim_incoming_action(session, msg); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
872 | default: |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
873 | /* 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
|
874 | * purposes during development. */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
875 | return msim_incoming_im(session, msg); |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
876 | } |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
877 | } else if (msim_msg_get(msg, "rid")) { |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
878 | return msim_process_reply(session, msg); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
879 | } else if (msim_msg_get(msg, "error")) { |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
880 | return msim_error(session, msg); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
881 | } else if (msim_msg_get(msg, "ka")) { |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
882 | purple_debug_info("msim", "msim_process: got keep alive\n"); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
883 | return TRUE; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
884 | } else { |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
885 | /* 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
|
886 | * 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
|
887 | * 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
|
888 | purple_debug_info("msim", "msim_process: unhandled message\n"); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
889 | return FALSE; |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
890 | } |
|
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
891 | } |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
892 | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
893 | /** |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
894 | * Process a persistance message reply from the server. |
| 16322 | 895 | * |
| 896 | * @param session | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
897 | * @param msg Message reply from server. |
| 16322 | 898 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
899 | * @return TRUE if successful. |
| 16322 | 900 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
901 | gboolean msim_process_reply(MsimSession *session, MsimMessage *msg) |
| 16322 | 902 | { |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
903 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
904 | g_return_val_if_fail(msg != NULL, FALSE); |
| 16322 | 905 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
906 | if (msim_msg_get(msg, "rid")) /* msim_lookup_user sets callback for here */ |
| 16322 | 907 | { |
| 908 | MSIM_USER_LOOKUP_CB cb; | |
| 909 | gpointer data; | |
| 910 | guint rid; | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
911 | GHashTable *body; |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
912 | gchar *username, *body_str; |
| 16322 | 913 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
914 | rid = msim_msg_get_integer(msg, "rid"); |
| 16322 | 915 | |
| 916 | /* Cache the user info. Currently, the GHashTable of user info in | |
| 917 | * this cache never expires so is never freed. TODO: expire and destroy | |
| 918 | * | |
| 919 | * Some information never changes (username->userid map), some does. | |
| 920 | * TODO: Cache what doesn't change only | |
| 921 | */ | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
922 | body_str = msim_msg_get_string(msg, "body"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
923 | body = msim_parse_body(body_str); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
924 | g_free(body_str); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
925 | |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
926 | /* TODO: implement a better hash-like interface, and use it. */ |
| 16322 | 927 | username = g_hash_table_lookup(body, "UserName"); |
| 928 | if (username) | |
| 929 | { | |
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
930 | /* TODO: permanently associated with blist item, if in buddy in blist, |
|
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
931 | * See purple_blist_node_set_int(). */ |
| 16322 | 932 | g_hash_table_insert(session->user_lookup_cache, g_strdup(username), body); |
| 933 | } else { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
934 | purple_debug_info("msim", |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
935 | "msim_process_reply: not caching body, no UserName\n"); |
| 16322 | 936 | } |
| 937 | ||
| 938 | /* If a callback is registered for this userid lookup, call it. */ | |
| 939 | cb = g_hash_table_lookup(session->user_lookup_cb, GUINT_TO_POINTER(rid)); | |
| 940 | data = g_hash_table_lookup(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); | |
| 941 | ||
| 942 | if (cb) | |
| 943 | { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
944 | 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
|
945 | "msim_process_body: calling callback now\n"); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
946 | /* Clone message, so that the callback 'cb' can use it (needs to free it also). */ |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
947 | cb(session, msim_msg_clone(msg), data); |
| 16322 | 948 | g_hash_table_remove(session->user_lookup_cb, GUINT_TO_POINTER(rid)); |
| 949 | g_hash_table_remove(session->user_lookup_cb_data, GUINT_TO_POINTER(rid)); | |
| 950 | } else { | |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
951 | 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
|
952 | "msim_process_body: no callback for rid %d\n", rid); |
| 16322 | 953 | } |
| 954 | } | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
955 | |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
956 | return TRUE; |
| 16322 | 957 | } |
| 958 | ||
| 959 | /** | |
| 960 | * Handle an error from the server. | |
| 961 | * | |
| 962 | * @param session | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
963 | * @param msg The message. |
| 16322 | 964 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
965 | * @return TRUE if successfully reported error. |
| 16322 | 966 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
967 | gboolean msim_error(MsimSession *session, MsimMessage *msg) |
| 16322 | 968 | { |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
969 | gchar *errmsg, *full_errmsg; |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
970 | guint err; |
| 16322 | 971 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
972 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
973 | g_return_val_if_fail(msg != NULL, FALSE); |
| 16322 | 974 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
975 | err = msim_msg_get_integer(msg, "err"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
976 | errmsg = msim_msg_get_string(msg, "errmsg"); |
| 16322 | 977 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
978 | full_errmsg = g_strdup_printf(_("Protocol error, code %d: %s"), err, errmsg); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
979 | |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
980 | g_free(errmsg); |
| 16322 | 981 | |
| 16324 | 982 | purple_debug_info("msim", "msim_error: %s\n", full_errmsg); |
| 16322 | 983 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
984 | /* TODO: do something with the error # (localization of errmsg?) */ |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
985 | purple_notify_error(session->account, g_strdup(_("MySpaceIM Error")), |
| 16322 | 986 | full_errmsg, NULL); |
| 987 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
988 | /* Destroy session if fatal. */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
989 | if (msim_msg_get(msg, "fatal")) |
| 16322 | 990 | { |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
991 | purple_debug_info("msim", "fatal error, closing\n"); |
| 16324 | 992 | purple_connection_error(session->gc, full_errmsg); |
| 16322 | 993 | close(session->fd); |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
994 | /* Do not call msim_session_destroy(session) - called in msim_close(). */ |
| 16322 | 995 | } |
| 996 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
997 | return TRUE; |
| 16322 | 998 | } |
| 999 | ||
| 1000 | #if 0 | |
| 1001 | /* Not sure about this */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1002 | void msim_status_now(gchar *who, gpointer data) |
| 16322 | 1003 | { |
| 1004 | printf("msim_status_now: %s\n", who); | |
| 1005 | } | |
| 1006 | #endif | |
| 1007 | ||
| 1008 | /** | |
| 1009 | * Callback to update incoming status messages, after looked up username. | |
| 1010 | * | |
| 1011 | * @param session | |
| 1012 | * @param userinfo Looked up user information from server. | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1013 | * @param data gchar * status string, will be freed. |
| 16322 | 1014 | * |
| 1015 | */ | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1016 | void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) |
| 16322 | 1017 | { |
| 16324 | 1018 | PurpleBuddyList *blist; |
| 1019 | PurpleBuddy *buddy; | |
| 16322 | 1020 | GHashTable *body; |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1021 | gchar *body_str; |
| 16324 | 1022 | //PurpleStatus *status; |
| 16322 | 1023 | gchar **status_array; |
| 1024 | GList *list; | |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1025 | gchar *status_headline; |
| 16322 | 1026 | gchar *status_str; |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1027 | gint i, status_code, purple_status_code; |
| 16322 | 1028 | gchar *username; |
| 1029 | ||
| 1030 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1031 | g_return_if_fail(userinfo != NULL); | |
| 1032 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1033 | status_str = (gchar *)data; |
| 16322 | 1034 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1035 | body_str = msim_msg_get_string(userinfo, "body"); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1036 | body = msim_parse_body(body_str); |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1037 | g_free(body_str); |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1038 | g_return_if_fail(body != NULL); |
| 16322 | 1039 | |
| 1040 | username = g_hash_table_lookup(body, "UserName"); | |
| 1041 | /* Note: DisplayName doesn't seem to be resolvable. It could be displayed on | |
| 1042 | * the buddy list, if the UserID was stored along with it. */ | |
| 1043 | ||
| 1044 | if (!username) | |
| 1045 | { | |
| 16324 | 1046 | purple_debug_info("msim", "msim_status_cb: no username?!\n"); |
| 16322 | 1047 | return; |
| 1048 | } | |
| 1049 | ||
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1050 | 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
|
1051 | "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
|
1052 | username, status_str); |
| 16322 | 1053 | |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1054 | /* TODO: generic functions to split into a GList, part of MsimMessage */ |
| 16322 | 1055 | status_array = g_strsplit(status_str, "|", 0); |
| 1056 | for (list = NULL, i = 0; | |
| 1057 | status_array[i]; | |
| 1058 | i++) | |
| 1059 | { | |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1060 | /* Note: this adds the 0th ordinal too, which might not be a value |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1061 | * at all (the 0 in the 0|1|2|3... status fields, but 0 always appears blank). |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1062 | */ |
| 16322 | 1063 | list = g_list_append(list, status_array[i]); |
| 1064 | } | |
| 1065 | ||
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1066 | /* Example fields: |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1067 | * |s|0|ss|Offline |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1068 | * |s|1|ss|:-)|ls||ip|0|p|0 |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1069 | * |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1070 | * TODO: write list support in MsimMessage, and use it here. |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1071 | */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1072 | |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1073 | status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE)); |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1074 | purple_debug_info("msim", "msim_status_cb: %s's status code = %d\n", username, status_code); |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1075 | status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE); |
| 16322 | 1076 | |
| 16324 | 1077 | blist = purple_get_blist(); |
| 16322 | 1078 | |
| 1079 | /* Add buddy if not found */ | |
| 16324 | 1080 | buddy = purple_find_buddy(session->account, username); |
| 16322 | 1081 | if (!buddy) |
| 1082 | { | |
| 16324 | 1083 | /* 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
|
1084 | 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
|
1085 | "msim_status: making new buddy for %s\n", username); |
| 16324 | 1086 | buddy = purple_buddy_new(session->account, username, NULL); |
| 16322 | 1087 | |
| 1088 | /* TODO: sometimes (when click on it), buddy list disappears. Fix. */ | |
| 16324 | 1089 | purple_blist_add_buddy(buddy, NULL, NULL, NULL); |
| 16322 | 1090 | } else { |
| 16324 | 1091 | purple_debug_info("msim", "msim_status: found buddy %s\n", username); |
| 16322 | 1092 | } |
| 1093 | ||
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1094 | /* TODO: show headline */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1095 | |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1096 | /* Set user status */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1097 | switch (status_code) |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1098 | { |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1099 | case 1: purple_status_code = PURPLE_STATUS_AVAILABLE; |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1100 | break; |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1101 | case 0: purple_status_code = PURPLE_STATUS_OFFLINE; |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1102 | break; |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1103 | default: |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1104 | purple_debug_info("msim", "msim_status_cb for %s, unknown status code %d\n", |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1105 | username, status_code); |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1106 | purple_status_code = PURPLE_STATUS_AVAILABLE; |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1107 | } |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1108 | purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL); |
| 16322 | 1109 | |
| 1110 | g_strfreev(status_array); | |
| 1111 | g_list_free(list); | |
| 1112 | g_hash_table_destroy(body); | |
|
17927
ba45a8cbae1b
Fix double-free crash when sending messages (typo). Works again.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17924
diff
changeset
|
1113 | /* msim_msg_free(userinfo); TODO: right? */ |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1114 | /* Do not free status_str - it will currently be freed by g_hash_table_destroy |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1115 | * on session->user_lookup_cb_data. But this is questionable (TODO: unask) since |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1116 | * sometimes user_lookup_cb_data stores integers in gpointers, and sometimes |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1117 | * real gpointers that need to be freed, like our status_str. |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1118 | */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1119 | /* g_free(status_str); */ |
| 16322 | 1120 | } |
| 1121 | ||
| 1122 | /** | |
| 1123 | * Process incoming status messages. | |
| 1124 | * | |
| 1125 | * @param session | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1126 | * @param msg Status update message. |
| 16322 | 1127 | * |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1128 | * @return TRUE if successful. |
| 16322 | 1129 | */ |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1130 | gboolean msim_status(MsimSession *session, MsimMessage *msg) |
| 16322 | 1131 | { |
| 1132 | gchar *status_str; | |
| 1133 | gchar *userid; | |
| 1134 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1135 | g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1136 | g_return_val_if_fail(msg != NULL, FALSE); |
| 16322 | 1137 | |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1138 | /* TODO: free */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1139 | status_str = msim_msg_get_string(msg, "msg"); |
| 16322 | 1140 | if (!status_str) |
| 1141 | { | |
|
17901
ecaeb5f6e531
Replacement magic numbers by symbolic constants.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17900
diff
changeset
|
1142 | purple_debug_info("msim", "msim_status: bm is status but no status msg\n"); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1143 | return FALSE; |
| 16322 | 1144 | } |
| 1145 | ||
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1146 | /* TODO: free */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1147 | userid = msim_msg_get_string(msg, "f"); |
| 16322 | 1148 | if (!userid) |
| 1149 | { | |
|
17901
ecaeb5f6e531
Replacement magic numbers by symbolic constants.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17900
diff
changeset
|
1150 | purple_debug_info("msim", "msim_status: bm is status but no f field\n"); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1151 | return FALSE; |
| 16322 | 1152 | } |
| 1153 | ||
| 1154 | /* TODO: if buddies were identified on buddy list by uid, wouldn't have to lookup | |
| 1155 | * 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
|
1156 | 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
|
1157 | "msim_status: got status msg <%s> for <%s>, scheduling lookup\n", |
| 16322 | 1158 | status_str, userid); |
| 1159 | ||
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1160 | /* Actually update status, once username is obtained. |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1161 | * status_str() will currently be freed by g_hash_table_destroy() on |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1162 | * user_lookup_cb_data (TODO: this is questionable, since it can also |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1163 | * store gpointers. Fix this, and the 2 other TODOs of the same problem.) |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1164 | */ |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1165 | msim_lookup_user(session, userid, msim_status_cb, status_str); |
| 16322 | 1166 | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1167 | return TRUE; |
| 16322 | 1168 | } |
| 1169 | ||
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1170 | /** Add a buddy to user's buddy list. TODO: make work. Should receive statuses from added buddy. */ |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1171 | void msim_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1172 | { |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1173 | MsimSession *session; |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1174 | |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1175 | session = (MsimSession *)gc->proto_data; |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1176 | purple_debug_info("msim", "msim_add_buddy: want to add %s to %s\n", buddy->name, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1177 | group ? group->name : "(no group)"); |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1178 | |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1179 | if (!msim_send(session, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1180 | "addbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
1181 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1182 | /* Currently only allow numeric ID. TODO: Lookup username/email to uid. */ |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1183 | "newprofileid", MSIM_TYPE_STRING, g_strdup(buddy->name), |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1184 | "reason", MSIM_TYPE_STRING, g_strdup(""), |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1185 | NULL)) |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1186 | { |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1187 | purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("'addbuddy' command failed.")); |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1188 | return; |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1189 | } |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1190 | |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1191 | /* TODO: update blocklist */ |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1192 | |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1193 | if (!msim_send(session, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1194 | "persist", MSIM_TYPE_INTEGER, 1, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
1195 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1196 | "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_PUT, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1197 | "dsn", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_DSN, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1198 | "lid", MSIM_TYPE_INTEGER, MC_CONTACT_INFO_LID, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1199 | /* TODO: msim_send_persist, to handle all this rid business */ |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1200 | "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1201 | "body", MSIM_TYPE_STRING, |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1202 | g_strdup_printf("ContactID=%s\034" |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1203 | "GroupName=%s\034" |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1204 | "Position=1000\034" |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1205 | "Visibility=1\034" |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1206 | "NickName=\034" |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1207 | "NameSelect=0", |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1208 | buddy->name, group->name), |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1209 | NULL)) |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1210 | { |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1211 | purple_notify_error(NULL, NULL, _("Failed to add buddy"), _("persist command failed")); |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1212 | return; |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1213 | } |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1214 | } |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1215 | |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1216 | /** Remove a buddy from the user's buddy list. */ |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1217 | void msim_remove_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1218 | { |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1219 | MsimSession *session; |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1220 | |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1221 | session = (MsimSession *)gc->proto_data; |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1222 | |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1223 | if (!msim_send(session, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1224 | "delbuddy", MSIM_TYPE_BOOLEAN, TRUE, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
1225 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1226 | /* TODO: Lookup username/email to uid, currently on userid. */ |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1227 | "delprofileid", MSIM_TYPE_STRING, g_strdup(buddy->name), |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1228 | NULL)) |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1229 | { |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1230 | purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("'delbuddy' command failed")); |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1231 | return; |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1232 | } |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1233 | |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1234 | if (!msim_send(session, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1235 | "persist", MSIM_TYPE_INTEGER, 1, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
1236 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1237 | "cmd", MSIM_TYPE_INTEGER, MSIM_CMD_BIT_ACTION | MSIM_CMD_DELETE, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1238 | "dsn", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_DSN, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1239 | "lid", MSIM_TYPE_INTEGER, MD_DELETE_BUDDY_LID, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1240 | "uid", MSIM_TYPE_INTEGER, 42, /* TODO: put YOUR userid here */ |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1241 | "rid", MSIM_TYPE_INTEGER, session->next_rid++, |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1242 | "body", MSIM_TYPE_STRING, g_strdup_printf("ContactID=%s", buddy->name), |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1243 | NULL)) |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1244 | { |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1245 | purple_notify_error(NULL, NULL, _("Failed to remove buddy"), _("persist command failed")); |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1246 | return; |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1247 | } |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1248 | |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1249 | /* TODO: update blocklist */ |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1250 | } |
|
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1251 | |
| 16322 | 1252 | |
| 1253 | ||
| 1254 | /** | |
| 1255 | * Callback when input available. | |
| 1256 | * | |
| 16324 | 1257 | * @param gc_uncasted A PurpleConnection pointer. |
| 16322 | 1258 | * @param source File descriptor. |
| 16324 | 1259 | * @param cond PURPLE_INPUT_READ |
| 16322 | 1260 | * |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1261 | * Reads the input, and dispatches msim_process() to handle it. |
| 16322 | 1262 | */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1263 | void msim_input_cb(gpointer gc_uncasted, gint source, PurpleInputCondition cond) |
| 16322 | 1264 | { |
| 16324 | 1265 | PurpleConnection *gc; |
| 1266 | PurpleAccount *account; | |
| 16322 | 1267 | MsimSession *session; |
| 1268 | gchar *end; | |
| 1269 | int n; | |
| 1270 | ||
| 1271 | g_return_if_fail(gc_uncasted != NULL); | |
| 1272 | g_return_if_fail(source >= 0); /* Note: 0 is a valid fd */ | |
| 1273 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1274 | gc = (PurpleConnection *)(gc_uncasted); |
| 16324 | 1275 | account = purple_connection_get_account(gc); |
| 16322 | 1276 | session = gc->proto_data; |
| 1277 | ||
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1278 | g_return_if_fail(cond == PURPLE_INPUT_READ); |
| 16322 | 1279 | g_return_if_fail(MSIM_SESSION_VALID(session)); |
| 1280 | ||
| 1281 | /* Only can handle so much data at once... | |
| 1282 | * If this happens, try recompiling with a higher MSIM_READ_BUF_SIZE. | |
| 1283 | * Should be large enough to hold the largest protocol message. | |
| 1284 | */ | |
| 1285 | if (session->rxoff == MSIM_READ_BUF_SIZE) | |
| 1286 | { | |
| 16324 | 1287 | purple_debug_error("msim", "msim_input_cb: %d-byte read buffer full!\n", |
| 16322 | 1288 | MSIM_READ_BUF_SIZE); |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1289 | purple_connection_error(gc, _("Read buffer full")); |
| 16322 | 1290 | /* TODO: fix 100% CPU after closing */ |
| 1291 | close(source); | |
| 1292 | return; | |
| 1293 | } | |
| 1294 | ||
| 16324 | 1295 | 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
|
1296 | 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
|
1297 | MSIM_READ_BUF_SIZE - session->rxoff); |
| 16322 | 1298 | |
| 1299 | /* Read into buffer. On Win32, need recv() not read(). session->fd also holds | |
| 1300 | * the file descriptor, but it sometimes differs from the 'source' parameter. | |
| 1301 | */ | |
| 1302 | n = recv(session->fd, session->rxbuf + session->rxoff, MSIM_READ_BUF_SIZE - session->rxoff, 0); | |
| 1303 | ||
| 1304 | if (n < 0 && errno == EAGAIN) | |
| 1305 | { | |
| 1306 | return; | |
| 1307 | } | |
| 1308 | else if (n < 0) | |
| 1309 | { | |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1310 | purple_connection_error(gc, _("Read error")); |
| 16324 | 1311 | purple_debug_error("msim", "msim_input_cb: read error, ret=%d, " |
| 16322 | 1312 | "error=%s, source=%d, fd=%d (%X))\n", |
| 1313 | n, strerror(errno), source, session->fd, session->fd); | |
| 1314 | close(source); | |
| 1315 | return; | |
| 1316 | } | |
| 1317 | else if (n == 0) | |
| 1318 | { | |
| 16324 | 1319 | purple_debug_info("msim", "msim_input_cb: server disconnected\n"); |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1320 | purple_connection_error(gc, _("Server has disconnected")); |
| 16322 | 1321 | return; |
| 1322 | } | |
| 1323 | ||
| 1324 | /* Null terminate */ | |
| 1325 | session->rxbuf[session->rxoff + n] = 0; | |
| 1326 | ||
| 1327 | /* Check for embedded NULs. I don't handle them, and they shouldn't occur. */ | |
| 1328 | if (strlen(session->rxbuf + session->rxoff) != n) | |
| 1329 | { | |
| 1330 | /* Occurs after login, but it is not a null byte. */ | |
| 16324 | 1331 | 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
|
1332 | "--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
|
1333 | strlen(session->rxbuf + session->rxoff), n); |
| 16324 | 1334 | //purple_connection_error(gc, "Invalid message - null byte on input"); |
| 16322 | 1335 | return; |
| 1336 | } | |
| 1337 | ||
| 1338 | session->rxoff += n; | |
| 16324 | 1339 | purple_debug_info("msim", "msim_input_cb: read=%d\n", n); |
| 16322 | 1340 | |
|
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
|
1341 | #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
|
1342 | 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
|
1343 | #endif |
| 16322 | 1344 | |
| 1345 | /* Look for \\final\\ end markers. If found, process message. */ | |
| 1346 | while((end = strstr(session->rxbuf, MSIM_FINAL_STRING))) | |
| 1347 | { | |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1348 | MsimMessage *msg; |
| 16322 | 1349 | |
|
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
|
1350 | #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
|
1351 | 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
|
1352 | #endif |
| 16322 | 1353 | *end = 0; |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1354 | msg = msim_parse(g_strdup(session->rxbuf)); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1355 | if (!msg) |
| 16322 | 1356 | { |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1357 | 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
|
1358 | session->rxbuf); |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1359 | purple_connection_error(gc, _("Unparseable message")); |
| 16322 | 1360 | } |
| 1361 | else | |
| 1362 | { | |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1363 | /* Process message and then free it (processing function should |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1364 | * clone message if it wants to keep it afterwards.) */ |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1365 | if (!msim_process(gc, msg)) |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1366 | { |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1367 | gchar *dbs; |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1368 | |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1369 | dbs = msim_msg_debug_string(msg); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1370 | purple_debug_info("msim", "msim_input_cb: processing message failed on msg: %s\n", |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1371 | dbs); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1372 | g_free(dbs); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1373 | } |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1374 | msim_msg_free(msg); |
| 16322 | 1375 | } |
| 1376 | ||
| 1377 | /* Move remaining part of buffer to beginning. */ | |
| 1378 | session->rxoff -= strlen(session->rxbuf) + strlen(MSIM_FINAL_STRING); | |
| 1379 | memmove(session->rxbuf, end + strlen(MSIM_FINAL_STRING), | |
| 1380 | MSIM_READ_BUF_SIZE - (end + strlen(MSIM_FINAL_STRING) - session->rxbuf)); | |
| 1381 | ||
| 1382 | /* Clear end of buffer */ | |
| 1383 | //memset(end, 0, MSIM_READ_BUF_SIZE - (end - session->rxbuf)); | |
| 1384 | } | |
| 1385 | } | |
| 1386 | ||
| 1387 | /** | |
| 1388 | * Callback when connected. Sets up input handlers. | |
| 1389 | * | |
| 16324 | 1390 | * @param data A PurpleConnection pointer. |
| 16322 | 1391 | * @param source File descriptor. |
| 1392 | * @param error_message | |
| 1393 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1394 | void msim_connect_cb(gpointer data, gint source, const gchar *error_message) |
| 16322 | 1395 | { |
| 16324 | 1396 | PurpleConnection *gc; |
| 16322 | 1397 | MsimSession *session; |
| 1398 | ||
| 1399 | g_return_if_fail(data != NULL); | |
| 1400 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1401 | gc = (PurpleConnection *)data; |
| 16322 | 1402 | session = gc->proto_data; |
| 1403 | ||
| 1404 | if (source < 0) | |
| 1405 | { | |
|
17895
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1406 | purple_connection_error(gc, _("Couldn't connect to host")); |
|
6c2facc6c33b
Use _ for translations in msimprpl. See #648.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17894
diff
changeset
|
1407 | purple_connection_error(gc, g_strdup_printf(_("Couldn't connect to host: %s (%d)"), |
| 16322 | 1408 | error_message, source)); |
| 1409 | return; | |
| 1410 | } | |
| 1411 | ||
| 1412 | session->fd = source; | |
| 1413 | ||
| 16324 | 1414 | gc->inpa = purple_input_add(source, PURPLE_INPUT_READ, msim_input_cb, gc); |
| 16322 | 1415 | } |
| 1416 | ||
| 1417 | /* Session methods */ | |
| 1418 | ||
| 1419 | /** | |
| 1420 | * Create a new MSIM session. | |
| 1421 | * | |
| 1422 | * @param acct The account to create the session from. | |
| 1423 | * | |
| 1424 | * @return Pointer to a new session. Free with msim_session_destroy. | |
| 1425 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1426 | MsimSession *msim_session_new(PurpleAccount *acct) |
| 16322 | 1427 | { |
| 1428 | MsimSession *session; | |
| 1429 | ||
| 1430 | g_return_val_if_fail(acct != NULL, NULL); | |
| 1431 | ||
| 1432 | session = g_new0(MsimSession, 1); | |
| 1433 | ||
| 1434 | session->magic = MSIM_SESSION_STRUCT_MAGIC; | |
| 1435 | session->account = acct; | |
| 16324 | 1436 | session->gc = purple_account_get_connection(acct); |
| 16322 | 1437 | session->fd = -1; |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1438 | session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1439 | g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */ |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1440 | session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, |
|
17924
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1441 | g_direct_equal, NULL, g_free);/* TODO: we don't know what the values are, |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1442 | they could be integers inside gpointers |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1443 | or strings, but we free them anyway. |
|
191c78db42ae
Use MsimMessage for receiving messages everywhere, instead of GHashTable.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17910
diff
changeset
|
1444 | Figure this out, once free cache. */ |
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1445 | 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
|
1446 | g_free, (GDestroyNotify)g_hash_table_destroy); |
| 16322 | 1447 | session->rxoff = 0; |
| 1448 | 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
|
1449 | session->next_rid = 1; |
| 16322 | 1450 | |
| 1451 | return session; | |
| 1452 | } | |
| 1453 | ||
| 1454 | /** | |
| 1455 | * Free a session. | |
| 1456 | * | |
| 1457 | * @param session The session to destroy. | |
| 1458 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1459 | void msim_session_destroy(MsimSession *session) |
| 16322 | 1460 | { |
| 1461 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1462 | ||
| 1463 | session->magic = -1; | |
| 1464 | ||
| 1465 | g_free(session->rxbuf); | |
| 1466 | g_free(session->userid); | |
| 1467 | ||
| 1468 | g_free(session); | |
| 1469 | } | |
|
16333
0fdea8ad21cb
Add MySpaceIM header file and reorganize functions.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16332
diff
changeset
|
1470 | |
| 16322 | 1471 | |
| 1472 | ||
| 1473 | /** | |
| 1474 | * Close the connection. | |
| 1475 | * | |
| 1476 | * @param gc The connection. | |
| 1477 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1478 | void msim_close(PurpleConnection *gc) |
| 16322 | 1479 | { |
| 1480 | g_return_if_fail(gc != NULL); | |
|
17937
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1481 | |
|
0f30d74fcd9c
Add incomplete msim_add_buddy() implementation.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17935
diff
changeset
|
1482 | purple_debug_info("msim", "msim_close: destroying session\n"); |
| 16322 | 1483 | |
| 1484 | msim_session_destroy(gc->proto_data); | |
| 1485 | } | |
| 1486 | ||
| 1487 | ||
| 1488 | /** | |
| 1489 | * Check if a string is a userid (all numeric). | |
| 1490 | * | |
| 1491 | * @param user The user id, email, or name. | |
| 1492 | * | |
| 1493 | * @return TRUE if is userid, FALSE if not. | |
| 1494 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1495 | gboolean msim_is_userid(const gchar *user) |
| 16322 | 1496 | { |
| 1497 | g_return_val_if_fail(user != NULL, FALSE); | |
| 1498 | ||
| 1499 | return strspn(user, "0123456789") == strlen(user); | |
| 1500 | } | |
| 1501 | ||
| 1502 | /** | |
| 1503 | * Check if a string is an email address (contains an @). | |
| 1504 | * | |
| 1505 | * @param user The user id, email, or name. | |
| 1506 | * | |
| 1507 | * @return TRUE if is an email, FALSE if not. | |
| 1508 | * | |
| 1509 | * This function is not intended to be used as a generic | |
| 1510 | * means of validating email addresses, but to distinguish | |
| 1511 | * between a user represented by an email address from | |
| 1512 | * other forms of identification. | |
| 1513 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1514 | gboolean msim_is_email(const gchar *user) |
| 16322 | 1515 | { |
| 1516 | g_return_val_if_fail(user != NULL, FALSE); | |
| 1517 | ||
| 1518 | return strchr(user, '@') != NULL; | |
| 1519 | } | |
| 1520 | ||
| 1521 | ||
| 1522 | /** | |
| 1523 | * Asynchronously lookup user information, calling callback when receive result. | |
| 1524 | * | |
| 1525 | * @param session | |
| 1526 | * @param user The user id, email address, or username. | |
| 1527 | * @param cb Callback, called with user information when available. | |
| 1528 | * @param data An arbitray data pointer passed to the callback. | |
| 1529 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1530 | void msim_lookup_user(MsimSession *session, const gchar *user, MSIM_USER_LOOKUP_CB cb, gpointer data) |
| 16322 | 1531 | { |
| 1532 | gchar *field_name; | |
| 1533 | guint rid, cmd, dsn, lid; | |
| 1534 | ||
| 1535 | g_return_if_fail(MSIM_SESSION_VALID(session)); | |
| 1536 | g_return_if_fail(user != NULL); | |
| 1537 | g_return_if_fail(cb != NULL); | |
| 1538 | ||
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1539 | purple_debug_info("msim", "msim_lookup_userid: " |
|
16332
f0e987f024e0
Use g_convert for UTF-16LE conversion instead of converting manually.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16330
diff
changeset
|
1540 | "asynchronously looking up <%s>\n", user); |
| 16322 | 1541 | |
| 1542 | /* TODO: check if this user's info was cached and fresh; if so return immediately */ | |
| 1543 | #if 0 | |
| 1544 | /* If already know userid, then call callback immediately */ | |
| 1545 | cached_userid = g_hash_table_lookup(session->userid_cache, who); | |
| 1546 | if (cached_userid && !by_userid) | |
| 1547 | { | |
| 1548 | cb(cached_userid, NULL, NULL, data); | |
| 1549 | return; | |
| 1550 | } | |
| 1551 | #endif | |
| 1552 | ||
|
16335
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1553 | rid = session->next_rid; |
|
0c2b32acc27a
Replace printf() in MySpaceIM prpl with purple_debug_info().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16334
diff
changeset
|
1554 | ++session->next_rid; |
| 16322 | 1555 | |
| 1556 | /* Setup callback. Response will be associated with request using 'rid'. */ | |
| 1557 | g_hash_table_insert(session->user_lookup_cb, GUINT_TO_POINTER(rid), cb); | |
| 1558 | g_hash_table_insert(session->user_lookup_cb_data, GUINT_TO_POINTER(rid), data); | |
| 1559 | ||
| 1560 | /* Send request */ | |
| 1561 | ||
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1562 | cmd = MSIM_CMD_GET; |
| 16322 | 1563 | |
| 1564 | if (msim_is_userid(user)) | |
| 1565 | { | |
| 1566 | field_name = "UserID"; | |
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1567 | dsn = MG_MYSPACE_INFO_BY_ID_DSN; |
|
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1568 | lid = MG_MYSPACE_INFO_BY_ID_LID; |
| 16322 | 1569 | } else if (msim_is_email(user)) { |
| 1570 | field_name = "Email"; | |
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1571 | dsn = MG_MYSPACE_INFO_BY_STRING_DSN; |
|
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1572 | lid = MG_MYSPACE_INFO_BY_STRING_LID; |
| 16322 | 1573 | } else { |
| 1574 | field_name = "UserName"; | |
|
17930
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1575 | dsn = MG_MYSPACE_INFO_BY_STRING_DSN; |
|
d8908611bf64
Use symbolic constants for persist messages.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17929
diff
changeset
|
1576 | lid = MG_MYSPACE_INFO_BY_STRING_LID; |
| 16322 | 1577 | } |
| 1578 | ||
| 1579 | ||
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1580 | g_return_if_fail(msim_send(session, |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1581 | "persist", MSIM_TYPE_INTEGER, 1, |
|
17941
cdc104d92cdf
Change MsimSession.sesskey to an integer (used to be a string), now that
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17940
diff
changeset
|
1582 | "sesskey", MSIM_TYPE_INTEGER, session->sesskey, |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1583 | "cmd", MSIM_TYPE_INTEGER, 1, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1584 | "dsn", MSIM_TYPE_INTEGER, dsn, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1585 | "uid", MSIM_TYPE_STRING, g_strdup(session->userid), |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1586 | "lid", MSIM_TYPE_INTEGER, lid, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1587 | "rid", MSIM_TYPE_INTEGER, rid, |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1588 | /* TODO: dictionary field type */ |
|
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1589 | "body", MSIM_TYPE_STRING, g_strdup_printf("%s=%s", field_name, user), |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1590 | NULL)); |
| 16322 | 1591 | } |
| 1592 | ||
| 1593 | ||
| 1594 | /** | |
| 1595 | * Obtain the status text for a buddy. | |
| 1596 | * | |
| 1597 | * @param buddy The buddy to obtain status text for. | |
| 1598 | * | |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1599 | * @return Status text, or NULL if error. |
| 16322 | 1600 | * |
| 1601 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1602 | char *msim_status_text(PurpleBuddy *buddy) |
| 16322 | 1603 | { |
| 1604 | MsimSession *session; | |
| 1605 | GHashTable *userinfo; | |
| 1606 | gchar *display_name; | |
| 1607 | ||
| 1608 | g_return_val_if_fail(buddy != NULL, NULL); | |
| 1609 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1610 | session = (MsimSession *)buddy->account->gc->proto_data; |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1611 | g_return_val_if_fail(MSIM_SESSION_VALID(session), NULL); |
|
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1612 | g_return_val_if_fail(session->user_lookup_cache != NULL, NULL); |
| 16322 | 1613 | |
| 1614 | userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | |
| 1615 | if (!userinfo) | |
| 1616 | { | |
| 1617 | return g_strdup(""); | |
| 1618 | } | |
| 1619 | ||
| 1620 | display_name = g_hash_table_lookup(userinfo, "DisplayName"); | |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1621 | g_return_val_if_fail(display_name != NULL, NULL); |
| 16322 | 1622 | |
| 1623 | return g_strdup(display_name); | |
| 1624 | } | |
| 1625 | ||
| 1626 | /** | |
| 1627 | * Obtain the tooltip text for a buddy. | |
| 1628 | * | |
| 1629 | * @param buddy Buddy to obtain tooltip text on. | |
| 1630 | * @param user_info Variable modified to have the tooltip text. | |
| 1631 | * @param full TRUE if should obtain full tooltip text. | |
| 1632 | * | |
| 1633 | */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1634 | void msim_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full) |
| 16322 | 1635 | { |
| 1636 | g_return_if_fail(buddy != NULL); | |
| 1637 | g_return_if_fail(user_info != NULL); | |
| 1638 | ||
| 16324 | 1639 | if (PURPLE_BUDDY_IS_ONLINE(buddy)) |
| 16322 | 1640 | { |
| 1641 | MsimSession *session; | |
| 1642 | GHashTable *userinfo; | |
| 1643 | ||
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1644 | session = (MsimSession *)buddy->account->gc->proto_data; |
| 16322 | 1645 | |
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1646 | g_return_if_fail(MSIM_SESSION_VALID(session)); |
|
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1647 | g_return_if_fail(session->user_lookup_cache); |
| 16322 | 1648 | |
| 1649 | userinfo = g_hash_table_lookup(session->user_lookup_cache, buddy->name); | |
| 1650 | ||
|
17894
e9d07c821d6f
Use g_return_if_fail() instead of g_assert(), as to not crash the whole program.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17893
diff
changeset
|
1651 | g_return_if_fail(userinfo != NULL); |
| 16322 | 1652 | |
| 1653 | // TODO: if (full), do something different | |
| 16324 | 1654 | purple_notify_user_info_add_pair(user_info, "User ID", g_hash_table_lookup(userinfo, "UserID")); |
| 1655 | purple_notify_user_info_add_pair(user_info, "Display Name", g_hash_table_lookup(userinfo, "DisplayName")); | |
| 1656 | purple_notify_user_info_add_pair(user_info, "User Name", g_hash_table_lookup(userinfo, "UserName")); | |
| 1657 | purple_notify_user_info_add_pair(user_info, "Total Friends", g_hash_table_lookup(userinfo, "TotalFriends")); | |
| 1658 | purple_notify_user_info_add_pair(user_info, "Song", | |
| 16322 | 1659 | g_strdup_printf("%s - %s", |
|
17906
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1660 | (gchar *)g_hash_table_lookup(userinfo, "BandName"), |
|
f87472f223aa
Stylistic improvements - use type *name instead of type* name for pointers
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17903
diff
changeset
|
1661 | (gchar *)g_hash_table_lookup(userinfo, "SongName"))); |
| 16322 | 1662 | } |
| 1663 | } | |
| 1664 | ||
| 16324 | 1665 | /** Callbacks called by Purple, to access this plugin. */ |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1666 | PurplePluginProtocolInfo prpl_info = |
| 16322 | 1667 | { |
| 1668 | OPT_PROTO_MAIL_CHECK,/* options - TODO: myspace will notify of mail */ | |
| 1669 | NULL, /* user_splits */ | |
| 1670 | NULL, /* protocol_options */ | |
| 1671 | NO_BUDDY_ICONS, /* icon_spec - TODO: eventually should add this */ | |
| 1672 | msim_list_icon, /* list_icon */ | |
| 1673 | NULL, /* list_emblems */ | |
| 1674 | msim_status_text, /* status_text */ | |
| 1675 | msim_tooltip_text, /* tooltip_text */ | |
| 1676 | msim_status_types, /* status_types */ | |
| 1677 | NULL, /* blist_node_menu */ | |
| 1678 | NULL, /* chat_info */ | |
| 1679 | NULL, /* chat_info_defaults */ | |
| 1680 | msim_login, /* login */ | |
| 1681 | msim_close, /* close */ | |
| 1682 | msim_send_im, /* send_im */ | |
| 1683 | NULL, /* set_info */ | |
|
17934
d163dde3aff1
Add, but do not use, incomplete functions for using typing notifications.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17933
diff
changeset
|
1684 | msim_send_typing, /* send_typing */ |
| 16322 | 1685 | NULL, /* get_info */ |
| 1686 | NULL, /* set_away */ | |
| 1687 | NULL, /* set_idle */ | |
| 1688 | NULL, /* change_passwd */ | |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1689 | msim_add_buddy, /* add_buddy */ |
| 16322 | 1690 | NULL, /* add_buddies */ |
|
17940
46246b04b219
Add (incomplete) msim_remove_buddy().
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17937
diff
changeset
|
1691 | msim_remove_buddy, /* remove_buddy */ |
| 16322 | 1692 | NULL, /* remove_buddies */ |
| 1693 | NULL, /* add_permit */ | |
| 1694 | NULL, /* add_deny */ | |
| 1695 | NULL, /* rem_permit */ | |
| 1696 | NULL, /* rem_deny */ | |
| 1697 | NULL, /* set_permit_deny */ | |
| 1698 | NULL, /* join_chat */ | |
| 1699 | NULL, /* reject chat invite */ | |
| 1700 | NULL, /* get_chat_name */ | |
| 1701 | NULL, /* chat_invite */ | |
| 1702 | NULL, /* chat_leave */ | |
| 1703 | NULL, /* chat_whisper */ | |
| 1704 | NULL, /* chat_send */ | |
| 1705 | NULL, /* keepalive */ | |
| 1706 | NULL, /* register_user */ | |
| 1707 | NULL, /* get_cb_info */ | |
| 1708 | NULL, /* get_cb_away */ | |
| 1709 | NULL, /* alias_buddy */ | |
| 1710 | NULL, /* group_buddy */ | |
| 1711 | NULL, /* rename_group */ | |
| 1712 | NULL, /* buddy_free */ | |
| 1713 | NULL, /* convo_closed */ | |
| 1714 | NULL, /* normalize */ | |
| 1715 | NULL, /* set_buddy_icon */ | |
| 1716 | NULL, /* remove_group */ | |
| 1717 | NULL, /* get_cb_real_name */ | |
| 1718 | NULL, /* set_chat_topic */ | |
| 1719 | NULL, /* find_blist_chat */ | |
| 1720 | NULL, /* roomlist_get_list */ | |
| 1721 | NULL, /* roomlist_cancel */ | |
| 1722 | NULL, /* roomlist_expand_category */ | |
| 1723 | NULL, /* can_receive_file */ | |
| 1724 | NULL, /* send_file */ | |
| 1725 | NULL, /* new_xfer */ | |
| 1726 | NULL, /* offline_message */ | |
| 1727 | NULL, /* whiteboard_prpl_ops */ | |
| 1728 | 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
|
1729 | 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
|
1730 | NULL, /* _purple_reserved1 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1731 | NULL, /* _purple_reserved2 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1732 | NULL, /* _purple_reserved3 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1733 | NULL /* _purple_reserved4 */ |
| 16322 | 1734 | }; |
| 1735 | ||
| 1736 | ||
| 1737 | ||
| 1738 | /** Based on MSN's plugin info comments. */ | |
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1739 | PurplePluginInfo info = |
| 16322 | 1740 | { |
| 16324 | 1741 | PURPLE_PLUGIN_MAGIC, |
| 1742 | PURPLE_MAJOR_VERSION, | |
| 1743 | PURPLE_MINOR_VERSION, | |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1744 | PURPLE_PLUGIN_PROTOCOL, /**< type */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1745 | NULL, /**< ui_requirement */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1746 | 0, /**< flags */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1747 | NULL, /**< dependencies */ |
|
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1748 | PURPLE_PRIORITY_DEFAULT, /**< priority */ |
| 16322 | 1749 | |
| 1750 | "prpl-myspace", /**< id */ | |
| 1751 | "MySpaceIM", /**< name */ | |
|
17933
03228b5c78b5
Show online buddies on buddy list as online.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17931
diff
changeset
|
1752 | "0.6", /**< version */ |
| 16322 | 1753 | /** summary */ |
| 1754 | "MySpaceIM Protocol Plugin", | |
| 1755 | /** description */ | |
| 1756 | "MySpaceIM Protocol Plugin", | |
| 1757 | "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */ | |
| 1758 | "http://developer.pidgin.im/wiki/MySpaceIM/", /**< homepage */ | |
| 1759 | ||
|
17893
308a27332b57
Check for RC4 in libpurple on plugin initialization.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17892
diff
changeset
|
1760 | msim_load, /**< load */ |
| 16322 | 1761 | NULL, /**< unload */ |
| 1762 | NULL, /**< destroy */ | |
| 1763 | NULL, /**< ui_info */ | |
| 1764 | &prpl_info, /**< extra_info */ | |
| 1765 | NULL, /**< prefs_info */ | |
| 1766 | ||
| 1767 | /* msim_actions */ | |
|
17890
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1768 | NULL, |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1769 | |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1770 | NULL, /**< reserved1 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1771 | NULL, /**< reserved2 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1772 | NULL, /**< reserved3 */ |
|
6926ed504a9a
Add initializers for reserved fields in plugin and prpl structures.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
16337
diff
changeset
|
1773 | NULL /**< reserved4 */ |
| 16322 | 1774 | }; |
| 1775 | ||
|
17903
1c344d9266b8
Use MsimMessage via msim_send(), instead of msim_send_raw(). This is a more
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17902
diff
changeset
|
1776 | void init_plugin(PurplePlugin *plugin) |
|
17900
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1777 | { |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1778 | PurpleAccountOption *option; |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1779 | #ifdef _TEST_MSIM_MSG |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1780 | { |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1781 | MsimMessage *msg; |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1782 | |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1783 | purple_debug_info("msim", "testing MsimMessage\n"); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1784 | msg = msim_msg_new(); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1785 | msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3)); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1786 | msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1")); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1787 | msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42)); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1788 | msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43")); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1789 | msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy")); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1790 | msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7")); |
|
17935
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1791 | purple_debug_info("msim", "msg debug str=%s\n", msim_msg_debug_string(msg)); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1792 | purple_debug_info("msim", "msg packed=%s\n", msim_msg_pack(msg)); |
|
a6a70c7213ab
Previously, the return value of the processing function and msim_process() told
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17934
diff
changeset
|
1793 | purple_debug_info("msim", "msg cloned=%s\n", msim_msg_pack(msim_msg_clone(msg))); |
|
17910
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1794 | msim_msg_free(msg); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1795 | exit(0); |
|
9bbfa75ba90b
(Incomplete - plugin does not load) Begin migrating protocol message receiving to MsimMessage.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17906
diff
changeset
|
1796 | } |
|
17902
8e0b1d066efb
Add partial implementation of MsimMessage (not used anywhere yet).
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17901
diff
changeset
|
1797 | #endif |
|
17900
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1798 | |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1799 | /* TODO: default to automatically try different ports. Make the user be |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1800 | * able to set the first port to try (like LastConnectedPort in Windows client). */ |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1801 | option = purple_account_option_string_new(_("Connect server"), "server", MSIM_SERVER); |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1802 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1803 | |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1804 | option = purple_account_option_int_new(_("Connect port"), "port", MSIM_PORT); |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1805 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); |
|
402fdc925e30
Clean up a few TODO's.
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
17898
diff
changeset
|
1806 | } |
| 16322 | 1807 | |
| 16324 | 1808 | PURPLE_INIT_PLUGIN(myspace, init_plugin, info); |