* 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
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;
}
* 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
*/
#include <yaz/comstack.h>
+#include <yaz/tcpip.h>
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;
+}
* 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
return 1;
}
#endif
+ h->cerrno = CSYSERR;
return -1;
}
h->state = CS_CONNECTING;
h->io_pending = CS_WANT_WRITE;
return 1;
}
+ h->cerrno = CSERRORSSL;
return -1;
}
}
}
if (res == 0)
return 0;
+ h->cerrno = CSERRORSSL;
return -1;
}
hasread += res;
yaz_log (LOG_LOG, "SSL_write. want_write");
return 1;
}
+ h->cerrno = CSERRORSSL;
return -1;
}
state->written += res;
-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
* 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
#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.
#define CSNODATA 3
#define CSWRONGBUF 4
#define CSDENY 5
+#define CSERRORSSL 6
/* backwards compatibility */
#define CS_SR PROTO_SR
* 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
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')':'<address>",
- 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)