xmlrpc_client.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*============================================================================
  2. xmlrpc_client.h
  3. ==============================================================================
  4. This header file defines the interface between xmlrpc.c and its users,
  5. related to clients.
  6. Copyright information is at the end of the file.
  7. ============================================================================*/
  8. #ifndef _XMLRPC_CLIENT_H_
  9. #define _XMLRPC_CLIENT_H_ 1
  10. #ifdef __cplusplus
  11. extern "C" {
  12. #endif /* __cplusplus */
  13. /*=========================================================================
  14. ** Initialization and Shutdown
  15. **=========================================================================
  16. ** These routines initialize and terminate the XML-RPC client. If you're
  17. ** already using libwww on your own, you can pass
  18. ** XMLRPC_CLIENT_SKIP_LIBWWW_INIT to avoid initializing it twice.
  19. */
  20. #define XMLRPC_CLIENT_NO_FLAGS (0)
  21. #define XMLRPC_CLIENT_SKIP_LIBWWW_INIT (1)
  22. extern void
  23. xmlrpc_client_init(int const flags,
  24. const char * const appname,
  25. const char * const appversion);
  26. struct xmlrpc_clientparms {
  27. const char * transport;
  28. };
  29. #define XMLRPC_CP_MEMBER_OFFSET(mbrname) \
  30. ((unsigned int)(char*)&((struct xmlrpc_clientparms *)0)->mbrname)
  31. #define XMLRPC_CP_MEMBER_SIZE(mbrname) \
  32. sizeof(((struct xmlrpc_clientparms *)0)->mbrname)
  33. #define XMLRPC_CPSIZE(mbrname) \
  34. (XMLRPC_CP_MEMBER_OFFSET(mbrname) + XMLRPC_CP_MEMBER_SIZE(mbrname))
  35. /* XMLRPC_CPSIZE(xyz) is the minimum size a struct xmlrpc_clientparms
  36. must be to include the 'xyz' member. This is essential to forward and
  37. backward compatbility, as new members will be added to the end of the
  38. struct in future releases. This is how the callee knows whether or
  39. not the caller is new enough to have supplied a certain parameter.
  40. */
  41. void
  42. xmlrpc_client_init2(xmlrpc_env * const env,
  43. int const flags,
  44. const char * const appname,
  45. const char * const appversion,
  46. struct xmlrpc_clientparms * const clientparms,
  47. unsigned int const parm_size);
  48. extern void
  49. xmlrpc_client_cleanup(void);
  50. const char *
  51. xmlrpc_client_get_default_transport(xmlrpc_env * const env);
  52. /*=========================================================================
  53. ** Required for both internal and external development.
  54. **=========================================================================
  55. */
  56. /* A callback function to handle the response to an asynchronous call.
  57. ** If 'fault->fault_occurred' is true, then response will be NULL. All
  58. ** arguments except 'user_data' will be deallocated internally; please do
  59. ** not free any of them yourself.
  60. ** WARNING: param_array may (or may not) be NULL if fault->fault_occurred
  61. ** is true, and you set up the call using xmlrpc_client_call_asynch.
  62. ** WARNING: If asynchronous calls are still pending when the library is
  63. ** shut down, your handler may (or may not) be called with a fault. */
  64. typedef void (*xmlrpc_response_handler) (const char *server_url,
  65. const char *method_name,
  66. xmlrpc_value *param_array,
  67. void *user_data,
  68. xmlrpc_env *fault,
  69. xmlrpc_value *result);
  70. /*=========================================================================
  71. ** xmlrpc_server_info
  72. **=========================================================================
  73. ** We normally refer to servers by URL. But sometimes we need to do extra
  74. ** setup for particular servers. In that case, we can create an
  75. ** xmlrpc_server_info object, configure it in various ways, and call the
  76. ** remote server.
  77. **
  78. ** (This interface is also designed to discourage further multiplication
  79. ** of xmlrpc_client_call APIs. We have enough of those already. Please
  80. ** add future options and flags using xmlrpc_server_info.)
  81. */
  82. typedef struct _xmlrpc_server_info xmlrpc_server_info;
  83. /* Create a new server info record, pointing to the specified server. */
  84. xmlrpc_server_info *
  85. xmlrpc_server_info_new(xmlrpc_env * const env,
  86. const char * const server_url);
  87. /* Create a new server info record, with a copy of the old server. */
  88. extern xmlrpc_server_info *
  89. xmlrpc_server_info_copy(xmlrpc_env *env, xmlrpc_server_info *src_server);
  90. /* Delete a server info record. */
  91. extern void
  92. xmlrpc_server_info_free (xmlrpc_server_info *server);
  93. /* We support rudimentary basic authentication. This lets us talk to Zope
  94. ** servers and similar critters. When called, this routine makes a copy
  95. ** of all the authentication information and passes it to future requests.
  96. ** Only the most-recently-set authentication information is used.
  97. ** (In general, you shouldn't write XML-RPC servers which require this
  98. ** kind of authentication--it confuses many client implementations.)
  99. ** If we fail, leave the xmlrpc_server_info record unchanged. */
  100. void
  101. xmlrpc_server_info_set_basic_auth(xmlrpc_env * const envP,
  102. xmlrpc_server_info * const serverP,
  103. const char * const username,
  104. const char * const password);
  105. /*=========================================================================
  106. ** xmlrpc_client_call
  107. **=========================================================================
  108. ** A synchronous XML-RPC client. Do not attempt to call any of these
  109. ** functions from inside an asynchronous callback!
  110. */
  111. xmlrpc_value *
  112. xmlrpc_client_call(xmlrpc_env * const envP,
  113. const char * const server_url,
  114. const char * const method_name,
  115. const char * const format,
  116. ...);
  117. xmlrpc_value *
  118. xmlrpc_client_call_params (xmlrpc_env * const env,
  119. const char * const server_url,
  120. const char * const method_name,
  121. xmlrpc_value * const param_array);
  122. xmlrpc_value *
  123. xmlrpc_client_call_server(xmlrpc_env * const envP,
  124. xmlrpc_server_info * const server,
  125. const char * const method_name,
  126. const char * const format,
  127. ...);
  128. extern xmlrpc_value *
  129. xmlrpc_client_call_server_params (xmlrpc_env *env,
  130. xmlrpc_server_info *server,
  131. char *method_name,
  132. xmlrpc_value *param_array);
  133. /*=========================================================================
  134. ** xmlrpc_client_call_asynch
  135. **=========================================================================
  136. ** An asynchronous XML-RPC client.
  137. */
  138. /* Make an asynchronous XML-RPC call. We make internal copies of all
  139. ** arguments except user_data, so you can deallocate them safely as soon
  140. ** as you return. Errors will be passed to the callback. You will need
  141. ** to run the event loop somehow; see below.
  142. ** WARNING: If an error occurs while building the argument, the
  143. ** response handler will be called with a NULL param_array. */
  144. void
  145. xmlrpc_client_call_asynch(const char * const server_url,
  146. const char * const method_name,
  147. xmlrpc_response_handler callback,
  148. void * const user_data,
  149. const char * const format,
  150. ...);
  151. /* As above, but use an xmlrpc_server_info object. The server object can be
  152. ** safely destroyed as soon as this function returns. */
  153. void
  154. xmlrpc_client_call_server_asynch(xmlrpc_server_info * const server,
  155. const char * const method_name,
  156. xmlrpc_response_handler callback,
  157. void * const user_data,
  158. const char * const format,
  159. ...);
  160. /* As above, but the parameter list is supplied as an xmlrpc_value
  161. ** containing an array.
  162. */
  163. void
  164. xmlrpc_client_call_asynch_params(const char * const server_url,
  165. const char * const method_name,
  166. xmlrpc_response_handler callback,
  167. void * const user_data,
  168. xmlrpc_value * const paramArrayP);
  169. /* As above, but use an xmlrpc_server_info object. The server object can be
  170. ** safely destroyed as soon as this function returns. */
  171. void
  172. xmlrpc_client_call_server_asynch_params(
  173. xmlrpc_server_info * const server,
  174. const char * const method_name,
  175. xmlrpc_response_handler callback,
  176. void * const user_data,
  177. xmlrpc_value * const paramArrayP);
  178. /*=========================================================================
  179. ** Event Loop Interface
  180. **=========================================================================
  181. ** These functions can be used to run the XML-RPC event loop. If you
  182. ** don't like these, you can also run the libwww event loop directly.
  183. */
  184. /* Finish all outstanding asynchronous calls. Alternatively, the loop
  185. ** will exit if someone calls xmlrpc_client_event_loop_end. */
  186. extern void
  187. xmlrpc_client_event_loop_finish_asynch(void);
  188. /* Finish all outstanding asynchronous calls. */
  189. extern void
  190. xmlrpc_client_event_loop_finish_asynch_timeout(timeout_t const milliseconds);
  191. /* Copyright (C) 2001 by First Peer, Inc. All rights reserved.
  192. **
  193. ** Redistribution and use in source and binary forms, with or without
  194. ** modification, are permitted provided that the following conditions
  195. ** are met:
  196. ** 1. Redistributions of source code must retain the above copyright
  197. ** notice, this list of conditions and the following disclaimer.
  198. ** 2. Redistributions in binary form must reproduce the above copyright
  199. ** notice, this list of conditions and the following disclaimer in the
  200. ** documentation and/or other materials provided with the distribution.
  201. ** 3. The name of the author may not be used to endorse or promote products
  202. ** derived from this software without specific prior written permission.
  203. **
  204. ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  205. ** ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  206. ** IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  207. ** ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  208. ** FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  209. ** DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  210. ** OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  211. ** HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  212. ** LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  213. ** OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  214. ** SUCH DAMAGE. */
  215. #ifdef __cplusplus
  216. }
  217. #endif /* __cplusplus */
  218. #endif /* _XMLRPC_CLIENT_H_ */