Mercurial > pidgin
annotate src/protocols/msn/dispatch.c @ 5918:7134be4a319f
[gaim-migrate @ 6358]
Okay, adding buddies should no longer stick numbers in your list. What on
hell was I thinking?
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Wed, 18 Jun 2003 04:15:45 +0000 |
parents | 952710ac6635 |
children | 156e6643f9db |
rev | line source |
---|---|
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 | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
30 ver_cmd(MsnServConn *servconn, const char *command, const char **params, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
31 size_t param_count) |
5309 | 32 { |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
33 GaimConnection *gc = servconn->session->account->gc; |
5309 | 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) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
45 gaim_connection_error(gc, _("Protocol not supported")); |
5309 | 46 |
47 return FALSE; | |
48 } | |
49 | |
50 if (!msn_servconn_send_command(servconn, "INF", NULL)) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
51 gaim_connection_error(gc, _("Unable to request INF\n")); |
5309 | 52 |
53 return FALSE; | |
54 } | |
55 | |
56 return TRUE; | |
57 } | |
58 | |
59 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
60 inf_cmd(MsnServConn *servconn, const char *command, const char **params, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
61 size_t param_count) |
5309 | 62 { |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
63 GaimAccount *account = servconn->session->account; |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
64 GaimConnection *gc = gaim_account_get_connection(account); |
5309 | 65 char outparams[MSN_BUF_LEN]; |
66 | |
67 if (strcmp(params[1], "MD5")) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
68 gaim_connection_error(gc, _("Unable to login using MD5")); |
5309 | 69 |
70 return FALSE; | |
71 } | |
72 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
73 g_snprintf(outparams, sizeof(outparams), "MD5 I %s", |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
74 gaim_account_get_username(account)); |
5309 | 75 |
76 if (!msn_servconn_send_command(servconn, "USR", outparams)) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
77 gaim_connection_error(gc, _("Unable to send USR\n")); |
5309 | 78 |
79 return FALSE; | |
80 } | |
81 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
82 gaim_connection_update_progress(gc, _("Requesting to send password"), |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
83 3, MSN_CONNECT_STEPS); |
5309 | 84 |
85 return TRUE; | |
86 } | |
87 | |
88 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
89 xfr_cmd(MsnServConn *servconn, const char *command, const char **params, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
90 size_t param_count) |
5309 | 91 { |
92 MsnSession *session = servconn->session; | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
93 GaimConnection *gc = servconn->session->account->gc; |
5309 | 94 char *host; |
95 int port; | |
96 char *c; | |
97 | |
98 if (param_count < 2 || strcmp(params[1], "NS")) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
99 gaim_connection_error(gc, _("Got invalid XFR\n")); |
5309 | 100 |
101 return FALSE; | |
102 } | |
103 | |
104 host = g_strdup(params[2]); | |
105 | |
106 if ((c = strchr(host, ':')) != NULL) { | |
107 *c = '\0'; | |
108 | |
109 port = atoi(c + 1); | |
110 } | |
111 else | |
112 port = 1863; | |
113 | |
114 session->passport_info.sl = time(NULL); | |
115 | |
116 /* Disconnect from here. */ | |
117 msn_servconn_destroy(servconn); | |
118 session->dispatch_conn = NULL; | |
119 | |
120 /* Now connect to the switchboard. */ | |
121 session->notification_conn = msn_notification_new(session, host, port); | |
122 | |
123 g_free(host); | |
124 | |
125 if (!msn_servconn_connect(session->notification_conn)) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
126 gaim_connection_error(gc, _("Unable to transfer")); |
5309 | 127 } |
128 | |
129 return FALSE; | |
130 } | |
131 | |
132 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
133 unknown_cmd(MsnServConn *servconn, const char *command, const char **params, |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
134 size_t param_count) |
5309 | 135 { |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
136 GaimConnection *gc = servconn->session->account->gc; |
5309 | 137 |
138 if (isdigit(*command)) { | |
139 char buf[4]; | |
140 | |
141 strncpy(buf, command, 4); | |
142 buf[4] = '\0'; | |
143 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
144 gaim_connection_error(gc, (char *)msn_error_get_text(atoi(buf))); |
5309 | 145 } |
146 else | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
147 gaim_connection_error(gc, _("Unable to parse message.")); |
5309 | 148 |
149 return FALSE; | |
150 } | |
151 | |
152 static gboolean | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
153 connect_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 154 { |
155 MsnServConn *dispatch = data; | |
156 MsnSession *session = dispatch->session; | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
157 GaimConnection *gc = session->account->gc; |
5309 | 158 |
159 if (source == -1) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
160 gaim_connection_error(session->account->gc, _("Unable to connect")); |
5309 | 161 return FALSE; |
162 } | |
163 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
164 gaim_connection_update_progress(gc, _("Connecting"), 1, MSN_CONNECT_STEPS); |
5309 | 165 |
166 if (dispatch->fd != source) | |
167 dispatch->fd = source; | |
168 | |
169 if (!msn_servconn_send_command(dispatch, "VER", | |
170 "MSNP7 MSNP6 MSNP5 MSNP4 CVR0")) { | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
171 gaim_connection_error(gc, _("Unable to write to server")); |
5309 | 172 return FALSE; |
173 } | |
174 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
175 gaim_connection_update_progress(gc, _("Syncing with server"), |
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
176 2, MSN_CONNECT_STEPS); |
5309 | 177 |
178 return TRUE; | |
179 } | |
180 | |
181 static void | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
182 failed_read_cb(gpointer data, gint source, GaimInputCondition cond) |
5309 | 183 { |
184 MsnServConn *dispatch = data; | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
185 GaimConnection *gc; |
5309 | 186 |
187 gc = dispatch->session->account->gc; | |
188 | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
189 gaim_connection_error(gc, _("Error reading from server")); |
5309 | 190 } |
191 | |
192 MsnServConn * | |
193 msn_dispatch_new(MsnSession *session, const char *server, int port) | |
194 { | |
195 MsnServConn *dispatch; | |
196 | |
197 dispatch = msn_servconn_new(session); | |
198 | |
199 msn_servconn_set_server(dispatch, server, port); | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
200 msn_servconn_set_connect_cb(dispatch, connect_cb); |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
201 msn_servconn_set_failed_read_cb(dispatch, failed_read_cb); |
5309 | 202 |
203 if (dispatch_commands == NULL) { | |
204 /* Register the command callbacks. */ | |
5793
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
205 msn_servconn_register_command(dispatch, "VER", ver_cmd); |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
206 msn_servconn_register_command(dispatch, "INF", inf_cmd); |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
207 msn_servconn_register_command(dispatch, "XFR", xfr_cmd); |
952710ac6635
[gaim-migrate @ 6218]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
208 msn_servconn_register_command(dispatch, "_unknown_", unknown_cmd); |
5309 | 209 |
210 /* Save this for future use. */ | |
211 dispatch_commands = dispatch->commands; | |
212 } | |
213 else { | |
214 g_hash_table_destroy(dispatch->commands); | |
215 | |
216 dispatch->commands = dispatch_commands; | |
217 } | |
218 | |
219 return dispatch; | |
220 } | |
221 |