ZOOM_record_get: xml returns MARC XML instead of OAI MARC
[yaz-moved-to-github.git] / comstack / comstack.c
1 /*
2  * Copyright (c) 1995-2001, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Log: comstack.c,v $
6  * Revision 1.10  2002-06-04 11:36:10  adam
7  * New COMSTACK: UNIX socket
8  *
9  * Revision 1.9  2001/10/22 13:57:24  adam
10  * Implemented cs_rcvconnect and cs_look as described in the documentation.
11  *
12  * Revision 1.8  2001/07/19 19:49:02  adam
13  * Added include of string.h.
14  *
15  * Revision 1.7  2001/03/21 12:43:36  adam
16  * Implemented cs_create_host. Better error reporting for SSL comstack.
17  *
18  * Revision 1.6  1999/11/30 13:47:11  adam
19  * Improved installation. Moved header files to include/yaz.
20  *
21  * Revision 1.5  1998/06/22 11:32:35  adam
22  * Added 'conditional cs_listen' feature.
23  *
24  * Revision 1.4  1997/09/29 07:16:14  adam
25  * Array cs_errlist no longer global.
26  *
27  * Revision 1.3  1997/09/01 08:49:14  adam
28  * New windows NT/95 port using MSV5.0. Minor changes only.
29  *
30  * Revision 1.2  1995/09/29 17:01:48  quinn
31  * More Windows work
32  *
33  * Revision 1.1  1995/06/14  09:58:20  quinn
34  * Renamed yazlib to comstack.
35  *
36  * Revision 1.2  1995/05/16  08:51:15  quinn
37  * License, documentation, and memory fixes
38  *
39  * Revision 1.1  1995/03/14  10:28:34  quinn
40  * Adding server-side support to tcpip.c and fixing bugs in nonblocking I/O
41  *
42  *
43  */
44
45 #include <string.h>
46 #include <yaz/comstack.h>
47 #include <yaz/tcpip.h>
48 #include <yaz/unix.h>
49
50 static const char *cs_errlist[] =
51 {
52     "No error or unspecified error",
53     "System (lower-layer) error",
54     "Operation out of state",
55     "No data (operation would block)",
56     "New data while half of old buffer is on the line (flow control)",
57     "Permission denied",
58     "SSL error"
59 };
60
61 const char *cs_errmsg(int n)
62 {
63     if (n < 0 || n > 6)
64         n = 0;
65     return cs_errlist[n];
66 }
67
68 const char *cs_strerror(COMSTACK h)
69 {
70     return cs_errmsg(h->cerrno);
71 }
72
73 COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp)
74 {
75     const char *host = 0;
76     COMSTACK cs;
77     CS_TYPE t;
78
79     if (strncmp (type_and_host, "tcp:", 4) == 0)
80     {
81         t = tcpip_type;
82         host = type_and_host + 4;
83     }
84     else if (strncmp (type_and_host, "ssl:", 4) == 0)
85     {
86 #if HAVE_OPENSSL_SSL_H
87         t = ssl_type;
88         host = type_and_host + 4;
89 #else
90         return 0;
91 #endif
92     }
93     else if (strncmp (type_and_host, "unix:", 5) == 0)
94     {
95 #ifndef WIN32
96         t = unix_type;
97         host = type_and_host + 5;
98 #else
99         return 0;
100 #endif
101     }
102     else
103     {
104         t = tcpip_type;
105         host = type_and_host;
106
107     }
108     cs = cs_create (t, blocking, PROTO_Z3950);
109     if (!cs)
110         return 0;
111
112     if (!(*vp = cs_straddr(cs, host)))
113     {
114         cs_close (cs);
115         return 0;
116     }    
117     return cs;
118 }
119
120 int cs_look (COMSTACK cs)
121 {
122     return cs->event;
123 }