functions.xml 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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="pa.functions"><title>Functions</title>
  5. <variablelist>
  6. <varlistentry>
  7. <term><varname>handle_subscription(domain)</varname></term>
  8. <listitem>
  9. <para>This function processes SUBSCRIBE requests to "presence" and
  10. "presence.winfo" (see <link
  11. linkend="pa.param.watcherinfo_notify">watcherinfo_notify
  12. parameter</link>) events. </para>
  13. <para>Meaning of the parameters is as follows:</para>
  14. <itemizedlist>
  15. <listitem>
  16. <para><emphasis>domain</emphasis> - This can be either "registrar" or "jabber".
  17. </para>
  18. </listitem>
  19. </itemizedlist>
  20. <example>
  21. <title><function>handle_subscription</function> usage</title>
  22. <programlisting>
  23. ...
  24. handle_subscription("registrar");
  25. ...
  26. </programlisting>
  27. </example>
  28. </listitem>
  29. </varlistentry>
  30. <varlistentry>
  31. <term><varname>handle_publish(domain)</varname></term>
  32. <listitem><para>Processes PUBLISH request and generates response to it.
  33. </para></listitem>
  34. </varlistentry>
  35. <varlistentry>
  36. <term><varname>target_online(domain)</varname></term>
  37. <listitem><para>This function returns 1 if the target (using get_to_uid on
  38. current message) is online, -1 otherwise.
  39. </para>
  40. </listitem>
  41. </varlistentry>
  42. <varlistentry>
  43. <term><varname>check_subscription_status(status)</varname></term>
  44. <listitem><para>This function returns 1 if last subscription is in status
  45. given by parameter, -1 otherwise. The <parameter>status</parameter> can have
  46. values:
  47. <variablelist>
  48. <varlistentry>
  49. <term>pending</term>
  50. <listitem><para>Subscription was created but no status information will
  51. be sent to the watcher.</para></listitem>
  52. </varlistentry>
  53. <varlistentry>
  54. <term>active</term>
  55. <listitem><para>Subscription was established and all presence
  56. information will be sent to the watcher.</para></listitem>
  57. </varlistentry>
  58. <!-- <varlistentry>
  59. <term>rejected</term>
  60. <listitem><para>Subscription was not established due to authorization
  61. rules.</para></listitem>
  62. </varlistentry>-->
  63. <varlistentry>
  64. <term>terminated</term>
  65. <listitem><para>Subscription was terminated.</para></listitem>
  66. </varlistentry>
  67. </variablelist>
  68. </para>
  69. </listitem>
  70. </varlistentry>
  71. <varlistentry>
  72. <term><varname>store_winfo(domain)</varname></term>
  73. <listitem><para>This function stores data about currently created
  74. subscription into database for later dumping in the form of watcherinfo
  75. notification. It should be called after handle_subscription
  76. during processing SUBSCRIBE request.</para>
  77. </listitem>
  78. </varlistentry>
  79. <varlistentry>
  80. <term><varname>dump_stored_winfo(domain, event_package)</varname></term>
  81. <listitem><para>This function tries to send stored watcherinfo data
  82. in the context of existing watcherinfo subscription. It uses get_to_uid as
  83. target for notification. If there is no watcherinfo subscription to such
  84. presentity, no information is sent.</para>
  85. <para>If the client responds with 2xx on generated NOTIFY request, the
  86. stored information is removed from database.
  87. </para>
  88. <example><title><function>target_online</function>,
  89. <function>store_winfo</function>, <function>dump_stored_winfo</function> usage</title>
  90. <programlisting>
  91. ...
  92. if (method=="SUBSCRIBE") {
  93. if (!t_newtran()) {
  94. sl_reply_error();
  95. break;
  96. };
  97. if (handle_subscription("registrar")) {; # uses uid from AVP (get_to_uid)
  98. if (@msg.event=~"presence\.winfo") {
  99. log(1, "subscription to watcherinfo\n");
  100. dump_stored_winfo("registrar", "presence");
  101. log(1, "OFFLINE AUTH: watcherinfo dumped\n");
  102. }
  103. else {
  104. if ((@msg.event=~"presence") &amp;&amp; (check_subscription_status("pending"))) {
  105. log(1, "pending subscription to presence\n");
  106. # if offline user and new "pending" subscription
  107. if (!target_online("registrar") &amp;&amp; (@to.tag=="")) {
  108. log(1, "OFFLINE AUTH: storing for offline user\n");
  109. store_winfo("registrar");
  110. }
  111. }
  112. }
  113. }
  114. break;
  115. };
  116. ...
  117. </programlisting>
  118. </example>
  119. </listitem>
  120. </varlistentry>
  121. <varlistentry>
  122. <term><varname>authorize_message(filename)</varname></term>
  123. <listitem><para>This function reads and processes IM authorization data and
  124. returns 1 if message can be accepted by destination user. If there is no IM
  125. authorization document on given XCAP server, it returns 1 too (MESSAGE is
  126. enabled by default). If the sender is blocked by recipient rules, this
  127. function returns -1. For more details about authorization documents see
  128. <xref linkend="im_rules"/>.
  129. </para>
  130. <para>Filename parameter specifies the name of file on XCAP server which
  131. contains message authorization rules. It is <quote>im-rules.xml</quote> by
  132. default.
  133. </para>
  134. <example><title><function>authorize_message</function> usage</title>
  135. <programlisting>
  136. ...
  137. if (method=="MESSAGE") {
  138. if (authorize_message("im-rules.xml")) {
  139. if (!lookup("location")) {
  140. sl_reply("404", "Not Found");
  141. break;
  142. };
  143. if (!t_relay()) { sl_reply_error(); };
  144. }
  145. else {
  146. sl_reply("403", "Forbidden");
  147. }
  148. break;
  149. }
  150. ...
  151. </programlisting>
  152. </example>
  153. </listitem>
  154. </varlistentry>
  155. </variablelist>
  156. </section>