ZOOM_record_get: xml returns MARC XML instead of OAI MARC
[yaz-moved-to-github.git] / comstack / comstack.c
index f1892ea..121d143 100644 (file)
@@ -1,10 +1,24 @@
 /*
 /*
- * Copyright (c) 1995-1998, Index Data
+ * Copyright (c) 1995-2001, Index Data
  * See the file LICENSE for details.
  * See the file LICENSE for details.
- * Sebastian Hammer, Adam Dickmeiss
  *
  * $Log: comstack.c,v $
  *
  * $Log: comstack.c,v $
- * Revision 1.5  1998-06-22 11:32:35  adam
+ * Revision 1.10  2002-06-04 11:36:10  adam
+ * New COMSTACK: UNIX socket
+ *
+ * Revision 1.9  2001/10/22 13:57:24  adam
+ * Implemented cs_rcvconnect and cs_look as described in the documentation.
+ *
+ * Revision 1.8  2001/07/19 19:49:02  adam
+ * Added include of string.h.
+ *
+ * Revision 1.7  2001/03/21 12:43:36  adam
+ * Implemented cs_create_host. Better error reporting for SSL comstack.
+ *
+ * Revision 1.6  1999/11/30 13:47:11  adam
+ * Improved installation. Moved header files to include/yaz.
+ *
+ * Revision 1.5  1998/06/22 11:32:35  adam
  * Added 'conditional cs_listen' feature.
  *
  * Revision 1.4  1997/09/29 07:16:14  adam
  * Added 'conditional cs_listen' feature.
  *
  * Revision 1.4  1997/09/29 07:16:14  adam
  *
  */
 
  *
  */
 
-#include <comstack.h>
+#include <string.h>
+#include <yaz/comstack.h>
+#include <yaz/tcpip.h>
+#include <yaz/unix.h>
 
 static const char *cs_errlist[] =
 {
 
 static const char *cs_errlist[] =
 {
@@ -37,10 +54,70 @@ static const char *cs_errlist[] =
     "Operation out of state",
     "No data (operation would block)",
     "New data while half of old buffer is on the line (flow control)",
     "Operation out of state",
     "No data (operation would block)",
     "New data while half of old buffer is on the line (flow control)",
-    "Permission denied"
+    "Permission denied",
+    "SSL error"
 };
 
 const char *cs_errmsg(int n)
 {
 };
 
 const char *cs_errmsg(int n)
 {
+    if (n < 0 || n > 6)
+       n = 0;
     return cs_errlist[n];
 }
     return cs_errlist[n];
 }
+
+const char *cs_strerror(COMSTACK h)
+{
+    return cs_errmsg(h->cerrno);
+}
+
+COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp)
+{
+    const char *host = 0;
+    COMSTACK cs;
+    CS_TYPE t;
+
+    if (strncmp (type_and_host, "tcp:", 4) == 0)
+    {
+       t = tcpip_type;
+        host = type_and_host + 4;
+    }
+    else if (strncmp (type_and_host, "ssl:", 4) == 0)
+    {
+#if HAVE_OPENSSL_SSL_H
+       t = ssl_type;
+        host = type_and_host + 4;
+#else
+       return 0;
+#endif
+    }
+    else if (strncmp (type_and_host, "unix:", 5) == 0)
+    {
+#ifndef WIN32
+       t = unix_type;
+        host = type_and_host + 5;
+#else
+       return 0;
+#endif
+    }
+    else
+    {
+       t = tcpip_type;
+       host = type_and_host;
+
+    }
+    cs = cs_create (t, blocking, PROTO_Z3950);
+    if (!cs)
+       return 0;
+
+    if (!(*vp = cs_straddr(cs, host)))
+    {
+       cs_close (cs);
+       return 0;
+    }    
+    return cs;
+}
+
+int cs_look (COMSTACK cs)
+{
+    return cs->event;
+}