xmlrpc.xml 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
  3. "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
  4. <!-- Include general documentation entities -->
  5. <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
  6. %docentities;
  7. ]>
  8. <book id="xmlrpc" xmlns:xi="http://www.w3.org/2001/XInclude">
  9. <bookinfo>
  10. <title>The XMLRPC Module</title>
  11. <authorgroup>
  12. <author>
  13. <firstname>Jan</firstname>
  14. <surname>Janak</surname>
  15. <affiliation><orgname>iptelorg GmbH</orgname></affiliation>
  16. <address>
  17. <email>[email protected]</email>
  18. </address>
  19. </author>
  20. </authorgroup>
  21. <copyright>
  22. <year>2005</year>
  23. <holder>iptelorg GmbH</holder>
  24. </copyright>
  25. </bookinfo>
  26. <section id="xmlrpc.design">
  27. <title>Design Goals</title>
  28. <para>
  29. </para>
  30. <itemizedlist>
  31. <listitem>
  32. <para>Implemented as a module.</para>
  33. </listitem>
  34. <listitem>
  35. <para>API independent of transport protocols.</para>
  36. </listitem>
  37. <listitem>
  38. <para>Reuse transports available in &kamailio;.</para>
  39. </listitem>
  40. <listitem>
  41. <para>The possibility to encrypt all communication.</para>
  42. </listitem>
  43. <listitem>
  44. <para>The possibility to authenticate clients.</para>
  45. </listitem>
  46. <listitem>
  47. <para>Easy integration with existing languages and
  48. implementations.</para>
  49. </listitem>
  50. <listitem>
  51. <para>
  52. Easy and straightforward implementation of management
  53. functions in &kamailio; modules.
  54. </para>
  55. </listitem>
  56. </itemizedlist>
  57. </section>
  58. <section id="xmlrpc.overview">
  59. <title>Overview of Operation</title>
  60. <para>
  61. This module implements the XML-RPC transport and encoding interface
  62. for &kamailio; RPCs.
  63. </para>
  64. <para>
  65. The XML-RPC protocol encodes the name of the method
  66. to be called along with its parameter in an XML document which is
  67. then conveyed using HTTP (Hyper Text Transfer Protocol) to the
  68. server. The server will extract the name of the function to be
  69. called along with its parameters from the XML document, execute the
  70. function, and encode any data returned by the function into another
  71. XML document which is then returned to the client in the body of a
  72. 200 OK reply to the HTTP request.
  73. </para>
  74. <para>
  75. XML-RPC is similar to more popular <ulink
  76. url="http://www.w3.org/TR/soap/">SOAP</ulink> (Simple Object
  77. Access Protocol), which is an XML-based messaging framework
  78. used in Web Services developed within the <ulink
  79. url="http://www.w3c.org">World Wide Web
  80. Consortium</ulink>. Both protocols are using HTTP as the
  81. transport protocol for XML documents, but XML-RPC is much
  82. simpler and easier to implement than SOAP.
  83. </para>
  84. <para>
  85. Here is an example of single XML-RPC function call to determine
  86. current time:
  87. </para>
  88. <programlisting>
  89. <![CDATA[
  90. POST /RPC2 HTTP/1.0
  91. User-Agent: Radio UserLand/7.1b7 (WinNT)
  92. Host: time.xmlrpc.com
  93. Content-Type: text/xml
  94. Content-length: 131
  95. <?xml version="1.0"?>
  96. <methodCall>
  97. <methodName>currentTime.getCurrentTime</methodName>
  98. <params>
  99. </params>
  100. </methodCall>
  101. ]]>
  102. </programlisting>
  103. <para>
  104. And the response returned by the server:
  105. </para>
  106. <programlisting>
  107. <![CDATA[
  108. HTTP/1.1 200 OK
  109. Connection: close
  110. Content-Length: 183
  111. Content-Type: text/xml
  112. Date: Wed, 03 Oct 2001 15:53:38 GMT
  113. Server: UserLand Frontier/7.0.1-WinNT
  114. <?xml version="1.0"?>
  115. <methodResponse>
  116. <params>
  117. <param>
  118. <value><dateTime.iso8601>20011003T08:53:38</dateTime.iso8601>
  119. </value>
  120. </param>
  121. </params>
  122. </methodResponse>
  123. ]]>
  124. </programlisting>
  125. <para>
  126. XML-RPC specification spells HTTP as the official transport
  127. protocol for XML-RPC documents. &kamailio; does not directly support
  128. HTTP, it is a SIP server so SIP is the only protocol supported by
  129. &kamailio;. Because we would like to reuse all transport protocols
  130. available in &kamailio;, such as TCP and TLS, it would be natural to use
  131. modified version of XML-RPC which would run on top of SIP instead
  132. of HTTP. XML-RPC documents would be then encoded in the bodies of
  133. SIP requests and replies would be sent by the server in the bodies of
  134. SIP replies. This way we could reuse all transport protocols
  135. (including UDP) and message parsers available in &kamailio;.
  136. </para>
  137. <para>
  138. Although this approach seems to be the logical choice, there is one
  139. big drawback. No existing XML-RPC implementations support SIP as the
  140. transport protocol, and there are many existing implementations
  141. available for vast majority of existing languages. See the <ulink
  142. url="http://www.xmlrpc.com/directory/1568/implementations">XML-RPC
  143. implementation page</ulink> for more details. Extending existing
  144. implementations with SIP support would not be easy.
  145. </para>
  146. <para>
  147. Because extending available XML-RPC implementation would be too
  148. expensive, we could also do it the other way around, keep existing
  149. XML-RPC implementations and extend &kamailio; to support HTTP. Extending
  150. &kamailio; with HTTP support is easier than it might seem at a first
  151. glance, due to the similarity between SIP requests and HTTP
  152. requests.
  153. </para>
  154. <para>
  155. &kamailio; already supports TCP, so existing HTTP implementations can send
  156. HTTP requests to it. HTTP requests are missing certain mandatory
  157. SIP header fields, such as Via, From, and CSeq. The contents of the
  158. header fields is mainly used for transaction matching. A SIP server
  159. could perform two basic operations when processing an HTTP
  160. request:
  161. <itemizedlist>
  162. <listitem>
  163. <para>
  164. Terminate the request, execute the function and send a
  165. reply back.
  166. </para>
  167. </listitem>
  168. <listitem>
  169. <para>
  170. Forward the request to another SIP server.
  171. </para>
  172. </listitem>
  173. </itemizedlist>
  174. </para>
  175. <para>
  176. Nothing special is needed on the SIP server terminating the
  177. request, except that it has to know where it should send the
  178. reply. Parsing of HTTP header field bodies would fail because we do
  179. not have parsers for them in &kamailio;, but that does not matter anyway
  180. because all the information is encoded in the body of the
  181. request. HTTP requests contain no Via header fields. Via header
  182. fields are used by SIP implementations to determine the destination
  183. (IP, transport protocol, and port number) for replies. When
  184. processing HTTP requests the SIP server needs to create a fake Via
  185. header field based on the source IP address and port number of the
  186. TCP connection. The SIP server will use this information when
  187. sending a reply back.
  188. </para>
  189. <para>
  190. Forwarding of HTTP requests by SIP proxies is a little bit more
  191. complicated and there are several limitations. First of all, we can
  192. only use stateless forwarding, no transactional forwarding, because
  193. HTTP requests do not contain all the header fields needed for
  194. transaction matching. Any attempt to call t_relay on an HTTP
  195. requests would fail. HTTP requests always use TCP and thus we could
  196. use stateless forwarding on the SIP server, provided that the
  197. request will be also forwarded over TCP. Stateless forwarding does
  198. not require the mandatory header fields (which are missing here)
  199. and it would work. In addition to that, the SIP server would also
  200. append fake Via header field to the request and change the contents
  201. of the Request-URI. The Request-URI of HTTP requests sent by XML-RPC
  202. implementations typically contain something like "/RPC2" and the
  203. first SIP server processing the request should rewrite the value
  204. with a valid SIP URI.
  205. </para>
  206. <para>
  207. <xref linkend="fig.rpc_example"/> shows a scenario which involves
  208. two SIP servers, one performs HTTP request "normalization" and
  209. forwarding, and the other terminates the request, executes
  210. corresponding function, and generates a reply.
  211. </para>
  212. <mediaobject id="fig.rpc_example" xreflabel="Figure RPC Example">
  213. <imageobject>
  214. <imagedata align="center" fileref="xmlrpc_example.png" format="PNG"/>
  215. </imageobject>
  216. <textobject>
  217. <para>Example RPC Scenario</para>
  218. </textobject>
  219. <caption>
  220. Example RPC Scenario
  221. </caption>
  222. </mediaobject>
  223. <para>
  224. <emphasis>Step 1.</emphasis> An HTTP user agent sends an ordinary
  225. HTTP request to a SIP server. The user agent can either establish a
  226. connection directly to port 5060 or the SIP server can be
  227. configured to listen on port 80. The request contains standard HTTP
  228. headers and an XML-RPC document in the body:
  229. <programlisting>
  230. <![CDATA[
  231. POST / HTTP/1.0.
  232. Host: localhost:5060
  233. User-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com)
  234. Content-Type: text/xml
  235. Content-Length: 111
  236. <?xml version='1.0'?>
  237. <methodCall>
  238. <methodName>]]><emphasis>usrloc.statistics</emphasis><![CDATA[</methodName>
  239. <params>
  240. </params>
  241. </methodCall>
  242. ]]>
  243. </programlisting>
  244. This particular request calls method "statistics" from from usrloc
  245. module of &kamailio;. The method has no parameters.
  246. </para>
  247. <para>
  248. The outbound SIP server receives the HTTP request and performs a
  249. set of actions called "SIP-normalization". This includes creation
  250. of fake Via header field based on the source IP and port of the TCP
  251. connection, looking up of the target SIP server that should
  252. terminate and process the request, and rewriting of the Request-URI
  253. with the SIP URI of the target SIP server. Modified HTTP request
  254. will be then forwarded statelessly to the target SIP server.
  255. <programlisting>
  256. POST <emphasis>sip:proxy01.sip-server.net</emphasis> HTTP/1.0
  257. <emphasis>Via: SIP/2.0/TCP 127.0.0.1:3571</emphasis>
  258. Host: localhost:5060
  259. User-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com)
  260. Content-Type: text/xml
  261. Content-Length: 111
  262. <![CDATA[
  263. <?xml version='1.0'?>
  264. <methodCall>
  265. <methodName>usrloc.statistics</methodName>
  266. <params>
  267. </params>
  268. </methodCall>
  269. ]]>
  270. </programlisting>
  271. </para>
  272. <para>
  273. <emphasis>Step 2.</emphasis> "normalized" HTTP request is
  274. statelessly forwarded to the target SIP server over TCP.
  275. </para>
  276. <para>
  277. <emphasis>Step 3.</emphasis> The target SIP server receives the
  278. HTTP request and executes function called
  279. <function>dispatch_rpc</function> from xmlrpc &kamailio; module. This
  280. function will parse the XML-RPC document in the body of the request
  281. and lookup the function to be called among all RPC functions
  282. exported by the &kamailio; core and modules. Function
  283. <function>dispatch_rpc</function> will be called from the
  284. configuration file just like any other function:
  285. <programlisting>
  286. if (method == "POST" || method == "GET") {
  287. <emphasis>dispatch_rpc();</emphasis>
  288. break;
  289. };
  290. </programlisting>
  291. This particular configuration snippet executes the function
  292. whenever &kamailio; receives GET or POST requests. These two method names
  293. indicate HTTP.
  294. </para>
  295. <para>
  296. <emphasis>Step 4.</emphasis> The function
  297. <function>dispatch_rpc</function> scans through the list of all
  298. exported RPC functions searching for the
  299. <function>statistics</function> function of the usrloc module. The
  300. <ulink url='http://sip-router.org/docbook/sip-router/branch/master/rpc/ser_rpc.html'>
  301. &kamailio; RPC Module API</ulink>
  302. describes in detail how modules export RPC functions.
  303. </para>
  304. <para>
  305. <emphasis>Step 5.</emphasis> As the RPC function from usrloc module
  306. is running and gathering statistics, it calls functions of RPC
  307. interface to prepare the result for the caller.
  308. </para>
  309. <para>
  310. <emphasis>Step 6.</emphasis> Once the RPC function finishes, xmlrpc
  311. module will build the XML-RPC document from the data received from
  312. usrloc module and generate a reply which will be sent to the caller.
  313. </para>
  314. <para>
  315. <emphasis>Steps 7. and 8.</emphasis> HTTP reply is sent back to the
  316. caller and the remote procedure call finishes.
  317. <programlisting>
  318. <![CDATA[
  319. HTTP/1.0 200 OK
  320. Via: SIP/2.0/TCP 127.0.0.1:3571
  321. Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))
  322. Content-Length: 651
  323. Warning: 392 127.0.0.1:5060 "Noisy feedback tells: pid=9975 req_src_ip=127.0.0
  324. 1 req_src_port=3571 in_uri=/ out_uri=sip:proxy01.sip-server.net via_cnt==1"
  325. <?xml version="1.0" encoding="UTF-8"?>
  326. <methodResponse>
  327. <params>
  328. <param><value><array><data>
  329. <value><struct>
  330. <member><name>domain</name>
  331. <value><string>aliases</string></value></member>
  332. <member><name>users</name>
  333. <value><i4>0</i4></value></member>
  334. <member><name>expired</name>
  335. <value><i4>0</i4></value></member>
  336. </struct></value>
  337. <value><struct>
  338. <member><name>domain</name>
  339. <value><string>location</string></value></member>
  340. <member><name>users</name>
  341. <value><i4>0</i4></value></member>
  342. <member><name>expired</name>
  343. <value><i4>0</i4></value></member>
  344. </struct></value>
  345. </data></array></value></param>
  346. </params>
  347. </methodResponse>
  348. ]]>
  349. </programlisting>
  350. </para>
  351. <note>
  352. <para>
  353. The scenario described on <xref linkend="fig.rpc_example"/>
  354. involves two SIP servers. This is just to demonstrate that in
  355. setups containing more SIP servers it is possible to forward
  356. HTTP requests from one SIP server to another and use standard
  357. SIP routing mechanisms to decide which SIP server should
  358. process the request. There is no need to have multiple SIP
  359. servers in simple setups, because one SIP server can both add
  360. fake Via header field and process the RPC at the same
  361. time. Modified configuration file snipped could then look like
  362. this:
  363. <programlisting>
  364. if (method == "POST" || method == "GET") {
  365. <emphasis>dispatch_rpc();</emphasis> # Process the request
  366. break;
  367. };
  368. </programlisting>
  369. </para>
  370. </note>
  371. </section>
  372. <section id="xmlrpc.implementation">
  373. <title>XML-RPC Implementation</title>
  374. <para>
  375. The purpose of the functions of this module is to convert XML-RPC
  376. document carried in the body of HTTP requests into data returned by
  377. the RPC interface and back. The module also contains functions
  378. necessary to "normalize" HTTP requests. The module uses <ulink
  379. url="http://xmlrpc-c.sourceforge.net">xmlrpc-c</ulink>
  380. library to perform XML-RPC related functions.
  381. </para>
  382. <para>
  383. The module always returns 200 OK HTTP reply, it will never return
  384. any other HTTP reply. Failures are expressed in XML-RPC documents
  385. in the body of the reply. There is basic method introspection
  386. support in the module. Currently the module can list all functions
  387. exported by the server and for each function it can return the
  388. documentation string describing the function.
  389. </para>
  390. <section id="xmlrpc.implementation.requests">
  391. <title>Requests</title>
  392. <para>
  393. Requests processed by the module are standard XML-RPC requests
  394. encoded in bodies of HTTP requests.
  395. <programlisting>
  396. <![CDATA[
  397. POST / HTTP/1.0
  398. Host: localhost:5060
  399. User-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com)
  400. Content-Type: text/xml
  401. Content-Length: 112
  402. <?xml version='1.0'?>
  403. <methodCall>
  404. ]]><emphasis><![CDATA[<methodName>system.listMethods</methodName>]]></emphasis><![CDATA[
  405. <params>
  406. </params>
  407. </methodCall>
  408. ]]>
  409. </programlisting>
  410. The name of the method to be called in this example is
  411. "listMethods". This is one of the introspection methods. &kamailio;
  412. will call <function>dispatch_rpc</function> function of xmlrpc
  413. module to handle the request. The function will parse the
  414. XML-RPC document, lookup <function>listMethods</function>
  415. function in the list of all export RPC functions, prepare the
  416. context for the function and execute it.
  417. </para>
  418. </section>
  419. <section id="xmlrpc.implementation.replies">
  420. <title>Replies</title>
  421. <para>
  422. The module will always generate 200 OK. Other response codes
  423. and classes are reserved for &kamailio;. The status code of the
  424. XML-RPC reply, response code, and additional data will be
  425. encoded in the body of the reply. Failure replies do not
  426. contain any data, just the response code and reason phrase:
  427. <programlisting>
  428. <![CDATA[
  429. HTTP/1.0 200 OK
  430. Via: SIP/2.0/TCP 127.0.0.1:2464
  431. Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))
  432. Content-Length: 301
  433. <?xml version="1.0" encoding="UTF-8"?>
  434. <methodResponse>
  435. ]]><emphasis><![CDATA[
  436. <fault>
  437. <value><struct>
  438. <member><name>faultCode</name>
  439. <value><i4>501</i4></value></member>
  440. <member><name>faultString</name>
  441. <value><string>Method Not Implemented</string></value></member>
  442. </struct></value>
  443. </fault>
  444. ]]></emphasis><![CDATA[
  445. </methodResponse>
  446. ]]>
  447. </programlisting>
  448. This particular reply indicates that there is no such RPC
  449. method available on the server.
  450. </para>
  451. <para>
  452. Success replies always contain at least one return value. In
  453. our case the simplest success replies contain single boolean
  454. with value 1:
  455. <programlisting>
  456. <![CDATA[
  457. HTTP/1.0 200 OK
  458. Via: SIP/2.0/TCP 127.0.0.1:4626
  459. Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))
  460. Content-Length: 150
  461. <?xml version="1.0" encoding="UTF-8"?>
  462. <methodResponse>
  463. <params>
  464. ]]><emphasis><![CDATA[<param><value><boolean>1</boolean></value></param>]]></emphasis><![CDATA[
  465. </params>
  466. </methodResponse>
  467. ]]>
  468. </programlisting>
  469. This is exactly how the reply looks like when an RPC function
  470. does not add any data to the reply set.
  471. </para>
  472. <para>
  473. If an RPC function adds just a single item (it calls
  474. <function>add</function> once
  475. with just one character in the formatting string) then the data
  476. will be converted to XML-RPC representation according to the
  477. rules described in
  478. <ulink url='http://sip-router.org/docbook/sip-router/branch/master/rpc/ser_rpc.html#rpc.data_types'>
  479. &kamailio; RPC Type Conversion</ulink> and
  480. the reply will contain just the single value:
  481. <programlisting>
  482. <![CDATA[
  483. HTTP/1.0 200 OK
  484. Via: SIP/2.0/TCP 127.0.0.1:3793
  485. Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))
  486. Content-Length: 216
  487. <?xml version="1.0" encoding="UTF-8"?>
  488. <methodResponse>
  489. <params>
  490. ]]><emphasis><![CDATA[<param><value><string>Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))</string></value></param>]]></emphasis><![CDATA[
  491. </params>
  492. </methodResponse>
  493. ]]>
  494. </programlisting>
  495. </para>
  496. <para>
  497. If an RPC function adds more than one data items to the result
  498. set then the module will return an array containing all the
  499. data items:
  500. <programlisting>
  501. <![CDATA[
  502. HTTP/1.0 200 OK
  503. Via: SIP/2.0/TCP 127.0.0.1:2932
  504. Server: Sip EXpress router (0.10.99-janakj_experimental (i386/linux))
  505. Content-Length: 276
  506. <?xml version="1.0" encoding="UTF-8"?>
  507. <methodResponse>
  508. <params>
  509. <param><value>]]><emphasis><![CDATA[<array><data>
  510. <value><string>./ser</string></value>
  511. <value><string>-f</string></value>
  512. <value><string>ser.cfg</string></value>
  513. </data></array>]]></emphasis><![CDATA[</value></param>
  514. </params>
  515. </methodResponse>
  516. ]]>
  517. </programlisting>
  518. This is probably the most common scenario.
  519. </para>
  520. </section>
  521. <section id="xmlrpc.implementation.type_conversion">
  522. <title>Type Conversion</title>
  523. <para>
  524. The data types of the RPC API are converted to the data types
  525. of XML-RPC and vice versa. <xref
  526. linkend="tab.type_conversion"/> shows for each RPC API data
  527. type corresponding XML-RPC data type.
  528. <table id="tab.type_conversion">
  529. <title>Data Type Conversion</title>
  530. <tgroup cols="3">
  531. <tbody>
  532. <row>
  533. <entry>RPC API</entry>
  534. <entry>XML-RPC</entry>
  535. <entry>RPC Example</entry>
  536. <entry>XML-RPC Example</entry>
  537. </row>
  538. <row>
  539. <entry>Integer</entry>
  540. <entry>
  541. <markup role="xmlrpc">
  542. <![CDATA[
  543. <i4></i4>
  544. ]]>
  545. </markup>
  546. </entry>
  547. <entry>rpc->add("d", 42)</entry>
  548. <entry>
  549. <markup role="xmlrpc">
  550. <![CDATA[
  551. <i4>42</i4>
  552. ]]>
  553. </markup>
  554. </entry>
  555. </row>
  556. <row>
  557. <entry>Float</entry>
  558. <entry>
  559. <markup role="xmlrpc">
  560. <![CDATA[
  561. <double></double>
  562. ]]>
  563. </markup>
  564. </entry>
  565. <entry>rpc->add("f", -12.214)</entry>
  566. <entry>
  567. <markup role="xmlrpc">
  568. <![CDATA[
  569. <double>-12.214</double>
  570. ]]>
  571. </markup>
  572. </entry>
  573. </row>
  574. <row>
  575. <entry>String</entry>
  576. <entry>
  577. <markup role="xmlrpc">
  578. <![CDATA[
  579. <string></string>
  580. ]]>
  581. </markup>
  582. </entry>
  583. <entry>rpc->add("s","Don't panic")</entry>
  584. <entry>
  585. <markup role="xmlrpc">
  586. <![CDATA[
  587. <string>Don't panic</string>
  588. ]]>
  589. </markup>
  590. </entry>
  591. </row>
  592. <row>
  593. <entry>Struct</entry>
  594. <entry>
  595. <markup role="xmlrpc">
  596. <![CDATA[
  597. <struct></struct>
  598. ]]>
  599. </markup>
  600. </entry>
  601. <entry>rpc->struct_add(handle,"sd","param1",42,"param2",-12.214)</entry>
  602. <entry>
  603. <programlisting>
  604. <![CDATA[
  605. <struct>
  606. <member>
  607. <name>param1</name>
  608. <value>
  609. <i4>42</i4>
  610. </value>
  611. </member>
  612. <member>
  613. <name>param2</name>
  614. <value>
  615. <double>-12.214</i4>
  616. </value>
  617. </member>
  618. </struct>
  619. ]]>
  620. </programlisting>
  621. </entry>
  622. </row>
  623. </tbody>
  624. </tgroup>
  625. </table>
  626. </para>
  627. </section>
  628. <section id="xmlrpc.implementation.limitations">
  629. <title>Limitations</title>
  630. <para>
  631. &kamailio; xmlrpc modules does not implement all data types allowed in
  632. XML-RPC. As well it does not implement arrays and nested
  633. structures. This simplification is a feature, not bug. In our
  634. case the XML-RPC interface will be used mainly for management
  635. purposes and we do not need all the bells and whistles of
  636. XML-RPC. Parsing and interpreting nested structures is
  637. complex and we try to avoid it.
  638. </para>
  639. </section>
  640. <section id="xmlrpc.interoperability_problems">
  641. <title>Interoperability Problems</title>
  642. <para>
  643. Due to a bug in Python xmlrpclib there is an interoperability
  644. problem with basic clients using it: by default an xmlrpclib client
  645. expects the server to immediately close the connection after answering
  646. and if the server does not close the connections the xmlrpclib client
  647. will wait forever.
  648. </para>
  649. <para>
  650. There are 2 ways to work around this problem: write a "fixed"
  651. Transport class and initialize xmlpclib using it (recommended) or
  652. make ser close the tcp connection after each request.
  653. </para>
  654. <para>
  655. The <ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules/xmlrpc/examples/xmlrpc_test.py'>
  656. examples/xmlrpc_test.py
  657. </ulink> provides a very simple example of using xmlrpclib with a
  658. Transport class that works.
  659. </para>
  660. <para>
  661. For the second solution (force closing tcp connections after answering)
  662. the XMLRPC route should have a <function>set_reply_close()</function>
  663. command before <function>dispatch_rpc()</function>.
  664. <function>set_reply_no_connect()</function> is also recommended
  665. (avoid trying to open tcp connection to xmlrpc clients that closed it).
  666. Alternatively ending the XMLRPC route with return -1, exit -1 or
  667. drop -1 can also be used, but note that this will not work for
  668. async rpcs (it will close the connection immeidately and not on the
  669. async response).
  670. <example>
  671. <programlisting>
  672. <![CDATA[
  673. route[XMLRPC]{
  674. # close connection only for xmlrpclib user agents
  675. if search("^User-Agent:.*xmlrpclib"))
  676. set_reply_close();
  677. set_reply_no_connect(); # optional
  678. dispatch_rpc();
  679. }
  680. ]]>
  681. </programlisting>
  682. </example>
  683. </para>
  684. <para>
  685. Another common problem is CRLF handling. According to the xml spec
  686. CR ('\r') must be escaped (to &amp;#xD;) or they will be "normalized"
  687. when parsing the xml document. However some xmlrpc clients do not
  688. follow this rule (e.g. clients based on the python or php xmlrpclib)
  689. and send CRLF unescaped. A possible workaround is to enable
  690. automatic LFLF to CRLF conversion (using the
  691. <varname>double_lf_to_crlf</varname> modules parameter) and replace
  692. CRLF with LFLF in the client queries.
  693. </para>
  694. </section>
  695. </section>
  696. <section id="xmlrpc.client_examples">
  697. <title>Client Examples</title>
  698. <!-- TODO:
  699. implement clients in various languages
  700. - pros, cons
  701. - How failures
  702. are mapped to XMLRPC
  703. - How success replies are mapped
  704. - How data
  705. types of the API are mapped to XMLRPC elements
  706. - 200 OK with no
  707. data transformed to one value - True
  708. -->
  709. <para>
  710. <itemizedlist>
  711. <listitem><para>
  712. <ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules/xmlrpc/examples/xmlrpc_test.pl'>
  713. <emphasis>examples/xmlrpc_test.pl</emphasis>
  714. </ulink> (basic perl application that builds and sends an
  715. <emphasis>XMLRPC</emphasis> request from its commandline
  716. parameters).
  717. </para></listitem>
  718. <listitem><para>
  719. <ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=sip-router;a=blob;f=modules/xmlrpc/examples/xmlrpc_test.py'>
  720. <emphasis>examples/xmlrpc_test.py</emphasis>
  721. </ulink> (basic python application that builds and sends an
  722. <emphasis>XMLRPC</emphasis> request from its commandline
  723. parameters).
  724. </para></listitem>
  725. <listitem><para>
  726. <ulink url='http://git.sip-router.org/cgi-bin/gitweb.cgi?p=ser;a=tree;f=ser_ctl'>
  727. <emphasis>ser_ctl</emphasis>
  728. </ulink>
  729. (complex python application that
  730. uses the <emphasis>XML-RPC</emphasis> interface implemented by the
  731. <emphasis>xmlrpc</emphasis> module).
  732. </para></listitem>
  733. <listitem><para>
  734. <ulink uri='http://www.iptel.org/serweb'>
  735. <emphasis>serweb</emphasis>
  736. </ulink>
  737. (php application that can use
  738. the <emphasis>XML-RPC</emphasis> interface to call ser
  739. functions).
  740. </para></listitem>
  741. </itemizedlist>
  742. </para>
  743. </section>
  744. <xi:include href="xmlrpc_admin.xml"/>
  745. </book>