1 /* Copyright and license information is at the end of the file */
3 #ifndef XMLRPC_H_INCLUDED
4 #define XMLRPC_H_INCLUDED
9 #include <xmlrpc-c/util.h>
10 #include <xmlrpc-c/config.h> /* Defines XMLRPC_HAVE_WCHAR */
21 /*=========================================================================
23 **=========================================================================
24 ** We define names for these types, because they may change from platform
28 typedef signed int xmlrpc_int;
29 /* An integer of the type defined by XML-RPC <int>; i.e. 32 bit */
30 typedef signed int xmlrpc_int32;
31 /* An integer of the type defined by XML-RPC <int4>; i.e. 32 bit */
32 typedef int xmlrpc_bool;
33 /* A boolean (of the type defined by XML-RPC <boolean>, but there's
36 typedef double xmlrpc_double;
37 /* A double precision floating point number as defined by
38 XML-RPC <float>. But the C "double" type is universally the same,
39 so it's probably clearer just to use that. This typedef is here
40 for mathematical completeness.
44 typedef SOCKET xmlrpc_socket;
46 typedef int xmlrpc_socket;
49 #define XMLRPC_INT32_MAX (2147483647)
50 #define XMLRPC_INT32_MIN (-XMLRPC_INT32_MAX - 1)
54 /*=========================================================================
56 **=========================================================================
57 ** An XML-RPC value (of any type).
63 XMLRPC_TYPE_DOUBLE = 2,
64 XMLRPC_TYPE_DATETIME = 3,
65 XMLRPC_TYPE_STRING = 4,
66 XMLRPC_TYPE_BASE64 = 5,
67 XMLRPC_TYPE_ARRAY = 6,
68 XMLRPC_TYPE_STRUCT = 7,
69 XMLRPC_TYPE_C_PTR = 8,
71 XMLRPC_TYPE_DEAD = 0xDEAD
74 /* These are *always* allocated on the heap. No exceptions. */
75 typedef struct _xmlrpc_value xmlrpc_value;
78 xmlrpc_abort_if_array_bad(xmlrpc_value * const arrayP);
80 #define XMLRPC_ASSERT_ARRAY_OK(val) \
81 xmlrpc_abort_if_array_bad(val)
83 /* Increment the reference count of an xmlrpc_value. */
84 extern void xmlrpc_INCREF (xmlrpc_value* value);
86 /* Decrement the reference count of an xmlrpc_value. If there
87 ** are no more references, free it. */
88 extern void xmlrpc_DECREF (xmlrpc_value* value);
90 /* Get the type of an XML-RPC value. */
91 extern xmlrpc_type xmlrpc_value_type (xmlrpc_value* value);
94 xmlrpc_int_new(xmlrpc_env * const envP,
98 xmlrpc_read_int(xmlrpc_env * const envP,
99 const xmlrpc_value * const valueP,
100 int * const intValueP);
103 xmlrpc_bool_new(xmlrpc_env * const envP,
104 xmlrpc_bool const boolValue);
107 xmlrpc_read_bool(xmlrpc_env * const envP,
108 const xmlrpc_value * const valueP,
109 xmlrpc_bool * const boolValueP);
112 xmlrpc_double_new(xmlrpc_env * const envP,
113 double const doubleValue);
116 xmlrpc_read_double(xmlrpc_env * const envP,
117 const xmlrpc_value * const valueP,
118 xmlrpc_double * const doubleValueP);
121 xmlrpc_datetime_new_str(xmlrpc_env * const envP,
122 const char * const value);
125 xmlrpc_datetime_new_sec(xmlrpc_env * const envP,
129 xmlrpc_read_datetime_str(xmlrpc_env * const envP,
130 const xmlrpc_value * const valueP,
131 const char ** const stringValueP);
134 xmlrpc_read_datetime_sec(xmlrpc_env * const envP,
135 const xmlrpc_value * const valueP,
136 time_t * const timeValueP);
139 xmlrpc_string_new(xmlrpc_env * const envP,
140 const char * const stringValue);
143 xmlrpc_string_new_lp(xmlrpc_env * const envP,
145 const char * const stringValue);
148 xmlrpc_read_string(xmlrpc_env * const envP,
149 const xmlrpc_value * const valueP,
150 const char ** const stringValueP);
154 xmlrpc_read_string_lp(xmlrpc_env * const envP,
155 const xmlrpc_value * const valueP,
156 size_t * const lengthP,
157 const char ** const stringValueP);
159 #if XMLRPC_HAVE_WCHAR
161 xmlrpc_string_w_new(xmlrpc_env * const envP,
162 const wchar_t * const stringValue);
165 xmlrpc_string_w_new_lp(xmlrpc_env * const envP,
167 const wchar_t * const stringValue);
170 xmlrpc_read_string_w(xmlrpc_env * const envP,
171 xmlrpc_value * const valueP,
172 const wchar_t ** const stringValueP);
175 xmlrpc_read_string_w_lp(xmlrpc_env * const envP,
176 xmlrpc_value * const valueP,
177 size_t * const lengthP,
178 const wchar_t ** const stringValueP);
180 #endif /* XMLRPC_HAVE_WCHAR */
183 xmlrpc_base64_new(xmlrpc_env * const envP,
185 const unsigned char * const value);
188 xmlrpc_read_base64(xmlrpc_env * const envP,
189 const xmlrpc_value * const valueP,
190 size_t * const lengthP,
191 const unsigned char ** const bytestringValueP);
194 xmlrpc_read_base64_size(xmlrpc_env * const envP,
195 const xmlrpc_value * const valueP,
196 size_t * const lengthP);
199 xmlrpc_array_new(xmlrpc_env * const envP);
201 /* Return the number of elements in an XML-RPC array.
202 ** Sets XMLRPC_TYPE_ERROR if 'array' is not an array. */
204 xmlrpc_array_size(xmlrpc_env * const env,
205 const xmlrpc_value * const array);
207 /* Append an item to an XML-RPC array.
208 ** Sets XMLRPC_TYPE_ERROR if 'array' is not an array. */
210 xmlrpc_array_append_item (xmlrpc_env * envP,
211 xmlrpc_value * arrayP,
212 xmlrpc_value * valueP);
215 xmlrpc_array_read_item(xmlrpc_env * const envP,
216 const xmlrpc_value * const arrayP,
217 unsigned int const index,
218 xmlrpc_value ** const valuePP);
220 /* Deprecated. Use xmlrpc_array_read_item() instead.
222 Get an item from an XML-RPC array.
223 Does not increment the reference count of the returned value.
224 Sets XMLRPC_TYPE_ERROR if 'array' is not an array.
225 Sets XMLRPC_INDEX_ERROR if 'index' is out of bounds.
228 xmlrpc_array_get_item(xmlrpc_env * const envP,
229 const xmlrpc_value * const arrayP,
232 /* Not implemented--we don't need it yet.
234 int xmlrpc_array_set_item (xmlrpc_env* env,
237 xmlrpc_value* value);
241 xmlrpc_read_nil(xmlrpc_env * const envP,
242 xmlrpc_value * const valueP);
246 xmlrpc_read_cptr(xmlrpc_env * const envP,
247 const xmlrpc_value * const valueP,
248 void ** const ptrValueP);
251 xmlrpc_struct_new(xmlrpc_env * env);
253 /* Return the number of key/value pairs in a struct.
254 ** Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct. */
256 xmlrpc_struct_size (xmlrpc_env * env,
257 xmlrpc_value * strct);
259 /* Returns true iff 'strct' contains 'key'.
260 ** Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct. */
262 xmlrpc_struct_has_key(xmlrpc_env * const envP,
263 xmlrpc_value * const strctP,
264 const char * const key);
266 /* The same as the above, but the key may contain zero bytes.
267 Deprecated. xmlrpc_struct_get_value_v() is more general, and this
268 case is not common enough to warrant a shortcut.
271 xmlrpc_struct_has_key_n(xmlrpc_env * const envP,
272 xmlrpc_value * const strctP,
273 const char * const key,
274 size_t const key_len);
277 /* Not implemented yet, but needed for completeness. */
279 xmlrpc_struct_has_key_v(xmlrpc_env * env,
280 xmlrpc_value * strct,
281 xmlrpc_value * const keyval);
286 xmlrpc_struct_find_value(xmlrpc_env * const envP,
287 xmlrpc_value * const structP,
288 const char * const key,
289 xmlrpc_value ** const valuePP);
293 xmlrpc_struct_find_value_v(xmlrpc_env * const envP,
294 xmlrpc_value * const structP,
295 xmlrpc_value * const keyP,
296 xmlrpc_value ** const valuePP);
299 xmlrpc_struct_read_value_v(xmlrpc_env * const envP,
300 xmlrpc_value * const structP,
301 xmlrpc_value * const keyP,
302 xmlrpc_value ** const valuePP);
305 xmlrpc_struct_read_value(xmlrpc_env * const envP,
306 xmlrpc_value * const strctP,
307 const char * const key,
308 xmlrpc_value ** const valuePP);
310 /* The "get_value" functions are deprecated. Use the "find_value"
311 and "read_value" functions instead.
314 xmlrpc_struct_get_value(xmlrpc_env * const envP,
315 xmlrpc_value * const strctP,
316 const char * const key);
318 /* The same as above, but the key may contain zero bytes.
319 Deprecated. xmlrpc_struct_get_value_v() is more general, and this
320 case is not common enough to warrant a shortcut.
323 xmlrpc_struct_get_value_n(xmlrpc_env * const envP,
324 xmlrpc_value * const strctP,
325 const char * const key,
326 size_t const key_len);
328 /* Set the value associated with 'key' in 'strct' to 'value'.
329 Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct.
332 xmlrpc_struct_set_value(xmlrpc_env * const env,
333 xmlrpc_value * const strct,
334 const char * const key,
335 xmlrpc_value * const value);
337 /* The same as above, but the key may contain zero bytes. Deprecated.
338 The general way to set a structure value is xmlrpc_struct_set_value_v(),
339 and this case is not common enough to deserve a shortcut.
342 xmlrpc_struct_set_value_n(xmlrpc_env * const env,
343 xmlrpc_value * const strct,
344 const char * const key,
345 size_t const key_len,
346 xmlrpc_value * const value);
348 /* The same as above, but the key must be an XML-RPC string.
349 ** Fails with XMLRPC_TYPE_ERROR if 'keyval' is not a string. */
351 xmlrpc_struct_set_value_v(xmlrpc_env * const env,
352 xmlrpc_value * const strct,
353 xmlrpc_value * const keyval,
354 xmlrpc_value * const value);
356 /* Given a zero-based index, return the matching key and value. This
357 ** is normally used in conjunction with xmlrpc_struct_size.
358 ** Fails with XMLRPC_TYPE_ERROR if 'struct' is not a struct.
359 ** Fails with XMLRPC_INDEX_ERROR if 'index' is out of bounds. */
362 xmlrpc_struct_read_member(xmlrpc_env * const envP,
363 xmlrpc_value * const structP,
364 unsigned int const index,
365 xmlrpc_value ** const keyvalP,
366 xmlrpc_value ** const valueP);
368 /* The same as above, but does not increment the reference count of the
369 two values it returns, and return NULL for both if it fails, and
370 takes a signed integer for the index (but fails if it is negative).
372 Deprecated. Use xmlrpc_struct_read_member() instead.
375 xmlrpc_struct_get_key_and_value(xmlrpc_env * env,
376 xmlrpc_value * strct,
378 xmlrpc_value ** out_keyval,
379 xmlrpc_value ** out_value);
382 xmlrpc_cptr_new(xmlrpc_env * const envP,
386 xmlrpc_nil_new(xmlrpc_env * const envP);
389 /* Build an xmlrpc_value from a format string. */
392 xmlrpc_build_value(xmlrpc_env * const env,
393 const char * const format,
396 /* The same as the above, but using a va_list and more general */
398 xmlrpc_build_value_va(xmlrpc_env * const env,
399 const char * const format,
401 xmlrpc_value ** const valPP,
402 const char ** const tailP);
405 xmlrpc_decompose_value(xmlrpc_env * const envP,
406 xmlrpc_value * const value,
407 const char * const format,
411 xmlrpc_decompose_value_va(xmlrpc_env * const envP,
412 xmlrpc_value * const value,
413 const char * const format,
416 /* xmlrpc_parse_value... is the same as xmlrpc_decompose_value... except
417 that it doesn't do proper memory management -- it returns xmlrpc_value's
418 without incrementing the reference count and returns pointers to data
419 inside an xmlrpc_value structure.
421 These are deprecated. Use xmlrpc_decompose_value... instead.
424 xmlrpc_parse_value(xmlrpc_env * const envP,
425 xmlrpc_value * const value,
426 const char * const format,
429 /* The same as the above, but using a va_list. */
431 xmlrpc_parse_value_va(xmlrpc_env * const envP,
432 xmlrpc_value * const value,
433 const char * const format,
436 /*=========================================================================
438 **=======================================================================*/
440 /* Serialize an XML value without any XML header. This is primarily used
441 ** for testing purposes. */
443 xmlrpc_serialize_value(xmlrpc_env * env,
444 xmlrpc_mem_block * output,
445 xmlrpc_value * value);
447 /* Serialize a list of parameters without any XML header. This is
448 ** primarily used for testing purposes. */
450 xmlrpc_serialize_params(xmlrpc_env * env,
451 xmlrpc_mem_block * output,
452 xmlrpc_value * param_array);
454 /* Serialize an XML-RPC call. */
456 xmlrpc_serialize_call (xmlrpc_env * const env,
457 xmlrpc_mem_block * const output,
458 const char * const method_name,
459 xmlrpc_value * const param_array);
461 /* Serialize an XML-RPC return value. */
463 xmlrpc_serialize_response(xmlrpc_env * env,
464 xmlrpc_mem_block * output,
465 xmlrpc_value * value);
467 /* Serialize an XML-RPC fault (as specified by 'fault'). */
469 xmlrpc_serialize_fault(xmlrpc_env * env,
470 xmlrpc_mem_block * output,
474 /*=========================================================================
476 **=======================================================================*/
478 /* Parse an XML-RPC call. If an error occurs, set a fault and set
479 ** the output variables to NULL.
480 ** The caller is responsible for calling free(*out_method_name) and
481 ** xmlrpc_DECREF(*out_param_array). */
483 xmlrpc_parse_call(xmlrpc_env * const envP,
484 const char * const xml_data,
485 size_t const xml_len,
486 const char ** const out_method_name,
487 xmlrpc_value ** const out_param_array);
490 xmlrpc_parse_response2(xmlrpc_env * const envP,
491 const char * const xmlData,
492 size_t const xmlDataLen,
493 xmlrpc_value ** const resultPP,
494 int * const faultCodeP,
495 const char ** const faultStringP);
498 /* xmlrpc_parse_response() is for backward compatibility */
501 xmlrpc_parse_response(xmlrpc_env * const envP,
502 const char * const xmlData,
503 size_t const xmlDataLen);
506 /*=========================================================================
507 ** XML-RPC Base64 Utilities
508 **=========================================================================
509 ** Here are some lightweight utilities which can be used to encode and
510 ** decode Base64 data. These are exported mainly for testing purposes.
513 /* This routine inserts newlines every 76 characters, as required by the
514 ** Base64 specification. */
516 xmlrpc_base64_encode(xmlrpc_env * env,
517 unsigned char * bin_data,
520 /* This routine encodes everything in one line. This is needed for HTTP
521 ** authentication and similar tasks. */
523 xmlrpc_base64_encode_without_newlines(xmlrpc_env * env,
524 unsigned char * bin_data,
527 /* This decodes Base64 data with or without newlines. */
528 extern xmlrpc_mem_block *
529 xmlrpc_base64_decode(xmlrpc_env * const envP,
530 const char * const ascii_data,
531 size_t const ascii_len);
534 /*=========================================================================
535 ** UTF-8 Encoding and Decoding
536 **=========================================================================
537 ** We need a correct, reliable and secure UTF-8 decoder. This decoder
538 ** raises a fault if it encounters invalid UTF-8.
540 ** Note that ANSI C does not precisely define the representation used
541 ** by wchar_t--it may be UCS-2, UTF-16, UCS-4, or something from outer
542 ** space. If your platform does something especially bizarre, you may
543 ** need to reimplement these routines.
546 /* Ensure that a string contains valid, legally-encoded UTF-8 data.
547 (Incorrectly-encoded UTF-8 strings are often used to bypass security
551 xmlrpc_validate_utf8 (xmlrpc_env * const env,
552 const char * const utf8_data,
553 size_t const utf8_len);
555 /* Decode a UTF-8 string. */
557 xmlrpc_utf8_to_wcs(xmlrpc_env * const envP,
558 const char * const utf8_data,
559 size_t const utf8_len);
561 /* Encode a UTF-8 string. */
563 #if XMLRPC_HAVE_WCHAR
565 xmlrpc_wcs_to_utf8(xmlrpc_env * env,
570 /*=========================================================================
571 ** Authorization Cookie Handling
572 **=========================================================================
573 ** Routines to get and set values for authorizing via authorization
574 ** cookies. Both the client and server use HTTP_COOKIE_AUTH to store
575 ** the representation of the authorization value, which is actually
576 ** just a base64 hash of username:password. (This entire method is
577 ** a cookie replacement of basic authentication.)
580 extern void xmlrpc_authcookie_set(xmlrpc_env * env,
581 const char * username,
582 const char * password);
584 char *xmlrpc_authcookie(void);
590 /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
592 ** Redistribution and use in source and binary forms, with or without
593 ** modification, are permitted provided that the following conditions
595 ** 1. Redistributions of source code must retain the above copyright
596 ** notice, this list of conditions and the following disclaimer.
597 ** 2. Redistributions in binary form must reproduce the above copyright
598 ** notice, this list of conditions and the following disclaimer in the
599 ** documentation and/or other materials provided with the distribution.
600 ** 3. The name of the author may not be used to endorse or promote products
601 ** derived from this software without specific prior written permission.
603 ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
604 ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
605 ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
606 ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
607 ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
608 ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
609 ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
610 ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
611 ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
612 ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF