Removed the comments about RMS being an asshole communist. I don't want anyone to...
[citadel.git] / webcit-ng / ctdlclient.c
index 0a5e1fbcd47492b64781f24f7d12c93fc775c1e2..ddbc0926a7a294f1688ccdc0a116134dc8e8ff48 100644 (file)
@@ -1,16 +1,17 @@
-/*
- * Functions that handle communication with a Citadel Server
- *
- * Copyright (c) 1987-2018 by the citadel.org team
- *
- * This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 3.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- */
+//
+// Functions that handle communication with a Citadel Server
+//
+// Copyright (c) 1987-2018 by the citadel.org team
+//
+// This program is open source software.  It runs great on the
+// Linux operating system (and probably elsewhere).  You can use,
+// copy, and run it under the terms of the GNU General Public
+// License version 3.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+// GNU General Public License for more details.
 
 #include "webcit.h"
 
@@ -18,9 +19,29 @@ struct ctdlsession *cpool = NULL;                            // linked list of connections to the Citade
 pthread_mutex_t cpool_mutex = PTHREAD_MUTEX_INITIALIZER;       // Lock it before modifying
 
 
+/*
+ * Read a specific number of bytes of binary data from the Citadel server.
+ * Returns the number of bytes read or -1 for error.
+ */
+int ctdl_read_binary(struct ctdlsession *ctdl, char *buf, int bytes_requested)
+{
+       int bytes_read = 0;
+       int c = 0;
+
+       while (bytes_read < bytes_requested) {
+               c = read(ctdl->sock, &buf[bytes_read], bytes_requested-bytes_read);
+               if (c <= 0) {
+                       syslog(LOG_DEBUG, "Socket error or zero-length read");
+                       return (-1);
+               }
+               bytes_read += c;
+       }
+       return (bytes_read);
+}
+
+
 /*
  * Read a newline-terminated line of text from the Citadel server.
- * Implemented in terms of client_read() and is therefore transparent...
  * Returns the string length or -1 for error.
  */
 int ctdl_readline(struct ctdlsession *ctdl, char *buf, int maxbytes)