From: Jiří Filipovič Date: Thu, 23 Oct 2008 09:26:31 +0000 (+0000) Subject: - merged with notification flags X-Git-Tag: test_tag~113 X-Git-Url: http://scientific.zcu.cz/git/?a=commitdiff_plain;h=5e8d7fa49bfa6abc89cf97737eead1550f64ae2d;p=jra1mw.git - merged with notification flags - unfinished notification conditions interpretation --- diff --git a/org.glite.lb.server/src/lb_html.c b/org.glite.lb.server/src/lb_html.c index ceab196..075a72f 100644 --- a/org.glite.lb.server/src/lb_html.c +++ b/org.glite.lb.server/src/lb_html.c @@ -50,7 +50,7 @@ int edg_wll_QueryToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut } /* construct Message-Body of Response-Line for edg_wll_UserJobs */ -int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **notifids, char **message) +int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **message) { char *pomA = NULL, *pomB; int i = 0; @@ -70,21 +70,6 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu i++; } - char *pomC = NULL, *pomD; - pomD = strdup(""); - i = 0; - - while(notifids && notifids[i]){ - asprintf(&pomC, "%s\t\t
  • %s\r\n", - pomD, - notifids[i], - notifids[i] - ); - free(pomD); - pomD = pomC; - i++; - } - char *ret; asprintf(&ret, "\r\n\t\r\n"); pomA = ret; @@ -97,15 +82,6 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu free(pomB); } pomA = ret; - if (pomC){ - asprintf(&ret, "%s

    User notifications

    \r\n" - "", - pomA, pomD - ); - free(pomA); - free(pomD); - } - pomA = ret; asprintf(&ret, "%sUser subject: %s

    " "\t\r\n", pomA, ctx->peerName?ctx->peerName: "<anonymous>" @@ -117,6 +93,37 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu return 0; } +int edg_wll_UserNotifsToHTML(edg_wll_Context ctx UNUSED_VAR, char **notifids, char **message){ + char *pomA = NULL, *pomB; + pomB = strdup(""); + + int i = 0; + while(notifids && notifids[i]){ + asprintf(&pomA, "%s\t\t

  • %s\r\n", + pomB, + notifids[i], + notifids[i] + ); + free(pomB); + pomB = pomA; + i++; + } + + char *ret; + asprintf(&ret, "\r\n\t\r\n"); + asprintf(&ret, "\r\n\t\r\n" + "

    User notifications

    \r\n" + "" + "\t\r\n", + pomA + ); + free(pomA); + + *message = ret; + + return 0; +} + #define TR(name,type,field) \ if (field) { \ asprintf(&pomA,"%s" name ":" \ @@ -125,8 +132,14 @@ int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOu pomB = pomA; \ } +#define GS(string){ \ + asprintf(&pomA, "%s %s", pomB, (string)); \ + free(pomB); \ + pomB = pomA; \ +} + int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){ - char *pomA, *pomB, *flags; + char *pomA = NULL, *pomB, *flags; pomB = strdup(""); @@ -135,7 +148,155 @@ printf("flags %d - %s", ni->flags, flags); TR("Destination", "%s", ni->destination); TR("Valid until", "%s", ni->valid); - char *cond = xmlToHTML(ni->conditions); + +/* // Fake the ni->conditions content + ni->conditions = malloc(3*sizeof(*(ni->conditions))); + ni->conditions[0] = malloc(2*sizeof(*(ni->conditions[0]))); + ni->conditions[0][0].attr = EDG_WLL_QUERY_ATTR_OWNER; + ni->conditions[0][0].op = EDG_WLL_QUERY_OP_EQUAL; + ni->conditions[0][0].value.c = strdup("fila"); + ni->conditions[0][1].attr = EDG_WLL_QUERY_ATTR_UNDEF; + ni->conditions[1] = malloc(3*sizeof(*(ni->conditions[1]))); + ni->conditions[1][0].attr = EDG_WLL_QUERY_ATTR_OWNER; + ni->conditions[1][0].op = EDG_WLL_QUERY_OP_EQUAL; + ni->conditions[1][0].value.c = strdup("fila"); + ni->conditions[1][1].attr = EDG_WLL_QUERY_ATTR_OWNER; + ni->conditions[1][1].op = EDG_WLL_QUERY_OP_EQUAL; + ni->conditions[1][1].value.c = strdup("sauron"); + ni->conditions[1][2].attr = EDG_WLL_QUERY_ATTR_UNDEF; + ni->conditions[2] = NULL;*/ + +/* edg_wll_QueryRec **l1; + edg_wll_QueryRec *l2; + for (l1 = ni->conditions; *l1; l1++){ + if (l1 != ni->conditions) + GS ("and"); + l2 = *l1; + switch (l2->attr){ + case EDG_WLL_QUERY_ATTR_JOBID: GS("jobId"); + break; + case EDG_WLL_QUERY_ATTR_OWNER: GS("owner"); + break; + case EDG_WLL_QUERY_ATTR_STATUS: GS("status"); + break; + case EDG_WLL_QUERY_ATTR_LOCATION: GS("location"); + break; + case EDG_WLL_QUERY_ATTR_DESTINATION: GS("destination"); + break; + case EDG_WLL_QUERY_ATTR_DONECODE: GS("donecode"); + break; + case EDG_WLL_QUERY_ATTR_USERTAG: GS("usertag"); + break; + case EDG_WLL_QUERY_ATTR_TIME: GS("time"); + break; + case EDG_WLL_QUERY_ATTR_LEVEL: GS("level"); + break; + case EDG_WLL_QUERY_ATTR_HOST: GS("host"); + break; + case EDG_WLL_QUERY_ATTR_SOURCE: GS("source"); + break; + case EDG_WLL_QUERY_ATTR_INSTANCE: GS("instance"); + break; + case EDG_WLL_QUERY_ATTR_EVENT_TYPE: GS("eventtype"); + break; + case EDG_WLL_QUERY_ATTR_CHKPT_TAG: GS("chkpttag"); + break; + case EDG_WLL_QUERY_ATTR_RESUBMITTED: GS("resubmitted"); + break; + case EDG_WLL_QUERY_ATTR_PARENT: GS("parent_job"); + break; + case EDG_WLL_QUERY_ATTR_EXITCODE: GS("exitcode"); + break; + case EDG_WLL_QUERY_ATTR_JDL_ATTR: GS("jdl"); + break; + case EDG_WLL_QUERY_ATTR_STATEENTERTIME: GS("stateentertime"); + break; + case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: GS("lastupdatetime"); + break; + case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: GS("networkserver"); + break; + } + for (l2 = *l1; l2->attr; l2++){ + if (l2 != *l1) GS ("or"); + switch(l2->op){ + case EDG_WLL_QUERY_OP_EQUAL: GS("="); + break; + case EDG_WLL_QUERY_OP_LESS: GS ("<"); + break; + case EDG_WLL_QUERY_OP_GREATER: GS ("<"); + break; + case EDG_WLL_QUERY_OP_WITHIN: GS ("within"); + break; + case EDG_WLL_QUERY_OP_UNEQUAL: GS ("!="); + } + char *buf; + switch (l2->attr){ + case EDG_WLL_QUERY_ATTR_JOBID: + GS(edg_wlc_JobIdUnparse(l2->value.j)); + break; + case EDG_WLL_QUERY_ATTR_DESTINATION: + case EDG_WLL_QUERY_ATTR_LOCATION: + case EDG_WLL_QUERY_ATTR_OWNER: + GS(l2->value.c); + break; + case EDG_WLL_QUERY_ATTR_STATUS: + //XXX: need interpretation! + asprintf(&buf, "%i", l2->value.i); + GS(buf); + free(buf); + break; + case EDG_WLL_QUERY_ATTR_DONECODE: + //XXX: need interpretation! + asprintf(&buf, "%i", l2->value.i); + GS(buf); + free(buf); + break; + case EDG_WLL_QUERY_ATTR_USERTAG: + GS(l2->attr_id.tag); + break; + case EDG_WLL_QUERY_ATTR_TIME: + buf = ctime(&(l2->value.t.tv_sec)); + if (l2->op == EDG_WLL_QUERY_OP_WITHIN){ + buf[strlen(buf)-1] = 0; // cut out '\n' + asprintf(&buf, " and %s", ctime(&(l2->value2.t.tv_sec))); + GS(buf); + } + else + GS(buf); + free(buf); + break; + case EDG_WLL_QUERY_ATTR_LEVEL: + break; + case EDG_WLL_QUERY_ATTR_HOST: + break; + case EDG_WLL_QUERY_ATTR_SOURCE: + break; + case EDG_WLL_QUERY_ATTR_INSTANCE: + break; + case EDG_WLL_QUERY_ATTR_EVENT_TYPE: + break; + case EDG_WLL_QUERY_ATTR_CHKPT_TAG: + break; + case EDG_WLL_QUERY_ATTR_RESUBMITTED: + break; + case EDG_WLL_QUERY_ATTR_PARENT: + break; + case EDG_WLL_QUERY_ATTR_EXITCODE: + break; + case EDG_WLL_QUERY_ATTR_JDL_ATTR: + break; + case EDG_WLL_QUERY_ATTR_STATEENTERTIME: + break; + case EDG_WLL_QUERY_ATTR_LASTUPDATETIME: + break; + case EDG_WLL_QUERY_ATTR_NETWORK_SERVER: + break; + } + GS("\n"); + } + }*/ + + char *cond = xmlToHTML(ni->conditions_text); asprintf(&pomA, "%s

    Conditions

    \r\n
    %s
    \r\n", pomB, cond); free(cond); @@ -143,12 +304,6 @@ printf("flags %d - %s", ni->flags, flags); pomB = pomA; TR("Flags", "%s", flags); free(flags); - if (ni->JDL_VirtualOrganisation && ni->JDL_VirtualOrganisation[0]) - TR("JDL VirtualOrganisation", "%s", ni->JDL_VirtualOrganisation); - if (ni->STD_owner && ni->STD_owner[0]) - TR("STD owner", "%s", ni->STD_owner); - if (ni->STD_network_server && ni->STD_network_server[0]) - TR("STD network server", "%s", ni->STD_network_server); asprintf(&pomA, "\r\n\t\r\n" "

    Notification %s

    \r\n" diff --git a/org.glite.lb.server/src/lb_html.h b/org.glite.lb.server/src/lb_html.h index 335b6ac..23bd87d 100644 --- a/org.glite.lb.server/src/lb_html.h +++ b/org.glite.lb.server/src/lb_html.h @@ -9,7 +9,7 @@ int edg_wll_QueryToHTML(edg_wll_Context,edg_wll_Event *,char **); int edg_wll_JobStatusToHTML(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, char **, char **); +int edg_wll_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, char **); char *edg_wll_ErrorToHTML(edg_wll_Context,int); #endif /* GLITE_LB_HTML_H */ diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index 4d2c041..6b927f8 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -199,7 +199,7 @@ static int drain_text_request(char *request){ while (!isspace(request[i])) i++; if (i < 5) return 0; - if (! strncmp(request+i-5, "/text", 5)){ + if (! strncmp(request+i-5, "?text", 5)){ if (i == 5) strcpy(request+i-4, request+i); // keep '/' else @@ -243,10 +243,9 @@ err: static int getNotifInfo(edg_wll_Context ctx, char *notifId, notifInfo *ni){ char *q = NULL; glite_lbu_Statement notif = NULL; - char *notifc[7] = {NULL, NULL, NULL, NULL, NULL, NULL, NULL}; + char *notifc[4] = {NULL, NULL, NULL, NULL}; - trio_asprintf(&q, "select destination, valid, conditions, flags, " - "JDL_VirtualOrganisation, STD_owner, STD_network_server " + trio_asprintf(&q, "select destination, valid, conditions, flags " "from notif_registrations " "where notifid='%s'", notifId); @@ -257,11 +256,9 @@ static int getNotifInfo(edg_wll_Context ctx, char *notifId, notifInfo *ni){ if (edg_wll_FetchRow(ctx, notif, sizeof(notifc)/sizeof(notifc[0]), NULL, notifc)){ ni->destination = notifc[0]; ni->valid = notifc[1]; - ni->conditions = notifc[2]; + ni->conditions_text = notifc[2]; + parseJobQueryRec(ctx, notifc[2], strlen(notifc[2]), &(ni->conditions)); ni->flags = atoi(notifc[3]); - ni->JDL_VirtualOrganisation = notifc[4]; - ni->STD_owner = notifc[5]; - ni->STD_network_server = notifc[6]; } else goto err; @@ -276,10 +273,17 @@ static void freeNotifInfo(notifInfo *ni){ if (ni->notifid) free(ni->notifid); if (ni->destination) free(ni->destination); if (ni->valid) free(ni->valid); - if (ni->conditions) free(ni->conditions); - if (ni->JDL_VirtualOrganisation) free(ni->JDL_VirtualOrganisation); - if (ni->STD_owner) free(ni->STD_owner); - if (ni->STD_network_server) free(ni->STD_network_server); + if (ni->conditions){ + edg_wll_QueryRec **p; + int i; + for (p = ni->conditions; *p; p++){ + for (i = 0; (*p)[i].attr; i++) + edg_wll_QueryRecFree((*p)+i); + free(*p); + } + free(ni->conditions); + } + if (ni->conditions_text) free(ni->conditions_text); } edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx, @@ -527,18 +531,18 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, flags = (requestPTR[1]=='?') ? edg_wll_string_to_stat_flags(requestPTR + 2) : 0; - char **notifids = NULL; + //char **notifids = NULL; char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); - char *userid = strmd5(can_peername, NULL); + /*char *userid = strmd5(can_peername, NULL); free(can_peername); - getUserNotifications(ctx, userid, ¬ifids); + getUserNotifications(ctx, userid, ¬ifids);*/ // FIXME: edg_wll_UserJobs should take flags as parameter switch (edg_wll_UserJobsServer(ctx,&jobsOut,NULL)) { case 0: if (text) - edg_wll_UserInfoToText(ctx, jobsOut, notifids, &message); + edg_wll_UserInfoToText(ctx, jobsOut, &message); else if (html) - edg_wll_UserInfoToHTML(ctx, jobsOut, notifids, &message); + edg_wll_UserInfoToHTML(ctx, jobsOut, &message); else ret = HTTP_OK; break; case ENOENT: ret = HTTP_NOTFOUND; break; @@ -554,16 +558,13 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, for (i=0; jobsOut[i]; i++) edg_wlc_JobIdFree(jobsOut[i]); free(jobsOut); } - if (notifids){ - for (i = 0; notifids[i]; i++) - free(notifids[i]); - free(notifids); - } } /* GET /[jobId]: Job Status */ else if (*requestPTR=='/' - && strncmp(requestPTR, "/notif/", strlen("/notif/"))) { + && strncmp(requestPTR, "/notif", strlen("/notif")) + && *(requestPTR+strlen("/notif")-1) != '/' + && !isspace(*(requestPTR+strlen("/notif")-1))) { edg_wlc_JobId jobId = NULL; char *pom1,*fullid = NULL; edg_wll_JobStat stat; @@ -606,6 +607,21 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, free(fullid); edg_wlc_JobIdFree(jobId); edg_wll_FreeStatus(&stat); + /*GET /notif[/]: All user's notifications*/ + } else if (strncmp(requestPTR, "/notif", strlen("/notif")) == 0 + && (*(requestPTR+strlen("/notif/")-1) == '/' && isspace(*(requestPTR+strlen("/notif/")))) + || isspace(*(requestPTR+strlen("/notif/")-1))){ + char **notifids = NULL; + char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0); + char *userid = strmd5(can_peername, NULL); + getUserNotifications(ctx, userid, ¬ifids); + free(can_peername); + if (text) + edg_wll_UserNotifsToText(ctx, notifids, &message); + else if (html) + edg_wll_UserNotifsToHTML(ctx, notifids, &message); + else ret = HTTP_OK; + /*GET /notif/[notifId]: Notification info*/ } else if (strncmp(requestPTR, "/notif/", strlen("/notif/")) == 0){ notifInfo ni; @@ -614,6 +630,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, for (pom=pomCopy; *pom && !isspace(*pom); pom++); *pom = 0; getNotifInfo(ctx, strrchr(pomCopy, '/')+1, &ni); + //TODO handle error free(pomCopy); if (text) diff --git a/org.glite.lb.server/src/lb_proto.h b/org.glite.lb.server/src/lb_proto.h index b726f6b..b3aaba0 100644 --- a/org.glite.lb.server/src/lb_proto.h +++ b/org.glite.lb.server/src/lb_proto.h @@ -4,6 +4,7 @@ #ident "$Header$" #include "glite/lb/context.h" +#include "glite/lb/query_rec.h" /* Handle a single request of the LB server protocol * returns a complete response string (may contain a formatted error @@ -24,11 +25,9 @@ typedef struct _notifInfo{ char *notifid; char *destination; char *valid; - char *conditions; + edg_wll_QueryRec **conditions; + char *conditions_text; int flags; - char *JDL_VirtualOrganisation; - char *STD_owner; - char *STD_network_server; } notifInfo; extern char *edg_wll_HTTPErrorMessage(int); diff --git a/org.glite.lb.server/src/lb_text.c b/org.glite.lb.server/src/lb_text.c index fcbb71d..d69d18d 100644 --- a/org.glite.lb.server/src/lb_text.c +++ b/org.glite.lb.server/src/lb_text.c @@ -85,7 +85,16 @@ int edg_wll_QueryToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut return 0; }*/ -int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **notifids, char **message) +#define TR(name,type,field) \ + if (field) { \ + asprintf(&a,"%s%s=" type "\n", \ + b, name, field); \ + free(b); \ + b = a; \ + } + + +int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message) { char *a = NULL, *b; int i = 0; @@ -105,66 +114,54 @@ int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **n i++; } - char *c = NULL, *d; - i = 0; - d = strdup(""); - while(notifids[i]){ - if (i == 0) - asprintf(&c, "%s", notifids[i]); - else - asprintf(&c, "%s,%s", d, notifids[i]); - free(d); - d = c; - i++; - } - if (a){ asprintf(&a, "User_jobs=%s\n", b); + free(b); b = a; - if (c) - asprintf(&a, "%sUser_notifications=%s\n", b, d); } - else if (c) - asprintf(&a, "User_notifications=%s\n", d); b = a; - if (a) - asprintf(&a, "%sUser_subject=%s\n", b, ctx->peerName ? ctx->peerName: ""); - else - asprintf(&a, "User_subject=%s\n", ctx->peerName ? ctx->peerName: ""); + asprintf(&a, "%sUser_subject=%s\n", b, ctx->peerName ? ctx->peerName: ""); *message = a; return 0; } +int edg_wll_UserNotifsToText(edg_wll_Context ctx, char **notifids, char **message){ + char *a = NULL, *b; + int i = 0; + b = strdup(""); + + while(notifids[i]){ + if (i == 0) + asprintf(&a, "%s", notifids[i]); + else + asprintf(&a, "%s,%s", b, notifids[i]); + free(b); + b = a; + i++; + } + if (b) + asprintf(&a, "User_notifications=%s\n", b); + + *message = a; +} int edg_wll_NotificationToText(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){ - char *a = NULL, *b = NULL; - asprintf(&a, "Notif_id=%s\n", ni->notifid); - asprintf(&b, "%sDestination=%s\n", a, ni->destination); free(a); - asprintf(&a, "%sValid_until=%s\n", b, ni->valid); free(b); - char *cond = escape_text(ni->conditions); - asprintf(&b, "%sConditions=%s\n", a, cond); free(a); + char *a = NULL, *b; + b = strdup(""); + + TR("Notif_id", "%s", ni->notifid); + TR("Destination", "%s", ni->destination); + TR("Valid_until", "%s", ni->valid); + char *cond = escape_text(ni->conditions_text); + TR("Conditions", "%s", cond); free(cond); char *flags = edg_wll_stat_flags_to_string(ni->flags); - asprintf(&a, "%sFlags=%s\n", b, flags); free(b); + TR("Flags", "%s", flags); free(flags); - b = a; - if (ni->JDL_VirtualOrganisation && ni->JDL_VirtualOrganisation[0]) { - asprintf(&a, "%sJDL_VirtualOrganisation=%s\n", b, ni->JDL_VirtualOrganisation); - free(b); - } - b = a; - if (ni->STD_owner && ni->STD_owner[0]) { - asprintf(&a, "%sSTD_owner=%s\n", b, ni->STD_owner); - free(b); - } - b = a; - if (ni->STD_network_server && ni->STD_network_server[0]) { - asprintf(&a, "%sSTD_network_server=%s\n", b, ni->STD_network_server); - free(b); - } + *message = a; return 0; @@ -177,14 +174,6 @@ int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat char *chid,*chstat; char *jdl,*rsl; - #define TR(name,type,field) \ - if (field) { \ - asprintf(&a,"%s%s=" type "\n", \ - b, name, field); \ - free(b); \ - b = a; \ - } - jdl = strdup(""); rsl = strdup(""); diff --git a/org.glite.lb.server/src/lb_text.h b/org.glite.lb.server/src/lb_text.h index 8d9eace..2b65834 100644 --- a/org.glite.lb.server/src/lb_text.h +++ b/org.glite.lb.server/src/lb_text.h @@ -7,7 +7,7 @@ int edg_wll_QueryToText(edg_wll_Context,edg_wll_Event *,char **); int edg_wll_JobStatusToText(edg_wll_Context, edg_wll_JobStat, char **); -int edg_wll_UserInfoToText(edg_wll_Context, edg_wlc_JobId *, char **, char **); +int edg_wll_UserInfoToText(edg_wll_Context, edg_wlc_JobId *, char **); char *edg_wll_ErrorToText(edg_wll_Context,int); #endif /* GLITE_LB_TEXT */