]> granicus.if.org Git - php/commitdiff
forgot
authorThies C. Arntzen <thies@php.net>
Fri, 3 May 2002 08:32:03 +0000 (08:32 +0000)
committerThies C. Arntzen <thies@php.net>
Fri, 3 May 2002 08:32:03 +0000 (08:32 +0000)
ext/standard/url_scanner_ex.c

index 041890ad9bf740a56b4b2d43c615f7a49c083eac..f84a371e7b514aa342b313c8947ca581860c163a 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by re2c 0.5 on Sun Apr 28 13:46:08 2002 */ 
+/* Generated by re2c 0.5 on Fri May  3 10:31:33 2002 */
 #line 1 "/home/thies/devel/php4/ext/standard/url_scanner_ex.re"
 /*
   +----------------------------------------------------------------------+
@@ -34,7 +34,6 @@
 #include "basic_functions.h"
 #undef STATE_TAG
 
-#define url_adapt_ext url_adapt_ext_ex
 #define url_scanner url_scanner_ex
 
 #include "php_smart_str.h"
@@ -86,7 +85,7 @@ PHP_INI_BEGIN()
        STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=fakeentry", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
 PHP_INI_END()
 
-#line 91
+#line 90
 
 
 #define YYFILL(n) goto done
@@ -95,11 +94,15 @@ PHP_INI_END()
 #define YYLIMIT q
 #define YYMARKER r
        
-static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
+static inline void append_modified_url(smart_str *url, smart_str *dest, HashTable *rewrite_vars, const char *separator)
 {
        register const char *p, *q;
        const char *bash = NULL;
        const char *sep = "?";
+       char *string_key;
+       url_adapt_var_t *value;
+       int num_key;
+
        
        q = (p = url->c) + url->len;
 
@@ -151,25 +154,25 @@ yy0:
        if(yych >= ';') goto yy4;
 yy2:   yych = *++YYCURSOR;
 yy3:
-#line 109
+#line 112
        { smart_str_append(dest, url); return; }
 yy4:   yych = *++YYCURSOR;
 yy5:
-#line 110
+#line 113
        { sep = separator; goto scan; }
 yy6:   yych = *++YYCURSOR;
 yy7:
-#line 111
+#line 114
        { bash = p - 1; goto done; }
 yy8:   ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
 yy9:   if(yybm[0+yych] & 128)  goto yy8;
 yy10:
-#line 112
+#line 115
        { goto scan; }
 }
-#line 113
+#line 116
 
 done:
        
@@ -184,10 +187,16 @@ done:
        else
                smart_str_append(dest, url);
 
-       smart_str_appends(dest, sep);
-       smart_str_append(dest, name);
-       smart_str_appendc(dest, '=');
-       smart_str_append(dest, val);
+       zend_hash_internal_pointer_reset(rewrite_vars);
+       while (zend_hash_get_current_key(rewrite_vars, &string_key, &num_key, 0) != HASH_KEY_NON_EXISTANT) {
+               zend_hash_get_current_data(rewrite_vars, &value);
+               smart_str_appends(dest, sep);
+               smart_str_append(dest, &(value->var));
+               smart_str_appendc(dest, '=');
+               smart_str_append(dest, &(value->val));
+               zend_hash_move_forward(rewrite_vars);
+               sep = separator;  /* switch from ? to now! */
+       }
 
        if (bash)
                smart_str_appendl(dest, bash, q - bash);
@@ -210,7 +219,7 @@ static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSR
        if (quotes)
                smart_str_appendc(&ctx->result, type);
        if (f) {
-               append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator).output);
+               append_modified_url(&ctx->val, &ctx->result, ctx->rewrite_vars, PG(arg_separator).output);
        } else {
                smart_str_append(&ctx->result, &ctx->val);
        }
@@ -245,11 +254,20 @@ static inline void passthru(STD_PARA)
 static inline void handle_form(STD_PARA) 
 {
        if (ctx->tag.len == 4 && strncasecmp(ctx->tag.c, "form", 4) == 0) {
-               smart_str_appends(&ctx->result, "<input type=\"hidden\" name=\""); 
-               smart_str_append(&ctx->result, &ctx->q_name);
-               smart_str_appends(&ctx->result, "\" value=\"");
-               smart_str_append(&ctx->result, &ctx->q_value);
-               smart_str_appends(&ctx->result, "\" />");
+               char *string_key;
+               url_adapt_var_t *value;
+               int num_key;
+
+               zend_hash_internal_pointer_reset(ctx->rewrite_vars);
+               while (zend_hash_get_current_key(ctx->rewrite_vars, &string_key, &num_key, 0) != HASH_KEY_NON_EXISTANT) {
+                       zend_hash_get_current_data(ctx->rewrite_vars, &value);
+                       smart_str_appends(&ctx->result, "<input type=\"hidden\" name=\""); 
+                       smart_str_append(&ctx->result, &(value->var));
+                       smart_str_appends(&ctx->result, "\" value=\"");
+                       smart_str_append(&ctx->result, &(value->val));
+                       smart_str_appends(&ctx->result, "\" />");
+                       zend_hash_move_forward(ctx->rewrite_vars);
+               }
        }
 }
 
@@ -364,17 +382,17 @@ yy11:
        if(yybm[0+yych] & 128)  goto yy15;
 yy13:  yych = *++YYCURSOR;
 yy14:
-#line 263
+#line 281
        { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; }
 yy15:  ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
        yych = *YYCURSOR;
 yy16:  if(yybm[0+yych] & 128)  goto yy15;
 yy17:
-#line 264
+#line 282
        { passthru(STD_ARGS); goto state_plain; }
 }
-#line 265
+#line 283
 
 
 state_tag:     
@@ -428,11 +446,11 @@ yy18:
 yy20:  yych = *++YYCURSOR;
        goto yy25;
 yy21:
-#line 270
+#line 288
        { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; }
 yy22:  yych = *++YYCURSOR;
 yy23:
-#line 271
+#line 289
        { passthru(STD_ARGS); goto state_plain_begin; }
 yy24:  ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -440,7 +458,7 @@ yy24:       ++YYCURSOR;
 yy25:  if(yybm[0+yych] & 128)  goto yy24;
        goto yy21;
 }
-#line 272
+#line 290
 
 
 state_next_arg_begin:
@@ -511,20 +529,20 @@ yy26:
        }
 yy28:  yych = *++YYCURSOR;
 yy29:
-#line 280
+#line 298
        { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }
 yy30:  yych = *++YYCURSOR;
        goto yy37;
 yy31:
-#line 281
+#line 299
        { passthru(STD_ARGS); goto state_next_arg; }
 yy32:  yych = *++YYCURSOR;
 yy33:
-#line 282
+#line 300
        { --YYCURSOR; STATE = STATE_ARG; goto state_arg; }
 yy34:  yych = *++YYCURSOR;
 yy35:
-#line 283
+#line 301
        { passthru(STD_ARGS); goto state_plain_begin; }
 yy36:  ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -532,7 +550,7 @@ yy36:       ++YYCURSOR;
 yy37:  if(yybm[0+yych] & 128)  goto yy36;
        goto yy31;
 }
-#line 284
+#line 302
 
 
 state_arg:
@@ -586,11 +604,11 @@ yy38:
 yy40:  yych = *++YYCURSOR;
        goto yy45;
 yy41:
-#line 289
+#line 307
        { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }
 yy42:  yych = *++YYCURSOR;
 yy43:
-#line 290
+#line 308
        { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }
 yy44:  ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -598,7 +616,7 @@ yy44:       ++YYCURSOR;
 yy45:  if(yybm[0+yych] & 128)  goto yy44;
        goto yy41;
 }
-#line 291
+#line 309
 
 
 state_before_val:
@@ -653,12 +671,12 @@ yy48:     yyaccept = 0;
        if(yych == ' ') goto yy55;
        if(yych == '=') goto yy53;
 yy49:
-#line 297
+#line 315
        { --YYCURSOR; goto state_next_arg_begin; }
 yy50:  yych = *++YYCURSOR;
        goto yy54;
 yy51:
-#line 296
+#line 314
        { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }
 yy52:  yych = *++YYCURSOR;
        goto yy49;
@@ -677,7 +695,7 @@ yy57:       YYCURSOR = YYMARKER;
        case 0: goto yy49;
        }
 }
-#line 298
+#line 316
 
 
 
@@ -747,7 +765,7 @@ yy60:       yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
        if(yych != '>') goto yy74;
 yy61:
-#line 307
+#line 325
        { passthru(STD_ARGS); goto state_next_arg_begin; }
 yy62:  yyaccept = 0;
        yych = *(YYMARKER = ++YYCURSOR);
@@ -756,7 +774,7 @@ yy62:       yyaccept = 0;
 yy63:  yych = *++YYCURSOR;
        goto yy67;
 yy64:
-#line 306
+#line 324
        { handle_val(STD_ARGS, 0, '"'); goto state_next_arg_begin; }
 yy65:  yych = *++YYCURSOR;
        goto yy61;
@@ -776,7 +794,7 @@ yy70:       YYCURSOR = YYMARKER;
        }
 yy71:  yych = *++YYCURSOR;
 yy72:
-#line 305
+#line 323
        { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }
 yy73:  ++YYCURSOR;
        if(YYLIMIT == YYCURSOR) YYFILL(1);
