📄 url_scanner_ex.c
字号:
case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy32; default: goto yy34; }yy28: ++YYCURSOR; goto yy29;yy29:{ passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }yy30: ++YYCURSOR; yych = *YYCURSOR; goto yy37;yy31:{ passthru(STD_ARGS); goto state_next_arg; }yy32: ++YYCURSOR; goto yy33;yy33:{ --YYCURSOR; STATE = STATE_ARG; goto state_arg; }yy34: ++YYCURSOR; goto yy35;yy35:{ passthru(STD_ARGS); goto state_plain_begin; }yy36: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy37;yy37: switch(yych){ case 0x09: case 0x0A: case 0x0B: case 0x0D: case ' ': goto yy36; default: goto yy31; }}state_arg: start = YYCURSOR;{ YYCTYPE yych; goto yy38; ++YYCURSOR;yy38: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy40; default: goto yy42; }yy40: ++YYCURSOR; yych = *YYCURSOR; goto yy45;yy41:{ passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }yy42: ++YYCURSOR; goto yy43;yy43:{ passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }yy44: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy45;yy45: switch(yych){ case '-': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z': case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g': case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n': case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u': case 'v': case 'w': case 'x': case 'y': case 'z': goto yy44; default: goto yy41; }}state_before_val: start = YYCURSOR;{ YYCTYPE yych; unsigned int yyaccept = 0; goto yy46; ++YYCURSOR;yy46: if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; switch(yych){ case ' ': goto yy48; case '=': goto yy50; default: goto yy52; }yy48: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); switch(yych){ case ' ': goto yy55; case '=': goto yy53; default: goto yy49; }yy49:{ --YYCURSOR; goto state_next_arg_begin; }yy50: ++YYCURSOR; yych = *YYCURSOR; goto yy54;yy51:{ passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }yy52: yych = *++YYCURSOR; goto yy49;yy53: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy54;yy54: switch(yych){ case ' ': goto yy53; default: goto yy51; }yy55: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy56;yy56: switch(yych){ case ' ': goto yy55; case '=': goto yy53; default: goto yy57; }yy57: YYCURSOR = YYMARKER; switch(yyaccept){ case 0: goto yy49; }}state_val: start = YYCURSOR;{ YYCTYPE yych; unsigned int yyaccept = 0; goto yy58; ++YYCURSOR;yy58: if((YYLIMIT - YYCURSOR) < 3) YYFILL(3); yych = *YYCURSOR; switch(yych){ case 0x09: case 0x0A: case 0x0D: case ' ': case '>': goto yy64; case '"': goto yy60; case '\'': goto yy62; default: goto yy63; }yy60: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); goto yy77;yy61:{ handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; }yy62: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); goto yy69;yy63: yych = *++YYCURSOR; goto yy67;yy64: ++YYCURSOR; goto yy65;yy65:{ passthru(STD_ARGS); goto state_next_arg_begin; }yy66: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy67;yy67: switch(yych){ case 0x09: case 0x0A: case 0x0D: case ' ': case '>': goto yy61; default: goto yy66; }yy68: yyaccept = 0; YYMARKER = ++YYCURSOR; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; goto yy69;yy69: switch(yych){ case 0x09: case 0x0A: case 0x0D: case ' ': goto yy72; case '\'': goto yy70; case '>': goto yy61; default: goto yy68; }yy70: ++YYCURSOR; switch((yych = *YYCURSOR)) { case 0x09: case 0x0A: case 0x0D: case ' ': case '>': goto yy71; default: goto yy66; }yy71:{ handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }yy72: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy73;yy73: switch(yych){ case '\'': goto yy75; case '>': goto yy74; default: goto yy72; }yy74: YYCURSOR = YYMARKER; switch(yyaccept){ case 0: goto yy61; }yy75: yych = *++YYCURSOR; goto yy71;yy76: yyaccept = 0; YYMARKER = ++YYCURSOR; if((YYLIMIT - YYCURSOR) < 2) YYFILL(2); yych = *YYCURSOR; goto yy77;yy77: switch(yych){ case 0x09: case 0x0A: case 0x0D: case ' ': goto yy80; case '"': goto yy78; case '>': goto yy61; default: goto yy76; }yy78: ++YYCURSOR; switch((yych = *YYCURSOR)) { case 0x09: case 0x0A: case 0x0D: case ' ': case '>': goto yy79; default: goto yy66; }yy79:{ handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }yy80: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; goto yy81;yy81: switch(yych){ case '"': goto yy82; case '>': goto yy74; default: goto yy80; }yy82: ++YYCURSOR; yych = *YYCURSOR; goto yy79;}stop: rest = YYLIMIT - start; scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest)); /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */ if (rest < 0) rest = 0; if (rest) memmove(ctx->buf.c, start, rest); ctx->buf.len = rest;}char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC){ smart_str surl = {0}; smart_str buf = {0}; smart_str url_app = {0}; smart_str_setl(&surl, url, urllen); smart_str_appends(&url_app, name); smart_str_appendc(&url_app, '='); smart_str_appends(&url_app, value); append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output); smart_str_0(&buf); if (newlen) *newlen = buf.len; smart_str_free(&url_app); return buf.c;}static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_bool do_flush TSRMLS_DC){ url_adapt_state_ex_t *ctx; char *retval; ctx = &BG(url_adapt_state_ex); xx_mainloop(ctx, src, srclen TSRMLS_CC); *newlen = ctx->result.len; if (!ctx->result.c) { smart_str_appendl(&ctx->result, "", 0); } smart_str_0(&ctx->result); if (do_flush) { smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len); *newlen += ctx->buf.len; smart_str_free(&ctx->buf); } retval = ctx->result.c; ctx->result.c = NULL; ctx->result.len = 0; return retval;}int php_url_scanner_ex_activate(TSRMLS_D){ url_adapt_state_ex_t *ctx; ctx = &BG(url_adapt_state_ex); memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags)); return SUCCESS;}int php_url_scanner_ex_deactivate(TSRMLS_D){ url_adapt_state_ex_t *ctx; ctx = &BG(url_adapt_state_ex); smart_str_free(&ctx->result); smart_str_free(&ctx->buf); smart_str_free(&ctx->tag); smart_str_free(&ctx->arg); return SUCCESS;}static void php_url_scanner_output_handler(char *output, uint output_len, char **handled_output, uint *handled_output_len, int mode TSRMLS_DC){ size_t len; if (BG(url_adapt_state_ex).url_app.len != 0) { *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC); if (sizeof(uint) < sizeof(size_t)) { if (len > UINT_MAX) len = UINT_MAX; } *handled_output_len = len; } else if (BG(url_adapt_state_ex).url_app.len == 0) { url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex); if (ctx->buf.len) { smart_str_appendl(&ctx->result, ctx->buf.c, ctx->buf.len); smart_str_appendl(&ctx->result, output, output_len); *handled_output = ctx->result.c; *handled_output_len = ctx->buf.len + output_len; ctx->result.c = NULL; ctx->result.len = 0; smart_str_free(&ctx->buf); } else { *handled_output = NULL; } } else { *handled_output = NULL; }}int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC){ char *encoded; int encoded_len; smart_str val; if (! BG(url_adapt_state_ex).active) { php_url_scanner_ex_activate(TSRMLS_C); php_ob_set_internal_handler(php_url_scanner_output_handler, 0, "URL-Rewriter", 1 TSRMLS_CC); BG(url_adapt_state_ex).active = 1; } if (BG(url_adapt_state_ex).url_app.len != 0) { smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output); } if (urlencode) { encoded = php_url_encode(value, value_len, &encoded_len); smart_str_setl(&val, encoded, encoded_len); } else { smart_str_setl(&val, value, value_len); } smart_str_appendl(&BG(url_adapt_state_ex).url_app, name, name_len); smart_str_appendc(&BG(url_adapt_state_ex).url_app, '='); smart_str_append(&BG(url_adapt_state_ex).url_app, &val); smart_str_appends(&BG(url_adapt_state_ex).form_app, "<input type=\"hidden\" name=\""); smart_str_appendl(&BG(url_adapt_state_ex).form_app, name, name_len); smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" value=\""); smart_str_append(&BG(url_adapt_state_ex).form_app, &val); smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />"); if (urlencode) efree(encoded); return SUCCESS;}int php_url_scanner_reset_vars(TSRMLS_D){ BG(url_adapt_state_ex).form_app.len = 0; BG(url_adapt_state_ex).url_app.len = 0; return SUCCESS;}PHP_MINIT_FUNCTION(url_scanner){ BG(url_adapt_state_ex).tags = NULL; BG(url_adapt_state_ex).form_app.c = BG(url_adapt_state_ex).url_app.c = 0; BG(url_adapt_state_ex).form_app.len = BG(url_adapt_state_ex).url_app.len = 0; REGISTER_INI_ENTRIES(); return SUCCESS;}PHP_MSHUTDOWN_FUNCTION(url_scanner){ UNREGISTER_INI_ENTRIES(); return SUCCESS;}PHP_RINIT_FUNCTION(url_scanner){ BG(url_adapt_state_ex).active = 0; return SUCCESS;}PHP_RSHUTDOWN_FUNCTION(url_scanner){ if (BG(url_adapt_state_ex).active) { php_url_scanner_ex_deactivate(TSRMLS_C); BG(url_adapt_state_ex).active = 0; } smart_str_free(&BG(url_adapt_state_ex).form_app); smart_str_free(&BG(url_adapt_state_ex).url_app); return SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -