move code for resolving a username + password -> config to main.c (we want it to be more general)

This commit is contained in:
Andreas Öman 2008-02-15 15:37:42 +00:00
parent ec9406de71
commit f3057b7803
3 changed files with 31 additions and 24 deletions

26
http.c
View file

@ -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
View file

@ -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;
}

View file

@ -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 */