2 These functions writen by Devrim SERAL <devrim@gazi.edu.tr>
4 Applicable format is : <day str><time str> [,|] <day str><time str> [,|] and so on
6 The accept parameter for day str is:
20 For example it's to be -> 0000-1200 or 1600-1700 or 1600-0800
22 License: This code is free software; you can redistribute it and/or modify it
23 under the terms of the GNU General Public License as published by the Free
24 Software Foundation; either version 2, or (at your option) any later version.
36 #include "time_limit.h"
42 static int str_token_proc TAC_ARGS((char *str));
43 static int process TAC_ARGS((char *str));
44 static int time_calc TAC_ARGS((char *str, int lct));
45 static int antoi TAC_ARGS((char *str, int n));
48 static char* week_days[] = {"SU","MO","TU","WE","TH","FR","SA","WK","WD","AL"};
49 static long week_day_val[] = {1, 2, 4, 8, 16, 32, 64, 62, 65, 127};
51 static int problem = 0;
54 int time_limit_process TAC_ARGS((const char *str));
57 time_limit_process(str)
61 char *tmp_str, *str_copy;
63 str_copy = tac_strdup(str);
64 tmp_str = (char *) strtok(str_copy,",|");
66 while ( tmp_str != NULL) {
67 ret |= str_token_proc(tmp_str);
68 tmp_str = (char *) strtok(NULL,",");
75 static int str_token_proc TAC_ARGS((char *str));
83 /* Pass space characters */
84 while (isspace((int) *str))
95 if ( debug & DEBUG_AUTHEN_FLAG )
96 report(LOG_DEBUG,"Timestamp format incorrect");
108 static void str_up TAC_ARGS((char *str));
115 if (islower((int) *str))
116 *str = toupper((int) *str);
122 static int process TAC_ARGS((char *str));
128 int count = 0, ret = 0, i, j, localtm;
129 char *head, *buf, *gec;
133 /* Pass space characters */
134 while (isspace((int) *str))
139 /* Count alphanumeric char */
140 while (isalpha((int) *str)) {
145 if ( count==0 || count%2 ) {
150 buf = (char *) tac_malloc(count+1);
151 strncpy(buf, head, count);
155 for (i=1; i<=(count/2); i++) {
156 for (j=0; j<NUM; j++)
157 if(!strncmp(gec,week_days[j],2))
158 ret ^= week_day_val[j];
162 /* We finished to use buffer so free it */
166 tms = localtime(&sec);
167 localtm = (tms->tm_hour)*60 + tms->tm_min;
168 ret = ( week_day_val[tms->tm_wday] & ret ) && time_calc(str,localtm);
177 static int time_calc TAC_ARGS((char *str, int lct));
184 char *t1, *t2, *head;
185 int say1, say2, count=0;
189 while (isdigit((int) *head) || *head=='-') {
194 if ( *str=='\0' || count!= TPL ) {
199 t1 = (char *) tac_malloc(count);
200 strncpy(t1, str, count); /* Put str value to t1 */
202 t2 = (char *) strstr(t1,"-"); /* Find next time part */
212 if ( strlen(t1)<4 || strlen(t2)<4 ) {
217 say1 = antoi(t1,2)*60 + antoi(t1+2,2);
218 say2 = antoi(t2,2)*60 + antoi(t2+2,2);
223 if( (lct>=say1) && (lct<=say2) )
226 if( (lct>=say1) || (lct<=say2) )
232 static int antoi TAC_ARGS((char *str, int n));
242 buf = (char *) tac_malloc(n);
243 strncpy(buf, str, n);