Handling WS messages over legacy port
authorDaniel Kouřil <kouril@ics.muni.cz>
Fri, 3 Jul 2009 11:21:24 +0000 (11:21 +0000)
committerDaniel Kouřil <kouril@ics.muni.cz>
Fri, 3 Jul 2009 11:21:24 +0000 (11:21 +0000)
org.glite.lb.server/src/bkserverd.c
org.glite.lb.server/src/lb_http.c
org.glite.lb.server/src/lb_http.h

index d33d1ee..e06dd1d 100644 (file)
@@ -1144,12 +1144,13 @@ int bk_handle_connection(int conn, struct timeval *timeout, void *data)
 }
 
 #ifdef GLITE_LB_SERVER_WITH_WS
-int bk_init_ws_connection(struct clnt_data_t *cdata, glite_gsplugin_Context *gsplugin_ctx)
+int bk_init_ws_connection(struct clnt_data_t *cdata)
 {
        struct soap             *soap = NULL;
+       glite_gsplugin_Context  gsplugin_ctx = NULL;
        int err = 0;
 
-       if ( glite_gsplugin_init_context(gsplugin_ctx) ) {
+       if ( glite_gsplugin_init_context(&gsplugin_ctx) ) {
                 fprintf(stderr, "Couldn't create gSOAP plugin context");
                 return -1;
         }
@@ -1160,23 +1161,23 @@ int bk_init_ws_connection(struct clnt_data_t *cdata, glite_gsplugin_Context *gsp
         }
 
         soap_init2(soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE);
-    if ( soap_set_namespaces(soap, namespaces) ) { 
+       if ( soap_set_namespaces(soap, namespaces) ) { 
                 soap_done(soap);
                 perror("Couldn't set soap namespaces");
                 goto err;
         }
-    if ( soap_register_plugin_arg(soap, glite_gsplugin, *gsplugin_ctx) ) {
+       if ( soap_register_plugin_arg(soap, glite_gsplugin, gsplugin_ctx) ) {
                 soap_done(soap);
                 perror("Couldn't set soap namespaces");
                 goto err;
         }
 
-       glite_gsplugin_use_credential(*gsplugin_ctx, mycred);
+       glite_gsplugin_use_credential(gsplugin_ctx, mycred);
         cdata->soap = soap;
 
        return 0;
 err:
-       if ( *gsplugin_ctx ) glite_gsplugin_free_context(*gsplugin_ctx);
+       if ( gsplugin_ctx ) glite_gsplugin_free_context(gsplugin_ctx);
         if ( soap ) soap_destroy(soap);
 
        return err;
@@ -1189,19 +1190,20 @@ int bk_handle_ws_connection(int conn, struct timeval *timeout, void *data)
        int                     rv = 0;
        int                     err = 0;
 
-       if ((err = bk_init_ws_connection(cdata, &gsplugin_ctx)))
+       if ((err = bk_init_ws_connection(cdata)))
                return -1;
 
        if ( (rv = bk_handle_connection(conn, timeout, data)) ){
                soap_done(cdata->soap);
                goto err;
        }
+
+       gsplugin_ctx = glite_gsplugin_get_context(cdata->soap);
        glite_gsplugin_set_connection(gsplugin_ctx, &cdata->ctx->connections->serverConnection->gss);
 
        return 0;
 
 err:
-       if ( gsplugin_ctx ) glite_gsplugin_free_context(gsplugin_ctx);
        if ( cdata->soap ) soap_destroy(cdata->soap);
 
        return rv ? : -1;
@@ -1367,13 +1369,41 @@ int bk_accept_store(int conn, struct timeval *timeout, void *cdata)
        return 0;
 }
 
+static int
+try_accept_ws(int conn, struct timeval *timeout, void *cdata, char *req, size_t len)
+{
+       edg_wll_Context ctx = ((struct clnt_data_t *) cdata)->ctx;
+       glite_gsplugin_Context  gsplugin_ctx = NULL;
+       struct soap *soap = NULL;
+       int err;
+
+       err = bk_init_ws_connection(cdata);
+       if (err)
+               return err;
+       soap = ((struct clnt_data_t *) cdata)->soap;
+       gsplugin_ctx = glite_gsplugin_get_context(soap);
+       err = edg_wll_gss_unread(&ctx->connections->serverConnection->gss, req, len);
+       if (err)
+               goto end;
+       glite_gsplugin_set_connection(gsplugin_ctx, &ctx->connections->serverConnection->gss);
+       bk_accept_ws(conn, timeout, cdata);
+
+       err = 0;
+end:
+       soap_destroy(soap);
+       glite_gsplugin_free_context(gsplugin_ctx);
+
+       return err;
+}
+
+
 
 int bk_accept_serve(int conn, struct timeval *timeout, void *cdata)
 {
        edg_wll_Context         ctx = ((struct clnt_data_t *) cdata)->ctx;
        struct timeval          before, after;
        int     err;
-       char    *resp = NULL, **hdrOut = NULL, *bodyOut = NULL;
+       char    *body = NULL, *resp = NULL, **hdrOut = NULL, *bodyOut = NULL;
        int     httpErr;
 
        /*
@@ -1381,29 +1411,31 @@ int bk_accept_serve(int conn, struct timeval *timeout, void *cdata)
         */
        memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout));
        gettimeofday(&before, NULL);
-       err = edg_wll_AcceptHTTP(ctx, &resp, &hdrOut, &bodyOut, &httpErr);
+       err = edg_wll_AcceptHTTP(ctx, &body, &resp, &hdrOut, &bodyOut, &httpErr);
        if (httpErr != HTTP_BADREQ){
                if (err && (err = handle_server_error(ctx))){
                        edg_wll_DoneHTTP(ctx, resp, hdrOut, bodyOut);
                        free(resp);
                        free(bodyOut);
+                        if (body)
+                               free(body);
                        // hdrOut are static
                        return err;
                }
        }
+
+       err = 0;
 #ifdef GLITE_LB_SERVER_WITH_WS
-       else{
-               glite_gsplugin_Context  gsplugin_ctx = NULL;
-               bk_init_ws_connection(cdata, &gsplugin_ctx);
-               glite_gsplugin_set_connection(gsplugin_ctx, &ctx->connections->serverConnection->gss);
-               // write back buffer
-               //bk_accept_ws()
-       }
+       if (httpErr == HTTP_BADREQ)
+               err = try_accept_ws(conn, timeout, cdata, body, strlen(body) + 1);
 #endif
+       if (!err)
+               edg_wll_DoneHTTP(ctx, resp, hdrOut, bodyOut);
 
-       edg_wll_DoneHTTP(ctx, resp, hdrOut, bodyOut);
        free(resp);
        free(bodyOut);
+       if (body)
+               free(body);
        // hdrOut are static
 
        gettimeofday(&after, NULL);
index a46313f..2571f6f 100644 (file)
@@ -16,26 +16,25 @@ extern int debug;
 #define dprintf(x) if (debug) printf x
 
 
-int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **resp, char ***hdrOut, char **bodyOut, int *httpErr)
+int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **body, char **resp, char ***hdrOut, char **bodyOut, int *httpErr)
 {
-       char    **hdr = NULL,*req = NULL,*body = NULL,
-               *err_desc = NULL;
+       char    **hdr = NULL,*req = NULL, *err_desc = NULL;
        edg_wll_ErrorCode       err = 0;
        *httpErr = HTTP_OK;
 
 
-       if ( ctx->isProxy ) err = edg_wll_http_recv_proxy(ctx,&req,&hdr,&body);
-       else err = edg_wll_http_recv(ctx,&req,&hdr,&body,ctx->connections->serverConnection);
+       if ( ctx->isProxy ) err = edg_wll_http_recv_proxy(ctx,&req,&hdr,body);
+       else err = edg_wll_http_recv(ctx,&req,&hdr,body,ctx->connections->serverConnection);
 
        if (req) {
                dprintf(("[%d] request: %s\n",getpid(),req));
        } else {
                dprintf(("no request\n"));
        }
-       if (body) dprintf(("request body:\n%s\n\n",body));
+       if (body && *body) dprintf(("request body:\n%s\n\n",*body));
 
        if (!err) {
-               if ((err = edg_wll_Proto(ctx,req,hdr,body,resp,hdrOut,bodyOut,httpErr)))
+               if ((err = edg_wll_Proto(ctx,req,hdr,*body,resp,hdrOut,bodyOut,httpErr)))
                        edg_wll_Error(ctx,NULL,&err_desc);
        }
 
@@ -45,7 +44,6 @@ int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **resp, char ***hdrOut, char **
                for (h = hdr; *h; h++) free(*h);
                free(hdr);
        }
-       free(body);
 
        if (err != edg_wll_Error(ctx,NULL,NULL)) edg_wll_SetError(ctx,err,err_desc);
        free(err_desc);
index 2ddf3a4..0c77bc8 100644 (file)
@@ -5,7 +5,7 @@
 
 #include "glite/lb/context.h"
 
-int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **resp, char ***hdrOut, char **bodyOut, int *httpErr);
+int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **body, char **resp, char ***hdrOut, char **bodyOut, int *httpErr);
 int edg_wll_DoneHTTP(edg_wll_Context ctx, char *resp, char **hdrOut, char *bodyOut);
 
 #endif /* GLITE_LB_HTTP_H */