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

📄 conf.c

📁 video motion detection of linux base
💻 C
📖 第 1 页 / 共 4 页
字号:
	copy_int,	print_int	},	{	"track_speed",	"# Speed to set the motor to (stepper motor option) (default: 255)",	TRACK_OFFSET(speed),	copy_int,	print_int	},	{	"track_stepsize",	"# Number of steps to make (stepper motor option) (default: 40)",	TRACK_OFFSET(stepsize),	copy_int,	print_int	},	{	"quiet",	"\n############################################################\n"	"# External Commands, Warnings and Logging:\n"	"# You can use conversion specifiers for the on_xxxx commands\n"	"# %Y = year, %m = month, %d = date,\n"	"# %H = hour, %M = minute, %S = second,\n"	"# %v = event, %q = frame number, %t = thread (camera) number,\n"	"# %D = changed pixels, %N = noise level,\n"	"# %i and %J = width and height of motion area,\n"	"# %K and %L = X and Y coordinates of motion center\n"	"# %C = value defined by text_event\n"	"# %f = filename with full path\n"	"# %n = number indicating filetype\n"	"# Both %f and %n are only defined for on_picture_save,\n"	"# on_movie_start and on_movie_end\n" 	"# Quotation marks round string are allowed.\n"	"############################################################\n\n"	"# Do not sound beeps when detecting motion (default: on)\n"	"# Note: Motion never beeps when running in daemon mode.",	CONF_OFFSET(quiet),	copy_bool,	print_bool	},	{	"on_event_start",	"# Command to be executed when an event starts. (default: none)\n"	"# An event starts at first motion detected after a period of no motion defined by gap ",	CONF_OFFSET(on_event_start),	copy_string,	print_string	},	{	"on_event_end",	"# Command to be executed when an event ends after a period of no motion\n"	"# (default: none). The period of no motion is defined by option gap.",	CONF_OFFSET(on_event_end),	copy_string,	print_string	},	{	"on_picture_save",	"# Command to be executed when a picture (.ppm|.jpg) is saved (default: none)\n"	"# To give the filename as an argument to a command append it with %f",	CONF_OFFSET(on_picture_save),	copy_string,	print_string	},	{	"on_motion_detected",	"# Command to be executed when a motion frame is detected (default: none)",	CONF_OFFSET(on_motion_detected),	copy_string,	print_string	},#ifdef HAVE_FFMPEG	{	"on_movie_start",	"# Command to be executed when a movie file (.mpg|.avi) is created. (default: none)\n"	"# To give the filename as an argument to a command append it with %f",	CONF_OFFSET(on_movie_start),	copy_string,	print_string	},	{	"on_movie_end",	"# Command to be executed when a movie file (.mpg|.avi) is closed. (default: none)\n"	"# To give the filename as an argument to a command append it with %f",	CONF_OFFSET(on_movie_end),	copy_string,	print_string	},#endif /* HAVE_FFMPEG */#if defined(HAVE_MYSQL) || defined(HAVE_PGSQL)	{	"sql_log_image",	"\n############################################################\n"	"# Common Options For MySQL and PostgreSQL database features.\n"	"# Options require the MySQL/PostgreSQL options to be active also.\n"	"############################################################\n\n"	"# Log to the database when creating motion triggered image file  (default: on)",	CONF_OFFSET(sql_log_image),	copy_bool,	print_bool	},	{	"sql_log_snapshot",	"# Log to the database when creating a snapshot image file (default: on)",	CONF_OFFSET(sql_log_snapshot),	copy_bool,	print_bool	},	{	"sql_log_mpeg",	"# Log to the database when creating motion triggered mpeg file (default: off)",	CONF_OFFSET(sql_log_mpeg),	copy_bool,	print_bool	},	{	"sql_log_timelapse",	"# Log to the database when creating timelapse mpeg file (default: off)",	CONF_OFFSET(sql_log_timelapse),	copy_bool,	print_bool	},	{	"sql_query",	"# SQL query string that is sent to the database\n"	"# Use same conversion specifiers has for text features\n"	"# Additional special conversion specifiers are\n"	"# %n = the number representing the file_type\n"	"# %f = filename with full path\n"	"# Default value:\n"	"# insert into security(camera, filename, frame, file_type, time_stamp, text_event) values('%t', '%f', '%q', '%n', '%Y-%m-%d %T', '%C')",	CONF_OFFSET(sql_query),	copy_string,	print_string	},#endif /* defined(HAVE_MYSQL) || defined(HAVE_PGSQL) */#ifdef HAVE_MYSQL	{	"mysql_db",	"\n############################################################\n"	"# Database Options For MySQL\n"	"############################################################\n\n"	"# Mysql database to log to (default: not defined)",	CONF_OFFSET(mysql_db),	copy_string,	print_string	},	{	"mysql_host",	"# The host on which the database is located (default: not defined)",	CONF_OFFSET(mysql_host),	copy_string,	print_string	},	{	"mysql_user",	"# User account name for MySQL database (default: not defined)",	CONF_OFFSET(mysql_user),	copy_string,	print_string	},	{	"mysql_password",	"# User password for MySQL database (default: not defined)",	CONF_OFFSET(mysql_password),	copy_string,	print_string	},#endif /* HAVE_MYSQL */#ifdef HAVE_PGSQL	{	"pgsql_db",	"\n############################################################\n"	"# Database Options For PostgreSQL\n"	"############################################################\n\n"	"# PostgreSQL database to log to (default: not defined)",	CONF_OFFSET(pgsql_db),	copy_string,	print_string	},	{	"pgsql_host",	"# The host on which the database is located (default: not defined)",	CONF_OFFSET(pgsql_host),	copy_string,	print_string	},	{	"pgsql_user",	"# User account name for PostgreSQL database (default: not defined)",	CONF_OFFSET(pgsql_user),	copy_string,	print_string	},	{	"pgsql_password",	"# User password for PostgreSQL database (default: not defined)",	CONF_OFFSET(pgsql_password),	copy_string,	print_string	},	{	"pgsql_port",	"# Port on which the PostgreSQL database is located (default: 5432)",	CONF_OFFSET(pgsql_port),	copy_int,	print_int	},#endif /* HAVE_PGSQL */		{	"video_pipe",	"\n############################################################\n"	"# Video Loopback Device (vloopback project)\n"	"############################################################\n\n"	"# Output images to a video4linux loopback device\n"	"# The value '-' means next available (default: not defined)",	CONF_OFFSET(vidpipe),	copy_string,	print_string	},	{	"motion_video_pipe",	"# Output motion images to a video4linux loopback device\n"	"# The value '-' means next available (default: not defined)",	CONF_OFFSET(motionvidpipe),	copy_string,	print_string	},/*	{	"debug_parameter",	"\n############################################################\n"	"# Thread Config Files - One for each camera\n"	"# If Only One Camera - Use default values in this file\n"	"############################################################\n\n",	//"# Debug option for programmers - not normally used",	CONF_OFFSET(debug_parameter),	copy_int,	print_int	},*/	{	"thread",	"\n##############################################################\n"	"# Thread config files - One for each camera.\n"	"# Except if only one camera - You only need this config file.\n"	"# If you have more than one camera you MUST define one thread\n"	"# config file for each camera in addition to this config file.\n"	"##############################################################\n",	0,	config_thread,	print_thread	},	{ NULL, NULL, 0 , NULL, NULL }};/* conf_cmdline sets the conf struct options as defined by the command line. * Any option already set from a config file are overridden. */static void conf_cmdline (struct context *cnt, int thread){	struct config *conf=&cnt->conf;	int c;	/* For the string options, we free() if necessary and malloc()	 * if necessary. This is accomplished by calling mystrcpy();	 * see this function for more information.	 */	while ((c=getopt(conf->argc, conf->argv, "c:d:hns?p"))!=EOF)		switch (c) {			case 'c':				if (thread==-1) strcpy(cnt->conf_filename, optarg);				break;			case 'n':				cnt->daemon=0;				break;			case 's':				conf->setup_mode=1;				break;			case 'd':				/* no validation - just take what user gives */				debug_level = atoi(optarg);				break;			case 'p':				cnt->conf.pid_file = mystrcpy(cnt->conf.pid_file, optarg);				break;				case 'h':			case '?':			default:				usage();				exit(1);		}	optind=1;}/* conf_cmdparse sets a config option given by 'cmd' to the value given by 'arg1'. * Based on the name of the option it searches through the struct 'config_params' * for an option where the config_params[i].param_name matches the option. * By calling the function pointed to by config_params[i].copy the option gets * assigned. */struct context **conf_cmdparse(struct context **cnt, const char *cmd, const char *arg1){	int i = 0;	if(!cmd)		return cnt;	/* We search through config_params until we find a param_name that matches	 * our option given by cmd (or reach the end = NULL)	 */	while( config_params[i].param_name != NULL ) {		if(!strncasecmp(cmd, config_params[i].param_name , 255 + 50)) { // Why +50?				/* if config_param is string we don't want to check arg1 */					if (strcmp(config_type(&config_params[i]),"string")) {				if(config_params[i].conf_value && !arg1)					return cnt;			}						/* We call the function given by the pointer config_params[i].copy			 * If the option is a bool, copy_bool is called.			 * If the option is an int, copy_int is called.			 * If the option is a string, copy_string is called.			 * If the option is a thread, config_thread is called.			 * The arguments to the function are:			 *  cnt  - a pointer to the context structure			 *  arg1 - a pointer to the new option value (represented as string)			 *  config_params[i].conf_value - an integer value which is a pointer			 *    to the context structure member relative to the pointer cnt.			 */			cnt=config_params[i].copy( cnt, arg1, config_params[i].conf_value );			return cnt;		}		i++;	}	/* We reached the end of config_params without finding a matching option */	motion_log(LOG_ERR, 0, "Unknown config option \"%s\"",cmd);	return cnt;}/* conf_process walks through an already open config file line by line * Any line starting with '#' or ';' or empty lines are ignored as a comments. * Any non empty line is process so that the first word is the name of an option 'cnd' * and the rest of the line is the argument 'arg1' * White space before the first word, between option and argument and end of the line * is discarded. A '=' between option and first word in argument is also discarded. * Quotation marks round the argument are also discarded. * For each option/argument pair the function conf_cmdparse is called which takes * care of assigning the value to the option in the config structures. */static struct context **conf_process(struct context **cnt, FILE *fp){	/* process each line from the config file */		char line[PATH_MAX], *cmd = NULL, *arg1 = NULL;	char *beg = NULL, *end = NULL;	while (fgets(line, PATH_MAX-1, fp)) {		if(!(line[0]=='#' || line[0]==';' || strlen(line)< 2)) {/* skipcomment */						arg1 = NULL;			/* trim white space and any CR or LF at the end of the line */			end = line + strlen(line) - 1; /* Point to the last non-null character in the string */			while (*end == ' ' || *end == '\t' || *end == '\n' || *end == '\r') {				end--;			}			*(end+1) = '\0';						/* If line is only whitespace we continue to the next line */			if (strlen(line) == 0)				continue;			/* trim leading whitespace from the line and find command */			beg = line;			while (*beg == ' ' || *beg == '\t') {				beg++;			}			cmd = beg; /* command starts here */			while (*beg != ' ' && *beg != '\t' && *beg != '=' && *beg != '\0') {				beg++;			}			*beg = '\0'; /* command string terminates here */			/* trim space between command and argument */			beg++;			if (strlen(beg) > 0){				while (*beg == ' ' || *beg == '\t' || *beg == '=' || *beg == '\n' || *beg == '\r') {					beg++;				}				/* If argument is in "" we will strip them off				   It is important that we can use "" so that we can use				   leading spaces in text_left and text_right */				if ((beg[0]=='"' && beg[strlen(beg)-1]=='"') ||				    (beg[0]=='\'' && beg[strlen(beg)-1]=='\'')) {					beg[strlen(beg)-1]='\0';					beg++;				}								arg1 = beg; /* Argument starts here */			}			/* else arg1 stays null pointer */			cnt = conf_cmdparse(cnt, cmd, arg1);		}	}	return cnt;}/* conf_print is used to write out the config file(s) motion.conf and any thread * config files. The function is called when using http remote control. */void conf_print(struct context **cnt){	const char *retval;	char *val;	int i, thread;	FILE *conffile;	for (thread=0; cnt[thread]; thread++) {		motion_log(LOG_INFO, 1, "Writing config file to %s",cnt[thread]->conf_filename);		conffile=myfopen(cnt[thread]->conf_filename, "w");		if (!conffile)			continue;		fprintf(conffile, "# %s\n", cnt[thread]->conf_filename);		fprintf(conffile, "#\n# This config file was generated by motion " VERSION "\n");		fprintf(conffile, "\n\n");		for (i=0; config_params[i].param_name; i++) {			retval=config_params[i].print(cnt, NULL, i, thread);			/*If config parameter has a value (not NULL) print it to the config file*/			if (retval) {				fprintf(conffile, "%s\n", config_params[i].param_help);				/* If the option is a text_* and first char is a space put				   quotation marks around to allow leading spaces */				if (strncmp(config_params[i].param_name, "text", 4) || strncmp(retval, " ", 1))					fprintf(conffile, "%s %s\n\n", config_params[i].param_name, retval);				else					fprintf(conffile, "%s \"%s\"\n\n", config_params[i].param_name, retval);			} else {				val = NULL;				config_params[i].print(cnt, &val, i, thread);				/* It can either be a thread file parameter or a disabled parameter				   If it is a thread parameter write it out				   Else write the disabled option to the config file but with a				   comment mark in front of the parameter name */				if (val) {					fprintf(conffile,"%s\n", config_params[i].param_help);					fprintf(conffile, "%s\n", val);					if (strlen(val)==0)

⌨️ 快捷键说明

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