⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 webhttpd.c

📁 video motion detection of linux base
💻 C
📖 第 1 页 / 共 5 页
字号:
				while (cnt[++i])					cnt[i]->snapshot=1;			} else {				cnt[thread]->snapshot=1;			}			cnt[thread]->snapshot = 1;			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res,"snapshot 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,"snapshot 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, "restart")) {		pointer = pointer + 7;		length_uri = length_uri - 7;		if (length_uri == 0) {			int i = 0;			do {				motion_log(LOG_DEBUG, 0, "httpd restart");				kill(getpid(),1);			} while (cnt[++i]);			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res,"restart in progress ... bye<br>\n<a href='/'>Home</a>");				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				sprintf(res,"restart in progress ...\nDone\n");				send_template_raw(client_socket, res);			}			return 0; // to restart		} 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 (!strcmp(command,"quit")) {		pointer = pointer + 4;		length_uri = length_uri - 4;		if (length_uri == 0) {			int i = 0;			/*call quit*/			do {				motion_log(LOG_DEBUG, 0, "httpd quitting");				cnt[i]->makemovie = 1;				cnt[i]->finish = 1;			} while (cnt[++i]);			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res,"quit in progress ... bye");				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				sprintf(res,"quit in progress ... bye\nDone\n");				send_template_raw(client_socket, res);			}			return 0; // to quit		} 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 detection actions for motion ( status , start , pause ).*/static int detection(char *pointer, char *res, int length_uri, int thread, int client_socket, void *userdata){	char command[256]={'\0'};	struct context **cnt=userdata;	warningkill = sscanf (pointer, "%256[a-z]" , command);	if (!strcmp(command,"status")) {		pointer = pointer + 6;		length_uri = length_uri - 6;		if (length_uri == 0) {			/*call status*/			if (cnt[thread]->pause)				sprintf(res, "Thread %d Detection status PAUSE\n", thread);			else				sprintf(res, "Thread %d Detection status ACTIVE\n", thread);			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				send_template(client_socket, res);				sprintf(res, "<br><a href=/%d/detection><- back</a>\n", thread);				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				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, "start")) {		pointer = pointer + 5;		length_uri = length_uri - 5;		if (length_uri == 0) {			/*call start*/			int i = 0;			cnt[thread]->pause = 0;			if (thread == 0) {				do {					cnt[i]->pause = 0;				} while (cnt[++i]);			} else {				cnt[thread]->pause = 0;			}			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket,ini_template);				sprintf(res,"Thread %i Detection resumed<br>\n"				            "<a href=/%d/detection><- 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 %i Detection resumed\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,"pause")){		pointer = pointer + 5;		length_uri = length_uri - 5;		if (length_uri==0) {			/*call pause*/			int i = 0;						cnt[thread]->pause=1;			if (thread == 0) {				do {					cnt[i]->pause = 1;				} while (cnt[++i]);			} else {				cnt[thread]->pause = 1;			}						if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res,"Thread %i Detection paused<br>\n"				            "<a href=/%d/detection><- 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 %i Detection paused\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 (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 ).*/static int track(char *pointer, char *res, int length_uri, int thread, int client_socket, void *userdata){	char question;	char command[256] = {'\0'};	struct context **cnt = userdata;	warningkill = sscanf(pointer, "%256[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, "%256[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, &cent, &pancnt->imgs, 1);					if (cnt[thread]->moved) {						if (cnt[0]->conf.control_html_output) {							send_template_ini_client(client_socket, ini_template);							sprintf(res,"track set relative pan=%s<br>\n"							            "<a href=/%d/track><- back</a>\n", panvalue, thread);							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=/%d/track><- back</a>\n", 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, &cent, &tiltcnt->imgs, 1);					if (cnt[thread]->moved){							if (cnt[0]->conf.control_html_output) {							send_template_ini_client(client_socket, ini_template);							sprintf(res,"track set relative tilt=%s<br>\n"							            "<a href=/%d/track><- back</a>\n", tiltvalue, thread);							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=/%d/track><- back</a>\n", 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,"track set absolute x=%s<br>\n"							            "<a href=/%d/track><- back</a>\n", x_value, thread);							send_template(client_socket, res);							send_template_end_client(client_socket);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -