parent
fbd4693035
commit
cabd42f2b4
@ -1 +1 @@ |
||||
Subproject commit d2fabc40f1874cabd7f7ceca690a5874887c3c5d |
||||
Subproject commit 32c889b714dae859f51e6b46829fd85be59d9ed0 |
@ -0,0 +1,3 @@ |
||||
#!/usr/bin/env bash |
||||
|
||||
xtensa-lx106-elf-gcc -E -Iuser -Ilibesphttpd/include -Iesp_iot_sdk_v1.5.2/include -Iinclude $@ |
@ -0,0 +1,99 @@ |
||||
//
|
||||
// Created by MightyPork on 2017/10/22.
|
||||
//
|
||||
|
||||
#include "config_xmacros.h" |
||||
#include "cgi_logging.h" |
||||
|
||||
void ICACHE_FLASH_ATTR xget_dec(char *buff, u32 value) |
||||
{ |
||||
sprintf(buff, "%d", value); |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR xget_bool(char *buff, bool value) |
||||
{ |
||||
sprintf(buff, "%d", value?1:0); |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR xget_ustring(char *buff, const u8 *value) |
||||
{ |
||||
sprintf(buff, "%s", (const char *) value); |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR xget_string(char *buff, const char *value) |
||||
{ |
||||
sprintf(buff, "%s", value); |
||||
} |
||||
|
||||
void ICACHE_FLASH_ATTR xget_ip(char *buff, const struct ip_addr *value) |
||||
{ |
||||
sprintf(buff, IPSTR, GOOD_IP2STR(value->addr)); |
||||
} |
||||
|
||||
// ------------- XSET -------------
|
||||
|
||||
enum xset_result ICACHE_FLASH_ATTR |
||||
xset_ip(const char *name, struct ip_addr *field, const char *buff, const void *arg) |
||||
{ |
||||
cgi_dbg("Setting %s = %s", name, buff); |
||||
u32 ip = ipaddr_addr(buff); |
||||
if (ip != 0 && ip != 0xFFFFFFFFUL) { |
||||
if (field->addr != ip) { |
||||
field->addr = ip; |
||||
return XSET_SET; |
||||
} |
||||
return XSET_UNCHANGED; |
||||
} else { |
||||
cgi_warn("Bad IP: %s", buff); |
||||
return XSET_FAIL; |
||||
} |
||||
} |
||||
|
||||
enum xset_result ICACHE_FLASH_ATTR |
||||
xset_bool(const char *name, bool *field, const char *buff, const void *arg) |
||||
{ |
||||
cgi_dbg("Setting %s = %s", name, buff); |
||||
bool enable = (atoi(buff) != 0); |
||||
|
||||
if (*field != enable) { |
||||
*field = enable; |
||||
return XSET_SET; |
||||
} |
||||
return XSET_UNCHANGED; |
||||
} |
||||
|
||||
enum xset_result ICACHE_FLASH_ATTR |
||||
xset_u8(const char *name, u8 *field, const char *buff, const void *arg) |
||||
{ |
||||
cgi_dbg("Setting %s = %s", name, buff); |
||||
u32 val = (u32) atoi(buff); |
||||
|
||||
if (val <= 255) { |
||||
if (*field != val) { |
||||
*field = (u8) val; |
||||
return XSET_SET; |
||||
} |
||||
return XSET_UNCHANGED; |
||||
} else { |
||||
cgi_warn("Bad value, max 255: %s", buff); |
||||
return XSET_FAIL; |
||||
} |
||||
} |
||||
|
||||
enum xset_result ICACHE_FLASH_ATTR |
||||
xset_string(const char *name, char *field, const char *buff, const void *arg) |
||||
{ |
||||
cgi_dbg("Setting %s = %s", name, buff); |
||||
u32 maxlen = (u32) arg; |
||||
|
||||
if (arg > 0 && (u32)strlen(buff) > maxlen) { |
||||
cgi_warn("String too long, max %d", maxlen); |
||||
return XSET_FAIL; |
||||
} |
||||
|
||||
if (!streq(field, buff)) { |
||||
strncpy_safe(field, buff, (u32)arg); |
||||
return XSET_SET; |
||||
} |
||||
return XSET_UNCHANGED; |
||||
} |
@ -0,0 +1,85 @@ |
||||
//
|
||||
// Created by MightyPork on 2017/10/22.
|
||||
//
|
||||
|
||||
#ifndef ESPTERM_CONFIG_XMACROS_H |
||||
#define ESPTERM_CONFIG_XMACROS_H |
||||
|
||||
#include <esp8266.h> |
||||
#include <helpers.h> |
||||
|
||||
#define XJOIN(a, b) a##b |
||||
|
||||
/**Do nothing xnotify */ |
||||
#define xnoop() |
||||
|
||||
/**
|
||||
* XGET interface |
||||
* |
||||
* @param buff - buffer where the value should be printed |
||||
* @param value - value to render to the buffer |
||||
*/ |
||||
|
||||
static inline bool xget_dummy(char *buff, u32 value) |
||||
{ |
||||
sprintf(buff, "unused %d", value); |
||||
return false; |
||||
} |
||||
|
||||
void xget_dec(char *buff, u32 value); |
||||
void xget_bool(char *buff, bool value); |
||||
void xget_ustring(char *buff, const u8 *value); |
||||
void xget_string(char *buff, const char *value); |
||||
void xget_ip(char *buff, const struct ip_addr *value); |
||||
void xget_dhcp(char *buff, const struct dhcps_lease *value); |
||||
|
||||
|
||||
/**
|
||||
* XSET interface |
||||
* |
||||
* @param name - field name (for debug) |
||||
* @param field - pointer to the target field |
||||
* @param buff - field with the value to be set |
||||
* @param arg - arbitrary argument, used to modify behavior |
||||
* |
||||
* @return xset_result |
||||
*/ |
||||
|
||||
enum xset_result { |
||||
XSET_FAIL = 0, |
||||
XSET_SET = 1, |
||||
XSET_UNCHANGED = 2 |
||||
}; |
||||
|
||||
// Dummy for unimplemented setters
|
||||
static inline enum xset_result xset_dummy(const char *name, void *field, const char *buff, const void *arg) |
||||
{ |
||||
return XSET_UNCHANGED; |
||||
} |
||||
|
||||
enum xset_result xset_ip(const char *name, struct ip_addr *field, const char *buff, const void *arg); |
||||
enum xset_result xset_bool(const char *name, bool *field, const char *buff, const void *arg); |
||||
enum xset_result xset_u8(const char *name, u8 *field, const char *buff, const void *arg); |
||||
|
||||
/**
|
||||
* @param arg - max string length |
||||
*/ |
||||
enum xset_result xset_string(const char *name, char *field, const char *buff, const void *arg); |
||||
|
||||
/**
|
||||
* Helper template macro for CGI functions that load GET args to structs using XTABLE |
||||
* |
||||
* If 'name' is found in connData->getArgs, xset() is called. |
||||
* If the result is SET, xnotify() is fired. Else, 'name,' is appended to the redir_url buffer. |
||||
*/ |
||||
#define XSET_CGI_FUNC(type, name, suffix, deref, xget, cast, xset, xsarg, xnotify) \ |
||||
if (GET_ARG(#name)) { \
|
||||
enum xset_result res = xset(#name, cast &wificonf->name, buff, (const void*) (xsarg)); \
|
||||
if (res == XSET_SET) { xnotify(); } \
|
||||
else if (res == XSET_FAIL) { redir_url += sprintf(redir_url, #name","); } \
|
||||
} |
||||
|
||||
#define XGET_CGI_FUNC(type, name, suffix, deref, xget, cast, xset, xsarg, xnotify) \ |
||||
if (streq(token, #name)) xget(buff, deref wificonf->name); |
||||
|
||||
#endif //ESPTERM_CONFIG_XMACROS_H
|
Loading…
Reference in new issue