- From: <linda_fu@peoplesoft.com>
- Date: Fri, 12 Nov 1999 09:33:24 -0800
- To: Patrik.Lannergard@nexus.se
- Cc: www-lib@w3.org
I think it is not correct to use HTProfile_delete( ) before any other function call. HTProfile_delete must be the last function call you want to use for the whole program since it closes every resource the program has established. If you move HTProfile_delete() out of terminate_handler() and move it to the end of main(), it probably works. Regards, Linda Patrik Lannergård <Patrik.Lannergard To: www-lib@w3.org @nexus.se> cc: Sent by: Subject: Help...HTEventList_stopLoop() www-lib-request@w3 .org 11/12/99 01:41 AM Hi my name i Patrik from Sweden and i have for two weeks ago start to use libwww, for internet application. I try to build an application for posting and receiving data. I start to use postform.c example and it works nice until I change the terminal_handler function to use return 1 or 0 instead exit(0) and some strange memory error oocured. I have try to do as people said in the discussion on libwww's homepage .I try to stop (HTEventList_stopLoop(); the eventloop in the end of the terminal_handler function without result. Do you think anybody can help me. The progrma looks like: #include "WWWLib.h" #include "WWWInit.h" PRIVATE HTChunk * result = NULL; PRIVATE char *Response = NULL; /////////////////////////////////////////////////////////////////////////////// // Explanation: // Arguments: // Returnvalues: /////////////////////////////////////////////////////////////////////////////// PRIVATE int printer (const char * fmt, va_list pArgs) { return (vfprintf(stdout, fmt, pArgs)); } /////////////////////////////////////////////////////////////////////////////// // Explanation: // Arguments: // Returnvalues: /////////////////////////////////////////////////////////////////////////////// PRIVATE int tracer (const char * fmt, va_list pArgs) { return (vfprintf(stderr, fmt, pArgs)); } /////////////////////////////////////////////////////////////////////////////// // Explanation: // Arguments: // Returnvalues: /////////////////////////////////////////////////////////////////////////////// PRIVATE int terminate_handler (HTRequest * request, HTResponse * response, void * param, int status) { if (status == HT_LOADED && result && HTChunk_data(result)) { Response = HTChunk_data(result); HTPrint("%s", Response); /* We are done with this request */ HTRequest_delete(request); /* Terminate libwww */ HTProfile_delete(); HTEventList_stopLoop(); return 1; } return 0; } /////////////////////////////////////////////////////////////////////////////// // Explanation: read i file and put it in a buffer // Arguments: unsigned long *data_len,char *filename, char **data // Returnvalues: int, 1 ok 0 error /////////////////////////////////////////////////////////////////////////////// int read_file(unsigned long *data_len,char *filename, char **data) { int result = 1; FILE *input = NULL; input = fopen(filename, "rb"); if(input == NULL) { result = 0; printf("Error\n"); } else if (input != NULL) { *data_len = 0; // get length for file if (fseek(input, 0, SEEK_END) != 0) { result = 0; } else { *data_len = ftell(input); rewind(input); if ((*data = (char*) malloc(*data_len)) != NULL) { if (fread(*data, 1, *data_len, input) != *data_len) { result = 0; } } } fclose(input); } return result; } /////////////////////////////////////////////////////////////////////////////// // Explanation: Main function // Arguments: // Returnvalues: 0 error 1 ok /////////////////////////////////////////////////////////////////////////////// int main (int argc, char ** argv) { HTRequest * request = NULL; HTAnchor * anchor = NULL; HTAssocList * formfields = NULL; char * uri = NULL; unsigned long data_len = 0; char *filename = NULL; char *data = NULL; char *response_result = NULL; if(read_file(&data_len,"D:\\pkcs7.txt",&data)) /* Create a new premptive client */ HTProfile_newNoCacheClient("TestApp", "1.0"); /* Need our own trace and print functions */ HTPrint_setCallback(printer); HTTrace_setCallback(tracer); /* Get trace messages */ #if 0 HTSetTraceMessageMask("sop"); #endif /* Add our own filter to update the history list */ HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST ); /* Set the timeout for long we are going to wait for a response */ //HTHost_setEventTimeout(20000); /* Handle command line args */ if (argc >= 2) { int arg; uri = argv[1]; for (arg=2; arg<argc; arg++) { char * string = argv[arg]; /* Create a list to hold the form arguments */ if (!formfields) { formfields = HTAssocList_new(); } /* Parse the content and add it to the association list */ HTParseFormInput(formfields, string); } } if (uri && formfields) { /* Create a request */ request = HTRequest_new(); /* Set the default output to "asis" */ HTRequest_setOutputFormat(request, WWW_SOURCE); /* Get an anchor object for the URI */ anchor = HTAnchor_findAddress(uri); /* Post the data and get the result in a chunk */ result = HTPostFormAnchorToChunk(formfields, anchor, request); /* Clean up the form fields */ HTAssocList_delete(formfields); /* Go into the event loop... */ HTEventList_loop(request); } else { HTPrint("Type the URI to post to and the arguments for the POST operation. Encode spaces as '+'\n"); HTPrint("\t%s <uri> 'a=1' 'b=+2+' 'c=3 ...'\n", argv[0]); } return 0; } -- Mvh Patrik :-)
Received on Friday, 12 November 1999 12:31:04 UTC