}
/* 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;
i++;
}
- char *pomC = NULL, *pomD;
- pomD = strdup("");
- i = 0;
-
- while(notifids && notifids[i]){
- asprintf(&pomC, "%s\t\t <li> <a href=\"/notif/%s\">%s</a>\r\n",
- pomD,
- notifids[i],
- notifids[i]
- );
- free(pomD);
- pomD = pomC;
- i++;
- }
-
char *ret;
asprintf(&ret, "<html>\r\n\t<body>\r\n");
pomA = ret;
free(pomB);
}
pomA = ret;
- if (pomC){
- asprintf(&ret, "%s<h2><B>User notifications</B></h2>\r\n"
- "<ul>%s</ul>",
- pomA, pomD
- );
- free(pomA);
- free(pomD);
- }
- pomA = ret;
asprintf(&ret, "%sUser subject: %s<p>"
"\t</body>\r\n</html>",
pomA, ctx->peerName?ctx->peerName: "<anonymous>"
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 <li> <a href=\"/notif/%s\">%s</a>\r\n",
+ pomB,
+ notifids[i],
+ notifids[i]
+ );
+ free(pomB);
+ pomB = pomA;
+ i++;
+ }
+
+ char *ret;
+ asprintf(&ret, "<html>\r\n\t<body>\r\n");
+ asprintf(&ret, "<html>\r\n\t<body>\r\n"
+ "<h2><B>User notifications</B></h2>\r\n"
+ "<ul>%s</ul>"
+ "\t</body>\r\n</html>",
+ pomA
+ );
+ free(pomA);
+
+ *message = ret;
+
+ return 0;
+}
+
#define TR(name,type,field) \
if (field) { \
asprintf(&pomA,"%s<tr><th align=\"left\">" name ":</th>" \
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("");
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<h3>Conditions</h3>\r\n<pre>%s</pre>\r\n",
pomB, cond);
free(cond);
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, "<html>\r\n\t<body>\r\n"
"<h2>Notification %s</h2>\r\n"
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 */
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
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);
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;
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,
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;
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;
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;
for (pom=pomCopy; *pom && !isspace(*pom); pom++);
*pom = 0;
getNotifInfo(ctx, strrchr(pomCopy, '/')+1, &ni);
+ //TODO handle error
free(pomCopy);
if (text)
#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
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);
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;
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: "<anonymous>");
- else
- asprintf(&a, "User_subject=%s\n", ctx->peerName ? ctx->peerName: "<anonymous>");
+ asprintf(&a, "%sUser_subject=%s\n", b, ctx->peerName ? ctx->peerName: "<anonymous>");
*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;
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("");
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 */