magic with two "static" gsoap worlds -- handles faults correctly now
authorAleš Křenek <ljocha@ics.muni.cz>
Tue, 14 Feb 2006 18:59:10 +0000 (18:59 +0000)
committerAleš Křenek <ljocha@ics.muni.cz>
Tue, 14 Feb 2006 18:59:10 +0000 (18:59 +0000)
org.glite.jp.primary/Makefile
org.glite.jp.primary/src/bones_server.c
org.glite.jp.primary/src/is_client.c
org.glite.jp.primary/src/mk_soap_switch.pl [new file with mode: 0755]
org.glite.jp.primary/src/soap_ops.c

index 10a5328..61ff0d1 100644 (file)
@@ -55,7 +55,7 @@ SRCS:= bones_server.c soap_ops.c \
        new_ftp_backend.c mysql.c file_plugin.c \
        feed.c authz.c attrs.c\
        is_client.c \
-       env_C.c
+       soap_switch.c
 
 #      ${ps_prefix}ServerLib.c \
 #      ${is_prefix}ClientLib.c jpps_C.c
@@ -197,3 +197,6 @@ soap_version.h:
        ${gsoap_bin_prefix}/soapcpp2 /dev/null
        perl -ne '$$. == 2 && /.*([0-9])\.([0-9])\.([0-9]).*/ && printf "#define GSOAP_VERSION %d%02d%02d\n",$$1,$$2,$$3' soapH.h >$@
        -rm soapC.cpp soapH.h soapStub.h soapClient.cpp soapServer.cpp soapClientLib.cpp soapServerLib.cpp 
+
+soap_env_ctx.c soap_env_ctx.h soap_switch.c: env_C.c mk_soap_switch.pl
+       ${top_srcdir}/src/mk_soap_switch.pl env_C.c >soap_switch.c
index 3d4f835..214e2f7 100644 (file)
@@ -222,8 +222,9 @@ static int data_init(void **data)
        *data = (void *) soap_new();
 
        printf("[%d] slave started\n",getpid());
+       glite_jpps_srv_init(ctx);
        glite_jppsbe_init_slave(ctx);   /* XXX: global but slave's */
-       sleep(10);
+       // sleep(10);
        if (glite_jppsbe_read_feeds(ctx)) fputs(glite_jp_error_chain(ctx),stderr);
        printf("[%d] slave init done\n",getpid());
 
index 5a0159b..30c12a9 100644 (file)
@@ -5,17 +5,26 @@
 #include <errno.h>
 #include <assert.h>
 
+#define SOAP_FMAC1 static
+
 #include "glite/jp/types.h"
 #include "glite/security/glite_gsplugin.h"
 
 #include "feed.h"
 #include "is_client.h"
 
-#include "jpis_ClientLib.c"
+/* same as ClientLib.c, without WITH_NOGLOBAL */
+#define SOAP_FMAC3 static
+#include "jpis_C.c"
+#include "jpis_Client.c"
+
 #include "jpis_.nsmap"
 
 #include "soap_util.c"
 
+#include "soap_env_ctx.h"
+#include "soap_env_ctx.c"
+
 extern char *server_key, *server_cert; /* XXX */
 
 static int check_other_soap(glite_jp_context_t ctx)
@@ -56,6 +65,18 @@ static check_fault(glite_jp_context_t ctx,struct soap *soap,int ec)
        }
 }
 
