X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=libcitadel%2Flib%2Fstringbuf.c;h=082cd7046854db4fe69935c1a692ddff700de2b6;hb=2528cd97b30089b196615adb7ec94777245bad6f;hp=55daf6192c57b9127e1735b71a947ea9772804dd;hpb=f1e86bdcc55adbd5bc7af04ccf64af01674ea64c;p=citadel.git diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 55daf6192..082cd7046 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -2125,6 +2125,7 @@ long StrECMAEscAppend(StrBuf *Target, const StrBuf *Source, const char *PlainIn) const char *aptr, *eiptr; char *bptr, *eptr; long len; + int IsUtf8Sequence; if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) ) return -1; @@ -2663,6 +2664,8 @@ int StrBufRFC2047encode(StrBuf **target, const StrBuf *source) (ch > 126) || (ch == 61) || (ch == '=') || + (ch == '?') || + (ch == '_') || (ch == '[') || (ch == ']') ) { @@ -2670,7 +2673,10 @@ int StrBufRFC2047encode(StrBuf **target, const StrBuf *source) (*target)->BufUsed += 3; } else { - (*target)->buf[(*target)->BufUsed] = ch; + if (ch == ' ') + (*target)->buf[(*target)->BufUsed] = '_'; + else + (*target)->buf[(*target)->BufUsed] = ch; (*target)->BufUsed++; } } @@ -3315,7 +3321,7 @@ static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *Char int n = 0; unsigned char test = (1<<7); - if ((*CharS & 0xC0) == 0) + if ((*CharS & 0xC0) != 0xC0) return 1; while ((n < 8) && @@ -3338,7 +3344,7 @@ static inline int Ctdl_GetUtf8SequenceLength(const char *CharS, const char *Char static inline int Ctdl_IsUtf8SequenceStart(const char Char) { /** 11??.???? indicates an UTF8 Sequence. */ - return ((Char & 0xC0) != 0); + return ((Char & 0xC0) == 0xC0); } /** @@ -3699,7 +3705,18 @@ eReadState StrBufChunkSipLine(StrBuf *LineBuf, IOBuffer *FB) optr --; if ((*(ptr - 1) != '\r') && (*(ptr - 1) != '\n')) { LineBuf->BufUsed = optr - LineBuf->buf; - *optr = '\0'; + *optr = '\0'; + if ((FB->ReadWritePointer != NULL) && + (FB->ReadWritePointer != FB->Buf->buf)) + { + /* Ok, the client application read all the data + it was interested in so far. Since there is more to read, + we now shrink the buffer, and move the rest over. + */ + StrBufCutLeft(FB->Buf, + FB->ReadWritePointer - FB->Buf->buf); + FB->ReadWritePointer = FB->Buf->buf; + } return eMustReadMore; } }