~ubuntu-branches/ubuntu/hardy/php5/hardy-updates

« back to all changes in this revision

Viewing changes to ext/standard/url_scanner_ex.c.orig

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad
  • Date: 2005-10-09 03:14:32 UTC
  • Revision ID: james.westby@ubuntu.com-20051009031432-kspik3lobxstafv9
Tags: upstream-5.0.5
ImportĀ upstreamĀ versionĀ 5.0.5

Show diffs side-by-side

added added

removed removed

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