From 7c633c259ebc4a863c5076462c5792ecb8b9f617 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 15 Apr 2024 00:39:02 +0200 Subject: clang-format --- scan_urlencoded_query.c | 97 ++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 37 deletions(-) (limited to 'scan_urlencoded_query.c') diff --git a/scan_urlencoded_query.c b/scan_urlencoded_query.c index a4f89c2..2d3599d 100644 --- a/scan_urlencoded_query.c +++ b/scan_urlencoded_query.c @@ -45,37 +45,45 @@ static const unsigned char is_unreserved[256] = { /* Do a fast nibble to hex representation conversion */ static unsigned char fromhex(unsigned char x) { - x-='0'; if( x<=9) return x; - x&=~0x20; x-='A'-'0'; - if( x<6 ) return x+10; + x -= '0'; + if (x <= 9) + return x; + x &= ~0x20; + x -= 'A' - '0'; + if (x < 6) + return x + 10; return 0xff; } /* Skip the value of a param=value pair */ -void scan_urlencoded_skipvalue( char **string ) { - const unsigned char* s=*(const unsigned char**) string; - unsigned char f; +void scan_urlencoded_skipvalue(char **string) { + const unsigned char *s = *(const unsigned char **)string; + unsigned char f; /* Since we are asked to skip the 'value', we assume to stop at terminators for a 'value' string position */ - while( ( f = is_unreserved[ *s++ ] ) & SCAN_SEARCHPATH_VALUE ); + while ((f = is_unreserved[*s++]) & SCAN_SEARCHPATH_VALUE) + ; /* If we stopped at a hard terminator like \0 or \n, make the next scan_urlencoded_query encounter it again */ - if( f & SCAN_SEARCHPATH_TERMINATOR ) --s; + if (f & SCAN_SEARCHPATH_TERMINATOR) + --s; - *string = (char*)s; + *string = (char *)s; } -int scan_find_keywords( const ot_keywords * keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { - char *deststring = *string; - ssize_t match_length = scan_urlencoded_query(string, deststring, flags ); +int scan_find_keywords(const ot_keywords *keywords, char **string, SCAN_SEARCHPATH_FLAG flags) { + char *deststring = *string; + ssize_t match_length = scan_urlencoded_query(string, deststring, flags); - if( match_length < 0 ) return match_length; - if( match_length == 0 ) return -3; + if (match_length < 0) + return match_length; + if (match_length == 0) + return -3; - while( keywords->key ) { - if( !strncmp( keywords->key, deststring, match_length ) && !keywords->key[match_length] ) + while (keywords->key) { + if (!strncmp(keywords->key, deststring, match_length) && !keywords->key[match_length]) return keywords->value; keywords++; } @@ -84,59 +92,74 @@ int scan_find_keywords( const ot_keywords * keywords, char **string, SCAN_SEARCH } ssize_t scan_urlencoded_query(char **string, char *deststring, SCAN_SEARCHPATH_FLAG flags) { - const unsigned char* s=*(const unsigned char**) string; - unsigned char *d = (unsigned char*)deststring; - unsigned char b, c; + const unsigned char *s = *(const unsigned char **)string; + unsigned char *d = (unsigned char *)deststring; + unsigned char b, c; /* This is the main decoding loop. 'flag' determines, which characters are non-terminating in current context (ie. stop at '=' and '&' if scanning for a 'param'; stop at '?' if scanning for the path ) */ - while( is_unreserved[ c = *s++ ] & flags ) { + while (is_unreserved[c = *s++] & flags) { /* When encountering an url escaped character, try to decode */ - if( c=='%') { - if( ( b = fromhex(*s++) ) == 0xff ) return -1; - if( ( c = fromhex(*s++) ) == 0xff ) return -1; - c|=(b<<4); + if (c == '%') { + if ((b = fromhex(*s++)) == 0xff) + return -1; + if ((c = fromhex(*s++)) == 0xff) + return -1; + c |= (b << 4); } /* Write (possibly decoded) character to output */ *d++ = c; } - switch( c ) { - case 0: case '\r': case '\n': case ' ': + switch (c) { + case 0: + case '\r': + case '\n': + case ' ': /* If we started scanning on a hard terminator, indicate we've finished */ - if( d == (unsigned char*)deststring ) return -2; + if (d == (unsigned char *)deststring) + return -2; /* Else make the next call to scan_urlencoded_param encounter it again */ --s; break; case '?': - if( flags != SCAN_PATH ) return -1; + if (flags != SCAN_PATH) + return -1; break; case '=': - if( flags != SCAN_SEARCHPATH_PARAM ) return -1; + if (flags != SCAN_SEARCHPATH_PARAM) + return -1; break; case '&': - if( flags == SCAN_PATH ) return -1; - if( flags == SCAN_SEARCHPATH_PARAM ) --s; + if (flags == SCAN_PATH) + return -1; + if (flags == SCAN_SEARCHPATH_PARAM) + --s; break; default: return -1; } *string = (char *)s; - return d - (unsigned char*)deststring; + return d - (unsigned char *)deststring; } -ssize_t scan_fixed_int( char *data, size_t len, int *tmp ) { +ssize_t scan_fixed_int(char *data, size_t len, int *tmp) { int minus = 0; - *tmp = 0; - if( *data == '-' ) --len, ++data, ++minus; - while( (len > 0) && (*data >= '0') && (*data <= '9') ) { --len; *tmp = 10**tmp + *data++-'0'; } - if( minus ) *tmp = -*tmp; + *tmp = 0; + if (*data == '-') + --len, ++data, ++minus; + while ((len > 0) && (*data >= '0') && (*data <= '9')) { + --len; + *tmp = 10 * *tmp + *data++ - '0'; + } + if (minus) + *tmp = -*tmp; return len; } -- cgit v1.2.3