- From: Sofiane Cherchalli <abou_sofiane@hotmail.com>
- Date: Mon, 7 Feb 2000 08:20:19 -0500 (EST)
- To: www-lib@w3.org
Hi, I'm having a big problem using the PostFormAnchorToChunk function. I
wrote a simple library which is based on libwww library to transmit xml
message using HTTP post form between a unix (solaris 2.7) client (linked
with libwww) and Netscape Server 4.0 running on windows NT. I configured
Netscape server to run perl scripts as cgi shell. I wrote a very simple
script in perl 'hello.pl' wich prints a "Hello World" message. I tested this
script on a client browser (netscape navigator). It works well.
The binary sample name that I wrote which is based on my library is
'TestXMLRequest'. The command line is :
TestXMLRequest http://myserver/cgi/cgi-shell/hello.pl "xml message" 80
where 80 is the http port number.
When I run the program TestXMLRequest I get the 'HTTP/1.1 500 Server Error'
The wierd thing is that if I run the program refering to an html file
instead of my perl file it returns me the content of the html file:
TestXMLRequest http://myserver/docroot/index.html "xml message" 80
It seems also that in both cases the form parameters are not transmited
Please could anyone one help me cuz I'm getting mad, this is an emergency :
Thanks in advance,
Sofiane CHERCHALLI
Here I include the source file of my library and the sample program :
########################## XMLRequest.h #############################
#ifndef __XMLREQUEST_H
#define __XMLREQUEST_H
#include "WWWLib.h"
#include "WWWInit.h"
#include "WWWHTTP.h"
typedef struct {
char * uri_str;
int port;
int timeout;
int status;
char * xml_in_str;
char * xml_out_str;
HTRequest * request;
HTAnchor * uri_anchor;
HTAssocList * formfields;
HTChunk * chunk;
} XMLRequest;
extern void XMLRequest_init (BOOL trace);
extern void XMLRequest_terminate ();
extern XMLRequest * XMLRequest_new (const char * uri_str, int port, int
timeout, const char * xml_in_str);
extern void XMLRequest_post (XMLRequest * xmlr);
extern BOOL XMLRequest_delete(XMLRequest * xmlr);
#endif
#####################################################################
######################### XMLRequest.c ##############################
#include "XMLRequest.h"
#define MILLIES 1000
PRIVATE int printer (const char * fmt, va_list pArgs)
{
return (vfprintf(stdout, fmt, pArgs));
}
PRIVATE int tracer (const char * fmt, va_list pArgs)
{
return (vfprintf(stderr, fmt, pArgs));
}
PRIVATE int terminate_handler (HTRequest * request, HTResponse * response,
void * param, int status)
{
XMLRequest * xmlr = (XMLRequest *) HTRequest_context(request);
xmlr->status = status;
HTPrint("STATUS = %d\n", status);
/* Get the response content and set xml_out_str to point to it */
if (status == HT_LOADED && xmlr->chunk && HTChunk_data(xmlr->chunk)) {
xmlr->xml_out_str = HTChunk_data(xmlr->chunk);
}
HTEventList_stopLoop();
return HT_OK;
}
PUBLIC void XMLRequest_init (BOOL trace)
{
HTList * converters = HTList_new();
HTList * transfert_encodings = HTList_new();
if (!HTLib_isInitialized()) HTLibInit("XMLRequest-Library", "1.0");
HTEventInit();
HTAlertInit();
HTTransport_add("buffered_tcp", HT_TP_SINGLE, HTReader_new,
HTBufferWriter_new);
HTProtocol_add("http", "buffered_tcp", HTTP_PORT, YES, HTLoadHTTP,
NULL);
HTNet_setMaxSocket(50);
HTNetInit();
HTNet_addAfter(terminate_handler, NULL, NULL, HT_ALL, HT_FILTER_LAST);
HTProxy_getEnvVar();
HTConverterInit(converters);
HTFormat_setConversion(converters);
HTTransferEncoderInit(transfert_encodings);
HTFormat_setTransferCoding(transfert_encodings);
HTMIMEInit();
HTFileInit();
HTIconInit(NULL);
/* Need our own trace and print functions */
if (trace) {
HTPrint_setCallback(printer);
HTTrace_setCallback(tracer);
HTSetTraceMessageMask("p");
}
}
PUBLIC void XMLRequest_terminate ()
{
HTEventTerminate();
if (HTLib_isInitialized()) {
HTFormat_deleteAll();
HTLibTerminate();
}
}
PUBLIC XMLRequest * XMLRequest_new (const char * uri_str, int port, int
timeout, const char * xml_in_str)
{
XMLRequest * xmlr;
if ((xmlr = (XMLRequest *) HT_CALLOC(1, sizeof(XMLRequest))) == NULL)
return NULL;
if (uri_str && *uri_str && xml_in_str && *xml_in_str) {
xmlr->uri_str = (char *)uri_str;
xmlr->port = port;
xmlr->timeout = timeout * MILLIES;
xmlr->status = HT_ERROR;
xmlr->xml_in_str = (char *)xml_in_str;
xmlr->formfields = HTAssocList_new();
HTAssocList_addObject(xmlr->formfields, "xmlmsg", xmlr->xml_in_str);
xmlr->uri_anchor = HTAnchor_findAddress(uri_str);
xmlr->chunk = NULL;
xmlr->request = HTRequest_new();
HTRequest_setOutputFormat(xmlr->request, WWW_SOURCE);
HTRequest_setMaxRetry(5);
HTRequest_setContext(xmlr->request, xmlr);
}
return xmlr;
}
PUBLIC BOOL XMLRequest_delete(XMLRequest * xmlr)
{
if (xmlr) {
HTRequest_delete(xmlr->request);
if (xmlr->uri_anchor) {
HTAnchor_delete((HTParentAnchor *)xmlr->uri_anchor);
xmlr->uri_anchor = NULL;
}
if (xmlr->formfields) {
HTAssocList_delete(xmlr->formfields);
xmlr->formfields = NULL;
}
if (xmlr->chunk) {
HTChunk_delete(xmlr->chunk);
xmlr->chunk = NULL;
}
HT_FREE(xmlr);
return YES;
}
return NO;
}
PUBLIC void XMLRequest_post (XMLRequest * xmlr)
{
BOOL status = NO;
HTProtocol_delete("http");
HTProtocol_add("http", "buffered_tcp", xmlr->port, NO, HTLoadHTTP,
NULL);
/* Set a timeout for response */
HTHost_setEventTimeout(xmlr->timeout);
/* POST the source to the dest */
xmlr->chunk = HTPostFormAnchorToChunk(xmlr->formfields,
xmlr->uri_anchor, xmlr->request);
/* Go into the event loop... */
HTEventList_loop(xmlr->request);
/* Only gets here if event loop fails */
HTPrint("Timeout");
xmlr->status = HT_ERROR;
}
####################################################################
############################ TestXMLRequest.c ######################
#include "XMLRequest.h"
int main(int argc, char **argv)
{
XMLRequest * xmlr = NULL;
char * uri_str = argv[1];
char * xml_in_str = argv[2];
int port = atoi(argv[3]);
XMLRequest_init(YES);
xmlr = XMLRequest_new(uri_str, port, 10000, xml_in_str);
XMLRequest_post(xmlr);
XMLRequest_delete(xmlr);
XMLRequest_terminate();
return 0;
}
##################################################################
########################################## Makefile ################
CC = c89
LIBWWW_INCLUDE = `libwww-config --cflags`
LIBWWW_LIBS = `libwww-config --libs`
all : libXMLRequest.so XMLRequest.o TestXMLRequest.o TestXMLRequest
libXMLRequest.so : XMLRequest.o
c89 -G -h libXMLRequest.so -o libXMLRequest.so XMLRequest.o
# Create links to your local library
# ln -s ./libXMLRequest.so /usr/lib/libXMLRequest.so
# ln -s ./libXMLRequest.so /usr/lib/libXMLRequest.so.1
XMLRequest.o : XMLRequest.h XMLRequest.c
$(CC) -KPIC -c $(LIBWWW_INCLUDE) XMLRequest.c
TestXMLRequest.o : TestXMLRequest.c
$(CC) -c $(LIBWWW_INCLUDE) TestXMLRequest.c
TestXMLRequest : TestXMLRequest.o XMLRequest.o
$(CC) $(LIBWWW_LIBS) -lXMLRequest -o TestXMLRequest TestXMLRequest.o
####################################################################
______________________________________________________
Get Your Private, Free Email at http://www.hotmail.com
Received on Monday, 7 February 2000 08:28:58 UTC