comparison src/protocols/msn/servconn.c @ 7288:ff9127038a5a

[gaim-migrate @ 7869] It doesn't completely work yet, but this is the beginnings of the MSN HTTP port 80 connect method. I don't have it set so it can be enabled, so it's harmless to commit this now, but I want a second set of eyes, and I also want to do other MSN work without dealing with hand-merging patches. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 17 Oct 2003 14:57:59 +0000
parents bd433a45a463
children 43803965ef45
comparison
equal deleted inserted replaced
7287:3a41c3f80228 7288:ff9127038a5a
184 static void 184 static void
185 connect_cb(gpointer data, gint source, GaimInputCondition cond) 185 connect_cb(gpointer data, gint source, GaimInputCondition cond)
186 { 186 {
187 MsnServConn *servconn = data; 187 MsnServConn *servconn = data;
188 188
189 gaim_debug_info("msn", "In servconn's connect_cb\n");
189 if (servconn->connect_cb(data, source, cond)) 190 if (servconn->connect_cb(data, source, cond))
190 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ, 191 servconn->inpa = gaim_input_add(servconn->fd, GAIM_INPUT_READ,
191 servconn->login_cb, data); 192 servconn->login_cb, data);
192 } 193 }
193 194
201 servconn = g_new0(MsnServConn, 1); 202 servconn = g_new0(MsnServConn, 1);
202 203
203 servconn->login_cb = msn_servconn_parse_data; 204 servconn->login_cb = msn_servconn_parse_data;
204 servconn->session = session; 205 servconn->session = session;
205 206
207 if (session->http_method)
208 {
209 servconn->http_data = g_new0(MsnHttpMethodData, 1);
210 servconn->http_data->virgin = TRUE;
211 }
212
206 servconn->commands = g_hash_table_new_full(g_str_hash, g_str_equal, 213 servconn->commands = g_hash_table_new_full(g_str_hash, g_str_equal,
207 g_free, NULL); 214 g_free, NULL);
208 215
209 servconn->msg_types = g_hash_table_new_full(g_str_hash, g_str_equal, 216 servconn->msg_types = g_hash_table_new_full(g_str_hash, g_str_equal,
210 g_free, NULL); 217 g_free, NULL);
215 } 222 }
216 223
217 gboolean 224 gboolean
218 msn_servconn_connect(MsnServConn *servconn) 225 msn_servconn_connect(MsnServConn *servconn)
219 { 226 {
227 MsnSession *session;
220 int i; 228 int i;
221 229
222 g_return_val_if_fail(servconn != NULL, FALSE); 230 g_return_val_if_fail(servconn != NULL, FALSE);
223 g_return_val_if_fail(servconn->server != NULL, FALSE); 231 g_return_val_if_fail(servconn->server != NULL, FALSE);
224 g_return_val_if_fail(!servconn->connected, TRUE); 232 g_return_val_if_fail(!servconn->connected, TRUE);
225 233
226 i = gaim_proxy_connect(servconn->session->account, servconn->server, 234 session = servconn->session;
227 servconn->port, connect_cb, servconn); 235
236 if (session->http_method)
237 {
238 servconn->http_data->gateway_ip = g_strdup(servconn->server);
239 servconn->port = 80;
240 }
241
242 i = gaim_proxy_connect(session->account, servconn->server,
243 servconn->port, connect_cb, servconn);
228 244
229 if (i == 0) 245 if (i == 0)
230 servconn->connected = TRUE; 246 servconn->connected = TRUE;
231 247
232 return servconn->connected; 248 return servconn->connected;
233 } 249 }
234 250
235 void 251 void
236 msn_servconn_disconnect(MsnServConn *servconn) 252 msn_servconn_disconnect(MsnServConn *servconn)
237 { 253 {
254 MsnSession *session;
255
238 g_return_if_fail(servconn != NULL); 256 g_return_if_fail(servconn != NULL);
239 g_return_if_fail(servconn->connected); 257 g_return_if_fail(servconn->connected);
258
259 session = servconn->session;
240 260
241 if (servconn->inpa) 261 if (servconn->inpa)
242 gaim_input_remove(servconn->inpa); 262 gaim_input_remove(servconn->inpa);
243 263
244 close(servconn->fd); 264 close(servconn->fd);
265
266 if (servconn->http_data != NULL)
267 {
268 if (servconn->http_data->session_id != NULL)
269 g_free(servconn->http_data->session_id);
270
271 if (servconn->http_data->old_gateway_ip != NULL)
272 g_free(servconn->http_data->old_gateway_ip);
273
274 if (servconn->http_data->gateway_ip != NULL)
275 g_free(servconn->http_data->gateway_ip);
276
277 if (servconn->http_data->timer)
278 g_source_remove(servconn->http_data->timer);
279
280 g_free(servconn->http_data);
281 }
245 282
246 if (servconn->rxqueue != NULL) 283 if (servconn->rxqueue != NULL)
247 g_free(servconn->rxqueue); 284 g_free(servconn->rxqueue);
248 285
249 while (servconn->txqueue != NULL) { 286 while (servconn->txqueue != NULL) {
338 g_return_val_if_fail(servconn != NULL, 0); 375 g_return_val_if_fail(servconn != NULL, 0);
339 376
340 gaim_debug(GAIM_DEBUG_MISC, "msn", "C: %s%s", buf, 377 gaim_debug(GAIM_DEBUG_MISC, "msn", "C: %s%s", buf,
341 (*(buf + size - 1) == '\n' ? "" : "\n")); 378 (*(buf + size - 1) == '\n' ? "" : "\n"));
342 379
343 return write(servconn->fd, buf, size); 380 if (servconn->session->http_method)
381 return msn_http_servconn_write(servconn, buf, size,
382 servconn->http_data->server_type);
383 else
384 return write(servconn->fd, buf, size);
344 } 385 }
345 386
346 gboolean 387 gboolean
347 msn_servconn_send_command(MsnServConn *servconn, const char *command, 388 msn_servconn_send_command(MsnServConn *servconn, const char *command,
348 const char *params) 389 const char *params)
387 GSList *l; 428 GSList *l;
388 429
389 g_return_if_fail(servconn != NULL); 430 g_return_if_fail(servconn != NULL);
390 g_return_if_fail(msg != NULL); 431 g_return_if_fail(msg != NULL);
391 432
392 for (l = servconn->msg_queue; l != NULL; l = l->next) { 433 for (l = servconn->msg_queue; l != NULL; l = l->next)
434 {
393 entry = l->data; 435 entry = l->data;
394 436
395 if (entry->msg == msg) 437 if (entry->msg == msg)
396 break; 438 break;
397 439
446 gboolean cont = TRUE; 488 gboolean cont = TRUE;
447 int len; 489 int len;
448 490
449 len = read(servconn->fd, buf, sizeof(buf)); 491 len = read(servconn->fd, buf, sizeof(buf));
450 492
451 if (len <= 0) { 493 if (len <= 0)
494 {
452 if (servconn->failed_read_cb != NULL) 495 if (servconn->failed_read_cb != NULL)
453 servconn->failed_read_cb(data, source, cond); 496 servconn->failed_read_cb(data, source, cond);
454 497
455 return; 498 return;
456 } 499 }
457 500
458 servconn->rxqueue = g_realloc(servconn->rxqueue, len + servconn->rxlen); 501 servconn->rxqueue = g_realloc(servconn->rxqueue, len + servconn->rxlen);
459 memcpy(servconn->rxqueue + servconn->rxlen, buf, len); 502 memcpy(servconn->rxqueue + servconn->rxlen, buf, len);
460 servconn->rxlen += len; 503 servconn->rxlen += len;
461 504
462 while (cont) { 505 if (session->http_method)
463 if (servconn->parsing_multiline) { 506 {
507 char *result_msg = NULL;
508 size_t result_len = 0;
509 gboolean error;
510 char *tmp;
511
512 tmp = g_strndup(servconn->rxqueue, servconn->rxlen);
513
514 if (!msn_http_servconn_parse_data(servconn, tmp,
515 servconn->rxlen, &result_msg,
516 &result_len, &error))
517 {
518 g_free(tmp);
519 return;
520 }
521
522 g_free(tmp);
523
524 if (error)
525 {
526 gaim_connection_error(
527 gaim_account_get_connection(session->account),
528 _("Received HTTP error. Please report this."));
529
530 return;
531 }
532
533 if (servconn->http_data->session_id != NULL &&
534 !strcmp(servconn->http_data->session_id, "close"))
535 {
536 msn_servconn_destroy(servconn);
537
538 return;
539 }
540
541 #if 0
542 if (strcmp(servconn->http_data->gateway_ip,
543 msn_servconn_get_server(servconn)) != 0)
544 {
545 int i;
546
547 /* Evil hackery. I promise to remove it, even though I can't. */
548
549 servconn->connected = FALSE;
550
551 if (servconn->inpa)
552 gaim_input_remove(servconn->inpa);
553
554 close(servconn->fd);
555
556 i = gaim_proxy_connect(session->account, servconn->server,
557 servconn->port, servconn->login_cb,
558 servconn);
559
560 if (i == 0)
561 servconn->connected = TRUE;
562 }
563 #endif
564
565 g_free(servconn->rxqueue);
566 servconn->rxqueue = result_msg;
567 servconn->rxlen = result_len;
568 }
569
570 while (cont)
571 {
572 if (servconn->parsing_multiline)
573 {
464 char *msg; 574 char *msg;
465 575
466 if (servconn->rxlen == 0) 576 if (servconn->rxlen == 0)
467 break; 577 break;
468 578
537 647
538 g_free(cmd); 648 g_free(cmd);
539 } 649 }
540 } 650 }
541 } 651 }
542