+static struct _glite_jp_soap_env_ctx_t *keep_soap_env_ctx;
+
+#define SWITCH_SOAP_CTX \
+{ \
+       keep_soap_env_ctx = glite_jp_soap_env_ctx; \
+       glite_jp_soap_env_ctx = &my_soap_env_ctx; \
+} \
+
+#define RESTORE_SOAP_CTX \
+{ \
+       glite_jp_soap_env_ctx = keep_soap_env_ctx; \
+} \
 
 int glite_jpps_single_feed(
                glite_jp_context_t ctx,
@@ -101,6 +122,7 @@ int glite_jpps_single_feed(
        jr.primaryStorage = &ctx->myURL;
 
 
+       SWITCH_SOAP_CTX
        if (soap_call___jpsrv__UpdateJobs(ctx->other_soap,destination,"",
                &in,&out
        )) {
@@ -120,6 +142,7 @@ int glite_jpps_single_feed(
                buf[999] = 0;
                glite_jp_stack_error(ctx,&err);
        }
+       RESTORE_SOAP_CTX
 
        attrValues_free(ctx->other_soap,jr.attributes,jr.__sizeattributes);
 
@@ -175,8 +198,10 @@ int glite_jpps_multi_feed(
                jr->primaryStorage = &ctx->myURL;
        }
 
+       SWITCH_SOAP_CTX
        check_fault(ctx,ctx->other_soap,
                soap_call___jpsrv__UpdateJobs(ctx->other_soap,destination,"", &in,&out));
+       RESTORE_SOAP_CTX
        for (i=0; i<njobs; i++) {
                jr = in.jobAttributes[i];
                attrValues_free(ctx->other_soap,jr->attributes,jr->__sizeattributes);
diff --git a/org.glite.jp.primary/src/mk_soap_switch.pl b/org.glite.jp.primary/src/mk_soap_switch.pl
new file mode 100755 (executable)
index 0000000..c9acdab
--- /dev/null
@@ -0,0 +1,63 @@
+#!/usr/bin/perl
+
+$formula = "/* Generated from @ARGV with the help of black magic.\n   Do not edit.\n*/\n\n";
+print "${formula}#include \"soap_env_ctx.h\"\n\n";
+
+# XXX: hardcoded
+$prefix = 'ENV';
+
+open EH,">soap_env_ctx.h" or die "soap_env_ctx.h: $!\n";
+open EC,">soap_env_ctx.c" or die "soap_env_ctx.c: $!\n";
+
+print EH "${formula}struct _glite_jp_soap_env_ctx_t {\n";
+
+print EC "${formula}static struct _glite_jp_soap_env_ctx_t my_soap_env_ctx = {\n";
+
+
+while ($_ = <>) {
+       if (/^}$/) {
+               print;
+               $infunc = 0;
+               undef @args;
+               next;
+       }
+
+       next if $infunc;
+
+       if (/^SOAP_FMAC3\s+(.+)\s+SOAP_FMAC4\s+([^(]+)\(([^)]*)\)/) {
+               $type = $1;
+               $func = $2;
+               @a = split /,/,$3;
+               for $a (@a) {
+                       $a =~ /.*\W(\w+)/;
+                       push @args,$1;
+               }
+               print;
+
+               next if $func =~ "SOAP_$prefix";
+
+               print EH "\t$type (*$func)();\n";
+               print EC "\t$func,\n";
+               next;
+       }
+
+       if (/^{/) {
+               print;
+               next if $func =~ "SOAP_$prefix";
+               local $"=',';
+               $infunc = 1;
+               print "\t";
+               print 'return ' unless $type eq 'void';
+               print "glite_jp_soap_env_ctx->$func(@args);\n";
+
+               next;
+       }
+
+       print;
+}
+
+print EH "};\n\n";
+print EH "extern struct _glite_jp_soap_env_ctx_t *glite_jp_soap_env_ctx;\n";
+print EC "};\n";
+
+print "struct _glite_jp_soap_env_ctx_t *glite_jp_soap_env_ctx;\n";
index 135b23c..3943879 100644 (file)
@@ -2,6 +2,8 @@
 #include <fcntl.h>
 #include <assert.h>
 
+#define SOAP_FMAC1     static
+
 #include "glite/jp/types.h"
 #include "glite/jp/context.h"
 #include "glite/jp/attr.h"
 #include "file_plugin.h"
 #include "builtin_plugins.h"
 
-#include "jpps_ServerLib.c"
+/* the same as ServerLib.c but without WITH_NOGLOBAL which breaks the soap_env_ctx trick */
+#define SOAP_FMAC3 static
+#include "jpps_C.c"
+#include "jpps_Server.c"
+
 #include "jpps_.nsmap"
 
 #include "soap_util.c"
 
+#include "soap_env_ctx.h"
+#include "soap_env_ctx.c"
+
 static struct jptype__genericFault *jp2s_error(struct soap *soap,
                const glite_jp_error_t *err)
 {
@@ -60,6 +69,12 @@ static void err2fault(const glite_jp_context_t ctx,struct soap *soap)
 
 #define CONTEXT_FROM_SOAP(soap,ctx) glite_jp_context_t ctx = (glite_jp_context_t) ((soap)->user)
 
+int glite_jpps_srv_init(glite_jp_context_t ctx)
+{
+       glite_jp_soap_env_ctx = &my_soap_env_ctx;
+       return 0;
+}
+
 SOAP_FMAC5 int SOAP_FMAC6 __jpsrv__RegisterJob(
                struct soap *soap,
                struct _jpelem__RegisterJob *in,