Avoid mixed stmt/var declare
[simpleserver-moved-to-github.git] / SimpleServer.xs
index 16eb108..862ef21 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: SimpleServer.xs,v 1.32 2004-06-07 16:48:38 adam Exp $ 
+ * $Id: SimpleServer.xs,v 1.36 2006-01-30 21:29:41 adam Exp $ 
  * ----------------------------------------------------------------------
  * 
  * Copyright (c) 2000-2004, Index Data.
@@ -358,7 +358,7 @@ void fatal(char *fmt, ...)
 {
     va_list ap;
 
-    fprintf(stderr, "FATAL (yazwrap): ");
+    fprintf(stderr, "FATAL (SimpleServer): ");
     va_start(ap, fmt);
     vfprintf(stderr, fmt, ap);
     va_end(ap);
@@ -441,8 +441,22 @@ static SV *rpn2perl(Z_RPNStructure *s)
     case Z_RPNStructure_simple: {
        Z_Operand *o = s->u.simple;
        Z_AttributesPlusTerm *at;
+       if (o->which == Z_Operand_resultSetId) {
+           SV *sv2;
+           /* This code causes a SIGBUS on my machine, and I have no
+              idea why.  It seems as clear as day to me */
+           char *rsid = (char*) o->u.resultSetId;
+           printf("Encoding resultSetId '%s'\n", rsid);
+           sv = newObject("Net::Z3950::RPN::RSID", (SV*) (hv = newHV()));
+           printf("Made sv=0x%lx, hv=0x%lx\n",
+                  (unsigned long) sv ,(unsigned long) hv);
+           sv2 = newSVpv(rsid, strlen(rsid));
+           setMember(hv, "id", sv2);
+           printf("Set hv{id} to 0x%lx\n", (unsigned long) sv2);
+           return sv;
+       }
        if (o->which != Z_Operand_APT)
-           fatal("can't handle RPN simples other than APT");
+           fatal("can't handle RPN simples other than APT and RSID");
        at = o->u.attributesPlusTerm;
        if (at->term->which != Z_Term_general)
            fatal("can't handle RPN terms other than general");
@@ -1301,7 +1315,8 @@ void bend_close(void *handle)
 
                sv_free((SV*) href);
        }
-       sv_free(zhandle->handle);
+       else
+               sv_free(zhandle->handle);
        PUTBACK;
        FREETMPS;
        LEAVE;
@@ -1317,6 +1332,9 @@ void bend_close(void *handle)
 
 MODULE = Net::Z3950::SimpleServer      PACKAGE = Net::Z3950::SimpleServer
 
+PROTOTYPES: DISABLE
+
+
 void
 set_init_handler(arg)
                SV *arg
@@ -1424,3 +1442,11 @@ ScanPartial()
                RETVAL
 
  
+void
+yazlog(arg)
+               SV *arg
+       CODE:
+               STRLEN len;
+               char *ptr;
+               ptr = SvPV(arg, len);
+               yaz_log(YLOG_LOG, "%.*s", len, ptr);