📄 webhttpd.c
字号:
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,"%256[a-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 (!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,"%1024s", 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, "<li><a href=/%d/config/set?%s>%s</a> = %s</li> <b>Done</b><br>\n" "<a href=/%d/config/list><- back</a>\n", thread, config_params[i].param_name, config_params[i].param_name, Value, thread); 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,"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, "<li><a href=/%d/config/set?%s>%s</a> = %s</li> <b>Done</b><br>\n" "<a href=/%d/config/list><- back</a>", thread, config_params[i].param_name, config_params[i].param_name, type, thread); 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 (!strcasecmp(command, config_params[i].param_name)) break; i++; } /* param_name exists */ if (config_params[i].param_name) { send_template_ini_client(client_socket, ini_template); if (!strcmp ("bool",config_type(&config_params[i])) ) sprintf(res, "<b>Thread %d </b>\n" "<form action=set?>\n" "<b>%s</b> <select name='%s'>\n" "<option value='on'>on</option>\n" "<option value='off'>off</option></select>\n" "<input type='submit' value='set'>\n" "</form>\n" "<a href=/%d/config/list><- back</a>\n", thread, config_params[i].param_name, config_params[i].param_name, thread); else sprintf(res, "<b>Thread %d </b>\n" "<form action=set?>\n" "<b>%s</b> <input type=text name='%s' value=''>\n" "<input type='submit' value='set'>\n" "</form>\n" "<a href=/%d/config/list><- back</a>\n", thread, config_params[i].param_name, config_params[i].param_name, thread); send_template(client_socket, res); send_template_end_client(client_socket); } 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, "<b>Thread %d </b>\n<form name='n'>\n<select name='onames'>\n", thread); send_template(client_socket, res); for (i=0; config_params[i].param_name != NULL; i++) { 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" "<a href=/%d/config><- back</a>\n", thread); 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,"%256[a-z]%c", command, &question); if ( (question == '=') && (!strcmp(command,"query")) ) { pointer = pointer + 6; length_uri = length_uri - 6; warningkill = sscanf(pointer, "%256[a-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 (!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 { value = config_params[i].print(cnt, NULL, i, thread); 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,"<li>%s = %s</li><br>\n" "<a href=/%d/config/get><- back</a>\n", config_params[i].param_name,value, thread); 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_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,"<b>Thread %d </b><br>\n" "<form action=get>\n" "<select name='query'>\n", thread); send_template(client_socket, res); for (i=0; config_params[i].param_name != NULL; i++) { 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" "<input type='submit' value='get'>\n" "</form>\n" "<a href=/%d/config><- back</a>\n", thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res,"get needs param_name\n"); 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 if (!strcmp(command,"write")) { pointer = pointer + 5; length_uri = length_uri - 5; if (length_uri == 0) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res,"Are you sure? <a href=/%d/config/writeyes>Yes</a><br>\n" "<a href=/%d/config>No</a>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { conf_print(cnt); send_template_ini_client_raw(client_socket); sprintf(res,"Thread %d write\nDone\n", thread); 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, "writeyes")) { pointer = pointer + 8; length_uri = length_uri - 8; if (length_uri==0) { conf_print(cnt); if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res,"<b>Thread %d</b> write done !<br>\n" "<a href=/%d/config><- back</a>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res,"Thread %d write\nDone\n", thread); 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); } return 1;}/* This function manages/parses the actions for motion ( makemovie , snapshot , restart , quit ).*/static int action(char *pointer, char *res, int length_uri, int thread, int client_socket, void *userdata){ /* parse action commands */ char command[256] = {'\0'}; struct context **cnt = userdata; warningkill = sscanf (pointer, "%256[a-z]" , command); if (!strcmp(command,"makemovie")) { pointer = pointer + 9; length_uri = length_uri - 9; if (length_uri == 0) { /*call makemovie*/ if (thread == 0) { int i = 0; while (cnt[++i]) cnt[i]->makemovie=1; } else { cnt[thread]->makemovie=1; } if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res,"makemovie for thread %d done<br>\n" "<a href=/%d/action><- back</a>\n", thread, thread); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res,"makemovie for thread %d\nDone\n", thread); 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,"snapshot")) { pointer = pointer + 8; length_uri = length_uri - 8; if (length_uri == 0) { /*call snapshot*/ if (thread == 0) { int i = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -