20160627_jeffrey - silenceuncrio/diary GitHub Wiki
Index
- 0925 - 更動 file 如下
- 1050 - ameba cJSON library porting SuperTask 放棄
- 1110 - morris m300 NAND Flash boot code
- 1530 - 討論 alarm sensor ISD9160
- 1640 - acl_cgi.c
- 1805 - engineering notebook
0925
上禮拜更動的 file 如下
- srcefmbridge\www\doc\ajax\acl_cgi.sht
- srcefmbridge\cgi\SSI_VARS.C
- srcefmbridge\cgi\All_cgis.h
- srcefmbridge\cgi\acl_cgi.c
acl_cgi.sht
<!--#exec cmd="acl_cgi" -->
*.sht
的 file 在 web server 丟給 client 前會先處理過
<!--#exec cmd="acl_cgi" -->
表示處理的 function 為 acl_cgi
SSI_VARS.C
/* ----------- constant string for <!--#exec cmd="??" --> -------------------*/
struct inc_cmd_entry cmd_tbl[] = {
...
#ifdef _ACL
"acl_cgi", acl_cgi,
#endif
NULL, NULL
};
"acl_cgi" 這個字眼在處理前要先查表 - cmd_tbl[]
然後會叫用到 acl_cgi
All_cgis.h
...
int acl_cgi(register struct request_rec *r);
...
function prototype
acl_cgi.c
#include "all_cgis.h"
#if 1 // 1 is for debug
#define DBGPRINT eprintf
#else
#define DBGPRINT
#endif
#define STRCMP(a,b) (strcmp(a,b) == 0)
int nbytes = 0;
static void _get(register struct request_rec *r) {
nbytes += so_printf(r, "act = get");
}
static void _apply(register struct request_rec *r) {
nbytes += so_printf(r, "act = apply");
}
int acl_cgi(register struct request_rec *r) {
int x, i;
input inputs[5];
char *getstr, *stop;
char *act = NULL;
for (i = 0; i < 5; i ++) {
inputs[i].name = NULL;
inputs[i].val = NULL;
}
nbytes = 0;
getstr = r->args;
if (getstr) {
DBGPRINT("\n getstr: %s", getstr);
} else {
DBGPRINT("\n no getstr");
}
for (x = 0; *getstr != '\0'; x ++) {
inputs[x].name = makeword(getstr,'&');
plustospace(inputs[x].name);
unescape_url(inputs[x].name);
if (!(stop = strchr(inputs[x].name,'=')))
inputs[x].val = NULL;
else {
*stop++ = '\0';
inputs[x].val = stop;
}
}
for (i = 0; i < 5; i ++) {
if (inputs[i].name) {
DBGPRINT("\n %d - name: %s - val: %s", i, inputs[i].name, inputs[i].val);
}
}
act = GetCGIbyFieldName(inputs, "act");
if (act == NULL) {
nbytes += so_printf(r, "act required!");
goto end;
} else {
nbytes += so_printf(r, "got act");
goto end;
}
if (STRCMP(act, "get")) {
_get(r);
goto end;
}
if (STRCMP(act, "apply")) {
_apply(r);
goto end;
}
nbytes += so_printf(r, "act(%s) not support!", act);
end:
return nbytes;
}
這隻修了一些 bug 掉了
0940
繼續吧
1050
原本想從 ameba 將 cJSON library porting 到 SuperTask 來...
比想像中要花更多時間... 放棄
1110
morris 請我先把 m300 NAND Flash 可燒錄的 boot code 寄給他 - u-boot-imx6ul14x14ddr3arm2_nand.imx
1530
下午稍微討論一下 alarm sensor 的進度
會後大家有互相分享一下情報
- http://www.easylinkuk.co.uk/page57.html
- http://www.rehabmart.com/product/wireless-ring-extender-sound-activated-transmitter-and-vibrating-pager-24593.html
- https://www.electronickits.com/sound-activated-fm-transmitter-kit/
- http://www.nuvoton.com/hq/applications/consumer/voice-recognition/?__locale=zh_TW
ISD9160 這個晶片可以玩玩看...
1640
目前 acl_cgi.c
實作如下
#include "all_cgis.h"
#include "acl.h"
#if 1 // 1 is for debug
#define DBGPRINT eprintf
#else
#define DBGPRINT
#endif
#define STRCMP(a,b) (strcmp(a,b) == 0)
#define MAX_INPUTS 16
input Inputs[MAX_INPUTS];
int Nbytes = 0;
static char *_cgi_val(char *field) {
return GetCGIbyFieldName(Inputs, field);
}
static void _cgi_init(register struct request_rec *r) {
int i, x;
char *getstr, *stop;
DBGPRINT("\n _cgi_init()");
Nbytes = 0;
getstr = r->args;
DBGPRINT("\n method: %s", r->method);
// init all inputs before use them
for (i = 0; i < MAX_INPUTS; i ++) {
Inputs[i].name = NULL;
Inputs[i].val = NULL;
}
// parse name and val into Inputs
for (x = 0; *getstr != '\0'; x ++) {
Inputs[x].name = makeword(getstr,'&');
plustospace(Inputs[x].name);
unescape_url(Inputs[x].name);
if (!(stop = strchr(Inputs[x].name,'=')))
Inputs[x].val = NULL;
else {
*stop++ = '\0';
Inputs[x].val = stop;
}
// no more tuple into Inputs
if (x > MAX_INPUTS) return;
}
for (i = 0; i < x; i ++) {
if (Inputs[i].name) {
DBGPRINT("\n %d - name: %s - val: %s", i, Inputs[i].name, Inputs[i].val);
}
}
}
static int _set(register struct request_rec *r) {
char *entry = NULL;
int _entry = 0;
char *enable = NULL;
int _enable = 0;
char *smac, *dmac;
int mac[6];
int nfields = 0;
AclS acl;
int result;
// force the action to "filter" at current requirement
acl.action = ACL_ACTION_FILTER;
/* entry */
entry = _cgi_val("entry");
if (entry == NULL) {
Nbytes += so_printf(r, "{\"error\": \"entry required!\"}");
return Nbytes;
}
_entry = atoi(entry);
if (_entry < 1 || _entry > ACL_ENTRY) {
Nbytes += so_printf(r, "{\"error\": \"entry(%d) out of range(1 ~ 8)\"}", _entry);
return Nbytes;
}
DBGPRINT("\n entry = %d", _entry);
/* enable */
enable = _cgi_val("enable");
if (enable == NULL) {
Nbytes += so_printf(r, "{\"error\": \"enable required!\"}");
return Nbytes;
}
_enable = atoi(enable);
if (_enable < 0 || _enable > 1) {
Nbytes += so_printf(r, "{\"error\": \"enable(%d) out of range(0 or 1)\"}", _enable);
return Nbytes;
}
DBGPRINT("\n enable = %d", _enable);
/* smac */
smac = _cgi_val("smac");
if (smac == NULL) {
Nbytes += so_printf(r, "{\"error\": \"smac required!\"}");
return Nbytes;
}
nfields = sscanf(smac, "[%x,%x,%x,%x,%x,%x]",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if (nfields < 6) {
Nbytes += so_printf(r, "{\"error\": \"smac(%s) syntax error! - ex: [0x00,0x11,0x22,0x33,0x44,0x55]\"}", smac);
return Nbytes;
}
DBGPRINT("\n nfields of smac = %d", nfields);
DBGPRINT("\n smac = %02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
acl.smac[0] = mac[0];
acl.smac[1] = mac[1];
acl.smac[2] = mac[2];
acl.smac[3] = mac[3];
acl.smac[4] = mac[4];
acl.smac[5] = mac[5];
DBGPRINT("\n acl.smac = %02x:%02x:%02x:%02x:%02x:%02x",
acl.smac[0], acl.smac[1], acl.smac[2], acl.smac[3], acl.smac[4], acl.smac[5]);
/* dmac */
dmac = _cgi_val("dmac");
if (dmac == NULL) {
Nbytes += so_printf(r, "{\"error\": \"dmac required!\"}");
return Nbytes;
}
nfields = sscanf(dmac, "[%x,%x,%x,%x,%x,%x]",
&mac[0], &mac[1], &mac[2], &mac[3], &mac[4], &mac[5]);
if (nfields < 6) {
Nbytes += so_printf(r, "{\"error\": \"dmac(%s) syntax error! - ex: [0x00,0x11,0x22,0x33,0x44,0x55]\"}", dmac);
return Nbytes;
}
DBGPRINT("\n nfields of dmac = %d", nfields);
DBGPRINT("\n dmac = %02x:%02x:%02x:%02x:%02x:%02x",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
acl.dmac[0] = mac[0];
acl.dmac[1] = mac[1];
acl.dmac[2] = mac[2];
acl.dmac[3] = mac[3];
acl.dmac[4] = mac[4];
acl.dmac[5] = mac[5];
DBGPRINT("\n acl.dmac = %02x:%02x:%02x:%02x:%02x:%02x",
acl.dmac[0], acl.dmac[1], acl.dmac[2], acl.dmac[3], acl.dmac[4], acl.dmac[5]);
result = AclSet(_entry - 1, &acl);
if (result == 0) {
Nbytes += so_printf(r, "{\"ok\": true}");
return Nbytes;
} else {
Nbytes += so_printf(r, "{\"fail\": true}");
return Nbytes;
}
}
static int _get(register struct request_rec *r) {
char *entry = NULL;
int _entry = 0;
AclS acl;
/* entry */
entry = _cgi_val("entry");
if (entry == NULL) {
Nbytes += so_printf(r, "{\"error\": \"entry required!\"}");
return Nbytes;
}
_entry = atoi(entry);
if (_entry < 1 || _entry > ACL_ENTRY) {
Nbytes += so_printf(r, "{\"error\": \"entry(%d) out of range(1 ~ 8)\"}", _entry);
return Nbytes;
}
DBGPRINT("\n act = get; entry = %d", _entry);
AclGet(_entry - 1, &acl);
DBGPRINT("\n enable = %d", acl.enable);
DBGPRINT("\n action = %d", acl.action);
DBGPRINT("\n smac = %02x:%02x:%02x:%02x:%02x:%02x",
acl.smac[0], acl.smac[1], acl.smac[2], acl.smac[3], acl.smac[4], acl.smac[5]);
DBGPRINT("\n dmac = %02x:%02x:%02x:%02x:%02x:%02x",
acl.dmac[0], acl.dmac[1], acl.dmac[2], acl.dmac[3], acl.dmac[4], acl.dmac[5]);
/* prepare information with JSON format */
Nbytes += so_printf(r, "{");
Nbytes += so_printf(r, "\"enable\":%d,", acl.enable);
Nbytes += so_printf(r, "\"action\":%d,", acl.action);
Nbytes += so_printf(r, "\"smac\":[0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x],",
acl.smac[0], acl.smac[1], acl.smac[2], acl.smac[3], acl.smac[4], acl.smac[5]);
Nbytes += so_printf(r, "\"dmac\":[0x%02x,0x%02x,0x%02x,0x%02x,0x%02x,0x%02x]",
acl.dmac[0], acl.dmac[1], acl.dmac[2], acl.dmac[3], acl.dmac[4], acl.dmac[5]);
Nbytes += so_printf(r, "}");
return Nbytes;
}
static int _apply(register struct request_rec *r) {
char *entry = NULL;
int _entry = 0;
int result;
/* entry */
entry = _cgi_val("entry");
if (entry == NULL) {
Nbytes += so_printf(r, "{\"error\": \"entry required!\"}");
return Nbytes;
}
_entry = atoi(entry);
if (_entry < 1 || _entry > ACL_ENTRY) {
Nbytes += so_printf(r, "{\"error\": \"entry(%d) out of range(1 ~ 8)\"}", _entry);
return Nbytes;
}
DBGPRINT("\n entry = %d", _entry);
result = AclApply(_entry - 1);
if (result == 0) {
Nbytes += so_printf(r, "{\"ok\": true}");
return Nbytes;
} else {
Nbytes += so_printf(r, "{\"fail\": true}");
return Nbytes;
}
}
int acl_cgi(register struct request_rec *r) {
char *act = NULL;
_cgi_init(r);
act = _cgi_val("act");
if (act == NULL) {
Nbytes += so_printf(r, "{\"error\": \"act required!\"}", act);
goto end;
}
if (STRCMP(act, "get")) return _get(r);
if (STRCMP(act, "set")) return _set(r);
if (STRCMP(act, "apply")) return _apply(r);
Nbytes += so_printf(r, "{\"error\": \"act(%s) not support!\"}", act);
end:
return Nbytes;
}
CGI 先這樣, 可以來做網頁的部分了
1805
engineering notebook