📄 webhttpd.c
字号:
} send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); if (thread == 0){ do{ sprintf(res, "Thread %hu %s\n", i, (!cnt[i]->running)? "NOT RUNNING" : (cnt[i]->lost_connection)? CONNECTION_KO: CONNECTION_OK); send_template_raw(client_socket, res); }while (cnt[++i]); }else{ sprintf(res, "Thread %hu %s\n", thread, (!cnt[thread]->running)? "NOT RUNNING" : (cnt[thread]->lost_connection)? CONNECTION_KO: CONNECTION_OK); 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 (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 track action for motion ( set , pan , tilt , auto ). return 1 to exit from function.*/static unsigned short int track(char *pointer, char *res, unsigned short int length_uri, unsigned short int thread, int client_socket, void *userdata){ char question; char command[256] = {'\0'}; struct context **cnt = userdata; warningkill = sscanf(pointer, "%255[a-z]%c", command, &question); if (!strcmp(command, "set")) { pointer=pointer+3;length_uri=length_uri-3; /* FIXME need to check each value */ /* Relative movement set?pan=0&tilt=0 | set?pan=0 | set?tilt=0*/ /* Absolute movement set?x=0&y=0 | set?x=0 | set?y=0 */ if ((question == '?') && (length_uri > 2)) { char panvalue[12] = {'\0'}, tiltvalue[12] = {'\0'}; char x_value[12] = {'\0'}, y_value[12] = {'\0'}; struct context *setcnt; int pan = 0, tilt = 0, X = 0 , Y = 0; pointer++; length_uri--; /* set?pan=value&tilt=value */ /* set?x=value&y=value */ /* pan= or x= | tilt= or y= */ warningkill = sscanf (pointer, "%255[a-z]%c" , command, &question); if (( question != '=' ) || (command[0] == '\0')) { /* no valid syntax */ motion_log(LOG_WARNING, 0, "httpd debug race 1"); 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); return 1; } pointer++; length_uri--; /* Check first parameter */ if (!strcmp(command, "pan")) { pointer = pointer + 3; length_uri = length_uri - 3; pan = 1; if ((warningkill = sscanf(pointer, "%10[-0-9]", panvalue))){ pointer = pointer + strlen(panvalue); length_uri = length_uri - strlen(panvalue); } } else if (!strcmp(command, "tilt")) { pointer = pointer + 4; length_uri = length_uri - 4; tilt = 1; if ((warningkill = sscanf(pointer, "%10[-0-9]", tiltvalue))){ pointer = pointer + strlen(tiltvalue); length_uri = length_uri - strlen(tiltvalue); } } else if (!strcmp(command, "x")) { pointer++; length_uri--; X = 1; if ((warningkill = sscanf(pointer, "%10[-0-9]", x_value))){ pointer = pointer + strlen(x_value); length_uri = length_uri - strlen(x_value); } } else if (!strcmp(command, "y")) { pointer++; length_uri--; Y = 1; if ((warningkill = sscanf (pointer, "%10[-0-9]" , y_value))){ pointer = pointer + strlen(y_value); length_uri = length_uri - strlen(y_value); } } else { /* no valid syntax */ motion_log(LOG_WARNING, 0, "httpd debug race 2"); 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); return 1; } /* first value check for error */ if ( !warningkill ) { motion_log(LOG_WARNING, 0, "httpd debug race 3"); /* error value */ if (cnt[0]->conf.control_html_output) response_client(client_socket, error_value, NULL); else response_client(client_socket, error_value_raw, NULL); return 1; } /* Only one parameter (pan= ,tilt= ,x= ,y= ) */ if (length_uri == 0) { if (pan) { struct coord cent; struct context *pancnt; /* move pan */ pancnt = cnt[thread]; cent.width = pancnt->imgs.width; cent.height = pancnt->imgs.height; cent.y = 0; cent.x = atoi(panvalue); // Add the number of frame to skip for motion detection cnt[thread]->moved = track_move(pancnt, pancnt->video_dev, ¢, &pancnt->imgs, 1); if (cnt[thread]->moved) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b><br>\n" "track set relative pan=%s<br>\n", thread, thread, panvalue); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "track set relative pan=%s\nDone\n", panvalue); send_template_raw(client_socket, res); } } else { /*error in track action*/ if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b>\n", thread, thread); response_client(client_socket, track_error, res); } else response_client(client_socket, track_error_raw, NULL); } } else if (tilt) { struct coord cent; struct context *tiltcnt; /* move tilt */ tiltcnt = cnt[thread]; cent.width = tiltcnt->imgs.width; cent.height = tiltcnt->imgs.height; cent.x = 0; cent.y = atoi(tiltvalue); // Add the number of frame to skip for motion detection cnt[thread]->moved=track_move(tiltcnt, tiltcnt->video_dev, ¢, &tiltcnt->imgs, 1); if (cnt[thread]->moved){ if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b><br>\n" "track set relative tilt=%s\n", thread, thread, tiltvalue); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "track set relative tilt=%s\nDone\n",tiltvalue); send_template_raw(client_socket, res); } } else { /*error in track action*/ if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b>\n", thread, thread); response_client(client_socket, track_error, res); } else response_client(client_socket, track_error_raw, NULL); } } else if (X){ /* X */ setcnt = cnt[thread]; // 1000 is out of range for pwc cnt[thread]->moved = track_center(setcnt, setcnt->video_dev, 1, atoi(x_value), 1000); if (cnt[thread]->moved) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b><br>\n" "track set absolute x=%s\n", thread, thread, x_value); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "track set absolute x=%s\nDone\n", x_value); send_template_raw(client_socket, res); } } else { /*error in track action*/ if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b>\n", thread, thread); response_client(client_socket, track_error, res); } else response_client(client_socket, track_error_raw, NULL); } } else { /* Y */ setcnt = cnt[thread]; // 1000 is out of range for pwc cnt[thread]->moved = track_center(setcnt, setcnt->video_dev, 1, 1000, atoi(y_value)); if (cnt[thread]->moved) { if (cnt[0]->conf.control_html_output) { send_template_ini_client(client_socket, ini_template); sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b><br>\n" "track set absolute y=%s<br>\n", thread, thread, y_value); send_template(client_socket, res); send_template_end_client(client_socket); } else { send_template_ini_client_raw(client_socket); sprintf(res, "track set absolute y=%s\nDone\n", y_value); send_template_raw(client_socket, res); } } else { /*error in track action*/ if (cnt[0]->conf.control_html_output) { sprintf(res, "<a href=/%hu/track><– back</a><br><br>" "<b>Thread %hu</b>\n", thread, thread); response_client(client_socket, track_error, res); } else response_client(client_socket, track_error_raw, NULL); } } return 1; } /* Check Second parameter */ warningkill = sscanf (pointer, "%c%255[a-z]" ,&question, command); if ( ( question != '&' ) || (command[0] == '\0') ){ motion_log(LOG_WARNING, 0, "httpd debug race 4"); if ( strstr(pointer,"&")){ if (cnt[0]->conf.control_html_output) response_client(client_socket, error_value, NULL); else response_client(client_socket, error_value_raw, NULL); } /* no valid syntax */ else{ 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); } return 1; } pointer++; length_uri--; if (!strcmp(command, "pan")){ pointer = pointer + 3; length_uri = length_uri - 3; if ( (pan) || (!tilt) || (X) || (Y) ) { motion_log(LOG_WARNING, 0, "httpd debug race 5"); /* no valid syntax */ 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); return 1; } pan=2; warningkill = sscanf (pointer, "%c%10[-0-9]" ,&question, panvalue); } else if (!strcmp(command, "tilt")) { pointer = pointer + 4; length_uri = length_uri - 4; if ( (tilt) || (!pan) || (X) || (Y) ) { /* no valid syntax */ motion_log(LOG_WARNING, 0, "httpd debug race 6"); 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); return 1; } tilt = 2; warningkill = sscanf (pointer, "%c%10[-0-9]" ,&question, tiltvalue); } else if (!strcmp(command, "x")) { pointer++; length_uri--; if ( (X) || (!Y) || (pan) || (tilt) ) { motion_log(LOG_WARNING, 0, "httpd debug race 7"); /* no valid syntax */ 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); return 1; } X = 2; warningkill = sscanf (pointer, "%c%10[-0-9]" ,&question, x_value); } else if (!strcmp(command, "y")) { pointer++; length_uri--; if ( (Y) || (!X) || (pan) || (tilt) ){ motion_log(LOG_WARNING, 0, "httpd debug race 8"); /* no valid syntax */ 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); return 1; } Y = 2; warningkill = sscanf (pointer, "%c%10[-0-9]" ,&question, y_value); } else { motion_log(LOG_WARNING, 0, "httpd debug race 9"); /* no valid syntax */ 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); return 1; } /* Second value check */ if ( ( warningkill < 2 ) && (question != '=') ) { motion_log(LOG_WARNING, 0, "httpd debug race 10"); /* no valid syntax */ 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); return 1; }else if (( question == '=') && ( warningkill == 1)){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -