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
This stupid mailer wrapped lines, ignore previos patch.
-Dima
* 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 *cont);
-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 = namefrom;
- table->nameto = nameto;
- table->convtbl = ctbl;
- table->revtbl = rtbl;
- table->next = NULL;
- return table;
-}
-
static recode_table_t*
new_recode_table(pool *p, char *namefrom,char *nameto, unsigned char *ctbl,
unsigned char *rtbl)
{
recode_table_t *r = pcalloc(p,sizeof(recode_table_t));
- return make_recode_table(p,r,namefrom,nameto,ctbl,rtbl);
+ r->namefrom = namefrom;
+ r->nameto = nameto;
+ r->convtbl = ctbl;
+ r->revtbl = rtbl;
+ r->next = 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=malloc(strlen( str ) + 1),*substrn = malloc( strlen( substr ) + 1);
- char *n = strn;
- int ret;
- if(!strn || !substrn) return 0; /* ? */
- while ( (*n++ = (isupper(*str) ? tolower(*str++) : *str++)))
- ;
- n = substrn;
- while ((*n++ = (isupper(*substr) ? tolower(*substr++) : *substr++)))
- ;
- ret = strstr( strn, substrn )!=NULL;
- 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 == NULL) return NULL;
for (i = 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=tab[*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]=buf[1];
+ buffer[1]=buf[2];
+ buffer[2]=0;
+ sscanf(buffer,"%02X",&inchar);
+ inchar1=(unsigned)tab[inchar];
+ if(inchar1!=inchar)
+ {
+ sprintf(buffer,"%02X",inchar1);
+ buf[1]=buffer[0];buf[2]=buffer[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=='%' && isxdigit(buf[1]) && isxdigit(buf[2]))
+ recode_escape(tab, buf);
*buf=tab[*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>=3){
if(*buf=='%' && isxdigit(buf[1]) && isxdigit(buf[2])){
- buffer[0]=buf[1];
- buffer[1]=buf[2];
- buffer[2]=0;
- sscanf(buffer,"%02X",&inchar);
- inchar1=(unsigned)tab[inchar];
- if(inchar1!=inchar)
- {
- sprintf(buffer,"%02X",inchar1);
- buf[1]=buffer[0];buf[2]=buffer[1];
- }
+ recode_escape(tab, buf);
num-=2;
buf+=2;
}
@@ -740,8 +713,8 @@
int
charset_bread(BUFF *fb, void *vbuf, int nbyte,codepage_data_t* codep)
{
- int b_len,len=0,i,res = 0,k;
- unsigned char *tab, buf[3], inchar, outchar;
+ int b_len,len=0,i;
+ unsigned char *tab;
unsigned char *zbuf = (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 = strchr(r->uri+1,'/');
- if(p && strlen(p+1))
+ if (p && p[1])
ret = strncmp_getcharset(dirconf,p+1);
}
return ret;
}
-
/*
Попытка определить charset по User-Agent:
*/
@@ -850,8 +822,9 @@
int maxlen = -1, len,i,match = -1,clen;
- len = agent?strlen(agent):0;
- if (!agent || !len) return NULL;
+ if (!agent) return NULL;
+ len = strlen(agent);
+ if (!len) return NULL;
for(i=0;i<dirconf->agent_charset->nelts;i++)
{
@@ -868,7 +841,6 @@
return NULL;
}
-
/*
Возвращает charset, который лучше всего соответствует 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 = make_sub_pool(r->pool);
- array_header *u_charset = make_array(spool,5,sizeof(user_prio_t));
+ array_header *u_charset = make_array(r->pool,5,sizeof(user_prio_t));
user_prio_t *u_prio;
int i,max_prio,c_prio,match_idx=0;
charset_table_t *ret=NULL,*tmp;
*has_wildcard = 0;
- while (strlen(p=getword(r->pool,(CMDCONST char**)&clientstr,',')))
- {
+
+ cli = pstrdup(r->pool, clientstr);
+ str_tolower(cli);
+ while ((p = cli))
+ {
+ if ((q = strchr(cli, ',')))
+ {
+ *q='\0';
+ cli=q+1;
+ q--;
+ }
+ else
+ {
+ cli=NULL;
+ q=strchr(p, '\0')-1;
+ }
while (isspace(*p)) ++p;
weight=1;
- for (q=p+strlen(p)-1; isspace(*q) && q > p ; q--) ;
+ for (; isspace(*q) && q > p ; q--) ;
*(++q)='\0';
if ((q=strchr(p,';')))
{
@@ -914,14 +899,14 @@
*(++t)='\0';
if ((t=strchr(q,'=')))
{
- sscanf(t+1,"%g",&weight);
+ weight = atof(t+1);
weight = weight >1 ? 1: weight <0 ? 0 : weight;
}
}
- if(!strcmp(p,"*"))
+ if(p[0] == '*' && p[1] == '\0')
*has_wildcard = 1;
u_prio = push_array(u_charset);
- u_prio->cname = pstrdup(spool,p);
+ u_prio->cname = p;
u_prio->prio = weight;
}
/* sort u_charset array in descending order */
@@ -972,7 +957,7 @@
{
charset_table_t *charset=NULL, *cset_by_accept = NULL;
charset_dir_t *dirconf = get_module_config(r->per_dir_config, &charset_module);
- char *cset = NULL,*cset2;
+ char *cset;
int rc = DECLINED;
int has_wildcard = 0,i,*l, sc_flags = 0;
table *e = r->subprocess_env;
@@ -983,7 +968,7 @@
return DECLINED;
}
- /* Are we truned off ? */
+ /* Are we turned off ? */
if(dirconf->turnoff == FL_ON)
{
return DECLINED;
@@ -994,7 +979,7 @@
/* if no charset try to find in Accept: text/x-cyrillic-... */
if (!cset && (cset=table_get(r->headers_in,"Accept")))
{
- cset2=pstrdup(r->pool,cset);
+ char *cset2=pstrdup(r->pool,cset);
if ((cset=strstr(cset2,"text/x-cyrillic-")))
{
char *p=cset+16;
@@ -1007,9 +992,7 @@
/* Charset name come from client query */
if (cset)
{
- cset2 = pstrdup(r->pool,cset);
- str_tolower(cset2);
- if (!(cset_by_accept=find_best_charset(r,dirconf,cset2,&has_wildcard)))
+ if (!(cset_by_accept=find_best_charset(r,dirconf,cset,&has_wildcard)))
{
/* 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 = (table_entry*)dirconf->charset_priority->elts;
- charset = get_chtable(dirconf,e->key);
+ table_entry *ent = (table_entry*)dirconf->charset_priority->elts;
+ charset = get_chtable(dirconf,ent->key);
}
if(!charset)
@@ -1112,15 +1095,19 @@
{
char *src_cs = NULL,*ext,*fn;
- /* stolen from mod_mime */
- fn = strrchr(r->filename,'/');
- if(!fn) ext = r->filename;
-
- while((ext = getword(r->pool, (CMDCONST char**)&fn, '.')) && *ext)
+ if(dirconf->charset_exts->nelts)
{
- if(NULL!=(src_cs = table_get(dirconf->charset_exts,ext)))
- break;
+ /* stolen from mod_mime */
+ fn = strrchr(r->filename,'/');
+ if(!fn) ext = r->filename;
+
+ while((ext = getword(r->pool, (CMDCONST char**)&fn, '.')) && *ext)
+ {
+ if(NULL!=(src_cs = table_get(dirconf->charset_exts,ext)))
+ break;
+ }
}
+
if(!src_cs)
src_cs = dirconf->charset_source;
if(src_cs)
@@ -1135,7 +1122,7 @@
charset_dir_t *dirconf,int flags)
{
int i;
- char *agent,*vary = NULL;
+ char *agent;
int copy_to_parent = 0;
array_header *client_headers=r->headers_in;
table_entry *el = (table_entry *)r->headers_in->elts;
@@ -1194,8 +1181,12 @@
/* Lynx and some other can't accept Content-type: text/html; charset=name */
/* try to find current agent in bad list, than in not_so_bad list */
if ((agent = table_get(r->headers_in,"User-Agent")))
- if(strstr_table_get(dirconf->bad_agent,agent))
- r->codep->cp_flags &= DONT_NEED_CHARSET;
+ {
+ char *lcagent = pstrdup(r->pool, agent);
+ str_tolower(lcagent);
+ if(strstr_table_get(dirconf->bad_agent,lcagent))
+ r->codep->cp_flags &= DONT_NEED_CHARSET;
+ }
if(copy_to_parent)
{
@@ -1207,27 +1198,22 @@
if(r->main == NULL && !copy_to_parent && r->codep->cp_itabl!=NULL)
{
/* 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_itabl);
- if (r->path_info && strlen(r->path_info))
- rev_convert_by_table(r->path_info,strlen(r->path_info),r->codep->cp_itabl);
- 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 = 0; i < client_headers->nelts; i++)
{
- int l;
- if (el[i].key && (l=strlen(el[i].key)))
- rev_convert_by_table(el[i].key,l,r->codep->cp_itabl);
- if (el[i].val && (l=strlen(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==tMETAHTTP)
{
char *stub="Meta http equivalent was here";
- int i=0;
- unsigned sztag=strlen(stag)-9,
+ unsigned int i=0;
+ unsigned int sztag=strlen(stag)-9,
szstub=strlen(stub);
rputs("<!-- ",r);
for(i=0; i<sztag; i++)
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.