/* time 126-602 == 2:06 to 10:02 days NYYNNYY */ static int parse(int c, char **argv, int argc, const struct ebt_u_entry *entry, unsigned int *flags, struct ebt_entry_match **match) { EBT_TIME_ST* pstTimeInfo = (EBT_TIME_ST*)(*match)->data; switch (c) /* c is the return value of getopt_long */ { /* time */ case 't': if (EBT_TIME_OK != parse_time(&(pstTimeInfo->time_begin), &(pstTimeInfo->time_end), optarg)) { printf("atp: ebt_time parse time error. \r\n"); return 0; } break; /* weekday */ case 'w': pstTimeInfo->weekdays = parse_weekdays(optarg); break; default: return 0; } return 1; }
int calendar_spec_from_string(const char *p, CalendarSpec **spec) { CalendarSpec *c; int r; assert(p); assert(spec); if (isempty(p)) return -EINVAL; c = new0(CalendarSpec, 1); if (!c) return -ENOMEM; if (strcaseeq(p, "hourly")) { r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "daily")) { r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "monthly")) { r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "weekly")) { c->weekdays_bits = 1; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else { r = parse_weekdays(&p, c); if (r < 0) goto fail; r = parse_date(&p, c); if (r < 0) goto fail; r = parse_time(&p, c); if (r < 0) goto fail; if (*p != 0) { r = -EINVAL; goto fail; } } r = calendar_spec_normalize(c); if (r < 0) goto fail; if (!calendar_spec_valid(c)) { r = -EINVAL; goto fail; } *spec = c; return 0; fail: calendar_spec_free(c); return r; }
int calendar_spec_from_string(const char *p, CalendarSpec **spec) { const char *utc; CalendarSpec *c; int r; assert(p); assert(spec); c = new0(CalendarSpec, 1); if (!c) return -ENOMEM; c->dst = -1; c->timezone = NULL; utc = endswith_no_case(p, " UTC"); if (utc) { c->utc = true; p = strndupa(p, utc - p); } else { const char *e = NULL; int j; tzset(); /* Check if the local timezone was specified? */ for (j = 0; j <= 1; j++) { if (isempty(tzname[j])) continue; e = endswith_no_case(p, tzname[j]); if (!e) continue; if (e == p) continue; if (e[-1] != ' ') continue; break; } /* Found one of the two timezones specified? */ if (IN_SET(j, 0, 1)) { p = strndupa(p, e - p - 1); c->dst = j; } else { const char *last_space; last_space = strrchr(p, ' '); if (last_space != NULL && timezone_is_valid(last_space + 1)) { c->timezone = strdup(last_space + 1); if (!c->timezone) { r = -ENOMEM; goto fail; } p = strndupa(p, last_space - p); } } } if (isempty(p)) { r = -EINVAL; goto fail; } if (strcaseeq(p, "minutely")) { r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "hourly")) { r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "daily")) { r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "monthly")) { r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly") || strcaseeq(p, "anually") /* backwards compatibility */ ) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "weekly")) { c->weekdays_bits = 1; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "quarterly")) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(4, &c->month); if (r < 0) goto fail; r = const_chain(7, &c->month); if (r < 0) goto fail; r = const_chain(10, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else if (strcaseeq(p, "biannually") || strcaseeq(p, "bi-annually") || strcaseeq(p, "semiannually") || strcaseeq(p, "semi-annually")) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(7, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->microsecond); if (r < 0) goto fail; } else { r = parse_weekdays(&p, c); if (r < 0) goto fail; r = parse_date(&p, c); if (r < 0) goto fail; if (r == 0) { r = parse_calendar_time(&p, c); if (r < 0) goto fail; } if (*p != 0) { r = -EINVAL; goto fail; } } r = calendar_spec_normalize(c); if (r < 0) goto fail; if (!calendar_spec_valid(c)) { r = -EINVAL; goto fail; } *spec = c; return 0; fail: calendar_spec_free(c); return r; }
int calendar_spec_from_string(const char *p, CalendarSpec **spec) { CalendarSpec *c; int r; const char *utc; assert(p); assert(spec); if (isempty(p)) return -EINVAL; c = new0(CalendarSpec, 1); if (!c) return -ENOMEM; utc = endswith_no_case(p, " UTC"); if (utc) { c->utc = true; p = strndupa(p, utc - p); } if (strcaseeq(p, "minutely")) { r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "hourly")) { r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "daily")) { r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "monthly")) { r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "annually") || strcaseeq(p, "yearly") || strcaseeq(p, "anually") /* backwards compatibility */ ) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "weekly")) { c->weekdays_bits = 1; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "quarterly")) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(4, &c->month); if (r < 0) goto fail; r = const_chain(7, &c->month); if (r < 0) goto fail; r = const_chain(10, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else if (strcaseeq(p, "biannually") || strcaseeq(p, "bi-annually") || strcaseeq(p, "semiannually") || strcaseeq(p, "semi-annually")) { r = const_chain(1, &c->month); if (r < 0) goto fail; r = const_chain(7, &c->month); if (r < 0) goto fail; r = const_chain(1, &c->day); if (r < 0) goto fail; r = const_chain(0, &c->hour); if (r < 0) goto fail; r = const_chain(0, &c->minute); if (r < 0) goto fail; r = const_chain(0, &c->second); if (r < 0) goto fail; } else { r = parse_weekdays(&p, c); if (r < 0) goto fail; r = parse_date(&p, c); if (r < 0) goto fail; r = parse_time(&p, c); if (r < 0) goto fail; if (*p != 0) { r = -EINVAL; goto fail; } } r = calendar_spec_normalize(c); if (r < 0) goto fail; if (!calendar_spec_valid(c)) { r = -EINVAL; goto fail; } *spec = c; return 0; fail: calendar_spec_free(c); return r; }
/* 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; }