=================================================================== RCS file: /home/cvs/OpenXM/src/kan96xx/plugin/oxcgi.c,v retrieving revision 1.2 retrieving revision 1.9 diff -u -p -r1.2 -r1.9 --- OpenXM/src/kan96xx/plugin/oxcgi.c 2004/09/24 08:35:47 1.2 +++ OpenXM/src/kan96xx/plugin/oxcgi.c 2005/06/16 05:07:24 1.9 @@ -1,4 +1,4 @@ -/* $OpenXM: OpenXM/src/kan96xx/plugin/oxcgi.c,v 1.1 2004/09/21 12:52:01 takayama Exp $ */ +/* $OpenXM: OpenXM/src/kan96xx/plugin/oxcgi.c,v 1.8 2005/02/27 05:28:06 takayama Exp $ */ #include #include "datatype.h" #include "stackm.h" @@ -28,13 +28,19 @@ struct object cgiUrlEncodingToKeyValuePair(char *s) { int vstart,vend; /* start of value, end of value */ int state; int nOfPairs; - struct object rob; - struct object ob; + struct object rob = OINIT; + struct object ob = OINIT; int k; n = strlen(s); start = -1; for (i=0; i ' ') { start = i; break; } + } + } for (k=0; k<2; k++) { /* k==0 path one. Count nOfPairs. */ /* k==1 path two. generate array. */ @@ -174,7 +180,7 @@ struct object urlEncodedStringToObj(char *s,int vstart [ not implemented yet. ] */ { - struct object rob; + struct object rob = OINIT; char *ts; char *ts2; int i,j; @@ -235,7 +241,7 @@ static test1() { } static test2() { char s[1000]; - struct object ob; + struct object ob = OINIT; ob=cgiUrlEncodingToKeyValuePair("http://hoge.hoge?name=1231232&hoge=asdfsdf&foo=asdfasdf"); printObject(ob,1,stdout); ob=cgiUrlEncodingToKeyValuePair("http://hoge.hoge?name=1231232&hoge=&foo=asdfasdf&hoge=A%41+%42%62y%21"); @@ -247,7 +253,7 @@ static test2() { static test4() { char s[1000]; - struct object ob; + struct object ob = OINIT; char *ts; int size; ob=cgiUrlEncodingToKeyValuePair("http://hoge.hoge?name=1231232&hoge=&foo=asdfasdf&hoge=A%41+%42%62y%21"); @@ -277,7 +283,9 @@ char *cgiKeyValuePairToUrlEncoding(struct object ob) { } int checkKeyValuePairFormat(struct object ob,char *msg) { int i,n; - struct object eob,eob0,eob1; + struct object eob = OINIT; + struct object eob0 = OINIT; + struct object eob1 = OINIT; static char *fmt = NULL; int size; char *ss; @@ -303,7 +311,9 @@ int checkKeyValuePairFormat(struct object ob,char *msg int cgiKeyValuePairToUrlEncodingFile2(struct object ob,FILE2 *fp) { int n,i; - struct object eob,eob0,eob1; + struct object eob = OINIT; + struct object eob0 = OINIT; + struct object eob1 = OINIT; char *key, *s; checkKeyValuePairFormat(ob,"cgiKeyValuePairToUrlEncodingFile2"); n = getoaSize(ob); @@ -311,8 +321,7 @@ int cgiKeyValuePairToUrlEncodingFile2(struct object ob eob = getoa(ob,i); eob0 = getoa(eob,0); eob1 = getoa(eob,1); key = KopString(eob0); - if (i == 0) { - if (strcmp(key,"URL") != 0) warningKan("Key word should be URL.\n"); + if ((i == 0) && (strcmp(key,"URL")==0)) { if (eob1.tag != Sdollar) errorKan1("%s\n","URL value must be a string."); fp2fputs(KopString(eob1),fp); if ( n > 1 ) fp2fputc('?',fp); @@ -335,7 +344,7 @@ int cgiKeyValuePairToUrlEncodingFile2(struct object ob static struct object rStringToObj(char *s,int vstart,int vend,int mode) { /* mode has not yet been used. */ - struct object rob; + struct object rob = OINIT; char *sss; int i; int bytearray; bytearray=0; @@ -367,7 +376,8 @@ struct object cgiHttpToKeyValuePair(char *s,int size) int ssize,i,j,k; int nOfPairs, startbody,state, kstart,kend,vstart, vend,startline,endline; int nextstart,path; - struct object rob,ob; + struct object rob = OINIT; + struct object ob = OINIT; ssize = strlen(s); nOfPairs = 0; startbody = -1; /* state==0 : readline and set startline and endline; state = 1; @@ -450,7 +460,9 @@ char *cgiKeyValuePairToHttp(struct object ob,int *size int cgiKeyValuePairToHttpFile2(struct object ob,FILE2 *fp) { int n,i; - struct object eob,eob0,eob1; + struct object eob = OINIT; + struct object eob0 = OINIT; + struct object eob1 = OINIT; char *key, *s; checkKeyValuePairFormat(ob,"cgiKeyValuePairToHttpFile2"); n = getoaSize(ob); @@ -486,7 +498,7 @@ int cgiKeyValuePairToHttpFile2(struct object ob,FILE2 static test3() { char *s; - struct object ob; + struct object ob = OINIT; s = "Pragma: no-cache\nContent-Length: 2915\nContent-Type: text/html\nConnection: close\n\n
\n

 \n

