MJL 21/11/06 Fixed bugs in HttpConfigure as per SINQ version.

r1306 | mle | 2006-11-21 09:53:38 +1100 (Tue, 21 Nov 2006) | 2 lines
This commit is contained in:
Mark Lesha
2006-11-21 09:53:38 +11:00
committed by Douglas Clowes
parent 234843cc9a
commit 295eafefe8

View File

@@ -137,8 +137,7 @@ static int anstoHttpGet(pAnstoHttp self, char *request){
self->errorCode = SERVERERROR;
return 0;
} else {
int crstat=anstoHttpCheckResponse(self);
return crstat;
return anstoHttpCheckResponse(self);
}
return 1;
}
@@ -150,6 +149,7 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
pAnstoHttp pPriv = NULL;
int status, iInit;
float fVal;
int i;
char *confData = NULL;
ghttp_status httpStatus;
@@ -196,58 +196,70 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
/*
actually do configure
*/
if(iInit == 0){
memset(confCommand,0,512*sizeof(char));
if(StringDictGet(pOpt,"hmconfigscript",confCommand,511) != 1){
SCWrite(pCon,
"ERROR: required parameter hmconfigscript not found!",
eError);
return 0;
}
status = Tcl_Eval(pSics->pTcl,confCommand);
if(status != TCL_OK){
snprintf(confCommand,511,"ERROR: Tcl reported %s while evaluating hmconfigscript",
Tcl_GetStringResult(pSics->pTcl));
SCWrite(pCon,confCommand,eError);
return 0;
} else {
/*
uplod new configuration to HM
*/
ghttp_clean(pPriv->syncRequest);
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
status = ghttp_set_uri(pPriv->syncRequest,url);
if(status < 0){
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
*/
if(iInit == 1){
for(i = 0; i < 2; i++){
memset(confCommand,0,512*sizeof(char));
if(StringDictGet(pOpt,"hmconfigscript",confCommand,511) != 1){
SCWrite(pCon,
"ERROR: required parameter hmconfigscript not found!",
eError);
return 0;
}
status = ghttp_set_type(pPriv->syncRequest,ghttp_type_post);
confData = (char *)Tcl_GetStringResult(pSics->pTcl);
status = ghttp_set_body(pPriv->syncRequest,confData,
strlen(confData));
ghttp_set_authinfo(pPriv->syncRequest, pPriv->userName,
pPriv->passWord);
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
status = ghttp_prepare(pPriv->syncRequest);
httpStatus = ghttp_process(pPriv->syncRequest);
confData = (char *)ghttp_get_body(pPriv->syncRequest);
if(httpStatus != ghttp_done){
confData = (char *)ghttp_get_error(pPriv->syncRequest);
snprintf(confCommand,511,"ERROR: http error %s occurred",
confData);
status = Tcl_Eval(pSics->pTcl,confCommand);
if(status != TCL_OK){
snprintf(confCommand,511,
"ERROR: Tcl reported %s while evaluating hmconfigscript",
Tcl_GetStringResult(pSics->pTcl));
SCWrite(pCon,confCommand,eError);
return 0;
} else if (confData) { // MJL check ghttp_get_body result for NULL
if(strstr(confData,"ERROR") != NULL){
snprintf(confCommand,511,"%s",confData);
SCWrite(pCon,confCommand,eError);
} else {
/*
uplod new configuration to HM
*/
ghttp_clean(pPriv->syncRequest);
snprintf(url,511,"%s%s",pPriv->hmAddress,configure);
status = ghttp_set_uri(pPriv->syncRequest,url);
if(status < 0){
SCWrite(pCon,"ERROR: invalid URI for HM request",eError);
return 0;
}
if(strstr(confData,"Authentication Error") != NULL){
snprintf(confCommand,511,"%s",confData);
status = ghttp_set_type(pPriv->syncRequest,ghttp_type_post);
confData = (char *)Tcl_GetStringResult(pSics->pTcl);
status = ghttp_set_body(pPriv->syncRequest,confData,
strlen(confData));
ghttp_set_authinfo(pPriv->syncRequest, pPriv->userName,
pPriv->passWord);
ghttp_set_sync(pPriv->syncRequest,ghttp_sync);
status = ghttp_prepare(pPriv->syncRequest);
httpStatus = ghttp_process(pPriv->syncRequest);
confData = (char *)ghttp_get_body(pPriv->syncRequest);
if(httpStatus != ghttp_done){
/* we may need to reconnect.....
*/
if(i == 0){
ghttp_close(pPriv->syncRequest);
continue;
}
/*
* no we have a real error
*/
confData = (char *)ghttp_get_error(pPriv->syncRequest);
snprintf(confCommand,511,"ERROR: http error %s occurred",
confData);
SCWrite(pCon,confCommand,eError);
return 0;
} else if(confData != NULL){
if(strstr(confData,"ERROR") != NULL){
snprintf(confCommand,511,"%s",confData);
SCWrite(pCon,confCommand,eError);
return 0;
}
if(strstr(confData,"Authentication Error") != NULL){
snprintf(confCommand,511,"%s",confData);
SCWrite(pCon,confCommand,eError);
return 0;
}
}
}
}
@@ -288,7 +300,8 @@ static int AnstoHttpConfigure(pHistDriver self, SConnection *pCon,
}
}
} while(pItem);
return 1;
return 1;
}
/*--------------------------------------------------------------------*/
static int readStatus(pHistDriver pDriv){