From cb6137c527de8dd63e68caaaa80eecdca86999b6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Ji=C5=99=C3=AD=20Filipovi=C4=8D?= Date: Wed, 24 Jun 2009 15:20:41 +0000 Subject: [PATCH] SOAP accepted at the same port as HTTP/LB proto. (unfinished, but shouldn't corrupt anything) --- org.glite.lb.server/src/bkserverd.c | 103 +++++++++++++++++++++++++----------- org.glite.lb.server/src/lb_http.c | 28 +++++----- org.glite.lb.server/src/lb_http.h | 4 +- org.glite.lb.server/src/lb_proto.c | 5 +- org.glite.lb.server/src/lb_proto.h | 3 +- 5 files changed, 95 insertions(+), 48 deletions(-) diff --git a/org.glite.lb.server/src/bkserverd.c b/org.glite.lb.server/src/bkserverd.c index 5bcb762..d33d1ee 100644 --- a/org.glite.lb.server/src/bkserverd.c +++ b/org.glite.lb.server/src/bkserverd.c @@ -1144,51 +1144,67 @@ 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) +{ + struct soap *soap = NULL; + int err = 0; + + if ( glite_gsplugin_init_context(gsplugin_ctx) ) { + fprintf(stderr, "Couldn't create gSOAP plugin context"); + return -1; + } + + if ( !(soap = soap_new()) ) { + fprintf(stderr, "Couldn't create soap environment"); + goto err; + } + + soap_init2(soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE); + 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) ) { + soap_done(soap); + perror("Couldn't set soap namespaces"); + goto err; + } + + glite_gsplugin_use_credential(*gsplugin_ctx, mycred); + cdata->soap = soap; + + return 0; +err: + if ( *gsplugin_ctx ) glite_gsplugin_free_context(*gsplugin_ctx); + if ( soap ) soap_destroy(soap); + + return err; +} + int bk_handle_ws_connection(int conn, struct timeval *timeout, void *data) { struct clnt_data_t *cdata = (struct clnt_data_t *) data; - struct soap *soap = NULL; - glite_gsplugin_Context gsplugin_ctx; - int rv = 0; + glite_gsplugin_Context gsplugin_ctx = NULL; + int rv = 0; + int err = 0; - - if ( glite_gsplugin_init_context(&gsplugin_ctx) ) { - fprintf(stderr, "Couldn't create gSOAP plugin context"); + if ((err = bk_init_ws_connection(cdata, &gsplugin_ctx))) return -1; - } - if ( !(soap = soap_new()) ) { - fprintf(stderr, "Couldn't create soap environment"); - goto err; - } - - soap_init2(soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE); - 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) ) { - soap_done(soap); - perror("Couldn't set soap namespaces"); - goto err; - } - if ( (rv = bk_handle_connection(conn, timeout, data)) ) { - soap_done(soap); + if ( (rv = bk_handle_connection(conn, timeout, data)) ){ + soap_done(cdata->soap); goto err; } glite_gsplugin_set_connection(gsplugin_ctx, &cdata->ctx->connections->serverConnection->gss); - glite_gsplugin_use_credential(gsplugin_ctx, mycred); - cdata->soap = soap; - return 0; err: if ( gsplugin_ctx ) glite_gsplugin_free_context(gsplugin_ctx); - if ( soap ) soap_destroy(soap); + if ( cdata->soap ) soap_destroy(cdata->soap); - return rv? : -1; + return rv ? : -1; } #endif /* GLITE_LB_SERVER_WITH_WS */ @@ -1357,13 +1373,38 @@ 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; + int httpErr; /* * serve the request */ memcpy(&ctx->p_tmp_timeout, timeout, sizeof(ctx->p_tmp_timeout)); gettimeofday(&before, NULL); - if ( edg_wll_ServerHTTP(ctx) && (err = handle_server_error(ctx))) return err; + err = edg_wll_AcceptHTTP(ctx, &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); + // hdrOut are static + return err; + } + } +#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() + } +#endif + + edg_wll_DoneHTTP(ctx, resp, hdrOut, bodyOut); + free(resp); + free(bodyOut); + // hdrOut are static gettimeofday(&after, NULL); if ( decrement_timeout(timeout, before, after) ) { diff --git a/org.glite.lb.server/src/lb_http.c b/org.glite.lb.server/src/lb_http.c index 99439d2..a46313f 100644 --- a/org.glite.lb.server/src/lb_http.c +++ b/org.glite.lb.server/src/lb_http.c @@ -16,12 +16,12 @@ extern int debug; #define dprintf(x) if (debug) printf x -int edg_wll_ServerHTTP(edg_wll_Context ctx) +int edg_wll_AcceptHTTP(edg_wll_Context ctx, char **resp, char ***hdrOut, char **bodyOut, int *httpErr) { char **hdr = NULL,*req = NULL,*body = NULL, - **hdrOut = NULL, *resp = NULL, *bodyOut = 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); @@ -35,29 +35,31 @@ int edg_wll_ServerHTTP(edg_wll_Context ctx) if (body) dprintf(("request body:\n%s\n\n",body)); if (!err) { - if ((err = edg_wll_Proto(ctx,req,hdr,body,&resp,&hdrOut,&bodyOut))) + if ((err = edg_wll_Proto(ctx,req,hdr,body,resp,hdrOut,bodyOut,httpErr))) edg_wll_Error(ctx,NULL,&err_desc); - - if (resp) { - if ( ctx->isProxy ) - edg_wll_http_send_proxy(ctx,resp,(char const * const *)hdrOut,bodyOut); - else - edg_wll_http_send(ctx,resp,(char const * const *)hdrOut,bodyOut,ctx->connections->serverConnection); - } } free(req); - free(resp); if (hdr) { char **h; for (h = hdr; *h; h++) free(*h); free(hdr); } - // hdrOut are static free(body); - free(bodyOut); if (err != edg_wll_Error(ctx,NULL,NULL)) edg_wll_SetError(ctx,err,err_desc); free(err_desc); return err; } + +int edg_wll_DoneHTTP(edg_wll_Context ctx, char *resp, char **hdrOut, char *bodyOut) +{ + if (resp) { + if ( ctx->isProxy ) + edg_wll_http_send_proxy(ctx,resp,(char const * const *)hdrOut,bodyOut); + else + edg_wll_http_send(ctx,resp,(char const * const *)hdrOut,bodyOut,ctx->connections->serverConnection); + } + + return 0; +} diff --git a/org.glite.lb.server/src/lb_http.h b/org.glite.lb.server/src/lb_http.h index 421beea..2ddf3a4 100644 --- a/org.glite.lb.server/src/lb_http.h +++ b/org.glite.lb.server/src/lb_http.h @@ -5,7 +5,7 @@ #include "glite/lb/context.h" -int edg_wll_ServerHTTP(edg_wll_Context); -int edg_wll_ServerHTTPProxy(edg_wll_Context); +int edg_wll_AcceptHTTP(edg_wll_Context ctx, 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 */ diff --git a/org.glite.lb.server/src/lb_proto.c b/org.glite.lb.server/src/lb_proto.c index 773f63d..4bff14c 100644 --- a/org.glite.lb.server/src/lb_proto.c +++ b/org.glite.lb.server/src/lb_proto.c @@ -565,7 +565,8 @@ errV21: asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret)); edg_wll_ErrorCode edg_wll_Proto(edg_wll_Context ctx, char *request,char **headers,char *messageBody, - char **response,char ***headersOut,char **bodyOut) + char **response,char ***headersOut,char **bodyOut, + int *httpErr) { char *requestPTR = NULL, *message = NULL; int ret = HTTP_OK; @@ -1191,5 +1192,7 @@ err: asprintf(response,"HTTP/1.1 %d %s",ret,edg_wll_HTTPErrorMessage(ret)); if (requestPTR) free(requestPTR); + *httpErr = ret; + return edg_wll_Error(ctx,NULL,NULL); } diff --git a/org.glite.lb.server/src/lb_proto.h b/org.glite.lb.server/src/lb_proto.h index b3aaba0..65b5dde 100644 --- a/org.glite.lb.server/src/lb_proto.h +++ b/org.glite.lb.server/src/lb_proto.h @@ -18,7 +18,8 @@ extern edg_wll_ErrorCode edg_wll_Proto( char *, /* IN: HTTP message body */ char **, /* OUT: HTTP response line */ char ***, /* OUT: HTTP response headers */ - char ** /* OUT: HTTP response body */ + char **, /* OUT: HTTP response body */ + int * /* OUT: HTTP error code */ ); typedef struct _notifInfo{ -- 1.8.2.3