comparison src/protocols/msn/servconn.c @ 9158:c30d81b4dd22

[gaim-migrate @ 9942] Patch from Felipe Contreras to sync our MSN prpl with what's in his tree. He says this may fix a couple bugs, but the important thing is the restructuring of how MsnMessages work. Lots of style changes and other stuff as well. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Tue, 01 Jun 2004 06:42:20 +0000
parents 6dd02df922b4
children 43ea2b858112
comparison
equal deleted inserted replaced
9157:bd1ea0a717d7 9158:c30d81b4dd22
32 char *tmp; 32 char *tmp;
33 char *cmd; 33 char *cmd;
34 34
35 const char *names[] = { "Notification", "Switchboard" }; 35 const char *names[] = { "Notification", "Switchboard" };
36 const char *name; 36 const char *name;
37 37
38 gc = gaim_account_get_connection(servconn->session->account); 38 gc = gaim_account_get_connection(servconn->session->account);
39 name = names[servconn->type]; 39 name = names[servconn->type];
40 40
41 switch (servconn->cmdproc->error) 41 switch (servconn->cmdproc->error)
42 { 42 {
47 case MSN_ERROR_WRITE: 47 case MSN_ERROR_WRITE:
48 tmp = g_strdup_printf(_("Error writing to %s server"), name); 48 tmp = g_strdup_printf(_("Error writing to %s server"), name);
49 break; 49 break;
50 case MSN_ERROR_READ: 50 case MSN_ERROR_READ:
51 cmd = servconn->cmdproc->last_trans; 51 cmd = servconn->cmdproc->last_trans;
52 tmp = g_strdup_printf(_("Error reading from %s server. Last" 52 tmp = g_strdup_printf(_("Error reading from %s server"), name);
53 "command was:\n %s"), name, cmd);
54 gaim_debug_info("msn", "Last command was: %s\n", cmd); 53 gaim_debug_info("msn", "Last command was: %s\n", cmd);
55 break; 54 break;
56 default: 55 default:
57 tmp = g_strdup_printf(_("Unknown error from %s server"), name); 56 tmp = g_strdup_printf(_("Unknown error from %s server"), name);
58 break; 57 break;
59 } 58 }
60 59
61 gaim_connection_error(gc, tmp); 60 gaim_connection_error(gc, tmp);
62 61
63 g_free(tmp); 62 g_free(tmp);
64 } 63 }
65 64
66 static void 65 static void
67 connect_cb(gpointer data, gint source, GaimInputCondition cond) 66 connect_cb(gpointer data, gint source, GaimInputCondition cond)
68 { 67 {
69 MsnServConn *servconn = data; 68 MsnServConn *servconn = data;
70
71 gaim_debug_info("msn", "In servconn's connect_cb\n");
72 69
73 servconn->fd = source; 70 servconn->fd = source;
74 71
75 if (source > 0) 72 if (source > 0)
76 { 73 {
85 show_error(servconn); 82 show_error(servconn);
86 } 83 }
87 } 84 }
88 85
89 MsnServConn * 86 MsnServConn *
90 msn_servconn_new(MsnSession *session, MsnServerType type) 87 msn_servconn_new(MsnSession *session, MsnServConnType type)
91 { 88 {
92 MsnServConn *servconn; 89 MsnServConn *servconn;
93 90
94 g_return_val_if_fail(session != NULL, NULL); 91 g_return_val_if_fail(session != NULL, NULL);
95 92
111 session->servconns = g_list_append(session->servconns, servconn); 108 session->servconns = g_list_append(session->servconns, servconn);
112 109
113 return servconn; 110 return servconn;
114 } 111 }
115 112
113 void
114 msn_servconn_destroy(MsnServConn *servconn)
115 {
116 MsnSession *session;
117
118 g_return_if_fail(servconn != NULL);
119
120 if (servconn->processing)
121 {
122 servconn->wasted = TRUE;
123 return;
124 }
125
126 session = servconn->session;
127
128 session->servconns = g_list_remove(session->servconns, servconn);
129
130 if (servconn->connected)
131 msn_servconn_disconnect(servconn);
132
133 msn_cmdproc_destroy(servconn->cmdproc);
134
135 g_free(servconn);
136 }
137
116 gboolean 138 gboolean
117 msn_servconn_connect(MsnServConn *servconn, const char *host, int port) 139 msn_servconn_connect(MsnServConn *servconn, const char *host, int port)
118 { 140 {
119 MsnSession *session; 141 MsnSession *session;
120 int i; 142 int r;
121 143
122 g_return_val_if_fail(servconn != NULL, FALSE); 144 g_return_val_if_fail(servconn != NULL, FALSE);
123 g_return_val_if_fail(host != NULL, FALSE); 145 g_return_val_if_fail(host != NULL, FALSE);
124 g_return_val_if_fail(port > 0, FALSE); 146 g_return_val_if_fail(port > 0, FALSE);
125 147
128 if (servconn->connected) 150 if (servconn->connected)
129 msn_servconn_disconnect(servconn); 151 msn_servconn_disconnect(servconn);
130 152
131 if (session->http_method) 153 if (session->http_method)
132 { 154 {
133 servconn->http_data->gateway_ip = g_strdup(host); 155 servconn->http_data->gateway_host = g_strdup(host);
134 } 156 }
135 157
136 i = gaim_proxy_connect(session->account, host, port, connect_cb, 158 r = gaim_proxy_connect(session->account, host, port, connect_cb,
137 servconn); 159 servconn);
138 160
139 if (i == 0) 161 if (r == 0)
140 servconn->connected = TRUE; 162 servconn->connected = TRUE;
141 163
142 return servconn->connected; 164 return servconn->connected;
143 } 165 }
144 166
163 if (servconn->http_data != NULL) 185 if (servconn->http_data != NULL)
164 { 186 {
165 if (servconn->http_data->session_id != NULL) 187 if (servconn->http_data->session_id != NULL)
166 g_free(servconn->http_data->session_id); 188 g_free(servconn->http_data->session_id);
167 189
168 if (servconn->http_data->old_gateway_ip != NULL) 190 if (servconn->http_data->old_gateway_host != NULL)
169 g_free(servconn->http_data->old_gateway_ip); 191 g_free(servconn->http_data->old_gateway_host);
170 192
171 if (servconn->http_data->gateway_ip != NULL) 193 if (servconn->http_data->gateway_host != NULL)
172 g_free(servconn->http_data->gateway_ip); 194 g_free(servconn->http_data->gateway_host);
173 195
174 if (servconn->http_data->timer) 196 if (servconn->http_data->timer)
175 gaim_timeout_remove(servconn->http_data->timer); 197 gaim_timeout_remove(servconn->http_data->timer);
176 198
177 g_free(servconn->http_data); 199 g_free(servconn->http_data);
200 servconn->http_data = NULL;
178 } 201 }
179 202
180 servconn->rx_len = 0; 203 servconn->rx_len = 0;
181 servconn->payload_len = 0; 204 servconn->payload_len = 0;
182 205
183 if (servconn->disconnect_cb != NULL) 206 if (servconn->disconnect_cb != NULL)
184 servconn->disconnect_cb(servconn); 207 servconn->disconnect_cb(servconn);
185 208
186 servconn->connected = FALSE; 209 servconn->connected = FALSE;
187 }
188
189 void
190 msn_servconn_destroy(MsnServConn *servconn)
191 {
192 MsnSession *session;
193
194 g_return_if_fail(servconn != NULL);
195
196 if (servconn->processing)
197 {
198 servconn->wasted = TRUE;
199 return;
200 }
201
202 session = servconn->session;
203
204 session->servconns = g_list_remove(session->servconns, servconn);
205
206 if (servconn->connected)
207 msn_servconn_disconnect(servconn);
208
209 msn_cmdproc_destroy(servconn->cmdproc);
210 g_free(servconn);
211 } 210 }
212 211
213 void 212 void
214 msn_servconn_set_connect_cb(MsnServConn *servconn, 213 msn_servconn_set_connect_cb(MsnServConn *servconn,
215 gboolean (*connect_cb)(MsnServConn *servconn)) 214 gboolean (*connect_cb)(MsnServConn *servconn))
230 } 229 }
231 230
232 static void 231 static void
233 failed_io(MsnServConn *servconn) 232 failed_io(MsnServConn *servconn)
234 { 233 {
234 g_return_if_fail(servconn != NULL);
235
235 show_error(servconn); 236 show_error(servconn);
236 237
237 msn_servconn_disconnect(servconn); 238 msn_servconn_disconnect(servconn);
238 } 239 }
239 240
240 size_t 241 size_t
241 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t size) 242 msn_servconn_write(MsnServConn *servconn, const char *buf, size_t len)
242 { 243 {
243 size_t ret = FALSE; 244 size_t ret = FALSE;
244 245
245 g_return_val_if_fail(servconn != NULL, 0); 246 g_return_val_if_fail(servconn != NULL, 0);
246 247
247 if (servconn->session->http_method) 248 if (servconn->session->http_method)
248 { 249 {
249 ret = msn_http_servconn_write(servconn, buf, size, 250 ret = msn_http_servconn_write(servconn, buf, len,
250 servconn->http_data->server_type); 251 servconn->http_data->server_type);
251 } 252 }
252 else 253 else
253 { 254 {
254 ret = write(servconn->fd, buf, size); 255 ret = write(servconn->fd, buf, len);
255 } 256 }
256 257
257 if (ret < 0) 258 if (ret < 0)
258 { 259 {
259 servconn->cmdproc->error = MSN_ERROR_WRITE; 260 servconn->cmdproc->error = MSN_ERROR_WRITE;
274 275
275 servconn = data; 276 servconn = data;
276 session = servconn->session; 277 session = servconn->session;
277 278
278 len = read(servconn->fd, buf, sizeof(buf) - 1); 279 len = read(servconn->fd, buf, sizeof(buf) - 1);
280 buf[len] = '\0';
279 281
280 if (len <= 0) 282 if (len <= 0)
281 { 283 {
282 servconn->cmdproc->error = MSN_ERROR_READ; 284 servconn->cmdproc->error = MSN_ERROR_READ;
283 285
297 gboolean error; 299 gboolean error;
298 char *tmp; 300 char *tmp;
299 301
300 tmp = g_strndup(servconn->rx_buf, servconn->rx_len); 302 tmp = g_strndup(servconn->rx_buf, servconn->rx_len);
301 303
302 if (!msn_http_servconn_parse_data(servconn, tmp, 304 if (!msn_http_servconn_parse_data(servconn, tmp, servconn->rx_len,
303 servconn->rx_len, &result_msg, 305 &result_msg, &result_len,
304 &result_len, &error)) 306 &error))
305 { 307 {
306 g_free(tmp); 308 g_free(tmp);
307 return; 309 return;
308 } 310 }
309 311
310 g_free(tmp); 312 g_free(tmp);
311 313
312 if (error) 314 if (error)
313 { 315 {
314 gaim_connection_error( 316 gaim_connection_error(gaim_account_get_connection(session->account),
315 gaim_account_get_connection(session->account), 317 _("Received HTTP error. Please report this."));
316 _("Received HTTP error. Please report this."));
317 318
318 return; 319 return;
319 } 320 }
320 321
321 if (servconn->http_data->session_id != NULL && 322 if (servconn->http_data->session_id != NULL &&
340 gaim_input_remove(servconn->inpa); 341 gaim_input_remove(servconn->inpa);
341 342
342 close(servconn->fd); 343 close(servconn->fd);
343 344
344 i = gaim_proxy_connect(session->account, servconn->host, 345 i = gaim_proxy_connect(session->account, servconn->host,
345 servconn->port, servconn->login_cb, 346 servconn->port, read_cb, servconn);
346 servconn);
347 347
348 if (i == 0) 348 if (i == 0)
349 servconn->connected = TRUE; 349 servconn->connected = TRUE;
350 } 350 }
351 #endif 351 #endif