From: Jaroslav Kysela Date: Mon, 12 Mar 2018 15:07:10 +0000 (+0100) Subject: config: allow to override http user agent in the base config, fixes #3964 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ef96199c0cf82484981b4375f89969a65ed6f873;p=thirdparty%2Ftvheadend.git config: allow to override http user agent in the base config, fixes #3964 --- diff --git a/src/config.c b/src/config.c index 4ade4756c..d19521035 100644 --- a/src/config.c +++ b/src/config.c @@ -1677,7 +1677,8 @@ config_check ( void ) static int config_newcfg = 0; void -config_boot ( const char *path, gid_t gid, uid_t uid ) +config_boot + ( const char *path, gid_t gid, uid_t uid, const char *http_user_agent ) { struct stat st; char buf[1024]; @@ -1780,6 +1781,12 @@ config_boot ( const char *path, gid_t gid, uid_t uid ) config.realm = strdup("tvheadend"); if (tvh_str_default(config.http_server_name, NULL) == NULL) config.http_server_name = strdup("HTS/tvheadend"); + if ((config.http_user_agent && + strncmp(config.http_user_agent, "TVHeadend/", 10) == 0) || + tvh_str_default(config.http_user_agent, NULL) == NULL) { + snprintf(buf, sizeof(buf), "TVHeadend/%s", tvheadend_version); + tvh_str_set(&config.http_user_agent, buf); + } if (!config_scanfile_ok) config_muxconfpath_notify(&config.idnode, NULL); } @@ -1820,6 +1827,7 @@ void config_done ( void ) free(config.wizard); free(config.full_version); free(config.http_server_name); + free(config.http_user_agent); free(config.server_name); free(config.language); free(config.language_ui); @@ -2391,6 +2399,15 @@ const idclass_t config_class = { .opts = PO_EXPERT, .group = 5 }, + { + .type = PT_STR, + .id = "http_user_agent", + .name = N_("HTTP User Agent"), + .desc = N_("The user agent string for the build-in HTTP client."), + .off = offsetof(config_t, http_user_agent), + .opts = PO_HIDDEN | PO_EXPERT, + .group = 6, + }, { .type = PT_INT, .id = "iptv_tpool", diff --git a/src/config.h b/src/config.h index 85f614de9..39680475d 100644 --- a/src/config.h +++ b/src/config.h @@ -41,6 +41,7 @@ typedef struct config { char *full_version; char *server_name; char *http_server_name; + char *http_user_agent; char *language; char *info_area; int chname_num; @@ -71,9 +72,10 @@ typedef struct config { extern const idclass_t config_class; extern config_t config; -void config_boot ( const char *path, gid_t gid, uid_t uid ); -void config_init ( int backup ); -void config_done ( void ); +void config_boot + ( const char *path, gid_t gid, uid_t uid, const char *http_user_agent ); +void config_init( int backup ); +void config_done( void ); const char *config_get_server_name ( void ); const char *config_get_http_server_name ( void ); diff --git a/src/http.h b/src/http.h index 3e5b9ad18..c2a44a927 100644 --- a/src/http.h +++ b/src/http.h @@ -431,7 +431,7 @@ struct http_client { void (*hc_conn_closed) (http_client_t *hc, int err); }; -void http_client_init ( const char *user_agent ); +void http_client_init ( void ); void http_client_done ( void ); http_client_t* diff --git a/src/httpc.c b/src/httpc.c index 71be497db..858b99708 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -20,6 +20,7 @@ #include "tvheadend.h" #include "http.h" #include "tcp.h" +#include "config.h" #include #include @@ -44,6 +45,8 @@ #include #endif +#define HTTPCLIENT_TESTSUITE 1 + struct http_client_ssl { int connected; int shutdown; @@ -85,7 +88,6 @@ static TAILQ_HEAD(,http_client) http_clients; static pthread_mutex_t http_lock; static tvh_cond_t http_cond; static th_pipe_t http_pipe; -static char *http_user_agent; /* * @@ -1216,12 +1218,8 @@ http_client_basic_args ( http_client_t *hc, http_arg_list_t *h, const url_t *url http_port(hc, url->scheme, url->port)); http_arg_set(h, "Host", buf); } - if (http_user_agent) { - http_arg_set(h, "User-Agent", http_user_agent); - } else { - snprintf(buf, sizeof(buf), "TVHeadend/%s", tvheadend_version); - http_arg_set(h, "User-Agent", buf); - } + assert(config.http_user_agent); + http_arg_set(h, "User-Agent", config.http_user_agent); if (!keepalive) http_arg_set(h, "Connection", "close"); http_client_basic_auth(hc, h, url->user, url->pass); @@ -1659,10 +1657,8 @@ http_client_close ( http_client_t *hc ) pthread_t http_client_tid; void -http_client_init ( const char *user_agent ) +http_client_init ( void ) { - http_user_agent = user_agent ? strdup(user_agent) : NULL; - /* Setup list */ pthread_mutex_init(&http_lock, NULL); tvh_cond_init(&http_cond); @@ -1699,7 +1695,6 @@ http_client_done ( void ) tvhpoll_destroy(http_poll); http_poll = NULL; pthread_mutex_unlock(&http_lock); - free(http_user_agent); } /* diff --git a/src/main.c b/src/main.c index 01b27e92a..9083d4208 100644 --- a/src/main.c +++ b/src/main.c @@ -1094,7 +1094,7 @@ main(int argc, char **argv) uuid_init(); idnode_boot(); - config_boot(opt_config, gid, uid); + config_boot(opt_config, gid, uid, opt_user_agent); tcp_server_preinit(opt_ipv6); http_server_init(opt_bindaddr); // bind to ports only htsp_init(opt_bindaddr); // bind to ports only @@ -1222,7 +1222,7 @@ main(int argc, char **argv) tvhftrace(LS_MAIN, codec_init); tvhftrace(LS_MAIN, profile_init); tvhftrace(LS_MAIN, imagecache_init); - tvhftrace(LS_MAIN, http_client_init, opt_user_agent); + tvhftrace(LS_MAIN, http_client_init); tvhftrace(LS_MAIN, esfilter_init); tvhftrace(LS_MAIN, bouquet_init); tvhftrace(LS_MAIN, service_init);