xmlrpc_introspection.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604
  1. /*
  2. This file is part of libXMLRPC - a C library for xml-encoded function calls.
  3. Author: Dan Libby (dan@libby.com)
  4. Epinions.com may be contacted at feedback@epinions-inc.com
  5. */
  6. /*
  7. Copyright 2001 Epinions, Inc.
  8. Subject to the following 3 conditions, Epinions, Inc. permits you, free
  9. of charge, to (a) use, copy, distribute, modify, perform and display this
  10. software and associated documentation files (the "Software"), and (b)
  11. permit others to whom the Software is furnished to do so as well.
  12. 1) The above copyright notice and this permission notice shall be included
  13. without modification in all copies or substantial portions of the
  14. Software.
  15. 2) THE SOFTWARE IS PROVIDED "AS IS", WITHOUT ANY WARRANTY OR CONDITION OF
  16. ANY KIND, EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION ANY
  17. IMPLIED WARRANTIES OF ACCURACY, MERCHANTABILITY, FITNESS FOR A PARTICULAR
  18. PURPOSE OR NONINFRINGEMENT.
  19. 3) IN NO EVENT SHALL EPINIONS, INC. BE LIABLE FOR ANY DIRECT, INDIRECT,
  20. SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES OR LOST PROFITS ARISING OUT
  21. OF OR IN CONNECTION WITH THE SOFTWARE (HOWEVER ARISING, INCLUDING
  22. NEGLIGENCE), EVEN IF EPINIONS, INC. IS AWARE OF THE POSSIBILITY OF SUCH
  23. DAMAGES.
  24. */
  25. /****h* ABOUT/xmlrpc_introspection
  26. * AUTHOR
  27. * Dan Libby, aka danda (dan@libby.com)
  28. * HISTORY
  29. * $Log$
  30. * Revision 1.4 2003/12/16 21:00:21 sniper
  31. * Fix some compile warnings (patch by Joe Orton)
  32. *
  33. * Revision 1.3 2002/07/05 04:43:53 danda
  34. * merged in updates from SF project. bring php repository up to date with xmlrpc-epi version 0.51
  35. *
  36. * Revision 1.9 2001/09/29 21:58:05 danda
  37. * adding cvs log to history section
  38. *
  39. * 4/10/2001 -- danda -- initial introspection support
  40. * TODO
  41. * NOTES
  42. *******/
  43. #ifdef _WIN32
  44. #include "xmlrpc_win32.h"
  45. #endif
  46. #include "queue.h"
  47. #include "xmlrpc.h"
  48. #include "xmlrpc_private.h"
  49. #include "xmlrpc_introspection_private.h"
  50. #include <string.h>
  51. #include <stdlib.h>
  52. #include <stdarg.h>
  53. /* forward declarations for static (non public, non api) funcs */
  54. static XMLRPC_VALUE xi_system_describe_methods_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData);
  55. static XMLRPC_VALUE xi_system_list_methods_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData);
  56. static XMLRPC_VALUE xi_system_method_signature_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData);
  57. static XMLRPC_VALUE xi_system_method_help_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData);
  58. /*-**********************************
  59. * Introspection Callbacks (methods) *
  60. ************************************/
  61. /* iterates through a list of structs and finds the one with key "name" matching
  62. * needle. slow, would benefit from a struct key hash.
  63. */
  64. static inline XMLRPC_VALUE find_named_value(XMLRPC_VALUE list, const char* needle) {
  65. XMLRPC_VALUE xIter = XMLRPC_VectorRewind(list);
  66. while(xIter) {
  67. const char* name = XMLRPC_VectorGetStringWithID(xIter, xi_token_name);
  68. if(name && !strcmp(name, needle)) {
  69. return xIter;
  70. }
  71. xIter = XMLRPC_VectorNext(list);
  72. }
  73. return NULL;
  74. }
  75. /* iterates through docs callbacks and calls any that have not yet been called */
  76. static void check_docs_loaded(XMLRPC_SERVER server, void* userData) {
  77. if(server) {
  78. q_iter qi = Q_Iter_Head_F(&server->docslist);
  79. while( qi ) {
  80. doc_method* dm = Q_Iter_Get_F(qi);
  81. if(dm && !dm->b_called) {
  82. dm->method(server, userData);
  83. dm->b_called = 1;
  84. }
  85. qi = Q_Iter_Next_F(qi);
  86. }
  87. }
  88. }
  89. /* utility function for xi_system_describe_methods_cb */
  90. static inline void describe_method(XMLRPC_SERVER server, XMLRPC_VALUE vector, const char* method) {
  91. if(method) {
  92. server_method* sm = find_method(server, method);
  93. if(sm) {
  94. XMLRPC_AddValueToVector(vector, sm->desc);
  95. }
  96. }
  97. }
  98. /* system.describeMethods() callback */
  99. static XMLRPC_VALUE xi_system_describe_methods_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData) {
  100. XMLRPC_VALUE xParams = XMLRPC_VectorRewind(XMLRPC_RequestGetData(input));
  101. XMLRPC_VALUE xResponse = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
  102. XMLRPC_VALUE xMethodList = XMLRPC_CreateVector("methodList", xmlrpc_vector_array);
  103. XMLRPC_VALUE xTypeList = NULL;
  104. int bAll = 1;
  105. /* lazy loading of introspection data */
  106. check_docs_loaded(server, userData);
  107. xTypeList = XMLRPC_VectorGetValueWithID(server->xIntrospection, "typeList");
  108. XMLRPC_AddValueToVector(xResponse, xTypeList);
  109. XMLRPC_AddValueToVector(xResponse, xMethodList);
  110. /* check if we have any param */
  111. if(xParams) {
  112. /* check if string or vector (1 or n) */
  113. XMLRPC_VALUE_TYPE type = XMLRPC_GetValueType(xParams);
  114. if(type == xmlrpc_string) {
  115. /* just one. spit it out. */
  116. describe_method(server, xMethodList, XMLRPC_GetValueString(xParams));
  117. bAll = 0;
  118. }
  119. else if(type == xmlrpc_vector) {
  120. /* multiple. spit all out */
  121. XMLRPC_VALUE xIter = XMLRPC_VectorRewind(xParams);
  122. while(xIter) {
  123. describe_method(server, xMethodList, XMLRPC_GetValueString(xIter));
  124. xIter = XMLRPC_VectorNext(xParams);
  125. }
  126. bAll = 0;
  127. }
  128. }
  129. /* otherwise, default to sending all methods */
  130. if(bAll) {
  131. q_iter qi = Q_Iter_Head_F(&server->methodlist);
  132. while( qi ) {
  133. server_method* sm = Q_Iter_Get_F(qi);
  134. if(sm) {
  135. XMLRPC_AddValueToVector(xMethodList, sm->desc);
  136. }
  137. qi = Q_Iter_Next_F(qi);
  138. }
  139. }
  140. return xResponse;
  141. }
  142. /* this complies with system.listMethods as defined at http://xmlrpc.usefulinc.com/doc/reserved.html */
  143. static XMLRPC_VALUE xi_system_list_methods_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData) {
  144. XMLRPC_VALUE xResponse = XMLRPC_CreateVector(NULL, xmlrpc_vector_array);
  145. q_iter qi = Q_Iter_Head_F(&server->methodlist);
  146. while( qi ) {
  147. server_method* sm = Q_Iter_Get_F(qi);
  148. if(sm) {
  149. XMLRPC_VectorAppendString(xResponse, 0, sm->name, 0);
  150. }
  151. qi = Q_Iter_Next_F(qi);
  152. }
  153. return xResponse;
  154. }
  155. /* this complies with system.methodSignature as defined at
  156. * http://xmlrpc.usefulinc.com/doc/sysmethodsig.html
  157. */
  158. static XMLRPC_VALUE xi_system_method_signature_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData) {
  159. const char* method = XMLRPC_GetValueString(XMLRPC_VectorRewind(XMLRPC_RequestGetData(input)));
  160. XMLRPC_VALUE xResponse = NULL;
  161. /* lazy loading of introspection data */
  162. check_docs_loaded(server, userData);
  163. if(method) {
  164. server_method* sm = find_method(server, method);
  165. if(sm && sm->desc) {
  166. XMLRPC_VALUE xTypesArray = XMLRPC_CreateVector(NULL, xmlrpc_vector_array);
  167. XMLRPC_VALUE xIter, xParams, xSig, xSigIter;
  168. const char* type;
  169. /* array of possible signatures. */
  170. xResponse = XMLRPC_CreateVector(NULL, xmlrpc_vector_array);
  171. /* find first signature */
  172. xSig = XMLRPC_VectorGetValueWithID(sm->desc, xi_token_signatures);
  173. xSigIter = XMLRPC_VectorRewind( xSig );
  174. /* iterate through sigs */
  175. while(xSigIter) {
  176. /* first type is the return value */
  177. type = XMLRPC_VectorGetStringWithID(XMLRPC_VectorRewind(
  178. XMLRPC_VectorGetValueWithID(xSigIter, xi_token_returns)),
  179. xi_token_type);
  180. XMLRPC_AddValueToVector(xTypesArray,
  181. XMLRPC_CreateValueString(NULL,
  182. type ? type : type_to_str(xmlrpc_none, 0),
  183. 0));
  184. /* the rest are parameters */
  185. xParams = XMLRPC_VectorGetValueWithID(xSigIter, xi_token_params);
  186. xIter = XMLRPC_VectorRewind(xParams);
  187. /* iter through params, adding to types array */
  188. while(xIter) {
  189. XMLRPC_AddValueToVector(xTypesArray,
  190. XMLRPC_CreateValueString(NULL,
  191. XMLRPC_VectorGetStringWithID(xIter, xi_token_type),
  192. 0));
  193. xIter = XMLRPC_VectorNext(xParams);
  194. }
  195. /* add types for this signature */
  196. XMLRPC_AddValueToVector(xResponse, xTypesArray);
  197. xSigIter = XMLRPC_VectorNext( xSig );
  198. }
  199. }
  200. }
  201. return xResponse;
  202. }
  203. /* this complies with system.methodHelp as defined at
  204. * http://xmlrpc.usefulinc.com/doc/sysmethhelp.html
  205. */
  206. static XMLRPC_VALUE xi_system_method_help_cb(XMLRPC_SERVER server, XMLRPC_REQUEST input, void* userData) {
  207. const char* method = XMLRPC_GetValueString(XMLRPC_VectorRewind(XMLRPC_RequestGetData(input)));
  208. XMLRPC_VALUE xResponse = NULL;
  209. /* lazy loading of introspection data */
  210. check_docs_loaded(server, userData);
  211. if(method) {
  212. server_method* sm = find_method(server, method);
  213. if(sm && sm->desc) {
  214. const char* help = XMLRPC_VectorGetStringWithID(sm->desc, xi_token_purpose);
  215. /* returns a documentation string, or empty string */
  216. xResponse = XMLRPC_CreateValueString(NULL, help ? help : xi_token_empty, 0);
  217. }
  218. }
  219. return xResponse;
  220. }
  221. /*-**************************************
  222. * End Introspection Callbacks (methods) *
  223. ****************************************/
  224. /*-************************
  225. * Introspection Utilities *
  226. **************************/
  227. /* performs registration of introspection methods */
  228. void xi_register_system_methods(XMLRPC_SERVER server) {
  229. XMLRPC_ServerRegisterMethod(server, xi_token_system_list_methods, xi_system_list_methods_cb);
  230. XMLRPC_ServerRegisterMethod(server, xi_token_system_method_help, xi_system_method_help_cb);
  231. XMLRPC_ServerRegisterMethod(server, xi_token_system_method_signature, xi_system_method_signature_cb);
  232. XMLRPC_ServerRegisterMethod(server, xi_token_system_describe_methods, xi_system_describe_methods_cb);
  233. }
  234. /* describe a value (param, return, type) */
  235. static XMLRPC_VALUE describeValue_worker(const char* type, const char* id, const char* desc, int optional, const char* default_val, XMLRPC_VALUE sub_params) {
  236. XMLRPC_VALUE xParam = NULL;
  237. if(id || desc) {
  238. xParam = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
  239. XMLRPC_VectorAppendString(xParam, xi_token_name, id, 0);
  240. XMLRPC_VectorAppendString(xParam, xi_token_type, type, 0);
  241. XMLRPC_VectorAppendString(xParam, xi_token_description, desc, 0);
  242. if(optional != 2) {
  243. XMLRPC_VectorAppendInt(xParam, xi_token_optional, optional);
  244. }
  245. if(optional == 1 && default_val) {
  246. XMLRPC_VectorAppendString(xParam, xi_token_default, default_val, 0);
  247. }
  248. XMLRPC_AddValueToVector(xParam, sub_params);
  249. }
  250. return xParam;
  251. }
  252. /* convert an xml tree conforming to spec <url tbd> to XMLRPC_VALUE
  253. * suitable for use with XMLRPC_ServerAddIntrospectionData
  254. */
  255. XMLRPC_VALUE xml_element_to_method_description(xml_element* el, XMLRPC_ERROR err) {
  256. XMLRPC_VALUE xReturn = NULL;
  257. if(el->name) {
  258. const char* name = NULL;
  259. const char* type = NULL;
  260. const char* basetype = NULL;
  261. const char* desc = NULL;
  262. const char* def = NULL;
  263. int optional = 0;
  264. xml_element_attr* attr_iter = Q_Head(&el->attrs);
  265. /* grab element attributes up front to save redundant while loops */
  266. while(attr_iter) {
  267. if(!strcmp(attr_iter->key, "name")) {
  268. name = attr_iter->val;
  269. }
  270. else if(!strcmp(attr_iter->key, "type")) {
  271. type = attr_iter->val;
  272. }
  273. else if(!strcmp(attr_iter->key, "basetype")) {
  274. basetype = attr_iter->val;
  275. }
  276. else if(!strcmp(attr_iter->key, "desc")) {
  277. desc = attr_iter->val;
  278. }
  279. else if(!strcmp(attr_iter->key, "optional")) {
  280. if(attr_iter->val && !strcmp(attr_iter->val, "yes")) {
  281. optional = 1;
  282. }
  283. }
  284. else if(!strcmp(attr_iter->key, "default")) {
  285. def = attr_iter->val;
  286. }
  287. attr_iter = Q_Next(&el->attrs);
  288. }
  289. /* value and typeDescription behave about the same */
  290. if(!strcmp(el->name, "value") || !strcmp(el->name, "typeDescription")) {
  291. XMLRPC_VALUE xSubList = NULL;
  292. const char* ptype = !strcmp(el->name, "value") ? type : basetype;
  293. if(ptype) {
  294. if(Q_Size(&el->children) &&
  295. (!strcmp(ptype, "array") || !strcmp(ptype, "struct") || !strcmp(ptype, "mixed"))) {
  296. xSubList = XMLRPC_CreateVector("member", xmlrpc_vector_array);
  297. if(xSubList) {
  298. xml_element* elem_iter = Q_Head(&el->children);
  299. while(elem_iter) {
  300. XMLRPC_AddValueToVector(xSubList,
  301. xml_element_to_method_description(elem_iter, err));
  302. elem_iter = Q_Next(&el->children);
  303. }
  304. }
  305. }
  306. xReturn = describeValue_worker(ptype, name, (desc ? desc : (xSubList ? NULL : el->text.str)), optional, def, xSubList);
  307. }
  308. }
  309. /* these three kids are about equivalent */
  310. else if(!strcmp(el->name, "params") ||
  311. !strcmp(el->name, "returns") ||
  312. !strcmp(el->name, "signature")) {
  313. if(Q_Size(&el->children)) {
  314. xml_element* elem_iter = Q_Head(&el->children);
  315. xReturn = XMLRPC_CreateVector(!strcmp(el->name, "signature") ? NULL : el->name, xmlrpc_vector_struct);
  316. while(elem_iter) {
  317. XMLRPC_AddValueToVector(xReturn,
  318. xml_element_to_method_description(elem_iter, err));
  319. elem_iter = Q_Next(&el->children);
  320. }
  321. }
  322. }
  323. else if(!strcmp(el->name, "methodDescription")) {
  324. xml_element* elem_iter = Q_Head(&el->children);
  325. xReturn = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
  326. XMLRPC_VectorAppendString(xReturn, xi_token_name, name, 0);
  327. while(elem_iter) {
  328. XMLRPC_AddValueToVector(xReturn,
  329. xml_element_to_method_description(elem_iter, err));
  330. elem_iter = Q_Next(&el->children);
  331. }
  332. }
  333. /* items are slightly special */
  334. else if(!strcmp(el->name, "item")) {
  335. xReturn = XMLRPC_CreateValueString(name, el->text.str, el->text.len);
  336. }
  337. /* sure. we'll let any ol element with children through */
  338. else if(Q_Size(&el->children)) {
  339. xml_element* elem_iter = Q_Head(&el->children);
  340. xReturn = XMLRPC_CreateVector(el->name, xmlrpc_vector_mixed);
  341. while(elem_iter) {
  342. XMLRPC_AddValueToVector(xReturn,
  343. xml_element_to_method_description(elem_iter, err));
  344. elem_iter = Q_Next(&el->children);
  345. }
  346. }
  347. /* or anything at all really, so long as its got some text.
  348. * no reason being all snotty about a spec, right?
  349. */
  350. else if(el->name && el->text.len) {
  351. xReturn = XMLRPC_CreateValueString(el->name, el->text.str, el->text.len);
  352. }
  353. }
  354. return xReturn;
  355. }
  356. /*-****************************
  357. * End Introspection Utilities *
  358. ******************************/
  359. /*-******************
  360. * Introspection API *
  361. ********************/
  362. /****f* VALUE/XMLRPC_IntrospectionCreateDescription
  363. * NAME
  364. * XMLRPC_IntrospectionCreateDescription
  365. * SYNOPSIS
  366. * XMLRPC_VALUE XMLRPC_IntrospectionCreateDescription(const char* xml, XMLRPC_ERROR err)
  367. * FUNCTION
  368. * converts raw xml describing types and methods into an
  369. * XMLRPC_VALUE suitable for use with XMLRPC_ServerAddIntrospectionData()
  370. * INPUTS
  371. * xml - xml data conforming to introspection spec at <url tbd>
  372. * err - optional pointer to error struct. filled in if error occurs and not NULL.
  373. * RESULT
  374. * XMLRPC_VALUE - newly created value, or NULL if fatal error.
  375. * BUGS
  376. * Currently does little or no validation of xml.
  377. * Only parse errors are currently reported in err, not structural errors.
  378. * SEE ALSO
  379. * XMLRPC_ServerAddIntrospectionData ()
  380. * SOURCE
  381. */
  382. XMLRPC_VALUE XMLRPC_IntrospectionCreateDescription(const char* xml, XMLRPC_ERROR err) {
  383. XMLRPC_VALUE xReturn = NULL;
  384. xml_element* root = xml_elem_parse_buf(xml, 0, 0, err ? &err->xml_elem_error : NULL);
  385. if(root) {
  386. xReturn = xml_element_to_method_description(root, err);
  387. xml_elem_free(root);
  388. }
  389. return xReturn;
  390. }
  391. /*******/
  392. /****f* SERVER/XMLRPC_ServerAddIntrospectionData
  393. * NAME
  394. * XMLRPC_ServerAddIntrospectionData
  395. * SYNOPSIS
  396. * int XMLRPC_ServerAddIntrospectionData(XMLRPC_SERVER server, XMLRPC_VALUE desc)
  397. * FUNCTION
  398. * updates server with additional introspection data
  399. * INPUTS
  400. * server - target server
  401. * desc - introspection data, should be a struct generated by
  402. * XMLRPC_IntrospectionCreateDescription ()
  403. * RESULT
  404. * int - 1 if success, else 0
  405. * NOTES
  406. * - function will fail if neither typeList nor methodList key is present in struct.
  407. * - if method or type already exists, it will be replaced.
  408. * - desc is never freed by the server. caller is responsible for cleanup.
  409. * BUGS
  410. * - horribly slow lookups. prime candidate for hash improvements.
  411. * - uglier and more complex than I like to see for API functions.
  412. * SEE ALSO
  413. * XMLRPC_ServerAddIntrospectionData ()
  414. * XMLRPC_ServerRegisterIntrospectionCallback ()
  415. * XMLRPC_CleanupValue ()
  416. * SOURCE
  417. */
  418. int XMLRPC_ServerAddIntrospectionData(XMLRPC_SERVER server, XMLRPC_VALUE desc) {
  419. int bSuccess = 0;
  420. if(server && desc) {
  421. XMLRPC_VALUE xNewTypes = XMLRPC_VectorGetValueWithID(desc, "typeList");
  422. XMLRPC_VALUE xNewMethods = XMLRPC_VectorGetValueWithID(desc, "methodList");
  423. XMLRPC_VALUE xServerTypes = XMLRPC_VectorGetValueWithID(server->xIntrospection, "typeList");
  424. if(xNewMethods) {
  425. XMLRPC_VALUE xMethod = XMLRPC_VectorRewind(xNewMethods);
  426. while(xMethod) {
  427. const char* name = XMLRPC_VectorGetStringWithID(xMethod, xi_token_name);
  428. server_method* sm = find_method(server, name);
  429. if(sm) {
  430. if(sm->desc) {
  431. XMLRPC_CleanupValue(sm->desc);
  432. }
  433. sm->desc = XMLRPC_CopyValue(xMethod);
  434. bSuccess = 1;
  435. }
  436. xMethod = XMLRPC_VectorNext(xNewMethods);
  437. }
  438. }
  439. if(xNewTypes) {
  440. if(!xServerTypes) {
  441. if(!server->xIntrospection) {
  442. server->xIntrospection = XMLRPC_CreateVector(NULL, xmlrpc_vector_struct);
  443. }
  444. XMLRPC_AddValueToVector(server->xIntrospection, xNewTypes);
  445. bSuccess = 1;
  446. }
  447. else {
  448. XMLRPC_VALUE xIter = XMLRPC_VectorRewind(xNewTypes);
  449. while(xIter) {
  450. /* get rid of old values */
  451. XMLRPC_VALUE xPrev = find_named_value(xServerTypes, XMLRPC_VectorGetStringWithID(xIter, xi_token_name));
  452. if(xPrev) {
  453. XMLRPC_VectorRemoveValue(xServerTypes, xPrev);
  454. }
  455. XMLRPC_AddValueToVector(xServerTypes, xIter);
  456. bSuccess = 1;
  457. xIter = XMLRPC_VectorNext(xNewTypes);
  458. }
  459. }
  460. }
  461. }
  462. return bSuccess;
  463. }
  464. /*******/
  465. /****f* SERVER/XMLRPC_ServerRegisterIntrospectionCallback
  466. * NAME
  467. * XMLRPC_ServerRegisterIntrospectionCallback
  468. * SYNOPSIS
  469. * int XMLRPC_ServerRegisterIntrospectionCallback(XMLRPC_SERVER server, XMLRPC_IntrospectionCallback cb)
  470. * FUNCTION
  471. * registers a callback for lazy generation of introspection data
  472. * INPUTS
  473. * server - target server
  474. * cb - callback that will generate introspection data
  475. * RESULT
  476. * int - 1 if success, else 0
  477. * NOTES
  478. * parsing xml and generating introspection data is fairly expensive, thus a
  479. * server may wish to wait until this data is actually requested before generating
  480. * it. Any number of callbacks may be registered at any time. A given callback
  481. * will only ever be called once, the first time an introspection request is
  482. * processed after the time of callback registration.
  483. * SEE ALSO
  484. * XMLRPC_ServerAddIntrospectionData ()
  485. * XMLRPC_IntrospectionCreateDescription ()
  486. * SOURCE
  487. */
  488. int XMLRPC_ServerRegisterIntrospectionCallback(XMLRPC_SERVER server, XMLRPC_IntrospectionCallback cb) {
  489. int bSuccess = 0;
  490. if(server && cb) {
  491. doc_method* dm = calloc(1, sizeof(doc_method));
  492. if(dm) {
  493. dm->method = cb;
  494. dm->b_called = 0;
  495. if(Q_PushTail(&server->docslist, dm)) {
  496. bSuccess = 1;
  497. }
  498. else {
  499. my_free(dm);
  500. }
  501. }
  502. }
  503. return 0;
  504. }
  505. /*******/
  506. /*-**********************
  507. * End Introspection API *
  508. ************************/