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

📄 webhttpd.c

📁 motion motion
💻 C
📖 第 1 页 / 共 5 页
字号:
				motion_log(LOG_WARNING, 0, "httpd debug race 11");				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;			}									if (pan == 2){				pointer = pointer + strlen(panvalue) + 1;				length_uri = length_uri - strlen(panvalue) - 1;				}			else if (tilt == 2){				pointer = pointer + strlen(tiltvalue) + 1;				length_uri = length_uri - strlen(tiltvalue) - 1;			}			else if (X == 2){				pointer = pointer + strlen(x_value) + 1;				length_uri = length_uri - strlen(x_value) - 1;			}			else{				pointer = pointer + strlen(y_value) + 1;				length_uri = length_uri - strlen(y_value) - 1;			}										if (length_uri != 0) {				motion_log(LOG_WARNING, 0, "httpd debug race 12");				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;			}			/* track set absolute ( x , y )*/			if ( X && Y ) {				setcnt = cnt[thread];				cnt[thread]->moved = track_center(setcnt, setcnt->video_dev, 1, atoi(x_value), 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>&lt;&ndash; back</a><br><br>"						             "<b>Thread %hu</b><br>\n"						             "track absolute set x=%s y=%s<br>\n",						             thread, thread, x_value, y_value);						send_template(client_socket, res);						send_template_end_client(client_socket);					} else {						send_template_ini_client_raw(client_socket);						sprintf(res, "track absolute set x=%s y=%s\nDone\n", x_value, 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>&lt;&ndash; 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);				}				/* track set relative ( pan , tilt )*/			} else {				struct coord cent;				struct context *relativecnt;				/* move pan */				relativecnt = cnt[thread];				cent.width = relativecnt->imgs.width;				cent.height = relativecnt->imgs.height;				cent.y = 0;				cent.x = atoi(panvalue);				// Add the number of frame to skip for motion detection				cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, &cent, &relativecnt->imgs, 1);				if (cnt[thread]->moved){					/* move tilt */					relativecnt = cnt[thread];					cent.width = relativecnt->imgs.width;					cent.height = relativecnt->imgs.height;					cent.x = 0;					cent.y = atoi(tiltvalue);					SLEEP(1,0);					cnt[thread]->moved = track_move(relativecnt, relativecnt->video_dev, &cent, &relativecnt->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>&lt;&ndash; back</a><br><br>"							             "<b>Thread %hu</b><br>\n"							             "track relative pan=%s tilt=%s\n",							             thread, thread, panvalue, tiltvalue);							send_template(client_socket, res);							send_template_end_client(client_socket);						} else {							send_template_ini_client_raw(client_socket);							sprintf(res, "track relative pan=%s tilt=%s\nDone\n", panvalue, tiltvalue);							send_template_raw(client_socket, res);						}						return 1;					}					else{						/*error in track tilt*/							if (cnt[0]->conf.control_html_output) {							sprintf(res, "<a href=/%hu/track>&lt;&ndash; 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);					}				}				/*error in track pan*/				if (cnt[0]->conf.control_html_output) {					sprintf(res, "<a href=/%hu/track>&lt;&ndash; 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 (length_uri == 0) {			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res, "<a href=/%hu/track>&lt;&ndash; back</a><br><br>\n<b>Thread %hu</b><br>\n"				             "<form action='set'>\n"				             "Pan<input type=text name='pan' value=''>\n"				             "Tilt<input type=text name='tilt' value=''>\n"				             "<input type=submit value='set relative'>\n"				             "</form>\n"				             "<form action='set'>\n"				             "X<input type=text name='x' value=''>\n"				             "Y<input type=text name='y' value=''>\n"				             "<input type=submit value='set absolute'>\n"				             "</form>\n", thread, thread);				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				sprintf(res, "set needs a pan/tilt or x/y values\n");				send_template_raw(client_socket, res);			}		} else {			/* error not valid command */			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,"status")) {		pointer = pointer+6;		length_uri = length_uri-6;		if (length_uri==0) {			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket, ini_template);				sprintf(res, "<a href=/%hu/track>&lt;&ndash; back</a><br><br>\n<b>Thread %hu</b>"				             "<br>track auto %s", thread, thread, 				             (cnt[thread]->track.active)? "enabled":"disabled");				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				sprintf(res, "Thread %hu\n track auto %s\nDone\n",thread, 				             (cnt[thread]->track.active)? "enabled":"disabled");				send_template_ini_client_raw(client_socket);				send_template_raw(client_socket, res);			}		} else {			/* error not valid command */			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,"auto")) {		pointer = pointer + 4;		length_uri = length_uri - 4;		if ((question == '?') && (length_uri > 0)) {			char query[256] = {'\0'};			pointer++;			length_uri--;			/* value= */			warningkill = sscanf (pointer, "%255[a-z]%c",query,&question);			if ((question == '=') && (!strcmp(query,"value")) ) {				pointer = pointer + 6;				length_uri = length_uri - 6;				warningkill = sscanf (pointer, "%255[-0-9a-z]" , command);				if ((command!=NULL) && (strlen(command) > 0)) {					struct context *autocnt;					/* auto value=0|1|status*/					if (!strcmp(command,"status")) {						if (cnt[0]->conf.control_html_output) {							send_template_ini_client(client_socket, ini_template);							sprintf(res, "<a href=/%hu/track>&lt;&ndash; back</a><br><br>"							             "<b>Thread %hu</b><br>"								     "track auto %s", thread, thread, 								    (cnt[thread]->track.active)? "enabled":"disabled");							send_template(client_socket, res);							send_template_end_client(client_socket);						} else {							sprintf(res, "Thread %hu\n track auto %s\nDone\n", thread, 								     (cnt[thread]->track.active)? "enabled":"disabled");							send_template_ini_client_raw(client_socket);							send_template_raw(client_socket, res);						}					} else {						int active;						active = atoi(command);						/* CHECK */						if (active > -1 && active < 2) {							autocnt = cnt[thread];							autocnt->track.active = active;							if (cnt[0]->conf.control_html_output) {								send_template_ini_client(client_socket, ini_template);								sprintf(res, "<a href=/%hu/track>&lt;&ndash; back</a><br><br>"								             "<b>Thread %hu</b>"							 	             "<br>track auto %s<br>", thread, thread, 								             active ? "enabled":"disabled");								send_template(client_socket, res);								send_template_end_client(client_socket);							} else {								send_template_ini_client_raw(client_socket);								sprintf(res, "track auto %s\nDone\n",active ? "enabled":"disabled");								send_template_raw(client_socket, res);							}						} 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 (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/track>&lt;&ndash; back</a><br><br>\n<b>Thread %hu</b>\n"				             "<form action='auto'><select name='value'>\n"				             "<option value='0' %s>Disable</option><option value='1' %s>Enable</option>\n"				             "<option value='status'>status</option>\n"				             "</select><input type=submit value='set'>\n"				             "</form>\n",thread, thread, (cnt[thread]->track.active) ? "selected":"",				             (cnt[thread]->track.active) ? "selected":"" );				send_template(client_socket, res);				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				sprintf(res, "auto accepts only  0,1 or status as valid value\n");				send_template_raw(client_socket, res);			}		} 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);	}	return 1;}/*	parses the action requested for motion ( config , action , detection , track ) and call	to action function if needed.	return 0 on action restart or quit 	return 1 on success	*/static unsigned short int handle_get(int client_socket, const char* url, void *userdata){	struct context **cnt=userdata;	if (*url == '/' ){		unsigned short int i = 0;		char *res=NULL;		res = malloc(2048);		/* get the number of threads */		while (cnt[++i]);		/* ROOT_URI -> GET / */		if (! (strcmp (url, "/")) ) {			unsigned short int y;			if (cnt[0]->conf.control_html_output) {				send_template_ini_client(client_socket,ini_template);				sprintf(res, "<b>Motion "VERSION" Running [%hu] Threads</b><br>\n"				             "<a href='/0/'>All</a><br>\n", i);				send_template(client_socket, res);				for (y=1; y<i; y++) {					sprintf(res, "<a href='/%hu/'>Thread %hu</a><br>\n", y, y);					send_template(client_socket, res);				}				send_template_end_client(client_socket);			} else {				send_template_ini_client_raw(client_socket);				sprintf(res, "Motion "VERSION" Running [%hu] Threads\n0\n", i);				send_template_raw(client_socket, res);				for (y=1; y<i; y++) {					sprintf(res, "%hu\n", y);					send_template_raw(client_socket, res);				}			}		}		else {			char command[256] = {'\0'};			char slash;			short int thread = -1;			size_t length_uri = 0;			char *pointer = (char *)url;			length_uri = strlen(url);			/* Check for Thread number first -> GET /2 */			pointer++;			length_uri--;			warningkill = sscanf (pointer, "%hd%c", &thread, &slash);			if ((thread != -1) && (thread < i)) {				/* thread_number found */				if (thread > 9){					pointer = pointer + 2;					length_uri = length_uri - 2;				}else{					pointer++;					length_uri--;					}								if (slash == '/') {   /* slash found /2/ */					pointer++;					length_uri--;				} 				if (length_uri!=0) {					warningkill = sscanf (pointer, "%255[a-z]%c" , command , &slash);					/* config */					if (!strcmp(command,"config")) {						pointer = pointer + 6;						length_uri = length_uri - 6;						if (length_uri == 0) {							if (cnt[0]->conf.control_html_output) {								send_template_ini_client(client_socket, ini_template);								sprintf(res, "<a href=/%hd/>&lt;&ndash; back</a><br><br>\n"								             "<b>Thread %hd</b><br>\n"								             "<a href=/%hd/config/list>list</a><br>\n"								             "<a href=/%hd/config/write>write</a><br>\n"								             "<a href=/%hd/config/set>set</a><br>\n"								             "<a href=/%hd/config/get>get</a><br>\n",								             thread, thread, thread, thread, thread, thread);								send_template(client_socket, res);								send_template_end_client(client_socket);							} else {								send_template_ini_client_raw(client_socket);								sprintf(res, "Thread %hd\nlist\nwrite\nset\nget\n", thread);								send_template_raw(client_socket, res);							}						} else if ((slash == '/') && (length_uri >= 4)) {							/*call config() */							pointer++;							length_uri--;							config(pointer, res, length_uri, thread, client_socket, cnt);						} else {							if (cnt[0]->conf.control_html_output)								response_client(client_socket, not_found_respon

⌨️ 快捷键说明

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