xmlrpc_server.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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_SERVER_H_
  26. #define _XMLRPC_SERVER_H_ 1
  27. #include <xmlrpc.h>
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. /*=========================================================================
  32. ** XML-RPC Server Method Registry
  33. **=========================================================================
  34. ** A method registry maintains a list of functions, and handles
  35. ** dispatching. To build an XML-RPC server, just add an XML-RPC protocol
  36. ** driver.
  37. **
  38. ** Methods are C functions which take some combination of the following
  39. ** parameters. All pointers except user_data belong to the library, and
  40. ** must not be freed by the callback or used after the callback returns.
  41. **
  42. ** env: An XML-RPC error-handling environment. No faults will be
  43. ** set when the function is called. If an error occurs,
  44. ** set an appropriate fault and return NULL. (If a fault is
  45. ** set, the NULL return value will be enforced!)
  46. ** host: The 'Host:' header passed by the XML-RPC client, or NULL,
  47. ** if no 'Host:' header has been provided.
  48. ** method_name: The name used to call this method.
  49. ** user_data: The user_data used to register this method.
  50. ** param_array: The parameters passed to this function, stored in an
  51. ** XML-RPC array. You are *not* responsible for calling
  52. ** xmlrpc_DECREF on this array.
  53. **
  54. ** Return value: If no fault has been set, the function must return a
  55. ** valid xmlrpc_value. This will be serialized, returned
  56. ** to the caller, and xmlrpc_DECREF'd.
  57. */
  58. /* A function to call before invoking a method for doing things like access
  59. ** control or sanity checks. If a fault is set from this function, the
  60. ** method will not be called and the fault will be returned. */
  61. typedef void
  62. (*xmlrpc_preinvoke_method)(xmlrpc_env * env,
  63. const char * method_name,
  64. xmlrpc_value * param_array,
  65. void * user_data);
  66. /* An ordinary method. */
  67. typedef xmlrpc_value *
  68. (*xmlrpc_method)(xmlrpc_env * env,
  69. xmlrpc_value * param_array,
  70. void * user_data);
  71. /* A default method to call if no method can be found. */
  72. typedef xmlrpc_value *
  73. (*xmlrpc_default_method)(xmlrpc_env * env,
  74. const char * host,
  75. const char * method_name,
  76. xmlrpc_value * param_array,
  77. void * user_data);
  78. /* Our registry structure. This has no public members. */
  79. typedef struct _xmlrpc_registry xmlrpc_registry;
  80. /* Create a new method registry. */
  81. xmlrpc_registry *
  82. xmlrpc_registry_new(xmlrpc_env * env);
  83. /* Delete a method registry. */
  84. void
  85. xmlrpc_registry_free(xmlrpc_registry * registry);
  86. /* Disable introspection. The xmlrpc_registry has introspection
  87. ** capability built-in. If you want to make nosy people work harder,
  88. ** you can turn this off. */
  89. void
  90. xmlrpc_registry_disable_introspection(xmlrpc_registry * registry);
  91. /* Register a method. The host parameter must be NULL (for now). You
  92. ** are responsible for owning and managing user_data. The registry
  93. ** will make internal copies of any other pointers it needs to
  94. ** keep around. */
  95. void
  96. xmlrpc_registry_add_method(xmlrpc_env * env,
  97. xmlrpc_registry * registry,
  98. const char * host,
  99. const char * method_name,
  100. xmlrpc_method method,
  101. void * user_data);
  102. /* As above, but allow the user to supply introspection information.
  103. **
  104. ** Signatures use their own little description language. It consists
  105. ** of one-letter type code (similar to the ones used in xmlrpc_parse_value)
  106. ** for the result, a colon, and zero or more one-letter type codes for
  107. ** the parameters. For example:
  108. ** i:ibdsAS86
  109. ** If a function has more than one possible prototype, separate them with
  110. ** commas:
  111. ** i:,i:s,i:ii
  112. ** If the function signature can't be represented using this language,
  113. ** pass a single question mark:
  114. ** ?
  115. ** Help strings are ASCII text, and may contain HTML markup. */
  116. void
  117. xmlrpc_registry_add_method_w_doc(xmlrpc_env * env,
  118. xmlrpc_registry * registry,
  119. const char * host,
  120. const char * method_name,
  121. xmlrpc_method method,
  122. void * user_data,
  123. const char * signature,
  124. const char * help);
  125. /* Given a registry, a host name, and XML data; parse the <methodCall>,
  126. ** find the appropriate method, call it, serialize the response, and
  127. ** return it as an xmlrpc_mem_block. Most errors will be serialized
  128. ** as <fault> responses. If a *really* bad error occurs, set a fault and
  129. ** return NULL. (Actually, we currently give up with a fatal error,
  130. ** but that should change eventually.)
  131. ** The caller is responsible for destroying the memory block. */
  132. xmlrpc_mem_block *
  133. xmlrpc_registry_process_call(xmlrpc_env * const envP,
  134. xmlrpc_registry * const registryP,
  135. const char * const host,
  136. const char * const xml_data,
  137. size_t const xml_len);
  138. /* Define a default method for the specified registry. This will be invoked
  139. ** if no other method matches. The user_data pointer is property of the
  140. ** application, and will not be freed or manipulated by the registry. */
  141. void
  142. xmlrpc_registry_set_default_method(xmlrpc_env * env,
  143. xmlrpc_registry * registry,
  144. xmlrpc_default_method handler,
  145. void * user_data);
  146. /* Define a preinvoke method for the specified registry. This function will
  147. ** be called before any method (either the default or a registered one) is
  148. ** invoked. Applications can use this to do things like access control or
  149. ** sanity checks. The user_data pointer is property of the application,
  150. ** and will not be freed or manipulated by the registry. */
  151. void
  152. xmlrpc_registry_set_preinvoke_method(xmlrpc_env * env,
  153. xmlrpc_registry * registry,
  154. xmlrpc_preinvoke_method method,
  155. void * user_data);
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif