X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fparamhandling.c;h=1e07fcfb3aa018440580b65670c9061555d5b77c;hb=0e19dfa22f8f12f33b095abd24b10d7d39c74c60;hp=bfc8ac7ff1dfdead5a1132718425a9415e68e746;hpb=97ef45e304502bd67aff98f9d00cf4c05fa12018;p=citadel.git diff --git a/webcit/paramhandling.c b/webcit/paramhandling.c index bfc8ac7ff..1e07fcfb3 100644 --- a/webcit/paramhandling.c +++ b/webcit/paramhandling.c @@ -1,7 +1,7 @@ /* * parse urlparts and post data * - * Copyright (c) 1996-2013 by the citadel.org team + * Copyright (c) 1996-2019 by the citadel.org team * * This program is open source software. You can redistribute it and/or * modify it under the terms of the GNU General Public License, version 3. @@ -62,7 +62,7 @@ void PutSubstructUrlKey(HashList *list, urlcontent *u, char **keys, long *length } void PutUrlKey(HashList *urlstrings, urlcontent *u, int have_colons) { - if (!have_colons) { + if (have_colons == 0) { Put(urlstrings, u->url_key, u->klen, u, free_url); } else { @@ -78,22 +78,54 @@ void PutUrlKey(HashList *urlstrings, urlcontent *u, int have_colons) { pchs = pch = u->url_key; pche = u->url_key + u->klen; while ((i < 10) && (pch <= pche)) { - if ((*pch != ':') && (pch != pche)){ - pch ++; - continue; - } - *pch = '\0'; - if (i == 0) { - /* Separate the toplevel key : */ - u->klen = pch - pchs; + if ((have_colons == 2) && + (*pch == '%') && + (*(pch + 1) == '3') && + ((*(pch + 2) == 'A') || + (*(pch + 1) == 'a') + )) + { + *pch = '\0'; + + if (i == 0) { + /* Separate the toplevel key : */ + u->klen = pch - pchs; + } + + /* sub-section: */ + keys[i] = pchs; + lengths[i] = pch - pchs; + + pch += 3; + + pchs = pch; + i++; } - /* sub-section: */ - keys[i] = pchs; - lengths[i] = pch - pchs; + else if ((have_colons == 1) && + (*pch == ':')) { + *pch = '\0'; + if (i == 0) { + /* Separate the toplevel key : */ + u->klen = pch - pchs; + } + /* sub-section: */ + keys[i] = pchs; + lengths[i] = pch - pchs; - pch++; - pchs = pch; - i++; + pch++; + pchs = pch; + i++; + } + else if (pch == pche){ + /* sub-section: */ + keys[i] = pchs; + lengths[i] = pch - pchs; + i++; + break; + } + else { + pch ++; + } } PutSubstructUrlKey(urlstrings, u, keys, lengths, i - 1, 0); @@ -122,6 +154,14 @@ void ParseURLParams(StrBuf *url) if (*aptr == ':') { have_colon = 1; } + else if ((*aptr == '%') && + (*(aptr + 1) == '3') && + ((*(aptr + 2) == 'A') || + (*(aptr + 1) == 'a') + )) + { + have_colon = 2; + } aptr++; } if (*aptr != '=') { @@ -136,8 +176,10 @@ void ParseURLParams(StrBuf *url) keylen = aptr - up - 1; /* -1 -> '=' */ if (keylen > sizeof(u->url_key)) { syslog(LOG_WARNING, "%s:%d: invalid url_key of size %d in string size %ld", - __FILE__, __LINE__, keylen, sizeof(u->url_key) + __FILE__, __LINE__, keylen, (long)sizeof(u->url_key) ); + free(u); + return; } if (keylen < 0) { @@ -299,17 +341,6 @@ long LBstr(const char *key, size_t keylen) return (0); } -long LBSTR(const char *key) -{ - void *U; - - if ((WC->Hdr->urlstrings != NULL) && - GetHash(WC->Hdr->urlstrings, key, strlen(key), &U)) - return StrTol(((urlcontent *)U)->url_data); - else - return (0); -} - int IBstr(const char *key, size_t keylen) { void *U; @@ -343,41 +374,133 @@ int HaveBstr(const char *key, size_t keylen) return (0); } -int HAVEBSTR(const char *key) +int YesBstr(const char *key, size_t keylen) { void *U; if ((WC->Hdr->urlstrings != NULL) && - GetHash(WC->Hdr->urlstrings, key, strlen(key), &U)) - return (StrLength(((urlcontent *)U)->url_data) != 0); + GetHash(WC->Hdr->urlstrings, key, keylen, &U)) + return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0; else return (0); } - -int YesBstr(const char *key, size_t keylen) +int YESBSTR(const char *key) { void *U; if ((WC->Hdr->urlstrings != NULL) && - GetHash(WC->Hdr->urlstrings, key, keylen, &U)) + GetHash(WC->Hdr->urlstrings, key, strlen(key), &U)) return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0; else return (0); } -int YESBSTR(const char *key) + +/* + * Return a sub array that was separated by a colon: + */ +HashList* getSubStruct(const char *key, size_t keylen) { void *U; if ((WC->Hdr->urlstrings != NULL) && GetHash(WC->Hdr->urlstrings, key, strlen(key), &U)) - return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0; + return ((urlcontent *)U)->sub; + else + return NULL; +} + + +/* + * Return the value of a variable of a substruct provided by getSubStruct + */ +const char *XSubBstr(HashList *sub, const char *key, size_t keylen, size_t *len) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + *len = StrLength(((urlcontent *)U)->url_data); + return ChrPtr(((urlcontent *)U)->url_data); + } + else { + *len = 0; + return (""); + } +} + +const char *SubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return ChrPtr(((urlcontent *)U)->url_data); + } + else + return (""); +} + +const StrBuf *SSubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return ((urlcontent *)U)->url_data; + } + else + return NULL; +} + +long LSubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return StrTol(((urlcontent *)U)->url_data); + } else return (0); } +int ISubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return StrTol(((urlcontent *)U)->url_data); + } + else + return (0); +} + +int HaveSubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return (StrLength(((urlcontent *)U)->url_data) != 0); + } + else + return (0); +} + +int YesSubBstr(HashList *sub, const char *key, size_t keylen) +{ + void *U; + + if ((sub != NULL) && + GetHash(sub, key, keylen, &U)) { + return strcmp( ChrPtr(((urlcontent *)U)->url_data), "yes") == 0; + } + else + return (0); +} /*