summaryrefslogtreecommitdiffstats
path: root/libcsoap/soap-env.h
blob: b73bb38489471e060a52cb560f15367afb45654b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
/******************************************************************
 *  $Id: soap-env.h,v 1.17 2006/11/23 15:27:33 m0gg Exp $
 *
 * CSOAP Project:  A SOAP client/server library in C
 * Copyright (C) 2003  Ferhat Ayaz
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA  02111-1307, USA.
 * 
 * Email: ayaz@jprogrammer.net
 ******************************************************************/
#ifndef __csoap_env_h
#define __csoap_env_h

/**
 *
 * The SOAP envelope namespace
 *
 */
static const char * const soap_env_ns = "http://schemas.xmlsoap.org/soap/envelope/";

/**
 *
 *  The SOAP envelope object. 
 *
 */
struct SoapEnv
{
  xmlNodePtr root; /** Pointer to the firts xml element (envelope) */
  xmlNodePtr header;
  xmlNodePtr body;
  xmlNodePtr cur; /** Pointer to the current xml element. (stack) */
};

typedef void (*XmlSerializerCallback) (void * obj, const xmlChar *root_element_name, void (*OnStartElement) (const xmlChar * element_name, int attr_count, xmlChar ** keys, xmlChar ** values, void *userData), void (*OnCharacters) (const xmlChar * element_name, const xmlChar * chars, void *userData), void (*OnEndElement) (const xmlChar * element_name, void *userData), void *userdata);

