Back to index

webcit  8.12-dfsg
Functions
paramhandling.c File Reference
#include "webcit.h"
#include "webserver.h"

Go to the source code of this file.

Functions

void free_url (void *U)
void ParseURLParams (StrBuf *url)
void free_urls (void)
void dump_vars (void)
const char * XBstr (const char *key, size_t keylen, size_t *len)
const char * XBSTR (const char *key, size_t *len)
const char * BSTR (const char *key)
const char * Bstr (const char *key, size_t keylen)
const StrBuf * SBSTR (const char *key)
const StrBuf * SBstr (const char *key, size_t keylen)
long LBstr (const char *key, size_t keylen)
long LBSTR (const char *key)
int IBstr (const char *key, size_t keylen)
int IBSTR (const char *key)
int HaveBstr (const char *key, size_t keylen)
int HAVEBSTR (const char *key)
int YesBstr (const char *key, size_t keylen)
int YESBSTR (const char *key)
void upload_handler (char *name, char *filename, char *partnum, char *disp, void *content, char *cbtype, char *cbcharset, size_t length, char *encoding, char *cbid, void *userdata)
void PutBstr (const char *key, long keylen, StrBuf *Value)
int ConditionalBstr (StrBuf *Target, WCTemplputParams *TP)
void tmplput_bstr (StrBuf *Target, WCTemplputParams *TP)
void tmplput_bstrforward (StrBuf *Target, WCTemplputParams *TP)
void diagnostics (void)
void tmplput_url_part (StrBuf *Target, WCTemplputParams *TP)
void InitModule_PARAMHANDLING (void)
void SessionAttachModule_PARAMHANDLING (wcsession *sess)
void SessionDetachModule_PARAMHANDLING (wcsession *sess)

Function Documentation

const char* BSTR ( const char *  key)

Definition at line 159 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) &&
           GetHash(WC->Hdr->urlstrings, key, strlen (key), &U))
              return ChrPtr(((urlcontent *)U)->url_data);
       else   
              return ("");
}

Here is the caller graph for this function:

const char* Bstr ( const char *  key,
size_t  keylen 
)

Definition at line 170 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return ChrPtr(((urlcontent *)U)->url_data);
       else   
              return ("");
}

Here is the caller graph for this function:

int ConditionalBstr ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 386 of file paramhandling.c.

{
       if(TP->Tokens->nParameters == 3)
              return HaveBstr(TKEY(2));
       else {
              if (IS_NUMBER(TP->Tokens->Params[3]->Type))
              {
                     return LBstr(TKEY(2)) == 
                            GetTemplateTokenNumber(Target, 
                                                 TP, 
                                                 3, 
                                                 0);
              }
              else {
                     const char *pch;
                     long len;

                     GetTemplateTokenString (Target, TP, 3, &pch, &len);
                     return strcmp(Bstr(TKEY(2)), pch) == 0;
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void diagnostics ( void  )

Definition at line 428 of file paramhandling.c.

{
       output_headers(1, 1, 1, 0, 0, 0);
       wc_printf("Session: %d<hr />\n", WC->wc_session);
       wc_printf("Command: <br><PRE>\n");
/*     
StrEscAppend(WC->WBuf, NULL, WC->UrlFragment1, 0, 0);
       wc_printf("<br>\n");
StrEscAppend(WC->WBuf, NULL, WC->UrlFragment12 0, 0);
       wc_printf("<br>\n");
StrEscAppend(WC->WBuf, NULL, WC->UrlFragment3, 0, 0);
*/
       wc_printf("</PRE><hr />\n");
       wc_printf("Variables: <br><PRE>\n");
       dump_vars();
       wc_printf("</PRE><hr />\n");
       wDumpContent(1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void dump_vars ( void  )

Definition at line 108 of file paramhandling.c.

{
       wcsession *WCC = WC;
       urlcontent *u;
       void *U;
       long HKLen;
       const char *HKey;
       HashPos *Cursor;
       
       Cursor = GetNewHashPos (WCC->Hdr->urlstrings, 0);
       while (GetNextHashPos(WCC->Hdr->urlstrings, Cursor, &HKLen, &HKey, &U)) {
              u = (urlcontent*) U;
              wc_printf("%38s = %s\n", u->url_key, ChrPtr(u->url_data));
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void free_url ( void *  U)

Definition at line 18 of file paramhandling.c.

{
       urlcontent *u = (urlcontent*) U;
       FreeStrBuf(&u->url_data);
       free(u);
}

Here is the caller graph for this function:

void free_urls ( void  )

Definition at line 99 of file paramhandling.c.

{
       DeleteHash(&WC->Hdr->urlstrings);
}
int HaveBstr ( const char *  key,
size_t  keylen 
)

Definition at line 247 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return (StrLength(((urlcontent *)U)->url_data) != 0);
       else   
              return (0);
}

Here is the caller graph for this function:

int HAVEBSTR ( const char *  key)

Definition at line 258 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, strlen(key), &U))
              return (StrLength(((urlcontent *)U)->url_data) != 0);
       else   
              return (0);
}

Here is the caller graph for this function:

int IBstr ( const char *  key,
size_t  keylen 
)

Definition at line 225 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return StrTol(((urlcontent *)U)->url_data);
       else   
              return (0);
}
int IBSTR ( const char *  key)

Definition at line 236 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, strlen(key), &U))
              return StrToi(((urlcontent *)U)->url_data);
       else   
              return (0);
}

Here is the caller graph for this function:

void InitModule_PARAMHANDLING ( void  )

Definition at line 482 of file paramhandling.c.

{
       WebcitAddUrlHandler(HKEY("diagnostics"), "", 0, diagnostics, NEED_URL);

       RegisterConditional(HKEY("COND:BSTR"), 1, ConditionalBstr, CTX_NONE);
       RegisterNamespace("BSTR", 1, 2, tmplput_bstr, NULL, CTX_NONE);
       RegisterNamespace("BSTR:FORWARD", 1, 2, tmplput_bstrforward, NULL, CTX_NONE);
       RegisterNamespace("URLPART", 1, 2, tmplput_url_part, NULL, CTX_NONE);
}

Here is the call graph for this function:

Here is the caller graph for this function:

long LBstr ( const char *  key,
size_t  keylen 
)

Definition at line 203 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return StrTol(((urlcontent *)U)->url_data);
       else   
              return (0);
}

Here is the caller graph for this function:

long LBSTR ( const char *  key)

Definition at line 214 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, strlen(key), &U))
              return StrTol(((urlcontent *)U)->url_data);
       else   
              return (0);
}

Here is the caller graph for this function:

void ParseURLParams ( StrBuf *  url)

Definition at line 28 of file paramhandling.c.

{
       const char *aptr, *bptr, *eptr, *up;
       int len, keylen;
       urlcontent *u;
       wcsession *WCC = WC;

       if (WCC->Hdr->urlstrings == NULL)
              WCC->Hdr->urlstrings = NewHash(1, NULL);
       eptr = ChrPtr(url) + StrLength(url);
       up = ChrPtr(url);
       while ((up < eptr) && (!IsEmptyStr(up))) {
              aptr = up;
              while ((aptr < eptr) && (*aptr != '\0') && (*aptr != '='))
                     aptr++;
              if (*aptr != '=') {
                     return;
              }
              aptr++;
              bptr = aptr;
              while ((bptr < eptr) && (*bptr != '\0')
                    && (*bptr != '&') && (*bptr != '?') && (*bptr != ' ')) {
                     bptr++;
              }
              keylen = aptr - up - 1; /* -1 -> '=' */
              if(keylen > sizeof(u->url_key)) {
                     syslog(1, "URLkey to long! [%s]", up);
                     continue;
              }

              u = (urlcontent *) malloc(sizeof(urlcontent));
              memcpy(u->url_key, up, keylen);
              u->url_key[keylen] = '\0';
              if (keylen < 0) {
                     syslog(1, "URLkey to long! [%s]", up);
                     free(u);
                     continue;
              }
              
              if (strncmp(u->url_key, "__", 2) != 0)
              {
                     Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
                     len = bptr - aptr;
                     u->url_data = NewStrBufPlain(aptr, len);
                     StrBufUnescape(u->url_data, 1);
#ifdef DEBUG_URLSTRINGS
                     syslog(9, "%s = [%d]  %s\n", 
                            u->url_key, 
                            StrLength(u->url_data), 
                            ChrPtr(u->url_data)); 
#endif
              }
              else {
                     len = bptr - aptr;
                     u->url_data = NewStrBufPlain(aptr, len);
                     StrBufUnescape(u->url_data, 1);
                     syslog(1, "REJECTED because of __ is internal only: %s = [%d]  %s\n", 
                            u->url_key, 
                            StrLength(u->url_data), 
                            ChrPtr(u->url_data)); 
                     
                     free_url(u);
              }
              up = bptr;
              ++up;
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PutBstr ( const char *  key,
long  keylen,
StrBuf *  Value 
)

Definition at line 369 of file paramhandling.c.

{
       urlcontent *u;

       if(keylen > sizeof(u->url_key)) {
              syslog(1, "URLkey to long! [%s]", key);
              FreeStrBuf(&Value);
              return;
       }
       u = (urlcontent*)malloc(sizeof(urlcontent));
       memcpy(u->url_key, key, keylen + 1);
       u->url_data = Value;
       Put(WC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
}

Here is the call graph for this function:

Here is the caller graph for this function:

const StrBuf* SBSTR ( const char *  key)

Definition at line 181 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) &&
           GetHash(WC->Hdr->urlstrings, key, strlen (key), &U))
              return ((urlcontent *)U)->url_data;
       else   
              return NULL;
}

