+ return (-1);
+ }
+ StrBufAppendBufPlain(buf, sbuf, rlen, 0);
+ return rlen;
+ }
+ return (0);
+}
+
+int client_readline_sslbuffer(StrBuf *Line, StrBuf *IOBuf, const char **Pos, int timeout)
+{
+ CitContext *CCC = CC;
+ const char *pos = NULL;
+ const char *pLF;
+ int len, rlen;
+ int nSuccessLess = 0;
+ const char *pch = NULL;
+
+ if ((Line == NULL) ||
+ (Pos == NULL) ||
+ (IOBuf == NULL))
+ {
+ if (Pos != NULL)
+ *Pos = NULL;
+// *Error = ErrRBLF_PreConditionFailed;
+ return -1;
+ }
+
+ pos = *Pos;
+ if ((StrLength(IOBuf) > 0) &&
+ (pos != NULL) &&
+ (pos < ChrPtr(IOBuf) + StrLength(IOBuf)))
+ {
+ pch = pos;
+ pch = strchr(pch, '\n');
+
+ if (pch == NULL) {
+ StrBufAppendBufPlain(Line, pos,
+ StrLength(IOBuf) - (pos - ChrPtr(IOBuf)), 0);
+ FlushStrBuf(IOBuf);
+ pos = *Pos = NULL;
+ }
+ else {
+ int n = 0;
+ if ((pch > ChrPtr(IOBuf)) &&
+ (*(pch - 1) == '\r')) {
+ n = 1;
+ }
+ StrBufAppendBufPlain(Line, pos,
+ (pch - pos - n), 0);
+
+ if (StrLength(IOBuf) <= (pch - ChrPtr(IOBuf) + 1)) {
+ FlushStrBuf(IOBuf);
+ pos = *Pos = NULL;
+ }
+ else
+ *Pos = pch + 1;
+ return StrLength(Line);
+ }
+ }
+
+ pLF = NULL;
+ while ((nSuccessLess < timeout) &&
+ (pLF == NULL) &&
+ (CCC->ssl != NULL)) {
+
+ rlen = client_read_sslbuffer(IOBuf, timeout);
+ if (rlen < 1) {
+// *Error = strerror(errno);
+// close(*fd);
+// *fd = -1;
+ return -1;
+ }
+ else if (rlen > 0) {
+ pLF = strchr(ChrPtr(IOBuf), '\n');
+ }
+ }
+ *Pos = NULL;
+ if (pLF != NULL) {
+ pos = ChrPtr(IOBuf);
+ len = pLF - pos;
+ if (len > 0 && (*(pLF - 1) == '\r') )
+ len --;
+ StrBufAppendBufPlain(Line, pos, len, 0);
+ if (pLF + 1 >= ChrPtr(IOBuf) + StrLength(IOBuf))
+ {
+ FlushStrBuf(IOBuf);
+ }
+ else
+ *Pos = pLF + 1;
+ return StrLength(Line);
+ }
+// *Error = ErrRBLF_NotEnoughSentFromServer;
+ return -1;
+}
+
+
+
+int client_read_sslblob(StrBuf *Target, long bytes, int timeout)
+{
+ long baselen;
+ long RemainRead;
+ int retval = 0;
+ CitContext *CCC = CC;
+
+ baselen = StrLength(Target);
+
+ if (StrLength(CCC->RecvBuf.Buf) > 0)
+ {
+ long RemainLen;
+ long TotalLen;
+ const char *pchs;
+
+ if (CCC->RecvBuf.ReadWritePointer == NULL)
+ CCC->RecvBuf.ReadWritePointer = ChrPtr(CCC->RecvBuf.Buf);
+ pchs = ChrPtr(CCC->RecvBuf.Buf);
+ TotalLen = StrLength(CCC->RecvBuf.Buf);
+ RemainLen = TotalLen - (pchs - CCC->RecvBuf.ReadWritePointer);
+ if (RemainLen > bytes)
+ RemainLen = bytes;
+ if (RemainLen > 0)
+ {
+ StrBufAppendBufPlain(Target,
+ CCC->RecvBuf.ReadWritePointer,
+ RemainLen, 0);
+ CCC->RecvBuf.ReadWritePointer += RemainLen;
+ }
+ if ((ChrPtr(CCC->RecvBuf.Buf) + StrLength(CCC->RecvBuf.Buf)) <= CCC->RecvBuf.ReadWritePointer)
+ {
+ CCC->RecvBuf.ReadWritePointer = NULL;
+ FlushStrBuf(CCC->RecvBuf.Buf);
+ }
+ }
+
+ if (StrLength(Target) >= bytes + baselen)
+ return 1;
+
+ CCC->RecvBuf.ReadWritePointer = NULL;
+
+ while ((StrLength(Target) < bytes + baselen) &&
+ (retval >= 0))
+ {
+ retval = client_read_sslbuffer(CCC->RecvBuf.Buf, timeout);
+ if (retval >= 0) {
+ RemainRead = bytes - (StrLength (Target) - baselen);
+ if (RemainRead < StrLength(CCC->RecvBuf.Buf))
+ {
+ StrBufAppendBufPlain(
+ Target,
+ ChrPtr(CCC->RecvBuf.Buf),
+ RemainRead, 0);
+ CCC->RecvBuf.ReadWritePointer = ChrPtr(CCC->RecvBuf.Buf) + RemainRead;
+ break;
+ }
+ StrBufAppendBuf(Target, CCC->RecvBuf.Buf, 0); /* todo: Buf > bytes? */
+ FlushStrBuf(CCC->RecvBuf.Buf);
+ }
+ else
+ {
+ FlushStrBuf(CCC->RecvBuf.Buf);
+ return -1;
+