XML-RPC over libwww...
"Paul Ingram" <[email protected]>
| Newsgroups | gmane.comp.lib.libwww |
|---|---|
| Message-ID | <[email protected]> |
Hello all, Yesterday I asked if anyone had brought miniserv in line with the latest release of libww. My reasons for asking are that I am trying to use libwww as the transport mechanism for Epinions XML-RPC. I find the compressed zlib stream of libwww *extremely* interesting and a compelling reason for me to pursue success with integrating my application with libwww. I have been using the listen.c example as the basis for my implementation - and sure enough it works perfectly. I have written my own stream interface based on the libwww examples (attached) which simply takes a copy of the stream for me to play with in my application. I may not even have had to do this. What I haven't discovered yet is how to reply to my XML-RPC client with libwww. I have spent a while wallowing around in the enormity of library and I would truly appreciate a helping hand from a fellow engineer/human being to give me direction. I have attached shamelessly hacked 'listen.c' modified to talk to my application bits and I have also attached my streams interface, which works (well, seems to - no guarantees). Currently both my client and server are based on Codepunk/Indy. http://www.codepunk.com/ http://www.nevrona.com/Indy/ My XML-RPC Client sends... POST /RPC2 HTTP/1.0 Connection: Keep-Alive Content-Type: text/xml Content-Length: 189 Host: localhost:8080 Accept: */* User-Agent: Mozilla/3.0 (compatible; Indy Library) <?xml version="1.0"?> <methodCall> <methodName>example.getHello</methodName> <params> <param> <value><string>Hello</string></value> </param> </params> </methodCall> The Server sends back... HTTP/1.1 200 OK Connection: close Content-Type: text/xml Content-Length: 197 Server: Indy/9.00.10 <?xml version="1.0"?> <methodResponse> <params> <param> <value><string>You just sent some TEXT - it was: "Hello"</string></value> </param> </params> </methodResponse> This is what I want to achieve with libwww as the transport mechanism. I am after the reverse of listen.c, or more exactly a listen.c that can reply to my client. Hence my prior interest in miniserv. I am game on for a pint to any kind contributor who ends up in my neck of the woods. There, there is desperation for you:-) Development environment is Borland C++ Builder 5, set tabstop=2 if the code looks weird. Thank you for taking the trouble to read this, Best Regards, Paul Ingram. Paul Ingram Group Ltd email: [email protected] 140A High Street tel: +44 1483 862860 Godalming fax: +44 1483 862801 Surrey, www.ig.co.uk GU7 1AB United Kingdom www.sitedirector.org
IGHTWrite.h
(application/octet-stream, 744 B)
/*
W3C Sample Code Library libwww ANSI C File Streams
!
Basic ANSI C Stream Content Copy Stream
!
*/
/*
This module contains a basic Content Copy Stream that can be used to
copy data objects to memory. See also the HTFSave module.
This module is implemented by IGHTWrite.c, and it
is derived from the W3C Sample Code Library.
*/
#ifndef IGHTWRITE_H
#define IGHTWRITE_H
#include "HTStream.h"
#include "HTReq.h"
/*
.
Basic ANSI C Content Copy Stream
.
*/
#ifdef __cplusplus
extern "C" { /* Assume C declarations for C++ */
#endif /* __cplusplus */
extern HTStream * IGHTCopy_new(HTRequest *, int (*)(char *, int));
#ifdef __cplusplus
}
#endif /* __cplusplus */
/*
*/
#endif /* IGHTWRITE_H */
/*
*/
IGHTWrite.c
(application/octet-stream, 4.1 KB)
/* IGHTWrite.c
** BASIC CONTENT COPIER STREAM
**
** Derived from code which is (c) COPYRIGHT MIT 1995.
** Please first read the full copyright statement in the file COPYRIGH.
** @(#) $Id: HTFWrite.c,v 2.46 1999/02/22 22:10:11 frystyk Exp $
**
** This version of the stream object just copies the stream contents.
**
** Bugs:
** strings written must be less than buffer size.
**
** History:
** PWI: Took example code and produced this...
** HFN: wrote it
** HWL: converted the caching scheme to be hierachical by taking
** AL code from Deamon
** HFN: moved cache code to HTCache module
**
** Idiosyncracies: This was modified under Borland C++ Builder 5
** and uses a tabstop of two.So if my work looks
** weird in vi you know why.
*/
/* Library include files */
#include "wwwsys.h"
#include "WWWUtil.h"
#include "WWWCore.h"
#include "IGHTWrite.h" /* Implemented here */
#define OUTBUF_SIZE 32768
struct _HTStream {
const HTStreamClass *isa;
char * pc ; /* Private Copy, (char *) 0 if empty */
int len ; /* Size of data in private copy */
int CurBufSize ; /* Size of private buffer */
int (*Func)(char *, int) ;/* Callback function */
};
/* ------------------------------------------------------------------------- */
PRIVATE int IGHTCopy_MemSizeCheck(HTStream * me, int n)
{
return (me->len + n) > me->CurBufSize ;
}
/* ------------------------------------------------------------------------- */
PRIVATE int IGHTCopy_Realloc (HTStream * me, int n)
{
int NewSize = (((me->len + n) / OUTBUF_SIZE) * OUTBUF_SIZE) + OUTBUF_SIZE ;
if ( (me->len + n) > me->CurBufSize )
{
me->pc = me->pc ? malloc(NewSize) : realloc((void *)me->pc, NewSize) ;
if ( me->pc )
me->CurBufSize = NewSize ;
}
return me->pc ? HT_OK : HT_ERROR;
}
/* ------------------------------------------------------------------------- */
PRIVATE int IGHTCopy_put_character (HTStream * me, char c)
{
if ( IGHTCopy_MemSizeCheck(me, 1) )
IGHTCopy_Realloc(me, 1) ;
if ( me->pc )
{
me->pc[me->len] = c ;
me->len++ ;
}
return me->pc ? HT_OK : HT_ERROR;
}
PRIVATE int IGHTCopy_put_string (HTStream * me, const char* s)
{
int NewRequestedSize = strlen(s) + 1 ;
if (*s) /* For vms :-( 10/04-94 */
{
if ( IGHTCopy_MemSizeCheck(me, NewRequestedSize) )
IGHTCopy_Realloc(me, NewRequestedSize) ;
if ( me->pc )
{
memcpy((void *)&me->pc[me->len], (void *)s, NewRequestedSize) ; /* don't forget to take the null */
me->len += NewRequestedSize ;
}
}
return me->pc ? HT_OK : HT_ERROR;
}
PRIVATE int IGHTCopy_flush (HTStream * me)
{
#ifdef POINTLESS_AND_VICIOUS_FLUSH
/* If the buffer is still being used, don't waste time forcing a re-malloc */
if ( me->pc )
free( me->pc ) ;
me->CurBufSize = 0 ;
me->pc = (char *) 0 ;
#endif /* POINTLESS_AND_VICIOUS_FLUSH */
me->len = 0 ;
return HT_OK ;
}
PRIVATE int IGHTCopy_write (HTStream * me, const char* s, int l)
{
if ( IGHTCopy_MemSizeCheck(me, l) )
IGHTCopy_Realloc(me, l) ;
if ( me->pc )
{
memcpy((void *)&me->pc[me->len], (void *)s, l) ; /* don't forget to take the null */
me->len += l ;
me->Func(me->pc, me->len) ;
}
return me->pc ? HT_OK : HT_ERROR;
}
PRIVATE int IGHTCopy_free (HTStream * me)
{
if (me)
{
IGHTCopy_flush(me);
HT_FREE(me);
}
return HT_OK;
}
PRIVATE int IGHTCopy_abort (HTStream * me, HTList * e)
{
HTTRACE(STREAM_TRACE, "FileWriter.. ABORTING...\n");
if (me)
IGHTCopy_free(me);
return HT_ERROR;
}
PRIVATE const HTStreamClass IGHTCopy = /* As opposed to print etc */
{
"StreamContentCopy",
IGHTCopy_flush,
IGHTCopy_free,
IGHTCopy_abort,
IGHTCopy_put_character,
IGHTCopy_put_string,
IGHTCopy_write
};
//PUBLIC HTStream * IGHTCopy_new (HTRequest * request, int (*Func)(char *, int))
PUBLIC HTStream * IGHTCopy_new (HTRequest * request, int (*Func)(char *, int))
{
HTStream * me = NULL;
if ((me = (HTStream *) HT_CALLOC(1, sizeof(HTStream))) == NULL) // cdecl
HT_OUTOFMEM("IGHTCopy_new");
me->isa = &IGHTCopy;
me->Func = Func ;
return me;
}
mainepi.cpp
(application/octet-stream, 12.1 KB) - not displayed