HTTP interface shows WSDL files
authorJiří Filipovič <fila@ics.muni.cz>
Thu, 3 Feb 2011 15:16:24 +0000 (15:16 +0000)
committerJiří Filipovič <fila@ics.muni.cz>
Thu, 3 Feb 2011 15:16:24 +0000 (15:16 +0000)
org.glite.lb.server/src/lb_html.c
org.glite.lb.server/src/lb_proto.c

index 90d3786..9428819 100644 (file)
@@ -25,11 +25,14 @@ limitations under the License.
 #include "glite/lb/context-int.h"
 #include "glite/lb/xml_conversions.h"
 
+#include "glite/lbu/log.h"
+
 #include <string.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #include <assert.h>
+#include <errno.h>
 
 #ifdef __GNUC__
 #define UNUSED_VAR __attribute__((unused))
@@ -384,10 +387,12 @@ int edg_wll_CreamJobStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat
 
 int edg_wll_FileTransferStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_JobStat stat, char **message)
 {
-        char *pomA = NULL, *pomB = NULL, *lbstat;
-        int pomL = 0;
+        char *pomA = NULL, *pomB = NULL, *lbstat, *children;
+        int pomL = 0, i;
         char    *chid,*chcj,*chsbt;
 
+       children = strdup("");
+
         chid = edg_wlc_JobIdUnparse(stat.jobId);
 
        TR("Status", "%s", (lbstat = edg_wll_StatToString(stat.state)), NULL);
@@ -396,33 +401,99 @@ int edg_wll_FileTransferStatusToHTML(edg_wll_Context ctx UNUSED_VAR, edg_wll_Job
        chcj = edg_wlc_JobIdUnparse(stat.ft_compute_job);
        TRL("Compute job", "%s", chcj, NULL);
        free(chcj);
-       
-       switch(stat.ft_sandbox_type){
-               case EDG_WLL_STAT_INPUT: chsbt = strdup("INPUT");
-                       break;
-               case EDG_WLL_STAT_OUTPUT: chsbt = strdup("OUTPUT");
-                       break;
-               default: chsbt = NULL;
-                       break;
+
+       if (stat.jobtype == EDG_WLL_STAT_FILE_TRANSFER){
+               switch(stat.ft_sandbox_type){
+                       case EDG_WLL_STAT_INPUT: chsbt = strdup("INPUT");
+                               break;
+                       case EDG_WLL_STAT_OUTPUT: chsbt = strdup("OUTPUT");
+                               break;
+                       default: chsbt = NULL;
+                               break;
+               }
+               TR("Sandbox type", "%s", chsbt, NULL);
+               TR("File transfer source", "%s", stat.ft_src, NULL);
+               TR("File transfer destination", "%s", stat.ft_dest, NULL);
+       }
+       else if ((stat.jobtype == EDG_WLL_STAT_FILE_TRANSFER_COLLECTION) && (stat.children_num > 0)){
+               asprintf(&children, "<h3>Children</h3>\r\n");
+                for (i = 0; i < stat.children_num; i++){
+                        asprintf(&pomA,"%s\t\t <li/> <a href=\"%s\">%s</a>\r\n",
+                        children, stat.children[i], stat.children[i]);
+                        children = pomA;
+                }
        }
-       TR("Sandbox type", "%s", chsbt, NULL);
-       TR("File transfer source", "%s", stat.ft_src, NULL);
-       TR("File transfer destination", "%s", stat.ft_dest, NULL);
 
         asprintf(&pomA, "<html>\r\n\t<body>\r\n"
                         "<h2>%s</h2>\r\n"
-                        "<table halign=\"left\">%s</table>"
+                        "<table halign=\"left\">%s</table>\r\n"
+                       "%s\n"
                         "\t</body>\r\n</html>",
-                        chid,pomB);
+                        chid, pomB, children);
         free(pomB);
 
         *message = pomA;
 
        if (chsbt) free(chsbt);
         free(chid);
+       free(children);
         return 0;
 }
 
+// replace s1 to s2 in text
+static int replace_substr(char **text, char *s1, char *s2){
+       int l1, l2;
+       char *out;
+
+       char *p = strstr(*text, s1);
+       if (! p) return -1; // exit if s1 not found
+
+       l1 = strlen(s1);
+       l2 = strlen(s2);
+       out = (char*)malloc((strlen(*text)+l2-l1+1)*sizeof(char));
+       
+       strncpy(out, *text, p-*text);
+       out[p-*text] = 0;
+       sprintf(out+(p-*text), "%s%s", s2, p+l1);
+
+       free(*text);
+       *text = out;
+}
+
+int edg_wll_WSDLOutput(edg_wll_Context ctx UNUSED_VAR, char **message, char *filename){
+       FILE *f;
+       char *wsdl, *p, *start;
+       int i, b;
+
+       if ((f = fopen(filename, "r")) == NULL){
+               glite_common_log(LOG_CATEGORY_CONTROL, LOG_PRIORITY_WARN, "%s not found!\n", filename);
+               edg_wll_SetError(ctx, ENOENT, "WSDL File not found!");
+               return -1;
+       }
+
+       // load wsdl
+       wsdl = (char*)malloc(4096*sizeof(char));
+       i = 1;
+       while ((b = fread(wsdl+(i-1)*4096, sizeof(char), 4096, f)) == 4096){
+               i++;
+               wsdl = (char*)realloc(wsdl, 4096*i*sizeof(char));
+       }
+       wsdl[(i-1)*4096+b] = 0;
+
+       // fix imports
+       char *addr;
+       asprintf(&addr, "https://%s:%i/?types", ctx->srvName, ctx->srvPort);
+       replace_substr(&wsdl, "LBTypes.wsdl", addr);
+       free(addr);
+       asprintf(&addr, "https://%s:%i/?agu", ctx->srvName, ctx->srvPort);
+       replace_substr(&wsdl, "lb4agu.wsdl", addr);
+       free(addr);
+
+       *message = wsdl;
+       
+       return 0;
+}
+
 char *edg_wll_ErrorToHTML(edg_wll_Context ctx,int code)
 {
        char    *out,*et,*ed;
index cad2453..9d470d8 100644 (file)
@@ -642,7 +642,8 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                }
 
        /* GET /: Current User Jobs */
-               else if (requestPTR[0]=='/' && (requestPTR[1]==' ' || requestPTR[1]=='?')) {
+               else if (requestPTR[0]=='/' && 
+                       (requestPTR[1]==' ' || !strncmp(requestPTR+1, "/?text", strlen("/?text")))) {
                        edg_wlc_JobId *jobsOut = NULL;
                        edg_wll_JobStat *statesOut = NULL;
                        int     i, flags;
@@ -674,6 +675,9 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
 
        /* GET /[jobId]: Job Status */
                else if (*requestPTR=='/'
+                       && strncmp(requestPTR, "/?wsdl", strlen("/?wsdl"))
+                       && strncmp(requestPTR, "/?types", strlen("/?types"))
+                       && strncmp(requestPTR, "/?agu", strlen("/?agu"))
                        && strncmp(requestPTR, "/RSS:", strlen("/RSS:")) 
                        && ( strncmp(requestPTR, "/NOTIF", strlen("/NOTIF"))
                             || *(requestPTR+strlen("/NOTIF")) != ':'
@@ -711,6 +715,7 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                                        edg_wll_CreamJobStatusToHTML(ctx,stat,&message);
                                                        break;
                                                case EDG_WLL_STAT_FILE_TRANSFER:
+                                               case EDG_WLL_STAT_FILE_TRANSFER_COLLECTION:
                                                        edg_wll_FileTransferStatusToHTML(ctx,stat,&message);
                                                        break;
                                                default:
@@ -793,7 +798,30 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
                                edg_wll_SetError(ctx, ENOENT, "current index configuration does not support RSS feeds");
                        }
                        edg_wll_RSSFeed(ctx, states, requestPTR, &message);
-
+       /*GET /?wsdl */
+#define WSDL_LB "LB.wsdl"
+#define WSDL_LBTYPES "LBTypes.wsdl"
+#define WSDL_LB4AGU "lb4agu.wsdl"
+               } else if (strncmp(requestPTR, "/?wsdl", strlen("/?wsdl")) == 0) {
+                       char *filename;
+                       asprintf(&filename, "%s/interface/%s", getenv("GLITE_LOCTION"), WSDL_LB);
+                       if (edg_wll_WSDLOutput(ctx, &message, filename))
+                               ret = HTTP_INTERNAL;
+                       free(filename);
+       /* GET /?types */
+               } else if (strncmp(requestPTR, "/?types", strlen("/?types")) == 0) {
+                        char *filename;
+                        asprintf(&filename, "%s/interface/%s", getenv("GLITE_LOCTION"), WSDL_LBTYPES);
+                        if (edg_wll_WSDLOutput(ctx, &message, filename))
+                                ret = HTTP_INTERNAL;
+                       free(filename);
+       /* GET /?agu */
+                } else if (strncmp(requestPTR, "/?agu", strlen("/?agu")) == 0) {
+                        char *filename;
+                        asprintf(&filename, "%s/interface/%s", getenv("GLITE_LOCTION"), WSDL_LB4AGU);
+                        if (edg_wll_WSDLOutput(ctx, &message, filename))
+                                ret = HTTP_INTERNAL;
+                       free(filename);
        /* GET [something else]: not understood */
                } else ret = HTTP_BADREQ;
                free(requestPTR); requestPTR = NULL;