Sat, 24 May 2003 19:15:58 +0000
[gaim-migrate @ 5904]
Typing messages no longer require any acknowledgement, so all errors saying
that the message was not received should now be gone. This is what the
official client does.
| 5309 | 1 | /** |
| 2 | * @file dispatch.c Dispatch server functions | |
| 3 | * | |
| 4 | * gaim | |
| 5 | * | |
| 6 | * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
| 7 | * | |
| 8 | * This program is free software; you can redistribute it and/or modify | |
| 9 | * it under the terms of the GNU General Public License as published by | |
| 10 | * the Free Software Foundation; either version 2 of the License, or | |
| 11 | * (at your option) any later version. | |
| 12 | * | |
| 13 | * This program is distributed in the hope that it will be useful, | |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 16 | * GNU General Public License for more details. | |
| 17 | * | |
| 18 | * You should have received a copy of the GNU General Public License | |
| 19 | * along with this program; if not, write to the Free Software | |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 21 | */ | |
| 22 | #include "msn.h" | |
| 23 | #include "dispatch.h" | |
| 24 | #include "notification.h" | |
| 25 | #include "error.h" | |
| 26 | ||
| 27 | static GHashTable *dispatch_commands = NULL; | |
| 28 | ||
| 29 | static gboolean | |
| 30 | __ver_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 31 | size_t param_count) | |
| 32 | { | |
| 33 | struct gaim_connection *gc = servconn->session->account->gc; | |
| 34 | size_t i; | |
| 35 | gboolean msnp5_found = FALSE; | |
| 36 | ||
| 37 | for (i = 1; i < param_count; i++) { | |
| 38 | if (!strcmp(params[i], "MSNP5")) { | |
| 39 | msnp5_found = TRUE; | |
| 40 | break; | |
| 41 | } | |
| 42 | } | |
| 43 | ||
| 44 | if (!msnp5_found) { | |
| 45 | hide_login_progress(gc, _("Protocol not supported")); | |
| 46 | signoff(gc); | |
| 47 | ||
| 48 | return FALSE; | |
| 49 | } | |
| 50 | ||
| 51 | if (!msn_servconn_send_command(servconn, "INF", NULL)) { | |
| 52 | hide_login_progress(gc, _("Unable to request INF\n")); | |
| 53 | signoff(gc); | |
| 54 | ||
| 55 | return FALSE; | |
| 56 | } | |
| 57 | ||
| 58 | return TRUE; | |
| 59 | } | |
| 60 | ||
| 61 | static gboolean | |
| 62 | __inf_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 63 | size_t param_count) | |
| 64 | { | |
| 65 | struct gaim_connection *gc = servconn->session->account->gc; | |
| 66 | char outparams[MSN_BUF_LEN]; | |
| 67 | ||
| 68 | if (strcmp(params[1], "MD5")) { | |
| 69 | hide_login_progress(gc, _("Unable to login using MD5")); | |
| 70 | signoff(gc); | |
| 71 | ||
| 72 | return FALSE; | |
| 73 | } | |
| 74 | ||
| 75 | g_snprintf(outparams, sizeof(outparams), "MD5 I %s", gc->username); | |
| 76 | ||
| 77 | if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
| 78 | hide_login_progress(gc, _("Unable to send USR\n")); | |
| 79 | signoff(gc); | |
| 80 | ||
| 81 | return FALSE; | |
| 82 | } | |
| 83 | ||
| 84 | set_login_progress(gc, 3, _("Requesting to send password")); | |
| 85 | ||
| 86 | return TRUE; | |
| 87 | } | |
| 88 | ||
| 89 | static gboolean | |
| 90 | __xfr_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 91 | size_t param_count) | |
| 92 | { | |
| 93 | MsnSession *session = servconn->session; | |
| 94 | struct gaim_connection *gc = servconn->session->account->gc; | |
| 95 | char *host; | |
| 96 | int port; | |
| 97 | char *c; | |
| 98 | ||
| 99 | if (param_count < 2 || strcmp(params[1], "NS")) { | |
| 100 | hide_login_progress(gc, _("Got invalid XFR\n")); | |
| 101 | signoff(gc); | |
| 102 | ||
| 103 | return FALSE; | |
| 104 | } | |
| 105 | ||
| 106 | host = g_strdup(params[2]); | |
| 107 | ||
| 108 | if ((c = strchr(host, ':')) != NULL) { | |
| 109 | *c = '\0'; | |
| 110 | ||
| 111 | port = atoi(c + 1); | |
| 112 | } | |
| 113 | else | |
| 114 | port = 1863; | |
| 115 | ||
| 116 | session->passport_info.sl = time(NULL); | |
| 117 | ||
| 118 | /* Disconnect from here. */ | |
| 119 | msn_servconn_destroy(servconn); | |
| 120 | session->dispatch_conn = NULL; | |
| 121 | ||
| 122 | /* Now connect to the switchboard. */ | |
| 123 | session->notification_conn = msn_notification_new(session, host, port); | |
| 124 | ||
| 125 | g_free(host); | |
| 126 | ||
| 127 | if (!msn_servconn_connect(session->notification_conn)) { | |
| 128 | hide_login_progress(gc, _("Unable to transfer")); | |
| 129 | signoff(gc); | |
| 130 | } | |
| 131 | ||
| 132 | return FALSE; | |
| 133 | } | |
| 134 | ||
| 135 | static gboolean | |
| 136 | __unknown_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 137 | size_t param_count) | |
| 138 | { | |
| 139 | struct gaim_connection *gc = servconn->session->account->gc; | |
| 140 | ||
| 141 | if (isdigit(*command)) { | |
| 142 | char buf[4]; | |
| 143 | ||
| 144 | strncpy(buf, command, 4); | |
| 145 | buf[4] = '\0'; | |
| 146 | ||
| 147 | hide_login_progress(gc, (char *)msn_error_get_text(atoi(buf))); | |
| 148 | } | |
| 149 | else | |
| 150 | hide_login_progress(gc, _("Unable to parse message.")); | |
| 151 | ||
| 152 | signoff(gc); | |
| 153 | ||
| 154 | return FALSE; | |
| 155 | } | |
| 156 | ||
| 157 | static gboolean | |
| 158 | __connect_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 159 | { | |
| 160 | MsnServConn *dispatch = data; | |
| 161 | MsnSession *session = dispatch->session; | |
| 162 | struct gaim_connection *gc = session->account->gc; | |
| 163 | ||
| 164 | if (source == -1) { | |
| 165 | hide_login_progress(session->account->gc, _("Unable to connect")); | |
| 166 | signoff(session->account->gc); | |
| 167 | return FALSE; | |
| 168 | } | |
| 169 | ||
| 170 | set_login_progress(gc, 1, _("Connecting")); | |
| 171 | ||
| 172 | if (dispatch->fd != source) | |
| 173 | dispatch->fd = source; | |
| 174 | ||
| 175 | if (!msn_servconn_send_command(dispatch, "VER", | |
| 176 | "MSNP7 MSNP6 MSNP5 MSNP4 CVR0")) { | |
| 177 | hide_login_progress(gc, _("Unable to write to server")); | |
| 178 | signoff(gc); | |
| 179 | return FALSE; | |
| 180 | } | |
| 181 | ||
| 182 | set_login_progress(session->account->gc, 2, _("Syncing with server")); | |
| 183 | ||
| 184 | return TRUE; | |
| 185 | } | |
| 186 | ||
| 187 | static void | |
| 188 | __failed_read_cb(gpointer data, gint source, GaimInputCondition cond) | |
| 189 | { | |
| 190 | MsnServConn *dispatch = data; | |
| 191 | struct gaim_connection *gc; | |
| 192 | ||
| 193 | gc = dispatch->session->account->gc; | |
| 194 | ||
| 195 | hide_login_progress(gc, _("Error reading from server")); | |
| 196 | signoff(gc); | |
| 197 | } | |
| 198 | ||
| 199 | MsnServConn * | |
| 200 | msn_dispatch_new(MsnSession *session, const char *server, int port) | |
| 201 | { | |
| 202 | MsnServConn *dispatch; | |
| 203 | ||
| 204 | dispatch = msn_servconn_new(session); | |
| 205 | ||
| 206 | msn_servconn_set_server(dispatch, server, port); | |
| 207 | msn_servconn_set_connect_cb(dispatch, __connect_cb); | |
| 208 | msn_servconn_set_failed_read_cb(dispatch, __failed_read_cb); | |
| 209 | ||
| 210 | if (dispatch_commands == NULL) { | |
| 211 | /* Register the command callbacks. */ | |
| 212 | msn_servconn_register_command(dispatch, "VER", __ver_cmd); | |
| 213 | msn_servconn_register_command(dispatch, "INF", __inf_cmd); | |
| 214 | msn_servconn_register_command(dispatch, "XFR", __xfr_cmd); | |
| 215 | msn_servconn_register_command(dispatch, "_unknown_", __unknown_cmd); | |
| 216 | ||
| 217 | /* Save this for future use. */ | |
| 218 | dispatch_commands = dispatch->commands; | |
| 219 | } | |
| 220 | else { | |
| 221 | g_hash_table_destroy(dispatch->commands); | |
| 222 | ||
| 223 | dispatch->commands = dispatch_commands; | |
| 224 | } | |
| 225 | ||
| 226 | return dispatch; | |
| 227 | } | |
| 228 |