- Made sinqhttprot go asynchronous properly, the library was hiding a

problem
- Cleaned up sanslirebin
This commit is contained in:
koennecke
2008-07-14 07:23:42 +00:00
parent 0eeaaaff9d
commit fa59313759
3 changed files with 235 additions and 117 deletions

View File

@@ -55,12 +55,47 @@ static int configRequest(Ascon *a){
return 1;
}
/*---------------------------------------------------------------------*/
static void handleReply(Ascon *a){
char *pPtr = NULL, *pType = NULL;
int len, i, *dataPtr = NULL;
HistInt *hmData = NULL;
pHttpProt pHttp = (pHttpProt)a->private;
pPtr = ghttp_get_body(pHttp->request);
len = ghttp_get_body_len(pHttp->request);
if(strstr(pPtr,"ERROR") != NULL){
AsconError(a,pPtr, a->state);
DynStringConcat(a->rdBuffer,pPtr);
} else if(strstr(pPtr,"Authentication Error") != NULL){
DynStringConcat(a->rdBuffer,pPtr);
AsconError(a,pPtr, a->state);
} else {
pType = (char *)ghttp_get_header(pHttp->request,"Content-Type");
if(strstr(pType,"sinqhm") == NULL){
/* text data */
for(i = 0; i < len; i++){
DynStringConcatChar(a->rdBuffer, pPtr[i]);
}
} else {
hmData = (HistInt *)pPtr;
clearSICSData(pHttp->binData);
len = len/sizeof(HistInt);
dataPtr = getSICSDataPointer(pHttp->binData, 0, len);
for(i = 0; i < len; i++){
dataPtr[i] = htonl(hmData[i]);
}
assignSICSType(pHttp->binData, 0, len, INTTYPE);
DynStringCopy(a->rdBuffer,"SICSDATA");
}
}
}
/*---------------------------------------------------------------------*/
static int HttpHandler(Ascon *a) {
ghttp_status status;
pHttpProt pHttp = (pHttpProt)a->private;
char *pPtr = NULL, *pType = NULL;
HistInt *hmData = NULL;
int i, len, *dataPtr;
int socke, selStat;
fd_set rmask;
struct timeval tmo = {0,0};
switch (a->state) {
case AsconConnectStart:
@@ -92,19 +127,38 @@ static int HttpHandler(Ascon *a) {
DynStringClear(a->rdBuffer);
break;
case AsconReadStart:
socke = ghttp_get_socket(pHttp->request);
FD_ZERO(&rmask);
FD_SET(socke,&rmask);
selStat = select(socke+1,&rmask, NULL, NULL, &tmo);
if(selStat != 0){
status = ghttp_process(pHttp->request);
a->state = AsconReading;
} else {
if(DoubleTime() > a->start + a->timeout){
AsconError(a," read timeout", 0);
a->state = AsconTimeout;
/* this to clear the line */
ghttp_close(pHttp->request);
}
}
return 1;
break;
case AsconReading:
status = ghttp_process(pHttp->request);
switch(status){
case ghttp_not_done:
if(DoubleTime() > a->start + a->timeout){
AsconError(a," read timeout", 0);
a->state = AsconTimeout;
/* this to clear the line */
ghttp_close(pHttp->request);
}
return 1;
if(DoubleTime() > a->start + a->timeout){
AsconError(a," read timeout", 0);
a->state = AsconTimeout;
/* this to clear the line */
ghttp_close(pHttp->request);
}
return 1;
case ghttp_done:
a->state = AsconReading;
break;
handleReply(a);
a->state = AsconReadDone;
break;
case ghttp_error:
/*
* A first error may not be an error but a
@@ -118,42 +172,10 @@ static int HttpHandler(Ascon *a) {
DynStringConcat(a->rdBuffer,"Server error");
a->state = AsconReadDone;
}
return 1;
break;
default:
printf("Hugo\n");
break;
}
break;
case AsconReading:
pPtr = ghttp_get_body(pHttp->request);
len = ghttp_get_body_len(pHttp->request);
if(strstr(pPtr,"ERROR") != NULL){
AsconError(a,pPtr, a->state);
DynStringConcat(a->rdBuffer,pPtr);
} else if(strstr(pPtr,"Authentication Error") != NULL){
DynStringConcat(a->rdBuffer,pPtr);
AsconError(a,pPtr, a->state);
} else {
pType = (char *)ghttp_get_header(pHttp->request,"Content-Type");
if(strstr(pType,"sinqhm") == NULL){
/* text data */
for(i = 0; i < len; i++){
DynStringConcatChar(a->rdBuffer, pPtr[i]);
}
} else {
hmData = (HistInt *)pPtr;
clearSICSData(pHttp->binData);
len = len/sizeof(HistInt);
dataPtr = getSICSDataPointer(pHttp->binData, 0, len);
for(i = 0; i < len; i++){
dataPtr[i] = htonl(hmData[i]);
}
assignSICSType(pHttp->binData, 0, len, INTTYPE);
DynStringCopy(a->rdBuffer,"SICSDATA");
}
}
a->state = AsconReadDone;
break;
break;
default:
return AsconStdHandler(a);
}