AcePerl
view release on metacpan or search on metacpan
acelib/aceclientlib.c view on Meta::CPAN
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);
}
/* initial step of the copy process */
loop = (char *)binaryAnswer;
strcpy(answer,loop);
i = *loop ? strlen(loop): 0 ;
loop += i;
for (;(*loop == '\0')&&(i<length) ;loop++,i++);
for (;i<length;)
{ strcat(answer,loop);
i += strlen(loop);
loop += strlen(loop);
for (;(*loop == '\0')&&(i<length) ;loop++,i++);
}
*(answer+i) = '\0'; /* for safety, make sure the string is terminated */
free((char *)binaryAnswer);
*answerPtr = answer;
}
return returnValue;
}
/************** end of file **************/
( run in 0.656 second using v1.01-cache-2.11-cpan-39bf76dae61 )