xmlrpc.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783
  1. /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
  2. **
  3. ** Redistribution and use in source and binary forms, with or without
  4. ** modification, are permitted provided that the following conditions
  5. ** are met:
  6. ** 1. Redistributions of source code must retain the above copyright
  7. ** notice, this list of conditions and the following disclaimer.
  8. ** 2. Redistributions in binary form must reproduce the above copyright
  9. ** notice, this list of conditions and the following disclaimer in the
  10. ** documentation and/or other materials provided with the distribution.
  11. ** 3. The name of the author may not be used to endorse or promote products
  12. ** derived from this software without specific prior written permission.
  13. **
  14. ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. ** SUCH DAMAGE. */
  25. #ifndef _XMLRPC_H_
  26. #define _XMLRPC_H_ 1
  27. #include <stddef.h>
  28. #include <stdarg.h>
  29. #ifdef HAVE_UNICODE_WCHAR
  30. #include <wchar.h>
  31. #endif
  32. #ifdef __cplusplus
  33. extern "C" {
  34. #endif
  35. /*=========================================================================
  36. ** Typedefs
  37. **=========================================================================
  38. ** We define names for these types, because they may change from platform
  39. ** to platform.
  40. */
  41. typedef signed int xmlrpc_int;
  42. /* An integer of the type defined by XML-RPC <int>; i.e. 32 bit */
  43. typedef signed int xmlrpc_int32;
  44. /* An integer of the type defined by XML-RPC <int4>; i.e. 32 bit */
  45. typedef int xmlrpc_bool;
  46. /* A boolean (of the type defined by XML-RPC <boolean>, but there's
  47. really only one kind)
  48. */
  49. typedef double xmlrpc_double;
  50. /* A double precision floating point number as defined by
  51. XML-RPC <float>. But the C "double" type is universally the same,
  52. so it's probably clearer just to use that. This typedef is here
  53. for mathematical completeness.
  54. */
  55. #define XMLRPC_INT32_MAX (2147483647)
  56. #define XMLRPC_INT32_MIN (-XMLRPC_INT32_MAX - 1)
  57. /*=========================================================================
  58. ** C struct size computations
  59. **=======================================================================*/
  60. /* Use XMLRPC_STRUCT_MEMBER_SIZE() to determine how big a structure is
  61. up to and including a specified member. E.g. if you have
  62. struct mystruct {int red; int green; int blue};, then
  63. XMLRPC_STRUCT_MEMBER_SIZE(mystruct, green) is (8).
  64. */
  65. #define _XMLRPC_STRUCT_MEMBER_OFFSET(TYPE, MBRNAME) \
  66. ((unsigned int)(char*)&((TYPE *)0)->MBRNAME)
  67. #define _XMLRPC_STRUCT_MEMBER_SIZE(TYPE, MBRNAME) \
  68. sizeof(((TYPE *)0)->MBRNAME)
  69. #define XMLRPC_STRUCTSIZE(TYPE, MBRNAME) \
  70. (_XMLRPC_STRUCT_MEMBER_OFFSET(TYPE, MBRNAME) + \
  71. _XMLRPC_STRUCT_MEMBER_SIZE(TYPE, MBRNAME))
  72. /*=========================================================================
  73. ** Assertions and Debugging
  74. **=========================================================================
  75. ** We use xmlrpc_assert for internal sanity checks. For example:
  76. **
  77. ** xmlrpc_assert(ptr != NULL);
  78. **
  79. ** Assertions are only evaluated when debugging code is turned on. (To
  80. ** turn debugging off, define NDEBUG.) Some rules for using assertions:
  81. **
  82. ** 1) Assertions should never have side effects.
  83. ** 2) Assertions should never be used for run-time error checking.
  84. ** Instead, they should be used to check for "can't happen" errors.
  85. */
  86. #ifndef NDEBUG
  87. #define XMLRPC_ASSERT(cond) \
  88. do \
  89. if (!(cond)) \
  90. xmlrpc_assertion_failed(__FILE__, __LINE__); \
  91. while (0)
  92. #else
  93. #define XMLRPC_ASSERT(cond) (0)
  94. #endif
  95. extern void xmlrpc_assertion_failed (char* file, int line);
  96. /* Validate a pointer. */
  97. #define XMLRPC_ASSERT_PTR_OK(ptr) \
  98. XMLRPC_ASSERT((ptr) != NULL)
  99. /* We only call this if something truly drastic happens. */
  100. #define XMLRPC_FATAL_ERROR(msg) xmlrpc_fatal_error(__FILE__, __LINE__, (msg))
  101. extern void xmlrpc_fatal_error (char* file, int line, char* msg);
  102. /*=========================================================================
  103. ** Strings
  104. **=======================================================================*/
  105. /* Traditional C strings are char *, because they come from a time before
  106. there was 'const'. Now, const char * makes a lot more sense. Also,
  107. in modern times, we tend to dynamically allocate memory for strings.
  108. We need this free function accordingly. Ordinary free() doesn't check
  109. the type, and can generate a warning due to the 'const'.
  110. */
  111. void
  112. xmlrpc_strfree(const char * const string);
  113. /*=========================================================================
  114. ** xmlrpc_env
  115. **=========================================================================
  116. ** XML-RPC represents runtime errors as <fault> elements. These contain
  117. ** <faultCode> and <faultString> elements.
  118. **
  119. ** Since we need as much thread-safety as possible, we borrow an idea from
  120. ** CORBA--we store exception information in an "environment" object.
  121. ** You'll pass this to many different functions, and it will get filled
  122. ** out appropriately.
  123. **
  124. ** For example:
  125. **
  126. ** xmlrpc_env env;
  127. **
  128. ** xmlrpc_env_init(&env);
  129. **
  130. ** xmlrpc_do_something(&env);
  131. ** if (env.fault_occurred)
  132. ** report_error_appropriately();
  133. **
  134. ** xmlrpc_env_clean(&env);
  135. */
  136. #define XMLRPC_INTERNAL_ERROR (-500)
  137. #define XMLRPC_TYPE_ERROR (-501)
  138. #define XMLRPC_INDEX_ERROR (-502)
  139. #define XMLRPC_PARSE_ERROR (-503)
  140. #define XMLRPC_NETWORK_ERROR (-504)
  141. #define XMLRPC_TIMEOUT_ERROR (-505)
  142. #define XMLRPC_NO_SUCH_METHOD_ERROR (-506)
  143. #define XMLRPC_REQUEST_REFUSED_ERROR (-507)
  144. #define XMLRPC_INTROSPECTION_DISABLED_ERROR (-508)
  145. #define XMLRPC_LIMIT_EXCEEDED_ERROR (-509)
  146. #define XMLRPC_INVALID_UTF8_ERROR (-510)
  147. typedef struct _xmlrpc_env {
  148. int fault_occurred;
  149. xmlrpc_int32 fault_code;
  150. char* fault_string;
  151. } xmlrpc_env;
  152. /* Initialize and destroy the contents of the provided xmlrpc_env object.
  153. ** These functions will never fail. */
  154. void xmlrpc_env_init (xmlrpc_env* env);
  155. void xmlrpc_env_clean (xmlrpc_env* env);
  156. /* Fill out an xmlrpc_fault with the specified values, and set the
  157. ** fault_occurred flag. This function will make a private copy of 'string',
  158. ** so you retain responsibility for your copy. */
  159. void
  160. xmlrpc_env_set_fault(xmlrpc_env * const env,
  161. int const faultCode,
  162. const char * const faultDescription);
  163. /* The same as the above, but using a printf-style format string. */
  164. void
  165. xmlrpc_env_set_fault_formatted (xmlrpc_env * const envP,
  166. int const code,
  167. const char * const format,
  168. ...);
  169. /* A simple debugging assertion. */
  170. #define XMLRPC_ASSERT_ENV_OK(env) \
  171. XMLRPC_ASSERT((env) != NULL && !(env)->fault_occurred)
  172. /* This version must *not* interpret 'str' as a format string, to avoid
  173. ** several evil attacks. */
  174. #define XMLRPC_FAIL(env,code,str) \
  175. do { xmlrpc_env_set_fault((env),(code),(str)); goto cleanup; } while (0)
  176. #define XMLRPC_FAIL1(env,code,str,arg1) \
  177. do { \
  178. xmlrpc_env_set_fault_formatted((env),(code),(str),(arg1)); \
  179. goto cleanup; \
  180. } while (0)
  181. #define XMLRPC_FAIL2(env,code,str,arg1,arg2) \
  182. do { \
  183. xmlrpc_env_set_fault_formatted((env),(code),(str),(arg1),(arg2)); \
  184. goto cleanup; \
  185. } while (0)
  186. #define XMLRPC_FAIL3(env,code,str,arg1,arg2,arg3) \
  187. do { \
  188. xmlrpc_env_set_fault_formatted((env),(code), \
  189. (str),(arg1),(arg2),(arg3)); \
  190. goto cleanup; \
  191. } while (0)
  192. #define XMLRPC_FAIL_IF_NULL(ptr,env,code,str) \
  193. do { \
  194. if ((ptr) == NULL) \
  195. XMLRPC_FAIL((env),(code),(str)); \
  196. } while (0)
  197. #define XMLRPC_FAIL_IF_FAULT(env) \
  198. do { if ((env)->fault_occurred) goto cleanup; } while (0)
  199. /*=========================================================================
  200. ** Resource Limits
  201. **=========================================================================
  202. ** To discourage denial-of-service attacks, we provide several adjustable
  203. ** resource limits. These functions are *not* re-entrant.
  204. */
  205. /* Limit IDs. There will be more of these as time goes on. */
  206. #define XMLRPC_NESTING_LIMIT_ID (0)
  207. #define XMLRPC_XML_SIZE_LIMIT_ID (1)
  208. #define XMLRPC_LAST_LIMIT_ID (XMLRPC_XML_SIZE_LIMIT_ID)
  209. /* By default, deserialized data may be no more than 64 levels deep. */
  210. #define XMLRPC_NESTING_LIMIT_DEFAULT (64)
  211. /* By default, XML data from the network may be no larger than 512K.
  212. ** Some client and server modules may fail to enforce this properly. */
  213. #define XMLRPC_XML_SIZE_LIMIT_DEFAULT (512*1024)
  214. /* Set a specific limit to the specified value. */
  215. extern void xmlrpc_limit_set (int limit_id, size_t value);
  216. /* Get the value of a specified limit. */
  217. extern size_t xmlrpc_limit_get (int limit_id);
  218. /*=========================================================================
  219. ** xmlrpc_mem_block
  220. **=========================================================================
  221. ** A resizable chunk of memory. This is mostly used internally, but it is
  222. ** also used by the public API in a few places.
  223. ** The struct fields are private!
  224. */
  225. typedef struct _xmlrpc_mem_block {
  226. size_t _size;
  227. size_t _allocated;
  228. void* _block;
  229. } xmlrpc_mem_block;
  230. /* Allocate a new xmlrpc_mem_block. */
  231. xmlrpc_mem_block* xmlrpc_mem_block_new (xmlrpc_env* const env, size_t const size);
  232. /* Destroy an existing xmlrpc_mem_block, and everything it contains. */
  233. void xmlrpc_mem_block_free (xmlrpc_mem_block* block);
  234. /* Initialize the contents of the provided xmlrpc_mem_block. */
  235. void xmlrpc_mem_block_init
  236. (xmlrpc_env* env, xmlrpc_mem_block* block, size_t size);
  237. /* Deallocate the contents of the provided xmlrpc_mem_block, but not the
  238. ** block itself. */
  239. void xmlrpc_mem_block_clean (xmlrpc_mem_block* block);
  240. /* Get the size and contents of the xmlrpc_mem_block. */
  241. size_t
  242. xmlrpc_mem_block_size(const xmlrpc_mem_block * const block);
  243. void *
  244. xmlrpc_mem_block_contents(const xmlrpc_mem_block * const block);
  245. /* Resize an xmlrpc_mem_block, preserving as much of the contents as
  246. ** possible. */
  247. void xmlrpc_mem_block_resize
  248. (xmlrpc_env* const env, xmlrpc_mem_block* const block, size_t const size);
  249. /* Append data to an existing xmlrpc_mem_block. */
  250. void xmlrpc_mem_block_append
  251. (xmlrpc_env* const env, xmlrpc_mem_block* const block, void *const data, size_t const len);
  252. #define XMLRPC_MEMBLOCK_NEW(type,env,size) \
  253. xmlrpc_mem_block_new((env), sizeof(type) * (size))
  254. #define XMLRPC_MEMBLOCK_FREE(type,block) \
  255. xmlrpc_mem_block_free(block)
  256. #define XMLRPC_MEMBLOCK_INIT(type,env,block,size) \
  257. xmlrpc_mem_block_init((env), (block), sizeof(type) * (size))
  258. #define XMLRPC_MEMBLOCK_CLEAN(type,block) \
  259. xmlrpc_mem_block_clean(block)
  260. #define XMLRPC_MEMBLOCK_SIZE(type,block) \
  261. (xmlrpc_mem_block_size(block) / sizeof(type))
  262. #define XMLRPC_MEMBLOCK_CONTENTS(type,block) \
  263. ((type*) xmlrpc_mem_block_contents(block))
  264. #define XMLRPC_MEMBLOCK_RESIZE(type,env,block,size) \
  265. xmlrpc_mem_block_resize(env, block, sizeof(type) * (size))
  266. #define XMLRPC_MEMBLOCK_APPEND(type,env,block,data,size) \
  267. xmlrpc_mem_block_append(env, block, data, sizeof(type) * (size))
  268. /* Here are some backward compatibility definitions. These longer names
  269. used to be the only ones and typed memory blocks were considered
  270. special.
  271. */
  272. #define XMLRPC_TYPED_MEM_BLOCK_NEW(type,env,size) \
  273. XMLRPC_MEMBLOCK_NEW(type,env,size)
  274. #define XMLRPC_TYPED_MEM_BLOCK_FREE(type,block) \
  275. XMLRPC_MEMBLOCK_FREE(type,block)
  276. #define XMLRPC_TYPED_MEM_BLOCK_INIT(type,env,block,size) \
  277. XMLRPC_MEMBLOCK_INIT(type,env,block,size)
  278. #define XMLRPC_TYPED_MEM_BLOCK_CLEAN(type,block) \
  279. XMLRPC_MEMBLOCK_CLEAN(type,block)
  280. #define XMLRPC_TYPED_MEM_BLOCK_SIZE(type,block) \
  281. XMLRPC_MEMBLOCK_SIZE(type,block)
  282. #define XMLRPC_TYPED_MEM_BLOCK_CONTENTS(type,block) \
  283. XMLRPC_MEMBLOCK_CONTENTS(type,block)
  284. #define XMLRPC_TYPED_MEM_BLOCK_RESIZE(type,env,block,size) \
  285. XMLRPC_MEMBLOCK_RESIZE(type,env,block,size)
  286. #define XMLRPC_TYPED_MEM_BLOCK_APPEND(type,env,block,data,size) \
  287. XMLRPC_MEMBLOCK_APPEND(type,env,block,data,size)
  288. /*=========================================================================
  289. ** xmlrpc_value
  290. **=========================================================================
  291. ** An XML-RPC value (of any type).
  292. */
  293. typedef enum {
  294. XMLRPC_TYPE_INT = 0,
  295. XMLRPC_TYPE_BOOL = 1,
  296. XMLRPC_TYPE_DOUBLE = 2,
  297. XMLRPC_TYPE_DATETIME = 3,
  298. XMLRPC_TYPE_STRING = 4,
  299. XMLRPC_TYPE_BASE64 = 5,
  300. XMLRPC_TYPE_ARRAY = 6,
  301. XMLRPC_TYPE_STRUCT = 7,
  302. XMLRPC_TYPE_C_PTR = 8,
  303. XMLRPC_TYPE_DEAD = 0xDEAD,
  304. } xmlrpc_type;
  305. /* These are *always* allocated on the heap. No exceptions. */
  306. typedef struct _xmlrpc_value xmlrpc_value;
  307. #define XMLRPC_ASSERT_VALUE_OK(val) \
  308. XMLRPC_ASSERT((val) != NULL && (val)->_type != XMLRPC_TYPE_DEAD)
  309. /* A handy type-checking routine. */
  310. #define XMLRPC_TYPE_CHECK(env,v,t) \
  311. do \
  312. if ((v)->_type != (t)) \
  313. XMLRPC_FAIL(env, XMLRPC_TYPE_ERROR, "Expected " #t); \
  314. while (0)
  315. void
  316. xmlrpc_abort_if_array_bad(xmlrpc_value * const arrayP);
  317. #define XMLRPC_ASSERT_ARRAY_OK(val) \
  318. xmlrpc_abort_if_array_bad(val)
  319. /* Increment the reference count of an xmlrpc_value. */
  320. extern void xmlrpc_INCREF (xmlrpc_value* const value);
  321. /* Decrement the reference count of an xmlrpc_value. If there
  322. ** are no more references, free it. */
  323. extern void xmlrpc_DECREF (xmlrpc_value* const value);
  324. /* Get the type of an XML-RPC value. */
  325. extern xmlrpc_type xmlrpc_value_type (xmlrpc_value* value);
  326. /* Build an xmlrpc_value from a format string.
  327. ** Increments the reference counts of input arguments if necessary.
  328. ** See the xmlrpc-c documentation for more information. */
  329. xmlrpc_value *
  330. xmlrpc_build_value(xmlrpc_env * const env,
  331. const char * const format,
  332. ...);
  333. /* The same as the above, but using a va_list and more general */
  334. void
  335. xmlrpc_build_value_va(xmlrpc_env * const env,
  336. const char * const format,
  337. va_list args,
  338. xmlrpc_value ** const valPP,
  339. const char ** const tailP);
  340. /* Extract values from an xmlrpc_value and store them into C variables.
  341. ** Does not increment the reference counts of output values.
  342. ** See the xmlrpc-c documentation for more information. */
  343. void
  344. xmlrpc_parse_value(xmlrpc_env * const envP,
  345. xmlrpc_value * const value,
  346. const char * const format,
  347. ...);
  348. /* The same as the above, but using a va_list. */
  349. void
  350. xmlrpc_parse_value_va(xmlrpc_env * const envP,
  351. xmlrpc_value * const value,
  352. const char * const format,
  353. va_list args);
  354. void
  355. xmlrpc_read_int(xmlrpc_env * const envP,
  356. const xmlrpc_value * const valueP,
  357. int * const intValueP);
  358. void
  359. xmlrpc_read_double(xmlrpc_env * const envP,
  360. const xmlrpc_value * const valueP,
  361. xmlrpc_double * const doubleValueP);
  362. void
  363. xmlrpc_read_bool(xmlrpc_env * const envP,
  364. const xmlrpc_value * const valueP,
  365. xmlrpc_bool * const boolValueP);
  366. void
  367. xmlrpc_read_string(xmlrpc_env * const envP,
  368. const xmlrpc_value * const valueP,
  369. const char ** const stringValueP);
  370. void
  371. xmlrpc_read_string_lp(xmlrpc_env * const envP,
  372. const xmlrpc_value * const valueP,
  373. unsigned int * const lengthP,
  374. const char ** const stringValueP);
  375. /* Return the number of elements in an XML-RPC array.
  376. ** Sets XMLRPC_TYPE_ERROR if 'array' is not an array. */
  377. int
  378. xmlrpc_array_size(xmlrpc_env * const env,
  379. const xmlrpc_value * const array);
  380. /* Append an item to an XML-RPC array.
  381. ** Increments the reference count of 'value' if no fault occurs.
  382. ** Sets XMLRPC_TYPE_ERROR if 'array' is not an array. */
  383. extern void
  384. xmlrpc_array_append_item (xmlrpc_env* const env,
  385. xmlrpc_value* const array,
  386. xmlrpc_value* const value);
  387. void
  388. xmlrpc_array_read_item(xmlrpc_env * const envP,
  389. const xmlrpc_value * const arrayP,
  390. unsigned int const index,
  391. xmlrpc_value ** const valuePP);
  392. /* Get an item from an XML-RPC array.
  393. ** Does not increment the reference count of the returned value.
  394. ** Sets XMLRPC_TYPE_ERROR if 'array' is not an array.
  395. ** Sets XMLRPC_INDEX_ERROR if 'index' is out of bounds. */
  396. xmlrpc_value *
  397. xmlrpc_array_get_item(xmlrpc_env * const env,
  398. const xmlrpc_value * const array,
  399. int const index);
  400. /* Not implemented--we don't need it yet.
  401. extern
  402. int xmlrpc_array_set_item (xmlrpc_env* env,
  403. xmlrpc_value* array,
  404. int index,
  405. xmlrpc_value* value);
  406. */
  407. /* Create a new struct. Deprecated. xmlrpc_build_value() is the
  408. general way to create an xmlrpc_value, including an empty struct.
  409. */
  410. xmlrpc_value *
  411. xmlrpc_struct_new(xmlrpc_env * env);
  412. /* Return the number of key/value pairs in a struct.
  413. ** Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct. */
  414. int
  415. xmlrpc_struct_size (xmlrpc_env * env,
  416. xmlrpc_value * strct);
  417. /* Returns true iff 'strct' contains 'key'.
  418. ** Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct. */
  419. int
  420. xmlrpc_struct_has_key(xmlrpc_env * const envP,
  421. xmlrpc_value * const strctP,
  422. const char * const key);
  423. /* The same as the above, but the key may contain zero bytes.
  424. Deprecated. xmlrpc_struct_get_value_v() is more general, and this
  425. case is not common enough to warrant a shortcut.
  426. */
  427. int
  428. xmlrpc_struct_has_key_n(xmlrpc_env * const envP,
  429. xmlrpc_value * const strctP,
  430. const char * const key,
  431. size_t const key_len);
  432. #if 0
  433. /* Not implemented yet, but needed for completeness. */
  434. int
  435. xmlrpc_struct_has_key_v(xmlrpc_env * env,
  436. xmlrpc_value * strct,
  437. xmlrpc_value * const keyval);
  438. #endif
  439. void
  440. xmlrpc_struct_find_value(xmlrpc_env * const envP,
  441. xmlrpc_value * const structP,
  442. const char * const key,
  443. xmlrpc_value ** const valuePP);
  444. void
  445. xmlrpc_struct_find_value_v(xmlrpc_env * const envP,
  446. xmlrpc_value * const structP,
  447. xmlrpc_value * const keyP,
  448. xmlrpc_value ** const valuePP);
  449. void
  450. xmlrpc_struct_read_value_v(xmlrpc_env * const envP,
  451. xmlrpc_value * const structP,
  452. xmlrpc_value * const keyP,
  453. xmlrpc_value ** const valuePP);
  454. void
  455. xmlrpc_struct_read_value(xmlrpc_env * const envP,
  456. xmlrpc_value * const strctP,
  457. const char * const key,
  458. xmlrpc_value ** const valuePP);
  459. /* The "get_value" functions are deprecated. Use the "find_value"
  460. and "read_value" functions instead.
  461. */
  462. xmlrpc_value *
  463. xmlrpc_struct_get_value(xmlrpc_env * const envP,
  464. xmlrpc_value * const strctP,
  465. const char * const key);
  466. /* The same as above, but the key may contain zero bytes.
  467. Deprecated. xmlrpc_struct_get_value_v() is more general, and this
  468. case is not common enough to warrant a shortcut.
  469. */
  470. xmlrpc_value *
  471. xmlrpc_struct_get_value_n(xmlrpc_env * const envP,
  472. xmlrpc_value * const strctP,
  473. const char * const key,
  474. size_t const key_len);
  475. /* Set the value associated with 'key' in 'strct' to 'value'.
  476. ** Increments the reference count of value.
  477. ** Sets XMLRPC_TYPE_ERROR if 'strct' is not a struct. */
  478. void
  479. xmlrpc_struct_set_value(xmlrpc_env * const env,
  480. xmlrpc_value * const strct,
  481. const char * const key,
  482. xmlrpc_value * const value);
  483. /* The same as above, but the key may contain zero bytes. Deprecated.
  484. The general way to set a structure value is xmlrpc_struct_set_value_v(),
  485. and this case is not common enough to deserve a shortcut.
  486. */
  487. void
  488. xmlrpc_struct_set_value_n(xmlrpc_env * const env,
  489. xmlrpc_value * const strct,
  490. const char * const key,
  491. size_t const key_len,
  492. xmlrpc_value * const value);
  493. /* The same as above, but the key must be an XML-RPC string.
  494. ** Fails with XMLRPC_TYPE_ERROR if 'keyval' is not a string. */
  495. void
  496. xmlrpc_struct_set_value_v(xmlrpc_env * const env,
  497. xmlrpc_value * const strct,
  498. xmlrpc_value * const keyval,
  499. xmlrpc_value * const value);
  500. /* Given a zero-based index, return the matching key and value. This
  501. ** is normally used in conjunction with xmlrpc_struct_size.
  502. ** Fails with XMLRPC_TYPE_ERROR if 'struct' is not a struct.
  503. ** Fails with XMLRPC_INDEX_ERROR if 'index' is out of bounds. */
  504. void
  505. xmlrpc_struct_read_member(xmlrpc_env * const envP,
  506. xmlrpc_value * const structP,
  507. unsigned int const index,
  508. xmlrpc_value ** const keyvalP,
  509. xmlrpc_value ** const valueP);
  510. /* The same as above, but does not increment the reference count of the
  511. two values it returns, and return NULL for both if it fails, and
  512. takes a signed integer for the index (but fails if it is negative).
  513. Deprecated.
  514. */
  515. void
  516. xmlrpc_struct_get_key_and_value(xmlrpc_env * const env,
  517. xmlrpc_value * const strct,
  518. int const index,
  519. xmlrpc_value ** const out_keyval,
  520. xmlrpc_value ** const out_value);
  521. /*=========================================================================
  522. ** Encoding XML
  523. **=======================================================================*/
  524. /* Serialize an XML value without any XML header. This is primarily used
  525. ** for testing purposes. */
  526. void
  527. xmlrpc_serialize_value(xmlrpc_env * env,
  528. xmlrpc_mem_block * output,
  529. xmlrpc_value * value);
  530. /* Serialize a list of parameters without any XML header. This is
  531. ** primarily used for testing purposes. */
  532. void
  533. xmlrpc_serialize_params(xmlrpc_env * env,
  534. xmlrpc_mem_block * output,
  535. xmlrpc_value * param_array);
  536. /* Serialize an XML-RPC call. */
  537. void
  538. xmlrpc_serialize_call (xmlrpc_env * const env,
  539. xmlrpc_mem_block * const output,
  540. const char * const method_name,
  541. xmlrpc_value * const param_array);
  542. /* Serialize an XML-RPC return value. */
  543. extern void
  544. xmlrpc_serialize_response(xmlrpc_env * env,
  545. xmlrpc_mem_block * output,
  546. xmlrpc_value * value);
  547. /* Serialize an XML-RPC fault (as specified by 'fault'). */
  548. extern void
  549. xmlrpc_serialize_fault(xmlrpc_env * env,
  550. xmlrpc_mem_block * output,
  551. xmlrpc_env * fault);
  552. /*=========================================================================
  553. ** Decoding XML
  554. **=======================================================================*/
  555. /* Parse an XML-RPC call. If an error occurs, set a fault and set
  556. ** the output variables to NULL.
  557. ** The caller is responsible for calling free(*out_method_name) and
  558. ** xmlrpc_DECREF(*out_param_array). */
  559. void
  560. xmlrpc_parse_call(xmlrpc_env * const envP,
  561. const char * const xml_data,
  562. size_t const xml_len,
  563. const char ** const out_method_name,
  564. xmlrpc_value ** const out_param_array);
  565. /* Parse an XML-RPC response. If a fault occurs (or was received over the
  566. ** wire), return NULL and set up 'env'. The calling is responsible for
  567. ** calling xmlrpc_DECREF on the return value (if it isn't NULL). */
  568. xmlrpc_value *
  569. xmlrpc_parse_response(xmlrpc_env * env,
  570. const char * xml_data,
  571. size_t xml_len);
  572. /*=========================================================================
  573. ** XML-RPC Base64 Utilities
  574. **=========================================================================
  575. ** Here are some lightweight utilities which can be used to encode and
  576. ** decode Base64 data. These are exported mainly for testing purposes.
  577. */
  578. /* This routine inserts newlines every 76 characters, as required by the
  579. ** Base64 specification. */
  580. xmlrpc_mem_block *
  581. xmlrpc_base64_encode(xmlrpc_env * env,
  582. unsigned char * bin_data,
  583. size_t bin_len);
  584. /* This routine encodes everything in one line. This is needed for HTTP
  585. ** authentication and similar tasks. */
  586. xmlrpc_mem_block *
  587. xmlrpc_base64_encode_without_newlines(xmlrpc_env * env,
  588. unsigned char * bin_data,
  589. size_t bin_len);
  590. /* This decodes Base64 data with or without newlines. */
  591. extern xmlrpc_mem_block *
  592. xmlrpc_base64_decode(xmlrpc_env * env,
  593. char * ascii_data,
  594. size_t ascii_len);
  595. /*=========================================================================
  596. ** UTF-8 Encoding and Decoding
  597. **=========================================================================
  598. ** We need a correct, reliable and secure UTF-8 decoder. This decoder
  599. ** raises a fault if it encounters invalid UTF-8.
  600. **
  601. ** Note that ANSI C does not precisely define the representation used
  602. ** by wchar_t--it may be UCS-2, UTF-16, UCS-4, or something from outer
  603. ** space. If your platform does something especially bizarre, you may
  604. ** need to reimplement these routines.
  605. */
  606. #ifdef HAVE_UNICODE_WCHAR
  607. /* Ensure that a string contains valid, legally-encoded UTF-8 data.
  608. ** (Incorrectly-encoded UTF-8 strings are often used to bypass security
  609. ** checks.) */
  610. void
  611. xmlrpc_validate_utf8 (xmlrpc_env * const env,
  612. const char * const utf8_data,
  613. size_t const utf8_len);
  614. /* Decode a UTF-8 string. */
  615. xmlrpc_mem_block *
  616. xmlrpc_utf8_to_wcs(xmlrpc_env * env,
  617. char * utf8_data,
  618. size_t utf8_len);
  619. /* Encode a UTF-8 string. */
  620. xmlrpc_mem_block *
  621. xmlrpc_wcs_to_utf8(xmlrpc_env * env,
  622. wchar_t * wcs_data,
  623. size_t wcs_len);
  624. #endif /* HAVE_UNICODE_WCHAR */
  625. /*=========================================================================
  626. ** Authorization Cookie Handling
  627. **=========================================================================
  628. ** Routines to get and set values for authorizing via authorization
  629. ** cookies. Both the client and server use HTTP_COOKIE_AUTH to store
  630. ** the representation of the authorization value, which is actually
  631. ** just a base64 hash of username:password. (This entire method is
  632. ** a cookie replacement of basic authentication.)
  633. **/
  634. extern void xmlrpc_authcookie_set(xmlrpc_env * env,
  635. const char * username,
  636. const char * password);
  637. char *xmlrpc_authcookie(void);
  638. #ifdef __cplusplus
  639. }
  640. #endif
  641. /* In the days before xmlrpc_server.h existed, some of what's in it was
  642. in here. For backward compatibility, we need to include it here, even
  643. though it really isn't logical to do so.
  644. */
  645. #include <xmlrpc_server.h>
  646. #endif