Fix/update glite location when searching for WSDLs.
authorFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 3 Mar 2011 00:09:26 +0000 (00:09 +0000)
committerFrantišek Dvořák <valtri@civ.zcu.cz>
Thu, 3 Mar 2011 00:09:26 +0000 (00:09 +0000)
org.glite.lb.server/src/lb_proto.c

index cad1229..39e5bb2 100644 (file)
@@ -17,6 +17,8 @@ limitations under the License.
 */
 
 
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -395,6 +397,23 @@ static void hup_handler(int sig) {
        purge_quit = 1;
 }
 
+static char *glite_location() {
+       char *location = NULL;
+       struct stat info;
+
+       if (!(location = getenv("GLITE_LB_LOCATION")))
+       if (!(location = getenv("GLITE_LOCATION")))
+       {
+               if (stat("/opt/glite/interfaces", &info) == 0 && S_ISDIR(info.st_mode))
+                       location = "/opt/glite";
+               else 
+                       if (stat("/usr/interfaces", &info) == 0 && S_ISDIR(info.st_mode))
+                               location = "/usr";
+       }
+
+       return location;
+}
+
 edg_wll_ErrorCode edg_wll_ProtoV21(edg_wll_Context ctx,
        char *request,char **headers,char *messageBody,
        char **response,char ***headersOut,char **bodyOut)
@@ -801,21 +820,21 @@ edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx,
 #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);
+                       asprintf(&filename, "%s/interface/%s", glite_location(), 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);
+                        asprintf(&filename, "%s/interface/%s", glite_location(), 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);
+                        asprintf(&filename, "%s/interface/%s", glite_location(), WSDL_LB4AGU);
                         if (edg_wll_WSDLOutput(ctx, &message, filename))
                                 ret = HTTP_INTERNAL;
                        free(filename);