Mercurial > pidgin
annotate src/protocols/msn/cmdproc.c @ 12645:fc28451f5d96
[gaim-migrate @ 14983]
SF Patch #1314512 from Sadrul (who has a patch for everything)
"This patch introduces a flag for protocol plugins that
support offline messages (like Y!M and ICQ). This was
encouraged by the following conversation:
<sadrul> should offline buddies be listed/enabled in
the send-to menu?
<rekkanoryo> i would think only for protocols that
support offline messaging, if it's indicated that the
buddy is offline
-- <snip> --
<Bleeter> sadrul: personally, I'd like to see a
'supports offline' flag of some description
<Bleeter> one could then redirect (via plugins) through
email or alternative methods
<Bleeter> just a thought
<Paco-Paco> yeah, that sounds like a reasonble thing to have
This patch uses this flag to disable the buddies in the
send-to menu who are offline and the protocol doesn't
support offline messages."
I made this make the label insensitive instead of the whole menuitem. This
should address SimGuy's concerns about inconsistency (i.e. you could create a
conversation with someone via the buddy list that you couldn't create via the
Send To menu). I also hacked up some voodoo to show the label as sensitive when
moused-over, as that looks better (given the label-insensitive thing is itself a
hack). I think this works quite well.
BUG NOTE:
This makes more obvious an existing bug. The Send To menu isn't updated when
buddies sign on or off or change status (at least under some circumstances).
We need to fix that anyway, so I'm not going to let it hold up this commit.
Switching tabs will clear it up. I'm thinking we just might want to build the
contents of that menu when it is selected. That would save us a mess of
inefficient signal callbacks that update the Send To menus in open windows all
the time.
AIM NOTE:
This assumes that AIM can't offline message. That's not strictly true. You can
message invisible users on AIM. However, by design, we can't tell when a user
is invisible without resorting to dirty hackery. In practice, this isn't a
problem, as you can still select the AIM user from the menu. And really, how
often will you be choosing the Invisible contact, rather than the user going
Invisible in the middle of a conversation or IMing you while they're Invisible?
JABBER NOTE:
This assumes that Jabber can always offline message. This isn't strictly true.
Sadrul said:
I have updated Jabber according to this link which seems to
talk about how to determine the existence offline-message
support in a server:
http://www.jabber.org/jeps/jep-0013.html#discover
However, jabber.org doesn't seem to send the required
info. So I am not sure about it.
He later said:
I talked to Nathan and he said offline message support is
mostly assumed for most jabber servers. GTalk doesn't yet
support it, but they are working on it. So I have made
jabber to always return TRUE.
If there is truly no way to detect offline messaging capability, then this is
an acceptable solution. We could special case Google Talk because of its
popularity, and remove that later. It's probably not worth it though.
MSN NOTE:
This assumes that MSN can never offline message. That's effectively true, but
to be technically correct, MSN can offline message if there's already a
switchboard conversation open with a user. We could write an offline_message
function in the MSN prpl to detect that, but it'd be of limited usefulness,
especially given that under most circumstances (where this might matter), the
switchboard connection will be closed almost immediately.
CVS NOTE:
I'm writing to share a tragic little story.
I have a PC that I use for Gaim development. One day, I was writing a commit
message on it, when all of a suddent it went berserk. The screen started
flashing, and the whole commit message just disappeared. All of it. And it was
a good commit message! I had to cram and rewrite it really quickly. Needless to
say, my rushed commit message wasn't nearly as good, and I blame the PC for that.
Seriously, though, what kind of version control system loses your commit
message on a broken connection to the server? Stupid!
committer: Tailor Script <tailor@pidgin.im>
| author | Richard Laager <rlaager@wiktel.com> |
|---|---|
| date | Fri, 23 Dec 2005 19:26:04 +0000 |
| parents | 1a97d5e88d12 |
| children | 995aea35b05c |
| rev | line source |
|---|---|
| 8810 | 1 /** |
| 2 * @file cmdproc.c MSN command processor functions | |
| 3 * | |
| 4 * gaim | |
| 5 * | |
|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
| 8810 | 9 * |
| 10 * This program is free software; you can redistribute it and/or modify | |
| 11 * it under the terms of the GNU General Public License as published by | |
| 12 * the Free Software Foundation; either version 2 of the License, or | |
| 13 * (at your option) any later version. | |
| 14 * | |
| 15 * This program is distributed in the hope that it will be useful, | |
| 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 * GNU General Public License for more details. | |
| 19 * | |
| 20 * You should have received a copy of the GNU General Public License | |
| 21 * along with this program; if not, write to the Free Software | |
| 22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 */ | |
| 24 #include "msn.h" | |
| 25 #include "cmdproc.h" | |
| 26 | |
| 27 MsnCmdProc * | |
| 28 msn_cmdproc_new(MsnSession *session) | |
| 29 { | |
| 30 MsnCmdProc *cmdproc; | |
| 31 | |
| 32 cmdproc = g_new0(MsnCmdProc, 1); | |
| 33 | |
| 34 cmdproc->session = session; | |
| 35 cmdproc->txqueue = g_queue_new(); | |
| 36 cmdproc->history = msn_history_new(); | |
| 37 | |
| 38 return cmdproc; | |
| 39 } | |
| 40 | |
| 41 void | |
| 42 msn_cmdproc_destroy(MsnCmdProc *cmdproc) | |
| 43 { | |
| 44 MsnTransaction *trans; | |
| 45 | |
| 46 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) | |
| 47 msn_transaction_destroy(trans); | |
| 48 | |
| 49 g_queue_free(cmdproc->txqueue); | |
| 50 | |
| 51 msn_history_destroy(cmdproc->history); | |
| 10504 | 52 |
| 53 if (cmdproc->last_cmd != NULL) | |
| 54 msn_command_destroy(cmdproc->last_cmd); | |
| 55 | |
| 10481 | 56 g_free(cmdproc); |
| 8810 | 57 } |
| 58 | |
| 59 void | |
| 60 msn_cmdproc_process_queue(MsnCmdProc *cmdproc) | |
| 61 { | |
| 62 MsnTransaction *trans; | |
| 63 | |
| 10481 | 64 while ((trans = g_queue_pop_head(cmdproc->txqueue)) != NULL) |
| 8810 | 65 msn_cmdproc_send_trans(cmdproc, trans); |
| 66 } | |
| 67 | |
| 68 void | |
| 69 msn_cmdproc_queue_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
| 70 { | |
| 71 g_return_if_fail(cmdproc != NULL); | |
| 72 g_return_if_fail(trans != NULL); | |
| 73 | |
| 74 g_queue_push_tail(cmdproc->txqueue, trans); | |
| 75 } | |
| 76 | |
| 77 static void | |
| 78 show_debug_cmd(MsnCmdProc *cmdproc, gboolean incoming, const char *command) | |
| 79 { | |
| 80 MsnServConn *servconn; | |
| 81 const char *names[] = { "NS", "SB" }; | |
| 82 char *show; | |
| 83 char tmp; | |
| 84 size_t len; | |
| 85 | |
| 86 servconn = cmdproc->servconn; | |
| 87 len = strlen(command); | |
| 88 show = g_strdup(command); | |
| 89 | |
| 90 tmp = (incoming) ? 'S' : 'C'; | |
| 91 | |
| 92 if ((show[len - 1] == '\n') && (show[len - 2] == '\r')) | |
| 93 { | |
| 94 show[len - 2] = '\0'; | |
| 95 } | |
| 96 | |
| 97 gaim_debug_misc("msn", "%c: %s %03d: %s\n", tmp, | |
| 98 names[servconn->type], servconn->num, show); | |
| 99 | |
| 100 g_free(show); | |
| 101 } | |
| 102 | |
| 103 void | |
| 104 msn_cmdproc_send_trans(MsnCmdProc *cmdproc, MsnTransaction *trans) | |
| 105 { | |
| 106 MsnServConn *servconn; | |
| 107 char *data; | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
108 size_t len; |
| 8810 | 109 |
| 110 g_return_if_fail(cmdproc != NULL); | |
| 111 g_return_if_fail(trans != NULL); | |
| 112 | |
| 113 servconn = cmdproc->servconn; | |
| 10481 | 114 |
| 115 if (!servconn->connected) | |
| 116 return; | |
| 117 | |
| 8810 | 118 msn_history_add(cmdproc->history, trans); |
| 119 | |
| 120 data = msn_transaction_to_string(trans); | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
121 |
| 8810 | 122 len = strlen(data); |
| 123 | |
| 124 show_debug_cmd(cmdproc, FALSE, data); | |
| 125 | |
| 126 if (trans->callbacks == NULL) | |
| 127 trans->callbacks = g_hash_table_lookup(cmdproc->cbs_table->cmds, | |
| 128 trans->command); | |
| 129 | |
| 130 if (trans->payload != NULL) | |
| 131 { | |
| 132 data = g_realloc(data, len + trans->payload_len); | |
| 133 memcpy(data + len, trans->payload, trans->payload_len); | |
| 134 len += trans->payload_len; | |
| 135 } | |
| 136 | |
| 137 msn_servconn_write(servconn, data, len); | |
| 138 | |
| 139 g_free(data); | |
| 140 } | |
| 141 | |
| 142 void | |
| 143 msn_cmdproc_send_quick(MsnCmdProc *cmdproc, const char *command, | |
| 144 const char *format, ...) | |
| 145 { | |
| 146 MsnServConn *servconn; | |
| 147 char *data; | |
|
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
148 char *params = NULL; |
| 8810 | 149 va_list arg; |
| 150 size_t len; | |
| 151 | |
| 152 g_return_if_fail(cmdproc != NULL); | |
| 153 g_return_if_fail(command != NULL); | |
| 154 | |
| 155 servconn = cmdproc->servconn; | |
| 156 | |
| 10481 | 157 if (!servconn->connected) |
| 158 return; | |
| 159 | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
160 if (format != NULL) |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
161 { |
|
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
162 va_start(arg, format); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
163 params = g_strdup_vprintf(format, arg); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
164 va_end(arg); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
165 } |
| 8810 | 166 |
| 167 if (params != NULL) | |
| 168 data = g_strdup_printf("%s %s\r\n", command, params); | |
| 169 else | |
| 170 data = g_strdup_printf("%s\r\n", command); | |
| 171 | |
| 172 g_free(params); | |
| 173 | |
| 174 len = strlen(data); | |
| 175 | |
| 176 show_debug_cmd(cmdproc, FALSE, data); | |
| 177 | |
| 178 msn_servconn_write(servconn, data, len); | |
| 179 | |
| 180 g_free(data); | |
| 181 } | |
| 182 | |
| 183 void | |
| 184 msn_cmdproc_send(MsnCmdProc *cmdproc, const char *command, | |
| 185 const char *format, ...) | |
| 186 { | |
| 187 MsnTransaction *trans; | |
| 188 va_list arg; | |
| 189 | |
| 190 g_return_if_fail(cmdproc != NULL); | |
| 191 g_return_if_fail(command != NULL); | |
| 192 | |
| 10481 | 193 if (!cmdproc->servconn->connected) |
| 194 return; | |
| 195 | |
| 8810 | 196 trans = g_new0(MsnTransaction, 1); |
| 197 | |
| 198 trans->command = g_strdup(command); | |
| 199 | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
200 if (format != NULL) |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
201 { |
|
8830
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
202 va_start(arg, format); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
203 trans->params = g_strdup_vprintf(format, arg); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
204 va_end(arg); |
|
f8038b1f7449
[gaim-migrate @ 9594]
Christian Hammond <chipx86@chipx86.com>
parents:
8810
diff
changeset
|
205 } |
| 8810 | 206 |
| 207 msn_cmdproc_send_trans(cmdproc, trans); | |
| 208 } | |
| 209 | |
| 210 void | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
211 msn_cmdproc_process_payload(MsnCmdProc *cmdproc, char *payload, |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
212 int payload_len) |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
213 { |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
214 MsnCommand *last; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
215 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
216 g_return_if_fail(cmdproc != NULL); |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
217 |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
218 last = cmdproc->last_cmd; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
219 last->payload = g_memdup(payload, payload_len); |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
220 last->payload_len = payload_len; |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
221 |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
222 if (last->payload_cb != NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
223 last->payload_cb(cmdproc, last, payload, payload_len); |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
224 } |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
225 |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
226 void |
| 8810 | 227 msn_cmdproc_process_msg(MsnCmdProc *cmdproc, MsnMessage *msg) |
| 228 { | |
| 10345 | 229 MsnMsgTypeCb cb; |
| 8810 | 230 |
| 9881 | 231 if (msn_message_get_content_type(msg) == NULL) |
| 232 { | |
| 233 gaim_debug_misc("msn", "failed to find message content\n"); | |
| 234 return; | |
| 235 } | |
| 236 | |
| 8810 | 237 cb = g_hash_table_lookup(cmdproc->cbs_table->msgs, |
| 238 msn_message_get_content_type(msg)); | |
| 239 | |
| 240 if (cb == NULL) | |
| 241 { | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
242 gaim_debug_warning("msn", "Unhandled content-type '%s'\n", |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
243 msn_message_get_content_type(msg)); |
| 8810 | 244 |
| 245 return; | |
| 246 } | |
| 247 | |
| 248 cb(cmdproc, msg); | |
| 249 } | |
| 250 | |
| 251 void | |
| 252 msn_cmdproc_process_cmd(MsnCmdProc *cmdproc, MsnCommand *cmd) | |
| 253 { | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
254 MsnTransCb cb = NULL; |
| 8810 | 255 MsnTransaction *trans = NULL; |
| 256 | |
| 257 if (cmd->trId) | |
| 258 trans = msn_history_find(cmdproc->history, cmd->trId); | |
| 259 | |
| 10225 | 260 if (trans != NULL) |
| 261 if (trans->timer) | |
| 262 gaim_timeout_remove(trans->timer); | |
| 263 | |
| 8810 | 264 if (g_ascii_isdigit(cmd->command[0])) |
| 265 { | |
| 266 if (trans != NULL) | |
| 267 { | |
| 268 MsnErrorCb error_cb = NULL; | |
| 269 int error; | |
| 270 | |
| 271 error = atoi(cmd->command); | |
| 10225 | 272 |
| 273 if (trans->error_cb != NULL) | |
| 274 error_cb = trans->error_cb; | |
| 275 | |
| 276 if (error_cb == NULL && cmdproc->cbs_table->errors != NULL) | |
| 8810 | 277 error_cb = g_hash_table_lookup(cmdproc->cbs_table->errors, trans->command); |
| 278 | |
| 279 if (error_cb != NULL) | |
| 10225 | 280 { |
| 8810 | 281 error_cb(cmdproc, trans, error); |
| 10225 | 282 } |
| 8810 | 283 else |
| 284 { | |
| 285 #if 1 | |
| 286 msn_error_handle(cmdproc->session, error); | |
| 287 #else | |
| 288 gaim_debug_warning("msn", "Unhandled error '%s'\n", | |
| 289 cmd->command); | |
| 290 #endif | |
| 291 } | |
| 292 | |
| 293 return; | |
| 294 } | |
| 295 } | |
| 296 | |
| 297 if (cmdproc->cbs_table->async != NULL) | |
| 298 cb = g_hash_table_lookup(cmdproc->cbs_table->async, cmd->command); | |
| 299 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
300 if (cb == NULL && trans != NULL) |
| 8810 | 301 { |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
302 cmd->trans = trans; |
| 8810 | 303 |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
304 if (trans->callbacks != NULL) |
|
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
305 cb = g_hash_table_lookup(trans->callbacks, cmd->command); |
| 8810 | 306 } |
| 307 | |
| 10043 | 308 if (cb == NULL && cmdproc->cbs_table->fallback != NULL) |
| 309 cb = g_hash_table_lookup(cmdproc->cbs_table->fallback, cmd->command); | |
| 310 | |
| 8810 | 311 if (cb != NULL) |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
312 { |
| 8810 | 313 cb(cmdproc, cmd); |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
314 } |
| 8810 | 315 else |
| 316 { | |
| 317 gaim_debug_warning("msn", "Unhandled command '%s'\n", | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
8830
diff
changeset
|
318 cmd->command); |
| 8810 | 319 } |
| 320 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
321 if (trans != NULL && trans->pendent_cmd != NULL) |
| 10481 | 322 msn_transaction_unqueue_cmd(trans, cmdproc); |
| 8810 | 323 } |
| 324 | |
| 325 void | |
| 326 msn_cmdproc_process_cmd_text(MsnCmdProc *cmdproc, const char *command) | |
| 327 { | |
| 328 show_debug_cmd(cmdproc, TRUE, command); | |
| 329 | |
| 330 if (cmdproc->last_cmd != NULL) | |
| 331 msn_command_destroy(cmdproc->last_cmd); | |
| 332 | |
| 333 cmdproc->last_cmd = msn_command_from_string(command); | |
| 334 | |
| 335 msn_cmdproc_process_cmd(cmdproc, cmdproc->last_cmd); | |
| 336 } |
