More type casts. Modify CQL tree - bool is C++ reserved name.
[yaz-moved-to-github.git] / comstack / comstack.c
1 /*
2  * Copyright (c) 1995-2003, Index Data
3  * See the file LICENSE for details.
4  *
5  * $Id: comstack.c,v 1.11 2003-02-14 18:49:23 adam Exp $
6  */
7
8 #include <string.h>
9 #include <yaz/comstack.h>
10 #include <yaz/tcpip.h>
11 #include <yaz/unix.h>
12
13 static const char *cs_errlist[] =
14 {
15     "No error or unspecified error",
16     "System (lower-layer) error",
17     "Operation out of state",
18     "No data (operation would block)",
19     "New data while half of old buffer is on the line (flow control)",
20     "Permission denied",
21     "SSL error"
22 };
23
24 const char *cs_errmsg(int n)
25 {
26     if (n < 0 || n > 6)
27         n = 0;
28     return cs_errlist[n];
29 }
30
31 const char *cs_strerror(COMSTACK h)
32 {
33     return cs_errmsg(h->cerrno);
34 }
35
36 COMSTACK cs_create_host(const char *type_and_host, int blocking, void **vp)
37 {
38     const char *host = 0;
39     COMSTACK cs;
40     CS_TYPE t;
41
42     if (strncmp (type_and_host, "tcp:", 4) == 0)
43     {
44         t = tcpip_type;
45         host = type_and_host + 4;
46     }
47     else if (strncmp (type_and_host, "ssl:", 4) == 0)
48     {
49 #if HAVE_OPENSSL_SSL_H
50         t = ssl_type;
51         host = type_and_host + 4;
52 #else
53         return 0;
54 #endif
55     }
56     else if (strncmp (type_and_host, "unix:", 5) == 0)
57     {
58 #ifndef WIN32
59         t = unix_type;
60         host = type_and_host + 5;
61 #else
62         return 0;
63 #endif
64     }
65     else
66     {
67         t = tcpip_type;
68         host = type_and_host;
69
70     }
71     cs = cs_create (t, blocking, PROTO_Z3950);
72     if (!cs)
73         return 0;
74
75     if (!(*vp = cs_straddr(cs, host)))
76     {
77         cs_close (cs);
78         return 0;
79     }    
80     return cs;
81 }
82
83 int cs_look (COMSTACK cs)
84 {
85     return cs->event;
86 }