comparison src/neon/neon.c @ 2361:c831816c0b87

Add support for proxy_use_auth.
author William Pitcock <nenolod@atheme.org>
date Mon, 04 Feb 2008 22:55:38 -0600
parents 1a4f8ea5eb2a
children f0a895a1e50d
comparison
equal deleted inserted replaced
2360:ead24454f4b7 2361:c831816c0b87
478 478
479 /* 479 /*
480 * ----- 480 * -----
481 */ 481 */
482 482
483 static int neon_proxy_auth_cb(void *userdata, const char *realm, int attempt, char *username, char *password) {
484
485 ConfigDb *db;
486 gchar *value = NULL;
487
488 _ENTER;
489
490 if ((db = aud_cfg_db_open()) == NULL) {
491 _DEBUG("<%p> configdb failed to open!", userdata);
492 _LEAVE -1;
493 }
494
495 aud_cfg_db_get_string(db, NULL, "proxy_user", &value);
496 if (!value) {
497 _DEBUG("<%p> proxy_auth requested but no proxy_user", userdata);
498 _LEAVE -1;
499 }
500 g_strlcpy(username, value, NE_ABUFSIZ);
501 value = NULL;
502
503 aud_cfg_db_get_string(db, NULL, "proxy_pass", &value);
504 if (!value) {
505 _DEBUG("<%p> proxy_auth requested but no proxy_pass", userdata);
506 _LEAVE -1;
507 }
508 g_strlcpy(password, value, NE_ABUFSIZ);
509 value = NULL;
510
511 _LEAVE attempt;
512 }
513
514 /*
515 * -----
516 */
517
483 static int open_request(struct neon_handle* handle, unsigned long startbyte) { 518 static int open_request(struct neon_handle* handle, unsigned long startbyte) {
484 519
485 int ret; 520 int ret;
486 const ne_status* status; 521 const ne_status* status;
487 ne_uri* rediruri; 522 ne_uri* rediruri;
572 ConfigDb* db; 607 ConfigDb* db;
573 gchar* proxy_host; 608 gchar* proxy_host;
574 gchar* proxy_port_s; 609 gchar* proxy_port_s;
575 gchar* endptr; 610 gchar* endptr;
576 unsigned int proxy_port = 0; 611 unsigned int proxy_port = 0;
577 gboolean use_proxy; 612 gboolean use_proxy, use_proxy_auth;
578 613
579 _ENTER; 614 _ENTER;
580 615
581 db = aud_cfg_db_open(); 616 db = aud_cfg_db_open();
582 if (FALSE == aud_cfg_db_get_bool(db, NULL, "use_proxy", &use_proxy)) { 617 if (FALSE == aud_cfg_db_get_bool(db, NULL, "use_proxy", &use_proxy)) {
583 use_proxy = FALSE; 618 use_proxy = FALSE;
619 }
620
621 if (FALSE == aud_cfg_db_get_bool(db, NULL, "use_proxy_auth", &use_proxy_auth)) {
622 use_proxy_auth = FALSE;
584 } 623 }
585 624
586 if (use_proxy) { 625 if (use_proxy) {
587 if (FALSE == aud_cfg_db_get_string(db, NULL, "proxy_host", &proxy_host)) { 626 if (FALSE == aud_cfg_db_get_string(db, NULL, "proxy_host", &proxy_host)) {
588 _ERROR("<%p> Could not read proxy host, disabling proxy use", handle); 627 _ERROR("<%p> Could not read proxy host, disabling proxy use", handle);
631 ne_set_useragent(handle->session, "Audacious/1.4.0"); 670 ne_set_useragent(handle->session, "Audacious/1.4.0");
632 671
633 if (use_proxy) { 672 if (use_proxy) {
634 _DEBUG("<%p> Using proxy: %s:%d", handle, proxy_host, proxy_port); 673 _DEBUG("<%p> Using proxy: %s:%d", handle, proxy_host, proxy_port);
635 ne_session_proxy(handle->session, proxy_host, proxy_port); 674 ne_session_proxy(handle->session, proxy_host, proxy_port);
675
676 if (use_proxy_auth) {
677 ne_set_proxy_auth(handle->session, neon_proxy_auth_cb, handle);
678 }
636 } 679 }
637 680
638 _DEBUG("<%p> Creating request", handle); 681 _DEBUG("<%p> Creating request", handle);
639 ret = open_request(handle, startbyte); 682 ret = open_request(handle, startbyte);
640 683