#include #include #include #include "safestring.h" #include "util.h" #include "clog.h" bool reg_match( const char * input, const char * regexp, char * ret, int sz, int * pos /*= NULL*/ ) { regex_t compiled; regmatch_t match[2]; bool satisfied = false; if ( ret ) ret[0] = 0; // logfmt( FLOG_MAX, "Matching '%s' against '%s'", input, regexp ); if ( regcomp( &compiled, regexp, REG_EXTENDED ) != 0 ) { logfmt( logWARNING, "regcomp returned non-0, assuming a match" ); } else { size_t r = regexec( &compiled, input, 2, match, 0 ); if ( r==0 ) // match { if ( pos ) *pos = match[1].rm_so; int len = match[1].rm_eo-match[1].rm_so; if ( ret ) strnsafecpy( ret, &input[ match[1].rm_so ], len, sz ); satisfied = true; } else satisfied = false; regfree( &compiled ); } return satisfied; } char * urlencode( const char * buf, char * text, int sz ) { // old char url[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ^_\\-0123456789."; // . ??? char url[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789$-_.!*'(),"; // $-_.+!*'(), took '+' out int len = strlen(buf); // fprintf(flog, "buf: '%s', len: %d\n", buf, len); fflush(flog); text[0] = 0; for (int i=0; i=valuelen-1) // { EOS = TRUE; break; } c2+=c3+3; } } value[sz-1] = 0; // Log(text, "urldecode returning"); return text; }