Back to index

libcitadel  8.12
Functions
functions to translate the contents of a buffer
Stringbuffer, A class for manipulating strings with dynamic buffers

these functions translate the content of a buffer into another representation; some are combined Fillers and encoders More...

Collaboration diagram for functions to translate the contents of a buffer:

Functions

void StrBufUrlescAppend (StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
 Escape a string for feeding out as a URL while appending it to a Buffer.
void StrBufUrlescUPAppend (StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
 Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer.
void StrBufHexEscAppend (StrBuf *OutBuf, const StrBuf *In, const unsigned char *PlainIn, long PlainInLen)
 append a string in hex encoding to the buffer
void StrBufHexescAppend (StrBuf *OutBuf, const StrBuf *In, const char *PlainIn)
 append a string in hex encoding to the buffer
long StrEscAppend (StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
 Append a string, escaping characters which have meaning in HTML.
void StrMsgEscAppend (StrBuf *Target, const StrBuf *Source, const char *PlainIn)
 Append a string, escaping characters which have meaning in HTML.
void StrIcalEscAppend (StrBuf *Target, const StrBuf *Source, const char *PlainIn)
 Append a string, escaping characters which have meaning in ICAL.
long StrECMAEscAppend (StrBuf *Target, const StrBuf *Source, const char *PlainIn)
 Append a string, escaping characters which have meaning in JavaScript strings .
long StrHtmlEcmaEscAppend (StrBuf *Target, const StrBuf *Source, const char *PlainIn, int nbsp, int nolinebreaks)
 Append a string, escaping characters which have meaning in HTML + json.
void StrBufEUid_unescapize (StrBuf *target, const StrBuf *source)
 unhide special chars hidden to the HTML escaper
void StrBufEUid_escapize (StrBuf *target, const StrBuf *source)
 hide special chars from the HTML escapers and friends
int StrBufDecodeBase64 (StrBuf *Buf)
 decode a buffer from base 64 encoding; destroys original
int StrBufDecodeHex (StrBuf *Buf)
 decode a buffer from base 64 encoding; destroys original
int StrBufSanitizeAscii (StrBuf *Buf, const char Mute)
 replace all chars >0x20 && < 0x7F with Mute
long StrBufUnescape (StrBuf *Buf, int StripBlanks)
 remove escaped strings from i.e.
int StrBufRFC2047encode (StrBuf **target, const StrBuf *source)
 RFC2047-encode a header field if necessary.
void ctdl_iconv_open (const char *tocode, const char *fromcode, void *pic)
 Wrapper around iconv_open() Our version adds aliases for non-standard Microsoft charsets such as 'MS950', aliasing them to names like 'CP950'.
static const char * FindNextEnd (const StrBuf *Buf, const char *bptr)
 find one chunk of a RFC822 encoded string
void StrBufConvert (StrBuf *ConvertBuf, StrBuf *TmpBuf, void *pic)
 convert one buffer according to the preselected iconv pointer PIC
static void DecodeSegment (StrBuf *Target, const StrBuf *DecodeMe, const char *SegmentStart, const char *SegmentEnd, StrBuf *ConvertBuf, StrBuf *ConvertBuf2, StrBuf *FoundCharset)
 catches one RFC822 encoded segment, and decodes it.
void StrBuf_RFC822_to_Utf8 (StrBuf *Target, const StrBuf *DecodeMe, const StrBuf *DefaultCharset, StrBuf *FoundCharset)
 Handle subjects with RFC2047 encoding such as: [deprecated old syntax!] =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=.
void StrBuf_RFC822_2_Utf8 (StrBuf *Target, const StrBuf *DecodeMe, const StrBuf *DefaultCharset, StrBuf *FoundCharset, StrBuf *ConvertBuf, StrBuf *ConvertBuf2)
 Handle subjects with RFC2047 encoding such as: =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=.
int CompressBuffer (StrBuf *Buf)
 compress the buffer with gzip Attention! If you feed this a Const String, you must maintain the uncompressed buffer yourself!

Detailed Description

these functions translate the content of a buffer into another representation; some are combined Fillers and encoders


Function Documentation

int CompressBuffer ( StrBuf Buf)

compress the buffer with gzip Attention! If you feed this a Const String, you must maintain the uncompressed buffer yourself!

Parameters:
Bufbuffer whose content is to be gzipped

Definition at line 3611 of file stringbuf.c.

{
#ifdef HAVE_ZLIB
       char *compressed_data = NULL;
       size_t compressed_len, bufsize;
       int i = 0;

       bufsize = compressed_len = Buf->BufUsed +  (Buf->BufUsed / 100) + 100;
       compressed_data = malloc(compressed_len);
       
       if (compressed_data == NULL)
              return -1;
       /* Flush some space after the used payload so valgrind shuts up... */
        while ((i < 10) && (Buf->BufUsed + i < Buf->BufSize))
              Buf->buf[Buf->BufUsed + i++] = '\0';
       if (compress_gzip((Bytef *) compressed_data,
                       &compressed_len,
                       (Bytef *) Buf->buf,
                       (uLongf) Buf->BufUsed, Z_BEST_SPEED) == Z_OK) {
              if (!Buf->ConstBuf)
                     free(Buf->buf);
              Buf->buf = compressed_data;
              Buf->BufUsed = compressed_len;
              Buf->BufSize = bufsize;
              /* Flush some space after the used payload so valgrind shuts up... */
              i = 0;
              while ((i < 10) && (Buf->BufUsed + i < Buf->BufSize))
                     Buf->buf[Buf->BufUsed + i++] = '\0';
              return 1;
       } else {
              free(compressed_data);
       }
#endif /* HAVE_ZLIB */
       return 0;
}
void ctdl_iconv_open ( const char *  tocode,
const char *  fromcode,
void *  pic 
)

Wrapper around iconv_open() Our version adds aliases for non-standard Microsoft charsets such as 'MS950', aliasing them to names like 'CP950'.

Parameters:
tocodeTarget encoding
fromcodeSource encoding
picanonimized pointer to iconv struct

Definition at line 3035 of file stringbuf.c.

{
#ifdef HAVE_ICONV
       iconv_t ic = (iconv_t)(-1) ;
       ic = iconv_open(tocode, fromcode);
       if (ic == (iconv_t)(-1) ) {
              char alias_fromcode[64];
              if ( (strlen(fromcode) == 5) && (!strncasecmp(fromcode, "MS", 2)) ) {
                     safestrncpy(alias_fromcode, fromcode, sizeof alias_fromcode);
                     alias_fromcode[0] = 'C';
                     alias_fromcode[1] = 'P';
                     ic = iconv_open(tocode, alias_fromcode);
              }
       }
       *(iconv_t *)pic = ic;
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void DecodeSegment ( StrBuf Target,
const StrBuf DecodeMe,
const char *  SegmentStart,
const char *  SegmentEnd,
StrBuf ConvertBuf,
StrBuf ConvertBuf2,
StrBuf FoundCharset 
) [inline, static]

catches one RFC822 encoded segment, and decodes it.

Parameters:
Targetbuffer to fill with result
DecodeMebuffer with stuff to process
SegmentStartpoints to our current segment in DecodeMe
SegmentEndPoints to the end of our current segment in DecodeMe
ConvertBufWorkbuffer shared between several iterations. Random content; needs to be valid
ConvertBuf2Workbuffer shared between several iterations. Random content; needs to be valid
FoundCharsetCharacterset to default decoding to; if we find another we will overwrite it.

< base64

< quoted-printable

Definition at line 3163 of file stringbuf.c.

{
       StrBuf StaticBuf;
       char charset[128];
       char encoding[16];
#ifdef HAVE_ICONV
       iconv_t ic = (iconv_t)(-1);
#else
       void *ic = NULL;
#endif
       /* Now we handle foreign character sets properly encoded
        * in RFC2047 format.
        */
       StaticBuf.buf = (char*) SegmentStart; /*< it will just be read there... */
       StaticBuf.BufUsed = SegmentEnd - SegmentStart;
       StaticBuf.BufSize = DecodeMe->BufSize - (SegmentStart - DecodeMe->buf);
       extract_token(charset, SegmentStart, 1, '?', sizeof charset);
       if (FoundCharset != NULL) {
              FlushStrBuf(FoundCharset);
              StrBufAppendBufPlain(FoundCharset, charset, -1, 0);
       }
       extract_token(encoding, SegmentStart, 2, '?', sizeof encoding);
       StrBufExtract_token(ConvertBuf, &StaticBuf, 3, '?');
       
       *encoding = toupper(*encoding);
       if (*encoding == 'B') {     
              if (ConvertBuf2->BufSize < ConvertBuf->BufUsed)
                     IncreaseBuf(ConvertBuf2, 0, ConvertBuf->BufUsed);
              ConvertBuf2->BufUsed = CtdlDecodeBase64(ConvertBuf2->buf, 
                                                 ConvertBuf->buf, 
                                                 ConvertBuf->BufUsed);
       }
       else if (*encoding == 'Q') {       
              long pos;
              
              pos = 0;
              while (pos < ConvertBuf->BufUsed)
              {
                     if (ConvertBuf->buf[pos] == '_') 
                            ConvertBuf->buf[pos] = ' ';
                     pos++;
              }
              
              if (ConvertBuf2->BufSize < ConvertBuf->BufUsed)
                     IncreaseBuf(ConvertBuf2, 0, ConvertBuf->BufUsed);

              ConvertBuf2->BufUsed = CtdlDecodeQuotedPrintable(
                     ConvertBuf2->buf, 
                     ConvertBuf->buf,
                     ConvertBuf->BufUsed);
       }
       else {
              StrBufAppendBuf(ConvertBuf2, ConvertBuf, 0);
       }
#ifdef HAVE_ICONV
       ctdl_iconv_open("UTF-8", charset, &ic);
       if (ic != (iconv_t)(-1) ) {        
#endif
              StrBufConvert(ConvertBuf2, ConvertBuf, &ic);
              StrBufAppendBuf(Target, ConvertBuf2, 0);
#ifdef HAVE_ICONV
              iconv_close(ic);
       }
       else {
              StrBufAppendBufPlain(Target, HKEY("(unreadable)"), 0);
       }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

static const char* FindNextEnd ( const StrBuf Buf,
const char *  bptr 
) [inline, static]

find one chunk of a RFC822 encoded string

Parameters:
Bufferwhere to search
bptrwhere to start searching
Returns:
found position, NULL if none.

Definition at line 3061 of file stringbuf.c.

{
       const char * end;
       /* Find the next ?Q? */
       if (Buf->BufUsed - (bptr - Buf->buf)  < 6)
              return NULL;

       end = strchr(bptr + 2, '?');

       if (end == NULL)
              return NULL;

       if ((Buf->BufUsed - (end - Buf->buf) > 3) &&
           (((*(end + 1) == 'B') || (*(end + 1) == 'Q')) ||
            ((*(end + 1) == 'b') || (*(end + 1) == 'q'))) && 
           (*(end + 2) == '?')) {
              /* skip on to the end of the cluster, the next ?= */
              end = strstr(end + 3, "?=");
       }
       else
              /* sort of half valid encoding, try to find an end. */
              end = strstr(bptr, "?=");
       return end;
}

Here is the caller graph for this function:

void StrBuf_RFC822_2_Utf8 ( StrBuf Target,
const StrBuf DecodeMe,
const StrBuf DefaultCharset,
StrBuf FoundCharset,
StrBuf ConvertBuf,
StrBuf ConvertBuf2 
)

Handle subjects with RFC2047 encoding such as: =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=.

Parameters:
Targetwhere to put the decoded string to
DecodeMebuffer with encoded string
DefaultCharsetif we don't find one, which should we use?
FoundCharsetoverrides DefaultCharset if non-empty; If we find a charset inside of the string, put it here for later use where no string might be known.
ConvertBufworkbuffer. feed in, you shouldn't care about its content.
ConvertBuf2workbuffer. feed in, you shouldn't care about its content.

Definition at line 3277 of file stringbuf.c.

{
       StrBuf *DecodedInvalidBuf = NULL;
       const StrBuf *DecodeMee = DecodeMe;
       const char *start, *end, *next, *nextend, *ptr = NULL;
#ifdef HAVE_ICONV
       iconv_t ic = (iconv_t)(-1) ;
#endif
       const char *eptr;
       int passes = 0;
       int i;
       int illegal_non_rfc2047_encoding = 0;


       if (DecodeMe == NULL)
              return;
       /* Sometimes, badly formed messages contain strings which were simply
        *  written out directly in some foreign character set instead of
        *  using RFC2047 encoding.  This is illegal but we will attempt to
        *  handle it anyway by converting from a user-specified default
        *  charset to UTF-8 if we see any nonprintable characters.
        */
       
       for (i=0; i<DecodeMe->BufUsed; ++i) {
              if ((DecodeMe->buf[i] < 32) || (DecodeMe->buf[i] > 126)) {
                     illegal_non_rfc2047_encoding = 1;
                     break;
              }
       }

       if ((illegal_non_rfc2047_encoding) &&
           (strcasecmp(ChrPtr(DefaultCharset), "UTF-8")) && 
           (strcasecmp(ChrPtr(DefaultCharset), "us-ascii")) )
       {
#ifdef HAVE_ICONV
              ctdl_iconv_open("UTF-8", ChrPtr(DefaultCharset), &ic);
              if (ic != (iconv_t)(-1) ) {
                     DecodedInvalidBuf = NewStrBufDup(DecodeMe);
                     StrBufConvert(DecodedInvalidBuf, ConvertBuf, &ic);
                     DecodeMee = DecodedInvalidBuf;
                     iconv_close(ic);
              }
#endif
       }

       /* pre evaluate the first pair */
       end = NULL;
       start = strstr(DecodeMee->buf, "=?");
       eptr = DecodeMee->buf + DecodeMee->BufUsed;
       if (start != NULL) 
              end = FindNextEnd (DecodeMee, start + 2);
       else {
              StrBufAppendBuf(Target, DecodeMee, 0);
              FreeStrBuf(&DecodedInvalidBuf);
              return;
       }


       if (start != DecodeMee->buf) {
              long nFront;
              
              nFront = start - DecodeMee->buf;
              StrBufAppendBufPlain(Target, DecodeMee->buf, nFront, 0);
       }
       /*
        * Since spammers will go to all sorts of absurd lengths to get their
        * messages through, there are LOTS of corrupt headers out there.
        * So, prevent a really badly formed RFC2047 header from throwing
        * this function into an infinite loop.
        */
       while ((start != NULL) && 
              (end != NULL) && 
              (start < eptr) && 
              (end < eptr) && 
              (passes < 20))
       {
              passes++;
              DecodeSegment(Target, 
                           DecodeMee, 
                           start, 
                           end, 
                           ConvertBuf,
                           ConvertBuf2,
                           FoundCharset);
              
              next = strstr(end, "=?");
              nextend = NULL;
              if ((next != NULL) && 
                  (next < eptr))
                     nextend = FindNextEnd(DecodeMee, next);
              if (nextend == NULL)
                     next = NULL;

              /* did we find two partitions */
              if ((next != NULL) && 
                  ((next - end) > 2))
              {
                     ptr = end + 2;
                     while ((ptr < next) && 
                            (isspace(*ptr) ||
                            (*ptr == '\r') ||
                            (*ptr == '\n') || 
                            (*ptr == '\t')))
                            ptr ++;
                     /* 
                      * did we find a gab just filled with blanks?
                      * if not, copy its stuff over.
                      */
                     if (ptr != next)
                     {
                            StrBufAppendBufPlain(Target, 
                                               end + 2, 
                                               next - end - 2,
                                               0);
                     }
              }
              /* our next-pair is our new first pair now. */
              ptr = end + 2;
              start = next;
              end = nextend;
       }
       end = ptr;
       nextend = DecodeMee->buf + DecodeMee->BufUsed;
       if ((end != NULL) && (end < nextend)) {
              ptr = end;
              while ( (ptr < nextend) &&
                     (isspace(*ptr) ||
                      (*ptr == '\r') ||
                      (*ptr == '\n') || 
                      (*ptr == '\t')))
                     ptr ++;
              if (ptr < nextend)
                     StrBufAppendBufPlain(Target, end, nextend - end, 0);
       }
       FreeStrBuf(&DecodedInvalidBuf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBuf_RFC822_to_Utf8 ( StrBuf Target,
const StrBuf DecodeMe,
const StrBuf DefaultCharset,
StrBuf FoundCharset 
)

Handle subjects with RFC2047 encoding such as: [deprecated old syntax!] =?koi8-r?B?78bP0s3Mxc7JxSDXz9rE1dvO2c3JINvB0sHNySDP?=.

Parameters:
Targetwhere to put the decoded string to
DecodeMebuffer with encoded string
DefaultCharsetif we don't find one, which should we use?
FoundCharsetoverrides DefaultCharset if non-empty; If we find a charset inside of the string, put it here for later use where no string might be known.

Definition at line 3248 of file stringbuf.c.

{
       StrBuf *ConvertBuf;
       StrBuf *ConvertBuf2;
       ConvertBuf = NewStrBufPlain(NULL, StrLength(DecodeMe));
       ConvertBuf2 = NewStrBufPlain(NULL, StrLength(DecodeMe));
       
       StrBuf_RFC822_2_Utf8(Target, 
                          DecodeMe, 
                          DefaultCharset, 
                          FoundCharset, 
                          ConvertBuf, 
                          ConvertBuf2);
       FreeStrBuf(&ConvertBuf);
       FreeStrBuf(&ConvertBuf2);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufConvert ( StrBuf ConvertBuf,
StrBuf TmpBuf,
void *  pic 
)

convert one buffer according to the preselected iconv pointer PIC

Parameters:
ConvertBufbuffer we need to translate
TmpBufTo share a workbuffer over several iterations. prepare to have it filled with useless stuff afterwards.
picPointer to the iconv-session Object

Definition at line 3095 of file stringbuf.c.

{
#ifdef HAVE_ICONV
       long trycount = 0;
       size_t siz;
       iconv_t ic;
       char *ibuf;                 
       char *obuf;                 
       size_t ibuflen;                    
       size_t obuflen;                    
       if ((ConvertBuf == NULL) || (TmpBuf == NULL))
              return;

       /* since we're converting to utf-8, one glyph may take up to 6 bytes */
       if (ConvertBuf->BufUsed * 6 >= TmpBuf->BufSize)
              IncreaseBuf(TmpBuf, 0, ConvertBuf->BufUsed * 6);
TRYAGAIN:
       ic = *(iconv_t*)pic;
       ibuf = ConvertBuf->buf;
       ibuflen = ConvertBuf->BufUsed;
       obuf = TmpBuf->buf;
       obuflen = TmpBuf->BufSize;
       
       siz = iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);

       if (siz < 0) {
              if (errno == E2BIG) {
                     trycount ++;                
                     IncreaseBuf(TmpBuf, 0, 0);
                     if (trycount < 5) 
                            goto TRYAGAIN;

              }
              else if (errno == EILSEQ){ 
                     /* hm, invalid utf8 sequence... what to do now? */
                     /* An invalid multibyte sequence has been encountered in the input */
              }
              else if (errno == EINVAL) {
                     /* An incomplete multibyte sequence has been encountered in the input. */
              }

              FlushStrBuf(TmpBuf);
       }
       else {
              TmpBuf->BufUsed = TmpBuf->BufSize - obuflen;
              TmpBuf->buf[TmpBuf->BufUsed] = '\0';
              
              /* little card game: wheres the red lady? */
              SwapBuffers(ConvertBuf, TmpBuf);
              FlushStrBuf(TmpBuf);
       }
#endif
}

Here is the call graph for this function:

Here is the caller graph for this function:

int StrBufDecodeBase64 ( StrBuf Buf)

decode a buffer from base 64 encoding; destroys original

Parameters:
BufBuffor to transform

Definition at line 2602 of file stringbuf.c.

{
       char *xferbuf;
       size_t siz;
       if (Buf == NULL) return -1;

       xferbuf = (char*) malloc(Buf->BufSize);
       *xferbuf = '\0';
       siz = CtdlDecodeBase64(xferbuf,
                            Buf->buf,
                            Buf->BufUsed);
       free(Buf->buf);
       Buf->buf = xferbuf;
       Buf->BufUsed = siz;
       return siz;
}

Here is the call graph for this function:

int StrBufDecodeHex ( StrBuf Buf)

decode a buffer from base 64 encoding; destroys original

Parameters:
BufBuffor to transform

Definition at line 2624 of file stringbuf.c.

{
       unsigned int ch;
       char *pch, *pche, *pchi;

       if (Buf == NULL) return -1;

       pch = pchi = Buf->buf;
       pche = pch + Buf->BufUsed;

       while (pchi < pche){
              ch = decode_hex(pchi);
              *pch = ch;
              pch ++;
              pchi += 2;
       }

       *pch = '\0';
       Buf->BufUsed = pch - Buf->buf;
       return Buf->BufUsed;
}

Here is the call graph for this function:

void StrBufEUid_escapize ( StrBuf target,
const StrBuf source 
)

hide special chars from the HTML escapers and friends

Parameters:
targetbuffer to put the escaped string in
sourcebuffer to escape

Definition at line 2561 of file stringbuf.c.

{
       int i, len;

       if (target != NULL)
              FlushStrBuf(target);

       if ((source == NULL) || (target == NULL) || (target->buf == NULL))
       {
              return;
       }

       len = source->BufUsed;
       for (i=0; i<len; ++i) {
              if (target->BufUsed + 4 >= target->BufSize)
                     IncreaseBuf(target, 1, -1);
              if ( (isalnum(source->buf[i])) || 
                   (source->buf[i]=='-') || 
                   (source->buf[i]=='_') ) {
                     target->buf[target->BufUsed++] = source->buf[i];
              }
              else {
                     sprintf(&target->buf[target->BufUsed], 
                            "=%02X", 
                            (0xFF &source->buf[i]));
                     target->BufUsed += 3;
              }
       }
       target->buf[target->BufUsed + 1] = '\0';
}

Here is the call graph for this function:

void StrBufEUid_unescapize ( StrBuf target,
const StrBuf source 
)

unhide special chars hidden to the HTML escaper

Parameters:
targetbuffer to put the unescaped string in
sourcebuffer to unescape

Definition at line 2519 of file stringbuf.c.

{
       int a, b, len;
       char hex[3];

       if ((source == NULL) || (target == NULL) || (target->buf == NULL))
       {
              return;
       }

       if (target != NULL)
              FlushStrBuf(target);

       len = source->BufUsed;
       for (a = 0; a < len; ++a) {
              if (target->BufUsed >= target->BufSize)
                     IncreaseBuf(target, 1, -1);

              if (source->buf[a] == '=') {
                     hex[0] = source->buf[a + 1];
                     hex[1] = source->buf[a + 2];
                     hex[2] = 0;
                     b = 0;
                     sscanf(hex, "%02x", &b);
                     target->buf[target->BufUsed] = b;
                     target->buf[++target->BufUsed] = 0;
                     a += 2;
              }
              else {
                     target->buf[target->BufUsed] = source->buf[a];
                     target->buf[++target->BufUsed] = 0;
              }
       }
}

Here is the call graph for this function:

void StrBufHexEscAppend ( StrBuf OutBuf,
const StrBuf In,
const unsigned char *  PlainIn,
long  PlainInLen 
)

append a string in hex encoding to the buffer

Parameters:
OutBufthe output buffer
InBuffer to encode
PlainInway in from plain old c strings
PlainInLenway in from plain old c strings; maybe you've got binary data or know the length?

< we max append 3 chars at once plus the \0

< we max append 3 chars at once plus the \0

Definition at line 1913 of file stringbuf.c.

{
       const unsigned char *pch, *pche;
       char *pt, *pte;
       int len;
       
       if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
              return;
       if (PlainIn != NULL) {
              if (PlainInLen < 0)
                     len = strlen((const char*)PlainIn);
              else
                     len = PlainInLen;
              pch = PlainIn;
              pche = pch + len;
       }
       else {
              pch = (const unsigned char*)In->buf;
              pche = pch + In->BufUsed;
              len = In->BufUsed;
       }

       if (len == 0) 
              return;

       pt = OutBuf->buf + OutBuf->BufUsed;
       pte = OutBuf->buf + OutBuf->BufSize - 3; 
       while (pch < pche) {
              if (pt >= pte) {
                     IncreaseBuf(OutBuf, 1, -1);
                     pte = OutBuf->buf + OutBuf->BufSize - 3; 
                     pt = OutBuf->buf + OutBuf->BufUsed;
              }

              *pt = HexList[*pch][0];
              pt ++;
              *pt = HexList[*pch][1];
              pt ++; pch ++; OutBuf->BufUsed += 2;
       }
       *pt = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufHexescAppend ( StrBuf OutBuf,
const StrBuf In,
const char *  PlainIn 
)

append a string in hex encoding to the buffer

Parameters:
OutBufthe output buffer
InBuffer to encode
PlainInway in from plain old c strings

Definition at line 1963 of file stringbuf.c.

{
       StrBufHexEscAppend(OutBuf, In, (const unsigned char*) PlainIn, -1);
}

Here is the call graph for this function:

int StrBufRFC2047encode ( StrBuf **  target,
const StrBuf source 
)

RFC2047-encode a header field if necessary.

         If no non-ASCII characters are found, the string
         will be copied verbatim without encoding.
Parameters:
targetTarget buffer.
sourceSource string to be encoded.
Returns:
encoded length; -1 if non success.

Definition at line 2727 of file stringbuf.c.

{
       const char headerStr[] = "=?UTF-8?Q?";
       int need_to_encode = 0;
       int i = 0;
       unsigned char ch;

       if ((source == NULL) || 
           (target == NULL))
           return -1;

       while ((i < source->BufUsed) &&
              (!IsEmptyStr (&source->buf[i])) &&
              (need_to_encode == 0)) {
              if (((unsigned char) source->buf[i] < 32) || 
                  ((unsigned char) source->buf[i] > 126)) {
                     need_to_encode = 1;
              }
              i++;
       }

       if (!need_to_encode) {
              if (*target == NULL) {
                     *target = NewStrBufPlain(source->buf, source->BufUsed);
              }
              else {
                     FlushStrBuf(*target);
                     StrBufAppendBuf(*target, source, 0);
              }
              if (*target != 0)
                     return (*target)->BufUsed;
              else
                     return 0;
       }
       if (*target == NULL)
              *target = NewStrBufPlain(NULL, sizeof(headerStr) + source->BufUsed * 2);
       else if (sizeof(headerStr) + source->BufUsed >= (*target)->BufSize)
              IncreaseBuf(*target, sizeof(headerStr) + source->BufUsed, 0);
       memcpy ((*target)->buf, headerStr, sizeof(headerStr) - 1);
       (*target)->BufUsed = sizeof(headerStr) - 1;
       for (i=0; (i < source->BufUsed); ++i) {
              if ((*target)->BufUsed + 4 >= (*target)->BufSize)
                     IncreaseBuf(*target, 1, 0);
              ch = (unsigned char) source->buf[i];
              if ((ch  <  32) || 
                  (ch  > 126) || 
                  (ch ==  61) ||
                  (ch == '=') ||
                    (ch == '?') ||
                  (ch == '_') ||
                  (ch == '[') ||
                  (ch == ']')   )
              {
                     sprintf(&(*target)->buf[(*target)->BufUsed], "=%02X", ch);
                     (*target)->BufUsed += 3;
              }
              else {
                     if (ch == ' ')
                            (*target)->buf[(*target)->BufUsed] = '_';
                     else
                            (*target)->buf[(*target)->BufUsed] = ch;
                     (*target)->BufUsed++;
              }
       }
       
       if ((*target)->BufUsed + 4 >= (*target)->BufSize)
              IncreaseBuf(*target, 1, 0);

       (*target)->buf[(*target)->BufUsed++] = '?';
       (*target)->buf[(*target)->BufUsed++] = '=';
       (*target)->buf[(*target)->BufUsed] = '\0';
       return (*target)->BufUsed;;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int StrBufSanitizeAscii ( StrBuf Buf,
const char  Mute 
)

replace all chars >0x20 && < 0x7F with Mute

Parameters:
Mutechar to put over invalid chars
BufBuffor to transform

Definition at line 2652 of file stringbuf.c.

{
       unsigned char *pch;

       if (Buf == NULL) return -1;
       pch = (unsigned char *)Buf->buf;
       while (pch < (unsigned char *)Buf->buf + Buf->BufUsed) {
              if ((*pch < 0x20) || (*pch > 0x7F))
                     *pch = Mute;
              pch ++;
       }
       return Buf->BufUsed;
}
long StrBufUnescape ( StrBuf Buf,
int  StripBlanks 
)

remove escaped strings from i.e.

the url string (like %20 for blanks)

Parameters:
BufBuffer to translate
StripBlanksReduce several blanks to one?

Definition at line 2673 of file stringbuf.c.

{
       int a, b;
       char hex[3];
       long len;

       if (Buf == NULL)
              return -1;

       while ((Buf->BufUsed > 0) && (isspace(Buf->buf[Buf->BufUsed - 1]))){
              Buf->buf[Buf->BufUsed - 1] = '\0';
              Buf->BufUsed --;
       }

       a = 0; 
       while (a < Buf->BufUsed) {
              if (Buf->buf[a] == '+')
                     Buf->buf[a] = ' ';
              else if (Buf->buf[a] == '%') {
                     /* don't let % chars through, rather truncate the input. */
                     if (a + 2 > Buf->BufUsed) {
                            Buf->buf[a] = '\0';
                            Buf->BufUsed = a;
                     }
                     else {               
                            hex[0] = Buf->buf[a + 1];
                            hex[1] = Buf->buf[a + 2];
                            hex[2] = 0;
                            b = 0;
                            sscanf(hex, "%02x", &b);
                            Buf->buf[a] = (char) b;
                            len = Buf->BufUsed - a - 2;
                            if (len > 0)
                                   memmove(&Buf->buf[a + 1], &Buf->buf[a + 3], len);
                     
                            Buf->BufUsed -=2;
                     }
              }
              a++;
       }
       return a;
}
void StrBufUrlescAppend ( StrBuf OutBuf,
const StrBuf In,
const char *  PlainIn 
)

Escape a string for feeding out as a URL while appending it to a Buffer.

Parameters:
OutBufthe output buffer
InBuffer to encode
PlainInway in from plain old c strings

< we max append 3 chars at once plus the \0

< we max append 3 chars at once plus the \0

Definition at line 1792 of file stringbuf.c.

{
       const char *pch, *pche;
       char *pt, *pte;
       int len;
       
       if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
              return;
       if (PlainIn != NULL) {
              len = strlen(PlainIn);
              pch = PlainIn;
              pche = pch + len;
       }
       else {
              pch = In->buf;
              pche = pch + In->BufUsed;
              len = In->BufUsed;
       }

       if (len == 0) 
              return;

       pt = OutBuf->buf + OutBuf->BufUsed;
       pte = OutBuf->buf + OutBuf->BufSize - 4; 
       while (pch < pche) {
              if (pt >= pte) {
                     IncreaseBuf(OutBuf, 1, -1);
                     pte = OutBuf->buf + OutBuf->BufSize - 4; 
                     pt = OutBuf->buf + OutBuf->BufUsed;
              }

              if((*pch >= 'a' && *pch <= 'z') ||
                 (*pch >= '@' && *pch <= 'Z') || /* @ A-Z */
                 (*pch >= '0' && *pch <= ':') || /* 0-9 : */
                 (*pch == '!') || (*pch == '_') || 
                 (*pch == ',') || (*pch == '.'))
              {
                     *(pt++) = *(pch++);
                     OutBuf->BufUsed++;
              }                    
              else {
                     *pt = '%';
                     *(pt + 1) = HexList[(unsigned char)*pch][0];
                     *(pt + 2) = HexList[(unsigned char)*pch][1];
                     pt += 3;
                     OutBuf->BufUsed += 3;
                     pch ++;
              }
       }
       *pt = '\0';
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrBufUrlescUPAppend ( StrBuf OutBuf,
const StrBuf In,
const char *  PlainIn 
)

Escape a string for feeding out as a the username/password part of an URL while appending it to a Buffer.

Parameters:
OutBufthe output buffer
InBuffer to encode
PlainInway in from plain old c strings

< we max append 3 chars at once plus the \0

< we max append 3 chars at once plus the \0

Definition at line 1852 of file stringbuf.c.

{
       const char *pch, *pche;
       char *pt, *pte;
       int len;
       
       if (((In == NULL) && (PlainIn == NULL)) || (OutBuf == NULL) )
              return;
       if (PlainIn != NULL) {
              len = strlen(PlainIn);
              pch = PlainIn;
              pche = pch + len;
       }
       else {
              pch = In->buf;
              pche = pch + In->BufUsed;
              len = In->BufUsed;
       }

       if (len == 0) 
              return;

       pt = OutBuf->buf + OutBuf->BufUsed;
       pte = OutBuf->buf + OutBuf->BufSize - 4; 
       while (pch < pche) {
              if (pt >= pte) {
                     IncreaseBuf(OutBuf, 1, -1);
                     pte = OutBuf->buf + OutBuf->BufSize - 4; 
                     pt = OutBuf->buf + OutBuf->BufUsed;
              }

              if((*pch >= 'a' && *pch <= 'z') ||
                 (*pch >= 'A' && *pch <= 'Z') || /* A-Z */
                 (*pch >= '0' && *pch <= ':') || /* 0-9 : */
                 (*pch == '!') || (*pch == '_') || 
                 (*pch == ',') || (*pch == '.'))
              {
                     *(pt++) = *(pch++);
                     OutBuf->BufUsed++;
              }                    
              else {
                     *pt = '%';
                     *(pt + 1) = HexList[(unsigned char)*pch][0];
                     *(pt + 2) = HexList[(unsigned char)*pch][1];
                     pt += 3;
                     OutBuf->BufUsed += 3;
                     pch ++;
              }
       }
       *pt = '\0';
}

Here is the call graph for this function:

long StrECMAEscAppend ( StrBuf Target,
const StrBuf Source,
const char *  PlainIn 
)

Append a string, escaping characters which have meaning in JavaScript strings .

Parameters:
Targettarget buffer
Sourcesource buffer; set to NULL if you just have a C-String
PlainInPlain-C string to append; set to NULL if unused
Returns:
size of result or -1

Definition at line 2228 of file stringbuf.c.

{
       const char *aptr, *eiptr;
       char *bptr, *eptr;
       long len;
       int IsUtf8Sequence;

       if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
              return -1;

       if (PlainIn != NULL) {
              aptr = PlainIn;
              len = strlen(PlainIn);
              eiptr = aptr + len;
       }
       else {
              aptr = Source->buf;
              eiptr = aptr + Source->BufUsed;
              len = Source->BufUsed;
       }

       if (len == 0) 
              return -1;

       bptr = Target->buf + Target->BufUsed;
       eptr = Target->buf + Target->BufSize - 7; /* our biggest unit to put in...  */

       while (aptr < eiptr){
              if(bptr >= eptr) {
                     IncreaseBuf(Target, 1, -1);
                     eptr = Target->buf + Target->BufSize - 7; /* our biggest unit to put in...  */
                     bptr = Target->buf + Target->BufUsed;
              }
              switch (*aptr) {
              case '\n':
                     memcpy(bptr, HKEY("\\n"));
                     bptr += 2;
                     Target->BufUsed += 2;                            
                     break;
              case '\r':
                     memcpy(bptr, HKEY("\\r"));
                     bptr += 2;
                     Target->BufUsed += 2;
                     break;
              case '"':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = '"';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\\':
                     if ((*(aptr + 1) == 'u') &&
                         isxdigit(*(aptr + 2)) &&
                         isxdigit(*(aptr + 3)) &&
                         isxdigit(*(aptr + 4)) &&
                         isxdigit(*(aptr + 5)))
                     { /* oh, a unicode escaper. let it pass through. */
                            memcpy(bptr, aptr, 6);
                            aptr += 5;
                            bptr +=6;
                            Target->BufUsed += 6;
                     }
                     else 
                     {
                            *bptr = '\\';
                            bptr ++;
                            *bptr = '\\';
                            bptr ++;
                            Target->BufUsed += 2;
                     }
                     break;
              case '\b':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 'b';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\f':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 'f';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\t':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 't';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              default:
                     IsUtf8Sequence =  Ctdl_GetUtf8SequenceLength(aptr, eiptr);
                     while (IsUtf8Sequence > 0){
                            *bptr = *aptr;
                            Target->BufUsed ++;
                            if (--IsUtf8Sequence)
                                   aptr++;
                            bptr++;
                     }
              }
              aptr ++;
       }
       *bptr = '\0';
       if ((bptr == eptr - 1 ) && !IsEmptyStr(aptr) )
              return -1;
       return Target->BufUsed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

long StrEscAppend ( StrBuf Target,
const StrBuf Source,
const char *  PlainIn,
int  nbsp,
int  nolinebreaks 
)

Append a string, escaping characters which have meaning in HTML.

Parameters:
Targettarget buffer
Sourcesource buffer; set to NULL if you just have a C-String
PlainInPlain-C string to append; set to NULL if unused
nbspIf nonzero, spaces are converted to non-breaking spaces.
nolinebreaksif set to 1, linebreaks are removed from the string. if set to 2, linebreaks are replaced by &ltbr/&gt

Definition at line 1979 of file stringbuf.c.

{
       const char *aptr, *eiptr;
       char *bptr, *eptr;
       long len;

       if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
              return -1;

       if (PlainIn != NULL) {
              aptr = PlainIn;
              len = strlen(PlainIn);
              eiptr = aptr + len;
       }
       else {
              aptr = Source->buf;
              eiptr = aptr + Source->BufUsed;
              len = Source->BufUsed;
       }

       if (len == 0) 
              return -1;

       bptr = Target->buf + Target->BufUsed;
       eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */

       while (aptr < eiptr){
              if(bptr >= eptr) {
                     IncreaseBuf(Target, 1, -1);
                     eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */
                     bptr = Target->buf + Target->BufUsed;
              }
              if (*aptr == '<') {
                     memcpy(bptr, "&lt;", 4);
                     bptr += 4;
                     Target->BufUsed += 4;
              }
              else if (*aptr == '>') {
                     memcpy(bptr, "&gt;", 4);
                     bptr += 4;
                     Target->BufUsed += 4;
              }
              else if (*aptr == '&') {
                     memcpy(bptr, "&amp;", 5);
                     bptr += 5;
                     Target->BufUsed += 5;
              }
              else if (*aptr == '"') {
                     memcpy(bptr, "&quot;", 6);
                     bptr += 6;
                     Target->BufUsed += 6;
              }
              else if (*aptr == '\'') {
                     memcpy(bptr, "&#39;", 5);
                     bptr += 5;
                     Target->BufUsed += 5;
              }
              else if (*aptr == LB) {
                     *bptr = '<';
                     bptr ++;
                     Target->BufUsed ++;
              }
              else if (*aptr == RB) {
                     *bptr = '>';
                     bptr ++;
                     Target->BufUsed ++;
              }
              else if (*aptr == QU) {
                     *bptr ='"';
                     bptr ++;
                     Target->BufUsed ++;
              }
              else if ((*aptr == 32) && (nbsp == 1)) {
                     memcpy(bptr, "&nbsp;", 6);
                     bptr += 6;
                     Target->BufUsed += 6;
              }
              else if ((*aptr == '\n') && (nolinebreaks == 1)) {
                     *bptr='\0';   /* nothing */
              }
              else if ((*aptr == '\n') && (nolinebreaks == 2)) {
                     memcpy(bptr, "&lt;br/&gt;", 11);
                     bptr += 11;
                     Target->BufUsed += 11;
              }


              else if ((*aptr == '\r') && (nolinebreaks != 0)) {
                     *bptr='\0';   /* nothing */
              }
              else{
                     *bptr = *aptr;
                     bptr++;
                     Target->BufUsed ++;
              }
              aptr ++;
       }
       *bptr = '\0';
       if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
              return -1;
       return Target->BufUsed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

long StrHtmlEcmaEscAppend ( StrBuf Target,
const StrBuf Source,
const char *  PlainIn,
int  nbsp,
int  nolinebreaks 
)

Append a string, escaping characters which have meaning in HTML + json.

Parameters:
Targettarget buffer
Sourcesource buffer; set to NULL if you just have a C-String
PlainInPlain-C string to append; set to NULL if unused
nbspIf nonzero, spaces are converted to non-breaking spaces.
nolinebreaksif set to 1, linebreaks are removed from the string. if set to 2, linebreaks are replaced by &ltbr/&gt

Definition at line 2350 of file stringbuf.c.

{
       const char *aptr, *eiptr;
       char *bptr, *eptr;
       long len;
       int IsUtf8Sequence = 0;

       if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
              return -1;

       if (PlainIn != NULL) {
              aptr = PlainIn;
              len = strlen(PlainIn);
              eiptr = aptr + len;
       }
       else {
              aptr = Source->buf;
              eiptr = aptr + Source->BufUsed;
              len = Source->BufUsed;
       }

       if (len == 0) 
              return -1;

       bptr = Target->buf + Target->BufUsed;
       eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */

       while (aptr < eiptr){
              if(bptr >= eptr) {
                     IncreaseBuf(Target, 1, -1);
                     eptr = Target->buf + Target->BufSize - 11; /* our biggest unit to put in...  */
                     bptr = Target->buf + Target->BufUsed;
              }
              switch (*aptr) {
              case '<':
                     memcpy(bptr, HKEY("&lt;"));
                     bptr += 4;
                     Target->BufUsed += 4;
                     break;
              case '>':
                     memcpy(bptr, HKEY("&gt;"));
                     bptr += 4;
                     Target->BufUsed += 4;
                     break;
              case '&':
                     memcpy(bptr, HKEY("&amp;"));
                     bptr += 5;
                     Target->BufUsed += 5;
                     break;
              case LB:
                     *bptr = '<';
                     bptr ++;
                     Target->BufUsed ++;
                     break;
              case RB:
                     *bptr = '>';
                     bptr ++;
                     Target->BufUsed ++;
                     break;
              case '\n':
                     switch (nolinebreaks) {
                     case 1:
                            *bptr='\0';   /* nothing */
                            break;
                     case 2:
                            memcpy(bptr, HKEY("&lt;br/&gt;"));
                            bptr += 11;
                            Target->BufUsed += 11;
                            break;
                     default:
                            memcpy(bptr, HKEY("\\n"));
                            bptr += 2;
                            Target->BufUsed += 2;                            
                     }
                     break;
              case '\r':
                     switch (nolinebreaks) {
                     case 1:
                     case 2:
                            *bptr='\0';   /* nothing */
                            break;
                     default:
                            memcpy(bptr, HKEY("\\r"));
                            bptr += 2;
                            Target->BufUsed += 2;
                            break;
                     }
                     break;
              case '"':
              case QU:
                     *bptr = '\\';
                     bptr ++;
                     *bptr = '"';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\\':
                     if ((*(aptr + 1) == 'u') &&
                         isxdigit(*(aptr + 2)) &&
                         isxdigit(*(aptr + 3)) &&
                         isxdigit(*(aptr + 4)) &&
                         isxdigit(*(aptr + 5)))
                     { /* oh, a unicode escaper. let it pass through. */
                            memcpy(bptr, aptr, 6);
                            aptr += 5;
                            bptr +=6;
                            Target->BufUsed += 6;
                     }
                     else 
                     {
                            *bptr = '\\';
                            bptr ++;
                            *bptr = '\\';
                            bptr ++;
                            Target->BufUsed += 2;
                     }
                     break;
              case '\b':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 'b';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\f':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 'f';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case '\t':
                     *bptr = '\\';
                     bptr ++;
                     *bptr = 't';
                     bptr ++;
                     Target->BufUsed += 2;
                     break;
              case  32:
                     if (nbsp == 1) {
                            memcpy(bptr, HKEY("&nbsp;"));
                            bptr += 6;
                            Target->BufUsed += 6;
                            break;
                     }
              default:
                     IsUtf8Sequence =  Ctdl_GetUtf8SequenceLength(aptr, eiptr);
                     while (IsUtf8Sequence > 0){
                            *bptr = *aptr;
                            Target->BufUsed ++;
                            if (--IsUtf8Sequence)
                                   aptr++;
                            bptr++;
                     }
              }
              aptr ++;
       }
       *bptr = '\0';
       if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
              return -1;
       return Target->BufUsed;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void StrIcalEscAppend ( StrBuf Target,
const StrBuf Source,
const char *  PlainIn 
)

Append a string, escaping characters which have meaning in ICAL.

[
,]

Parameters:
Targettarget buffer
Sourcesource buffer; set to NULL if you just have a C-String
PlainInPlain-C string to append; set to NULL if unused

Definition at line 2157 of file stringbuf.c.

{
       const char *aptr, *eiptr;
       char *tptr, *eptr;
       long len;

       if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
              return ;

       if (PlainIn != NULL) {
              aptr = PlainIn;
              len = strlen(PlainIn);
              eiptr = aptr + len;
       }
       else {
              aptr = Source->buf;
              eiptr = aptr + Source->BufUsed;
              len = Source->BufUsed;
       }

       if (len == 0) 
              return;

       eptr = Target->buf + Target->BufSize - 8; 
       tptr = Target->buf + Target->BufUsed;
       
       while (aptr < eiptr){
              if(tptr + 3 >= eptr) {
                     IncreaseBuf(Target, 1, -1);
                     eptr = Target->buf + Target->BufSize - 8; 
                     tptr = Target->buf + Target->BufUsed;
              }
              
              if (*aptr == '\n') {
                     *tptr = '\\';
                     Target->BufUsed++;
                     tptr++;
                     *tptr = 'n';
                     Target->BufUsed++;
              }
              else if (*aptr == '\r') {
                     *tptr = '\\';
                     Target->BufUsed++;
                     tptr++;
                     *tptr = 'r';
                     Target->BufUsed++;
              }
              else if (*aptr == ',') {
                     *tptr = '\\';
                     Target->BufUsed++;
                     tptr++;
                     *tptr = ',';
                     Target->BufUsed++;
              } else {
                     *tptr = *aptr;
                     Target->BufUsed++;
              }
              tptr++; aptr++;
       }
       *tptr = '\0';
}

Here is the call graph for this function:

void StrMsgEscAppend ( StrBuf Target,
const StrBuf Source,
const char *  PlainIn 
)

Append a string, escaping characters which have meaning in HTML.

Converts linebreaks into blanks; escapes single quotes

Parameters:
Targettarget buffer
Sourcesource buffer; set to NULL if you just have a C-String
PlainInPlain-C string to append; set to NULL if unused

Definition at line 2090 of file stringbuf.c.

{
       const char *aptr, *eiptr;
       char *tptr, *eptr;
       long len;

       if (((Source == NULL) && (PlainIn == NULL)) || (Target == NULL) )
              return ;

       if (PlainIn != NULL) {
              aptr = PlainIn;
              len = strlen(PlainIn);
              eiptr = aptr + len;
       }
       else {
              aptr = Source->buf;
              eiptr = aptr + Source->BufUsed;
              len = Source->BufUsed;
       }

       if (len == 0) 
              return;

       eptr = Target->buf + Target->BufSize - 8; 
       tptr = Target->buf + Target->BufUsed;
       
       while (aptr < eiptr){
              if(tptr >= eptr) {
                     IncreaseBuf(Target, 1, -1);
                     eptr = Target->buf + Target->BufSize - 8; 
                     tptr = Target->buf + Target->BufUsed;
              }
              
              if (*aptr == '\n') {
                     *tptr = ' ';
                     Target->BufUsed++;
              }
              else if (*aptr == '\r') {
                     *tptr = ' ';
                     Target->BufUsed++;
              }
              else if (*aptr == '\'') {
                     *(tptr++) = '&';
                     *(tptr++) = '#';
                     *(tptr++) = '3';
                     *(tptr++) = '9';
                     *tptr = ';';
                     Target->BufUsed += 5;
              } else {
                     *tptr = *aptr;
                     Target->BufUsed++;
              }
              tptr++; aptr++;
       }
       *tptr = '\0';
}

Here is the call graph for this function: