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