/[drupal]/contributions/modules/xmpp_server/xmpp_handler/xmpp_handler.module
ViewVC logotype

Diff of /contributions/modules/xmpp_server/xmpp_handler/xmpp_handler.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Thu Sep 25 08:23:38 2008 UTC revision 1.3, Thu Sep 25 21:55:22 2008 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: xmpp_handler.module,v 1.1 2008/09/25 06:45:42 t0talmeltd0wn Exp $  // $Id: xmpp_handler.module,v 1.2 2008/09/25 08:23:38 t0talmeltd0wn Exp $
3    
4  /**  /**
5   * @file   * @file
6   * The implementation of the core XMPP stack.   * The implementation of the core XMPP stack.
7   *   *
  * Due to the complexity of the core XMPP protocol, the XMPP handler  
  * is split into multiple files. Thusly, to prevent functions like  
  * hook_xmpp_handler_xml() from becoming hundreds of lines long, they  
  * have been wrapped within separate function calls that are implemented  
  * within the files included in xmpp_handler_xmpp_server_start().  
  *  
8   * This file is primarilly responsible for including and delegating to   * This file is primarilly responsible for including and delegating to
9   * other files, which contain the actual implementation.   * other files, which contain the actual implementation.
10   */   */
# Line 74  function xmpp_handler_xmpp_server_protoc Line 68  function xmpp_handler_xmpp_server_protoc
68  function xmpp_handler_xmpp_server_xml() {  function xmpp_handler_xmpp_server_xml() {
69    $funcs = array();    $funcs = array();
70    
71      $funcs['xmpp_handler_router_message'] = array(
72        'authed' => TRUE,
73        'bound' => TRUE,
74        'tag' => 'message',
75        'options' => array(
76          'to' => '+',
77        ),
78      );
79    
80      $funcs['xmpp_handler_router_iq'] = array(
81        'authed' => TRUE,
82        'bound' => TRUE,
83        'tag' => 'iq',
84        'options' => array(
85          'to' => '+',
86        ),
87      );
88    
89      $funcs['xmpp_handler_router_directed_presence'] = array(
90        'authed' => TRUE,
91        'bound' => TRUE,
92        'tag' => 'presence',
93        'options' => array(
94          'type' => '?unavailable',
95          'to' => '+',
96        ),
97      );
98    
99      $funcs['xmpp_handler_router_presence'] = array(
100        'authed' => TRUE,
101        'bound' => TRUE,
102        'tag' => 'presence',
103        'options' => array(
104          'type' => '?unavailable',
105          'to' => '!',
106        ),
107      );
108    
109      $funcs['xmpp_handler_router_directed_presence'] = array(
110        'authed' => TRUE,
111        'bound' => TRUE,
112        'tag' => 'presence',
113        'options' => array(
114          'type' => '?unavailable',
115          'to' => '+',
116        ),
117      );
118    
119      $funcs['xmpp_handler_router_iq'] = array(
120        'authed' => TRUE,
121        'bound' => TRUE,
122        'tag' => 'iq',
123        'options' => array(
124          'to' => '+',
125        ),
126      );
127    
128    $funcs['xmpp_handler_stanza_ping'] = array(    $funcs['xmpp_handler_stanza_ping'] = array(
129      'tag' => 'iq',      'tag' => 'iq',
130      'protocol' => 'jabber:client',      'protocol' => 'jabber:client',
# Line 154  function xmpp_handler_stream_start($clie Line 205  function xmpp_handler_stream_start($clie
205    );    );
206  }  }
207    
208    function xmpp_handler_router_message($client, $node) {
209      $session = xmpp_server_get_session($client);
210      $node->options['from'] = xmpp_serialize_jid($session['jid']);
211    
212      module_invoke_all('xmpp_router_message', $client, $node);
213    
214      $to = xmpp_parse_jid($node->options['to']);
215      if (!$to['resource']) {
216        $to = xmpp_serialize_jid($to, true) . "/*";
217      }
218      else {
219        $to = xmpp_serialize_jid($to);
220      }
221      xmpp_server_send_to($to, 'jid', $node);
222    }
223    
224    function xmpp_handler_router_iq($client, $node) {
225      //Believe it or not, the implementation here is exactly the same.
226      xmpp_handler_router_message($client, $node);
227    }
228    
229    function xmpp_handler_router_directed_presence($client, $node) {
230      //Again, same thing.
231      xmpp_handler_router_message($client, $node);
232    }
233    
234    function xmpp_handler_router_presence($client, $node) {
235      $session = xmpp_server_get_session($client);
236      $session['presence'] = $node;
237      xmpp_server_save_session($session);
238    
239      module_invoke_all('xmpp_router_presence', $client, $node);
240    }
241    
242  /**  /**
243   * Handle the XMPP 'ping' extension.   * Handle the XMPP 'ping' extension.
244   */   */
# Line 167  function xmpp_handler_stanza_ping($clien Line 252  function xmpp_handler_stanza_ping($clien
252  }  }
253    
254  function xmpp_handler_disco_query($client, $node) {  function xmpp_handler_disco_query($client, $node) {
255    $resp = new XmlNode();    $ret = new XmlNode();
256    $ret->tag = 'iq';    $ret->tag = 'iq';
257    $ret->options['type'] = 'result';    $ret->options['type'] = 'result';
258    $ret->options['from'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']);    $ret->options['from'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']);
# Line 200  function xmpp_handler_disco_query($clien Line 285  function xmpp_handler_disco_query($clien
285  }  }
286    
287  function xmpp_handler_disco_items($client, $node) {  function xmpp_handler_disco_items($client, $node) {
288      $ret = new XmlNode();
289    $ret->tag = 'iq';    $ret->tag = 'iq';
290    $ret->options['type'] = 'result';    $ret->options['type'] = 'result';
291    $ret->options['from'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']);    $ret->options['from'] = variable_get('xmpp_server_host', $_SERVER['HTTP_HOST']);
# Line 222  function xmpp_handler_disco_items($clien Line 308  function xmpp_handler_disco_items($clien
308  }  }
309    
310  function xmpp_handler_tls($client, $node) {  function xmpp_handler_tls($client, $node) {
311      $proceed = new XmlNode();
312    $proceed->tag = 'proceed';    $proceed->tag = 'proceed';
313    $proceed->options = array('xmlns' => 'urn:ietf:params:xml:ns:xmpp-tls');    $proceed->options = array('xmlns' => 'urn:ietf:params:xml:ns:xmpp-tls');
314    
# Line 229  function xmpp_handler_tls($client, $node Line 316  function xmpp_handler_tls($client, $node
316    xmpp_server_encrypt($client);    xmpp_server_encrypt($client);
317    
318    if (!$client->ssl) {    if (!$client->ssl) {
319        $fail = new XmlNode();
320      $fail->tag = 'failure';      $fail->tag = 'failure';
321      $fail->options['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-tls';      $fail->options['xmlns'] = 'urn:ietf:params:xml:ns:xmpp-tls';
322      xmpp_server_send($client, $fail);      xmpp_server_send($client, $fail);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2