Back to index

webcit  8.12-dfsg
Defines | Functions
utils.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include "webcit.h"

Go to the source code of this file.

Defines

#define SHOW_ME_VAPPEND_PRINTF

Functions

long unescape_input (char *buf)
long stresc (char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks)
void escputs (const char *strbuf)
void urlescputs (const char *strbuf)
void hurlescputs (const char *strbuf)
 urlescape buffer and print it as header
void cdataout (char *rawdata)

Define Documentation

Definition at line 5 of file utils.c.


Function Documentation

void cdataout ( char *  rawdata)

Definition at line 159 of file utils.c.

{
       char *ptr = rawdata;
       wc_printf("<![CDATA[");

       while ((ptr != NULL) && (ptr[0] != 0))
       {
              if (!strncmp(ptr, "]]>", 3)) {
                     wc_printf("]]]]><![CDATA[>");
                     ++ptr; ++ptr; ++ptr;
              }
              else {
                     wc_printf("%c", ptr[0]);
                     ++ptr;
              }
       }

       wc_printf("]]>");
}

Here is the call graph for this function:

Here is the caller graph for this function:

void escputs ( const char *  strbuf)

Definition at line 133 of file utils.c.

{
       StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0);
}

Here is the caller graph for this function:

void hurlescputs ( const char *  strbuf)

urlescape buffer and print it as header

Definition at line 150 of file utils.c.

{
       StrBufUrlescAppend(WC->HBuf, NULL, strbuf);
}

Here is the caller graph for this function:

long stresc ( char *  target,
long  tSize,
char *  strbuf,
int  nbsp,
int  nolinebreaks 
)

Definition at line 65 of file utils.c.

{
        char *aptr, *bptr, *eptr;
 
        *target = '\0';
        aptr = strbuf;
        bptr = target;
        eptr = target + tSize - 6; /* our biggest unit to put in...  */
 
 
        while ((bptr < eptr) && !IsEmptyStr(aptr) ){
                if (*aptr == '<') {
                        memcpy(bptr, "&lt;", 4);
                        bptr += 4;
                }
                else if (*aptr == '>') {
                        memcpy(bptr, "&gt;", 4);
                        bptr += 4;
                }
                else if (*aptr == '&') {
                        memcpy(bptr, "&amp;", 5);
                        bptr += 5;
                }
                else if (*aptr == '\"') {
                        memcpy(bptr, "&quot;", 6);
                        bptr += 6;
                }
                else if (*aptr == '\'') {
                        memcpy(bptr, "&#39;", 5);
                        bptr += 5;
                }
                else if (*aptr == LB) {
                        *bptr = '<';
                        bptr ++;
                }
                else if (*aptr == RB) {
                        *bptr = '>';
                        bptr ++;
                }
                else if (*aptr == QU) {
                        *bptr ='"';
                        bptr ++;
                }
                else if ((*aptr == 32) && (nbsp == 1)) {
                        memcpy(bptr, "&nbsp;", 6);
                        bptr += 6;
                }
                else if ((*aptr == '\n') && (nolinebreaks)) {
                        *bptr='\0';     /* nothing */
                }
                else if ((*aptr == '\r') && (nolinebreaks)) {
                        *bptr='\0';     /* nothing */
                }
                else{
                        *bptr = *aptr;
                        bptr++;
                }
                aptr ++;
        }
        *bptr = '\0';
        if ((bptr = eptr - 1 ) && !IsEmptyStr(aptr) )
                return -1;
        return (bptr - target);
}

Here is the caller graph for this function:

long unescape_input ( char *  buf)

Definition at line 14 of file utils.c.

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

       buflen = strlen(buf);

       while ((buflen > 0) && (isspace(buf[buflen - 1]))){
              buf[buflen - 1] = 0;
              buflen --;
       }

       a = 0; 
       while (a < buflen) {
              if (buf[a] == '+')
                     buf[a] = ' ';
              if (buf[a] == '%') {
                     /* don't let % chars through, rather truncate the input. */
                     if (a + 2 > buflen) {
                            buf[a] = '\0';
                            buflen = a;
                     }
                     else {               
                            hex[0] = buf[a + 1];
                            hex[1] = buf[a + 2];
                            hex[2] = 0;
                            b = 0;
                            b = decode_hex(hex);
                            buf[a] = (char) b;
                            len = buflen - a - 2;
                            if (len > 0)
                                   memmove(&buf[a + 1], &buf[a + 3], len);
                     
                            buflen -=2;
                     }
              }
              a++;
       }
       return a;
}

Here is the caller graph for this function:

void urlescputs ( const char *  strbuf)

Definition at line 141 of file utils.c.

{
       StrBufUrlescAppend(WC->WBuf, NULL, strbuf);
}

Here is the caller graph for this function: