From: Wilfried Goesgens Date: Tue, 31 Aug 2010 18:00:13 +0000 (+0200) Subject: Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel X-Git-Tag: v8.01~807 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=84f596cfd831e6f38626c2d23c0cb81bee17e1cb;hp=32db4c337b9af33d964b295cb12b524e396c2e87;p=citadel.git Merge branch 'master' of ssh://git.citadel.org/appl/gitroot/citadel --- diff --git a/citadel/modules/crypto/serv_crypto.c b/citadel/modules/crypto/serv_crypto.c index a5b563239..30309f896 100644 --- a/citadel/modules/crypto/serv_crypto.c +++ b/citadel/modules/crypto/serv_crypto.c @@ -559,39 +559,71 @@ int client_readline_sslbuffer(StrBuf *Line, StrBuf *IOBuf, const char **Pos, int int client_read_sslblob(StrBuf *Target, long bytes, int timeout) { - long bufremain; long baselen; + long RemainRead; int retval = 0; CitContext *CCC = CC; baselen = StrLength(Target); - if (CCC->Pos == NULL) - CCC->Pos = ChrPtr(CCC->ReadBuf); - bufremain = StrLength(CCC->ReadBuf) - - (CCC->Pos - ChrPtr(CCC->ReadBuf)); + if (StrLength(CCC->ReadBuf) > 0) + { + long RemainLen; + long TotalLen; + const char *pchs; + + if (CCC->Pos == NULL) + CCC->Pos = ChrPtr(CCC->ReadBuf); + pchs = ChrPtr(CCC->ReadBuf); + TotalLen = StrLength(CCC->ReadBuf); + RemainLen = TotalLen - (pchs - CCC->Pos); + if (RemainLen > bytes) + RemainLen = bytes; + if (RemainLen > 0) + { + StrBufAppendBufPlain(Target, + CCC->Pos, + RemainLen, 0); + CCC->Pos += RemainLen; + } + if ((ChrPtr(CCC->ReadBuf) + StrLength(CCC->ReadBuf)) <= CCC->Pos) + { + CCC->Pos = NULL; + FlushStrBuf(CCC->ReadBuf); + } + } + + if (StrLength(Target) >= bytes + baselen) + return 1; - if (bytes < bufremain) - bufremain = bytes; - StrBufAppendBufPlain(Target, CCC->Pos, bufremain, 0); - StrBufCutLeft(CCC->ReadBuf, bufremain); CCC->Pos = NULL; - if (bytes > bufremain) + while ((StrLength(Target) < bytes + baselen) && + (retval >= 0)) { - while ((StrLength(CCC->ReadBuf) + StrLength(Target) < bytes + baselen) && - (retval >= 0)) - retval = client_read_sslbuffer(CCC->ReadBuf, timeout); + retval = client_read_sslbuffer(CCC->ReadBuf, timeout); if (retval >= 0) { + RemainRead = bytes - (StrLength (Target) - baselen); + if (RemainRead > StrLength(CCC->ReadBuf)) + { + StrBufAppendBufPlain( + Target, + ChrPtr(CCC->ReadBuf), + RemainRead, 0); + CCC->Pos = ChrPtr(CCC->ReadBuf) + RemainRead; + break; + } StrBufAppendBuf(Target, CCC->ReadBuf, 0); /* todo: Buf > bytes? */ - return 1; + FlushStrBuf(CCC->ReadBuf); } - else { + else + { + FlushStrBuf(CCC->ReadBuf); return -1; + } } - else - return 1; + return 1; }