Mercurial > pidgin.yaz
comparison libgaim/proxy.c @ 14356:4ae3c2913c3e
[gaim-migrate @ 17062]
Change gaim_proxy_connect_data_error() to accept a format string
and variable argument list, like printf, instead of an full
error message
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sun, 27 Aug 2006 21:26:33 +0000 |
parents | baff095b146c |
children | 92eb7a040663 |
comparison
equal
deleted
inserted
replaced
14355:fb675c9eef7a | 14356:4ae3c2913c3e |
---|---|
348 /* | 348 /* |
349 * TODO: Make sure all callers of this function pass a really really | 349 * TODO: Make sure all callers of this function pass a really really |
350 * good error_message. | 350 * good error_message. |
351 */ | 351 */ |
352 static void | 352 static void |
353 gaim_proxy_connect_data_error(GaimProxyConnectData *connect_data, const gchar *error_message) | 353 gaim_proxy_connect_data_error(GaimProxyConnectData *connect_data, const char *format, ...) |
354 { | 354 { |
355 gchar *error_message; | |
356 va_list args; | |
357 | |
358 va_start(args, format); | |
359 error_message = g_strdup_vprintf(format, args); | |
360 va_end(args); | |
361 | |
355 connect_data->connect_cb(connect_data->data, -1, error_message); | 362 connect_data->connect_cb(connect_data->data, -1, error_message); |
363 g_free(error_message); | |
364 | |
356 gaim_proxy_connect_data_destroy(connect_data); | 365 gaim_proxy_connect_data_destroy(connect_data); |
357 } | 366 } |
358 | 367 |
359 static void | 368 static void |
360 no_one_calls(gpointer data, gint source, GaimInputCondition cond) | 369 no_one_calls(gpointer data, gint source, GaimInputCondition cond) |
507 int len, headers_len, status = 0; | 516 int len, headers_len, status = 0; |
508 gboolean error; | 517 gboolean error; |
509 GaimProxyConnectData *connect_data = data; | 518 GaimProxyConnectData *connect_data = data; |
510 guchar *p; | 519 guchar *p; |
511 gsize max_read; | 520 gsize max_read; |
512 gchar *msg; | |
513 | 521 |
514 if(connect_data->read_buffer == NULL) { | 522 if(connect_data->read_buffer == NULL) { |
515 connect_data->read_buf_len = 8192; | 523 connect_data->read_buf_len = 8192; |
516 connect_data->read_buffer = g_malloc(connect_data->read_buf_len); | 524 connect_data->read_buffer = g_malloc(connect_data->read_buf_len); |
517 connect_data->read_len = 0; | 525 connect_data->read_len = 0; |
585 } | 593 } |
586 } | 594 } |
587 | 595 |
588 if (error) | 596 if (error) |
589 { | 597 { |
590 msg = g_strdup_printf("Unable to parse response from HTTP proxy: %s\n", | 598 gaim_proxy_connect_data_error(connect_data, |
599 _("Unable to parse response from HTTP proxy: %s\n"), | |
591 connect_data->read_buffer); | 600 connect_data->read_buffer); |
592 gaim_proxy_connect_data_error(connect_data, msg); | |
593 g_free(msg); | |
594 return; | 601 return; |
595 } | 602 } |
596 else if (status != 200) | 603 else if (status != 200) |
597 { | 604 { |
598 gaim_debug_error("proxy", | 605 gaim_debug_error("proxy", |
610 gchar *request; | 617 gchar *request; |
611 gchar *response; | 618 gchar *response; |
612 username = strchr(domain, '\\'); | 619 username = strchr(domain, '\\'); |
613 if (username == NULL) | 620 if (username == NULL) |
614 { | 621 { |
615 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | 622 gaim_proxy_connect_data_error(connect_data, |
616 gaim_proxy_connect_data_error(connect_data, msg); | 623 _("HTTP proxy connection error %d"), status); |
617 g_free(msg); | |
618 return; | 624 return; |
619 } | 625 } |
620 *username = '\0'; | 626 *username = '\0'; |
621 username++; | 627 username++; |
622 ntlm += strlen("Proxy-Authenticate: NTLM "); | 628 ntlm += strlen("Proxy-Authenticate: NTLM "); |
659 gchar *username; | 665 gchar *username; |
660 int request_len; | 666 int request_len; |
661 username = strchr(domain, '\\'); | 667 username = strchr(domain, '\\'); |
662 if (username == NULL) | 668 if (username == NULL) |
663 { | 669 { |
664 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | 670 gaim_proxy_connect_data_error(connect_data, |
665 gaim_proxy_connect_data_error(connect_data, msg); | 671 _("HTTP proxy connection error %d"), status); |
666 g_free(msg); | |
667 return; | 672 return; |
668 } | 673 } |
669 *username = '\0'; | 674 *username = '\0'; |
670 | 675 |
671 request_len = g_snprintf(request, sizeof(request), | 676 request_len = g_snprintf(request, sizeof(request), |
698 GAIM_INPUT_WRITE, proxy_do_write, connect_data); | 703 GAIM_INPUT_WRITE, proxy_do_write, connect_data); |
699 | 704 |
700 proxy_do_write(connect_data, connect_data->fd, cond); | 705 proxy_do_write(connect_data, connect_data->fd, cond); |
701 return; | 706 return; |
702 } else { | 707 } else { |
703 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | 708 gaim_proxy_connect_data_error(connect_data, |
704 gaim_proxy_connect_data_error(connect_data, msg); | 709 _("HTTP proxy connection error %d"), status); |
705 g_free(msg); | |
706 return; | 710 return; |
707 } | 711 } |
708 } | 712 } |
709 if(status == 403 /* Forbidden */ ) { | 713 if(status == 403 /* Forbidden */ ) { |
710 msg = g_strdup_printf(_("Access denied: HTTP proxy server forbids port %d tunnelling."), connect_data->port); | 714 gaim_proxy_connect_data_error(connect_data, |
711 gaim_proxy_connect_data_error(connect_data, msg); | 715 _("Access denied: HTTP proxy server forbids port %d tunnelling."), |
712 g_free(msg); | 716 connect_data->port); |
713 } else { | 717 } else { |
714 msg = g_strdup_printf(_("HTTP proxy connection error %d"), status); | 718 gaim_proxy_connect_data_error(connect_data, |
715 gaim_proxy_connect_data_error(connect_data, msg); | 719 _("HTTP proxy connection error %d"), status); |
716 g_free(msg); | |
717 } | 720 } |
718 } else { | 721 } else { |
719 gaim_input_remove(connect_data->inpa); | 722 gaim_input_remove(connect_data->inpa); |
720 connect_data->inpa = 0; | 723 connect_data->inpa = 0; |
721 g_free(connect_data->read_buffer); | 724 g_free(connect_data->read_buffer); |
1577 connect_data = data; | 1580 connect_data = data; |
1578 connect_data->query_data = NULL; | 1581 connect_data->query_data = NULL; |
1579 | 1582 |
1580 if (error_message != NULL) | 1583 if (error_message != NULL) |
1581 { | 1584 { |
1582 gchar *tmp; | 1585 gaim_proxy_connect_data_error(connect_data, |
1583 tmp = g_strdup_printf("Error while resolving hostname: %s\n", error_message); | 1586 _("Error while resolving hostname: %s\n"), error_message); |
1584 gaim_proxy_connect_data_error(connect_data, tmp); | |
1585 g_free(tmp); | |
1586 return; | 1587 return; |
1587 } | 1588 } |
1588 | 1589 |
1589 connect_data->hosts = hosts; | 1590 connect_data->hosts = hosts; |
1590 | 1591 |