From 82aa131a2169c922761239677d1469ca285c2719 Mon Sep 17 00:00:00 2001 From: Xu Zhaowei Date: Wed, 1 Jul 2020 23:06:54 +0800 Subject: [PATCH] softcenter:fix skipdbv2 api --- release/src/router/httpd/dbapi.c | 15 +++++++++++++++ release/src/router/httpd/dbapi.h | 1 + release/src/router/httpd/sysinfo.c | 2 +- release/src/router/httpd/web.c | 14 +++++++------- 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/release/src/router/httpd/dbapi.c b/release/src/router/httpd/dbapi.c index 3475910940..43f3c6a7da 100644 --- a/release/src/router/httpd/dbapi.c +++ b/release/src/router/httpd/dbapi.c @@ -141,6 +141,21 @@ int dbclient_start(dbclient* client) { return 0; } +int dbclient_rm(dbclient* client, const char* key, int nk) { + int n1,n2; + + if(nk < 0) { + return -1; + } + + n1 = nk + 2 + 6; + check_buf(client, n1 + HEADER_PREFIX); + n2 = snprintf(client->buf, client->buf_max, "%s%07d remove %s\n", MAGIC, n1, key); + write(client->remote_fd, client->buf, n2); + + return 0; +} + int dbclient_bulk(dbclient* client, const char* command, const char* key, int nk, const char* value, int nv) { int n1,n2,nc; diff --git a/release/src/router/httpd/dbapi.h b/release/src/router/httpd/dbapi.h index c15819dc76..e1afe9b99c 100644 --- a/release/src/router/httpd/dbapi.h +++ b/release/src/router/httpd/dbapi.h @@ -39,6 +39,7 @@ typedef struct _dbclient { typedef int (*fn_db_parse)(dbclient* client, webs_t wp, char* prefix, char* key, char* value); int dbclient_start(dbclient* client); +int dbclient_rm(dbclient* client, const char* key, int nk); int dbclient_bulk(dbclient* client, const char* command, const char* key, int nk, const char* value, int nv); int dbclient_end(dbclient* client); int dbclient_list(dbclient* client, char* prefix, webs_t wp, fn_db_parse fn); diff --git a/release/src/router/httpd/sysinfo.c b/release/src/router/httpd/sysinfo.c index 900a667959..3bba11ca04 100644 --- a/release/src/router/httpd/sysinfo.c +++ b/release/src/router/httpd/sysinfo.c @@ -651,7 +651,7 @@ unsigned int get_phy_temperature(int radio) snprintf(s, sizeof(s), "wlan2 gTemperature:%%d %%*[0-9 ]"); } if ((fp = popen(iw, "r")) != NULL) { - if(fgets(buffer, 100, fp) != NULL) { + if(fgets(buffer, 99, fp) != NULL) { sscanf(buffer, s, &temp); } pclose(fp); diff --git a/release/src/router/httpd/web.c b/release/src/router/httpd/web.c index 46358bb20d..d5b2274832 100644 --- a/release/src/router/httpd/web.c +++ b/release/src/router/httpd/web.c @@ -15787,7 +15787,7 @@ applydb_cgi(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, char *result = NULL; char *temp = NULL; char *name = websGetVar(wp, "p",""); - char *userm = strstr(url, "use_rm=1"); + char *userm = websGetVar(wp, "use_rm", ""); char scPath[128]; char *post_db_buf = post_json_buf; @@ -15825,8 +15825,8 @@ applydb_cgi(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, strcpy(dbval, temp+1); strncpy(dbvar, dbjson[j], strlen(dbjson[j])-strlen(temp)); //logmessage("HTTPD", "name: %s post: %s", dbvar, dbval); - if(userm) - doSystem("dbus remove %s", dbvar); + if(*userm || dbval[0]=='\0') + dbclient_rm(&client, dbvar, strlen(dbvar)); else dbclient_bulk(&client, "set", dbvar, strlen(dbvar), dbval, strlen(dbval)); } @@ -15856,9 +15856,9 @@ applydb_cgi(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, temp=strstr(dbjson[j], "="); strcpy(dbval, temp+1); strncpy(dbvar, dbjson[j], strlen(dbjson[j])-strlen(temp)); - //logmessage("HTTPD", "name: %s post: %s", dbvar, dbval); - if(userm) - doSystem("dbus remove %s", dbvar); + //logmessage("HTTPD", "dbvar: %s dbval: %s", dbvar, dbval); + if(*userm || dbval[0]=='\0') + dbclient_rm(&client, dbvar, strlen(dbvar)); else dbclient_bulk(&client, "set", dbvar, strlen(dbvar), dbval, strlen(dbval)); } @@ -15999,7 +15999,7 @@ do_logread(webs_t wp, char_t *urlPrefix, char_t *webDir, int arg, //sscanf(url, "logreaddb.cgi?%s", filename); char *filename = websGetVar(wp, "p",""); char *script = websGetVar(wp, "script", ""); - if(script){ + if(*script){ sprintf(scPath, "/jffs/softcenter/scripts/%s", script); strlcpy(SystemCmd, scPath, sizeof(SystemCmd)); sys_script("syscmd.sh");