version 1.6, 2002/10/20 07:58:18 |
version 1.7, 2002/10/21 00:37:00 |
|
|
/* $OpenXM: OpenXM/src/kan96xx/plugin/sm1Socket.c,v 1.5 2002/10/17 13:40:29 takayama Exp $ */ |
/* $OpenXM: OpenXM/src/kan96xx/plugin/sm1Socket.c,v 1.6 2002/10/20 07:58:18 takayama Exp $ */ |
/* msg0s.c */ |
/* msg0s.c */ |
#include <stdio.h> |
#include <stdio.h> |
#include <sys/types.h> |
#include <sys/types.h> |
Line 529 struct object KsocketWriteByte(struct object obj) { |
|
Line 529 struct object KsocketWriteByte(struct object obj) { |
|
return(KpoInteger(r)); |
return(KpoInteger(r)); |
} |
} |
|
|
struct object KsocketReadBlock(struct object socketObj) { |
struct object KsocketReadHTTP(struct object socketObj) { |
/* Read until the empty line appears. */ |
/* Read until two empty line appears. */ |
struct object ob; |
struct object ob; |
char *s; |
char *s; |
char *sss; |
char *sss; |
char *tmp; |
char *tmp; |
int i; |
int i; |
int flag; |
int flag; |
|
int flagmax = 1; |
int datasize; |
int datasize; |
|
int last; |
ob = KsocketRead(socketObj); |
ob = KsocketRead(socketObj); |
s = KopString(ob); |
s = KopString(ob); |
|
if (strncmp(s,"POST",4) == 0) flagmax=2; |
|
else flagmax=1; |
flag = 0; |
flag = 0; |
for (i=strlen(s)-1; i>=0; i--) { |
for (i=strlen(s)-1; i>=0; i--) { |
if ((s[i] == '\n') && (i==0)) { |
if ((s[i] == '\n') && (i==0)) { |
flag = 1; |
++flag; |
}else if ((s[i] == '\n') && (s[i-1] == '\n')) { |
}else if ((s[i] == '\n') && (s[i-1] == '\n')) { |
flag = 1; |
++flag; |
}else if ((s[i] == 0xd) && (s[i+1] == 0xa) && (i == 0)) { |
}else if ((s[i] == 0xd) && (s[i+1] == 0xa) && (i == 0)) { |
flag = 1; |
++flag; |
}else if ((s[i] == 0xa) && (s[i-1] == 0xd) && (s[i+1] == 0xd) && (s[i+2] == 0xa)) { |
}else if ((s[i] == 0xa) && (s[i-1] == 0xd) && (s[i+1] == 0xd) && (s[i+2] == 0xa)) { |
flag = 1; |
++flag; |
} |
} |
} |
} |
if (flag == 1) return ob; |
if (flag >= flagmax) return ob; |
datasize = strlen(s); |
datasize = strlen(s); |
sss = s; |
sss = s; |
|
if ((s[strlen(s)-1] == '\n') || |
|
(s[strlen(s)-2] == 0xd) && (s[strlen(s)-1] == 0xa)) { |
|
last = 1; |
|
}else last = 0; |
|
|
while (flag == 0) { |
while (flag < flagmax) { |
fprintf(stderr,"Waiting in socketReadBlock (spin lock to wait an empty line).\n"); |
fprintf(stderr,"Waiting in socketReadBlock (spin lock to wait an empty line). flagmax(0d,0a)=%d\n",flagmax); |
if (strlen(s) == 0) {fprintf(stderr,"but I'm not receiving data. Expecting a bug.\n"); |
if (strlen(s) == 0) {fprintf(stderr,"but I'm not receiving data. Expecting a bug.\n"); |
}else{ |
}else{ |
/* for debugging. */ |
/* for debugging. */ |
Line 569 struct object KsocketReadBlock(struct object socketObj |
|
Line 577 struct object KsocketReadBlock(struct object socketObj |
|
sleep(2); |
sleep(2); |
ob = KsocketRead(socketObj); |
ob = KsocketRead(socketObj); |
s = KopString(ob); |
s = KopString(ob); |
flag = 0; |
|
for (i=strlen(s)-1; i>=0; i--) { |
for (i=strlen(s)-1; i>=0; i--) { |
if ((s[i] == '\n') && (i==0)) { |
if ((s[i] == '\n') && (i==0) && last) { |
flag = 1; |
++flag; |
}else if ((s[i] == '\n') && (s[i-1] == '\n')) { |
}else if ((s[i] == '\n') && (s[i-1] == '\n')) { |
flag = 1; |
++flag; |
}else if ((s[i] == 0xd) && (s[i+1] == 0xa) && (i == 0)) { |
}else if ((s[i] == 0xd) && (s[i+1] == 0xa) && (i==0) && last) { |
flag = 1; |
++flag; |
}else if ((s[i] == 0xa) && (s[i-1] == 0xd) && (s[i+1] == 0xd) && (s[i+2] == 0xa)) { |
}else if ((s[i] == 0xa) && (s[i-1] == 0xd) && (s[i+1] == 0xd) && (s[i+2] == 0xa)) { |
flag = 1; |
++flag; |
} |
} |
} |
} |
if (datasize-1 <= strlen(sss)+strlen(s)) { |
if (datasize-1 <= strlen(sss)+strlen(s)) { |
Line 591 struct object KsocketReadBlock(struct object socketObj |
|
Line 598 struct object KsocketReadBlock(struct object socketObj |
|
}else{ |
}else{ |
strcat(sss,s); |
strcat(sss,s); |
} |
} |
|
|
|
if ((s[strlen(s)-1] == '\n') || |
|
(s[strlen(s)-2] == 0xd) && (s[strlen(s)-1] == 0xa)) { |
|
last = 1; |
|
}else last = 0; |
|
|
} |
} |
|
|
return KpoString(sss); |
return KpoString(sss); |
Line 611 struct object Kplugin_sm1Socket(char *key,struct objec |
|
Line 624 struct object Kplugin_sm1Socket(char *key,struct objec |
|
robj = KsocketSelectMulti(obj); |
robj = KsocketSelectMulti(obj); |
}else if (strcmp(key,"read") == 0) { |
}else if (strcmp(key,"read") == 0) { |
robj = KsocketRead(obj); |
robj = KsocketRead(obj); |
}else if (strcmp(key,"readBlock") == 0) { |
}else if (strcmp(key,"readHTTP") == 0) { |
robj = KsocketReadBlock(obj); |
robj = KsocketReadHTTP(obj); |
}else if (strcmp(key,"write") == 0) { |
}else if (strcmp(key,"write") == 0) { |
robj = KsocketWrite(obj); |
robj = KsocketWrite(obj); |
}else if (strcmp(key,"read") == 0) { |
}else if (strcmp(key,"read") == 0) { |