version 1.4, 2004/09/27 11:18:23 |
version 1.8, 2005/02/27 05:28:06 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/plugin/oxcgi.c,v 1.3 2004/09/27 01:20:46 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/plugin/oxcgi.c,v 1.7 2004/11/23 01:37:47 takayama Exp $ */ |
#include <stdio.h> |
#include <stdio.h> |
#include "datatype.h" |
#include "datatype.h" |
#include "stackm.h" |
#include "stackm.h" |
Line 35 struct object cgiUrlEncodingToKeyValuePair(char *s) { |
|
Line 35 struct object cgiUrlEncodingToKeyValuePair(char *s) { |
|
for (i=0; i<n; i++) { |
for (i=0; i<n; i++) { |
if (s[i] == '?') { start=i+1; break;} |
if (s[i] == '?') { start=i+1; break;} |
} |
} |
if (start == -1) start=0; |
if (start == -1) { |
|
start = 0; |
|
for (i=0; i<n; i++) { |
|
if (s[i] > ' ') { start = i; break; } |
|
} |
|
} |
for (k=0; k<2; k++) { |
for (k=0; k<2; k++) { |
/* k==0 path one. Count nOfPairs. */ |
/* k==0 path one. Count nOfPairs. */ |
/* k==1 path two. generate array. */ |
/* k==1 path two. generate array. */ |
Line 312 int cgiKeyValuePairToUrlEncodingFile2(struct object ob |
|
Line 317 int cgiKeyValuePairToUrlEncodingFile2(struct object ob |
|
eob = getoa(ob,i); |
eob = getoa(ob,i); |
eob0 = getoa(eob,0); eob1 = getoa(eob,1); |
eob0 = getoa(eob,0); eob1 = getoa(eob,1); |
key = KopString(eob0); |
key = KopString(eob0); |
if (i == 0) { |
if ((i == 0) && (strcmp(key,"URL")==0)) { |
if (strcmp(key,"URL") != 0) warningKan("Key word should be URL.\n"); |
|
if (eob1.tag != Sdollar) errorKan1("%s\n","URL value must be a string."); |
if (eob1.tag != Sdollar) errorKan1("%s\n","URL value must be a string."); |
fp2fputs(KopString(eob1),fp); |
fp2fputs(KopString(eob1),fp); |
if ( n > 1 ) fp2fputc('?',fp); |
if ( n > 1 ) fp2fputc('?',fp); |
Line 548 struct object KooUrlEncodedStringToObj(struct object s |
|
Line 552 struct object KooUrlEncodedStringToObj(struct object s |
|
n = getByteArraySize(sob); |
n = getByteArraySize(sob); |
}else errorKan1("%s\n","KooUrlEncodedStringToObj: argument must be a string."); |
}else errorKan1("%s\n","KooUrlEncodedStringToObj: argument must be a string."); |
return urlEncodedStringToObj(s,0,n-1,0); |
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; |
|
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); |
} |
} |