AcePerl
view release on metacpan or search on metacpan
acelib/aceclientlib.c view on Meta::CPAN
question.reponse.reponse_len = 0;
question.reponse.reponse_val = "";
question.kBytes = chunkSize;
question.aceError = 0;
/* check if request contains a local command */
if (!strncasecmp(request,"encore",6))
{
/* encore request */
question.encore = WANT_ENCORE;
question.question = "";
}
else if (!strncasecmp(request,"noencore",8))
{
/* encore request */
question.encore = DROP_ENCORE;
question.question = "";
}
else if (!strncasecmp(request,"quit",4))
{ /* ignore quit request. Must go through closeServer routine */
*answerLength = 0;
*answerPtr = NULL;
return 0;
}
else
{ question.encore = 0;
question.question = request;
}
if (*encorep == 3)
question.encore = -3 ;
reponse = ace_server_1(&question, handle->clnt);
/* validity checking of reponse */
/* no data was received, return error */
if (!reponse)
return EIO ;
/* store server returned error status. Give this to the client */
/* JC answer could contain more info on error, so
continue normal handling of the answer */
aceError = reponse->ace_reponse_u.res_data.aceError;
/* no answer was received, return NULL answer
leave checking for NULL reponse to upper layer
if (reponse->ace_reponse_u.res_data.reponse.reponse_len == 0) {
xdr_free((xdrproc_t )xdr_ace_reponse, (char *)reponse);
memset (reponse,0, sizeof(ace_reponse)) ;
*answerLength = 0;
*answerPtr = NULL;
return aceError;
}
*/
/* answer received. allocate memory and fill with answer */
length = reponse->ace_reponse_u.res_data.reponse.reponse_len;
loop = (unsigned char *) reponse->ace_reponse_u.res_data.reponse.reponse_val;
encore = reponse->ace_reponse_u.res_data.encore ;
if ((answer = (unsigned char *)malloc(sizeof(unsigned char)*(length+1))) == NULL)
{
/* JC Need to tell the server we have a problem ?
I guess if the server gave an encore, we need to cancel it
*/
xdr_free((xdrproc_t )xdr_ace_reponse, (char *)reponse);
return(ENOMEM);
}
for (i=0;i<length;i++)
answer[i] = loop[i];
answer[i] = 0 ; /* zero terminate */
xdr_free((xdrproc_t )xdr_ace_reponse, (char *)reponse);
*answerPtr = answer;
*answerLength = length;
*encorep = encore ;
return aceError ? aceError : - encore ; /* surcharge pour JD */
}
/***************************************************************
transfer request to server, and wait for binary answer. Convert answer
to ASCII string
INPUT
char * request string containing request
char ** answer ptr to char ptr, that has to be filled with answer
ace_handle * pointer to structure containing open connection
and client identification information
int chunkSize desired size (in kBytes) of returned data-block
This is only a hint. The server can return more.
The server splits on ace boundaries
a chunkSize of 0 indicates a request for unbuffered answers
OUTPUT
char ** answer ptr to char ptr. Pointing to allocated memory containing
answer string.
return value:
int error condition
ESUCCESS (0) no error.
EIO (5) no response received from server.
ENOMEM (12) no memory available to store answer.
or a server generated error
*/
int askServer(ace_handle *handle, char *request, char **answerPtr, int chunkSize)
{ int length, i, encore ;
int returnValue;
unsigned char *binaryAnswer;
char *answer;
char *loop;
returnValue = askServerBinary(handle, request, &binaryAnswer, &length, &encore, chunkSize) ;
if (returnValue <= 0)
{ /* allocate memory for return string */
/* if memory is more important than speed, we could run
through the string first and count the number of '\0''s
and substract this from the memoryblock we allocate */
if (!length ) /* empty string */
{ *answerPtr = 0;
return returnValue;
}
if ((answer = (char *)malloc(length+1)) == NULL)
{ free(binaryAnswer);
return(ENOMEM);
( run in 1.168 second using v1.01-cache-2.11-cpan-39bf76dae61 )