diff --git a/http.c b/http.c index 9cbbac20..1af8b714 100644 --- a/http.c +++ b/http.c @@ -321,30 +321,8 @@ http_process_request(http_connection_t *hc) static void hc_user_resolve(http_connection_t *hc) { - config_entry_t *ce; - const char *name, *pass; - - hc->hc_user_config = NULL; - - TAILQ_FOREACH(ce, &config_list, ce_link) { - if(ce->ce_type == CFG_SUB && !strcasecmp("user", ce->ce_key)) { - if((name = config_get_str_sub(&ce->ce_sub, "name", NULL)) == NULL) - continue; - if(!strcmp(name, hc->hc_username)) - break; - } - } - - if(ce == NULL) - return; - - if((pass = config_get_str_sub(&ce->ce_sub, "password", NULL)) == NULL) - return; - - if(strcmp(pass, hc->hc_password)) - return; - - hc->hc_user_config = &ce->ce_sub; + hc->hc_user_config = user_resolve_to_config(hc->hc_username, + hc->hc_password); } diff --git a/main.c b/main.c index d77bf0ed..a50432b5 100644 --- a/main.c +++ b/main.c @@ -381,3 +381,29 @@ settings_open_for_write(const char *name) return fp; } +struct config_head * +user_resolve_to_config(const char *username, const char *password) +{ + config_entry_t *ce; + const char *name, *pass; + + TAILQ_FOREACH(ce, &config_list, ce_link) { + if(ce->ce_type == CFG_SUB && !strcasecmp("user", ce->ce_key)) { + if((name = config_get_str_sub(&ce->ce_sub, "name", NULL)) == NULL) + continue; + if(!strcmp(name, username)) + break; + } + } + + if(ce == NULL) + return NULL; + + if((pass = config_get_str_sub(&ce->ce_sub, "password", NULL)) == NULL) + return NULL; + + if(strcmp(pass, password)) + return NULL; + + return &ce->ce_sub; +} diff --git a/tvhead.h b/tvhead.h index 70a49e5d..25d4df39 100644 --- a/tvhead.h +++ b/tvhead.h @@ -838,4 +838,7 @@ FILE *settings_open_for_write(const char *name); FILE *settings_open_for_read(const char *name); extern const char *sys_warning; +struct config_head *user_resolve_to_config(const char *username, + const char *password); + #endif /* TV_HEAD_H */