comparison src/protocols/msn/servconn.c @ 10463:9bed28273ec7

[gaim-migrate @ 11737] Felipe Contreras fixed the MSN HTTP Method. Yay! Thanks Felipe. committer: Tailor Script <tailor@pidgin.im>
author Stu Tomlinson <stu@nosnilmot.com>
date Fri, 31 Dec 2004 16:34:22 +0000
parents 6be6da69d603
children bcfea6c3d5c9
comparison
equal deleted inserted replaced
10462:f7b32dd67bdf 10463:9bed28273ec7
41 servconn->session = session; 41 servconn->session = session;
42 servconn->cmdproc = msn_cmdproc_new(session); 42 servconn->cmdproc = msn_cmdproc_new(session);
43 servconn->cmdproc->servconn = servconn; 43 servconn->cmdproc->servconn = servconn;
44 44
45 if (session->http_method) 45 if (session->http_method)
46 { 46 servconn->httpconn = msn_httpconn_new(servconn);
47 servconn->http_data = g_new0(MsnHttpMethodData, 1);
48 servconn->http_data->virgin = TRUE;
49 }
50 47
51 servconn->num = session->servconns_count++; 48 servconn->num = session->servconns_count++;
52 49
53 return servconn; 50 return servconn;
54 } 51 }
62 { 59 {
63 servconn->wasted = TRUE; 60 servconn->wasted = TRUE;
64 return; 61 return;
65 } 62 }
66 63
64 if (servconn->destroying)
65 return;
66
67 servconn->destroying = TRUE;
68
67 if (servconn->connected) 69 if (servconn->connected)
68 msn_servconn_disconnect(servconn); 70 msn_servconn_disconnect(servconn);
69 71
70 if (servconn->http_data != NULL) 72 if (servconn->destroy_cb)
71 g_free(servconn->http_data); 73 servconn->destroy_cb(servconn);
74
75 if (servconn->httpconn != NULL)
76 msn_httpconn_destroy(servconn->httpconn);
77
78 if (servconn->host != NULL)
79 g_free(servconn->host);
72 80
73 msn_cmdproc_destroy(servconn->cmdproc); 81 msn_cmdproc_destroy(servconn->cmdproc);
74 g_free(servconn); 82 g_free(servconn);
75 } 83 }
76 84
111 gaim_connection_error(gc, tmp); 119 gaim_connection_error(gc, tmp);
112 } 120 }
113 else 121 else
114 { 122 {
115 MsnSwitchBoard *swboard; 123 MsnSwitchBoard *swboard;
116 swboard = servconn->data; 124 swboard = servconn->cmdproc->data;
117 swboard->error = MSN_SB_ERROR_CONNECTION; 125 swboard->error = MSN_SB_ERROR_CONNECTION;
118 } 126 }
119 127
120 g_free(tmp); 128 g_free(tmp);
121 } 129 }
165 session = servconn->session; 173 session = servconn->session;
166 174
167 if (servconn->connected) 175 if (servconn->connected)
168 msn_servconn_disconnect(servconn); 176 msn_servconn_disconnect(servconn);
169 177
178 if (servconn->host != NULL)
179 g_free(servconn->host);
180
181 servconn->host = g_strdup(host);
182
170 if (session->http_method) 183 if (session->http_method)
171 { 184 {
172 if (servconn->http_data->gateway_host != NULL) 185 /* HTTP Connection. */
173 g_free(servconn->http_data->gateway_host); 186
174 187 if (!servconn->httpconn->connected)
175 servconn->http_data->gateway_host = g_strdup(host); 188 msn_httpconn_connect(servconn->httpconn, host, port);
189
190 servconn->connected = TRUE;
191 servconn->cmdproc->ready = TRUE;
192 servconn->httpconn->virgin = TRUE;
193
194 /* Someone wants to know we connected. */
195 servconn->connect_cb(servconn);
196
197 return TRUE;
176 } 198 }
177 199
178 r = gaim_proxy_connect(session->account, host, port, connect_cb, 200 r = gaim_proxy_connect(session->account, host, port, connect_cb,
179 servconn); 201 servconn);
180 202
198 servconn->disconnect_cb(servconn); 220 servconn->disconnect_cb(servconn);
199 221
200 return; 222 return;
201 } 223 }
202 224
225 if (servconn->session->http_method)
226 {
227 /* Fake disconnection */
228 if (servconn->disconnect_cb != NULL)
229 servconn->disconnect_cb(servconn);
230
231 return;
232 }
233
203 if (servconn->inpa > 0) 234 if (servconn->inpa > 0)
204 { 235 {
205 gaim_input_remove(servconn->inpa); 236 gaim_input_remove(servconn->inpa);
206 servconn->inpa = 0; 237 servconn->inpa = 0;
207 } 238 }
208 239
209 close(servconn->fd); 240 close(servconn->fd);
210
211 if (servconn->http_data != NULL)
212 {
213 if (servconn->http_data->session_id != NULL)
214 g_free(servconn->http_data->session_id);
215
216 if (servconn->http_data->old_gateway_host != NULL)
217 g_free(servconn->http_data->old_gateway_host);
218
219 if (servconn->http_data->gateway_host != NULL)
220 g_free(servconn->http_data->gateway_host);
221
222 if (servconn->http_data->timer)
223 gaim_timeout_remove(servconn->http_data->timer);
224 }
225 241
226 servconn->rx_buf = NULL; 242 servconn->rx_buf = NULL;
227 servconn->rx_len = 0; 243 servconn->rx_len = 0;
228 servconn->payload_len = 0; 244 servconn->payload_len = 0;
229 245
233 if (servconn->disconnect_cb != NULL) 249 if (servconn->disconnect_cb != NULL)
234 servconn->disconnect_cb(servconn); 250 servconn->disconnect_cb(servconn);
235 } 251 }
236 252
237 void 253 void
238 msn_servconn_set_connect_cb(MsnServConn *servconn, void (*connect_cb)(MsnServConn *)) 254 msn_servconn_set_connect_cb(MsnServConn *servconn,
255 void (*connect_cb)(MsnServConn *))
239 { 256 {
240 g_return_if_fail(servconn != NULL); 257 g_return_if_fail(servconn != NULL);
241 servconn->connect_cb = connect_cb; 258 servconn->connect_cb = connect_cb;
242 } 259 }
243 260
244 void 261 void
245 msn_servconn_set_disconnect_cb(MsnServConn *servconn, void (*disconnect_cb)(MsnServConn *)) 262 msn_servconn_set_disconnect_cb(MsnServConn *servconn,
263 void (*disconnect_cb)(MsnServConn *))
246 { 264 {
247 g_return_if_fail(servconn != NULL); 265 g_return_if_fail(servconn != NULL);
248 266
249 servconn->disconnect_cb = disconnect_cb; 267 servconn->disconnect_cb = disconnect_cb;
268 }
269
270 void
271 msn_servconn_set_destroy_cb(MsnServConn *servconn,
272 void (*destroy_cb)(MsnServConn *))
273 {
274 g_return_if_fail(servconn != NULL);
275
276 servconn->destroy_cb = destroy_cb;
250 } 277 }
251 278
252 static void 279 static void
253 failed_io(MsnServConn *servconn) 280 failed_io(MsnServConn *servconn)
254 { 281 {
264 { 291 {
265 size_t ret = FALSE; 292 size_t ret = FALSE;
266 293
267 g_return_val_if_fail(servconn != NULL, 0); 294 g_return_val_if_fail(servconn != NULL, 0);
268 295
269 if (servconn->http_data == NULL) 296 if (!servconn->session->http_method)
270 { 297 {
271 switch (servconn->type) 298 switch (servconn->type)
272 { 299 {
273 case MSN_SERVER_NS: 300 case MSN_SERVER_NS:
274 case MSN_SERVER_SB: 301 case MSN_SERVER_SB:
283 break; 310 break;
284 } 311 }
285 } 312 }
286 else 313 else
287 { 314 {
288 ret = msn_http_servconn_write(servconn, buf, len, 315 ret = msn_httpconn_write(servconn->httpconn, buf, len);
289 servconn->http_data->server_type);
290 } 316 }
291 317
292 if (ret == -1) 318 if (ret == -1)
293 { 319 {
294 servconn->cmdproc->error = MSN_ERROR_WRITE; 320 servconn->cmdproc->error = MSN_ERROR_WRITE;
324 buf[len] = '\0'; 350 buf[len] = '\0';
325 351
326 servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1); 352 servconn->rx_buf = g_realloc(servconn->rx_buf, len + servconn->rx_len + 1);
327 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1); 353 memcpy(servconn->rx_buf + servconn->rx_len, buf, len + 1);
328 servconn->rx_len += len; 354 servconn->rx_len += len;
329
330 if (session->http_method)
331 {
332 char *result_msg = NULL;
333 size_t result_len = 0;
334 gboolean error;
335 char *tmp;
336
337 tmp = g_strndup(servconn->rx_buf, servconn->rx_len);
338
339 if (!msn_http_servconn_parse_data(servconn, tmp, servconn->rx_len,
340 &result_msg, &result_len,
341 &error))
342 {
343 g_free(tmp);
344 return;
345 }
346
347 g_free(tmp);
348
349 if (error)
350 {
351 gaim_connection_error(gaim_account_get_connection(session->account),
352 _("Received HTTP error. Please report this."));
353
354 return;
355 }
356
357 if (servconn->http_data->session_id != NULL &&
358 !strcmp(servconn->http_data->session_id, "close"))
359 {
360 msn_servconn_destroy(servconn);
361
362 return;
363 }
364
365 #if 0
366 if (strcmp(servconn->http_data->gateway_ip,
367 msn_servconn_get_server(servconn)) != 0)
368 {
369 int i;
370
371 /* Evil hackery. I promise to remove it, even though I can't. */
372
373 servconn->connected = FALSE;
374
375 if (servconn->inpa)
376 gaim_input_remove(servconn->inpa);
377
378 close(servconn->fd);
379
380 i = gaim_proxy_connect(session->account, servconn->host,
381 servconn->port, read_cb, servconn);
382
383 if (i == 0)
384 servconn->connected = TRUE;
385 }
386 #endif
387
388 g_free(servconn->rx_buf);
389 servconn->rx_buf = result_msg;
390 servconn->rx_len = result_len;
391 }
392 355
393 end = old_rx_buf = servconn->rx_buf; 356 end = old_rx_buf = servconn->rx_buf;
394 357
395 servconn->processing = TRUE; 358 servconn->processing = TRUE;
396 359