From: Zdeněk Šustr Date: Tue, 24 May 2011 14:25:08 +0000 (+0000) Subject: - Essential checking of temporal arguments to glite-lb-dump for validity X-Git-Tag: glite-lb-client_R_4_1_10_1~15 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=b0d47e9770865ba5a724b4a40f66fe85aa07107d;p=jra1mw.git - Essential checking of temporal arguments to glite-lb-dump for validity - Support for special date values (now, last dump start/end) in glite-lb-dump --- diff --git a/org.glite.lb.utils/src/dump.c b/org.glite.lb.utils/src/dump.c index 0bba745..ef3305f 100644 --- a/org.glite.lb.utils/src/dump.c +++ b/org.glite.lb.utils/src/dump.c @@ -58,15 +58,32 @@ static struct option opts[] = { static void usage(char *me) { fprintf(stderr,"usage: %s [option]\n" - " -f, --from YYYYMMDDHHmmss beginning of the time interval for events to be dumped\n" - " -t, --to YYYYMMDDHHmmss end of the time interval for events to be dumped\n" + " -f, --from YYYYMMDDHHmmss beginning of the time interval for events to be dumped*\n" + " -t, --to YYYYMMDDHHmmss end of the time interval for events to be dumped*\n" " -h, --help display this help\n" " -v, --version display version\n" " -d, --debug diagnostic output\n" - " -m, --server L&B server machine name\n", + " -m, --server L&B server machine name\n\n" + " * Special values for temporal arguments '-f' and '-t':\n" + " 'now' this exact moment\n" + " 'last_start' last dump starting time\n" + " 'last_end' last dump ending time\n", me); } +double ParseDate(const char *s) { + if (!strcmp(s,"now")) return EDG_WLL_DUMP_NOW; + if (!strcmp(s,"last_start")) return EDG_WLL_DUMP_LAST_START; + if (!strcmp(s,"last_end")) return EDG_WLL_DUMP_LAST_END; + + if(strlen(s)<14) return -16; + + int i; + for (i = 0; i<14; i++) if((s[i]<'0')||(s[i]>'9')) return -16; + + return edg_wll_ULMDateToDouble(s); +} + int main(int argc,char *argv[]) { edg_wll_DumpRequest *request; @@ -76,7 +93,7 @@ int main(int argc,char *argv[]) char *me; int opt; - edg_wll_Context ctx; + edg_wll_Context ctx = NULL; /* initialize request to server defaults */ request = (edg_wll_DumpRequest *) calloc(1,sizeof(edg_wll_DumpRequest)); @@ -94,8 +111,8 @@ int main(int argc,char *argv[]) switch (opt) { - case 'f': request->from = (time_t) edg_wll_ULMDateToDouble(optarg); break; - case 't': request->to = (time_t) edg_wll_ULMDateToDouble(optarg); break; + case 'f': request->from = (time_t) ParseDate(optarg); break; + case 't': request->to = (time_t) ParseDate(optarg); break; case 'm': server = optarg; break; case 'd': debug = 1; break; case 'v': fprintf(stdout,"%s:\t%s\n",me,rcsid); exit(0); @@ -104,6 +121,13 @@ int main(int argc,char *argv[]) } } + if(request->from < -15) { + fprintf(stdout, "Invalid 'from' date\n"); + goto main_end; } + if(request->to < -15) { + fprintf(stdout, "Invalid 'to' date\n"); + goto main_end; } + /* check request */ if (debug) { printf("Dump request:\n");