📄 webhttpd.c
字号:
while (retval_miss != retval_len) { while (*temp != '\n') { thread_strings[ind++] = *temp; retval_miss++; temp++; } temp++; thread_strings[ind++] = '<'; thread_strings[ind++] = 'b'; thread_strings[ind++] = 'r'; thread_strings[ind++] = '>'; retval_miss++; } free(retval); retval = NULL; retval = strdup(thread_strings); } sprintf(res, "<li><a href=/%hu/config/set?%s>%s</a> = %s</li>\n", thread, config_params[i].param_name, config_params[i].param_name, retval); free(retval); } else if (thread != 0) { /* get the value from main thread for the rest of threads */ value = config_params[i].print(cnt, NULL, i, 0); sprintf(res, "<li><a href=/%hu/config/set?%s>%s</a> = %s</li>\n", thread, config_params[i].param_name, config_params[i].param_name, value ? value : "(not defined)"); } else { sprintf(res, "<li><a href=/%hu/config/set?%s>%s</a> = %s</li>\n", thread, config_params[i].param_name, config_params[i].param_name, "(not defined)"); } } else { sprintf(res, "<li><a href=/%hu/config/set?%s>%s</a> = %s</li>\n",thread, config_params[i].param_name, config_params[i].param_name, value); } send_template(client_socket, res); } sprintf(res, "</ul><a href=/%hu/config><– back</a>",thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); for (i=0; config_params[i].param_name != NULL; i++) { value=config_params[i].print(cnt, NULL, i, thread); if (value == NULL) value=config_params[i].print(cnt, NULL, i, 0); sprintf(res, "%s = %s\n", config_params[i].param_name, value); send_template_raw(client_socket, res); } } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command,"set")) { /* set?param_name=value */ pointer = pointer + 3; length_uri = length_uri - 3; if ((length_uri != 0) && (question == '?')) { pointer++; length_uri--; warningkill = sscanf(pointer,"%255[-0-9a-z_]%c", command, &question); /*check command , question == '=' length_uri too*/ if ((question == '=') && (command[0]!='\0')) { length_uri = length_uri - strlen(command) - 1; pointer = pointer + strlen(command) + 1; /* check if command exists and type of command and not end of URI */ i=0; while (config_params[i].param_name != NULL) { if ((thread != 0) && (config_params[i].main_thread)){ i++; continue; } if (!strcasecmp(command, config_params[i].param_name)) break; i++; } if (config_params[i].param_name) { if (length_uri > 0) { char Value[1024]={'\0'}; warningkill = sscanf(pointer,"%1023s", Value); length_uri = length_uri - strlen(Value); if ( (length_uri == 0) && (strlen(Value) > 0) ) { /* FIXME need to assure that is a valid value */ url_decode(Value,strlen(Value)); conf_cmdparse(cnt + thread, config_params[i].param_name, Value); if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/config/list><– back</a>" "<br><br>\n<b>Thread %hu</b>\n" "<ul><li><a href=/%hu/config/set?%s>%s</a> = %s" "</li></ul><b>Done</b>", thread, thread, thread,config_params[i].param_name, config_params[i].param_name, Value); send_template_ini_client(client_socket, ini_template); send_template(client_socket,res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "%s = %s\nDone\n", config_params[i].param_name, Value); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_valid_syntax, NULL); else response_client(client_socket, not_valid_syntax_raw, NULL); } } else { char *type = NULL; type = strdup(config_type(&config_params[i])); if (!strcmp(type,"string")) { char *value = NULL; conf_cmdparse(cnt+thread, config_params[i].param_name, value); free(type); type = strdup("(null)"); } else if (!strcmp(type,"int")) { free(type); type = strdup("0"); conf_cmdparse(cnt+thread, config_params[i].param_name, type); } else if (!strcmp(type,"short")) { free(type); type = strdup("0"); conf_cmdparse(cnt+thread, config_params[i].param_name, type); } else if (!strcmp(type,"bool")) { free(type); type = strdup("off"); conf_cmdparse(cnt+thread, config_params[i].param_name, type); } else { free(type); type = strdup("unknown"); } if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/config/list><– back</a><br><br>\n" "<b>Thread %hu</b>\n<ul><li><a href=/%hu/config/set?%s>%s</a>" "= %s</li></ul><br><b>Done</b>", thread, thread, thread, config_params[i].param_name, config_params[i].param_name, type); send_template_ini_client(client_socket, ini_template); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "%s = %s\nDone\n", config_params[i].param_name,type); send_template_raw(client_socket, res); } free(type); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else { /* Show param_name dialogue only for html output */ if ( (cnt[0]->conf.control_html_output) && (command[0]!='\0') && (((length_uri = length_uri - strlen(command)) == 0 )) ) { i=0; while (config_params[i].param_name != NULL) { if ((thread != 0) && (config_params[i].main_thread)){ i++; continue; } if (!strcasecmp(command, config_params[i].param_name)) break; i++; } /* param_name exists */ if (config_params[i].param_name) { const char *value = NULL; char *text_help = NULL; char *sharp = NULL; value = config_params[i].print(cnt, NULL, i, thread); sharp = strstr(config_params[i].param_help, "#\n\n#"); if (sharp == NULL) sharp = strstr(config_params[i].param_help, "#"); sharp++; text_help = replace(sharp, "\n#", "<br>"); send_template_ini_client(client_socket, ini_template); if (!strcmp ("bool",config_type(&config_params[i])) ){ char option[80] = {'\0'}; if ((value == NULL) && (thread != 0)) value = config_params[i].print(cnt, NULL, i, 0); if (!strcmp ("on", value)) sprintf(option, "<option value='on' selected>on</option>\n" "<option value='off'>off</option>\n"); else sprintf(option, "<option value='on'>on</option>\n" "<option value='off' selected>off</option>\n"); sprintf(res, "<a href=/%hu/config/list><– back</a><br><br>\n" "<b>Thread %hu</b>\n" "<form action=set?>\n" "<b>%s</b> <select name='%s'>\n" "%s" "</select><input type='submit' value='set'>\n" " " "<a href='%s#%s' target=_blank>[help]</a>" "</form>\n<hr><i>%s</i>", thread, thread, config_params[i].param_name, config_params[i].param_name, option, TWIKI_URL,config_params[i].param_name, text_help); }else{ if (value == NULL){ if (thread != 0) /* get the value from main thread for the rest of threads */ value = config_params[i].print(cnt, NULL, i, 0); if (value == NULL) value = ""; } sprintf(res, "<a href=/%hu/config/list><– back</a><br><br>\n" "<b>Thread %hu</b>\n<form action=set?>\n" "<b>%s</b> <input type=text name='%s' value='%s' size=50>\n" "<input type='submit' value='set'>\n" " " "<a href='%s#%s' target=_blank>[help]</a>" "</form>\n<hr><i>%s</i>", thread, thread, config_params[i].param_name, config_params[i].param_name, value, TWIKI_URL, config_params[i].param_name, text_help); } send_template(client_socket, res); send_template_end_client(client_socket); free(text_help); } else { if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else { if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } } else if (length_uri == 0) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, set_template); sprintf(res, "<a href=/%hu/config><– back</a><br><br>\n<b>Thread %hu</b>\n" "<form name='n'>\n<select name='onames'>\n", thread, thread ); send_template(client_socket, res); for (i=0; config_params[i].param_name != NULL; i++) { if ((thread != 0) && (config_params[i].main_thread)) continue; sprintf(res, "<option value='%s'>%s</option>\n", config_params[i].param_name, config_params[i].param_name); send_template(client_socket, res); } sprintf(res, "</select>\n</form>\n" "<form action=set name='s'" "ONSUBMIT='if (!this.submitted) return false; else return true;'>\n" "<input type=text name='valor' value=''>\n" "<input type='button' value='set' onclick='javascript:show()'>\n" "</form>\n"); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "set needs param_name=value\n"); send_template_raw(client_socket, res); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else if (!strcmp(command,"get")) { /* get?query=param_name */ pointer = pointer + 3; length_uri = length_uri - 3; if ((length_uri > 7) && (question == '?')) { /* 8 -> query=param_name FIXME minimum length param_name */ pointer++; length_uri--; warningkill = sscanf(pointer,"%255[-0-9a-z]%c", command, &question); if ( (question == '=') && (!strcmp(command,"query")) ) { pointer = pointer + 6; length_uri = length_uri - 6; warningkill = sscanf(pointer, "%255[-0-9a-z_]", command); /*check if command exist, length_uri too*/ length_uri = length_uri-strlen(command); if (length_uri == 0) { const char *value = NULL; i=0; while (config_params[i].param_name != NULL) { if ((thread != 0) && (config_params[i].main_thread)){ i++; continue; } if (!strcasecmp(command, config_params[i].param_name)) break; i++; } /* FIXME bool values or commented values maybe that should be solved with config_type */ if (config_params[i].param_name) { const char *type=NULL; type = config_type(&config_params[i]); if (!strcmp(type,"unknown")) { /*error doesn't exists this param_name */ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); return 1; } else { char *text_help = NULL; char *sharp = NULL; value = config_params[i].print(cnt, NULL, i, thread); sharp = strstr(config_params[i].param_help, "#\n\n#"); if (sharp == NULL) sharp = strstr(config_params[i].param_help, "#"); sharp++; text_help = replace(sharp, "\n#", "<br>"); if (value == NULL) value=config_params[i].print(cnt, NULL, i, 0); if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket,ini_template); sprintf(res, "<a href=/%hu/config/get><– back</a><br><br>\n" "<b>Thread %hu</b><br>\n<ul><li>%s = %s " " <a href='%s#%s' target=_blank>" "[help]</a></li></ul><hr><i>%s</i>", thread, thread, config_params[i].param_name, value, TWIKI_URL, config_params[i].param_name, text_help); send_template(client_socket, res); send_template_end_client(client_socket); free(text_help); } else { send_template_ini_client_raw(client_socket); sprintf(res, "%s = %s\nDone\n", config_params[i].param_name,value); send_template_raw(client_socket, res); } } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } else { /*error*/ if (cnt[0]->conf.control_html_output) response_client(client_socket, not_found_response_valid_command, NULL); else response_client(client_socket, not_found_response_valid_command_raw, NULL); } } } else if (length_uri == 0) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/config><– back</a><br><br>\n<b>Thread %hu</b><br>\n"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -