Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0227a4e

Browse files
committed
From: "Denis V. Dmitrienko" <denis@null.net>
What it does:It solves stupid problem with cyrillic charsets IP-based on-fly recoding.take a look at /data/charset.conf for details.You can use any tables for any charset.Tables are from Russian Apache project.Tables in this patch contains also Ukrainian characters.Then run ./configure --enable-recode
1 parent9631621 commit0227a4e

21 files changed

+844
-8
lines changed

‎src/backend/libpq/hba.c

Lines changed: 187 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.27 1998/01/27 03:24:56 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.28 1998/02/24 15:18:41 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -846,6 +846,192 @@ authident(struct sockaddr_in *raddr, struct sockaddr_in *laddr,
846846
}
847847

848848

849+
#ifdefCYR_RECODE
850+
#defineCHARSET_FILE "charset.conf"
851+
#defineMAX_CHARSETS 10
852+
#defineKEY_HOST 1
853+
#defineKEY_BASE 2
854+
#defineKEY_TABLE 3
855+
856+
structCharsetItem
857+
{
858+
charOrig[MAX_TOKEN];
859+
charDest[MAX_TOKEN];
860+
charTable[MAX_TOKEN];
861+
};
862+
863+
intInRange(char*buf,inthost)
864+
{
865+
intvalid,i,FromAddr,ToAddr,tmp;
866+
structin_addrfile_ip_addr;
867+
char*p;
868+
unsignedintone=0x80000000,NetMask=0;
869+
unsignedcharmask;
870+
p=strchr(buf,'/');
871+
if(p)
872+
{
873+
*p++='\0';
874+
valid=inet_aton(buf,&file_ip_addr);
875+
if(valid)
876+
{
877+
mask=strtoul(p,0,0);
878+
FromAddr=ntohl(file_ip_addr.s_addr);
879+
ToAddr=ntohl(file_ip_addr.s_addr);
880+
for(i=0;i<mask;i++)
881+
{
882+
NetMask |=one;
883+
one >>=1;
884+
}
885+
FromAddr &=NetMask;
886+
ToAddr=ToAddr | ~NetMask;
887+
tmp=ntohl(host);
888+
return ((unsigned)tmp>=(unsigned)FromAddr&&
889+
(unsigned)tmp<=(unsigned)ToAddr);
890+
}
891+
}
892+
else
893+
{
894+
p=strchr(buf,'-');
895+
if(p)
896+
{
897+
*p++='\0';
898+
valid=inet_aton(buf,&file_ip_addr);
899+
if(valid)
900+
{
901+
FromAddr=ntohl(file_ip_addr.s_addr);
902+
valid=inet_aton(p,&file_ip_addr);
903+
if(valid)
904+
{
905+
ToAddr=ntohl(file_ip_addr.s_addr);
906+
tmp=ntohl(host);
907+
return ((unsigned)tmp>=(unsigned)FromAddr&&
908+
(unsigned)tmp<=(unsigned)ToAddr);
909+
}
910+
}
911+
}
912+
else
913+
{
914+
valid=inet_aton(buf,&file_ip_addr);
915+
if(valid)
916+
{
917+
FromAddr=file_ip_addr.s_addr;
918+
return ((unsigned)FromAddr== (unsigned)host);
919+
}
920+
}
921+
}
922+
return false;
923+
}
924+
925+
voidGetCharSetByHost(charTableName[],inthost,constcharDataDir[])
926+
{
927+
FILE*file;
928+
charbuf[MAX_TOKEN],BaseCharset[MAX_TOKEN],
929+
OrigCharset[MAX_TOKEN],DestCharset[MAX_TOKEN],HostCharset[MAX_TOKEN];
930+
charc,eof=false;
931+
char*map_file;
932+
intkey=0,i;
933+
structCharsetItem*ChArray[MAX_CHARSETS];
934+
intChIndex=0;
935+
936+
*TableName='\0';
937+
map_file= (char*)malloc((strlen(DataDir)+
938+
strlen(CHARSET_FILE)+2)*sizeof(char));
939+
sprintf(map_file,"%s/%s",DataDir,CHARSET_FILE);
940+
file=fopen(map_file,"r");
941+
if (file==NULL)
942+
return;
943+
while (!eof)
944+
{
945+
c=getc(file);
946+
ungetc(c,file);
947+
if (c==EOF)
948+
eof= true;
949+
else
950+
{
951+
if (c=='#')
952+
read_through_eol(file);
953+
else
954+
{
955+
/* Read the key */
956+
next_token(file,buf,sizeof(buf));
957+
if (buf[0]!='\0')
958+
{
959+
if (strcasecmp(buf,"HostCharset")==0)
960+
key=KEY_HOST;
961+
if (strcasecmp(buf,"BaseCharset")==0)
962+
key=KEY_BASE;
963+
if (strcasecmp(buf,"RecodeTable")==0)
964+
key=KEY_TABLE;
965+
switch(key)
966+
{
967+
caseKEY_HOST:
968+
/* Read the host */
969+
next_token(file,buf,sizeof(buf));
970+
if (buf[0]!='\0')
971+
{
972+
if (InRange(buf,host))
973+
{
974+
/* Read the charset */
975+
next_token(file,buf,sizeof(buf));
976+
if (buf[0]!='\0')
977+
{
978+
strcpy(HostCharset,buf);
979+
}
980+
}
981+
}
982+
break;
983+
caseKEY_BASE:
984+
/* Read the base charset */
985+
next_token(file,buf,sizeof(buf));
986+
if (buf[0]!='\0')
987+
{
988+
strcpy(BaseCharset,buf);
989+
}
990+
break;
991+
caseKEY_TABLE:
992+
/* Read the original charset */
993+
next_token(file,buf,sizeof(buf));
994+
if (buf[0]!='\0')
995+
{
996+
strcpy(OrigCharset,buf);
997+
/* Read the destination charset */
998+
next_token(file,buf,sizeof(buf));
999+
if (buf[0]!='\0')
1000+
{
1001+
strcpy(DestCharset,buf);
1002+
/* Read the table filename */
1003+
next_token(file,buf,sizeof(buf));
1004+
if (buf[0]!='\0')
1005+
{
1006+
ChArray[ChIndex]= (structCharsetItem*)malloc(sizeof(structCharsetItem));
1007+
strcpy(ChArray[ChIndex]->Orig,OrigCharset);
1008+
strcpy(ChArray[ChIndex]->Dest,DestCharset);
1009+
strcpy(ChArray[ChIndex]->Table,buf);
1010+
ChIndex++;
1011+
}
1012+
}
1013+
}
1014+
break;
1015+
}
1016+
read_through_eol(file);
1017+
}
1018+
}
1019+
}
1020+
}
1021+
fclose(file);
1022+
free(map_file);
1023+
1024+
for(i=0;i<ChIndex;i++)
1025+
{
1026+
if(!strcasecmp(BaseCharset,ChArray[i]->Orig)&&
1027+
!strcasecmp(HostCharset,ChArray[i]->Dest))
1028+
{
1029+
strncpy(TableName,ChArray[i]->Table,79);
1030+
}
1031+
free((structCharsetItem*)ChArray[i]);
1032+
}
1033+
}
1034+
#endif
8491035

8501036
externint
8511037
hba_getauthmethod(SockAddr*raddr,char*database,char*auth_arg,

‎src/backend/postmaster/postmaster.c

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.73 1998/01/31 20:14:15 scrappy Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/postmaster/postmaster.c,v 1.74 1998/02/24 15:19:00 scrappy Exp $
1414
*
1515
* NOTES
1616
*
@@ -203,6 +203,10 @@ static void readStartupPacket(char *arg, PacketLen len, char *pkt);
203203
staticintinitMasks(fd_set*rmask,fd_set*wmask);
204204
staticvoidRandomSalt(char*salt);
205205

206+
#ifdefCYR_RECODE
207+
voidGetCharSetByHost(char*,int,char*);
208+
#endif
209+
206210
externchar*optarg;
207211
externintoptind,
208212
opterr;
@@ -974,7 +978,14 @@ BackendStartup(Port *port)
974978
Backend*bn;/* for backend cleanup */
975979
intpid,
976980
i;
981+
982+
#ifdefCYR_RECODE
983+
#defineNR_ENVIRONMENT_VBL 6
984+
charChTable[80];
985+
#else
977986
#defineNR_ENVIRONMENT_VBL 5
987+
#endif
988+
978989
staticcharenvEntry[NR_ENVIRONMENT_VBL][2*ARGV_SIZE];
979990

980991
for (i=0;i<NR_ENVIRONMENT_VBL;++i)
@@ -1000,6 +1011,15 @@ BackendStartup(Port *port)
10001011
sprintf(envEntry[4],"IPC_KEY=%d",ipc_key);
10011012
putenv(envEntry[4]);
10021013

1014+
#ifdefCYR_RECODE
1015+
GetCharSetByHost(ChTable,port->raddr.in.sin_addr.s_addr,DataDir);
1016+
if(*ChTable!='\0')
1017+
{
1018+
sprintf(envEntry[5],"PG_RECODETABLE=%s",ChTable);
1019+
putenv(envEntry[5]);
1020+
}
1021+
#endif
1022+
10031023
if (DebugLvl>2)
10041024
{
10051025
char**p;

‎src/backend/tcop/postgres.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.65 1998/02/02 00:05:03 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/tcop/postgres.c,v 1.66 1998/02/24 15:19:23 scrappy Exp $
1111
*
1212
* NOTES
1313
* this is the "main" module of the postgres backend and
@@ -1168,6 +1168,10 @@ PostgresMain(int argc, char *argv[])
11681168
SetPgUserName();
11691169
userName=GetPgUserName();
11701170

1171+
#ifdefCYR_RECODE
1172+
SetCharSet();
1173+
#endif
1174+
11711175
if (FindBackend(pg_pathname,argv[0])<0)
11721176
elog(FATAL,"%s: could not locate executable, bailing out...",
11731177
argv[0]);
@@ -1293,7 +1297,7 @@ PostgresMain(int argc, char *argv[])
12931297
if (IsUnderPostmaster== false)
12941298
{
12951299
puts("\nPOSTGRES backend interactive interface");
1296-
puts("$Revision: 1.65 $ $Date: 1998/02/02 00:05:03 $");
1300+
puts("$Revision: 1.66 $ $Date: 1998/02/24 15:19:23 $");
12971301
}
12981302

12991303
/* ----------------

‎src/backend/utils/adt/varchar.c

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.27 1998/02/10 16:03:46 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varchar.c,v 1.28 1998/02/24 15:19:44 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -16,6 +16,10 @@
1616
#include"postgres.h"
1717
#include"utils/builtins.h"
1818

19+
#ifdefCYR_RECODE
20+
char*convertstr(char*,int,int);
21+
#endif
22+
1923
/*
2024
* CHAR() and VARCHAR() types are part of the ANSI SQL standard. CHAR()
2125
* is for blank-padded string whose length is specified in CREATE TABLE.
@@ -84,6 +88,11 @@ bpcharin(char *s, int dummy, int16 atttypmod)
8488
if (*r=='\0')
8589
break;
8690
}
91+
92+
#ifdefCYR_RECODE
93+
convertstr(result+VARHDRSZ,len,0);
94+
#endif
95+
8796
/* blank pad the string if necessary */
8897
for (;i<len;i++)
8998
{
@@ -110,6 +119,11 @@ bpcharout(char *s)
110119
result= (char*)palloc(len+1);
111120
StrNCpy(result,VARDATA(s),len+1);/* these are blank-padded */
112121
}
122+
123+
#ifdefCYR_RECODE
124+
convertstr(result,len,1);
125+
#endif
126+
113127
return (result);
114128
}
115129

@@ -143,6 +157,10 @@ varcharin(char *s, int dummy, int16 atttypmod)
143157
VARSIZE(result)=len;
144158
strncpy(VARDATA(result),s,len-VARHDRSZ);
145159

160+
#ifdefCYR_RECODE
161+
convertstr(result+VARHDRSZ,len,0);
162+
#endif
163+
146164
return (result);
147165
}
148166

@@ -164,6 +182,11 @@ varcharout(char *s)
164182
result= (char*)palloc(len+1);
165183
StrNCpy(result,VARDATA(s),len+1);
166184
}
185+
186+
#ifdefCYR_RECODE
187+
convertstr(result,len,1);
188+
#endif
189+
167190
return (result);
168191
}
169192

‎src/backend/utils/adt/varlena.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.29 1998/01/07 18:46:54 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/varlena.c,v 1.30 1998/02/24 15:19:45 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -157,6 +157,11 @@ textin(char *inputText)
157157
VARSIZE(result)=len;
158158

159159
memmove(VARDATA(result),inputText,len-VARHDRSZ);
160+
161+
#ifdefCYR_RECODE
162+
convertstr(VARDATA(result),len-VARHDRSZ,0);
163+
#endif
164+
160165
return (result);
161166
}
162167

@@ -180,6 +185,11 @@ textout(text *vlena)
180185
result= (char*)palloc(len+1);
181186
memmove(result,VARDATA(vlena),len);
182187
result[len]='\0';
188+
189+
#ifdefCYR_RECODE
190+
convertstr(result,len,1);
191+
#endif
192+
183193
return (result);
184194
}
185195

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp