xcap.xml 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458
  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><title>XCAP</title>
  5. <section><title>Introduction</title>
  6. <para>XCAP is a HTTP based protocol for access remote configuration data. Data
  7. is stored in XML format and the XCAP protocol allows to query, modify or delete
  8. parts of such data. This is in detail described in <xref
  9. linkend="pres_rfc_xcap"/>. The XCAP server is server able to handle XCAP requests.
  10. </para>
  11. <para>The XCAP server may be used for storing <quote>presence interesting</quote>
  12. data. From the SIP_ROUTER's point of view these items are interesting:
  13. <itemizedlist>
  14. <listitem><para>authorization data</para></listitem>
  15. <listitem><para><quote>buddy lists</quote></para></listitem>
  16. </itemizedlist>
  17. </para>
  18. <section><title>XCAP authorization</title>
  19. <para>Definition of authorization documents and theirs usage is specified in <xref
  20. linkend="pres_draft_common_auth"/> and especially for presence purposes in <xref
  21. linkend="pres_draft_auth"/>. Both documents are quite common and in SIP_ROUTER's
  22. presence modules implemented only partialy. For more information about XCAP
  23. authorization see details in <xref linkend="pa.xcap"/>.</para>
  24. </section> <!-- XCAP authorization -->
  25. <section><title>Buddy lists</title>
  26. <para>XCAP server may be used for storing lists of users too. These lists may be
  27. used for presence subscriptions - subscription to such list means subscription
  28. to all users on it at once. This reduces number of created subscriptions and may
  29. reduce data transfers between server and client too; but presence documents for
  30. lists of users may be very big and thus require TCP connection.</para>
  31. <para>There may be not only lists for individual users with their contacts but
  32. there may be other sort of lists representing some <quote>logical
  33. entities</quote> such <quote>businessmen</quote>, <quote>technical
  34. support</quote>, ... which are used in cases like if some customer needs someone
  35. from technical support department and doesn't want to remeber all people
  36. there. Such customer may simply watch presence state of
  37. <quote>[email protected]</quote> if he needs help from them.
  38. </para>
  39. <para>Lists of users - more common resource lists - are defined in <xref
  40. linkend="pres_draft_rls"/> and their usage with SIP in <xref
  41. linkend="pres_draft_rls_sip"/>. These lists are partialy implemented in <link
  42. linkend="pres_rls">RLS module</link>.
  43. For more information about resource lists see details in <xref
  44. linkend="rls.xcap"/>.</para>
  45. </section> <!-- buddy lists -->
  46. <section><title>Manipulation with XCAP documents</title>
  47. <para>Manipulating with XCAP documents is quite simple because XCAP uses
  48. standard HTTP methods like GET, PUT or DELETE. Every web browser may be
  49. used to read XCAP data and it is quite simple to write utility to write data
  50. to XCAP server. These features allow to use XCAP with SIP_ROUTER although there are is
  51. not much client software supporting it.
  52. </para>
  53. </section> <!-- manipulating documents -->
  54. </section> <!-- XCAP introduction -->
  55. <section id="xcap.examples"><title>XCAP examples</title>
  56. <note><para>XCAP documents examples published there doesn't use correct XML
  57. namespaces due to problems with XCAP server used for tests (problems querying
  58. partial documents with namespaces).</para></note>
  59. <example><title>Storing XCAP documents</title>
  60. <para>There is a sample script in Python which stores XCAP documents onto a XCAP
  61. server. Documents are:
  62. <itemizedlist>
  63. <listitem><para><link linkend="rls.xml">rls-services document</link> stored
  64. under name <filename>index</filename>
  65. </para></listitem>
  66. <listitem><para><link linkend="list.xml">buddy list</link> for user Smith
  67. stored under name <filename>smith</filename></para></listitem>
  68. <listitem><para><link linkend="pres-rules.xml">presence authorization
  69. document</link> for user Smith stored under name
  70. <filename>presence-rules.xml</filename></para></listitem>
  71. </itemizedlist>
  72. </para>
  73. <programlisting>
  74. #!/usr/bin/python
  75. import httplib, urllib
  76. machine = "localhost"
  77. #
  78. # store rls-services document
  79. #
  80. uri = "/xcap-root/rls-services/global/index"
  81. headers = {"Content-Type": "application/rls-services+xml"}
  82. bf = file("rls.xml", "r")
  83. body = bf.read(65536);
  84. conn = httplib.HTTPConnection(machine)
  85. conn.request("PUT", uri, body, headers)
  86. response = conn.getresponse()
  87. print "Storing rls-services document: ", response.status, response.reason
  88. data = response.read()
  89. conn.close()
  90. #
  91. # store resource-list document for user
  92. #
  93. uri = "/xcap-root/resource-lists/users/smith/resource-list.xml"
  94. headers = {"Content-Type": "application/resource-lists+xml"}
  95. bf = file("list.xml", "r")
  96. body = bf.read(65536);
  97. conn = httplib.HTTPConnection(machine)
  98. conn.request("PUT", uri, body, headers)
  99. response = conn.getresponse()
  100. print "Storing resource-lists document: ", response.status, response.reason
  101. data = response.read()
  102. conn.close()
  103. #
  104. # store presence authorization rules
  105. #
  106. uri = "/xcap-root/pres-rules/users/smith/presence-rules.xml"
  107. headers = {"Content-Type": "application/pres-rules+xml"}
  108. bf = file("presence-rules.xml", "r")
  109. body = bf.read(65536);
  110. conn = httplib.HTTPConnection(machine)
  111. conn.request("PUT", uri, body, headers)
  112. response = conn.getresponse()
  113. print "Storing pres-rules document: ", response.status, response.reason
  114. data = response.read()
  115. conn.close()
  116. </programlisting>
  117. </example>
  118. <example id="list.xml"><title>Example resource list document (list.xml)</title>
  119. <para>Simple buddy lists which shows the possibility of nested lists.
  120. </para>
  121. <programlisting>
  122. &lt;?xml version="1.0" ?&gt;
  123. &lt;resource-lists&gt;
  124. &lt;list name="default"&gt;
  125. &lt;list name="work"&gt;
  126. &lt;entry uri="sip:[email protected]"&gt;
  127. &lt;display-name&gt;Someone&lt;/display-name&gt;
  128. &lt;/entry&gt;
  129. &lt;entry uri="sip:[email protected]"&gt;
  130. &lt;display-name&gt;Jonathan Smith&lt;/display-name&gt;
  131. &lt;/entry&gt;
  132. &lt;/list&gt;
  133. &lt;entry uri="sip:[email protected]"&gt;
  134. &lt;display-name&gt;Vasek&lt;/display-name&gt;
  135. &lt;/entry&gt;
  136. &lt;entry uri="sip:[email protected]"&gt;
  137. &lt;display-name&gt;Vaclav Picbumprask&lt;/display-name&gt;
  138. &lt;/entry&gt;
  139. &lt;/list&gt;
  140. &lt;/resource-lists&gt;
  141. </programlisting>
  142. </example>
  143. <example id="rls.xml"><title>Example rls-services document (rls.xml)</title>
  144. <para>Example document which is processed by Resource List Server (RLS module).
  145. This document can contain references to users buddy lists like
  146. <quote>[email protected]</quote> which points to buddy list for user smith
  147. named <quote>default</quote> and can contain such lists directly.
  148. <!--<caution><para>EyeBeam stores user's <quote>buddy list</quote> in
  149. <filename>&lt;XCAP-root&gt;/users/&lt;username&gt;/resource-list.xml</filename>,
  150. not in
  151. <filename>&lt;XCAP-root&gt;/users/&lt;username&gt;</filename> which was used in
  152. these examples.</para></caution>-->
  153. </para>
  154. <programlisting>
  155. &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  156. &lt;rls-services&gt;
  157. &lt;service uri="sip:[email protected]"&gt;
  158. &lt;resource-list&gt;http://localhost/xcap-root/resource-lists/users/smith/resource-list.xml/~~/resource-lists/list[@name=%22default%22]&lt;/resource-list&gt;
  159. &lt;packages&gt;
  160. &lt;package&gt;presence&lt;/package&gt;
  161. &lt;/packages&gt;
  162. &lt;/service&gt;
  163. &lt;service uri="sip:[email protected]"&gt;
  164. &lt;list name="czech part of some org"&gt;
  165. &lt;entry uri="sip:[email protected]"&gt;
  166. &lt;display-name&gt;A B&lt;/display-name&gt;
  167. &lt;/entry&gt;
  168. &lt;entry uri="sip:[email protected]"&gt;
  169. &lt;display-name&gt;C D&lt;/display-name&gt;
  170. &lt;/entry&gt;
  171. &lt;entry uri="sip:[email protected]"&gt;
  172. &lt;display-name&gt;Ef Ge&lt;/display-name&gt;
  173. &lt;/entry&gt;
  174. &lt;/list&gt;
  175. &lt;packages&gt;
  176. &lt;package&gt;presence&lt;/package&gt;
  177. &lt;package&gt;email&lt;/package&gt;
  178. &lt;/packages&gt;
  179. &lt;/service&gt;
  180. &lt;/rls-services&gt;
  181. </programlisting>
  182. </example>
  183. <example id="pres-rules.xml"><title>Example presence authorization document (presence-rules.xml)</title>
  184. <para>This document contains two rules:
  185. <itemizedlist>
  186. <listitem><para><quote>white list</quote>, which allows
  187. access to presence information from all from domain someorg.org
  188. </para></listitem>
  189. <listitem><para><quote>black list</quote>, which denies access for user
  190. [email protected]</para></listitem>
  191. </itemizedlist></para>
  192. <programlisting>
  193. &lt;?xml version="1.0" ?&gt;
  194. &lt;ruleset xmlns="urn:ietf:params:xml:ns:common-policy" xmlns:pr="urn:ietf:params:xml:ns:pres-rules"&gt;
  195. &lt;rule id="blacklist"&gt;
  196. &lt;conditions&gt;
  197. &lt;identity&gt;
  198. &lt;id&gt;sip:[email protected]&lt;/id&gt;
  199. &lt;/identity&gt;
  200. &lt;/conditions&gt;
  201. &lt;actions&gt;
  202. &lt;pr:sub-handling&gt;block&lt;/pr:sub-handling&gt;
  203. &lt;/actions&gt;
  204. &lt;transformations/&gt;
  205. &lt;/rule&gt;
  206. &lt;rule id="whitelist"&gt;
  207. &lt;conditions&gt;
  208. &lt;identity&gt;
  209. &lt;domain domain="someorg.org"/&gt;
  210. &lt;/identity&gt;
  211. &lt;/conditions&gt;
  212. &lt;actions&gt;
  213. &lt;pr:sub-handling&gt;allow&lt;/pr:sub-handling&gt;
  214. &lt;/actions&gt;
  215. &lt;transformations/&gt;
  216. &lt;/rule&gt;
  217. &lt;/ruleset&gt;
  218. </programlisting>
  219. </example>
  220. </section>
  221. <!-- There
  222. exist extensions for particular types of configuration - for purpose of this
  223. document only configuration from presence area will be mentioned.
  224. </para>-->
  225. <section><title>XCAP server simulation</title>
  226. <para>XCAP server is a HTTP server with some features like document validation
  227. or ability of working with parts of stored documents. If you have no XCAP
  228. server, you can simulate it using standard web server. There are not many XCAP
  229. servers available today, thus the simulation may be interesting for - at least -
  230. demonstration or testing purposes.
  231. </para>
  232. <para>There are some disadvantages when the XCAP server is only simulated:
  233. <itemizedlist>
  234. <listitem><para>no XML document validation</para></listitem>
  235. <listitem><para>unable to work with XPointer terms (mainly unable to work
  236. with parts of documents)</para></listitem>
  237. <listitem><para>possible synchronization problems (!)</para>
  238. <para>More clients used by one user working with the same document
  239. (authorization document, buddy list) may rewrite it to each other.
  240. When using regular XCAP server this will be done in one atomic query.
  241. In the case of simulation it is needed to download whole document,
  242. modify it and put it back.</para>
  243. </listitem>
  244. </itemizedlist>
  245. </para>
  246. <para>Depending on your needs you can
  247. <itemizedlist>
  248. <listitem><para>create hierarchical directory structure of XML documents according to
  249. <xref linkend="pres_rfc_xcap"/></para></listitem>
  250. <listitem><para>allow upload (handle HTTP PUT method) which stores documents into the
  251. directory structure</para></listitem>
  252. <listitem><para>improve upload to validate documents according to schema
  253. (every sort of XCAP document should have their XSD published)</para></listitem>
  254. <listitem><para>allow document removing (handle DELETE method)</para></listitem>
  255. <listitem><para>process HTTP GET requests with a CGI-script so it processes
  256. queries for partial documents</para></listitem>
  257. </itemizedlist>
  258. </para>
  259. <section><title>Directory structure</title>
  260. <para>Presence modules use XCAP documents stored in structure like this:
  261. <itemizedlist><title>xcap-root</title>
  262. <listitem><para><filename>pres-rules</filename></para>
  263. <itemizedlist>
  264. <listitem><para><filename>users</filename></para>
  265. <itemizedlist>
  266. <listitem><para><filename>smith</filename></para>
  267. <itemizedlist>
  268. <listitem><para><filename>presence-rules.xml</filename> (file
  269. containg presence authorization rules for user smith)</para></listitem>
  270. </itemizedlist>
  271. </listitem>
  272. <listitem><para><filename>joe</filename></para>
  273. <itemizedlist>
  274. <listitem><para><filename>presence-rules.xml</filename> (file containing
  275. presence authorization rules for user joe)</para></listitem>
  276. </itemizedlist>
  277. </listitem>
  278. <listitem><para>... (directories for other users)</para></listitem>
  279. </itemizedlist>
  280. </listitem>
  281. </itemizedlist></listitem>
  282. <listitem><para><filename>resource-lists</filename></para>
  283. <itemizedlist>
  284. <listitem><para><filename>users</filename></para>
  285. <itemizedlist>
  286. <listitem><para><filename>smith</filename></para>
  287. <itemizedlist>
  288. <listitem><para><filename>resource-list.xml</filename> (file
  289. containing resources lists for user smith)</para></listitem>
  290. </itemizedlist>
  291. </listitem>
  292. <listitem><para><filename>joe</filename></para>
  293. <itemizedlist>
  294. <listitem><para><filename>resource-list.xml</filename> (file
  295. containing resource lists for user joe)</para></listitem>
  296. </itemizedlist>
  297. </listitem>
  298. <listitem><para>... (directories for other users)</para></listitem>
  299. </itemizedlist>
  300. </listitem>
  301. <!-- rls-services globals used instead this
  302. <listitem><para><filename>global</filename></para>
  303. <itemizedlist>
  304. <listitem><para><filename>index</filename> (file containing global
  305. resource lists)</para></listitem>
  306. </itemizedlist>
  307. </listitem>-->
  308. </itemizedlist></listitem>
  309. <listitem><para><filename>rls-services</filename></para>
  310. <itemizedlist>
  311. <listitem><para><filename>global</filename></para>
  312. <itemizedlist>
  313. <listitem><para><filename>index</filename> (file containing global
  314. rls-services documents)</para></listitem>
  315. </itemizedlist>
  316. </listitem>
  317. </itemizedlist></listitem>
  318. </itemizedlist>
  319. </para>
  320. </section> <!-- directory structure -->
  321. <section><title>Usage with SIP_ROUTER</title>
  322. <para>You don't need a full XCAP server for presence authorization documents -
  323. these are read as standalone documents from directories of standalone users.
  324. </para>
  325. <para>For resource lists you have to set <link linkend="rls.parameters">RLS module
  326. parameters</link> <varname>mode</varname> and/or
  327. <varname>reduce_xcap_needs</varname>
  328. to work as much as possible with XCAP server simulation.
  329. </para>
  330. </section>
  331. <section><title>XCAP simulation examples</title>
  332. <para>Examples presented here can be used as simple XCAP server simulation. It
  333. is able to handle PUT method (for whole XML documents).
  334. </para>
  335. <example><title>Apache2 configuration</title>
  336. <programlisting><![CDATA[
  337. ...
  338. Alias /xcap-root /var/simulated-xcap-root
  339. <Directory /var/simulated-xcap-root>
  340. Options Indexes FollowSymLinks MultiViews
  341. Script PUT /cgi-bin/upload
  342. <Limit PUT DELETE GET>
  343. Order Allow,Deny
  344. Deny from none
  345. Allow from all
  346. </Limit>
  347. </Directory>
  348. ...
  349. ]]></programlisting>
  350. <para>If apache is running on machine with SIP_ROUTER, you can use as xcap-root
  351. <literal>http://localhost/xcap-root</literal>.
  352. </para>
  353. </example>
  354. <example><title>Simple (and dangerous) cgi-script for upload</title>
  355. <para>This code is written in C and it is able to create directories if needed, but its usage in
  356. presented form is realy unsafe! You have to compile it and put into directory
  357. with other CGI scripts.</para>
  358. <programlisting><![CDATA[
  359. #include <stdio.h>
  360. #include <stdlib.h>
  361. #include <string.h>
  362. #include <sys/stat.h>
  363. #include <sys/types.h>
  364. void copy_file(const char *filename)
  365. {
  366. char buf[2048];
  367. int r;
  368. FILE *f;
  369. f = fopen(filename, "wb");
  370. if (f) {
  371. while (!feof(stdin)) {
  372. r = fread(buf, 1, sizeof(buf), stdin);
  373. fwrite(buf, 1, r, f);
  374. }
  375. fclose(f);
  376. }
  377. }
  378. int main(int argc, char **argv)
  379. {
  380. char *filename, *x;
  381. char tmp[1024];
  382. int res = 0;
  383. filename = getenv ("PATH_TRANSLATED");
  384. strcpy(tmp, filename);
  385. x = strrchr(tmp, '/');
  386. if (x) {
  387. *x = 0;
  388. res = mkdir(tmp, 0755); /* ! dangerous ! */
  389. }
  390. else {
  391. printf("Status: 500\n");
  392. printf("Content-Type: text/html\n\n");
  393. printf("<html><head/>\n<body>Incorrect filename</body></html>\n");
  394. return -1;
  395. }
  396. copy_file(filename); /* ! dangerous ! */
  397. printf("Status: 200\n");
  398. printf("Content-Type: text/html\n\n");
  399. printf("<html><head><title>Upload</title>\n</head>\n<body>Finished...</body></html>\n");
  400. return 0;
  401. }
  402. ]]></programlisting>
  403. </example>
  404. </section><!-- XCAP simulation examples -->
  405. </section> <!-- XCAP server simulation -->
  406. </section>