PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - lcov_data/ext/standard - url_scanner_ex.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 127 166 76.5 %
Date: 2014-12-13 Functions: 0 0 -
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* Generated by re2c 0.13.5 */
       2             : #line 1 "ext/standard/url_scanner_ex.re"
       3             : /*
       4             :   +----------------------------------------------------------------------+
       5             :   | PHP Version 7                                                        |
       6             :   +----------------------------------------------------------------------+
       7             :   | Copyright (c) 1997-2014 The PHP Group                                |
       8             :   +----------------------------------------------------------------------+
       9             :   | This source file is subject to version 3.01 of the PHP license,      |
      10             :   | that is bundled with this package in the file LICENSE, and is        |
      11             :   | available through the world-wide-web at the following url:           |
      12             :   | http://www.php.net/license/3_01.txt                                  |
      13             :   | If you did not receive a copy of the PHP license and are unable to   |
      14             :   | obtain it through the world-wide-web, please send a note to          |
      15             :   | license@php.net so we can mail you a copy immediately.               |
      16             :   +----------------------------------------------------------------------+
      17             :   | Author: Sascha Schumann <sascha@schumann.cx>                         |
      18             :   +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include "php.h"
      24             : 
      25             : #ifdef HAVE_UNISTD_H
      26             : #include <unistd.h>
      27             : #endif
      28             : #ifdef HAVE_LIMITS_H
      29             : #include <limits.h>
      30             : #endif
      31             : 
      32             : #include <stdio.h>
      33             : #include <stdlib.h>
      34             : #include <string.h>
      35             : 
      36             : #include "php_ini.h"
      37             : #include "php_globals.h"
      38             : #define STATE_TAG SOME_OTHER_STATE_TAG
      39             : #include "basic_functions.h"
      40             : #include "url.h"
      41             : #undef STATE_TAG
      42             : 
      43             : #define url_scanner url_scanner_ex
      44             : 
      45             : #include "zend_smart_str.h"
      46             : 
      47             : static void tag_dtor(zval *zv)
      48             : {
      49             :         free(Z_PTR_P(zv));
      50             : }
      51             : 
      52             : static PHP_INI_MH(OnUpdateTags)
      53             : {
      54             :         url_adapt_state_ex_t *ctx;
      55             :         char *key;
      56             :         char *lasts;
      57             :         char *tmp;
      58             :         
      59             :         ctx = &BG(url_adapt_state_ex);
      60             :         
      61             :         tmp = estrndup(new_value->val, new_value->len);
      62             :         
      63             :         if (ctx->tags)
      64             :                 zend_hash_destroy(ctx->tags);
      65             :         else {
      66             :                 ctx->tags = malloc(sizeof(HashTable));
      67             :                 if (!ctx->tags) {
      68             :                         return FAILURE;
      69             :                 }
      70             :         }
      71             : 
      72             :         zend_hash_init(ctx->tags, 0, NULL, tag_dtor, 1);
      73             :         
      74             :         for (key = php_strtok_r(tmp, ",", &lasts);
      75             :                         key;
      76             :                         key = php_strtok_r(NULL, ",", &lasts)) {
      77             :                 char *val;
      78             : 
      79             :                 val = strchr(key, '=');
      80             :                 if (val) {
      81             :                         char *q;
      82             :                         size_t keylen;
      83             :                         
      84             :                         *val++ = '\0';
      85             :                         for (q = key; *q; q++)
      86             :                                 *q = tolower(*q);
      87             :                         keylen = q - key;
      88             :                         /* key is stored withOUT NUL
      89             :                            val is stored WITH    NUL */
      90             :                         zend_hash_str_add_mem(ctx->tags, key, keylen, val, strlen(val)+1);
      91             :                 }
      92             :         }
      93             : 
      94             :         efree(tmp);
      95             : 
      96             :         return SUCCESS;
      97             : }
      98             : 
      99             : PHP_INI_BEGIN()
     100             :         STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=,fieldset=", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
     101             : PHP_INI_END()
     102             : 
     103             : #line 107 "ext/standard/url_scanner_ex.re"
     104             : 
     105             : 
     106             : #define YYFILL(n) goto done
     107             : #define YYCTYPE unsigned char
     108             : #define YYCURSOR p
     109             : #define YYLIMIT q
     110             : #define YYMARKER r
     111             :         
     112             : static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *url_app, const char *separator)
     113             : {
     114             :         register const char *p, *q;
     115             :         const char *bash = NULL;
     116             :         const char *sep = "?";
     117             :         
     118             :         q = (p = url->s->val) + url->s->len;
     119             : 
     120             : scan:
     121             : 
     122             : #line 123 "ext/standard/url_scanner_ex.c"
     123             : {
     124             :         YYCTYPE yych;
     125             :         static const unsigned char yybm[] = {
     126             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     127             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     128             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     129             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     130             :                 128, 128, 128,   0, 128, 128, 128, 128, 
     131             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     132             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     133             :                 128, 128,   0, 128, 128, 128, 128,   0, 
     134             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     135             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     136             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     137             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     138             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     139             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     140             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     141             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     142             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     143             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     144             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     145             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     146             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     147             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     148             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     149             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     150             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     151             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     152             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     153             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     154             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     155             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     156             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     157             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     158             :         };
     159             : 
     160          32 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     161          30 :         yych = *YYCURSOR;
     162          30 :         if (yybm[0+yych] & 128) {
     163          21 :                 goto yy8;
     164             :         }
     165           9 :         if (yych <= '9') goto yy6;
     166           9 :         if (yych >= ';') goto yy4;
     167           0 :         ++YYCURSOR;
     168             : #line 125 "ext/standard/url_scanner_ex.re"
     169             :         { smart_str_append_smart_str(dest, url); return; }
     170             : #line 171 "ext/standard/url_scanner_ex.c"
     171             : yy4:
     172           9 :         ++YYCURSOR;
     173             : #line 126 "ext/standard/url_scanner_ex.re"
     174             :         { sep = separator; goto scan; }
     175             : #line 176 "ext/standard/url_scanner_ex.c"
     176             : yy6:
     177           0 :         ++YYCURSOR;
     178             : #line 127 "ext/standard/url_scanner_ex.re"
     179             :         { bash = p - 1; goto done; }
     180             : #line 181 "ext/standard/url_scanner_ex.c"
     181             : yy8:
     182         181 :         ++YYCURSOR;
     183         181 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     184         167 :         yych = *YYCURSOR;
     185         167 :         if (yybm[0+yych] & 128) {
     186         160 :                 goto yy8;
     187             :         }
     188             : #line 128 "ext/standard/url_scanner_ex.re"
     189             :         { goto scan; }
     190             : #line 191 "ext/standard/url_scanner_ex.c"
     191             : }
     192             : #line 129 "ext/standard/url_scanner_ex.re"
     193             : 
     194             : done:
     195             :         
     196             :         /* Don't modify URLs of the format "#mark" */
     197             :         if (bash && bash - url->s->val == 0) {
     198             :                 smart_str_append_smart_str(dest, url);
     199             :                 return;
     200             :         }
     201             : 
     202             :         if (bash)
     203             :                 smart_str_appendl(dest, url->s->val, bash - url->s->val);
     204             :         else
     205             :                 smart_str_append_smart_str(dest, url);
     206             : 
     207             :         smart_str_appends(dest, sep);
     208             :         smart_str_append_smart_str(dest, url_app);
     209             : 
     210             :         if (bash)
     211             :                 smart_str_appendl(dest, bash, q - bash);
     212             : }
     213             : 
     214             : 
     215             : #undef YYFILL
     216             : #undef YYCTYPE
     217             : #undef YYCURSOR
     218             : #undef YYLIMIT
     219             : #undef YYMARKER
     220             : 
     221             : static inline void tag_arg(url_adapt_state_ex_t *ctx, char quotes, char type TSRMLS_DC)
     222             : {
     223             :         char f = 0;
     224             : 
     225             :         if (strncasecmp(ctx->arg.s->val, ctx->lookup_data, ctx->arg.s->len) == 0)
     226             :                 f = 1;
     227             : 
     228             :         if (quotes)
     229             :                 smart_str_appendc(&ctx->result, type);
     230             :         if (f) {
     231             :                 append_modified_url(&ctx->val, &ctx->result, &ctx->url_app, PG(arg_separator).output);
     232             :         } else {
     233             :                 smart_str_append_smart_str(&ctx->result, &ctx->val);
     234             :         }
     235             :         if (quotes)
     236             :                 smart_str_appendc(&ctx->result, type);
     237             : }
     238             : 
     239             : enum {
     240             :         STATE_PLAIN = 0,
     241             :         STATE_TAG,
     242             :         STATE_NEXT_ARG,
     243             :         STATE_ARG,
     244             :         STATE_BEFORE_VAL,
     245             :         STATE_VAL
     246             : };
     247             : 
     248             : #define YYFILL(n) goto stop
     249             : #define YYCTYPE unsigned char
     250             : #define YYCURSOR xp
     251             : #define YYLIMIT end
     252             : #define YYMARKER q
     253             : #define STATE ctx->state
     254             : 
     255             : #define STD_PARA url_adapt_state_ex_t *ctx, char *start, char *YYCURSOR TSRMLS_DC
     256             : #define STD_ARGS ctx, start, xp TSRMLS_CC
     257             : 
     258             : #if SCANNER_DEBUG
     259             : #define scdebug(x) printf x
     260             : #else
     261             : #define scdebug(x)
     262             : #endif
     263             : 
     264             : static inline void passthru(STD_PARA) 
     265             : {
     266             :         scdebug(("appending %d chars, starting with %c\n", YYCURSOR-start, *start));
     267             :         smart_str_appendl(&ctx->result, start, YYCURSOR - start);
     268             : }
     269             : 
     270             : /*
     271             :  * This function appends a hidden input field after a <form> or
     272             :  * <fieldset>.  The latter is important for XHTML.
     273             :  */
     274             : 
     275             : static void handle_form(STD_PARA) 
     276             : {
     277             :         int doit = 0;
     278             : 
     279             :         if (ctx->form_app.s->len > 0) {
     280             :                 switch (ctx->tag.s->len) {
     281             :                         case sizeof("form") - 1:
     282             :                                 if (!strncasecmp(ctx->tag.s->val, "form", sizeof("form") - 1)) {
     283             :                                         doit = 1;               
     284             :                                 }
     285             :                                 if (doit && ctx->val.s && ctx->lookup_data && *ctx->lookup_data) {
     286             :                                         char *e, *p = (char *)zend_memnstr(ctx->val.s->val, "://", sizeof("://") - 1, ctx->val.s->val + ctx->val.s->len);
     287             :                                         if (p) {
     288             :                                                 e = memchr(p, '/', (ctx->val.s->val + ctx->val.s->len) - p);
     289             :                                                 if (!e) {
     290             :                                                         e = ctx->val.s->val + ctx->val.s->len;
     291             :                                                 }
     292             :                                                 if ((e - p) && strncasecmp(p, ctx->lookup_data, (e - p))) {
     293             :                                                         doit = 0;
     294             :                                                 }
     295             :                                         }
     296             :                                 }
     297             :                                 break;
     298             : 
     299             :                         case sizeof("fieldset") - 1:
     300             :                                 if (!strncasecmp(ctx->tag.s->val, "fieldset", sizeof("fieldset") - 1)) {
     301             :                                         doit = 1;               
     302             :                                 }
     303             :                                 break;
     304             :                 }
     305             : 
     306             :                 if (doit)
     307             :                         smart_str_append_smart_str(&ctx->result, &ctx->form_app);
     308             :         }
     309             : }
     310             : 
     311             : /*
     312             :  *  HANDLE_TAG copies the HTML Tag and checks whether we 
     313             :  *  have that tag in our table. If we might modify it,
     314             :  *  we continue to scan the tag, otherwise we simply copy the complete
     315             :  *  HTML stuff to the result buffer.
     316             :  */
     317             : 
     318             : static inline void handle_tag(STD_PARA) 
     319             : {
     320             :         int ok = 0;
     321             :         unsigned int i;
     322             : 
     323             :         if (ctx->tag.s) {
     324             :                 ctx->tag.s->len = 0;
     325             :         }
     326             :         smart_str_appendl(&ctx->tag, start, YYCURSOR - start);
     327             :         for (i = 0; i < ctx->tag.s->len; i++)
     328             :                 ctx->tag.s->val[i] = tolower((int)(unsigned char)ctx->tag.s->val[i]);
     329             :     /* intentionally using str_find here, in case the hash value is set, but the string val is changed later */
     330             :         if ((ctx->lookup_data = zend_hash_str_find_ptr(ctx->tags, ctx->tag.s->val, ctx->tag.s->len)) != NULL)
     331             :                 ok = 1;
     332             :         STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN;
     333             : }
     334             : 
     335             : static inline void handle_arg(STD_PARA) 
     336             : {
     337             :         if (ctx->arg.s) {
     338             :                 ctx->arg.s->len = 0;
     339             :         }
     340             :         smart_str_appendl(&ctx->arg, start, YYCURSOR - start);
     341             : }
     342             : 
     343             : static inline void handle_val(STD_PARA, char quotes, char type) 
     344             : {
     345             :         smart_str_setl(&ctx->val, start + quotes, YYCURSOR - start - quotes * 2);
     346             :         tag_arg(ctx, quotes, type TSRMLS_CC);
     347             : }
     348             : 
     349             : static inline void xx_mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size_t newlen TSRMLS_DC)
     350             : {
     351             :         char *end, *q;
     352             :         char *xp;
     353             :         char *start;
     354             :         size_t rest;
     355             : 
     356             :         smart_str_appendl(&ctx->buf, newdata, newlen);
     357             :         
     358             :         YYCURSOR = ctx->buf.s->val;
     359             :         YYLIMIT = ctx->buf.s->val + ctx->buf.s->len;
     360             : 
     361             :         switch (STATE) {
     362             :                 case STATE_PLAIN: goto state_plain;
     363             :                 case STATE_TAG: goto state_tag;
     364             :                 case STATE_NEXT_ARG: goto state_next_arg;
     365             :                 case STATE_ARG: goto state_arg;
     366             :                 case STATE_BEFORE_VAL: goto state_before_val;
     367             :                 case STATE_VAL: goto state_val;
     368             :         }
     369             :         
     370             : 
     371             : state_plain_begin:
     372             :         STATE = STATE_PLAIN;
     373             :         
     374             : state_plain:
     375             :         start = YYCURSOR;
     376             : 
     377             : #line 378 "ext/standard/url_scanner_ex.c"
     378             : {
     379             :         YYCTYPE yych;
     380             :         static const unsigned char yybm[] = {
     381             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     382             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     383             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     384             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     385             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     386             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     387             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     388             :                 128, 128, 128, 128,   0, 128, 128, 128, 
     389             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     390             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     391             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     392             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     393             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     394             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     395             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     396             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     397             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     398             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     399             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     400             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     401             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     402             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     403             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     404             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     405             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     406             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     407             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     408             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     409             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     410             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     411             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     412             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     413             :         };
     414          85 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     415          84 :         yych = *YYCURSOR;
     416          84 :         if (yybm[0+yych] & 128) {
     417          42 :                 goto yy15;
     418             :         }
     419          42 :         ++YYCURSOR;
     420             : #line 313 "ext/standard/url_scanner_ex.re"
     421             :         { passthru(STD_ARGS); STATE = STATE_TAG; goto state_tag; }
     422             : #line 423 "ext/standard/url_scanner_ex.c"
     423             : yy15:
     424         240 :         ++YYCURSOR;
     425         240 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     426         227 :         yych = *YYCURSOR;
     427         227 :         if (yybm[0+yych] & 128) {
     428         198 :                 goto yy15;
     429             :         }
     430             : #line 314 "ext/standard/url_scanner_ex.re"
     431             :         { passthru(STD_ARGS); goto state_plain; }
     432             : #line 433 "ext/standard/url_scanner_ex.c"
     433             : }
     434             : #line 315 "ext/standard/url_scanner_ex.re"
     435             : 
     436             : 
     437             : state_tag:      
     438             :         start = YYCURSOR;
     439             : 
     440             : #line 441 "ext/standard/url_scanner_ex.c"
     441             : {
     442             :         YYCTYPE yych;
     443             :         static const unsigned char yybm[] = {
     444             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     445             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     446             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     447             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     448             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     449             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     450             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     451             :                   0,   0, 128,   0,   0,   0,   0,   0, 
     452             :                   0, 128, 128, 128, 128, 128, 128, 128, 
     453             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     454             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     455             :                 128, 128, 128,   0,   0,   0,   0,   0, 
     456             :                   0, 128, 128, 128, 128, 128, 128, 128, 
     457             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     458             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     459             :                 128, 128, 128,   0,   0,   0,   0,   0, 
     460             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     461             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     462             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     463             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     464             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     465             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     466             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     467             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     468             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     469             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     470             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     471             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     472             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     473             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     474             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     475             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     476             :         };
     477          42 :         if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
     478          42 :         yych = *YYCURSOR;
     479          42 :         if (yych <= '@') {
     480          10 :                 if (yych != ':') goto yy22;
     481             :         } else {
     482          32 :                 if (yych <= 'Z') goto yy20;
     483          32 :                 if (yych <= '`') goto yy22;
     484          32 :                 if (yych >= '{') goto yy22;
     485             :         }
     486             : yy20:
     487          32 :         ++YYCURSOR;
     488          32 :         yych = *YYCURSOR;
     489          32 :         goto yy25;
     490             : yy21:
     491             : #line 320 "ext/standard/url_scanner_ex.re"
     492             :         { handle_tag(STD_ARGS); /* Sets STATE */; passthru(STD_ARGS); if (STATE == STATE_PLAIN) goto state_plain; else goto state_next_arg; }
     493             : #line 494 "ext/standard/url_scanner_ex.c"
     494             : yy22:
     495          10 :         ++YYCURSOR;
     496             : #line 321 "ext/standard/url_scanner_ex.re"
     497             :         { passthru(STD_ARGS); goto state_plain_begin; }
     498             : #line 499 "ext/standard/url_scanner_ex.c"
     499             : yy24:
     500          58 :         ++YYCURSOR;
     501          58 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     502          58 :         yych = *YYCURSOR;
     503             : yy25:
     504          90 :         if (yybm[0+yych] & 128) {
     505          58 :                 goto yy24;
     506             :         }
     507          32 :         goto yy21;
     508             : }
     509             : #line 322 "ext/standard/url_scanner_ex.re"
     510             : 
     511             : 
     512             : state_next_arg_begin:
     513             :         STATE = STATE_NEXT_ARG;
     514             :         
     515             : state_next_arg:
     516             :         start = YYCURSOR;
     517             : 
     518             : #line 519 "ext/standard/url_scanner_ex.c"
     519             : {
     520             :         YYCTYPE yych;
     521             :         static const unsigned char yybm[] = {
     522             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     523             :                   0, 128, 128, 128,   0, 128,   0,   0, 
     524             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     525             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     526             :                 128,   0,   0,   0,   0,   0,   0,   0, 
     527             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     528             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     529             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     530             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     531             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     532             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     533             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     534             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     535             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     536             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     537             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     538             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     539             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     540             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     541             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     542             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     543             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     544             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     545             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     546             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     547             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     548             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     549             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     550             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     551             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     552             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     553             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     554             :         };
     555          64 :         if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
     556          64 :         yych = *YYCURSOR;
     557          64 :         if (yych <= '.') {
     558          22 :                 if (yych <= '\f') {
     559           0 :                         if (yych <= 0x08) goto yy36;
     560           0 :                         if (yych <= '\v') goto yy32;
     561           0 :                         goto yy36;
     562             :                 } else {
     563          22 :                         if (yych <= '\r') goto yy32;
     564          21 :                         if (yych == ' ') goto yy32;
     565           0 :                         goto yy36;
     566             :                 }
     567             :         } else {
     568          42 :                 if (yych <= '@') {
     569          22 :                         if (yych <= '/') goto yy28;
     570          17 :                         if (yych == '>') goto yy30;
     571           0 :                         goto yy36;
     572             :                 } else {
     573          20 :                         if (yych <= 'Z') goto yy34;
     574          20 :                         if (yych <= '`') goto yy36;
     575          20 :                         if (yych <= 'z') goto yy34;
     576           0 :                         goto yy36;
     577             :                 }
     578             :         }
     579             : yy28:
     580           5 :         ++YYCURSOR;
     581           5 :         if ((yych = *YYCURSOR) == '>') goto yy39;
     582             : yy29:
     583             : #line 333 "ext/standard/url_scanner_ex.re"
     584             :         { passthru(STD_ARGS); goto state_plain_begin; }
     585             : #line 586 "ext/standard/url_scanner_ex.c"
     586             : yy30:
     587          17 :         ++YYCURSOR;
     588             : yy31:
     589             : #line 330 "ext/standard/url_scanner_ex.re"
     590             :         { passthru(STD_ARGS); handle_form(STD_ARGS); goto state_plain_begin; }
     591             : #line 592 "ext/standard/url_scanner_ex.c"
     592             : yy32:
     593          22 :         ++YYCURSOR;
     594          22 :         yych = *YYCURSOR;
     595          22 :         goto yy38;
     596             : yy33:
     597             : #line 331 "ext/standard/url_scanner_ex.re"
     598             :         { passthru(STD_ARGS); goto state_next_arg; }
     599             : #line 600 "ext/standard/url_scanner_ex.c"
     600             : yy34:
     601          20 :         ++YYCURSOR;
     602             : #line 332 "ext/standard/url_scanner_ex.re"
     603             :         { --YYCURSOR; STATE = STATE_ARG; goto state_arg; }
     604             : #line 605 "ext/standard/url_scanner_ex.c"
     605             : yy36:
     606           0 :         yych = *++YYCURSOR;
     607           0 :         goto yy29;
     608             : yy37:
     609           8 :         ++YYCURSOR;
     610           8 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     611           8 :         yych = *YYCURSOR;
     612             : yy38:
     613          30 :         if (yybm[0+yych] & 128) {
     614           8 :                 goto yy37;
     615             :         }
     616          22 :         goto yy33;
     617             : yy39:
     618           5 :         ++YYCURSOR;
     619           5 :         yych = *YYCURSOR;
     620           5 :         goto yy31;
     621             : }
     622             : #line 334 "ext/standard/url_scanner_ex.re"
     623             : 
     624             : 
     625             : state_arg:
     626             :         start = YYCURSOR;
     627             : 
     628             : #line 629 "ext/standard/url_scanner_ex.c"
     629             : {
     630             :         YYCTYPE yych;
     631             :         static const unsigned char yybm[] = {
     632             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     633             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     634             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     635             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     636             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     637             :                   0,   0,   0,   0,   0, 128,   0,   0, 
     638             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     639             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     640             :                   0, 128, 128, 128, 128, 128, 128, 128, 
     641             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     642             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     643             :                 128, 128, 128,   0,   0,   0,   0,   0, 
     644             :                   0, 128, 128, 128, 128, 128, 128, 128, 
     645             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     646             :                 128, 128, 128, 128, 128, 128, 128, 128, 
     647             :                 128, 128, 128,   0,   0,   0,   0,   0, 
     648             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     649             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     650             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     651             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     652             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     653             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     654             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     655             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     656             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     657             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     658             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     659             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     660             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     661             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     662             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     663             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     664             :         };
     665          20 :         if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
     666          20 :         yych = *YYCURSOR;
     667          20 :         if (yych <= '@') goto yy44;
     668          20 :         if (yych <= 'Z') goto yy42;
     669          20 :         if (yych <= '`') goto yy44;
     670          20 :         if (yych >= '{') goto yy44;
     671             : yy42:
     672          20 :         ++YYCURSOR;
     673          20 :         yych = *YYCURSOR;
     674          20 :         goto yy47;
     675             : yy43:
     676             : #line 339 "ext/standard/url_scanner_ex.re"
     677             :         { passthru(STD_ARGS); handle_arg(STD_ARGS); STATE = STATE_BEFORE_VAL; goto state_before_val; }
     678             : #line 679 "ext/standard/url_scanner_ex.c"
     679             : yy44:
     680           0 :         ++YYCURSOR;
     681             : #line 340 "ext/standard/url_scanner_ex.re"
     682             :         { passthru(STD_ARGS); STATE = STATE_NEXT_ARG; goto state_next_arg; }
     683             : #line 684 "ext/standard/url_scanner_ex.c"
     684             : yy46:
     685          74 :         ++YYCURSOR;
     686          74 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     687          74 :         yych = *YYCURSOR;
     688             : yy47:
     689          94 :         if (yybm[0+yych] & 128) {
     690          74 :                 goto yy46;
     691             :         }
     692          20 :         goto yy43;
     693             : }
     694             : #line 341 "ext/standard/url_scanner_ex.re"
     695             : 
     696             : 
     697             : state_before_val:
     698             :         start = YYCURSOR;
     699             : 
     700             : #line 701 "ext/standard/url_scanner_ex.c"
     701             : {
     702             :         YYCTYPE yych;
     703             :         static const unsigned char yybm[] = {
     704             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     705             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     706             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     707             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     708             :                 128,   0,   0,   0,   0,   0,   0,   0, 
     709             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     710             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     711             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     712             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     713             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     714             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     715             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     716             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     717             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     718             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     719             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     720             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     721             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     722             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     723             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     724             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     725             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     726             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     727             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     728             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     729             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     730             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     731             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     732             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     733             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     734             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     735             :                   0,   0,   0,   0,   0,   0,   0,   0, 
     736             :         };
     737          20 :         if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
     738          20 :         yych = *YYCURSOR;
     739          20 :         if (yych == ' ') goto yy50;
     740          20 :         if (yych == '=') goto yy52;
     741           0 :         goto yy54;
     742             : yy50:
     743           0 :         yych = *(YYMARKER = ++YYCURSOR);
     744           0 :         if (yych == ' ') goto yy57;
     745           0 :         if (yych == '=') goto yy55;
     746             : yy51:
     747             : #line 347 "ext/standard/url_scanner_ex.re"
     748             :         { --YYCURSOR; goto state_next_arg_begin; }
     749             : #line 750 "ext/standard/url_scanner_ex.c"
     750             : yy52:
     751          20 :         ++YYCURSOR;
     752          20 :         yych = *YYCURSOR;
     753          20 :         goto yy56;
     754             : yy53:
     755             : #line 346 "ext/standard/url_scanner_ex.re"
     756             :         { passthru(STD_ARGS); STATE = STATE_VAL; goto state_val; }
     757             : #line 758 "ext/standard/url_scanner_ex.c"
     758             : yy54:
     759           0 :         yych = *++YYCURSOR;
     760           0 :         goto yy51;
     761             : yy55:
     762           0 :         ++YYCURSOR;
     763           0 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     764           0 :         yych = *YYCURSOR;
     765             : yy56:
     766          20 :         if (yybm[0+yych] & 128) {
     767           0 :                 goto yy55;
     768             :         }
     769          20 :         goto yy53;
     770             : yy57:
     771           0 :         ++YYCURSOR;
     772           0 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     773           0 :         yych = *YYCURSOR;
     774           0 :         if (yych == ' ') goto yy57;
     775           0 :         if (yych == '=') goto yy55;
     776           0 :         YYCURSOR = YYMARKER;
     777           0 :         goto yy51;
     778             : }
     779             : #line 348 "ext/standard/url_scanner_ex.re"
     780             : 
     781             : 
     782             : 
     783             : state_val:
     784             :         start = YYCURSOR;
     785             : 
     786             : #line 787 "ext/standard/url_scanner_ex.c"
     787             : {
     788             :         YYCTYPE yych;
     789             :         static const unsigned char yybm[] = {
     790             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     791             :                 224, 192, 192, 224, 224, 192, 224, 224, 
     792             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     793             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     794             :                 192, 224,  64, 224, 224, 224, 224, 128, 
     795             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     796             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     797             :                 224, 224, 224, 224, 224, 224,   0, 224, 
     798             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     799             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     800             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     801             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     802             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     803             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     804             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     805             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     806             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     807             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     808             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     809             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     810             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     811             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     812             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     813             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     814             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     815             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     816             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     817             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     818             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     819             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     820             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     821             :                 224, 224, 224, 224, 224, 224, 224, 224, 
     822             :         };
     823          20 :         if ((YYLIMIT - YYCURSOR) < 2) YYFILL(2);
     824          20 :         yych = *YYCURSOR;
     825          20 :         if (yych <= ' ') {
     826           0 :                 if (yych <= '\f') {
     827           0 :                         if (yych <= 0x08) goto yy65;
     828           0 :                         if (yych <= '\n') goto yy67;
     829           0 :                         goto yy65;
     830             :                 } else {
     831           0 :                         if (yych <= '\r') goto yy67;
     832           0 :                         if (yych <= 0x1F) goto yy65;
     833           0 :                         goto yy67;
     834             :                 }
     835             :         } else {
     836          20 :                 if (yych <= '&') {
     837          14 :                         if (yych != '"') goto yy65;
     838             :                 } else {
     839           6 :                         if (yych <= '\'') goto yy64;
     840           4 :                         if (yych == '>') goto yy67;
     841           4 :                         goto yy65;
     842             :                 }
     843             :         }
     844          14 :         yych = *(YYMARKER = ++YYCURSOR);
     845          14 :         if (yych != '>') goto yy76;
     846             : yy63:
     847             : #line 357 "ext/standard/url_scanner_ex.re"
     848             :         { passthru(STD_ARGS); goto state_next_arg_begin; }
     849             : #line 850 "ext/standard/url_scanner_ex.c"
     850             : yy64:
     851           2 :         yych = *(YYMARKER = ++YYCURSOR);
     852           2 :         if (yych == '>') goto yy63;
     853           2 :         goto yy71;
     854             : yy65:
     855           4 :         ++YYCURSOR;
     856           4 :         yych = *YYCURSOR;
     857           4 :         goto yy69;
     858             : yy66:
     859             : #line 356 "ext/standard/url_scanner_ex.re"
     860             :         { handle_val(STD_ARGS, 0, ' '); goto state_next_arg_begin; }
     861             : #line 862 "ext/standard/url_scanner_ex.c"
     862             : yy67:
     863           0 :         yych = *++YYCURSOR;
     864           0 :         goto yy63;
     865             : yy68:
     866          17 :         ++YYCURSOR;
     867          17 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     868          17 :         yych = *YYCURSOR;
     869             : yy69:
     870          21 :         if (yybm[0+yych] & 32) {
     871          17 :                 goto yy68;
     872             :         }
     873           4 :         goto yy66;
     874             : yy70:
     875          10 :         ++YYCURSOR;
     876          10 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     877          10 :         yych = *YYCURSOR;
     878             : yy71:
     879          12 :         if (yybm[0+yych] & 64) {
     880          10 :                 goto yy70;
     881             :         }
     882           2 :         if (yych <= '=') goto yy73;
     883             : yy72:
     884           0 :         YYCURSOR = YYMARKER;
     885           0 :         goto yy63;
     886             : yy73:
     887           2 :         ++YYCURSOR;
     888             : #line 355 "ext/standard/url_scanner_ex.re"
     889             :         { handle_val(STD_ARGS, 1, '\''); goto state_next_arg_begin; }
     890             : #line 891 "ext/standard/url_scanner_ex.c"
     891             : yy75:
     892         255 :         ++YYCURSOR;
     893         255 :         if (YYLIMIT <= YYCURSOR) YYFILL(1);
     894         255 :         yych = *YYCURSOR;
     895             : yy76:
     896         269 :         if (yybm[0+yych] & 128) {
     897         255 :                 goto yy75;
     898             :         }
     899          14 :         if (yych >= '>') goto yy72;
     900          14 :         ++YYCURSOR;
     901             : #line 354 "ext/standard/url_scanner_ex.re"
     902             :         { handle_val(STD_ARGS, 1, '"'); goto state_next_arg_begin; }
     903             : #line 904 "ext/standard/url_scanner_ex.c"
     904             : }
     905             : #line 358 "ext/standard/url_scanner_ex.re"
     906             : 
     907             : 
     908             : stop:
     909             :         if (YYLIMIT < start) {
     910             :                 /* XXX: Crash avoidance. Need to work with reporter to figure out what goes wrong */    
     911             :                 rest = 0;
     912             :         } else {
     913             :                 rest = YYLIMIT - start;
     914             :                 scdebug(("stopped in state %d at pos %d (%d:%c) %d\n", STATE, YYCURSOR - ctx->buf.c, *YYCURSOR, *YYCURSOR, rest));
     915             :         }
     916             :         
     917             :         if (rest) memmove(ctx->buf.s->val, start, rest);
     918             :         ctx->buf.s->len = rest;
     919             : }
     920             : 
     921             : char *php_url_scanner_adapt_single_url(const char *url, size_t urllen, const char *name, const char *value, size_t *newlen TSRMLS_DC)
     922             : {
     923             :         char *result;
     924             :         smart_str surl = {0};
     925             :         smart_str buf = {0};
     926             :         smart_str url_app = {0};
     927             : 
     928             :         smart_str_setl(&surl, url, urllen);
     929             : 
     930             :         smart_str_appends(&url_app, name);
     931             :         smart_str_appendc(&url_app, '=');
     932             :         smart_str_appends(&url_app, value);
     933             : 
     934             :         append_modified_url(&surl, &buf, &url_app, PG(arg_separator).output);
     935             : 
     936             :         smart_str_0(&buf);
     937             :         if (newlen) *newlen = buf.s->len;
     938             :         result = estrndup(buf.s->val, buf.s->len);
     939             : 
     940             :         smart_str_free(&url_app);
     941             :         smart_str_free(&buf);
     942             : 
     943             :         return result;
     944             : }
     945             : 
     946             : 
     947             : static char *url_adapt_ext(const char *src, size_t srclen, size_t *newlen, zend_bool do_flush TSRMLS_DC)
     948             : {
     949             :         url_adapt_state_ex_t *ctx;
     950             :         char *retval;
     951             : 
     952             :         ctx = &BG(url_adapt_state_ex);
     953             : 
     954             :         xx_mainloop(ctx, src, srclen TSRMLS_CC);
     955             : 
     956             :         if (!ctx->result.s) {
     957             :                 smart_str_appendl(&ctx->result, "", 0);
     958             :                 *newlen = 0;
     959             :         } else {
     960             :                 *newlen = ctx->result.s->len;
     961             :         }
     962             :         smart_str_0(&ctx->result);
     963             :         if (do_flush) {
     964             :                 smart_str_append(&ctx->result, ctx->buf.s);
     965             :                 *newlen += ctx->buf.s->len;
     966             :                 smart_str_free(&ctx->buf);
     967             :                 smart_str_free(&ctx->val);
     968             :         }
     969             :         retval = estrndup(ctx->result.s->val, ctx->result.s->len);
     970             :         smart_str_free(&ctx->result);
     971             :         return retval;
     972             : }
     973             : 
     974             : static int php_url_scanner_ex_activate(TSRMLS_D)
     975             : {
     976             :         url_adapt_state_ex_t *ctx;
     977             :         
     978             :         ctx = &BG(url_adapt_state_ex);
     979             : 
     980             :         memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags));
     981             : 
     982             :         return SUCCESS;
     983             : }
     984             : 
     985             : static int php_url_scanner_ex_deactivate(TSRMLS_D)
     986             : {
     987             :         url_adapt_state_ex_t *ctx;
     988             :         
     989             :         ctx = &BG(url_adapt_state_ex);
     990             : 
     991             :         smart_str_free(&ctx->result);
     992             :         smart_str_free(&ctx->buf);
     993             :         smart_str_free(&ctx->tag);
     994             :         smart_str_free(&ctx->arg);
     995             : 
     996             :         return SUCCESS;
     997             : }
     998             : 
     999             : static void php_url_scanner_output_handler(char *output, size_t output_len, char **handled_output, size_t *handled_output_len, int mode TSRMLS_DC)
    1000             : {
    1001             :         size_t len;
    1002             : 
    1003             :         if (BG(url_adapt_state_ex).url_app.s->len != 0) {
    1004             :                 *handled_output = url_adapt_ext(output, output_len, &len, (zend_bool) (mode & (PHP_OUTPUT_HANDLER_END | PHP_OUTPUT_HANDLER_CONT | PHP_OUTPUT_HANDLER_FLUSH | PHP_OUTPUT_HANDLER_FINAL) ? 1 : 0) TSRMLS_CC);
    1005             :                 if (sizeof(uint) < sizeof(size_t)) {
    1006             :                         if (len > UINT_MAX)
    1007             :                                 len = UINT_MAX;
    1008             :                 }
    1009             :                 *handled_output_len = len;
    1010             :         } else if (BG(url_adapt_state_ex).url_app.s->len == 0) {
    1011             :                 url_adapt_state_ex_t *ctx = &BG(url_adapt_state_ex);
    1012             :                 if (ctx->buf.s && ctx->buf.s->len) {
    1013             :                         smart_str_append(&ctx->result, ctx->buf.s);
    1014             :                         smart_str_appendl(&ctx->result, output, output_len);
    1015             : 
    1016             :                         *handled_output = estrndup(ctx->result.s->val, ctx->result.s->len);
    1017             :                         *handled_output_len = ctx->buf.s->len + output_len;
    1018             : 
    1019             :                         smart_str_free(&ctx->buf);
    1020             :                         smart_str_free(&ctx->result);
    1021             :                 } else {
    1022             :                         *handled_output = estrndup(output, *handled_output_len = output_len);
    1023             :                 }
    1024             :         } else {
    1025             :                 *handled_output = NULL;
    1026             :         }
    1027             : }
    1028             : 
    1029             : PHPAPI int php_url_scanner_add_var(char *name, size_t name_len, char *value, size_t value_len, int urlencode TSRMLS_DC)
    1030             : {
    1031             :         smart_str val = {0};
    1032             :         zend_string *encoded;
    1033             :         
    1034             :         if (!BG(url_adapt_state_ex).active) {
    1035             :                 php_url_scanner_ex_activate(TSRMLS_C);
    1036             :                 php_output_start_internal(ZEND_STRL("URL-Rewriter"), php_url_scanner_output_handler, 0, PHP_OUTPUT_HANDLER_STDFLAGS TSRMLS_CC);
    1037             :                 BG(url_adapt_state_ex).active = 1;
    1038             :         }
    1039             : 
    1040             : 
    1041             :         if (BG(url_adapt_state_ex).url_app.s && BG(url_adapt_state_ex).url_app.s->len != 0) {
    1042             :                 smart_str_appends(&BG(url_adapt_state_ex).url_app, PG(arg_separator).output);
    1043             :         }
    1044             : 
    1045             :         if (urlencode) {
    1046             :                 encoded = php_url_encode(value, value_len);
    1047             :                 smart_str_setl(&val, encoded->val, encoded->len);
    1048             :         } else {
    1049             :                 smart_str_setl(&val, value, value_len);
    1050             :         }
    1051             :         
    1052             :         smart_str_appendl(&BG(url_adapt_state_ex).url_app, name, name_len);
    1053             :         smart_str_appendc(&BG(url_adapt_state_ex).url_app, '=');
    1054             :         smart_str_append_smart_str(&BG(url_adapt_state_ex).url_app, &val);
    1055             : 
    1056             :         smart_str_appends(&BG(url_adapt_state_ex).form_app, "<input type=\"hidden\" name=\""); 
    1057             :         smart_str_appendl(&BG(url_adapt_state_ex).form_app, name, name_len);
    1058             :         smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" value=\"");
    1059             :         smart_str_append_smart_str(&BG(url_adapt_state_ex).form_app, &val);
    1060             :         smart_str_appends(&BG(url_adapt_state_ex).form_app, "\" />");
    1061             : 
    1062             :         if (urlencode) {
    1063             :                 zend_string_free(encoded);
    1064             :         }
    1065             :         smart_str_free(&val);
    1066             : 
    1067             :         return SUCCESS;
    1068             : }
    1069             : 
    1070             : PHPAPI int php_url_scanner_reset_vars(TSRMLS_D)
    1071             : {
    1072             :         if (BG(url_adapt_state_ex).form_app.s) {
    1073             :                 BG(url_adapt_state_ex).form_app.s->len = 0;
    1074             :         }
    1075             :         if (BG(url_adapt_state_ex).url_app.s) {
    1076             :                 BG(url_adapt_state_ex).url_app.s->len = 0;
    1077             :         }
    1078             : 
    1079             :         return SUCCESS;
    1080             : }
    1081             : 
    1082             : PHP_MINIT_FUNCTION(url_scanner)
    1083             : {
    1084             :         BG(url_adapt_state_ex).tags = NULL;
    1085             : 
    1086             :         BG(url_adapt_state_ex).form_app.s = BG(url_adapt_state_ex).url_app.s = NULL;
    1087             : 
    1088             :         REGISTER_INI_ENTRIES();
    1089             :         return SUCCESS;
    1090             : }
    1091             : 
    1092             : PHP_MSHUTDOWN_FUNCTION(url_scanner)
    1093             : {
    1094             :         UNREGISTER_INI_ENTRIES();
    1095             : 
    1096             :         return SUCCESS;
    1097             : }
    1098             : 
    1099             : PHP_RINIT_FUNCTION(url_scanner)
    1100             : {
    1101             :         BG(url_adapt_state_ex).active = 0;
    1102             :         
    1103             :         return SUCCESS;
    1104             : }
    1105             : 
    1106             : PHP_RSHUTDOWN_FUNCTION(url_scanner)
    1107             : {
    1108             :         if (BG(url_adapt_state_ex).active) {
    1109             :                 php_url_scanner_ex_deactivate(TSRMLS_C);
    1110             :                 BG(url_adapt_state_ex).active = 0;
    1111             :         }
    1112             : 
    1113             :         smart_str_free(&BG(url_adapt_state_ex).form_app);
    1114             :         smart_str_free(&BG(url_adapt_state_ex).url_app);
    1115             : 
    1116             :         return SUCCESS;
    1117             : }

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:27 +0000 (6 days ago)

Copyright © 2005-2014 The PHP Group
All rights reserved.