+
+
+
+/**
+ * Read binary data from server into memory using a series of
+ * server READ commands.
+ * \return the read content as StrBuf
+ */
+int read_server_binary(StrBuf *Ret, size_t total_len)
+{
+ char buf[SIZ];
+ size_t bytes = 0;
+ size_t thisblock = 0;
+ StrBuf *Buf;
+
+ Buf = NewStrBuf();
+ if (Ret == NULL)
+ return -1;
+
+ while (bytes < total_len) {
+ thisblock = 4095;
+ if ((total_len - bytes) < thisblock) {
+ thisblock = total_len - bytes;
+ if (thisblock == 0) {
+ FlushStrBuf(Ret);
+ FreeStrBuf(&Buf);
+ return -1;
+ }
+ }
+ serv_printf("READ %d|%d", (int)bytes, (int)thisblock);
+ if (StrBuf_ServGetln(Buf) > 0)
+ {
+ if (ChrPtr(Buf)[0] == '6')
+ {
+ StrBufCutLeft(Buf, 4); //thisblock = (size_t)atoi(&buf[4]);
+ thisblock = StrTol(Buf);
+ if (!WC->connected) {
+ FlushStrBuf(Ret);
+ FreeStrBuf(&Buf);
+ return -1;
+ }
+ StrBuf_ServGetBLOB(Ret, thisblock);
+ bytes += thisblock;
+ }
+ else {
+ FreeStrBuf(&Buf);
+ lprintf(3, "Error: %s\n", &buf[4]);
+ return -1;
+ }
+ }
+ }
+ FreeStrBuf(&Buf);
+ return StrLength(Ret);
+}
+
+
+/**
+ * Read text from server, appending to a string buffer until the
+ * usual 000 terminator is found. Caller is responsible for freeing
+ * the returned pointer.
+ */
+int read_server_text(StrBuf *Buf, long *nLines)
+{
+ struct wcsession *WCC = WC;
+ long nRead;
+ long nTotal = 0;
+ long nlines;
+
+ nlines = 0;
+ while ((WCC->serv_sock!=-1) &&
+ (nRead = StrBuf_ServGetln(Buf), (nRead >= 0) ))
+ {
+ if (strcmp(ChrPtr(Buf) + nTotal, "000") != 0) {
+ StrBufCutRight(Buf, nRead);
+ break;
+ }
+ nTotal += nRead;
+ nlines ++;
+ }
+
+ *nLines = nlines;
+ return nTotal;
+}
+
+
+int GetServerStatus(StrBuf *Line, long* FullState)
+{
+ if (FullState != NULL)
+ *FullState = StrTol(Line);
+ return ChrPtr(Line)[0] - 48;
+}
+
+/*@}*/