+++ /dev/null
-#ident "$Header$"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <errno.h>
-#include <getopt.h>
-#include <time.h>
-
-#include "glite/lb/consumer.h"
-
-static void usage(char *);
-static int query_all(edg_wll_Context, int, struct timeval, edg_wll_JobStat **, edg_wlc_JobId **);
-static void dgerr(edg_wll_Context,char *);
-
-static char *myname = NULL;
-static int debug = 0, verbose = 0, lbproxy =0;
-static const char rcsid[] = "@(#)$Id$";
-
-static struct option const long_options[] = {
- { "help", no_argument, 0, 'h' },
- { "version", no_argument, 0, 'V' },
- { "verbose", no_argument, 0, 'v' },
- { "debug", no_argument, 0, 'd' },
- { "lbproxy", required_argument, 0, 'x' },
- { NULL, 0, NULL, 0}
-};
-
-int main(int argc,char *argv[]) {
- edg_wll_Context ctx;
- edg_wll_JobStat *statesOut = NULL;
- edg_wlc_JobId *jobsOut = NULL;
- struct timeval time_now;
-
- int i, result, opt, nJobs;
- i = result = opt = 0;
- gettimeofday(&time_now,0);
-
- myname = argv[0];
- fprintf(stdout,"\n");
- /* get arguments */
- while ((opt = getopt_long(argc,argv,
- "h" /* help */
- "V" /* version */
- "v" /* verbose */
- "d" /* debug */
- "x", /* lbproxy */
- long_options, (int *) 0)) != EOF) {
-
- switch (opt) {
- case 'V': fprintf(stdout,"%s:\t%s\n",argv[0],rcsid); exit(0);
- case 'v': verbose = 1; break;
- case 'd': debug = 1; break;
- case 'x': lbproxy = 1; break;
- case 'h':
- default:
- usage(argv[0]); exit(0);
- }
- }
- if ( edg_wll_InitContext(&ctx) ) {
- fprintf(stderr,"%s: cannot initialize edg_wll_Context\n ",myname);
- exit(1);
- }
-
- if ( (result = query_all(ctx, EDG_WLL_JOB_CLEARED, time_now, &statesOut, &jobsOut)) ) {
- dgerr(ctx, "edg_wll_QueryJobs");
- } else {
- fprintf(stdout,"Number of jobs... ");
- }
-
- nJobs = 0;
- if ( jobsOut ) {
- for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); {
- nJobs++;
- free(jobsOut);
- }
- }
- if ( statesOut ) {
- for (i=0; statesOut[i].state; i++) edg_wll_FreeStatus(&statesOut[i]);
- free(statesOut);
- }
- edg_wll_FreeContext(ctx);
-
-
- return result;
-}
-
-static void
-usage(char *name) {
- fprintf(stderr,"Usage: %s [-x]\n", name);
-}
-
-static int
-query_all(edg_wll_Context ctx, int query_status, struct timeval query_time, edg_wll_JobStat **statesOut, edg_wlc_JobId **jobsOut) {
- edg_wll_QueryRec jc[3];
- int ret;
-
- memset(jc, 0, sizeof jc);
-
- /* jobs in the state 'query_status' within last hour */
- jc[0].attr = EDG_WLL_QUERY_ATTR_STATUS;
- jc[0].op = EDG_WLL_QUERY_OP_EQUAL;
- jc[0].value.i = query_status;
- jc[1].attr = EDG_WLL_QUERY_ATTR_TIME;
- jc[1].attr_id.state = query_status;
- jc[1].op = EDG_WLL_QUERY_OP_WITHIN;
- jc[1].value.t.tv_sec = query_time.tv_sec - 3600;
- jc[1].value.t.tv_usec = query_time.tv_usec;
- jc[1].value2.t.tv_sec = query_time.tv_sec;
- jc[1].value2.t.tv_usec = query_time.tv_usec;
- jc[2].attr = EDG_WLL_QUERY_ATTR_UNDEF;
-
- if ( (ret = edg_wll_QueryJobs(ctx, jc, 0, jobsOut, statesOut)) ) {
- if ( ret == E2BIG ) {
- int r;
- if ( edg_wll_GetParam(ctx, EDG_WLL_PARAM_QUERY_RESULTS, &r) ) return ret;
- if ( r != EDG_WLL_QUERYRES_LIMITED ) return ret;
-
- fprintf(stderr," edg_wll_QueryJobs() Warning: only limited result returned!\n");
- return 0;
- } else return ret;
- }
-
- return ret;
-}
-
-static void
-dgerr(edg_wll_Context ctx,char *where) {
- char *etxt,*edsc;
-
- edg_wll_Error(ctx,&etxt,&edsc);
- fprintf(stderr,"%s: %s: %s",myname,where,etxt);
- if (edsc) fprintf(stderr," (%s)",edsc);
- putc('\n',stderr);
- if(etxt) free(etxt);
- if(edsc) free(edsc);
-}
--- /dev/null
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#include "glite/lb/producer.h"
+#include "glite/lb/events.h"
+#include "glite/lb/events_parse.h"
+
+#define MAXMSGSIZE 10240
+
+extern char *optarg;
+extern int opterr,optind;
+
+static const char *me;
+
+static void usage()
+{
+ fprintf(stderr,"usage: %s [-n] -f file_name\n", me);
+}
+
+int main(int argc, char *argv[])
+{
+ char *filename = NULL;
+ char buf[MAXMSGSIZE];
+ int done = 0,i=0,notif=0;
+ edg_wll_Context ctx;
+ edg_wll_Event *event = NULL;
+ FILE *f;
+ edg_wll_ErrorCode (*parse)(edg_wll_Context context,edg_wll_LogLine logline,edg_wll_Event **event);
+ edg_wll_LogLine (*unparse)(edg_wll_Context context,edg_wll_Event *event);
+ const char *parse_str,*unparse_str;
+
+ edg_wll_InitContext(&ctx);
+ opterr = 0;
+
+ me = strdup(argv[0]);
+
+ do {
+ switch (getopt(argc,argv,"nf:")) {
+ case 'n': notif = 1; break;
+ case 'f': filename = (char *) strdup(optarg); break;
+ case '?': usage(); exit(EINVAL);
+ case -1: done = 1; break;
+ }
+ } while (!done);
+
+ /* choose the right (un)parser */
+ if (notif) {
+ parse = edg_wll_ParseNotifEvent;
+ parse_str = "edg_wll_ParseNotifEvent";
+ unparse = edg_wll_UnparseNotifEvent;
+ unparse_str = "edg_wll_UnparseNotifEvent";
+ } else {
+ parse = edg_wll_ParseEvent;
+ parse_str = "edg_wll_ParseEvent";
+ unparse = edg_wll_UnparseEvent;
+ unparse_str = "edg_wll_UnparseEvent";
+ }
+
+ if (!filename) {
+ fprintf(stderr,"%s: -f required\n",me);
+ usage();
+ exit(1);
+ }
+
+ if ( (f = fopen(filename,"r")) == NULL) {
+ perror(filename);
+ exit(1);
+ } else {
+ fprintf(stderr,"Parsing file '%s' for correctness:\n",filename);
+ }
+
+ /* parse events */
+ i = 1;
+ while (!feof(f)) {
+ if (!fgets(buf,sizeof(buf),f)) break;
+ if (strcmp(buf,"\n")) {
+ // fprintf(stdout,"%d: %s\n",i,buf);
+
+ if (parse(ctx,buf,&event) != 0) {
+ /* Parse ERROR: */
+ char *et=NULL,*ed=NULL;
+
+ edg_wll_Error(ctx,&et,&ed);
+ fprintf(stderr,"line %d: %s() error: %s (%s)\n",i,parse_str,et,ed);
+ if (et) free(et);
+ if (ed) free(ed);
+ } else {
+ /* Parse OK : */
+ char *es=NULL;
+ edg_wll_LogLine logline = NULL;
+
+ es=edg_wll_EventToString(event->type);
+ logline = unparse(ctx,event);
+ fprintf(stderr,"line %d: %s() o.k. (event %s), ",i,parse_str,es);
+ if (logline) {
+ fprintf(stderr,"%s() o.k.\n",unparse_str);
+ free(logline);
+ } else {
+ fprintf(stderr,"%s() error\n",unparse_str);
+ }
+ if (es) free(es);
+ }
+ if (event) edg_wll_FreeEvent(event);
+ }
+ i++;
+ }
+ fclose(f);
+
+ edg_wll_FreeContext(ctx);
+
+ return 0;
+}