Mercurial > pidgin
comparison src/protocols/msn/dispatch.c @ 6701:b7e113a59b51
[gaim-migrate @ 7227]
Updated to MSN Protocol 9.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Tue, 02 Sep 2003 04:32:16 +0000 |
| parents | 156e6643f9db |
| children | cdcb43229e33 |
comparison
equal
deleted
inserted
replaced
| 6700:57161e3abbb5 | 6701:b7e113a59b51 |
|---|---|
| 2 * @file dispatch.c Dispatch server functions | 2 * @file dispatch.c Dispatch server functions |
| 3 * | 3 * |
| 4 * gaim | 4 * gaim |
| 5 * | 5 * |
| 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | 6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> |
| 7 * | 7 * |
| 8 * This program is free software; you can redistribute it and/or modify | 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 | 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 | 10 * the Free Software Foundation; either version 2 of the License, or |
| 11 * (at your option) any later version. | 11 * (at your option) any later version. |
| 12 * | 12 * |
| 25 #include "error.h" | 25 #include "error.h" |
| 26 | 26 |
| 27 static GHashTable *dispatch_commands = NULL; | 27 static GHashTable *dispatch_commands = NULL; |
| 28 | 28 |
| 29 static gboolean | 29 static gboolean |
| 30 ver_cmd(MsnServConn *servconn, const char *command, const char **params, | 30 cvr_cmd(MsnServConn *servconn, const char *command, const char **params, |
| 31 size_t param_count) | |
| 32 { | |
| 33 GaimConnection *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 gaim_connection_error(gc, _("Protocol not supported")); | |
| 46 | |
| 47 return FALSE; | |
| 48 } | |
| 49 | |
| 50 if (!msn_servconn_send_command(servconn, "INF", NULL)) { | |
| 51 gaim_connection_error(gc, _("Unable to request INF")); | |
| 52 | |
| 53 return FALSE; | |
| 54 } | |
| 55 | |
| 56 return TRUE; | |
| 57 } | |
| 58 | |
| 59 static gboolean | |
| 60 inf_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 61 size_t param_count) | 31 size_t param_count) |
| 62 { | 32 { |
| 63 GaimAccount *account = servconn->session->account; | 33 GaimAccount *account = servconn->session->account; |
| 64 GaimConnection *gc = gaim_account_get_connection(account); | 34 GaimConnection *gc = gaim_account_get_connection(account); |
| 65 char outparams[MSN_BUF_LEN]; | 35 char outparams[MSN_BUF_LEN]; |
| 66 | 36 |
| 37 g_snprintf(outparams, sizeof(outparams), | |
| 38 "TWN I %s", gaim_account_get_username(account)); | |
| 39 | |
| 40 if (!msn_servconn_send_command(servconn, "USR", outparams)) | |
| 41 { | |
| 42 gaim_connection_error(gc, _("Unable to request USR\n")); | |
| 43 | |
| 44 return FALSE; | |
| 45 } | |
| 46 | |
| 47 return TRUE; | |
| 48 } | |
| 49 | |
| 50 static gboolean | |
| 51 inf_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 52 size_t param_count) | |
| 53 { | |
| 54 GaimAccount *account = servconn->session->account; | |
| 55 GaimConnection *gc = gaim_account_get_connection(account); | |
| 56 char outparams[MSN_BUF_LEN]; | |
| 57 | |
| 67 if (strcmp(params[1], "MD5")) { | 58 if (strcmp(params[1], "MD5")) { |
| 68 gaim_connection_error(gc, _("Unable to login using MD5")); | 59 gaim_connection_error(gc, _("Unable to login using MD5")); |
| 69 | 60 |
| 70 return FALSE; | 61 return FALSE; |
| 71 } | 62 } |
| 79 return FALSE; | 70 return FALSE; |
| 80 } | 71 } |
| 81 | 72 |
| 82 gaim_connection_update_progress(gc, _("Requesting to send password"), | 73 gaim_connection_update_progress(gc, _("Requesting to send password"), |
| 83 3, MSN_CONNECT_STEPS); | 74 3, MSN_CONNECT_STEPS); |
| 75 | |
| 76 return TRUE; | |
| 77 } | |
| 78 | |
| 79 static gboolean | |
| 80 ver_cmd(MsnServConn *servconn, const char *command, const char **params, | |
| 81 size_t param_count) | |
| 82 { | |
| 83 MsnSession *session = servconn->session; | |
| 84 GaimAccount *account = session->account; | |
| 85 GaimConnection *gc = gaim_account_get_connection(account); | |
| 86 gboolean protocol_supported = FALSE; | |
| 87 char outparams[MSN_BUF_LEN]; | |
| 88 char proto_str[8]; | |
| 89 size_t i; | |
| 90 | |
| 91 g_snprintf(proto_str, sizeof(proto_str), "MSNP%d", session->protocol_ver); | |
| 92 | |
| 93 for (i = 1; i < param_count; i++) | |
| 94 { | |
| 95 if (!strcmp(params[i], proto_str)) | |
| 96 { | |
| 97 protocol_supported = TRUE; | |
| 98 break; | |
| 99 } | |
| 100 } | |
| 101 | |
| 102 if (!protocol_supported) | |
| 103 { | |
| 104 gaim_connection_error(gc, _("Protocol version not supported")); | |
| 105 | |
| 106 return FALSE; | |
| 107 } | |
| 108 | |
| 109 if (session->protocol_ver >= 8) | |
| 110 { | |
| 111 g_snprintf(outparams, sizeof(outparams), | |
| 112 "0x0409 winnt 5.1 i386 MSNMSGR 6.0.0602 MSMSGS %s", | |
| 113 gaim_account_get_username(account)); | |
| 114 | |
| 115 if (!msn_servconn_send_command(servconn, "CVR", outparams)) | |
| 116 { | |
| 117 gaim_connection_error(gc, _("Unable to request CVR\n")); | |
| 118 | |
| 119 return FALSE; | |
| 120 } | |
| 121 } | |
| 122 else | |
| 123 { | |
| 124 if (!msn_servconn_send_command(servconn, "INF", NULL)) | |
| 125 { | |
| 126 gaim_connection_error(gc, _("Unable to request INF\n")); | |
| 127 | |
| 128 return FALSE; | |
| 129 } | |
| 130 } | |
| 84 | 131 |
| 85 return TRUE; | 132 return TRUE; |
| 86 } | 133 } |
| 87 | 134 |
| 88 static gboolean | 135 static gboolean |
| 93 GaimConnection *gc = servconn->session->account->gc; | 140 GaimConnection *gc = servconn->session->account->gc; |
| 94 char *host; | 141 char *host; |
| 95 int port; | 142 int port; |
| 96 char *c; | 143 char *c; |
| 97 | 144 |
| 98 if (param_count < 2 || strcmp(params[1], "NS")) { | 145 if (param_count < 2 || strcmp(params[1], "NS")) |
| 146 { | |
| 99 gaim_connection_error(gc, _("Got invalid XFR")); | 147 gaim_connection_error(gc, _("Got invalid XFR")); |
| 100 | 148 |
| 101 return FALSE; | 149 return FALSE; |
| 102 } | 150 } |
| 103 | 151 |
| 104 host = g_strdup(params[2]); | 152 host = g_strdup(params[2]); |
| 105 | 153 |
| 106 if ((c = strchr(host, ':')) != NULL) { | 154 if ((c = strchr(host, ':')) != NULL) |
| 155 { | |
| 107 *c = '\0'; | 156 *c = '\0'; |
| 108 | 157 |
| 109 port = atoi(c + 1); | 158 port = atoi(c + 1); |
| 110 } | 159 } |
| 111 else | 160 else |
| 115 | 164 |
| 116 /* Disconnect from here. */ | 165 /* Disconnect from here. */ |
| 117 msn_servconn_destroy(servconn); | 166 msn_servconn_destroy(servconn); |
| 118 session->dispatch_conn = NULL; | 167 session->dispatch_conn = NULL; |
| 119 | 168 |
| 169 /* Reset our transaction ID. */ | |
| 170 session->trId = 0; | |
| 171 | |
| 120 /* Now connect to the switchboard. */ | 172 /* Now connect to the switchboard. */ |
| 121 session->notification_conn = msn_notification_new(session, host, port); | 173 session->notification_conn = msn_notification_new(session, host, port); |
| 122 | 174 |
| 123 g_free(host); | 175 g_free(host); |
| 124 | 176 |
| 125 if (!msn_servconn_connect(session->notification_conn)) { | 177 if (!msn_servconn_connect(session->notification_conn)) |
| 126 gaim_connection_error(gc, _("Unable to transfer")); | 178 gaim_connection_error(gc, _("Unable to transfer")); |
| 127 } | |
| 128 | 179 |
| 129 return FALSE; | 180 return FALSE; |
| 130 } | 181 } |
| 131 | 182 |
| 132 static gboolean | 183 static gboolean |
| 133 unknown_cmd(MsnServConn *servconn, const char *command, const char **params, | 184 unknown_cmd(MsnServConn *servconn, const char *command, const char **params, |
| 134 size_t param_count) | 185 size_t param_count) |
| 135 { | 186 { |
| 136 GaimConnection *gc = servconn->session->account->gc; | 187 GaimConnection *gc = servconn->session->account->gc; |
| 137 | 188 |
| 138 if (isdigit(*command)) { | 189 if (isdigit(*command)) |
| 190 { | |
| 139 char buf[4]; | 191 char buf[4]; |
| 140 | 192 |
| 141 strncpy(buf, command, 4); | 193 strncpy(buf, command, 4); |
| 142 buf[4] = '\0'; | 194 buf[4] = '\0'; |
| 143 | 195 |
| 153 connect_cb(gpointer data, gint source, GaimInputCondition cond) | 205 connect_cb(gpointer data, gint source, GaimInputCondition cond) |
| 154 { | 206 { |
| 155 MsnServConn *dispatch = data; | 207 MsnServConn *dispatch = data; |
| 156 MsnSession *session = dispatch->session; | 208 MsnSession *session = dispatch->session; |
| 157 GaimConnection *gc = session->account->gc; | 209 GaimConnection *gc = session->account->gc; |
| 158 | 210 char proto_vers[256]; |
| 159 if (source == -1) { | 211 size_t i; |
| 212 | |
| 213 if (source == -1) | |
| 214 { | |
| 160 gaim_connection_error(session->account->gc, _("Unable to connect")); | 215 gaim_connection_error(session->account->gc, _("Unable to connect")); |
| 161 return FALSE; | 216 return FALSE; |
| 162 } | 217 } |
| 163 | 218 |
| 164 gaim_connection_update_progress(gc, _("Connecting"), 1, MSN_CONNECT_STEPS); | 219 gaim_connection_update_progress(gc, _("Connecting"), 1, MSN_CONNECT_STEPS); |
| 165 | 220 |
| 166 if (dispatch->fd != source) | 221 if (dispatch->fd != source) |
| 167 dispatch->fd = source; | 222 dispatch->fd = source; |
| 168 | 223 |
| 169 if (!msn_servconn_send_command(dispatch, "VER", | 224 proto_vers[0] = '\0'; |
| 170 "MSNP7 MSNP6 MSNP5 MSNP4 CVR0")) { | 225 |
| 226 for (i = session->protocol_ver; i >= 7; i--) | |
| 227 { | |
| 228 char old_buf[256]; | |
| 229 | |
| 230 strcpy(old_buf, proto_vers); | |
| 231 | |
| 232 g_snprintf(proto_vers, sizeof(proto_vers), "MSNP%d %s", i, old_buf); | |
| 233 } | |
| 234 | |
| 235 strncat(proto_vers, "CVR0", sizeof(proto_vers)); | |
| 236 | |
| 237 if (!msn_servconn_send_command(dispatch, "VER", proto_vers)) | |
| 238 { | |
| 171 gaim_connection_error(gc, _("Unable to write to server")); | 239 gaim_connection_error(gc, _("Unable to write to server")); |
| 172 return FALSE; | 240 return FALSE; |
| 173 } | 241 } |
| 174 | 242 |
| 175 gaim_connection_update_progress(gc, _("Syncing with server"), | 243 gaim_connection_update_progress(gc, _("Syncing with server"), |
| 193 msn_dispatch_new(MsnSession *session, const char *server, int port) | 261 msn_dispatch_new(MsnSession *session, const char *server, int port) |
| 194 { | 262 { |
| 195 MsnServConn *dispatch; | 263 MsnServConn *dispatch; |
| 196 | 264 |
| 197 dispatch = msn_servconn_new(session); | 265 dispatch = msn_servconn_new(session); |
| 198 | 266 |
| 199 msn_servconn_set_server(dispatch, server, port); | 267 msn_servconn_set_server(dispatch, server, port); |
| 200 msn_servconn_set_connect_cb(dispatch, connect_cb); | 268 msn_servconn_set_connect_cb(dispatch, connect_cb); |
| 201 msn_servconn_set_failed_read_cb(dispatch, failed_read_cb); | 269 msn_servconn_set_failed_read_cb(dispatch, failed_read_cb); |
| 202 | 270 |
| 203 if (dispatch_commands == NULL) { | 271 if (dispatch_commands == NULL) { |
| 204 /* Register the command callbacks. */ | 272 /* Register the command callbacks. */ |
| 273 | |
| 274 msn_servconn_register_command(dispatch, "CVR", cvr_cmd); | |
| 275 msn_servconn_register_command(dispatch, "INF", inf_cmd); | |
| 205 msn_servconn_register_command(dispatch, "VER", ver_cmd); | 276 msn_servconn_register_command(dispatch, "VER", ver_cmd); |
| 206 msn_servconn_register_command(dispatch, "INF", inf_cmd); | |
| 207 msn_servconn_register_command(dispatch, "XFR", xfr_cmd); | 277 msn_servconn_register_command(dispatch, "XFR", xfr_cmd); |
| 208 msn_servconn_register_command(dispatch, "_unknown_", unknown_cmd); | 278 msn_servconn_register_command(dispatch, "_unknown_", unknown_cmd); |
| 209 | 279 |
| 210 /* Save this for future use. */ | 280 /* Save this for future use. */ |
| 211 dispatch_commands = dispatch->commands; | 281 dispatch_commands = dispatch->commands; |
