コード例 #1
0
/* Function which parses command options; returns true if it
   ate an option */
static int parse(	int c, 
			char **argv,
			int invert,
			unsigned int *flags,
#ifdef _XTABLES_H
			const void *entry,
#else
			const struct ipt_entry *entry,
			unsigned int *nfcache,
#endif			
			struct ipt_entry_match **match
			)
{
	struct ipt_weburl_info *info = (struct ipt_weburl_info *)(*match)->data;
	int valid_arg = 0;

	if(*flags < 10)
	{
		info->match_part = WEBURL_ALL_PART;
	}

	switch (c)
	{
		case WEBURL_CONTAINS_TYPE:
		case WEBURL_REGEX_TYPE:
		case WEBURL_EXACT_TYPE:
		case WEBURL_CONTAINS_NOCASE_TYPE:
			info->match_type = c;

			//test whether to invert rule
			my_check_inverse(optarg, &invert, &optind, 0);
			info->invert = invert ? 1 : 0;
	
			//test that test string is reasonable length, then to info
			int testlen = strlen(argv[optind-1]);
			if(testlen > 0 && testlen < MAX_TEST_STR)
			{
				strcpy(info->test_str, argv[optind-1]);
			}
			else if(testlen >= MAX_TEST_STR)
			{
				char err[100];
				sprintf(err, "Parameter definition is too long, must be less than %d characters", MAX_TEST_STR);
				param_problem_exit_error(err);
			}
			else
			{
				param_problem_exit_error("Parameter definition is incomplete");
			}

			if(*flags % 10 == 1)
			{
				param_problem_exit_error("You may only specify one string/pattern to match");
			}
			*flags = *flags + 1;
			
			valid_arg = 1;
			break;

		case WEBURL_DOMAIN_PART:
		case WEBURL_PATH_PART:
			info->match_part = c;
			if(*flags >= 10)
			{
				param_problem_exit_error("You may specify at most one part of the url to match:\n\t--domain_only, --path_only or neither (to match full url)\n");
			}
			*flags = *flags+10;
			
			valid_arg = 1;
			break;
	}
	
	return valid_arg;
}
コード例 #2
0
/* Function which parses command options; returns true if it
   ate an option */
static int parse(	int c, 
			char **argv,
			int invert,
			unsigned int *flags,
#ifdef _XTABLES_H
			const void *entry,
#else
			const struct ipt_entry *entry,
			unsigned int *nfcache,
#endif			
			struct ipt_entry_match **match
			)
{
	struct ipt_timerange_info *info = (struct ipt_timerange_info *)(*match)->data;
	int valid_arg = 0;
	if(*flags == 0)
	{
		my_check_inverse(optarg, &invert, &optind, 0);
		info->invert = invert ? 1 : 0;
	}

	long* parsed = NULL;
	switch (c)
	{
		case HOURS:
			parsed = parse_time_ranges(argv[optind-1], 0);
			if(parsed != NULL && (*flags & HOURS) == 0 && (*flags & WEEKLY_RANGE) == 0)
			{
				int range_index = 0;
				for(range_index = 0; parsed[range_index] != -1; range_index++)
				{
					if(range_index > 100)
					{
						return 0;
					}
					info->ranges[range_index] = parsed[range_index];
				}
				info->ranges[range_index] = -1;
				free(parsed);


				valid_arg = 1;
				*flags = *flags+ c;
				info->type = *flags;
			}
			break;


		case WEEKDAYS:
			parsed = parse_weekdays(argv[optind-1]);
			if(parsed != NULL && (*flags & WEEKDAYS) == 0 && (*flags & WEEKLY_RANGE) == 0)
			{
				int day_index;
				for(day_index=0; day_index < 7; day_index++)
				{
					info->days[day_index] = parsed[day_index];
				}
				free(parsed);

				valid_arg = 1 ;
				*flags = *flags + c;
				info->type = *flags;
			}
			break;
		case WEEKLY_RANGE:
			parsed = parse_time_ranges(argv[optind-1], 1);
			if(parsed != NULL && (*flags & HOURS) == 0 && (*flags & WEEKDAYS) == 0 && (*flags & WEEKLY_RANGE) == 0 )
			{
				int range_index = 0;
				for(range_index = 0; parsed[range_index] != -1; range_index++)
				{
					if(range_index > 100)
					{
						return 0;
					}
					info->ranges[range_index] = parsed[range_index];
				
				}
				info->ranges[range_index] = -1;
				free(parsed);

				valid_arg = 1;
				*flags = *flags+c;
				info->type = *flags;
			}
			break;
	}

	return valid_arg;
}