From c57830c1d21fcf03745149e2a9f23c94c2d54b50 Mon Sep 17 00:00:00 2001 From: Sascha Schumann Date: Thu, 26 Oct 2000 18:05:47 +0000 Subject: [PATCH] Reinstantiate single quotes properly. Add url_adapt_single_url() API which modifies a single URL. Might be used to modify the Location: URL. --- ext/standard/url_scanner_ex.c | 94 +++++++++++++++++++++------------- ext/standard/url_scanner_ex.h | 2 + ext/standard/url_scanner_ex.re | 46 ++++++++++++----- 3 files changed, 92 insertions(+), 50 deletions(-) diff --git a/ext/standard/url_scanner_ex.c b/ext/standard/url_scanner_ex.c index c89420e71a..c52ef2e87b 100644 --- a/ext/standard/url_scanner_ex.c +++ b/ext/standard/url_scanner_ex.c @@ -1,4 +1,4 @@ -/* Generated by re2c 0.5 on Thu Oct 19 19:46:51 2000 */ +/* Generated by re2c 0.5 on Thu Oct 26 20:28:43 2000 */ #line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re" /* +----------------------------------------------------------------------+ @@ -131,20 +131,20 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st smart_str_appendl(dest, bash, q - bash); } -static inline void tag_arg(url_adapt_state_ex_t *ctx PLS_DC) +static inline void tag_arg(url_adapt_state_ex_t *ctx, char quote PLS_DC) { char f = 0; if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0) f = 1; - smart_str_appendc(&ctx->result, '"'); + smart_str_appendc(&ctx->result, quote); if (f) { append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator)); } else { smart_str_append(&ctx->result, &ctx->val); } - smart_str_appendc(&ctx->result, '"'); + smart_str_appendc(&ctx->result, quote); } enum { @@ -187,20 +187,22 @@ enum { #define HANDLE_TAG() {\ int ok = 0; \ int i; \ - smart_str_copyl(&ctx->tag, start, YYCURSOR - start); \ + ctx->tag.len = 0; \ + smart_str_appendl(&ctx->tag, start, YYCURSOR - start); \ for (i = 0; i < ctx->tag.len; i++) \ ctx->tag.c[i] = tolower(ctx->tag.c[i]); \ - if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, &ctx->lookup_data) == SUCCESS) \ + if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS) \ ok = 1; \ STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; \ } #define HANDLE_ARG() {\ - smart_str_copyl(&ctx->arg, start, YYCURSOR - start); \ + ctx->arg.len = 0; \ + smart_str_appendl(&ctx->arg, start, YYCURSOR - start); \ } -#define HANDLE_VAL(quotes) {\ +#define HANDLE_VAL(quotes, type) {\ smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2); \ - tag_arg(ctx PLS_CC); \ + tag_arg(ctx, type PLS_CC); \ } #ifdef SCANNER_DEBUG @@ -222,7 +224,7 @@ static inline void mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size YYCURSOR = ctx->buf.c; YYLIMIT = ctx->buf.c + ctx->buf.len; -#line 226 +#line 228 while(1) { @@ -242,14 +244,14 @@ yy0: if(yych != '<') goto yy4; yy2: yych = *++YYCURSOR; yy3: -#line 235 +#line 237 { PASSTHRU(); STATE = STATE_TAG; continue; } yy4: yych = *++YYCURSOR; yy5: -#line 236 +#line 238 { PASSTHRU(); continue; } } -#line 237 +#line 239 break; @@ -303,11 +305,11 @@ yy6: yy8: yych = *++YYCURSOR; goto yy13; yy9: -#line 242 +#line 244 { HANDLE_TAG() /* Sets STATE */; PASSTHRU(); continue; } yy10: yych = *++YYCURSOR; yy11: -#line 243 +#line 245 { PASSTHRU(); STATE = STATE_PLAIN; continue; } yy12: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -315,7 +317,7 @@ yy12: ++YYCURSOR; yy13: if(yybm[0+yych] & 128) goto yy12; goto yy9; } -#line 244 +#line 246 break; @@ -349,22 +351,22 @@ yy14: } yy16: yych = *++YYCURSOR; yy17: -#line 249 +#line 251 { PASSTHRU(); HANDLE_FORM(); STATE = STATE_PLAIN; continue; } yy18: yych = *++YYCURSOR; yy19: -#line 250 +#line 252 { PASSTHRU(); continue; } yy20: yych = *++YYCURSOR; yy21: -#line 251 +#line 253 { YYCURSOR--; STATE = STATE_ARG; continue; } yy22: yych = *++YYCURSOR; yy23: -#line 252 +#line 254 { PASSTHRU(); continue; } } -#line 253 +#line 255 break; @@ -418,11 +420,11 @@ yy24: yy26: yych = *++YYCURSOR; goto yy31; yy27: -#line 258 +#line 260 { PASSTHRU(); HANDLE_ARG(); STATE = STATE_BEFORE_VAL; continue; } yy28: yych = *++YYCURSOR; yy29: -#line 259 +#line 261 { PASSTHRU(); STATE = STATE_NEXT_ARG; continue; } yy30: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); @@ -430,7 +432,7 @@ yy30: ++YYCURSOR; yy31: if(yybm[0+yych] & 128) goto yy30; goto yy27; } -#line 260 +#line 262 case STATE_BEFORE_VAL: @@ -484,12 +486,12 @@ yy34: yyaccept = 0; if(yych == ' ') goto yy41; if(yych == '=') goto yy39; yy35: -#line 265 +#line 267 { YYCURSOR--; STATE = STATE_NEXT_ARG; continue; } yy36: yych = *++YYCURSOR; goto yy40; yy37: -#line 264 +#line 266 { PASSTHRU(); STATE = STATE_VAL; continue; } yy38: yych = *++YYCURSOR; goto yy35; @@ -508,7 +510,7 @@ yy43: YYCURSOR = YYMARKER; case 0: goto yy35; } } -#line 266 +#line 268 break; @@ -577,14 +579,14 @@ yy46: yyaccept = 0; yych = *(YYMARKER = ++YYCURSOR); if(yych != '>') goto yy63; yy47: -#line 274 +#line 276 { PASSTHRU(); STATE = STATE_NEXT_ARG; continue; } yy48: yyaccept = 1; yych = *(YYMARKER = ++YYCURSOR); goto yy55; yy49: -#line 273 - { HANDLE_VAL(0); STATE = STATE_NEXT_ARG; continue; } +#line 275 + { HANDLE_VAL(0, '"'); STATE = STATE_NEXT_ARG; continue; } yy50: yych = *++YYCURSOR; goto yy53; yy51: yych = *++YYCURSOR; @@ -604,8 +606,8 @@ yy55: if(yybm[0+yych] & 32) goto yy54; yy56: yych = *++YYCURSOR; if(yybm[0+yych] & 16) goto yy52; yy57: -#line 272 - { HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; } +#line 274 + { HANDLE_VAL(1, '\''); STATE = STATE_NEXT_ARG; continue; } yy58: ++YYCURSOR; if(YYLIMIT == YYCURSOR) YYFILL(1); yych = *YYCURSOR; @@ -625,10 +627,10 @@ yy63: if(yybm[0+yych] & 128) goto yy62; if(yych >= '>') goto yy60; yy64: yych = *++YYCURSOR; yy65: -#line 271 - { HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; } +#line 273 + { HANDLE_VAL(1, '"'); STATE = STATE_NEXT_ARG; continue; } } -#line 275 +#line 277 break; } @@ -646,6 +648,26 @@ stop: ctx->buf.len = rest; } +char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen) +{ + smart_str surl = {0}; + smart_str buf = {0}; + smart_str sname = {0}; + smart_str sval = {0}; + PLS_FETCH(); + + smart_str_setl(&surl, url, urllen); + smart_str_sets(&sname, name); + smart_str_sets(&sval, value); + + append_modified_url(&surl, &buf, &sname, &sval, PG(arg_separator)); + + smart_str_0(&buf); + if (newlen) *newlen = buf.len; + + return buf.c; +} + char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen) { char *ret; @@ -659,14 +681,12 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char mainloop(ctx, src, srclen); *newlen = ctx->result.len; - if (ctx->result.len == 0) { return strdup(""); } smart_str_0(&ctx->result); ret = malloc(ctx->result.len + 1); memcpy(ret, ctx->result.c, ctx->result.len + 1); - ctx->result.len = 0; return ret; } diff --git a/ext/standard/url_scanner_ex.h b/ext/standard/url_scanner_ex.h index eaaf2e2074..d537b89a9f 100644 --- a/ext/standard/url_scanner_ex.h +++ b/ext/standard/url_scanner_ex.h @@ -26,6 +26,8 @@ PHP_RINIT_FUNCTION(url_scanner_ex); char *url_adapt_ext_ex(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen); +char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen); + #include "php_smart_str_public.h" typedef struct { diff --git a/ext/standard/url_scanner_ex.re b/ext/standard/url_scanner_ex.re index b4a108d6d2..2efdab9a88 100644 --- a/ext/standard/url_scanner_ex.re +++ b/ext/standard/url_scanner_ex.re @@ -129,20 +129,20 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st smart_str_appendl(dest, bash, q - bash); } -static inline void tag_arg(url_adapt_state_ex_t *ctx PLS_DC) +static inline void tag_arg(url_adapt_state_ex_t *ctx, char quote PLS_DC) { char f = 0; if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0) f = 1; - smart_str_appendc(&ctx->result, '"'); + smart_str_appendc(&ctx->result, quote); if (f) { append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator)); } else { smart_str_append(&ctx->result, &ctx->val); } - smart_str_appendc(&ctx->result, '"'); + smart_str_appendc(&ctx->result, quote); } enum { @@ -185,20 +185,22 @@ enum { #define HANDLE_TAG() {\ int ok = 0; \ int i; \ - smart_str_copyl(&ctx->tag, start, YYCURSOR - start); \ + ctx->tag.len = 0; \ + smart_str_appendl(&ctx->tag, start, YYCURSOR - start); \ for (i = 0; i < ctx->tag.len; i++) \ ctx->tag.c[i] = tolower(ctx->tag.c[i]); \ - if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, &ctx->lookup_data) == SUCCESS) \ + if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, (void **) &ctx->lookup_data) == SUCCESS) \ ok = 1; \ STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; \ } #define HANDLE_ARG() {\ - smart_str_copyl(&ctx->arg, start, YYCURSOR - start); \ + ctx->arg.len = 0; \ + smart_str_appendl(&ctx->arg, start, YYCURSOR - start); \ } -#define HANDLE_VAL(quotes) {\ +#define HANDLE_VAL(quotes, type) {\ smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2); \ - tag_arg(ctx PLS_CC); \ + tag_arg(ctx, type PLS_CC); \ } #ifdef SCANNER_DEBUG @@ -268,9 +270,9 @@ alpha = [a-zA-Z]; case STATE_VAL: /*!re2c - ["] (any\[">])* ["] { HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; } - ['] (any\['>])* ['] { HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; } - (any\[ \n>"])+ { HANDLE_VAL(0); STATE = STATE_NEXT_ARG; continue; } + ["] (any\[">])* ["] { HANDLE_VAL(1, '"'); STATE = STATE_NEXT_ARG; continue; } + ['] (any\['>])* ['] { HANDLE_VAL(1, '\''); STATE = STATE_NEXT_ARG; continue; } + (any\[ \n>"])+ { HANDLE_VAL(0, '"'); STATE = STATE_NEXT_ARG; continue; } any { PASSTHRU(); STATE = STATE_NEXT_ARG; continue; } */ break; @@ -289,6 +291,26 @@ stop: ctx->buf.len = rest; } +char *url_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen) +{ + smart_str surl = {0}; + smart_str buf = {0}; + smart_str sname = {0}; + smart_str sval = {0}; + PLS_FETCH(); + + smart_str_setl(&surl, url, urllen); + smart_str_sets(&sname, name); + smart_str_sets(&sval, value); + + append_modified_url(&surl, &buf, &sname, &sval, PG(arg_separator)); + + smart_str_0(&buf); + if (newlen) *newlen = buf.len; + + return buf.c; +} + char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char *value, size_t *newlen) { char *ret; @@ -302,14 +324,12 @@ char *url_adapt_ext(const char *src, size_t srclen, const char *name, const char mainloop(ctx, src, srclen); *newlen = ctx->result.len; - if (ctx->result.len == 0) { return strdup(""); } smart_str_0(&ctx->result); ret = malloc(ctx->result.len + 1); memcpy(ret, ctx->result.c, ctx->result.len + 1); - ctx->result.len = 0; return ret; } -- 2.50.1