Enable users to set the HTML tags to rewrite

through a configuration directive
This commit is contained in:
Sascha Schumann 2000-10-16 17:25:36 +00:00
parent 8f5e25598a
commit 1c85ad029b
5 changed files with 191 additions and 103 deletions

View File

@ -718,6 +718,9 @@ PHP_MINIT_FUNCTION(basic)
PHP_MINIT(syslog)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(array)(INIT_FUNC_ARGS_PASSTHRU);
PHP_MINIT(assert)(INIT_FUNC_ARGS_PASSTHRU);
#ifdef TRANS_SID
PHP_MINIT(url_scanner_ex)(INIT_FUNC_ARGS_PASSTHRU);
#endif
if(PG(allow_url_fopen)) {
if(FAILURE==php_register_url_wrapper("http",php_fopen_url_wrap_http)) {
@ -759,7 +762,7 @@ PHP_MSHUTDOWN_FUNCTION(basic)
PHP_MSHUTDOWN(browscap)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
PHP_MSHUTDOWN(array)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
PHP_MSHUTDOWN(assert)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
PHP_MSHUTDOWN(url_scanner_ex)(SHUTDOWN_FUNC_ARGS_PASSTHRU);
return SUCCESS;
}

View File

@ -1,4 +1,4 @@
/* Generated by re2c 0.5 on Wed Oct 4 20:04:55 2000 */
/* Generated by re2c 0.5 on Mon Oct 16 00:15:52 2000 */
#line 1 "/home/sas/src/php4/ext/standard/url_scanner_ex.re"
/*
+----------------------------------------------------------------------+
@ -30,6 +30,7 @@
#include <stdlib.h>
#include <string.h>
#include "php_ini.h"
#include "php_globals.h"
#define STATE_TAG SOME_OTHER_STATE_TAG
#include "basic_functions.h"
@ -40,6 +41,54 @@
#include "php_smart_str.h"
static PHP_INI_MH(OnUpdateTags)
{
url_adapt_state_ex_t *ctx;
char *key;
char *lasts;
char *tmp;
BLS_FETCH();
ctx = &BG(url_adapt_state_ex);
tmp = estrndup(new_value, new_value_length);
if (ctx->tags)
zend_hash_destroy(ctx->tags);
else
ctx->tags = malloc(sizeof(HashTable));
zend_hash_init(ctx->tags, 0, NULL, NULL, 1);
for (key = php_strtok_r(tmp, ",", &lasts);
key;
key = php_strtok_r(NULL, ",", &lasts)) {
char *val;
val = strchr(key, '=');
if (val) {
char *q;
int keylen;
*val++ = '\0';
for (q = key; *q; q++)
*q = tolower(*q);
keylen = q - key;
/* key is stored withOUT NUL
val is stored WITH NUL */
zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL);
}
}
efree(tmp);
return SUCCESS;
}
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=fakeentry", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
PHP_INI_END()
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
{
register const char *p, *q;
@ -62,6 +111,12 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
}
}
/* Don't modify URLs of the format "#mark" */
if (bash - url->c == 0) {
smart_str_append(dest, url);
return;
}
if (bash)
smart_str_appendl(dest, url->c, bash - url->c);
else
@ -76,47 +131,20 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
smart_str_appendl(dest, bash, q - bash);
}
struct php_tag_arg {
char *tag;
int taglen;
char *arg;
int arglen;
};
#define TAG_ARG_ENTRY(a,b) {#a,sizeof(#a)-1,#b,sizeof(#b)-1},
static struct php_tag_arg check_tag_arg[] = {
TAG_ARG_ENTRY(a, href)
TAG_ARG_ENTRY(area, href)
TAG_ARG_ENTRY(frame, src)
TAG_ARG_ENTRY(img, src)
TAG_ARG_ENTRY(input, src)
TAG_ARG_ENTRY(form, fake_entry_for_passing_on_form_tag)
{0}
};
static inline void tag_arg(url_adapt_state_ex_t *ctx PLS_DC)
{
char f = 0;
int i;
for (i = 0; check_tag_arg[i].tag; i++) {
if (check_tag_arg[i].arglen == ctx->arg.len
&& check_tag_arg[i].taglen == ctx->tag.len
&& strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0
&& strncasecmp(ctx->arg.c, check_tag_arg[i].arg, ctx->arg.len) == 0) {
f = 1;
break;
}
}
if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
f = 1;
smart_str_appends(&ctx->result, "\"");
smart_str_appendc(&ctx->result, '"');
if (f) {
append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator));
} else {
smart_str_append(&ctx->result, &ctx->val);
}
smart_str_appends(&ctx->result, "\"");
smart_str_appendc(&ctx->result, '"');
}
enum {
@ -160,13 +188,10 @@ enum {
int ok = 0; \
int i; \
smart_str_copyl(&ctx->tag, start, YYCURSOR - start); \
for (i = 0; check_tag_arg[i].tag; i++) { \
if (ctx->tag.len == check_tag_arg[i].taglen \
&& strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0) { \
ok = 1; \
break; \
} \
} \
for (i = 0; i < ctx->tag.len; i++) \
ctx->tag.c[i] = tolower(ctx->tag.c[i]); \
if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, &ctx->lookup_data) == SUCCESS) \
ok = 1; \
STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; \
}
@ -197,7 +222,7 @@ static inline void mainloop(url_adapt_state_ex_t *ctx, const char *newdata, size
YYCURSOR = ctx->buf.c;
YYLIMIT = ctx->buf.c + ctx->buf.len;
#line 201
#line 226
while(1) {
@ -217,14 +242,14 @@ yy0:
if(yych != '<') goto yy4;
yy2: yych = *++YYCURSOR;
yy3:
#line 210
#line 235
{ PASSTHRU(); STATE = STATE_TAG; continue; }
yy4: yych = *++YYCURSOR;
yy5:
#line 211
#line 236
{ PASSTHRU(); continue; }
}
#line 212
#line 237
break;
@ -278,11 +303,11 @@ yy6:
yy8: yych = *++YYCURSOR;
goto yy13;
yy9:
#line 217
#line 242
{ HANDLE_TAG() /* Sets STATE */; PASSTHRU(); continue; }
yy10: yych = *++YYCURSOR;
yy11:
#line 218
#line 243
{ PASSTHRU(); STATE = STATE_PLAIN; continue; }
yy12: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -290,7 +315,7 @@ yy12: ++YYCURSOR;
yy13: if(yybm[0+yych] & 128) goto yy12;
goto yy9;
}
#line 219
#line 244
break;
@ -324,22 +349,22 @@ yy14:
}
yy16: yych = *++YYCURSOR;
yy17:
#line 224
#line 249
{ PASSTHRU(); HANDLE_FORM(); STATE = STATE_PLAIN; continue; }
yy18: yych = *++YYCURSOR;
yy19:
#line 225
#line 250
{ PASSTHRU(); continue; }
yy20: yych = *++YYCURSOR;
yy21:
#line 226
#line 251
{ YYCURSOR--; STATE = STATE_ARG; continue; }
yy22: yych = *++YYCURSOR;
yy23:
#line 227
#line 252
{ PASSTHRU(); continue; }
}
#line 228
#line 253
break;
@ -393,11 +418,11 @@ yy24:
yy26: yych = *++YYCURSOR;
goto yy31;
yy27:
#line 233
#line 258
{ PASSTHRU(); HANDLE_ARG(); STATE = STATE_BEFORE_VAL; continue; }
yy28: yych = *++YYCURSOR;
yy29:
#line 234
#line 259
{ PASSTHRU(); STATE = STATE_NEXT_ARG; continue; }
yy30: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -405,7 +430,7 @@ yy30: ++YYCURSOR;
yy31: if(yybm[0+yych] & 128) goto yy30;
goto yy27;
}
#line 235
#line 260
case STATE_BEFORE_VAL:
@ -459,12 +484,12 @@ yy34: yyaccept = 0;
if(yych == ' ') goto yy41;
if(yych == '=') goto yy39;
yy35:
#line 240
#line 265
{ YYCURSOR--; STATE = STATE_NEXT_ARG; continue; }
yy36: yych = *++YYCURSOR;
goto yy40;
yy37:
#line 239
#line 264
{ PASSTHRU(); STATE = STATE_VAL; continue; }
yy38: yych = *++YYCURSOR;
goto yy35;
@ -483,7 +508,7 @@ yy43: YYCURSOR = YYMARKER;
case 0: goto yy35;
}
}
#line 241
#line 266
break;
@ -552,13 +577,13 @@ yy46: yyaccept = 0;
yych = *(YYMARKER = ++YYCURSOR);
if(yych != '>') goto yy63;
yy47:
#line 249
#line 274
{ PASSTHRU(); STATE = STATE_NEXT_ARG; continue; }
yy48: yyaccept = 1;
yych = *(YYMARKER = ++YYCURSOR);
goto yy55;
yy49:
#line 248
#line 273
{ HANDLE_VAL(0); STATE = STATE_NEXT_ARG; continue; }
yy50: yych = *++YYCURSOR;
goto yy53;
@ -579,7 +604,7 @@ yy55: if(yybm[0+yych] & 32) goto yy54;
yy56: yych = *++YYCURSOR;
if(yybm[0+yych] & 16) goto yy52;
yy57:
#line 247
#line 272
{ HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; }
yy58: ++YYCURSOR;
if(YYLIMIT == YYCURSOR) YYFILL(1);
@ -600,10 +625,10 @@ yy63: if(yybm[0+yych] & 128) goto yy62;
if(yych >= '>') goto yy60;
yy64: yych = *++YYCURSOR;
yy65:
#line 246
#line 271
{ HANDLE_VAL(1); STATE = STATE_NEXT_ARG; continue; }
}
#line 250
#line 275
break;
}
@ -650,7 +675,7 @@ PHP_RINIT_FUNCTION(url_scanner)
ctx = &BG(url_adapt_state_ex);
memset(ctx, 0, sizeof(*ctx));
memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags));
return SUCCESS;
}
@ -670,4 +695,18 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
return SUCCESS;
}
PHP_MINIT_FUNCTION(url_scanner)
{
REGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(url_scanner)
{
UNREGISTER_INI_ENTRIES();
zend_hash_destroy(BG(url_adapt_state_ex).tags);
free(BG(url_adapt_state_ex).tags);
return SUCCESS;
}
#endif

View File

@ -19,6 +19,8 @@
#ifndef URL_SCANNER_EX_H
#define URL_SCANNER_EX_H
PHP_MINIT_FUNCTION(url_scanner_ex);
PHP_MSHUTDOWN_FUNCTION(url_scanner_ex);
PHP_RSHUTDOWN_FUNCTION(url_scanner_ex);
PHP_RINIT_FUNCTION(url_scanner_ex);
@ -40,7 +42,11 @@ typedef struct {
smart_str q_name;
smart_str q_value;
char *lookup_data;
int state;
/* Everything above is zeroed in RINIT */
HashTable *tags;
} url_adapt_state_ex_t;
#endif

View File

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include "php_ini.h"
#include "php_globals.h"
#define STATE_TAG SOME_OTHER_STATE_TAG
#include "basic_functions.h"
@ -38,6 +39,54 @@
#include "php_smart_str.h"
static PHP_INI_MH(OnUpdateTags)
{
url_adapt_state_ex_t *ctx;
char *key;
char *lasts;
char *tmp;
BLS_FETCH();
ctx = &BG(url_adapt_state_ex);
tmp = estrndup(new_value, new_value_length);
if (ctx->tags)
zend_hash_destroy(ctx->tags);
else
ctx->tags = malloc(sizeof(HashTable));
zend_hash_init(ctx->tags, 0, NULL, NULL, 1);
for (key = php_strtok_r(tmp, ",", &lasts);
key;
key = php_strtok_r(NULL, ",", &lasts)) {
char *val;
val = strchr(key, '=');
if (val) {
char *q;
int keylen;
*val++ = '\0';
for (q = key; *q; q++)
*q = tolower(*q);
keylen = q - key;
/* key is stored withOUT NUL
val is stored WITH NUL */
zend_hash_add(ctx->tags, key, keylen, val, strlen(val)+1, NULL);
}
}
efree(tmp);
return SUCCESS;
}
PHP_INI_BEGIN()
STD_PHP_INI_ENTRY("url_rewriter.tags", "a=href,area=href,frame=src,form=fakeentry", PHP_INI_ALL, OnUpdateTags, url_adapt_state_ex, php_basic_globals, basic_globals)
PHP_INI_END()
static inline void append_modified_url(smart_str *url, smart_str *dest, smart_str *name, smart_str *val, const char *separator)
{
register const char *p, *q;
@ -60,6 +109,12 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
}
}
/* Don't modify URLs of the format "#mark" */
if (bash - url->c == 0) {
smart_str_append(dest, url);
return;
}
if (bash)
smart_str_appendl(dest, url->c, bash - url->c);
else
@ -74,47 +129,20 @@ static inline void append_modified_url(smart_str *url, smart_str *dest, smart_st
smart_str_appendl(dest, bash, q - bash);
}
struct php_tag_arg {
char *tag;
int taglen;
char *arg;
int arglen;
};
#define TAG_ARG_ENTRY(a,b) {#a,sizeof(#a)-1,#b,sizeof(#b)-1},
static struct php_tag_arg check_tag_arg[] = {
TAG_ARG_ENTRY(a, href)
TAG_ARG_ENTRY(area, href)
TAG_ARG_ENTRY(frame, src)
TAG_ARG_ENTRY(img, src)
TAG_ARG_ENTRY(input, src)
TAG_ARG_ENTRY(form, fake_entry_for_passing_on_form_tag)
{0}
};
static inline void tag_arg(url_adapt_state_ex_t *ctx PLS_DC)
{
char f = 0;
int i;
for (i = 0; check_tag_arg[i].tag; i++) {
if (check_tag_arg[i].arglen == ctx->arg.len
&& check_tag_arg[i].taglen == ctx->tag.len
&& strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0
&& strncasecmp(ctx->arg.c, check_tag_arg[i].arg, ctx->arg.len) == 0) {
f = 1;
break;
}
}
if (strncasecmp(ctx->arg.c, ctx->lookup_data, ctx->arg.len) == 0)
f = 1;
smart_str_appends(&ctx->result, "\"");
smart_str_appendc(&ctx->result, '"');
if (f) {
append_modified_url(&ctx->val, &ctx->result, &ctx->q_name, &ctx->q_value, PG(arg_separator));
} else {
smart_str_append(&ctx->result, &ctx->val);
}
smart_str_appends(&ctx->result, "\"");
smart_str_appendc(&ctx->result, '"');
}
enum {
@ -158,13 +186,10 @@ enum {
int ok = 0; \
int i; \
smart_str_copyl(&ctx->tag, start, YYCURSOR - start); \
for (i = 0; check_tag_arg[i].tag; i++) { \
if (ctx->tag.len == check_tag_arg[i].taglen \
&& strncasecmp(ctx->tag.c, check_tag_arg[i].tag, ctx->tag.len) == 0) { \
ok = 1; \
break; \
} \
} \
for (i = 0; i < ctx->tag.len; i++) \
ctx->tag.c[i] = tolower(ctx->tag.c[i]); \
if (zend_hash_find(ctx->tags, ctx->tag.c, ctx->tag.len, &ctx->lookup_data) == SUCCESS) \
ok = 1; \
STATE = ok ? STATE_NEXT_ARG : STATE_PLAIN; \
}
@ -293,7 +318,7 @@ PHP_RINIT_FUNCTION(url_scanner)
ctx = &BG(url_adapt_state_ex);
memset(ctx, 0, sizeof(*ctx));
memset(ctx, 0, ((size_t) &((url_adapt_state_ex_t *)0)->tags));
return SUCCESS;
}
@ -313,4 +338,18 @@ PHP_RSHUTDOWN_FUNCTION(url_scanner)
return SUCCESS;
}
PHP_MINIT_FUNCTION(url_scanner)
{
REGISTER_INI_ENTRIES();
return SUCCESS;
}
PHP_MSHUTDOWN_FUNCTION(url_scanner)
{
UNREGISTER_INI_ENTRIES();
zend_hash_destroy(BG(url_adapt_state_ex).tags);
free(BG(url_adapt_state_ex).tags);
return SUCCESS;
}
#endif

View File

@ -450,6 +450,7 @@ session.cache_limiter = nocache ; set to {nocache,private,public} to
session.cache_expire = 180 ; document expires after n minutes
session.use_trans_sid = 1 ; use transient sid support if enabled
; by compiling with --enable-trans-sid
url_rewriter.tags = a=href,area=href,frame=src,input=src,form=fakeentry
[MSSQL]
;extension=php_mssql.dll