]> code.citadel.org Git - citadel.git/blobdiff - webcit/tcp_sockets.c
* make server_getln return the number of bytes it read
[citadel.git] / webcit / tcp_sockets.c
index dfd62befbace686bd4bb4b49c808ccbce0309176..d03672eacc7edebde02b9d1b1e3b66d67af17d79 100644 (file)
@@ -3,7 +3,7 @@
  */
 /** 
  * \defgroup TcpSockets TCP client socket module for WebCit
- *
+ * \ingroup CitadelCommunitacion
  */
 /*@{*/
 
@@ -133,6 +133,7 @@ void serv_read(char *buf, int bytes)
                if (rlen < 1) {
                        lprintf(1, "Server connection broken: %s\n",
                                strerror(errno));
+                       wc_backtrace();
                        close(WC->serv_sock);
                        WC->serv_sock = (-1);
                        WC->connected = 0;
@@ -148,7 +149,7 @@ void serv_read(char *buf, int bytes)
 /**
  * \brief input string from pipe
  */
-void serv_getln(char *strbuf, int bufsize)
+int serv_getln(char *strbuf, int bufsize)
 {
        int ch, len;
        char buf[2];
@@ -158,13 +159,15 @@ void serv_getln(char *strbuf, int bufsize)
        do {
                serv_read(&buf[0], 1);
                ch = buf[0];
-               strbuf[len++] = ch;
+               if ((ch != 13) && (ch != 10)) {
+                       strbuf[len++] = ch;
+               }
        } while ((ch != 10) && (ch != 0) && (len < (bufsize-1)));
-       if (strbuf[len-1] == 10) strbuf[--len] = 0;
-       if (strbuf[len-1] == 13) strbuf[--len] = 0;
+       strbuf[len] = 0;
 #ifdef SERV_TRACE
        lprintf(9, "%3d>%s\n", WC->serv_sock, strbuf);
 #endif
+       return len;
 }
 
 
@@ -201,13 +204,11 @@ void serv_write(char *buf, int nbytes)
  */
 void serv_puts(char *string)
 {
-       char buf[SIZ];
-
 #ifdef SERV_TRACE
        lprintf(9, "%3d<%s\n", WC->serv_sock, string);
 #endif
-       sprintf(buf, "%s\n", string);
-       serv_write(buf, strlen(buf));
+       serv_write(string, strlen(string));
+       serv_write("\n", 1);
 }
 
 
@@ -220,13 +221,16 @@ void serv_printf(const char *format,...)
 {
        va_list arg_ptr;
        char buf[SIZ];
+       size_t len;
 
        va_start(arg_ptr, format);
        vsnprintf(buf, sizeof buf, format, arg_ptr);
        va_end(arg_ptr);
 
-       strcat(buf, "\n");
-       serv_write(buf, strlen(buf));
+       len = strlen(buf);
+       buf[len++] = '\n';
+       buf[len] = '\0';
+       serv_write(buf, len);
 #ifdef SERV_TRACE
        lprintf(9, "<%s", buf);
 #endif