"; ob=cgiHttpToKeyValuePair(s,strlen(s)); @@ -521,3 +533,100 @@ struct object cgiKeyValuePairToHttpString(struct objec return KpoString(s); } +struct object KooStringToUrlEncoding(struct object sob) { + unsigned char *s; + char *rs; + int n; + if (sob.tag == Sdollar) { + s = (unsigned char *) KopString(sob); + n = strlen((char *)s); + }else if (sob.tag == SbyteArray) { + s = KopByteArray(sob); + n = getByteArraySize(sob); + }else errorKan1("%s\n","KooStringToUrlEncoding: argument must be a string or a bytearray."); + rs = byteArrayToUrlEncoding(s,n); + return KpoString(rs); +} + +struct object KooUrlEncodedStringToObj(struct object sob) { + char *s; + int n; + if (sob.tag == Sdollar) { + s = KopString(sob); + n = strlen((char *)s); + }else if (sob.tag == SbyteArray) { + s = KopByteArray(sob); + n = getByteArraySize(sob); + }else errorKan1("%s\n","KooUrlEncodedStringToObj: argument must be a string."); + return urlEncodedStringToObj(s,0,n-1,0); +} + +static struct object toTokens(char *s,int *sep,int nsep) { + /* s is the input, and sep are the separators. */ + /* -1 means <=' ' are separators */ + int nOfTokens,n,i,done,k,start,sav; + struct object rob = OINIT; + char *t; + + rob = NullObject; + if (nsep < 1) return rob; + if (sep[0] != -1) { + fprintf(stderr,"cgiToTokens: Not implemeted for this separator.\n"); + return rob; + } + + /* Count the number of tokens */ + n = strlen(s); i = 0; nOfTokens=0; + while (i < n) { + done = 0; + while (s[i] <= ' ') { + i++; if (i >= n) { done=1; break;} + } + if (done==1) break; + nOfTokens++; + while (s[i] > ' ') { + i++; if (i >= n) { done=1; break; } + } + if (done == 1) break; + } + + rob = newObjectArray(nOfTokens); + n = strlen(s); i = 0; k = 0; + while (i < n) { + done = 0; + while (s[i] <= ' ') { + i++; if (i >= n) { done=1; break;} + } + if (done==1) break; + start = i; + while (s[i] > ' ') { + i++; if (i >= n) { done=1; break; } + } + t = (char *) GC_malloc(i-start+1); + if (t == NULL) { fprintf(stderr,"No more memory.\n"); exit(10); } + t[i-start] = 0; + strncpy(t,&(s[start]),i-start); + putoa(rob,k,KpoString(t)); + k++; + if (done == 1) break; + } + + return rob; +} + +struct object KooToTokens(struct object ob,struct object sep) { + char *s; + int n; + int tmp[1]; + tmp[0] = -1; + if (ob.tag == Sdollar) { + s = KopString(ob); + n = strlen((char *)s); + }else errorKan1("%s\n","KooToTokens: the first argument must be a string."); + if (sep.tag == Sarray) { + if (getoaSize(sep) != 0) { + errorKan1("%s\n","This separators have not been implemented."); + } + }else errorKan1("%s\n","KooToTokens: the second argument(separators) must be an array."); + return toTokens(s,tmp,1); +}