X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Futils.c;h=b5812b595d1e7f9bfa33dda53303fc5527b3dceb;hp=4a822814609ee26811bb6eb15c0ad4dc036d468a;hb=c6aec42f213ec284e34648f3d69bcf927dccddb1;hpb=7beff529e758f6f0706e733901824c63bcac6d19 diff --git a/webcit/utils.c b/webcit/utils.c index 4a8228146..b5812b595 100644 --- a/webcit/utils.c +++ b/webcit/utils.c @@ -1,3 +1,4 @@ + /* * de/encoding stuff. hopefully mostly to be depricated in favour of subst.c + strbuf */ @@ -11,8 +12,7 @@ /* * remove escaped strings from i.e. the url string (like %20 for blanks) */ -long unescape_input(char *buf) -{ +long unescape_input(char *buf) { unsigned int a, b; char hex[3]; long buflen; @@ -20,12 +20,12 @@ long unescape_input(char *buf) buflen = strlen(buf); - while ((buflen > 0) && (isspace(buf[buflen - 1]))){ + while ((buflen > 0) && (isspace(buf[buflen - 1]))) { buf[buflen - 1] = 0; - buflen --; + buflen--; } - a = 0; + a = 0; while (a < buflen) { if (buf[a] == '+') buf[a] = ' '; @@ -35,7 +35,7 @@ long unescape_input(char *buf) buf[a] = '\0'; buflen = a; } - else { + else { hex[0] = buf[a + 1]; hex[1] = buf[a + 2]; hex[2] = 0; @@ -45,8 +45,8 @@ long unescape_input(char *buf) len = buflen - a - 2; if (len > 0) memmove(&buf[a + 1], &buf[a + 3], len); - - buflen -=2; + + buflen -= 2; } } a++; @@ -62,84 +62,81 @@ long unescape_input(char *buf) * nbsp If nonzero, spaces are converted to non-breaking spaces. * nolinebreaks if set, linebreaks are removed from the string. */ -long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) -{ - 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, "<", 4); - bptr += 4; - } - else if (*aptr == '>') { - memcpy(bptr, ">", 4); - bptr += 4; - } - else if (*aptr == '&') { - memcpy(bptr, "&", 5); - bptr += 5; - } - else if (*aptr == '\"') { - memcpy(bptr, """, 6); - bptr += 6; - } - else if (*aptr == '\'') { - memcpy(bptr, "'", 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, " ", 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); +long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks) { + 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, "<", 4); + bptr += 4; + } + else if (*aptr == '>') { + memcpy(bptr, ">", 4); + bptr += 4; + } + else if (*aptr == '&') { + memcpy(bptr, "&", 5); + bptr += 5; + } + else if (*aptr == '\"') { + memcpy(bptr, """, 6); + bptr += 6; + } + else if (*aptr == '\'') { + memcpy(bptr, "'", 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, " ", 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); } /* * static wrapper for ecsputs1 */ -void escputs(const char *strbuf) -{ +void escputs(const char *strbuf) { StrEscAppend(WC->WBuf, NULL, strbuf, 0, 0); } /* * urlescape buffer and print it to the client */ -void urlescputs(const char *strbuf) -{ +void urlescputs(const char *strbuf) { StrBufUrlescAppend(WC->WBuf, NULL, strbuf); } @@ -147,8 +144,7 @@ void urlescputs(const char *strbuf) /** * urlescape buffer and print it as header */ -void hurlescputs(const char *strbuf) -{ +void hurlescputs(const char *strbuf) { StrBufUrlescAppend(WC->HBuf, NULL, strbuf); } @@ -156,16 +152,16 @@ void hurlescputs(const char *strbuf) /* * Output a string to the client as a CDATA block */ -void cdataout(char *rawdata) -{ +void cdataout(char *rawdata) { char *ptr = rawdata; wc_printf("", 3)) { wc_printf("]]]]>"); - ++ptr; ++ptr; ++ptr; + ++ptr; + ++ptr; + ++ptr; } else { wc_printf("%c", ptr[0]); @@ -175,4 +171,3 @@ void cdataout(char *rawdata) wc_printf("]]>"); } -