#ifdef __cplusplus
extern "C" {
#endif

/**
 *
 * Creates an envelope with a fault object. 
 *
 * @param faultcode The fault code @see fault_code_t
 * @param faultstring A fault message
 * @param faultactor The fault actor (This can be NULL)
 * @param detail The detail of the error (This can be NULL)
 * @param out the result envelope out parameter like follows
 *
 *  <pre>
 *  <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
 *       xmlns:xsi="..."
 *     xmlns:xsd="...">
 *   <SOAP-ENV:Body>
 *
 *	 <Fault>
 *	  <faultcode>...</faultcode>
 *	  <faultstring>...</faultstring>
 *	  <faultactor>...</faultactor>
 *	  <faultdetail>..</faultdetail>
 *	 </Fault>
 *
 *   </SOAP-ENV:Body>
 *  </SOAP-ENV:Envelope>
 *  </pre>
 *
 * @returns H_OK if success
 *
 * @see	soap_fault_new
 *
 */
extern herror_t soap_env_new_with_fault(int faultCode, const char *faultString, const char *faultActor, const char *detail, struct SoapEnv **out);

/**
 *
 * Creates an envelope with a method to invoke a soap service.
 * Use this function to create a client call.
 *
 * @param urn The urn of the soap service to invoke
 * @param method The method name of the soap service
 *
 * @param out the result envelope out parameter like follows
 * @returns H_OK if success
 *
 * <pre>
 * <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
 *      xmlns:xsi="..."
 *      xmlns:xsd="...">
 *    <SOAP-ENV:Body>
 *
 *     <m:[method] xmlns:m="[urn]">
 *     </m:[method]>
 *
 *    </SOAP-ENV:Body>
 * </SOAP-ENV:Envelope>
 * 
 * </pre>
 *
 */
extern herror_t soap_env_new_with_method(const char *urn, const char *method, struct SoapEnv ** out);

/**
 *
 * Creates a soap envelope with a response. 
 * Use this function to create a response envelope object
 * for a request. This function is only relevant for soap 
 * service implementors. 
 *
 * @see example csoap/simpleserver.c
 *
 * @param req The request object. A response object will be created
 *  to this request.
 *
 * @param out the result envelope out paramter like follows
 * @returns H_OK if success
 *
 * <pre>
 * <SOAP-ENV:Envelope xmlns:SOAP-ENV="..." SOAP-ENV:encoding="..."
 *      xmlns:xsi="..."
 *      xmlns:xsd="...">
 *    <SOAP-ENV:Body>
 *
 *     <m:[req-method]Response xmlns:m="[req-urn]">
 *     </m:[req-method]>
 *
 *    </SOAP-ENV:Body>
 * </SOAP-ENV:Envelope>
 * 
 * </pre>
 *
 *
 */
extern herror_t soap_env_new_with_response(struct SoapEnv * req, struct SoapEnv ** out);

/**
 *
 * Creates an envelope from a given libxml2 xmlDocPtr.
 *
 * @param doc the xml document pointer
 * @param out the output envelope object
 *
 * @returns H_OK if success
 *  
 */
extern herror_t soap_env_new_from_doc(xmlDocPtr doc, struct SoapEnv ** out);

/**
 *
 * Create an envelop object from a string. 
 * The string must be in xml format.
 *
 * @param buffer The string to parse into a envelope.
 * @param out the output envelope object
 * @returns H_OK if success
 */
extern herror_t soap_env_new_from_buffer(const char *buffer, struct SoapEnv ** out);

/**
 *
 * Adds a new xml node under the current parent.
 *
 * <pre>
 *  <m:[name] type=[type]>[value]</m:[name]>
 * </pre>
 * 
 * @param env The envelope object 
 * @param type Type of the parameter. Something like "xsd:string" or
 *  "xsd:int" or custom types. 
 * @param name Name of the xml node
 * @param value Text value of the xml node
 *
 * @returns The added xmlNode pointer.
 * 
 * @see tutorial 
 *
 */
extern xmlNodePtr soap_env_add_item(struct SoapEnv * env, const char *type, const char *name, const char *value);

/**
 *
 *  Adds attachment href node to the envelope current parent.
 *
 * <pre>
 *  <m:[name] href=[href]/>
 * </pre>
 *
 * @param env The envelope object 
 * @param name Name of the xml node
 * @param href href. A CID string filled by 
 *   soap_ctx_add_attachment()
 *
 * @returns The added xmlNode pointer.
 * 
 * @see soap_ctx_add_file tutorial 
 */
extern xmlNodePtr
soap_env_add_attachment(struct SoapEnv * env, const char *name, const char *href);

/**
 *
 *  Serialize and adds obj to the envelope.
 *  TODO: Document this function !
 *  <br>
 *  <b>Important: </b> 
 *
 */
extern void soap_env_add_custom(struct SoapEnv * env, void *obj, XmlSerializerCallback cb, const char *type, const char *name);

/**
 *
 * Same as soap_env_add_item() with c style arguments
 * like in printf(). "value" is the format string.
 * <br>
 * <b>Important: </b> The totally length of value (incl. args)
 *  must be lower the 1054.
 *
 * @see soap_env_add_item
 */
extern xmlNodePtr
soap_env_add_itemf(struct SoapEnv * env, const char *type, const char *name, const char *value, ...);

/**
 *
 * Push the current xml node in the soap envelope one level 
 * deeper. Here an example:
 * 
 * <pre>
 * soap_env_push_item(env, "my:custom", "Person");
 *  soap_env_add_item(env, "xsd:string", "name", "Mickey");
 *  soap_env_add_item(env, "xsd:string", "lastname", "Mouse");
 * soap_env_pop_item(env);
 * </pre>
 *
 * This will create the xml like follows.
 *
 * <pre>
 * <Person type="my:custom">
 *  <name>Mickey</name>
 *  <lastname>Mouse</lastname>
 * </Person>
 * </pre>
 *
 * @returns The added xmlNode pointer.
 * 
 * @see tutorial 
 *
 */
extern xmlNodePtr soap_env_push_item(struct SoapEnv * env, const char *type, const char *name);

/**
 *
 *  Sets the xml pointer 1 level higher. 
 *
 *  @param env The envelope object
 *
 *  @see soap_env_push_item
 */
extern void soap_env_pop_item(struct SoapEnv * env);

/**
 *
 *  Free the envelope. 
 *
 *  @param env The envelope object
 *
 */
extern void soap_env_free(struct SoapEnv * env);

/**
 *
 * Gets the xml node pointing to SOAP Body.
 *
 */
extern xmlNodePtr soap_env_get_body(struct SoapEnv * env);


/**
 *
 * Get the xml node pointing to SOAP method (call)
 *
 */
extern xmlNodePtr soap_env_get_method(struct SoapEnv * env);

/**
 *
 *  Get the xml node pointing to SOAP Fault
 *
 */
extern xmlNodePtr soap_env_get_fault(struct SoapEnv * env);

/**
 *
 * Get the xml node pointing to SOAP Header
 *
 */
extern xmlNodePtr soap_env_get_header(struct SoapEnv * env);

/**
 *
 * Get the URN of the message.
 *
 */
extern const char *soap_env_find_urn(struct SoapEnv * env);

/**
 *
 * Get the method of the message.
 *
 */
extern const char *soap_env_find_methodname(struct SoapEnv * env);

#ifdef __cplusplus
}
#endif

#endif