/* Function which parses command options; returns true if it
   ate an option */
static int
parse(int c, char **argv, int argc,
      const struct ebt_u_entry *entry,
      unsigned int *flags, struct ebt_entry_match **match)
{
	struct ebt_time_info *timeinfo = (struct ebt_time_info *)(*match)->data;
	int hours, minutes;

	switch (c) /* c is the return value of getopt_long */
	{
		/* timestart */
	case '1':
		if (*flags & EBT_TIME_START)
                        print_error("Can't specify --timestart twice");
		parse_time_string(&hours, &minutes, optarg);
		timeinfo->time_start = (hours * 60) + minutes;
		*flags |= EBT_TIME_START;
		break;
		/* timestop */
	case '2':
		if (*flags & EBT_TIME_STOP)
                        print_error("Can't specify --timestop twice");
		parse_time_string(&hours, &minutes, optarg);
		timeinfo->time_stop = (hours * 60) + minutes;
		*flags |= EBT_TIME_STOP;
		break;

		/* days */
	case '3':
		if (*flags & EBT_TIME_DAYS)
                        print_error("Can't specify --days twice");
		parse_days_string(&globaldays, optarg);
		timeinfo->days_match = globaldays;
		*flags |= EBT_TIME_DAYS;
		break;
	default:
		return 0;
	}
	/* default value if not specified */
	if (!(*flags & EBT_TIME_START))
		timeinfo->time_start = 0;
	if (!(*flags & EBT_TIME_STOP))
		timeinfo->time_stop = 1439; /* 23*60+59 = 1439*/
	if (!(*flags & EBT_TIME_DAYS))
		timeinfo->days_match = 0;

	return 1;
}
/* Function which parses command options; returns true if it
   ate an option */
static int
parse(int c, char **argv, int invert, unsigned int *flags,
      const struct ipt_entry *entry,
      unsigned int *nfcache,
      struct ipt_entry_match **match)
{
	struct ipt_time_info *timeinfo = (struct ipt_time_info *)(*match)->data;
	int hours, minutes;
	time_t temp_date;

	switch (c)
	{
		/* timestart */
	case '1':
		if (invert)
			exit_error(PARAMETER_PROBLEM,
                                   "unexpected '!' with --timestart");
		if (*flags & IPT_TIME_START)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --timestart twice");
		parse_time_string(&hours, &minutes, optarg);
		timeinfo->time_start = (hours * 60) + minutes;
		*flags |= IPT_TIME_START;
		break;
		/* timestop */
	case '2':
		if (invert)
			exit_error(PARAMETER_PROBLEM,
                                   "unexpected '!' with --timestop");
		if (*flags & IPT_TIME_STOP)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --timestop twice");
		parse_time_string(&hours, &minutes, optarg);
		timeinfo->time_stop = (hours * 60) + minutes;
		*flags |= IPT_TIME_STOP;
		break;

		/* days */
	case '3':
		if (invert)
			exit_error(PARAMETER_PROBLEM,
                                   "unexpected '!' with --days");
		if (*flags & IPT_TIME_DAYS)
                        exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --days twice");
		parse_days_string(&globaldays, optarg);
		timeinfo->days_match = globaldays;
		*flags |= IPT_TIME_DAYS;
		break;

		/* datestart */
	case '4':
		if (invert)
			exit_error(PARAMETER_PROBLEM,
                                   "unexpected '!' with --datestart");
		if (*flags & IPT_DATE_START)
			exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --datestart twice");
		temp_date = parse_date_string(optarg);
		timeinfo->date_start = temp_date;
		*flags |= IPT_DATE_START;
		break;

		/* datestop*/
	case '5':
		if (invert)
			exit_error(PARAMETER_PROBLEM,
                                   "unexpected '!' with --datestop");
		if (*flags & IPT_DATE_STOP)
			exit_error(PARAMETER_PROBLEM,
                                   "Can't specify --datestop twice");
		temp_date = parse_date_string(optarg);
		timeinfo->date_stop = temp_date;
		*flags |= IPT_DATE_STOP;
		break;
	default:
		return 0;
	}
	return 1;
}