Here is the caller graph for this function:

const StrBuf* SBstr ( const char *  key,
size_t  keylen 
)

Definition at line 192 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return ((urlcontent *)U)->url_data;
       else   
              return NULL;
}

Here is the caller graph for this function:

Definition at line 495 of file paramhandling.c.

{
       sess->Hdr->urlstrings = NewHash(1,NULL);
}

Here is the caller graph for this function:

Definition at line 502 of file paramhandling.c.

{
       DeleteHash(&sess->Hdr->urlstrings);
       FreeStrBuf(&sess->upload_filename);
}

Here is the caller graph for this function:

void tmplput_bstr ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 409 of file paramhandling.c.

{
       const StrBuf *Buf = SBstr(TKEY(0));
       if (Buf != NULL)
              StrBufAppendTemplate(Target, TP, Buf, 1);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tmplput_bstrforward ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 417 of file paramhandling.c.

{
       const StrBuf *Buf = SBstr(TKEY(0));
       if (Buf != NULL) {
              StrBufAppendBufPlain(Target, HKEY("?"), 0);             
              StrBufAppendBufPlain(Target, TKEY(0), 0);
              StrBufAppendBufPlain(Target, HKEY("="), 0);             
              StrBufAppendTemplate(Target, TP, Buf, 1);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tmplput_url_part ( StrBuf *  Target,
WCTemplputParams TP 
)

Definition at line 448 of file paramhandling.c.

{
       StrBuf *Name = NULL;
       StrBuf *UrlBuf = NULL;
       wcsession *WCC = WC;
       
       if (WCC != NULL) {
              long n;

              n = GetTemplateTokenNumber(Target, TP, 0, 0);
              if (n == 0) {
                     if (WCC->Hdr->HR.Handler != NULL)
                            UrlBuf = Name = WCC->Hdr->HR.Handler->Name;
              }
              else if (n == 1) {
                     UrlBuf = NewStrBuf();
                     StrBufExtract_token(UrlBuf, WCC->Hdr->HR.ReqLine, 0, '/');
              }
              else {
                     UrlBuf = NewStrBuf();
                     StrBufExtract_token(UrlBuf, WCC->Hdr->HR.ReqLine, 1, '/');
              }

              if (UrlBuf == NULL)  {
                     LogTemplateError(Target, "urlbuf", ERR_PARM1, TP, "not set.");
              }
              StrBufAppendTemplate(Target, TP, UrlBuf, 2);
              if (Name == NULL) FreeStrBuf(&UrlBuf);
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void upload_handler ( char *  name,
char *  filename,
char *  partnum,
char *  disp,
void *  content,
char *  cbtype,
char *  cbcharset,
size_t  length,
char *  encoding,
char *  cbid,
void *  userdata 
)

Definition at line 312 of file paramhandling.c.

{
       wcsession *WCC = WC;
       urlcontent *u;
       long keylen;

#ifdef DEBUG_URLSTRINGS
       syslog(9, "upload_handler() name=%s, type=%s, len=%d", name, cbtype, length);
#endif
       if (WCC->Hdr->urlstrings == NULL)
              WCC->Hdr->urlstrings = NewHash(1, NULL);

       /* Form fields */
       if ( (length > 0) && (IsEmptyStr(cbtype)) ) {
              u = (urlcontent *) malloc(sizeof(urlcontent));
              
              keylen = safestrncpy(u->url_key, name, sizeof(u->url_key));
              u->url_data = NewStrBufPlain(content, length);
              
              if (strncmp(u->url_key, "__", 2) != 0)
              {
                     Put(WCC->Hdr->urlstrings, u->url_key, keylen, u, free_url);
              }
              else {
                     syslog(1, "REJECTED because of __ is internal only: %s = [%d]  %s\n", 
                            u->url_key, 
                            StrLength(u->url_data), 
                            ChrPtr(u->url_data)); 
                     
                     free_url(u);
              }
#ifdef DEBUG_URLSTRINGS
              syslog(9, "Key: <%s> len: [%d] Data: <%s>", 
                     u->url_key, 
                     StrLength(u->url_data), 
                     ChrPtr(u->url_data));
#endif
       }

       /* Uploaded files */
       if ( (length > 0) && (!IsEmptyStr(cbtype)) ) {
              WCC->upload = NewStrBufPlain(content, length);
              WCC->upload_length = length;
              WCC->upload_filename = NewStrBufPlain(filename, -1);
              safestrncpy(WCC->upload_content_type, cbtype, sizeof(WC->upload_content_type));
#ifdef DEBUG_URLSTRINGS
              syslog(9, "File: <%s> len: [%ld]", filename, length);
#endif
              
       }

}

Here is the call graph for this function:

Here is the caller graph for this function:

const char* XBstr ( const char *  key,
size_t  keylen,
size_t *  len 
)

Definition at line 128 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U)) {
              *len = StrLength(((urlcontent *)U)->url_data);
              return ChrPtr(((urlcontent *)U)->url_data);
       }
       else {
              *len = 0;
              return ("");
       }
}
const char* XBSTR ( const char *  key,
size_t *  len 
)

Definition at line 143 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) &&
           GetHash(WC->Hdr->urlstrings, key, strlen (key), &U)){
              *len = StrLength(((urlcontent *)U)->url_data);
              return ChrPtr(((urlcontent *)U)->url_data);
       }
       else {
              *len = 0;
              return ("");
       }
}
int YesBstr ( const char *  key,
size_t  keylen 
)

Definition at line 270 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, keylen, &U))
              return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
       else   
              return (0);
}

Here is the caller graph for this function:

int YESBSTR ( const char *  key)

Definition at line 281 of file paramhandling.c.

{
       void *U;

       if ((WC->Hdr->urlstrings != NULL) && 
           GetHash(WC->Hdr->urlstrings, key, strlen(key), &U))
              return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0;
       else   
              return (0);
}

Here is the caller graph for this function: