From: Adam Dickmeiss Date: Wed, 21 Mar 2001 12:43:36 +0000 (+0000) Subject: Implemented cs_create_host. Better error reporting for SSL comstack. X-Git-Tag: YAZ.1.8~108 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=cfef2a68b0e7da6c2a3b47e44df9965d63156584 Implemented cs_create_host. Better error reporting for SSL comstack. --- diff --git a/client/client.c b/client/client.c index a7f9f54..89e8039 100644 --- a/client/client.c +++ b/client/client.c @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: client.c,v $ - * Revision 1.115 2001-03-13 18:10:58 adam + * Revision 1.116 2001-03-21 12:43:36 adam + * Implemented cs_create_host. Better error reporting for SSL comstack. + * + * Revision 1.115 2001/03/13 18:10:58 adam * Added option -c to set CCL config file. * * Revision 1.114 2001/02/21 13:46:53 adam @@ -647,44 +650,28 @@ int cmd_open(char *arg) base[0] = '\0'; if (sscanf (arg, "%100[^/]/%100s", type_and_host, base) < 1) return 0; - if (strncmp (type_and_host, "tcp:", 4) == 0) - host = type_and_host + 4; - else if (strncmp (type_and_host, "ssl:", 4) == 0) - { -#if HAVE_OPENSSL_SSL_H - t = ssl_type; -#else - printf ("SSL not supported\n"); -#endif - host = type_and_host + 4; - } - else - host = type_and_host; - if (*base) - cmd_base (base); - protocol = PROTO_Z3950; - if (!(conn = cs_create(t, 1, protocol))) + conn = cs_create_host(type_and_host, 1, &add); + if (!conn) { - perror("cs_create"); - return 0; - } - if (!(add = cs_straddr(conn, host))) - { - perror(arg); - return 0; + printf ("Couldn't create comstack\n"); + return 0; } printf("Connecting..."); fflush(stdout); if (cs_connect(conn, add) < 0) { - perror("connect"); + printf ("error = %s\n", cs_strerror(conn)); + if (conn->cerrno == CSYSERR) + perror("system"); cs_close(conn); conn = 0; return 0; } printf("Ok.\n"); send_initRequest(); + if (*base) + cmd_base (base); return 2; } diff --git a/comstack/comstack.c b/comstack/comstack.c index 8460316..1027792 100644 --- a/comstack/comstack.c +++ b/comstack/comstack.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: comstack.c,v $ - * Revision 1.6 1999-11-30 13:47:11 adam + * 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 @@ -32,6 +35,7 @@ */ #include +#include static const char *cs_errlist[] = { @@ -40,10 +44,56 @@ 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)", - "Permission denied" + "Permission denied", + "SSL error" }; const char *cs_errmsg(int n) { + if (n < 0 || n > 6) + n = 0; 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 + { + 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; +} diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 6887469..b558c88 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -3,7 +3,10 @@ * See the file LICENSE for details. * * $Log: tcpip.c,v $ - * Revision 1.37 2001-03-08 20:18:55 adam + * Revision 1.38 2001-03-21 12:43:36 adam + * Implemented cs_create_host. Better error reporting for SSL comstack. + * + * Revision 1.37 2001/03/08 20:18:55 adam * Added cs_set_blocking. Patch from Matthew Carey. * * Revision 1.36 2001/02/21 13:46:53 adam @@ -494,6 +497,7 @@ int tcpip_connect(COMSTACK h, void *address) return 1; } #endif + h->cerrno = CSYSERR; return -1; } h->state = CS_CONNECTING; @@ -529,6 +533,7 @@ int tcpip_connect(COMSTACK h, void *address) h->io_pending = CS_WANT_WRITE; return 1; } + h->cerrno = CSERRORSSL; return -1; } } @@ -940,6 +945,7 @@ int ssl_get(COMSTACK h, char **buf, int *bufsize) } if (res == 0) return 0; + h->cerrno = CSERRORSSL; return -1; } hasread += res; @@ -1064,6 +1070,7 @@ int ssl_put(COMSTACK h, char *buf, int size) yaz_log (LOG_LOG, "SSL_write. want_write"); return 1; } + h->cerrno = CSERRORSSL; return -1; } state->written += res; diff --git a/configure.in b/configure.in index 6e888a7..cb53580 100644 --- a/configure.in +++ b/configure.in @@ -1,6 +1,6 @@ -dnl YAZ Toolkit, Index Data 1994-2000 +dnl YAZ Toolkit, Index Data 1994-2001 dnl See the file LICENSE for details. -dnl $Id: configure.in,v 1.41 2001-03-20 15:58:23 adam Exp $ +dnl $Id: configure.in,v 1.42 2001-03-21 12:43:36 adam Exp $ AC_INIT(include/yaz/yaz-version.h) AM_INIT_AUTOMAKE(yaz, 1.7) dnl diff --git a/include/yaz/comstack.h b/include/yaz/comstack.h index 224c8d2..f7a5121 100644 --- a/include/yaz/comstack.h +++ b/include/yaz/comstack.h @@ -23,7 +23,7 @@ * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE * OF THIS SOFTWARE. * - * $Id: comstack.h,v 1.4 2001-03-08 20:18:55 adam Exp $ + * $Id: comstack.h,v 1.5 2001-03-21 12:43:36 adam Exp $ */ #ifndef COMSTACK_H @@ -143,6 +143,8 @@ struct comstack #define CS_WANT_WRITE 2 YAZ_EXPORT const char *cs_strerror(COMSTACK h); YAZ_EXPORT const char *cs_errmsg(int n); +YAZ_EXPORT COMSTACK cs_create_host(const char *type_and_host, + int blocking, void **vp); /* * error management. @@ -154,6 +156,7 @@ YAZ_EXPORT const char *cs_errmsg(int n); #define CSNODATA 3 #define CSWRONGBUF 4 #define CSDENY 5 +#define CSERRORSSL 6 /* backwards compatibility */ #define CS_SR PROTO_SR diff --git a/server/statserv.c b/server/statserv.c index 2af20bf..18382ed 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -7,7 +7,10 @@ * Chas Woodfield, Fretwell Downing Informatics. * * $Log: statserv.c,v $ - * Revision 1.70 2001-02-01 08:52:26 adam + * Revision 1.71 2001-03-21 12:43:36 adam + * Implemented cs_create_host. Better error reporting for SSL comstack. + * + * Revision 1.70 2001/02/01 08:52:26 adam * Fixed bug regarding inetd mode. * * Revision 1.69 2000/12/01 17:56:41 adam @@ -811,47 +814,13 @@ static void inetd_connection(int what) static void add_listener(char *where, int what) { COMSTACK l; - CS_TYPE type; - char mode[100], addr[100]; void *ap; IOCHAN lst = NULL; - if (!where || sscanf(where, "%[^:]:%s", mode, addr) != 2) + l = cs_create_host(where, 0, &ap); + if (!l) { - yaz_log (LOG_WARN, "%s: Address format: ('tcp'|'ssl')':'
", - me); - return; - } - if (!strcmp(mode, "tcp")) - type = tcpip_type; - else if (!strcmp(mode, "ssl")) - { -#if HAVE_OPENSSL_SSL_H - type = ssl_type; -#else - yaz_log (LOG_WARN, "SSL Transport not allowed by configuration."); - return; -#endif - } - else - { - yaz_log (LOG_WARN, "You must specify either 'ssl:' or 'tcp:'"); - return; - } - yaz_log(LOG_LOG, "Adding %s %s listener on %s", - control_block.dynamic ? "dynamic" : - (control_block.threads ? "threaded" : "static"), - what == PROTO_SR ? "SR" : "Z3950", where); - if (!(l = cs_create(type, 0, what))) - { - yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to create listener"); - return; - } - ap = cs_straddr (l, addr); - if (!ap) - { - fprintf(stderr, "Address resolution failed.\n"); - cs_close (l); + yaz_log(LOG_FATAL|LOG_ERRNO, "Failed to listen on %s", where); return; } if (cs_bind(l, ap, CS_SERVER) < 0)