Dotclear

Changeset 343


Ignore:
Timestamp:
02/20/08 00:30:16 (16 years ago)
Author:
sacha
Message:

Jabber Notifications - *testing* SSL connection

PLEASE READ the comment #14 from
 http://bricole.xn--phnix-csa.net/post/Dotclear-Suivez-les-commentaires-sur-votre-blog-en-temps-reel-avec-Jabber

Location:
plugins/jabberNotifications
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • plugins/jabberNotifications/_public.php

    r291 r343  
    33 *  This is Jabber Notifications, a plugin for Dotclear 2      * 
    44 *                                                             * 
    5  *  Copyright (c) 2007                                         * 
     5 *  Copyright (c) 2007,2008                                    * 
    66 *  Oleksandr Syenchuk, Olivier Tétard and contributors.       * 
    77 *                                                             * 
     
    6969               'pass'=>$core->blog->settings->jn_pass, 
    7070               'port'=>$core->blog->settings->jn_port, 
     71               'con'=>$core->blog->settings->jn_con, 
    7172               'gateway'=>$core->blog->settings->jn_gateway 
    7273          ); 
    73           $j = new jabberNotifier($settings['serv'],$settings['port'],$settings['user'],$settings['pass']); 
     74          $j = new jabberNotifier($settings['serv'],$settings['port'],$settings['user'],$settings['pass'],$settings['con']); 
    7475           
    7576          $msg = html::decodeEntities(html::clean($cur->comment_content)); 
  • plugins/jabberNotifications/class.jabbernotifier.php

    r291 r343  
    33 *  This is Jabber Notifications, a plugin for Dotclear 2      * 
    44 *                                                             * 
    5  *  Copyright (c) 2007                                         * 
     5 *  Copyright (c) 2007,2008                                    * 
    66 *  Oleksandr Syenchuk, Olivier Tétard and contributors.       * 
    77 *                                                             * 
     
    2929     public $done = false; 
    3030      
    31      public function __construct($serv,$port,$user,$pass) 
     31     public function __construct($serv,$port,$user,$pass,$con) 
    3232     { 
    3333          $this->serv = $serv; 
     
    3636          $this->pass = $pass; 
    3737           
    38           $this->j = new Jabber(); 
     38          $this->j = new Jabber($serv,$port,$user,$pass,$con); 
    3939          $this->messages = array(); 
    4040          $this->status = 'init'; 
     
    6464          } 
    6565     } 
    66       
    6766      
    6867     public function commitThroughGateway($url) 
     
    9493          $this->status = 'ok'; # Will be changed on error 
    9594           
    96           if ($this->j->connect($this->serv,$this->port,$timeout)) { 
     95          if ($this->j->connect($timeout)) { 
    9796               $this->j->execute($timeout); 
    9897               if (!$this->done) { 
  • plugins/jabberNotifications/forms.php

    r291 r343  
    11<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 
    2  
    32/***************************************************************\ 
    43 *  This is Jabber Notifications, a plugin for Dotclear 2      * 
    54 *                                                             * 
    6  *  Copyright (c) 2007                                         * 
     5 *  Copyright (c) 2007,2008                                    * 
    76 *  Oleksandr Syenchuk, Olivier Tétard and contributors.       * 
    87 *                                                             * 
     
    4039     __('Enable Jabber notifications').'</label></p> 
    4140 
    42 <div id="jn_config"> 
     41<div id="jn_config" class="two-cols"> 
     42<div class="col"> 
    4343<p><label class="required">'.__('Username:').' '. 
    4444     form::field('jn_user',20,255,html::escapeHTML($jn_user)).'</label></p> 
     
    5151<p><label>'.__('HTTP gateway (leave empty to disable):').' '. 
    5252     form::field('jn_gateway',40,255,html::escapeHTML($jn_gateway)).'</label></p> 
     53</div> 
     54<p class="col">'.__('Secure connection:').'<br/>'. 
     55     form::radio(array('jn_con','jn_con1'),'',$jn_con == ''). 
     56     '<label class="classic" for="jn_con1"> '.__('None').'</label><br/>'. 
     57     form::radio(array('jn_con','jn_con2'),'ssl://',$jn_con == 'ssl://'). 
     58     '<label class="classic" for="jn_con2"> '.__('SSL').'</label><br/>'. 
     59     form::radio(array('jn_con','jn_con3'),'tls://',$jn_con == 'tls://'). 
     60     '<label class="classic" for="jn_con3"> '.__('TLS').'</label><br/>'. 
     61'</p><br class="clear" /> 
    5362</div> 
    5463<p><input type="submit" name="jn_action_config" value="'.__('save').'" />'. 
     
    6574$jn_forms['help'] = ' 
    6675<h3>Passerelle HTTP</h3> 
    67 <p>Certains hébérgeurs (comme Free.fr) n\'autorisent pas les connexions sur le port 5222 utilisé par les serveurs Jabber. Pour contourner ce problème, vous pouvez utiliser une passerelle HTTP.</p> 
     76<p>Certains hébergeurs (comme Free.fr) n\'autorisent pas les connexions sur le port 5222 qui est utilisé par les serveurs Jabber. Pour contourner ce problème, vous pouvez utiliser une passerelle HTTP.</p> 
    6877<p>La passerelle HTTP permet d\'envoyer les notifications Jabber à une page web (accessible généralement sur le port 80) qui se charge de la connexion XMPP pour vous.</p> 
    6978<h4>Considérations de sécurité</h4> 
  • plugins/jabberNotifications/index.php

    r292 r343  
    11<?php /* -*- tab-width: 5; indent-tabs-mode: t; c-basic-offset: 5 -*- */ 
    2  
    32/***************************************************************\ 
    43 *  This is Jabber Notifications, a plugin for Dotclear 2      * 
    54 *                                                             * 
    6  *  Copyright (c) 2007                                         * 
     5 *  Copyright (c) 2007,2008                                    * 
    76 *  Oleksandr Syenchuk, Olivier Tétard and contributors.       * 
    87 *                                                             * 
     
    2928 
    3029     // Vérification de l'installation 
    31      if ($core->blog->settings->jn_enab === null) 
    32      { 
    33           $core->blog->settings->put('jn_serv','','string','Server',true,true); 
     30     if ($core->blog->settings->jn_enab === null || isset($_GET['reset'])) 
     31     { 
     32          $core->blog->settings->put('jn_serv','','string','Host',true,true); 
    3433          $core->blog->settings->put('jn_port',5222,'integer','Port',true,true); 
     34          $core->blog->settings->put('jn_con','','string','Secure connection protocol',true,true); 
    3535          $core->blog->settings->put('jn_user','','string','Username used to connect to the jabber server',true,true); 
    3636          $core->blog->settings->put('jn_pass','','string','Password used to connect to the jabber server',true,true); 
     
    4848          $jn_serv = $core->blog->settings->jn_serv; 
    4949          $jn_port = $core->blog->settings->jn_port; 
     50          $jn_con = $core->blog->settings->jn_con; 
    5051          $jn_gateway = $core->blog->settings->jn_gateway; 
    5152          $jn_dest = ''; 
     
    6869               $jn_serv = $_POST['jn_serv']; 
    6970               $jn_port = $_POST['jn_port']; 
     71               $jn_con = $_POST['jn_con']; 
    7072               $jn_gateway = $_POST['jn_gateway']; 
    7173               $jn_dest = $_POST['jn_dest']; 
     
    103105                    $core->blog->settings->put('jn_serv',$jn_serv,null,null,true,true); 
    104106                    $core->blog->settings->put('jn_port',$jn_port,null,null,true,true); 
     107                    $core->blog->settings->put('jn_con',$jn_con,null,null,true,true); 
    105108                    $core->blog->settings->put('jn_enab',true,null,null,true,true); 
    106109                    $core->blog->settings->put('jn_gateway',$jn_gateway,'string','HTTP Gateway',true); 
     
    114117     elseif (isset($_POST['jn_action_test'])) { 
    115118          $time = microtime(true); 
    116           $j = new jabberNotifier($jn_serv,$jn_port,$jn_user,$jn_pass); 
     119          $j = new jabberNotifier($jn_serv,$jn_port,$jn_user,$jn_pass,$jn_con); 
    117120          $j->setMessage('Jabber Notifications test. UNIX timestamp is '.time().' s.'); 
    118121          $j->addDestination(explode(',',$jn_dest)); 
  • plugins/jabberNotifications/lib/class_ConnectionSocket.php

    r271 r343  
    5858     public $socket = null; 
    5959     public $error = ''; 
     60     public $debug = false; 
    6061      
    6162     function socket_open($hostname,$port,$timeout) 
     
    7980     function socket_write($data) 
    8081     { 
     82          if ($this->debug) { 
     83               echo '=> '.$data."\n"; 
     84          } 
    8185          return fwrite($this->socket,$data); 
    8286     } 
     
    8791          $buffer = fread($this->socket,$byte_count); 
    8892          set_magic_quotes_runtime(get_magic_quotes_runtime()); 
    89  
     93          if ($this->debug && $buffer) { 
     94               echo '<= '.$buffer."\n"; 
     95          } 
    9096          return $buffer; 
    9197     } 
  • plugins/jabberNotifications/lib/class_Jabber.php

    r291 r343  
    11<?php 
    2 /* Jabber Client Library 
    3  * Version 0.8 
     2/***************************************************************\ 
     3 *  This is JabberMessage                                      * 
     4 *                                                             * 
     5 *  Copyright (c) 2008                                         * 
     6 *  Oleksandr Syenchuk                                         * 
     7 *                                                             * 
     8 *  This is an open source software, distributed under the GNU * 
     9 *  General Public License (version 2) terms and  conditions.  * 
     10 *                                                             * 
     11 *  You should have received a copy of the GNU General Public  * 
     12 *  License along JabberMessage (see COPYING.txt);             * 
     13 *  if not, write to the Free Software Foundation, Inc.,       * 
     14 *  59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    * 
     15\***************************************************************/ 
     16 
     17/* JabberMessage is based on 'Jabber Client Library', Version 0.8 
    418 * Copyright 2002-2005, eSite Media Inc. 
    519 * Portions Copyright 2002, Carlo Zottmann 
    620 * http://www.centova.com 
    7  * ============================================================================ 
    8  * 
    9  * This file was contributed (in part or whole) by a third party, and is 
    10  * released under the GNU LGPL.  Please see the CREDITS and LICENSE sections 
    11  * below for details. 
    12  *  
    13  ***************************************************************************** 
    14  * 
    15  * DETAILS 
    16  * 
    17  * This is an event-driven Jabber client class implementation.  This library 
    18  * allows PHP scripts to connect to and communicate with Jabber servers. 
    19  * 
    20  * 
    21  * CREDITS & COPYRIGHTS 
    22  * 
    23  * This class was originally based on Class.Jabber.PHP v0.4 (Copyright 2002, 
    24  * Carlo "Gossip" Zottmann). 
    25  * 
    26  * The code for this class has since been nearly completely rewritten by Steve 
    27  * Blinch for eSite Media Inc.  All such modified code is Copyright 2002-2005,  
    28  * eSite Media Inc. 
    29  * 
    30  * The original Class.Jabber.PHP was released under the GNU General Public 
    31  * License (GPL); however, we have received written permission from the 
    32  * original author and copyright holder, Carlo Zottmann, to relicense our 
    33  * version of this class and release it under the GNU Lesser General Public 
    34  * License (LGPL).  This allows compatibility with Centova's 
    35  * proprietary software license. 
    36  * 
    37  * 
    38  * LICENSE 
    39  * 
    40  * class_Jabber.php - Jabber Client Library 
    41  * Copyright (C) 2002-2005, eSite Media Inc. 
    42  * Copyright (C) 2002, Carlo Zottmann 
    43  * 
    44  * This library is free software; you can redistribute it and/or modify it 
    45  * under the terms of the GNU Lesser General Public License as published by the 
    46  * Free Software Foundation; either version 2.1 of the License, or (at your 
    47  * option) any later version. 
    48  *  
    49  * This library is distributed in the hope that it will be useful, but WITHOUT 
    50  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
    51  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
    52  * for more details. 
    53  * 
    54  * You should have received a copy of the GNU Lesser General Public License 
    55  * along with this library; if not, write to the Free Software Foundation, 
    56  * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
    57  * 
    58  * 
    59  * JABBER is a registered trademark of Jabber Inc. 
    60  * 
    6121 */ 
    6222 
     
    6626class Jabber 
    6727{ 
    68      public $jid = ''; 
    6928     public $use_msg_composing = true; 
    7029     public $use_msg_delivered = false; 
     
    11978     public $protocol_version = false; // set this to an XMPP protocol revision to include it in the <stream:stream> tag 
    12079      
    121      public function __construct() 
     80     private $host; 
     81     private $port; 
     82     private $jid; 
     83     private $password; 
     84      
     85     private $username; 
     86     private $server; 
     87     private $con; 
     88      
     89     public function __construct($host,$port,$jid,$password,$con='') 
    12290     { 
    12391          $this->_unique_counter = 0; 
    124            
    12592          $this->xml = new XMLParser(); 
     93           
     94          $this->host = $host; 
     95          $this->port = (int) $port; 
     96          $this->password = $password; 
     97           
     98          $pos = strpos($jid,'@'); 
     99          if ($pos === false) { 
     100               $this->jid = $jid.'@'.$this->host; 
     101               $this->server = $host; 
     102               $this->username = $jid; 
     103          } 
     104          else { 
     105               $this->jid = $jid; 
     106               $this->server = substr($jid,$pos+1); 
     107               $this->username = substr($jid,0,$pos); 
     108          } 
     109           
     110          if ($con !== '' && $con !== 'ssl://' && $con !== 'tls://') { 
     111               $con = ''; 
     112          } 
     113          $this->con = $con; 
    126114     } 
    127115 
     
    207195     //    
    208196     // 
    209      function connect($server_host,$server_port=5222,$connect_timeout=null,$alternate_ip=false) { 
    210            
    211           if (is_null($connect_timeout)) $connect_timeout = 4; 
     197     function connect($con_timeout=4,$alternate_ip=false) 
     198     { 
    212199          $connector = $this->_connector; 
    213200           
    214201          $this->_connection = new $connector(); 
    215           $this->_server_host = $server_host; 
    216           $this->_server_port = $server_port; 
    217           $this->_server_ip = $alternate_ip ? $alternate_ip : $server_host; 
    218           $this->_connect_timeout = $connect_timeout; 
     202          $this->_server_host = $this->host; 
     203          $this->_server_port = $this->port; 
     204          $this->_server_ip = $alternate_ip ? $alternate_ip : $this->host; 
     205          $this->_connect_timeout = (int) $con_timeout; 
    219206           
    220207          $this->roster = array(); 
     
    228215      
    229216     function _connect_socket() { 
    230           if ($this->_connection->socket_open($this->_server_ip,$this->_server_port,$this->_connect_timeout)) { 
     217          if ($this->_connection->socket_open($this->con.$this->_server_ip,$this->_server_port,$this->_connect_timeout)) { 
    231218               $this->_send("<?xml version='1.0' encoding='UTF-8' ?" . ">\n"); 
    232219                
    233220               $xmpp_version = ($this->protocol_version) ? " version='{$this->protocol_version}'" : ''; 
    234221                
    235                $this->_send("<stream:stream to='{$this->_server_host}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'{$xmpp_version}>\n"); 
     222               $this->_send("<stream:stream to='{$this->server}' xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams'{$xmpp_version}>\n"); 
    236223               return true; 
    237224          } else { 
     
    263250           
    264251          // prepare our shiny new JID 
    265           $this->_username = $username; 
     252          $this->_username = $this->username; 
    266253          $this->_password = $password; 
    267254          $this->_resource = $resource; 
     
    622609     // handle Stream packets 
    623610     function _handle_stream(&$packet) { 
    624           if ($packet["stream:stream"]['@']['from'] == $this->_server_host 
     611          if ($packet["stream:stream"]['@']['from'] == $this->server 
    625612               && $packet["stream:stream"]['@']['xmlns'] == "jabber:client" 
    626613               && $packet["stream:stream"]['@']["xmlns:stream"] == "http://etherx.jabber.org/streams") 
     
    650637     { 
    651638          $auth_id = $packet['iq']['@']['id']; 
    652           $this->_sendauth_digest($auth_id); 
     639           
     640          /* 
     641          if (isset($packet['iq']['#']['query'][0]['#']['digest'])) { 
     642               $this->_sendauth_digest($auth_id); 
     643          } 
     644          elseif (isset($packet['iq']['#']['query'][0]['#']['password'])) { 
     645               $this->_sendauth_plaintext($auth_id); 
     646          } 
     647          else { 
     648          // 
     649               //echo "===\n";var_dump($packet);echo "\n"; 
     650               $this->_sendauth_digest($auth_id); 
     651          //} 
     652          //*/ 
     653          //$this->_sendauth_digest($auth_id); 
     654          $this->_sendauth_plaintext($auth_id); 
    653655          $this->_set_iq_handler("_on_authentication_result",$auth_id); 
    654656     } 
     
    812814          return true; 
    813815     } 
    814       
    815      // receives the results of a roster query 
    816      // 
    817      // Note: You should always browse services BEFORE calling get_roster(), as this 
    818      // will ensure that the correct services get marked as "registered" in $this->services, 
    819      // and each roster contact will automatically have its "transport" element set to the 
    820      // correct transport. 
    821      function _on_roster_result(&$packet) { 
    822           $packet_type = $packet['iq']['@']['type']; 
    823  
    824           // did we get a result?  if so, process it, and remember the service list   
    825           if (($packet_type=="result") || ($packet_type=="set")) { 
    826                 
    827                $roster_updated = false; 
    828  
    829                $itemlist = &$packet['iq']['#']['query'][0]['#']['item']; 
    830                $number_of_contacts = is_array($itemlist) ? count($itemlist) : 0; 
    831                 
    832                for ($a = 0; $a < $number_of_contacts; $a++) 
    833                { 
    834                     $queryitem = &$itemlist[$a]; 
    835                     $jid = strtolower($queryitem['@']['jid']); 
    836                      
    837                     $subscription = $queryitem['@']['subscription']; 
    838                      
    839                      
    840                     list($u_username,$u_domain,$u_resource) = $this->_split_jid($jid); 
    841                     $jid = ($u_username?"{$u_username}@":"").$u_domain; 
    842                      
    843                      
    844                     $is_new = !isset($this->roster[$jid]); 
    845                      
    846                      
    847                     // Is it a transport? 
    848                     $is_service = (!strlen($u_username));  
    849                     if ($is_service) { 
    850                          // are we registered with it? 
    851                          /*if ($u_resource=="registered") {*/ 
    852                               if (!in_array($subscription,array("none","remove"))) { // if we're not subscribed to it, then we'll consider it unregistered 
    853                                    $this->services[$jid]["registered"] = true; 
    854                               } 
    855                          /*}*/ 
    856                     } 
    857                 
    858                     // don't add the entry to the roster if it's a service, and we've been 
    859                     // configured to handle service presence internally (via $this->services) 
    860                     if (!($is_service && $this->handle_services_internally)) { 
    861                          // if not new, don't clobber the old presence/availability 
    862                          $u_jid = $u_username."@".$u_domain; 
    863                          $status = $is_new?"Offline":$this->roster[$jid]["status"]; 
    864                          $show = $is_new?"off":$this->roster[$jid]["show"]; 
    865                           
    866                          // if presence was received before roster, grab the show value from the presence 
    867                          if ($this->presence_cache[$u_jid]) { 
    868                               if (!$show || $is_new) { 
    869                                    $show = $this->presence_cache[$u_jid]["show"]; 
    870                               } 
    871                               if (!$status || $is_new) { 
    872                                    $status = $this->presence_cache[$u_jid]["status"]; 
    873                               } 
    874       
    875                               // remove any cached presence info, as the roster item now exists 
    876                               unset($this->presence_cache[$u_jid]); 
    877                          } 
    878                           
    879                          $rostername = $queryitem['@']['name'] ? $queryitem['@']['name'] : $rostername = $u_username; 
    880                           
    881                                          
    882                          // prepare the roster item 
    883                          $rosteritem = array( 
    884                                                             "name"              => $rostername, 
    885                                                             "subscription" => $queryitem['@']['subscription'], 
    886                                                             "ask"               => $queryitem['@']['ask'], 
    887                                                             "group"             => $queryitem['#']['group'][0]['#'], 
    888                                                             "status"       => $status, 
    889                                                             "show"              => $show, 
    890                                                             "username"          => $u_username, 
    891                                                             "domain"       => $u_domain, 
    892                                                             "resource"          => $u_resource, 
    893                                                             "jid"               => $u_jid, 
    894                                                             "transport"         => $this->get_transport($u_domain) 
    895                                                        ); 
    896                          if ($is_new) { 
    897                               // if it's a new entry, just add it to the roster 
    898                               $this->roster[$jid] = $rosteritem; 
    899                          } else { 
    900                               // otherwise, carefully update the existing entry, preserving 
    901                               // any elements that may have been added externally 
    902                               foreach ($rosteritem as $k=>$v) { 
    903                                    $this->roster[$jid][$k] = $v; 
    904                               } 
    905                          } 
    906                           
    907                          // you may wish to set roster_single_update to TRUE before 
    908                          // calling your initial browse(); this will allow you to 
    909                          // initialize your entire roster in one swoop, rather than 
    910                          // doing it contact-by-contact 
    911                          if ($this->roster_single_update) { 
    912                               $roster_updated = true; 
    913                          } 
    914                          else { 
    915                               $this->_call_handler("rosterupdate",$jid,$is_new); 
    916                          } 
    917                     } 
    918                } 
    919                 
    920                if ($this->roster_single_update && $roster_updated) { 
    921                     $this->_call_handler("rosterupdate",NULL,false); 
    922                } 
    923  
    924           // choke on error 
    925           } 
    926           elseif ($packet_type=="error") { 
    927                $this->_handle_iq_error($packet); 
    928                 
    929           // confusion sets in 
    930           } 
    931      } 
    932       
    933      // receives the results of an account registration 'get' query (retrieving fields) 
    934      function _on_register_get_result(&$packet) { 
    935           $packet_type = $packet['iq']['@']['type']; 
    936           $reg_id   = $this->_unique_id("reg"); 
    937  
    938           if ($packet_type=="result") { 
    939  
    940                if (isset($packet['iq']['#']['query'][0]['#']['registered'][0]['#'])) { 
    941                     $this->_call_handler("regfailure",-1,"Username already registered",""); 
    942                     return; 
    943                }  
    944       
    945                $key = $packet['iq']['#']['query'][0]['#']['key'][0]['#']; 
    946                unset($packet); 
    947       
    948                // Looks like CJP just hardcoded these fields, regardless of what the server sends...?! 
    949                // FIXME: parse fields dynamically this when time permits 
    950                $payload = "<username>{$this->_username}</username> 
    951           <password>{$this->_password}</password> 
    952           <email>{$this->_reg_email}</email> 
    953           <name>{$this->_reg_name}</name>\n"; 
    954            
    955                $payload .= ($key) ? "<key>$key</key>\n" : ''; 
    956       
    957                $this->_set_iq_handler("_on_register_set_result",$reg_id); 
    958                $this->_send_iq($this->_server_host, 'set', $reg_id, "jabber:iq:register", $payload); 
    959            
    960            
    961           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    962                $this->_handle_iq_error(&$packet,"regfailure"); 
    963            
    964           } else { 
    965                $this->_call_handler("regfailure",-2,"Unrecognized response from server",""); 
    966           } 
    967      } 
    968       
    969      // receives the results of an account registration 'set' query (the actual result of 
    970      // the account registration attempt) 
    971      function _on_register_set_result(&$packet) { 
    972           $packet_type = $packet['iq']['@']['type']; 
    973           $error_code = 0; 
    974            
    975           if ($packet_type=="result") { 
    976  
    977                if ($this->_resource) { 
    978                     $this->jid = "{$this->_username}@{$this->_server_host}/{$this->_resource}"; 
    979                } else { 
    980                     $this->jid = "{$this->_username}@{$this->_server_host}"; 
    981                } 
    982                $this->_call_handler("registered",$this->jid); 
    983                 
    984           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    985                // "conflict" error, i.e. already registered 
    986                if ($packet['iq']['#']['error'][0]['@']['code'] == '409') { 
    987                     $this->_call_handler("regfailure",-1,"Username already registered",""); 
    988                } else { 
    989                     $this->_handle_iq_error(&$packet,"regfailure"); 
    990                } 
    991  
    992           } else { 
    993                $this->_call_handler("regfailure",-2,"Unrecognized response from server"); 
    994           } 
    995      } 
    996       
    997      function _on_deregister_result(&$packet) { 
    998  
    999           $packet_type = $packet['iq']['@']['type']; 
    1000            
    1001           if ($packet_type=="result") { 
    1002                $this->_call_handler("deregistered",$this->jid); 
    1003           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1004                $this->_handle_iq_error(&$packet,"deregfailure"); 
    1005           } else { 
    1006                $this->_call_handler("deregfailure",-2,"Unrecognized response from server"); 
    1007           }          
    1008      } 
    1009       
    1010  
    1011      // receives the result of a password change   
    1012      function _on_chgpassword_result(&$packet) { 
    1013           $packet_type = $packet['iq']['@']['type']; 
    1014           if ($packet_type=="result") { 
    1015                $this->_call_handler("passwordchanged"); 
    1016                 
    1017           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1018                $this->_handle_iq_error(&$packet,"passwordfailure"); 
    1019           } else { 
    1020                $this->_call_handler("passwordfailure",-2,"Unrecognized response from server"); 
    1021           }                    
    1022      } 
    1023       
    1024      // receives the result of a service (transport) registration 
    1025      function _on_servicefields_result(&$packet) { 
    1026           $packet_type = $packet['iq']['@']['type']; 
    1027           $packet_id = $packet['iq']['@']['id']; 
    1028  
    1029           if ($packet_type=="result") { 
    1030                      
    1031                $reg_key = ""; 
    1032                $reg_instructions = ""; 
    1033                $reg_x = ""; 
    1034                $fields = array(); 
    1035                 
    1036                foreach ($packet['iq']['#']['query'][0]['#'] as $element => $data) { 
    1037                     switch($element) { 
    1038                          case "key": 
    1039                               $reg_key = $data[0]['#']; 
    1040                               break; 
    1041                          case "instructions": 
    1042                               $reg_instructions = $data[0]['#']; 
    1043                               break; 
    1044                          case "x": 
    1045                               $reg_x = $data[0]['#']; 
    1046                               break; 
    1047                          default: 
    1048                               $fields[] = $element; 
    1049                               break; 
    1050                     } 
    1051                } 
    1052                $this->_call_handler("servicefields",&$fields,$packet_id,$reg_key,$reg_instructions,&$reg_x); 
    1053                 
    1054           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1055                $this->_handle_iq_error(&$packet,"servicefieldsfailure"); 
    1056           } else { 
    1057                $this->_call_handler("servicefieldsfailure",-2,"Unrecognized response from server"); 
    1058           }                    
    1059      } 
    1060       
    1061      function _on_serviceregister_result(&$packet) { 
    1062           $packet_type = $packet['iq']['@']['type']; 
    1063           $from = $packet['iq']['@']['from']; 
    1064           if ($packet_type == 'result') { 
    1065                if (isset($packet['iq']['#']['query'][0]['#']['registered'][0]['#'])) { 
    1066                     $this->_call_handler("serviceregfailure",-1,"Already registered with service",""); 
    1067                } else { 
    1068                     $jid = $this->_bare_jid($from); 
    1069                     $this->_call_handler("serviceregistered",$from); 
    1070                } 
    1071           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1072                $this->_handle_iq_error(&$packet,"serviceregfailure"); 
    1073           } else { 
    1074                $this->_call_handler("serviceregfailure",-2,"Unrecognized response from server"); 
    1075           }                    
    1076      } 
    1077       
    1078      function _on_servicedereg_initial_result(&$packet) { 
    1079            
    1080           $packet_type = $packet['iq']['@']['type']; 
    1081           $from = $packet['iq']['@']['from']; 
    1082            
    1083           if ($packet_type == 'result') { 
    1084                 
    1085                // we're now deregistered with the transport, but we need to remove 
    1086                // our roster subscription 
    1087                $dereg_id = $this->_unique_id("svcdereg"); 
    1088                $this->_set_iq_handler("_on_servicedereg_final_result",$dereg_id); 
    1089  
    1090  
    1091                $this->services[$from]["registered"] = false; 
    1092                $this->services[$from]["subscription"] = "none"; 
    1093  
    1094                $payload = "<item jid='{$from}' subscription='remove'/>"; 
    1095       
    1096                if ($this->_send_iq(NULL, 'set', $dereg_id, "jabber:iq:roster", $payload)) { 
    1097  
    1098                     return $dereg_id; 
    1099                } 
    1100                else { 
    1101                     return false; 
    1102                }               
    1103                 
    1104           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1105                $this->_handle_iq_error(&$packet,"servicederegfailure"); 
    1106           } else { 
    1107                $this->_call_handler("servicederegfailure",-2,"Unrecognized response from server"); 
    1108           }                    
    1109      } 
    1110  
    1111      function _on_servicedereg_final_result(&$packet) 
    1112      { 
    1113           $packet_type = $packet['iq']['@']['type']; 
    1114           if ($packet_type == 'result') { 
    1115                $this->_call_handler("servicederegistered"); 
    1116           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1117                $this->_handle_iq_error(&$packet,"servicederegfailure"); 
    1118           } else { 
    1119                $this->_call_handler("servicederegfailure",-2,"Unrecognized response from server"); 
    1120           }                    
    1121      } 
    1122       
    1123      function _on_rosteradd_result(&$packet) { 
    1124           $packet_type = $packet['iq']['@']['type']; 
    1125           if ($packet_type == 'result') { 
    1126  
    1127                $this->_call_handler("rosteradded",$packet['iq']['@']['id']); 
    1128                 
    1129           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1130                $this->_handle_iq_error(&$packet,"rosteraddfailure"); 
    1131           } else { 
    1132                $this->_call_handler("rosteraddfailure",-2,"Unrecognized response from server"); 
    1133           }                    
    1134      } 
    1135  
    1136      function _on_rosterupdate_result(&$packet) { 
    1137           $packet_type = $packet['iq']['@']['type']; 
    1138           if ($packet_type == 'result') { 
    1139                $this->_call_handler("contactupdated",$packet['iq']['@']['id']); 
    1140                 
    1141           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1142                $this->_handle_iq_error(&$packet,"contactupdatefailure"); 
    1143           } else { 
    1144                $this->_call_handler("contactupdatefailure",-2,"Unrecognized response from server"); 
    1145           }                    
    1146      } 
    1147      function _on_rosterremove_result(&$packet) { 
    1148           $packet_type = $packet['iq']['@']['type']; 
    1149           if ($packet_type == 'result') { 
    1150                $this->_call_handler("rosterremoved",$packet['iq']['@']['id']); 
    1151                 
    1152           } elseif ($packet_type == 'error' && isset($packet['iq']['#']['error'][0]['#'])) { 
    1153                $this->_handle_iq_error(&$packet,"rosterremovefailure"); 
    1154           } else { 
    1155                $this->_call_handler("rosterremovefailure",-2,"Unrecognized response from server"); 
    1156           }                    
    1157      } 
     816 
    1158817      
    1159818     function _on_private_data(&$packet) { 
     
    1323982          $sleepfunc = $this->_sleep_func; 
    1324983 
    1325           $iterations = 0;  
     984          $iterations = 0; 
    1326985          do { 
    1327986               $line = $this->_connection->socket_read(16384); 
     
    1338997 
    1339998          if ($incoming != "") { 
    1340  
     999                
    13411000               $temp = $this->_split_incoming($incoming); 
    1342                 
    13431001               $packet_count = count($temp); 
    13441002 
    13451003               for ($a = 0; $a < $packet_count; $a++) { 
    13461004                    $this->_packet_queue[] = $this->xml->xmlize($temp[$a]); 
     1005                    //var_dump($this->xml->xmlize($temp[$a]));echo "\n---\n"; 
    13471006               } 
    13481007          } 
  • plugins/jabberNotifications/lib/class_XMLParser.php

    r271 r343  
    7676          $children = array(); 
    7777 
    78           if (!empty($vals[$i]['value'])) { 
     78          if (isset($vals[$i]['value'])) { 
    7979               array_push($children, trim($vals[$i]['value'])); 
    8080          } 
  • plugins/jabberNotifications/locales/fr/main.po

    r292 r343  
    11# French translation of Jabber Notification 
    2 # Copyright (c) 2007. 
    3 # Oleksandr Syenchuk <sacha@xn--phnix-csa.net>, 2007; 
     2# Copyright (c) 2007,2008. 
     3# Oleksandr Syenchuk <sacha@xn--phnix-csa.net>, 2008; 
    44# Olivier Tétard <toutoune25@free.fr>, 2007. 
    55 
  • plugins/jabberNotifications/test.php

    r291 r343  
    11<?php 
     2# Edit, than run this file from a shell ! 
     3# $ php test.php 
     4 
    25$t1 = microtime(true); 
    36 
    47include_once dirname(__FILE__).'/lib/class_Jabber.php'; 
    58 
    6 $serv = 'serv'; 
     9$host = 'host'; 
    710$port = 5222; 
    8 $user = 'user'; 
     11$con = 'ssl://'; # or '' or 'tls://' 
     12$user = 'user@server'; 
    913$pass = 'pass'; 
    1014$dest = 'dest@serv.tld'; 
     
    2125     private $messages; 
    2226      
    23      public function __construct($serv,$port,$user,$pass) 
     27     public function __construct($serv,$port,$user,$pass,$con='') 
    2428     { 
    2529          $this->serv = $serv; 
     
    2832          $this->pass = $pass; 
    2933           
    30           $this->j = new Jabber(); 
     34          $this->j = new Jabber($serv,$port,$user,$pass,$con); 
    3135           
    3236          $this->messages = array(); 
     
    4448     public function commit($timeout=4) 
    4549     { 
    46           echo "Attemp to commit...\n"; 
    47           if($this->j->connect($this->serv,$this->port,$timeout)) 
    48           { 
    49                echo "Connected ;)\n"; 
     50          echo "[S] Attemp to commit...\n"; 
     51          if ($this->j->connect($timeout)) { 
     52               $this->j->_connection->debug = true; 
     53               echo "[I] Connected ;)\n"; 
    5054               $this->j->execute($timeout); 
    51                echo "STOPPED\n"; 
     55               echo "[S] STOPPED\n"; 
    5256               return true; 
    53           } else { 
     57          } 
     58          else { 
    5459               echo "[E] Connection failure\n"; 
    5560          } 
     
    6065     { 
    6166          $this->j->login($this->user,$this->pass); 
    62           echo "Logged in\n"; 
     67          echo "[I] Logged in\n"; 
    6368     } 
    6469      
    6570     public function handleAuthenticated() 
    6671     { 
    67           echo "Authenticated\n"; 
     72          echo "[I] Authenticated\n"; 
    6873          foreach ($this->messages as $m) 
    6974          { 
    70                $this->j->message($m[0],"chat",NULL,$m[1]); 
     75               $this->j->message($m[0],"normal",NULL,$m[1]); 
    7176          } 
    72           echo "All sended\n"; 
     77          echo "[I] All sended\n"; 
    7378          $this->j->terminated = true; 
    7479     } 
     
    8085} 
    8186 
    82 $j = new jabberNotifier($serv,$port,$user,$pass); 
    83 $j->addMessage($dest,'Test...'.time().'!'); 
     87$j = new jabberNotifier($host,$port,$user,$pass,$con); 
     88$j->addMessage($dest,'/me makes a test... '.time().'!'); 
    8489$j->commit(8); 
    8590 
    8691echo "Total execution time : ".(microtime(true) - $t1)." s\n"; 
    87 //*/ 
     92 
    8893?> 
Note: See TracChangeset for help on using the changeset viewer.

Sites map