xmlrpc.xml 25 KB

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