Simplify the page name to script mapping

This commit is contained in:
George Oikonomou 2015-03-23 04:11:57 +00:00
parent 90a3cd8e14
commit 54c1cd05e8
1 changed files with 20 additions and 13 deletions

View File

@ -192,37 +192,49 @@ static const char config_div_left[] = "<div class=\"left\">";
static const char config_div_right[] = "<div class=\"right\">"; static const char config_div_right[] = "<div class=\"right\">";
static const char config_div_close[] = "</div>"; static const char config_div_close[] = "</div>";
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
static char generate_index(struct httpd_state *s);
static char generate_config(struct httpd_state *s);
/*---------------------------------------------------------------------------*/
typedef struct page { typedef struct page {
struct page *next; struct page *next;
char *filename; char *filename;
char *title; char *title;
char (*script)(struct httpd_state *s);
} page_t; } page_t;
static page_t http_index_page = { static page_t http_index_page = {
NULL, NULL,
"index.html", "index.html",
"Index", "Index",
generate_index,
}; };
static page_t http_dev_cfg_page = { static page_t http_dev_cfg_page = {
NULL, NULL,
"config.html", "config.html",
"Device Config", "Device Config",
generate_config,
}; };
#if CC26XX_WEB_DEMO_NET_UART #if CC26XX_WEB_DEMO_NET_UART
static char generate_net_uart_config(struct httpd_state *s);
static page_t http_net_cfg_page = { static page_t http_net_cfg_page = {
NULL, NULL,
"net.html", "netu.html",
"Net-UART Config", "Net-UART Config",
generate_net_uart_config,
}; };
#endif #endif
#if CC26XX_WEB_DEMO_MQTT_CLIENT #if CC26XX_WEB_DEMO_MQTT_CLIENT
static char generate_mqtt_config(struct httpd_state *s);
static page_t http_mqtt_cfg_page = { static page_t http_mqtt_cfg_page = {
NULL, NULL,
"mqtt.html", "mqtt.html",
"MQTT/IBM Cloud Config", "MQTT/IBM Cloud Config",
generate_mqtt_config,
}; };
#endif #endif
/*---------------------------------------------------------------------------*/ /*---------------------------------------------------------------------------*/
@ -969,18 +981,13 @@ parse_post_request_chunk(char *buf, int buf_len, int last_chunk)
static httpd_simple_script_t static httpd_simple_script_t
get_script(const char *name) get_script(const char *name)
{ {
if(strlen(name) == 10 && strncmp(name, "index.html", 10) == 0) { page_t *page;
return generate_index;
} else if(strlen(name) == 11 && strncmp(name, "config.html", 11) == 0) { for(page = list_head(pages_list); page != NULL;
return generate_config; page = list_item_next(page)) {
#if CC26XX_WEB_DEMO_MQTT_CLIENT if(strncmp(name, page->filename, strlen(page->filename)) == 0) {
} else if(strlen(name) == 9 && strncmp(name, "mqtt.html", 9) == 0) { return page->script;
return generate_mqtt_config; }
#endif
#if CC26XX_WEB_DEMO_NET_UART
} else if(strlen(name) == 8 && strncmp(name, "net.html", 8) == 0) {
return generate_net_uart_config;
#endif
} }
return NULL; return NULL;