Russian Apache mailing list archive (apache-rus@lists.lexa.ru)
[Date Prev ][Date Next ][Thread Prev ][Thread Next ][Date Index ][Thread Index ]
[apache-rus] various patches
-----BEGIN PGP SIGNED MESSAGE-----
* don't convert http header field names.
* performance: speed up find_code_page and descendents
* silence gcc -Wall -Wshadow
* signed/unsigned mismatch
- --- mod_charset.h.ORIG Fri Nov 7 22:51:18 1997
+++ mod_charset.h Fri Nov 7 22:53:03 1997
@@ -92,10 +92,6 @@
=
void =
convert_by_table(unsigned char *buf,int len,unsigned char* tab,char *con=
t);
- -void =
- -rev_convert_by_table(unsigned char *buf,int len, unsigned char *tab);
- -void =
- -rev_convert_by_table_num(unsigned char *buf,int num,unsigned char *tab);=
int charset_bread(BUFF *fb, void *buf, int nbyte,codepage_data_t*);
=
=
- --- mod_charset.c.ORIG Tue Oct 28 21:56:33 1997
+++ mod_charset.c Sun Nov 9 00:33:18 1997
@@ -140,6 +140,8 @@
char* read_table(FILE *fp, char *tab1, char *tab2);
void set_charset(charset_table_t *, request_rec *, charset_dir_t *, int)=
;
int have_different_charsets(charset_dir_t *dirconf);
+void rev_convert_by_table(unsigned char *buf, unsigned char *tab);
+void rev_convert_by_table_num(unsigned char *buf,int num,unsigned char *=
tab);
=
=
void* =
@@ -250,28 +252,19 @@
return NULL;
}
=
- -
- -static recode_table_t*
- -make_recode_table(pool *p, recode_table_t *table, char *namefrom, char =
*nameto,
- - unsigned char *ctbl,unsigned char *rtbl)
- -{
- - table->namefrom =3D namefrom;
- - table->nameto =3D nameto;
- - table->convtbl =3D ctbl;
- - table->revtbl =3D rtbl;
- - table->next =3D NULL;
- - return table;
- -}
- -
static recode_table_t*
new_recode_table(pool *p, char *namefrom,char *nameto, unsigned char *ct=
bl,
unsigned char *rtbl)
{
recode_table_t *r =3D pcalloc(p,sizeof(recode_table_t));
- - return make_recode_table(p,r,namefrom,nameto,ctbl,rtbl);
+ r->namefrom =3D namefrom;
+ r->nameto =3D nameto;
+ r->convtbl =3D ctbl;
+ r->revtbl =3D rtbl;
+ r->next =3D NULL;
+ return r;
}
=
- -
static recode_table_t*
find_recode_table(recode_table_t *l, char* from_name)
{
@@ -452,6 +445,7 @@
CMDCONST char *
add_bad_agent(cmd_parms *cmd,charset_dir_t *dc, char *agent)
{
+ str_tolower(agent);
table_set(dc->bad_agent,agent," ");
return NULL;
}
@@ -554,7 +548,7 @@
{ "CharsetAgent", add_agent_charset,NULL,OR_FILEINFO, ITERATE2,
"Set default charset for agent" },
{ "CharsetBadAgent", add_bad_agent,NULL,OR_FILEINFO, ITERATE,
- - "Set agents, wich can't understand charset in header" },
+ "Set agents, which can't understand charset in header" },
{ "CharsetErrReject", add_reject_error_charset,NULL,OR_FILEINFO, FLAG,=
"Set/unset rejecting error charset negotiation" },
{ "CharsetPriority", add_charset_priority,NULL,OR_FILEINFO, ITERATE,
@@ -607,30 +601,6 @@
return NULL;
}
=
- -
- -/*
- - Case-insensitive strstr()
- -*/
- -
- -int =
- -strcasestr( const char *str, const char *substr )
- -{
- - /* GNUism */
- - char *strn=3Dmalloc(strlen( str ) + 1),*substrn =3D malloc( strlen( su=
bstr ) + =
1);
- - char *n =3D strn; =
- - int ret;
- - if(!strn || !substrn) return 0; /* ? */
- - while ( (*n++ =3D (isupper(*str) ? tolower(*str++) : *str++)))
- - ;
- - n =3D substrn;
- - while ((*n++ =3D (isupper(*substr) ? tolower(*substr++) : *substr++)))=
- - ;
- - ret =3D strstr( strn, substrn )!=3DNULL;
- - free(strn);
- - free(substrn);
- - return ret;
- -}
- -
/* get 1st table entry with key first chars of bkey */
char *
strncmp_table_get(table *t, const char *bkey)
@@ -654,7 +624,7 @@
=
if (bkey =3D=3D NULL) return NULL;
for (i =3D 0; i < t->nelts; ++i)
- - if (strcasestr (bkey,elts[i].key))
+ if (strstr (bkey,elts[i].key))
return elts[i].val;
return NULL;
}
@@ -690,42 +660,45 @@
*p=3Dtab[*p];
}
=
- -void rev_convert_by_table(buf,len, tab)
+static void recode_escape(unsigned char *tab, char *buf) {
+ char buffer[3];
+ unsigned inchar,inchar1;
+ buffer[0]=3Dbuf[1];
+ buffer[1]=3Dbuf[2];
+ buffer[2]=3D0;
+ sscanf(buffer,"%02X",&inchar); =
+ inchar1=3D(unsigned)tab[inchar];
+ if(inchar1!=3Dinchar)
+ {
+ sprintf(buffer,"%02X",inchar1);
+ buf[1]=3Dbuffer[0];buf[2]=3Dbuffer[1];
+ }
+}
+
+void rev_convert_by_table(buf, tab)
unsigned char *buf;
- -int len;
unsigned char *tab;
{
if(!tab)
return;
- - rev_convert_by_table_num(buf,len,tab);
- - while (*buf && len)
+
+ while (*buf)
{
+ if(*buf=3D=3D'%' && isxdigit(buf[1]) && isxdigit(buf[2]))
+ recode_escape(tab, buf);
*buf=3Dtab[*buf];
++buf;
- - --len;
}
} =
=
- -
void
rev_convert_by_table_num(unsigned char *buf, int num,unsigned char *tab)=
{
- - char buffer[3];
- - unsigned inchar,inchar1;
if(!tab)
return;
while(num>=3D3){
if(*buf=3D=3D'%' && isxdigit(buf[1]) && isxdigit(buf[2])){
- - buffer[0]=3Dbuf[1];
- - buffer[1]=3Dbuf[2];
- - buffer[2]=3D0;
- - sscanf(buffer,"%02X",&inchar); =
- - inchar1=3D(unsigned)tab[inchar];
- - if(inchar1!=3Dinchar)
- - {
- - sprintf(buffer,"%02X",inchar1);
- - buf[1]=3Dbuffer[0];buf[2]=3Dbuffer[1];
- - }
+ recode_escape(tab, buf);
num-=3D2;
buf+=3D2;
}
@@ -740,8 +713,8 @@
int =
charset_bread(BUFF *fb, void *vbuf, int nbyte,codepage_data_t* codep)
{
- - int b_len,len=3D0,i,res =3D 0,k;
- - unsigned char *tab, buf[3], inchar, outchar;
+ int b_len,len=3D0,i;
+ unsigned char *tab;
unsigned char *zbuf =3D (unsigned char *) vbuf;
if(!codep || !codep->cp_itabl)
return bread(fb,zbuf,nbyte);
@@ -832,13 +805,12 @@
if(!ret && !strncmp(r->uri,"/~",2))
{
char *p =3D strchr(r->uri+1,'/');
- - if(p && strlen(p+1))
+ if (p && p[1])
ret =3D strncmp_getcharset(dirconf,p+1);
}
return ret;
}
=
- -
/*
=F0=CF=D0=D9=D4=CB=C1 =CF=D0=D2=C5=C4=C5=CC=C9=D4=D8 charset =D0=CF Us=
er-Agent:
*/
@@ -850,8 +822,9 @@
int maxlen =3D -1, len,i,match =3D -1,clen;
=
=
- - len =3D agent?strlen(agent):0;
- - if (!agent || !len) return NULL;
+ if (!agent) return NULL;
+ len =3D strlen(agent);
+ if (!len) return NULL;
=
for(i=3D0;i<dirconf->agent_charset->nelts;i++)
{
@@ -868,7 +841,6 @@
return NULL;
}
=
- -
/*
=F7=CF=DA=D7=D2=C1=DD=C1=C5=D4 charset, =CB=CF=D4=CF=D2=D9=CA =CC=D5=DE=
=DB=C5 =D7=D3=C5=C7=CF =D3=CF=CF=D4=D7=C5=D4=D3=D4=D7=D5=C5=D4 User query=
=
(Accept, Accept-Charset)
@@ -888,24 +860,37 @@
return c->prio>d->prio?-1:c->prio<d->prio?1:0;
}
=
- -
charset_table_t *
find_best_charset(request_rec *r,charset_dir_t *dirconf,
char *clientstr,int* has_wildcard)
{
char *p,*q,*t;
+ char *cli;
float weight;
- - pool *spool =3D make_sub_pool(r->pool);
- - array_header *u_charset =3D make_array(spool,5,sizeof(user_prio_t));
+ array_header *u_charset =3D make_array(r->pool,5,sizeof(user_prio_t));=
user_prio_t *u_prio;
int i,max_prio,c_prio,match_idx=3D0;
charset_table_t *ret=3DNULL,*tmp;
*has_wildcard =3D 0;
- - while (strlen(p=3Dgetword(r->pool,(CMDCONST char**)&clientstr,',')))
- - {
+
+ cli =3D pstrdup(r->pool, clientstr);
+ str_tolower(cli);
+ while ((p =3D cli))
+ {
+ if ((q =3D strchr(cli, ',')))
+ {
+ *q=3D'\0';
+ cli=3Dq+1;
+ q--;
+ }
+ else =
+ {
+ cli=3DNULL;
+ q=3Dstrchr(p, '\0')-1;
+ }
while (isspace(*p)) ++p;
weight=3D1;
- - for (q=3Dp+strlen(p)-1; isspace(*q) && q > p ; q--) ;
+ for (; isspace(*q) && q > p ; q--) ;
*(++q)=3D'\0';
if ((q=3Dstrchr(p,';')))
{
@@ -914,14 +899,14 @@
*(++t)=3D'\0';
if ((t=3Dstrchr(q,'=3D')))
{
- - sscanf(t+1,"%g",&weight);
+ weight =3D atof(t+1);
weight =3D weight >1 ? 1: weight <0 ? 0 : weight;
}
}
- - if(!strcmp(p,"*"))
+ if(p[0] =3D=3D '*' && p[1] =3D=3D '\0')
*has_wildcard =3D 1;
u_prio =3D push_array(u_charset);
- - u_prio->cname =3D pstrdup(spool,p);
+ u_prio->cname =3D p;
u_prio->prio =3D weight;
}
/* sort u_charset array in descending order */
@@ -972,7 +957,7 @@
{
charset_table_t *charset=3DNULL, *cset_by_accept =3D NULL;
charset_dir_t *dirconf =3D get_module_config(r->per_dir_config, =
&charset_module);
- - char *cset =3D NULL,*cset2;
+ char *cset;
int rc =3D DECLINED;
int has_wildcard =3D 0,i,*l, sc_flags =3D 0;
table *e =3D r->subprocess_env;
@@ -983,7 +968,7 @@
return DECLINED;
}
=
- - /* Are we truned off ? */
+ /* Are we turned off ? */
if(dirconf->turnoff =3D=3D FL_ON)
{
return DECLINED;
@@ -994,7 +979,7 @@
/* if no charset try to find in Accept: text/x-cyrillic-... */
if (!cset && (cset=3Dtable_get(r->headers_in,"Accept")))
{
- - cset2=3Dpstrdup(r->pool,cset);
+ char *cset2=3Dpstrdup(r->pool,cset);
if ((cset=3Dstrstr(cset2,"text/x-cyrillic-")))
{
char *p=3Dcset+16;
@@ -1007,9 +992,7 @@
/* Charset name come from client query */
if (cset)
{
- - cset2 =3D pstrdup(r->pool,cset);
- - str_tolower(cset2);
- - if (!(cset_by_accept=3Dfind_best_charset(r,dirconf,cset2,&has_wild=
card)))
+ if (!(cset_by_accept=3Dfind_best_charset(r,dirconf,cset,&has_wildc=
ard)))
{ =
/* cannot set charset specified in Accept: or Accept-Charset: */
if(!has_wildcard) =
@@ -1077,8 +1060,8 @@
/* try 1st element in charset priority list */
if(!charset && dirconf->charset_priority->nelts > 0)
{
- - table_entry *e =3D (table_entry*)dirconf->charset_priority->elts;
- - charset =3D get_chtable(dirconf,e->key);
+ table_entry *ent =3D (table_entry*)dirconf->charset_priority->elts=
;
+ charset =3D get_chtable(dirconf,ent->key);
}
=
if(!charset)
@@ -1112,15 +1095,19 @@
{
char *src_cs =3D NULL,*ext,*fn;
=
- - /* stolen from mod_mime */
- - fn =3D strrchr(r->filename,'/');
- - if(!fn) ext =3D r->filename;
- - =
- - while((ext =3D getword(r->pool, (CMDCONST char**)&fn, '.')) && *ext)
+ if(dirconf->charset_exts->nelts)
{
- - if(NULL!=3D(src_cs =3D table_get(dirconf->charset_exts,ext)))
- - break;
+ /* stolen from mod_mime */
+ fn =3D strrchr(r->filename,'/');
+ if(!fn) ext =3D r->filename;
+ =
+ while((ext =3D getword(r->pool, (CMDCONST char**)&fn, '.')) && *ex=
t)
+ {
+ if(NULL!=3D(src_cs =3D table_get(dirconf->charset_exts,ext)))
+ break;
+ }
}
+
if(!src_cs)
src_cs =3D dirconf->charset_source;
if(src_cs)
@@ -1135,7 +1122,7 @@
charset_dir_t *dirconf,int flags)
{
int i;
- - char *agent,*vary =3D NULL;
+ char *agent;
int copy_to_parent =3D 0;
array_header *client_headers=3Dr->headers_in;
table_entry *el =3D (table_entry *)r->headers_in->elts;
@@ -1194,8 +1181,12 @@
/* Lynx and some other can't accept Content-type: text/html; charset=3D=
name */
/* try to find current agent in bad list, than in not_so_bad list */
if ((agent =3D table_get(r->headers_in,"User-Agent")))
- - if(strstr_table_get(dirconf->bad_agent,agent))
- - r->codep->cp_flags &=3D DONT_NEED_CHARSET;
+ {
+ char *lcagent =3D pstrdup(r->pool, agent);
+ str_tolower(lcagent);
+ if(strstr_table_get(dirconf->bad_agent,lcagent))
+ r->codep->cp_flags &=3D DONT_NEED_CHARSET;
+ }
=
if(copy_to_parent)
{
@@ -1207,27 +1198,22 @@
if(r->main =3D=3D NULL && !copy_to_parent && r->codep->cp_itabl!=3DNUL=
L)
{
/* Let's begin to convert input data from client */
- - if (r->the_request && strlen(r->the_request))
- - rev_convert_by_table(r->the_request,strlen(r->the_request), =
- - r->codep->cp_itabl);
- - if (r->uri && strlen(r->uri) &&
+ if (r->the_request)
+ rev_convert_by_table(r->the_request, r->codep->cp_itabl);
+ if (r->uri &&
strncmp(r->uri,"INTERNALLY GENERATED file-relative req",38))
- - rev_convert_by_table(r->uri,strlen(r->uri), r->codep->cp_itabl);
- - if (r->filename && strlen(r->filename))
- - rev_convert_by_table(r->filename,strlen(r->filename), r->codep->cp_itab=
l);
- - if (r->path_info && strlen(r->path_info))
- - rev_convert_by_table(r->path_info,strlen(r->path_info),r->codep->cp_ita=
bl);
- - if (r->args && strlen(r->args))
- - rev_convert_by_table(r->args,strlen(r->args), r->codep->cp_itabl);
+ rev_convert_by_table(r->uri, r->codep->cp_itabl);
+ if (r->filename)
+ rev_convert_by_table(r->filename, r->codep->cp_itabl);
+ if (r->path_info)
+ rev_convert_by_table(r->path_info, r->codep->cp_itabl);
+ if (r->args)
+ rev_convert_by_table(r->args, r->codep->cp_itabl);
=
/* Time to convert headers from client */
for (i =3D 0; i < client_headers->nelts; i++)
{
- - int l;
- - if (el[i].key && (l=3Dstrlen(el[i].key)))
- - rev_convert_by_table(el[i].key,l,r->codep->cp_itabl);
- - if (el[i].val && (l=3Dstrlen(el[i].val)))
- - rev_convert_by_table(el[i].val,l, r->codep->cp_itabl);
+ rev_convert_by_table(el[i].val, r->codep->cp_itabl);
}
}
}
@@ -1334,8 +1320,8 @@
if(tag=3D=3DtMETAHTTP)
{
char *stub=3D"Meta http equivalent was here";
- - int i=3D0;
- - unsigned sztag=3Dstrlen(stag)-9,
+ unsigned int i=3D0;
+ unsigned int sztag=3Dstrlen(stag)-9,
szstub=3Dstrlen(stub);
rputs("<!-- ",r);
for(i=3D0; i<sztag; i++)
-----BEGIN PGP SIGNATURE-----
Version: 2.6.3ia
Charset: noconv
iQCVAwUBNGTg18AsTWqxp2FpAQGhUAQAjnb5iyxwtw1CW6yCOeJ2blv9ST8xwd8Z
wsZ2IQhZ4+P5iShkVFeOSJQBg1imP07snF7/JVectcN7DADrt1obEF5WrYp1e0mB
KIdmB6D8unmsxWHQ3xcoM+eooN7QssGY8OAAFqK5aP9A2+d9nhlV1jfcOJ/NFR5m
mghRIayoYac=
=0T6Z
-----END PGP SIGNATURE-----
Спонсоры сайта:
"Russian Apache" includes software developed
by the Apache Group for use in the Apache HTTP server project
(http://www.apache.org/) See
Apache LICENSE .
Copyright (C) 1995-2001 The Apache Group. All rights reserved.
Copyright (C) 1996 Dm. Kryukov; Copyright (C)
1997-2009 Alex Tutubalin . Design (C) 1998 Max Smolev.