#define UNUSED_VAR
#endif
+static char *xmlToHTML(char *xml) {
+ char *html = strdup("");
+ int i = 0;
+ int j = 0;
+ while (xml[i]){
+ if (xml[i] == '<'){
+ html = realloc(html, (j+strlen("<")+1)*sizeof(*html) );
+ strcpy(html+j, "<");
+ j += strlen("<");
+ }
+ else if (xml[i] == '>'){
+ html = realloc(html, (j+strlen(">")+1)*sizeof(*html) );
+ strcpy(html+j, ">");
+ j += strlen(">");
+ }
+ else{
+ html = realloc(html, (j+2)*sizeof(*html));
+ html[j] = xml[i];
+ j++;
+ }
+ i++;
+ }
+ html[j] = 0;
+
+ return html;
+}
+
int edg_wll_QueryToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Event *eventsOut UNUSED_VAR, char **message UNUSED_VAR)
{
/* not implemented yet */
}
/* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserJobsToHTML(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
+int edg_wll_UserInfoToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wlc_JobId *jobsOut, char **notifids, char **message)
{
- char *pomA, *pomB;
+ char *pomA = NULL, *pomB;
int i = 0;
- /* head */
- pomB = strdup("");
+ /* head */
+ pomB = strdup("");
while (jobsOut[i]) {
- char *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
+ char *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
asprintf(&pomA,"%s\t\t <li> <a href=\"%s\">%s</a>\r\n",
pomB, chid,chid);
- free(chid);
+ free(chid);
free(pomB);
pomB = pomA;
i++;
}
- asprintf(&pomA, "<html>\r\n\t<body>\r\n"
- "<h2><B>User jobs</B></h2>\r\n"
- "User subject: %s<p>"
- "<ul>%s</ul>"
- "\t</body>\r\n</html>",ctx->peerName?ctx->peerName: "<anonymous>",pomB);
- free(pomB);
+ char *pomC = NULL, *pomD;
+ pomD = strdup("");
+ i = 0;
+
+ while(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++;
+ }
- *message = pomA;
+ char *ret;
+ asprintf(&ret, "<html>\r\n\t<body>\r\n");
+ pomA = ret;
+ if (pomB[0]){
+ asprintf(&ret, "%s<h2><B>User jobs</B></h2>\r\n"
+ "<ul>%s</ul>",
+ pomA, pomB
+ );
+ free(pomA);
+ 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>"
+ );
+ free(pomA);
+
+ *message = ret;
return 0;
}
+#define TR(name,type,field) \
+ if (field) { \
+ asprintf(&pomA,"%s<tr><th align=\"left\">" name ":</th>" \
+ "<td>" type "</td></tr>",pomB,(field)); \
+ free(pomB); \
+ pomB = pomA; \
+ }
+
+int edg_wll_NotificationToHTML(edg_wll_Context ctx UNUSED_VAR, notifInfo *ni, char **message){
+ char *pomA, *pomB;
+ pomB = strdup("");
+
+ TR("Destination", "%s", ni->destination);
+ TR("Valid until", "%s", ni->valid);
+ char *cond = xmlToHTML(ni->conditions);
+ asprintf(&pomA, "%s<h3>Conditions</h3>\r\n<pre>%s</pre>\r\n",
+ pomB, cond);
+ free(cond);
+ free(pomB);
+ pomB = pomA;
+ 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>Norification %s</h2>\r\n"
+ "<table halign=\"left\">%s</table>"
+ "\t</body>\r\n</html>",
+ ni->notifid, pomB);
+
+ *message = pomA;
+
+ return 0;
+}
/* construct Message-Body of Response-Line for edg_wll_JobStatus */
int edg_wll_JobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
chid = edg_wlc_JobIdUnparse(stat.jobId);
-#define TR(name,type,field) \
- if (field) { \
- asprintf(&pomA,"%s<tr><th align=\"left\">" name ":</th>" \
- "<td>" type "</td></tr>",pomB,(field)); \
- free(pomB); \
- pomB = pomA; \
- }
-
TR("Status","%s",(chstat = edg_wll_StatToString(stat.state)));
free(chstat);
TR("owner","%s",stat.owner);
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_UserJobsToHTML(edg_wll_Context, edg_wlc_JobId *, char **);
+int edg_wll_UserInfoToHTML(edg_wll_Context, edg_wlc_JobId *, char **, char **);
char *edg_wll_ErrorToHTML(edg_wll_Context,int);
#endif /* GLITE_LB_HTML_H */
#include "glite/lb/context-int.h"
#include "glite/lb/mini_http.h"
#include "glite/lb/xml_conversions.h"
+#include "glite/jobid/strmd5.h"
+#include "glite/lbu/trio.h"
#include "lb_proto.h"
#include "lb_text.h"
#include "purge.h"
#include "lb_xml_parse.h"
#include "lb_xml_parse_V21.h"
+#include "db_supp.h"
#define METHOD_GET "GET "
return 0;
}
+static int getUserNotifications(edg_wll_Context ctx, char *user, char ***notifids){
+ char *q = NULL;
+ glite_lbu_Statement notifs = NULL;
+ char *notifc[1] = {NULL};
+
+ trio_asprintf(&q, "select notifid "
+ "from notif_registrations "
+ "where userid='%s'",
+ user);
+ if (edg_wll_ExecSQL(ctx, q, ¬ifs) < 0) goto err;
+ free(q); q = NULL;
+
+ int n = 0;
+ *notifids = NULL;
+ while(edg_wll_FetchRow(ctx, notifs, sizeof(notifc)/sizeof(notifc[0]), NULL, notifc)){
+ n++;
+ *notifids = realloc(*notifids, n*sizeof(**notifids));
+ (*notifids)[n-1] = strdup(notifc[n-1]);
+ printf("Notif %s found\n", notifc[n-1]);
+ }
+ if (n){
+ *notifids = realloc(*notifids, (n+1)*sizeof(**notifids));
+ (*notifids)[n] = NULL;
+ }
+ return n;
+
+err:
+ return 0;
+}
+
+static int getNotifInfo(edg_wll_Context ctx, char *notifId, notifInfo *ni){
+ char *q = NULL;
+ glite_lbu_Statement notif = NULL;
+ char *notifc[6] = {NULL, NULL, NULL, NULL, NULL, NULL};
+
+ trio_asprintf(&q, "select destination, valid, conditions, "
+ "JDL_VirtualOrganisation, STD_owner, STD_network_server "
+ "from notif_registrations "
+ "where notifid='%s'",
+ notifId);
+ if (edg_wll_ExecSQL(ctx, q, ¬if) < 0) goto err;
+ free(q); q = NULL;
+
+ ni->notifid = strdup(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->JDL_VirtualOrganisation = notifc[3];
+ ni->STD_owner = notifc[4];
+ ni->STD_network_server = notifc[5];
+ }
+ else
+ goto err;
+
+ printf("%s\n%s\n", ni->destination, ni->valid);
+
+ return 0;
+
+err:
+ return edg_wll_Error(ctx, NULL, NULL);
+}
+
+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);
+}
edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx,
char *request,char **headers,char *messageBody,
flags = (requestPTR[1]=='?') ? edg_wll_string_to_stat_flags(requestPTR + 2) : 0;
+ char **notifids = NULL;
+ char *can_peername = edg_wll_gss_normalize_subj(ctx->peerName, 0);
+ char *userid = strmd5(can_peername, NULL);
+ free(can_peername);
+ 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_UserJobsToText(ctx, jobsOut, &message);
+ edg_wll_UserInfoToText(ctx, jobsOut, notifids, &message);
else if (html)
- edg_wll_UserJobsToHTML(ctx, jobsOut, &message);
+ edg_wll_UserInfoToHTML(ctx, jobsOut, notifids, &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=='/') {
+ else if (*requestPTR=='/'
+ && strncmp(requestPTR, "/notif/", strlen("/notif/"))) {
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/[notifId]: Norification info*/
+ } else if (strncmp(requestPTR, "/notif/", strlen("/notif/")) == 0){
+ notifInfo ni;
+ char *pomCopy, *pom;
+ pomCopy = strdup(requestPTR + 1);
+ for (pom=pomCopy; *pom && !isspace(*pom); pom++);
+ *pom = 0;
+ getNotifInfo(ctx, strrchr(pomCopy, '/')+1, &ni);
+ free(pomCopy);
+
+ if (text)
+ edg_wll_NotificationToText(ctx, &ni, &message);
+ else
+ edg_wll_NotificationToHTML(ctx, &ni, &message);
+
+ freeNotifInfo(&ni);
/* GET [something else]: not understood */
} else ret = HTTP_BADREQ;
char ** /* OUT: HTTP response body */
);
+typedef struct _notifInfo{
+ char *notifid;
+ char *destination;
+ char *valid;
+ char *conditions;
+ char *JDL_VirtualOrganisation;
+ char *STD_owner;
+ char *STD_network_server;
+} notifInfo;
+
extern char *edg_wll_HTTPErrorMessage(int);
extern int edg_wll_UserJobsServer(edg_wll_Context ctx, edg_wlc_JobId **jobs, edg_wll_JobStat **states);
#include "lb_proto.h"
#include "glite/lb/context-int.h"
+#include "glite/lbu/trio.h"
+#include "glite/lbu/db.h"
#include <string.h>
#include <stdio.h>
}
/* construct Message-Body of Response-Line for edg_wll_UserJobs */
-int edg_wll_UserJobsToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
+/*int edg_wll_UserJobsToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **message)
{
char *a, *b;
int i = 0;
*message = a;
return 0;
+}*/
+
+int edg_wll_UserInfoToText(edg_wll_Context ctx, edg_wlc_JobId *jobsOut, char **notifids, char **message)
+{
+ char *a = NULL, *b;
+ int i = 0;
+ b = strdup("");
+
+ while (jobsOut[i]){
+ char *chid = edg_wlc_JobIdUnparse(jobsOut[i]);
+
+ if (i == 0)
+ asprintf(&a, "%s%s", b, chid);
+ else
+ asprintf(&a, "%s,%s", b, chid);
+
+ free(chid);
+ free(b);
+ b = a;
+ 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);
+ 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>");
+
+ *message = a;
+
+ return 0;
}
+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);
+ asprintf(&a, "%sValid_until=%s\n", b, ni->valid);
+ char *cond = escape_text(ni->conditions);
+ asprintf(&b, "%sConditions=%s\n", a, cond);
+ free(cond);
+ a = b;
+ if (ni->JDL_VirtualOrganisation && ni->JDL_VirtualOrganisation[0])
+ asprintf(&a, "%sJDL_VirtualOrganisation=%s\n", b, ni->JDL_VirtualOrganisation);
+ b = a;
+ if (ni->STD_owner && ni->STD_owner[0])
+ asprintf(&a, "%sSTD_owner=%s\n", b, ni->STD_owner);
+ b = a;
+ if (ni->STD_network_server && ni->STD_network_server[0])
+ asprintf(&a, "%sSTD_network_server=%s\n", b, ni->STD_network_server);
+ *message = a;
+
+ return 0;
+}
+
/* construct Message-Body of Response-Line for edg_wll_JobStatus */
int edg_wll_JobStatusToText(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
{
asprintf(&jdl,"Job_description=%s\n", my_jdl);
free(my_jdl);
}
-
if (stat.rsl) asprintf(&rsl,"RSL=%s\n", stat.rsl);
asprintf(&a, "Job=%s\n"
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_UserJobsToText(edg_wll_Context, edg_wlc_JobId *, char **);
+int edg_wll_UserInfoToText(edg_wll_Context, edg_wlc_JobId *, char **, char **);
char *edg_wll_ErrorToText(edg_wll_Context,int);
#endif /* GLITE_LB_TEXT */