gSoap generated client-side structure initialization and use (using ANSI C bindings)
After reading through gSoap examples and documentation I was not able to find anything directly answering this issue. I have since sorted it out. This post/answer pair lays out the problem and my solution.
Problem description:
I am using gSoap generated client source code to build ANSI C bindings to access web services. Arguments 4 & 5 of the "soap_call__" functions provided as application interfaces (defined in soapClient.c) are often generated as complex (nested) structures. Because struct ns3__send (4th argument) is the input structure, it must be declared, initialized, allocated and freed within the calling application.
for example, given the following gSoap generated prototype:
SOAP_FMAC5 int SOAP_FMAC6 soap_call___ns1__SendFile((struct soap *soap, const char *soap_endpoint, const char *soap_action, struct ns3__send *mtdf, struct recv *response)
with the following structure definition (looking only at argument 4) defined in soapStub.h
NOTE: I have shortened the names and reduced the number of members from original contents of the structures to simplify.
struct ns3__send
{
char *wsStDate; /* optional element of type xsd:date */
int *wsStDuration; /* optional element of type xsd:int */
int *wsStFailures; /* optional element of type xsd:int */
char *wsStFileName; /* optional element of type xsd:string */
struct ns3__Param *details; /* optional element of type ns3:Param */
};
struct ns3__Param
{
int __sizeRow; /* sequence of elements <wsStdDetailsRow> */
struct ns3__Row *row; /* optional element of type ns3:xxmtdfws_wsStdDetailsRow */
};
struct ns3__Row
{
int *wsStdSeq; /* optional element of type xsd:int */
char *wsStdStep; /* optional element of type xsd:string */
char *wsStdTestDesc; /* optional element of type xsd:string */
char *wsStdLowLim; /* optional element of type xsd:string */
};
Question:
How are the members and pointers within this complex (nested) input structure properly initialized, memory allocated, values assigned and memory freed such that they are useable within a calling application?
The following describes an ANSI C method for initializing, allocating, assigning and freeing members and pointers within a nested structure construct where the number of fields in the nested section is unknown until run-time.
To explain the shape of structs requiring this treatment, The data schema is comprised of a known number of header fields, each field having one value per row. The last field (row) serves as a delimiter
********between the header and data sections. The data section contains an unknown number of data records, but each record contains a known (and constant) number of comma delimited fields:Example data:

The two files shown below are fully commented. Together, they will compile and build with any ANSI C compiler:
InitComplexStructs.h:
InitComplexStructs.c