Skip to content
Permalink
Browse files

httpd/webui: dot presets cosmetics

* eliminate buffer allocations in loop
* clean up no-dnspriv js code
  • Loading branch information...
themiron committed Apr 14, 2019
1 parent 7f3d1c0 commit 0c7bded7893b00a5be4c891b6d69d064f8a59d6f
Showing with 17 additions and 34 deletions.
  1. +16 −33 release/src/router/httpd/web.c
  2. +1 −1 release/src/router/www/Advanced_WAN_Content.asp
int
ej_get_dnsprivacy_presets(int eid, webs_t wp, int argc, char_t **argv)
{
int ret, len;
FILE *fp;
char line[256];
char *item, *buf, *type, *typeString, *datafile;
char buf[256], *type, *datafile, *ptr, *item, *lsep, *fsep;
int ret = 0;

if (ejArgs(argc, argv, "%s", &type) < 1) {
websError(wp, 400, "Insufficient args\n");
return -1;
}

if (!strcmp(type, "dot")) {
typeString = "dot";
if (!strcmp(type, "dot"))
datafile = "/rom/dot-servers.dat";
} else {
else {
websError(wp, 400, "Invalid argument\n");
return -1;
}

ret = websWrite(wp, "var %s_servers_array = [", typeString);

if (!(fp = fopen(datafile, "r"))) {
ret += websWrite(wp, "];\n");
return ret;
}
if (!(fp = fopen(datafile, "r")))
return 0;

while (fgets(line, sizeof(line), fp) != NULL) {
len = strlen(line);
if (len == 0 || line[0] == '#' || line[0] == '\n')
for (lsep = ""; (ptr = fgets(buf, sizeof(buf), fp)) != NULL;) {
buf[sizeof(buf) - 1] = '\0';
ptr = strsep(&ptr, "#\n");
if (*ptr == '\0')
continue;

if (line[len-1] == '\n')
line[len-1] = '\0';

buf = strdup(line);
item = strsep(&buf, ",");

ret += websWrite(wp, "[");
while (item != NULL) {
ret += websWrite(wp, "\"%s\"", item);
item = strsep(&buf, ",");

if (item)
ret += websWrite(wp, ",");
ret += websWrite(wp, "%s[", lsep);
for (fsep = ""; (item = strsep(&ptr, ",")) != NULL;) {
ret += websWrite(wp, "%s\"%s\"", fsep, item);
fsep = ",";
}
ret += websWrite(wp, "],\n");
free(buf);
ret += websWrite(wp, "]");
lsep = ",";
}

fclose(fp);
ret += websWrite(wp, "];\n");

return ret;
}
#endif

@@ -49,7 +49,6 @@ if(dualWAN_support && ( wans_dualwan.search("wan") >= 0 || wans_dualwan.search("
}
<% login_state_hook(); %>
<% wan_get_parameter(); %>
<% get_dnsprivacy_presets("dot"); %>
var wan_proto_orig = '<% nvram_get("wan_proto"); %>';
var original_wan_type = wan_proto_orig;
@@ -65,6 +64,7 @@ if(yadns_support){
}
if(dnspriv_support){
var dot_servers_array = [<% get_dnsprivacy_presets("dot"); %>];
var dnspriv_rulelist_array = '<% nvram_get("dnspriv_rulelist"); %>';
}

0 comments on commit 0c7bded

Please sign in to comment.
You can’t perform that action at this time.