will now work again on 1-character urls, spaces before and after '='

and urls containing '#' scrolling info
# argh, this file's not even a week old and already needs
# a heavy cleanup rewrite, but at least it gets all my test cases right
This commit is contained in:
Hartmut Holzgraefe 2000-08-03 11:42:39 +00:00
parent c438f0abc9
commit 74ca22e9ca

View file

@ -30,7 +30,9 @@
#include "basic_functions.h" #include "basic_functions.h"
#include "url_scanner.h" #include "url_scanner.h"
#ifndef BUFSIZE
#define BUFSIZE 256 #define BUFSIZE 256
#endif
PHP_RINIT_FUNCTION(url_scanner) { PHP_RINIT_FUNCTION(url_scanner) {
url_adapt(NULL,0,NULL,NULL); url_adapt(NULL,0,NULL,NULL);
@ -58,18 +60,18 @@ static char *url_attr_addon(const char *tag,const char *attr,const char *val,con
if(flag) { if(flag) {
if(!strstr(val,buf)) if(!strstr(val,buf))
{ {
char *p = (char *)emalloc(strlen(buf)+strlen(PG(arg_separator))+1); char *result = (char *)emalloc(strlen(buf)+strlen(PG(arg_separator))+1);
int n; int n;
if(strchr(val,'?')) { if(strchr(val,'?')) {
strcpy(p,PG(arg_separator)); strcpy(result,PG(arg_separator));
n=strlen(PG(arg_separator)); n=strlen(PG(arg_separator));
} else { } else {
*p='?'; *result='?';
n=1; n=1;
} }
strcpy(p+n,buf); strcpy(result+n,buf);
return p; return result;
} }
} }
return NULL; return NULL;
@ -181,10 +183,43 @@ char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen
case STATE_TAG_IS: case STATE_TAG_IS:
case STATE_TAG_IS2: case STATE_TAG_IS2:
if(!isspace(*src)) { if(*src=='>'){
US.state=STATE_NORMAL;
if(! (US.attr_done)) {
char *p;
p=url_attr_addon(US.tag,US.attr,"",data);
if(p) {
int l= strlen(p);
maxl+=l;
out=realloc(out,maxl);
outp=out+*newlen;
strcpy(outp,p);
outp+=l;
*newlen+=l;
efree(p);
}
}
} else if(*src=='#') {
if(! (US.attr_done)) {
char *p;
US.attr_done=1;
p=url_attr_addon(US.tag,US.attr,"#",data);
if(p) {
int l= strlen(p);
maxl+=l;
out=realloc(out,maxl);
outp=out+*newlen;
strcpy(outp,p);
outp+=l;
*newlen+=l;
efree(p);
}
}
} else if(!isspace(*src)&&(*src!='=')) {
US.ml=BUFSIZE; US.ml=BUFSIZE;
US.p=US.val=erealloc(US.val,US.ml); US.p=US.val=erealloc(US.val,US.ml);
US.l=0; US.l=0;
US.attr_done=0;
if((*src=='"')||(*src=='\'')) { if((*src=='"')||(*src=='\'')) {
US.state=STATE_TAG_QVAL2; US.state=STATE_TAG_QVAL2;
US.delim=*src; US.delim=*src;
@ -198,20 +233,39 @@ char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen
case STATE_TAG_QVAL2: case STATE_TAG_QVAL2:
if(*src==US.delim) { if(*src=='#') {
char *p; if(! (US.attr_done)) {
char *p;
US.attr_done=1;
*US.p='\0';
p=url_attr_addon(US.tag,US.attr,US.val,data);
if(p) {
int l= strlen(p);
maxl+=l;
out=realloc(out,maxl);
outp=out+*newlen;
strcpy(outp,p);
outp+=l;
*newlen+=l;
efree(p);
}
}
} else if(*src==US.delim) {
US.state=STATE_IN_TAG; US.state=STATE_IN_TAG;
*US.p='\0'; *US.p='\0';
p=url_attr_addon(US.tag,US.attr,US.val,data); if(! (US.attr_done)) {
if(p) { char *p;
int l= strlen(p); p=url_attr_addon(US.tag,US.attr,US.val,data);
maxl+=l; if(p) {
out=realloc(out,maxl); int l= strlen(p);
outp=out+*newlen; maxl+=l;
strcpy(outp,p); out=realloc(out,maxl);
outp+=l; outp=out+*newlen;
*newlen+=l; strcpy(outp,p);
efree(p); outp+=l;
*newlen+=l;
efree(p);
}
} }
break; break;
} else if(*src=='\\') { } else if(*src=='\\') {
@ -243,38 +297,40 @@ char *url_adapt(const char *src, size_t srclen, const char *data, size_t *newlen
break; break;
case STATE_TAG_VAL: case STATE_TAG_VAL:
if(!isspace(*src)) {
if((*src=='"')||(*src=='\'')) {
US.state=STATE_TAG_QVAL2;
US.delim=*src;
} else {
*US.p++=*src;
US.l++;
if(US.l==US.ml) {
US.ml+=BUFSIZE;
US.val=erealloc(US.val,US.ml);
US.p = US.val+US.l;
}
US.state=STATE_TAG_VAL2;
}
}
break;
case STATE_TAG_VAL2: case STATE_TAG_VAL2:
if(isspace(*src)||(*src=='>')) { if(*src=='#') {
char *p; if(! (US.attr_done)) {
char *p;
US.attr_done=1;
*US.p='\0';
p=url_attr_addon(US.tag,US.attr,US.val,data);
if(p) {
int l= strlen(p);
maxl+=l;
out=realloc(out,maxl);
outp=out+*newlen;
strcpy(outp,p);
outp+=l;
*newlen+=l;
efree(p);
}
}
} else if(isspace(*src)||(*src=='>')) {
US.state=(*src=='>')?STATE_NORMAL:STATE_IN_TAG; US.state=(*src=='>')?STATE_NORMAL:STATE_IN_TAG;
*US.p='\0'; *US.p='\0';
p=url_attr_addon(US.tag,US.attr,US.val,data); if(! (US.attr_done)) {
if(p) { char *p;
int l= strlen(p); p=url_attr_addon(US.tag,US.attr,US.val,data);
maxl+=l; if(p) {
out=realloc(out,maxl); int l= strlen(p);
outp=out+*newlen; maxl+=l;
strcpy(outp,p); out=realloc(out,maxl);
outp+=l; outp=out+*newlen;
*newlen+=l; strcpy(outp,p);
efree(p); outp+=l;
*newlen+=l;
efree(p);
}
} }
} else { } else {
*US.p++=*src; *US.p++=*src;