Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hi there
Im in the process of implementing an XMLRPC library(nothing fancy) for a Uni project, written in C.
I have a problem and that I have a function called XmlRpcBuildRequest
which basically builds an xmlrpc request as an xml documnent.It will be something like :
XmlRpcBuildRequest("My.Method","MyParam1",100,100.0,myStruct);
It will bascially take a variable arg list and use this list to build the xml.
All this works fine apart from the struct parameter.
How do I pass any struct defined by the user and then get the contents from the struct to build the xml params e.g.
struct foo
{
int x;
int y;
};
struct foo a;a.x=10;
a.y=20;I then some how need to re-package the struct from the xmlrpc request on the server side to pass the struct into the server method.
Any good ideas?
I hope im clear in my explanation.
Many thanks in advanced.

The only way I know of to pass "any struct" to a function is by way of a (void*).
This doesn't give you any clue as to what (or even how much) is inside the struct. You'll need to know at least the "how much" part so you'll probably need to pass a length as well as a pointer.
But you still don't know what's in the struct. And that's the end of the C tricks. In order to go any further, you have to give up on "any struct" and demand that the user structure the data in SOME fashion. You could, for example, pass data as ASCII text that can be subjected to a parser on the remote side. Or you could limit the structs that are used to some set that defines the sort of thing that the server knows how to deal with.
XmlRpcBuildRequest can be constructed without specific knowledge of the contents of the structs, but I don't think the server side software can. This may be enough to solve your dilemma, since it could be that MyMethod is to be passed the struct for interpretation and MyMethod knows, by definition, how to pass the struct that comes with it. In this case, simply have MyMethod accept the struct as a (void*) and cast it to the struct type of interest - then check carefully for struct validity (no sense in opening yourself to hackers).
Make any sense?
Jeff

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |