move code for resolving a username + password -> config to main.c (we want it to be more general)
This commit is contained in:
parent
ec9406de71
commit
f3057b7803
3 changed files with 31 additions and 24 deletions
26
http.c
26
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
26
main.c
26
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;
|
||||
}
|
||||
|
|
3
tvhead.h
3
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 */
|
||||
|
|
Loading…
Add table
Reference in a new issue