*
*/
+#ifdef DLL_EXPORT
+#define IN_LIBCIT
+#endif
+
#include "sysdep.h"
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <stdarg.h>
#include "citadel.h"
+#include "server.h"
+#include "dynloader.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
return(-1);
}
-/* FIX ... the alarm clock is a problem for multithreaded programs because all
- * threads receive the signal.
- signal(SIGALRM, timeout);
- alarm(30);
- */
-
if (connect(s, (struct sockaddr *) &sin, sizeof(sin)) < 0) {
lprintf(3, "can't connect to %s.%s: %s\n",
host, service, strerror(errno));
return(-1);
}
-/*
- alarm(0);
- signal(SIGALRM, SIG_IGN);
- */
return (s);
}
}
+
/*
* Input string from socket - implemented in terms of sock_read()
*
*/
for (i = 0;; i++) {
if (sock_read(sock, &buf[i], 1) < 0) return(-1);
- if (buf[i] == '\n' || i == 255)
+ if (buf[i] == '\n' || i == (SIZ-1))
break;
}
/* If we got a long line, discard characters until the newline.
*/
- if (i == 255)
+ if (i == (SIZ-1))
while (buf[i] != '\n')
if (sock_read(sock, &buf[i], 1) < 0) return(-1);
return(strlen(buf));
}
+/*
+ * Multiline version of sock_gets() ... this is a convenience function for
+ * client side protocol implementations. It only returns the first line of
+ * a multiline response, discarding the rest.
+ */
+int ml_sock_gets(int sock, char *buf) {
+ char bigbuf[1024];
+ int g;
+
+ g = sock_gets(sock, buf);
+ if (g < 4) return(g);
+ if (buf[3] != '-') return(g);
+
+ do {
+ g = sock_gets(sock, bigbuf);
+ if (g < 0) return(g);
+ } while ( (g >= 4) && (bigbuf[3] == '-') );
+
+ return(strlen(buf));
+}
+
/*
* sock_puts() - send line to server - implemented in terms of serv_write()
if (j<0) return(j);
return(i+j);
}
+
+
+/*
+ * sock_puts_crlf() - same as sock_puts() but ends line with CRLF, not LF
+ * Returns the number of bytes written, or -1 for error.
+ */
+int sock_puts_crlf(int sock, char *buf)
+{
+ int i, j;
+
+ i = sock_write(sock, buf, strlen(buf));
+ if (i<0) return(i);
+ j = sock_write(sock, "\r\n", 2);
+ if (j<0) return(j);
+ return(i+j);
+}