@@ -785,10 +803,10 @@ yy74:     if(yybm[0+yych] & 128)  goto yy73;
        if(yych >= '>') goto yy70;
 yy75:  yych = *++YYCURSOR;
 yy76:
-#line 304
+#line 322
        { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }
 }
-#line 308
+#line 326
 
 
 stop:
@@ -802,34 +820,13 @@ stop:
 }
 
 
-char *url_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 sname = {0};
-       smart_str sval = {0};
-
-       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).output);
-
-       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, zend_bool do_flush TSRMLS_DC)
+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);
 
-       smart_str_sets(&ctx->q_name, name);
-       smart_str_sets(&ctx->q_value, value);
        xx_mainloop(ctx, src, srclen TSRMLS_CC);
 
        *newlen = ctx->result.len;
@@ -873,14 +870,66 @@ int php_url_scanner_ex_deactivate(TSRMLS_D)
        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)
+{
+    if (BG(url_adapt_state_ex).rewrite_vars && zend_hash_num_elements(BG(url_adapt_state_ex).rewrite_vars)) {
+        *handled_output = url_adapt_ext(output, output_len, handled_output_len, (zend_bool) (mode&PHP_OUTPUT_HANDLER_END ? 1 : 0) TSRMLS_CC);
+    } else {
+        *handled_output = NULL;
+    }
+}
+
+static void php_url_scanner_var_dtor(url_adapt_var_t *var)
+{
+       smart_str_free(&(var->var));
+       smart_str_free(&(var->val));
+}
+
+int php_url_scanner_add_var(char *name, int name_len, char *value, int value_len, int urlencode TSRMLS_DC)
+{
+       url_adapt_var_t var;
+       char *encoded;
+       int encoded_len;
+
+       if (! BG(url_adapt_state_ex).active) {
+               int chunk_size = 4096; /* XXX where should we get chunk_size from? */
+
+               php_url_scanner_ex_activate(TSRMLS_C);
+               php_start_ob_buffer(NULL, chunk_size, 1 TSRMLS_CC);
+               php_ob_set_internal_handler(php_url_scanner_output_handler, chunk_size, "URL-Rewriter", 1 TSRMLS_CC);
+               BG(url_adapt_state_ex).active = 1;
+       }
+
+       if (! BG(url_adapt_state_ex).rewrite_vars) {
+               BG(url_adapt_state_ex).rewrite_vars = emalloc(sizeof(HashTable));
+               zend_hash_init(BG(url_adapt_state_ex).rewrite_vars, 0, NULL, (void (*)(void *)) php_url_scanner_var_dtor, 0);
+       }
+
+       smart_str_setl(&(var.var), estrndup(name, name_len), name_len);
+
+       if (urlencode) {
+               encoded = php_url_encode(value, value_len, &encoded_len);
+               smart_str_setl(&(var.val), encoded, encoded_len);
+       } else {
+               smart_str_setl(&(var.val), estrndup(value, value_len), value_len);
+       }
+
+       return zend_hash_add(BG(url_adapt_state_ex).rewrite_vars, name, name_len, &var, sizeof(url_adapt_var_t), NULL);
+}
+
+int php_url_scanner_remove_var(char *name, int name_len TSRMLS_DC)
+{
+       if (BG(url_adapt_state_ex).rewrite_vars) {
+               return zend_hash_del(BG(url_adapt_state_ex).rewrite_vars, name, name_len);
+       }
+
+       return FAILURE;
+}
+
 PHP_MINIT_FUNCTION(url_scanner)
 {
-       url_adapt_state_ex_t *ctx;
-       
-       ctx = &BG(url_adapt_state_ex);
+       BG(url_adapt_state_ex).tags = NULL;
 
-       ctx->tags = NULL;
-       
        REGISTER_INI_ENTRIES();
        return SUCCESS;
 }
@@ -890,5 +939,30 @@ PHP_MSHUTDOWN_FUNCTION(url_scanner)
        UNREGISTER_INI_ENTRIES();
        zend_hash_destroy(BG(url_adapt_state_ex).tags);
        free(BG(url_adapt_state_ex).tags);
+
+       return SUCCESS;
+}
+
+PHP_RINIT_FUNCTION(url_scanner)
+{
+       BG(url_adapt_state_ex).active = 0;
+       BG(url_adapt_state_ex).rewrite_vars = NULL;
+
+       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;
+       }
+
+       if (BG(url_adapt_state_ex).rewrite_vars) {
+               zend_hash_destroy(BG(url_adapt_state_ex).rewrite_vars);
+               efree(BG(url_adapt_state_ex).rewrite_vars);
+               BG(url_adapt_state_ex).rewrite_vars = NULL;
+       }
+
        return SUCCESS;
 }