Ignore:
Timestamp:
01/18/08 15:17:58 (16 years ago)
Author:
niltonneto
Message:

Commit da nova versão do módulo, usando agente em C.
Vide Página do módulo do Trac:
http://www.expressolivre.org/dev/wiki/messenger

A versão anterior encontra-se na subpasta bkp (32/64).

Location:
trunk/instant_messenger/inc
Files:
2 deleted
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/instant_messenger/inc/Jabber.abstract.php

    r64 r151  
    11<?php 
    22/* 
    3 +-------------------------------------------------------------------------+ 
    4 |                                                                         | 
    5 | @FILE:        Jabber.abstract.php                                       | 
    6 | @ABSTRACT:    Jabber                                                    | 
    7 | @EXTENDS:     Socket (Socket.class.php)                                 | 
    8 |                                                                         | 
    9 | @DATE:        Wed May,16 2007 08:18:59                                  | 
    10 | @LAST_CHANGE: Wed May,16 2007 09:03:28                                  | 
    11 |                                                                         | 
    12 | @AUTHOR:      [NUTS] Rodrigo Souza - rodsouza@celepar.pr.gov.br        | 
    13 |                                                                         | 
    14 | @BRIEF:       Abstract class for connect with any Jabber server         | 
    15 |                                                                         | 
    16 +-------------------------------------------------------------------------+ 
     3+---------------------------------------------------------------------------------+ 
     4|                                                                                 | 
     5| @FILE:        Jabber.abstract.php                                               | 
     6| @ABSTRACT:    Jabber                                                            | 
     7| @EXTENDS:     Socket (Socket.class.php)                                         | 
     8|                                                                                 | 
     9| @DATE:        Wed May,16 2007 08:18:59                                          | 
     10| @LAST_CHANGE: Wed May,16 2007 09:03:28                                          | 
     11|                                                                                 | 
     12| @AUTHOR:      [NUTS] Rodrigo Souza - rodrigosouzadossantos [at] gmail [dot] com | 
     13|                                                                                 | 
     14| @BRIEF:       Abstract class for connect with any Jabber server                 | 
     15|                                                                                 | 
     16+---------------------------------------------------------------------------------+ 
    1717*/ 
    1818 
     
    2121abstract class Jabber extends Socket 
    2222{ 
    23    const J_FILE    = '/var/log/expresso/Jabber.log'; 
    24    const J_ALL     = false; 
    25    const J_ERROR   = true; 
    26    const J_WARNING = true; 
    27    const J_NOTICE  = true; 
    28  
    29    const ALL     = 'ALL'; 
    30    const ERROR   = 'ERROR'; 
    31    const WARNING = 'WARNING'; 
    32    const NOTICE  = 'NOTICE'; 
    33  
    34    private final function _connect( $pUser = false, $pPassword = false ) 
    35    { 
    36       try 
    37       {  
    38          if ( !preg_match('/^(.+)@(.+)\/(.+):(\d+)$/',$pUser, $matches) ) 
    39             throw new Exception('[connect] #1 ' . $pUser . ' must be [USER]@[DOMAIN]/[RESOURCE]:[PORT] and [PORT] is integer. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    40  
    41          list($subject, $USER, $SERVER, $RESOURCE, $PORT) = $matches; 
    42  
    43          if ( !($socket = $this->open('tcp://' . $SERVER . ':' . $PORT, 1, 1)) ) 
    44             throw new Exception('[connect] #2 can\'t access tcp://' . $SERVER . ':' . $PORT . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    45  
    46          $this->_socket = $socket; 
    47  
    48          $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
    49          $xml .= "<stream:stream to='" . $SERVER . "' xmlns='jabber:client' "; 
    50          $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
    51  
    52          if ( $this->write($xml) === false ) 
    53             throw new Exception('[connect] #3 it isn\'t possible write in the socket ' . $socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    54  
    55          $this->_server = $SERVER; 
    56          $this->_username = $USER; 
    57          $this->_password = $pPassword; 
    58          $this->_resource = $RESOURCE; 
    59       } 
    60       catch(Exception $e) 
    61       { 
    62          $this->writeLog('ERROR', $e->getMessage()); 
    63          return false; 
    64       } 
    65    } 
    66  
    67    protected function connect( $pUser = false, $pPassword = false ) 
    68    {    
    69       try 
    70       { 
    71          $this->_connect($pUser, $pPassword); 
     23        const J_FILE    = 'Jabber.log'; 
     24        const J_ALL     = false; 
     25        const J_ERROR   = true; 
     26        const J_WARNING = true; 
     27        const J_NOTICE  = true; 
     28 
     29        const ALL     = 'ALL'; 
     30        const ERROR   = 'ERROR'; 
     31        const WARNING = 'WARNING'; 
     32        const NOTICE  = 'NOTICE'; 
     33 
     34        private final function _connect( $pUser = false, $pPassword = false ) 
     35        { 
     36                try 
     37                { 
     38                        if ( !preg_match('/^(.+)@(.+)\/(.+):(\d+)$/',$pUser, $matches) ) 
     39                                throw new Exception('[connect] #1 ' . $pUser . ' must be [USER]@[DOMAIN]/[RESOURCE]:[PORT] and [PORT] is integer. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     40 
     41                        list($subject, $USER, $SERVER, $RESOURCE, $PORT) = $matches; 
     42 
     43                        if ( !($socket = $this->open('tcp://' . $SERVER . ':' . $PORT, 1, 1)) ) 
     44                                throw new Exception('[connect] #2 can\'t access tcp://' . $SERVER . ':' . $PORT . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     45 
     46                        $this->_socket = $socket; 
     47 
     48                        $return = fread($socket, 4096); 
     49                        fwrite($socket, $pUser); 
     50 
     51                        $return = fread($socket, 4096); 
     52                        fwrite($socket, $pPassword); 
     53 
     54                        $return = fread($socket, 4096); 
     55                        #echo __FUNCTION__ . "<br>\n"; 
     56                        #var_dump($return); 
     57                        #exit; 
     58 
     59                        if ( $return == "new" ) 
     60                        { 
     61                                $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
     62                                $xml .= "<stream:stream to='" . $SERVER . "' xmlns='jabber:client' "; 
     63                                $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
     64 
     65                                if ( $this->write($xml) === false ) 
     66                                        throw new Exception('[connect] #4 it isn\'t possible connect in the server becase exists a client connected with same user. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     67                        } 
     68 
     69                        $this->_server = $SERVER; 
     70                        $this->_username = $USER; 
     71                        $this->_password = $pPassword; 
     72                        $this->_resource = $RESOURCE; 
     73 
     74                        #var_dump($return); 
     75                        #exit; 
     76                        return $return; 
     77                } 
     78                catch(Exception $e) 
     79                { 
     80                        $this->writeLog('ERROR', $e->getMessage()); 
     81                        return false; 
     82                } 
     83        } 
     84 
     85        protected function connect( $pUser = false, $pPassword = false ) 
     86        { 
     87                try 
     88                { 
     89                        $_connect = $this->_connect($pUser, $pPassword); 
    7290                         
    73          if ( ($xml = $this->read()) === false ) 
    74             throw new Exception('[connect] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    75           
    76          if ( preg_match('/(<starttls .*<required\/><\/starttls>)/', $xml, $matches) ) 
    77          { 
    78             if ( !$this->starttls() ) 
    79                throw new Exception('[connect] #2 it isn\'t possible start tls. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    80  
    81             # $this->writeLog('NOTICE', 'Connected TLS'); 
    82          } 
    83          else 
    84                         { 
    85             if ( !$this->_plain() ) 
    86                throw new Exception('[connect] #3 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    87                         } 
    88  
    89          return true; 
    90       } 
    91       catch(Exception $e) 
    92       { 
    93          $this->writeLog('ERROR', $e->getMessage()); 
    94          $this->_disconnect(); 
    95          return false; 
    96       } 
    97    } 
    98  
    99    protected final function _disconnect() 
    100    { 
    101       try 
    102       { 
    103          $xml = "</stream:stream>"; 
    104  
    105          if ( $this->write($xml) === false ) 
    106             throw new Exception('[disconnect] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    107  
    108          if ( ($xml = $this->read()) === false ) 
    109             throw new Exception('[disconnect] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    110       } 
    111       catch(Exception $e) 
    112       { 
    113          $this->writeLog('ERROR', $e->getMessage()); 
    114          return false; 
    115       } 
    116    } 
    117  
    118    private final function starttls() 
    119    { 
    120       try 
    121       { 
    122          $xml = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"; 
    123          if ( $this->write($xml) === false ) 
    124             throw new Exception('[starttls] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    125  
    126          if ( ($xml = $this->read()) === false ) 
    127             throw new Exception('[starttls] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    128  
    129          if ( !preg_match('/<proceed.*\/>/', $xml, $matches) ) 
    130             throw new Exception('[starttls] #3 can\'t start tls in the socket ' .$this->_socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    131  
    132                    stream_socket_enable_crypto($this->_socket, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); 
    133  
    134          $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
    135          $xml .= "<stream:stream to='" . $this->_server . "' xmlns='jabber:client' "; 
    136          $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
    137          if ( $this->write($xml) === false ) 
    138             throw new Exception('[starttls] #4 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    139  
    140          usleep(90000); 
    141          $this->blocking($this->_socket, 0); 
    142  
    143          if ( ($xml = $this->read()) === false ) 
    144             throw new Exception('[starttls] #5 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    145  
    146          if ( !$this->_plain() ) 
    147             throw new Exception('[starttls] #6 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    148  
    149          return true; 
    150       } 
    151       catch(Exception $e) 
    152       { 
    153          $this->writeLog('ERROR', $e->getMessage()); 
    154          return false; 
    155       } 
    156    } 
    157  
    158    private final function _plain() 
    159    { 
    160       try 
    161       { 
    162          $this->blocking($this->_socket, 0); 
    163  
    164          if ( ($xml = $this->read()) === false ) 
    165             throw new Exception('[_plain] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    166  
    167          $xml  = "<username>" . $this->_username . "</username>"; 
    168          $xml .= "<password>" . $this->_password . "</password>"; 
    169          $xml .= "<resource>" . $this->_resource . "</resource>"; 
    170  
    171          unset($this->_password); 
    172  
    173          if ( !$this->iq('set', 'auth_1', NULL, NULL, "jabber:iq:auth", $xml) ) 
    174             throw new Exception('[_plain] #2 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    175  
    176          while ( !preg_match("/<iq xmlns='jabber:client' id='auth_1' type='(result|error)'/", ($readSocket = $this->read()), $matches) ) 
    177                    usleep(10000); 
     91                        if ( !$_connect ) 
     92                                throw new Exception('[connect] #0. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     93 
     94                        if ( $_connect == "new" ) 
     95                        { 
     96                                if ( ($xml = $this->read()) === false ) 
     97                                        throw new Exception('[connect] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     98 
     99                                if ( preg_match('/(<starttls .*<required\/><\/starttls>)/', $xml, $matches) ) 
     100                                { 
     101                                        if ( !$this->starttls() ) 
     102                                                throw new Exception('[connect] #2 it isn\'t possible start tls. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     103 
     104                                        # $this->writeLog('NOTICE', 'Connected TLS'); 
     105                                } 
     106                                else 
     107                                { 
     108                                        if ( !$this->_plain() ) 
     109                                                throw new Exception('[connect] #3 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     110                                } 
     111                        } 
     112 
     113                        return $_connect; 
     114                } 
     115                catch(Exception $e) 
     116                { 
     117                        $this->writeLog('ERROR', $e->getMessage()); 
     118                        $this->_disconnect(); 
     119                        return false; 
     120                } 
     121        } 
     122 
     123        protected final function _disconnect() 
     124        { 
     125                try 
     126                { 
     127                        $xml = "</stream:stream>"; 
     128 
     129                        if ( $this->write($xml) === false ) 
     130                                throw new Exception('[disconnect] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     131 
     132                        if ( ($xml = $this->read()) === false ) 
     133                                throw new Exception('[disconnect] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     134                } 
     135                catch(Exception $e) 
     136                { 
     137                        $this->writeLog('ERROR', $e->getMessage()); 
     138                        return false; 
     139                } 
     140        } 
     141 
     142        private final function starttls() 
     143        { 
     144                try 
     145                { 
     146                        $xml = "<starttls xmlns='urn:ietf:params:xml:ns:xmpp-tls'/>"; 
     147                        if ( $this->write($xml) === false ) 
     148                                throw new Exception('[starttls] #1 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     149 
     150                        if ( ($xml = $this->read()) === false ) 
     151                                throw new Exception('[starttls] #2 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     152 
     153                        if ( !preg_match('/<proceed.*\/>/', $xml, $matches) ) 
     154                                throw new Exception('[starttls] #3 can\'t start tls in the socket ' .$this->_socket . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     155 
     156                        stream_socket_enable_crypto($this->_socket, TRUE, STREAM_CRYPTO_METHOD_TLS_CLIENT); 
     157 
     158                        $xml  = "<?xml version='1.0' encoding='UTF-8'?>"; 
     159                        $xml .= "<stream:stream to='" . $this->_server . "' xmlns='jabber:client' "; 
     160                        $xml .= "xmlns:stream='http://etherx.jabber.org/streams' version='1.0'>"; 
     161                        if ( $this->write($xml) === false ) 
     162                                throw new Exception('[starttls] #4 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     163 
     164                        usleep(90000); 
     165                        $this->blocking($this->_socket, 0); 
     166 
     167                        if ( ($xml = $this->read()) === false ) 
     168                                throw new Exception('[starttls] #5 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     169 
     170                        if ( !$this->_plain() ) 
     171                                throw new Exception('[starttls] #6 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     172 
     173                        return true; 
     174                } 
     175                catch(Exception $e) 
     176                { 
     177                        $this->writeLog('ERROR', $e->getMessage()); 
     178                        return false; 
     179                } 
     180        } 
     181 
     182        private final function _plain() 
     183        { 
     184                try 
     185                { 
     186                        $this->blocking($this->_socket, 0); 
     187 
     188                        if ( ($xml = $this->read()) === false ) 
     189                                throw new Exception('[_plain] #1 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     190 
     191                        $xml  = "<username>" . $this->_username . "</username>"; 
     192                        $xml .= "<password>" . $this->_password . "</password>"; 
     193                        $xml .= "<resource>" . $this->_resource . "</resource>"; 
     194 
     195                        unset($this->_password); 
     196 
     197                        if ( !$this->iq('set', 'auth_1', NULL, NULL, "jabber:iq:auth", $xml) ) 
     198                                throw new Exception('[_plain] #2 it isn\'t possible carry out the verification. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     199 
     200                        while ( !preg_match("/<iq xmlns='jabber:client' id='auth_1' type='(result|error)'/", ($readSocket = $this->read()), $matches) ) 
     201                                usleep(10000); 
    178202 
    179203                        if($matches[1] == "error") 
    180204                                return false; 
    181205 
    182          if ( ($xml = $this->read()) === false ) 
    183             throw new Exception('[_plain] #3 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    184  
    185          return true; 
    186       } 
    187       catch(Exception $e) 
    188       { 
    189          $this->writeLog('ERROR', $e->getMessage()); 
    190          return false; 
    191       } 
    192    } 
     206                        if ( ($xml = $this->read()) === false ) 
     207                                throw new Exception('[_plain] #3 it isn\'t possible read the socket. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     208 
     209                        return true; 
     210                } 
     211                catch(Exception $e) 
     212                { 
     213                        $this->writeLog('ERROR', $e->getMessage()); 
     214                        return false; 
     215                } 
     216        } 
    193217 
    194218        private final function _iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false ) 
     
    199223 
    200224                if ( $pXmlns == "vcard-temp" ) 
    201       { 
     225                { 
    202226                        $xml .= ">"; 
    203227                        $xml .= $pLoad; 
    204228                } 
    205       else 
    206       { 
     229                else 
     230                { 
    207231                        $xml .= "><query xmlns='" . $pXmlns . "'"; 
    208232                        $xml .= ( $pLoad ) ? ">" . $pLoad . "</query>" : "/>"; 
     
    210234 
    211235                $xml .= "</iq>"; 
    212                  
    213                 return $xml;     
    214         } 
    215  
    216    protected final function iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false) 
    217    { 
    218       try 
    219       { 
    220          if ( !preg_match("/^(get|set|result|error)$/i", $pType, $matches) ) 
    221             throw new Exception('[iq] #1 type must be GET, SET, RESULT or ERROR. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    222  
    223                    if ( $this->write($this->_iq($pType, $pId, $pTo, $pFrom, $pXmlns, $pLoad)) === false ) 
    224             throw new Exception('[iq] #2 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
    225          else 
    226             return true; 
    227       } 
    228       catch(Exception $e) 
    229       { 
    230          $this->writeLog('ERROR', $e->getMessage()); 
    231          return false; 
    232       } 
    233    } 
     236 
     237                return $xml; 
     238        } 
     239 
     240        protected final function iq($pType = false, $pId = false, $pTo = false, $pFrom = false, $pXmlns = false, $pLoad = false) 
     241        { 
     242                try 
     243                { 
     244                        if ( !preg_match("/^(get|set|result|error)$/i", $pType, $matches) ) 
     245                                throw new Exception('[iq] #1 type must be GET, SET, RESULT or ERROR. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     246 
     247                        if ( $this->write($this->_iq($pType, $pId, $pTo, $pFrom, $pXmlns, $pLoad)) === false ) 
     248                                throw new Exception('[iq] #2 Cannot write to socket (' . $this->_socket . '). File: ' . __FILE__ . '  ::  ' . __LINE__); 
     249                        else 
     250                                return true; 
     251                } 
     252                catch(Exception $e) 
     253                { 
     254                        $this->writeLog('ERROR', $e->getMessage()); 
     255                        return false; 
     256                } 
     257        } 
    234258 
    235259        protected final function presence($pType = false, $pTo = false, $pShow = false, $pStatus = false, $pPriority = false) 
    236260        { 
    237       try 
    238       { 
    239          $xml  = "<presence"; 
    240          $xml .= ($pTo)   ? " to='{$pTo}'" : ''; 
    241          $xml .= ($pType) ? " type='{$pType}'" : ''; 
    242           
    243          //$xml .= ($pStatus || $pShow || $pPriority) ? ">" : "/>"; 
    244          if ( !($pStatus || $pShow || $pPriority) ) 
     261                try 
     262                { 
     263                        $xml  = "<presence"; 
     264                        $xml .= ($pTo)   ? " to='{$pTo}'" : ''; 
     265                        $xml .= ($pType) ? " type='{$pType}'" : ''; 
     266 
     267                        if ( !($pStatus || $pShow || $pPriority) ) 
    245268                                $xml .= "/>"; 
    246269                        else 
    247270                        { 
    248                          $xml .= ">"; 
    249                  $xml .= ($pStatus) ? "<status>" . $pStatus . "</status>" : ''; 
    250                  $xml .= ($pShow) ? "<show>" . $pShow . "</show>" : ''; 
    251                  $xml .= ($pPriority) ? "<priority>" . $pPriority . "</priority>" : ''; 
    252                  $xml .= ($pStatus || $pShow || $pPriority) ? "</presence>" : ''; 
     271                                $xml .= ">"; 
     272                                $xml .= ($pStatus) ? "<status>" . $pStatus . "</status>" : ''; 
     273                                $xml .= ($pShow) ? "<show>" . $pShow . "</show>" : ''; 
     274                                $xml .= ($pPriority) ? "<priority>" . $pPriority . "</priority>" : ''; 
     275                                $xml .= ($pStatus || $pShow || $pPriority) ? "</presence>" : ''; 
    253276                        } 
    254  
    255          if ( $this->write($xml) === false ) 
    256             throw new Exception('[presence] #1 it isn\'t possible send presence for ' . $this->_server . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
    257  
    258          return true; 
    259       } 
    260       catch(Exception $e) 
    261       { 
    262          $this->writeLog('ERROR', $e->getMessage()); 
    263          return false; 
    264       } 
    265         } 
    266  
    267    protected final function read() 
    268    { 
    269       $return = NULL; 
    270       do 
    271       { 
    272          $line = NULL; 
    273          $line = utf8_decode(parent::read($this->_socket, 4096)); 
    274  
    275          if ( $line === false ) 
    276          { 
    277             $return = false; 
    278             break; 
    279          } 
    280  
    281          if ( $line != NULL ) 
    282             $return .= $line;// . "\n"; 
    283       } 
    284       while ( $line != NULL ); 
    285  
    286       return $return; 
    287    } 
     277                         
     278                        if ( $this->write($xml) === false ) 
     279                                throw new Exception('[presence] #1 it isn\'t possible send presence for ' . $this->_server . '. File: ' . __FILE__ . '  ::  ' . __LINE__); 
     280 
     281                        return true; 
     282                } 
     283                catch(Exception $e) 
     284                { 
     285                        $this->writeLog('ERROR', $e->getMessage()); 
     286                        return false; 
     287                } 
     288        } 
     289 
     290        protected final function read() 
     291        { 
     292                $return = NULL; 
     293                do 
     294                { 
     295                        $line = NULL; 
     296                        $line = utf8_decode(parent::read($this->_socket, 4096)); 
     297 
     298                        if ( $line === false ) 
     299                        { 
     300                                $return = false; 
     301                                break; 
     302                        } 
     303 
     304                        if ( $line != NULL ) 
     305                                $return .= $line;// . "\n"; 
     306                } 
     307                while ( $line != NULL ); 
     308 
     309                return $return; 
     310        } 
    288311 
    289312        protected final function write($pData = false) 
    290    { 
    291       if ( !$pData ) 
    292          return false; 
    293  
    294       return parent::write($this->_socket, utf8_encode($pData)); 
    295    } 
    296  
    297    protected final function writeLog($pType = false, $pLog = false) 
    298    { 
    299       if ( !defined('self::'.$pType) && !$pLog ) 
    300          return false; 
    301  
    302       if ( !(bool)constant('self::J_'.$pType) && !(bool)constant('self::J_ALL') ) 
    303          return false; 
    304  
    305       $log  = date('m/d/Y H:i:s'); 
    306       $log .= ' [' . constant('self::'.$pType) . '] :: '; 
    307       $log .= $pLog . "\n"; 
    308       if ( $fp = fopen (self::J_FILE, "a+") ) 
    309       { 
    310          fwrite($fp, $log); 
    311          fclose($fp); 
    312       } 
    313    } 
     313        { 
     314                if ( !$pData ) 
     315                        return false; 
     316 
     317                return parent::write($this->_socket, utf8_encode($pData)); 
     318        } 
     319 
     320        function __destruct() 
     321        { 
     322                $this->close($this->_socket); 
     323        } 
     324 
     325        protected final function writeLog($pType = false, $pLog = false) 
     326        { 
     327                if ( !defined('self::'.$pType) && !$pLog ) 
     328                        return false; 
     329 
     330                if ( !(bool)constant('self::J_'.$pType) && !(bool)constant('self::J_ALL') ) 
     331                        return false; 
     332 
     333                $log  = date('m/d/Y H:i:s'); 
     334                $log .= ' [' . constant('self::'.$pType) . '] :: '; 
     335                $log .= $pLog . "\n"; 
     336                if ( $fp = fopen (self::J_FILE, "a+") ) 
     337                { 
     338                        fwrite($fp, $log); 
     339                        fclose($fp); 
     340                } 
     341        } 
    314342} 
    315  
    316343?> 
  • trunk/instant_messenger/inc/Jabberd2.abstract.php

    r55 r151  
    77class Jabberd2 extends Jabber 
    88{ 
    9    final function connect($pUser = false, $pPassword = false) 
    10    { 
    11       try 
    12       { 
    13          if ( parent::connect($pUser, $pPassword) ) 
    14             if ( $this->presence() ) 
    15                return true; 
     9        final function connect($pUser = false, $pPassword = false) 
     10        { 
     11                try 
     12                { 
     13                        if ( $_connect = parent::connect($pUser, $pPassword) ) 
     14                                return $_connect; 
    1615 
    17          return false; 
    18       } 
    19       catch(Exception $e) 
    20       { 
    21          $this->writeLog('ERROR', $e->getMessage()); 
    22          return false; 
    23       } 
    24    } 
     16                        return false; 
     17                } 
     18                catch(Exception $e) 
     19                { 
     20                        $this->writeLog('ERROR', $e->getMessage()); 
     21                        return false; 
     22                } 
     23        } 
    2524 
    26    function disconnect() 
    27    { 
    28       $this->_disconnect(); 
    29    } 
     25        function closeSocket() 
     26        { 
     27                $this->close($this->_socket); 
     28        } 
    3029 
    31    final function readSocket() 
    32    { 
    33       return $this->read(); 
    34    } 
     30        function disconnect() 
     31        { 
     32                $this->_disconnect(); 
     33        } 
    3534 
    36    final function writeSocket($pData) 
    37    { 
    38       return $this->write($pData); 
    39    } 
     35        final function readSocket() 
     36        { 
     37                return $this->read(); 
     38        } 
     39 
     40        final function writeSocket($pData) 
     41        { 
     42                return $this->write($pData); 
     43        } 
     44 
     45        /* 
     46         * Jabber - Functions 
     47         */ 
     48 
     49        final function addContacts($pContact) 
     50        { 
     51                $jid = explode("@",$pContact['email']); 
     52                $jid = $jid[0]."@".$this->_server; 
     53                $name = $pContact['name']; 
     54                $group = $pContact['group']; 
     55 
     56                if(trim($jid[0]) != trim($this->_user)) 
     57                { 
     58                        if ( $jid ) 
     59                        { 
     60                                $newcontact  = "<item jid='".$jid."'"; 
     61                                $newcontact .= " name='" . $name . "'"; 
     62                                $newcontact .= "><group>" . $group . "</group></item>"; 
     63                        } 
     64                } 
     65                $addid = "adduser_" . time(); 
     66                if ( !$this->connected ) 
     67                        echo "disconnected"; 
     68                else 
     69                { 
     70                        if($this->writeSocket($this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $newcontact))) 
     71                        { 
     72                                $this->getContacts(); 
     73                                if($this->subscription($pContact['jid'],"subscribe")) 
     74                                        echo "OK"; 
     75                        } 
     76                } 
     77        } 
     78 
     79        final function getContacts() 
     80        { 
     81                $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); 
     82        } 
     83 
     84        final function getVcard($pJid) 
     85        { 
     86                if(is_array($pJid)) 
     87                { 
     88                        $jid = (trim($pJid['jid']) == "this") ? $this->_user . '@' . $this->_server : $pJid['jid']; 
     89 
     90                        if ( !$this->connected ) 
     91                                echo "disconnected"; 
     92                        else 
     93                        { 
     94                                $this->writeSocket($this->iq('get', 'vCard', $jid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>")); 
     95                                echo "OK"; 
     96                        } 
     97                } 
     98                else 
     99                { 
     100                        $this->iq('get', 'vCard', $pJid, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); 
     101                } 
     102        } 
     103 
     104        final function newVcard($NewVcard) 
     105        { 
     106                $id = $this->_user; 
     107 
     108                if ( !$this->connected ) 
     109                        echo "disconnected"; 
     110                else 
     111                {                
     112                        $this->writeSocket($this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard['vcard']."</vCard>")); 
     113                        echo "OK"; 
     114                }                        
     115        } 
    40116         
    41         final function setPresence($pPresence) 
     117        final function removeContact($pContact) 
    42118        { 
     119                $delid  = 'deluser_' . time(); 
     120                if( !$this->connected ) 
     121                        echo "disconnected"; 
     122                else 
     123                { 
     124                        if($this->writeSocket($this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact['jid']."' subscription='remove'/>"))) 
     125                        { 
     126                                $this->getContacts(); 
     127                                if($this->subscription($pContact['jid'],"unsubscribed")) 
     128                                        echo "OK";                       
     129                        } 
     130                } 
     131        } 
     132 
     133        final function subscription($pTo, $pType = false) 
     134        { 
     135                $jid = (is_array($pTo)) ? $pTo['jid'] : $pTo ; 
     136                $type = (is_array($pTo)) ? $pTo['type'] : $pType ; 
     137 
     138                if ( !$this->connected ) 
     139                        return false; 
     140                else 
     141                { 
     142                        $this->writeSocket("<presence xmlns='jabber:client' from='".$this->_user."@".$this->_server."' type='".$type."' to='".$jid."'/>"); 
     143                        return true;                     
     144                } 
     145        } 
     146 
     147        final function setPresence($pPresence = false) 
     148        { 
     149                 
     150                if ( !$pPresence ) 
     151                        $this->presence(); 
     152 
    43153                $type = ( isset($pPresence['type']) ) ? $pPresence['type'] : NULL; 
    44154                $to = ( isset($pPresence['to']) ) ? $pPresence['to'] : NULL; 
     
    46156                $status = ( isset($pPresence['status']) ) ? $pPresence['status'] : NULL; 
    47157                $priority = ( isset($pPresence['priority']) ) ? $pPresence['priority'] : NULL; 
    48                  
     158 
    49159                $this->presence($type, $to, $show, $status, $priority); 
    50         } 
    51         /* 
    52          * Vcard 
    53          */ 
    54160 
    55    final function getVcard($pVcard) 
    56    { 
    57                 $this->iq('get', $pVcard, $pVcard, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'/>"); 
    58    } 
    59  
    60    final function newVcard($NewVcard) 
    61    { 
    62         $id = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    63         $this->iq('set', $id, NULL, NULL, "vcard-temp", "<vCard xmlns='vcard-temp'>".$NewVcard."</vCard>");      
    64    } 
    65          
    66         /* 
    67          *  Contacts 
    68          */ 
    69  
    70    final function getContacts() 
    71    { 
    72                 $this->iq('get', 'contacts', NULL, NULL, 'jabber:iq:roster'); 
    73    } 
    74     
    75    final function addContacts($pContact) 
    76    { 
    77         $addid = "adduser_" . time(); 
    78         $this->iq('set', $addid, NULL, NULL, "jabber:iq:roster", $pContact); 
    79    } 
    80     
    81    final function removeContact($pContact) 
    82    { 
    83         $delid  = 'deluser_' . time(); 
    84         $this->iq('set',$delid,NULL,NULL,"jabber:iq:roster","<item jid='".$pContact."' subscription='remove'/>"); 
    85    } 
    86     
    87    final function updateContact($pContact) 
    88    { 
    89         $upid = 'updateuser_' . time(); 
    90         $this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $pContact); 
    91    } 
    92     
    93    /* 
    94     * Presence  
    95     */ 
    96     
    97    final function SubscriptionAcceptRequest($to = NULL) 
    98         { 
    99                 $this->presence("subscribed", $to); 
    100161        } 
    101162 
    102         final function SubscriptionDenyRequest($to = NULL) 
     163        final function updateContact($pContact) 
    103164        { 
    104                 $this->presence("unsubscribed", $to); 
    105         } 
     165                $jid   = $pContact['jid']; 
     166                $name  = $pContact['name']; 
     167                $group = $pContact['group']; 
    106168 
    107         final function Subscribe($to = NULL) 
    108         { 
    109                 $this->presence("subscribe", $to); 
    110         } 
     169                if ( $jid ) 
     170                { 
     171                        $updatecontact  = "<item jid='$jid'"; 
     172                        $updatecontact .= " name='" . $name . "'"; 
     173                        $updatecontact .= "><group>" . $group . "</group></item>"; 
     174                } 
    111175 
    112         final function Unsubscribe($to = NULL) 
    113         { 
    114                 $this->presence("unsubscribe", $to); 
     176                $upid = 'updateuser_' . time(); 
     177                if ( !$this->connected ) 
     178                        echo "disconnected"; 
     179                else 
     180                { 
     181                        $this->writeSocket($this->iq('set', $upid, NULL, NULL, "jabber:iq:roster", $updatecontact)); 
     182                        $this->getContacts(); 
     183                        echo "OK"; 
     184                } 
    115185        } 
    116186} 
  • trunk/instant_messenger/inc/Socket.abstract.php

    r63 r151  
    2020        protected final function open( $pSocket = false, $pTimeOut = 1, $pBlockingMode = 0 ) 
    2121        { 
    22       if ( !$pSocket ) 
    23          return false; 
     22                if ( !$pSocket ) 
     23                        return false; 
    2424 
    25       if ( $socket = @stream_socket_client($pSocket, $errno, $errstr) ) 
    26       { 
    27          stream_set_blocking($socket, $pBlockingMode); 
    28          stream_set_timeout($socket, $pTimeOut); 
    29       } 
    30       return $socket; 
     25                if ( $socket = @stream_socket_client($pSocket, $errno, $errstr) ) 
     26                { 
     27                        #stream_set_blocking($socket, $pBlockingMode); 
     28                        #stream_set_timeout($socket, $pTimeOut); 
     29                        stream_set_blocking($socket, 1); 
     30                        stream_set_timeout($socket, 1); 
     31                } 
     32                return $socket; 
    3133        } 
    3234 
    33    protected final function blocking($pSocket = false, $pBlockingMode = 1) 
    34    { 
    35       if ( !$pSocket || !is_resource($pSocket) ) 
    36          return false; 
     35        protected final function blocking($pSocket = false, $pBlockingMode = 1) 
     36        { 
     37                if ( !$pSocket || !is_resource($pSocket) ) 
     38                        return false; 
    3739 
    38       stream_set_blocking($pSocket, $pBlockingMode); 
    39    } 
     40                stream_set_blocking($pSocket, $pBlockingMode); 
     41        } 
    4042 
    4143 
    4244        protected function read( $pSocket = false, $pLength = 4096 ) 
    4345        { 
    44       ini_set( 'track_errors', '1' ); 
    45       $php_errormsg = ''; 
     46                ini_set( 'track_errors', '1' ); 
     47                $php_errormsg = ''; 
    4648 
    47       if ( !$pSocket || !is_resource($pSocket) ) 
    48          return false; 
     49                if ( !$pSocket || !is_resource($pSocket) ) 
     50                        return false; 
    4951 
    50       set_magic_quotes_runtime(0); 
    51       $return = @fread($pSocket, $pLength); 
    52       set_magic_quotes_runtime(get_magic_quotes_gpc()); 
     52                set_magic_quotes_runtime(0); 
     53                $return = @fread($pSocket, $pLength); 
     54                set_magic_quotes_runtime(get_magic_quotes_gpc()); 
    5355 
    5456 
    55       if ( $php_errormsg ) 
    56          return false; 
     57                if ( $php_errormsg ) 
     58                        return false; 
    5759 
    58       return $return; 
     60                return $return; 
    5961        } 
    6062 
    6163        protected function write( $pSocket = false, $pData = false ) 
    6264        { 
    63       ini_set( 'track_errors', '1' ); 
    64       $php_errormsg = ''; 
    65        
    66       if ( (!$pSocket || !is_resource($pSocket)) || !$pData ) 
    67          return false; 
     65                ini_set( 'track_errors', '1' ); 
     66                $php_errormsg = ''; 
    6867 
    69           $return = @fwrite($pSocket, $pData); 
    70        
    71       if ( $php_errormsg ) 
    72          return false; 
     68                if ( (!$pSocket || !is_resource($pSocket)) || !$pData ) 
     69                        return false; 
    7370 
    74       return $return; 
     71                $return = @fwrite($pSocket, $pData); 
     72 
     73                if ( $php_errormsg ) 
     74                        return false; 
     75 
     76                return $return; 
    7577        } 
    7678 
    7779        protected final function close( $pSocket = false ) 
    7880        { 
    79       if ( !$pSocket || !is_resource($pSocket) ) 
    80          return false; 
     81                if ( !$pSocket || !is_resource($pSocket) ) 
     82                        return false; 
    8183 
    8284                return fclose($pSocket); 
  • trunk/instant_messenger/inc/class.Ujabber.inc.php

    r89 r151  
    11<?php 
    22 
    3 class Ujabber 
     3require_once 'Jabberd2.abstract.php'; 
     4 
     5class Ujabber extends Jabberd2 
    46{ 
    5    /* 
    6     * Listen  
    7     */ 
    8     
    9    final function listen() 
    10    { 
    11       $return = null; 
     7        public final function __construct() 
     8        { 
     9                session_start(); 
    1210                 
    13                 if($_SESSION['phpgw_info']['instant_messenger']['IM_disconnect']) 
     11                $_user     = $_SESSION['phpgw_info']['instant_messenger']['user']; 
     12                $_pass     = $_SESSION['phpgw_info']['instant_messenger']['passwd']; 
     13                $_server   = $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
     14                $_port     = $_SESSION['phpgw_info']['instant_messenger']['port_jabber']; 
     15                $_resource = $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']; 
     16                 
     17                session_write_close(); 
     18 
     19                if ( $this->connect($_user . '@' . $_server . '/' . $_resource . ':' . $_port, $_pass) ) 
     20                        $this->connected = true; 
     21                else 
     22                        $this->connected = false; 
     23                 
     24                 
     25        } 
     26 
     27        public final function __destruct() 
     28        { 
     29                $this->closeSocket(); 
     30        } 
     31 
     32        public final function listen() 
     33        { 
     34                if ( !$this->connected ) 
     35                        return "disconnected"; 
     36 
     37                if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) 
    1438                { 
    15         $_SESSION['phpgw_info']['instant_messenger']['IM_disconnect'] = false; 
    16         return "disconnected"; 
    17                 } 
    18                  
    19            $_SESSION['phpgw_info']['instant_messenger']['timeClient'] = time(); 
    20       $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = true; 
    21       $xml = $_SESSION['phpgw_info']['instant_messenger']['socket']['in']; 
    22       //str_replace inserido por problemas com clientes que inserem 
    23       //quebra de linha no XML descomentar e retirar a seguinte para 
    24       //voltar ao padrão assim que possível 
    25       //24/10/2007 - problema verificado por usuários do SERPRO na 
    26       //plataforma Windows ocorrendo também no cliente Linux 
    27       //por Alexandre e Rodrigo 
    28                 $xml = str_replace("\n","",$xml); 
    29                 $xml = str_replace("\r","",$xml); 
    30  
    31       unset($_SESSION['phpgw_info']['instant_messenger']['socket']['in']); 
    32       $_SESSION['phpgw_info']['instant_messenger']['socket']['block'] = false; 
    33  
    34       ### Arranjo Tecnico ###  
    35       $vkrd = $xml; 
    36        
    37       if(isset($_SESSION['phpgw_info']['instant_messenger']['contacts'])) 
    38          unset($_SESSION['phpgw_info']['instant_messenger']['contacts']); 
    39  
    40       ### - messages - ### 
    41       //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
    42       //o PSI não seguem o padrão assim ocorre problemas de comunicação 
    43       //descomentar e retirar a seguinte para voltar ao padrão assim 
    44       //que possível 
    45       //24/10/2007 - problema verificado por usuários do SERPRO na 
    46       //plataforma Windows ocorrendo também no cliente Linux 
    47       //por Alexandre e Rodrigo 
    48       //$_messages = "/<message[^>]+from='(\S+)'[^>]*>(?(?=.*?<composing |.*?<paused ).*?<(composing|paused) )(?(?=.*?<html).*?<html[^>]*><body[^>]*>(.*?)<\/body><\/html>).*?<\/message>/s"; 
    49       //retirar a linha abaixo para voltar ao padrão conforme acima 
    50       $_messages = "/<message[^>]+from='(\S+)'[^>]*>(?(?=.*?<composing |.*?<paused ).*?<(composing|paused) )(?(?=.*?<body).*?<body[^>]*>(.*?)<\/body>).*?<\/message>/s"; 
    51       $_messages = preg_match_all($_messages, $xml, $messages); 
    52       if ( $_messages !== false && $_messages > 0 ) 
    53       { 
    54          $xml = preg_replace("/<message.*?<\/message>/", "", $xml);          
    55          $return .= $this->getMessages($messages); 
    56       } 
    57       ### - Fim messages - ### 
    58  
    59       ### - contacts - ### 
    60       $_contacts = "/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/"; 
    61       $_contacts = preg_match_all($_contacts, $xml, $_xml); 
    62  
    63       $_contacts = "/<item.*?(?(?=[^>]+name)[^>]+name='(.*?)')[^>]+subscription='(.*?)'[^>]+jid='(.*?)'"; 
    64       $_contacts .= "(?(?=[^>]*\/>)[^>]*\/>|[^>]*><group>(.*?)<\/group><\/item>)/"; 
    65       $_contacts = preg_match_all($_contacts, $_xml[0][0], $contacts); 
    66       if ( $_contacts !== false && $_contacts > 0 ) 
    67       { 
    68          $xml = preg_replace("/<iq[^>]+id='contacts'[^>]*>.*?<\/iq>/", "", $xml); 
    69          $return .= rawurldecode(urldecode($this->getContacts($contacts))); 
    70       } 
    71       ### - Fim contacts - ### 
    72  
    73       ### - presence - ### 
    74       $xml = $_SESSION['phpgw_info']['instant_messenger']['presences'] . $xml; 
    75  
    76       $_presence  = "/<presence(?(?=[^>]+\/>)[^>]+\/>|[^>]+>.*?<\/presence>)/"; 
    77       $_presence = preg_match_all($_presence, $xml, $presence); 
    78  
    79       $patterns[0] = '/<priority>[^<]*<\/priority>|<(\S) (?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/\1>)/'; 
    80       $patterns[1] = '/ xmlns=\'.*?\'| to=\'.*?\'/'; 
    81       $patterns[2] = '/> +</'; 
    82       $replacements[0] = ''; 
    83       $replacements[1] = ''; 
    84       $replacements[2] = '><'; 
    85       $_xml = preg_replace($patterns, $replacements, implode('', $presence[0])); 
    86  
    87       $_presence  = "/<presence[^>]+from='(\S+)'[^>]*type='(unavailable)'(?(?=[^>]*\/>)[^>]*\/>|[^>]*>.*?<\/presence>)|"; 
    88       $_presence .= "<presence[^>]+from='(\S+)'(?(?=[^>]+type)[^>]+type='(\S+)')[^>]*"; 
    89       $_presence .= "(?(?=\/>)\/>|>"; 
    90       $_presence .= "(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>(?(?=<s[^>]*?>)<s[^>]*?>(.*?)<\/s[^>]*?>))"; 
    91       $_presence .= "<\/presence>)/"; 
    92       $_presence = preg_match_all($_presence, $_xml, $presence); 
    93       if ( $_presence !== false && $_presence > 0 ) 
    94       { 
    95          foreach ( $presence[5] as $key => $val ) 
    96          { 
    97             if ( !empty($presence[1][$key]) && (strpos($presence[1][$key], '/') !== false) ) 
    98                $presence[1][$key] = substr($presence[1][$key], 0, strpos($presence[1][$key], '/')); 
    99              
    100             if ( !empty($presence[3][$key]) && strpos($presence[3][$key], '/') !== false ) 
    101                $presence[3][$key] = substr($presence[3][$key], 0, strpos($presence[3][$key], '/')); 
    102     
    103             if ( !empty($val) && !preg_match("/^(away|chat|dnd|xa)$/", $val) ) 
    104                if ( preg_match("/^(away|chat|dnd|xa)$/", $presence[6][$key]) ) 
    105                { 
    106                   $aux = $presence[5][$key]; 
    107                   $presence[5][$key] = $presence[6][$key]; 
    108                   $presence[6][$key] = $aux; 
    109                } 
    110                else 
    111                { 
    112                   if ( empty($presence[6][$key]) )           
    113                      $presence[6][$key] = $presence[5][$key]; 
    114                   $presence[5][$key] = ''; 
    115                } 
    116          } 
    117          $xml = preg_replace("/<presence[^>]\/?>|<presence[^>]>.*?<\/presence>/", "", $xml); 
    118  
    119          $return .= $this->getPresence($presence); 
    120       } 
    121       ### - Fim presence - ### 
    122  
    123        
    124       ### - vcard - ### 
    125       ### - Arranjo Tecnico - ### 
    126       $_xml = $vkrd; 
    127       $_vcard = "/<iq.*? id='(.*?)' .*?(<vCard [^>]+\/>|<vCard.*?<\/vCard>)<\/iq>/";  
    128       $_vcard = preg_match_all($_vcard, $_xml, $vcard); 
    129       if( $_vcard !== false && $_vcard > 0) 
    130       { 
    131          $xml = preg_replace("/<iq.*?<vCard.*?<\/iq>/", "", $xml); 
    132          $return .= urldecode($this->getVcard($vcard)); 
    133       } 
    134       ### - Fim vcard - ### 
    135       ## Final do Listen; 
    136  
    137       return $return; 
    138    } 
    139     
    140    function reconnect() 
    141    { 
    142       require_once("IMConfigure.php"); 
    143  
    144       $_transport = TRANSPORT_NON_SECURITY; 
    145       $_port = PORT_NON_SECURITY; 
    146  
    147                 $SERVER = "127.0.0.1"; 
    148  
    149                 $fp  = ""; 
    150                 @$fp = stream_socket_client($_transport . "://" . $SERVER . ":" . $_port, $errno, $errstr, 10); 
    151  
    152                 if ( $fp ) 
    153                 { 
    154                         fwrite($fp, "GET /" . CONNECT . ";" . session_id() . " HTTP/1.1\r\nHost: " . $SERVER . ":" . $_port . "\r\nAccept: */*\r\n\r\n"); 
    155                         return 'true'; 
     39                        sleep(1); 
     40                        $xml = $this->readSocket(); 
     41                        printf("%s", $xml); 
    15642                } 
    15743                else 
    158                         return 'false'; 
    159    }  
    160     
    161    /* 
    162     * Contacts 
    163     */ 
     44                { 
     45                        ob_end_clean(); 
     46                        ignore_user_abort(true); 
     47                        ob_start(); 
    16448 
    165    function getContacts(array $pContacts) 
    166    { 
    167       $_group = array(); 
    168       $return = NULL; 
    169       $jid = array_unique($pContacts[3]); 
    170        
    171       foreach ( $jid as $key => $val ) 
    172       { 
    173          $_SESSION['phpgw_info']['instant_messenger']['contacts'][] = $val; 
     49                        $init = time(); 
    17450 
    175          $item  = NULL; 
    176          $item .= '<item name="' . (( !empty($pContacts[1][$key]) ) ? $pContacts[1][$key] : $val); 
    177          $item .= '" jid="' . $val; 
    178          $item .= '" subscription="' . $pContacts[2][$key]; 
    179          $item .= '" />'; 
     51                        while ( !connection_aborted() && time() - $init < 10 ) 
     52                        { 
     53                                # read from server and write in the client 
     54                                $xml = $this->readSocket(); 
     55                                $xml = ( strlen($xml) ) ? $xml : ' '; 
     56                                printf("%s", $xml ); 
    18057 
    181          $_group[utf8_decode(strtolower(!empty($pContacts[4][$key]) ? $pContacts[4][$key] : 'default'))][] = $item; 
    182       }  
    183        
    184       ksort($_group); 
     58                                ob_flush(); 
     59                                flush(); 
     60                                usleep(6000); 
     61                        } 
    18562 
    186       foreach ( $_group as $key => $val ) 
    187          $return .= '<group name="' . $key . '">' . implode('', $val) . '</group>'; 
     63                        ob_end_flush(); 
     64                } 
     65        } 
    18866 
    189       return '<contacts>' . $return . '</contacts>'; 
    190    } 
     67        public final function SendMessage($pSendMessage) 
     68        { 
     69                $pSendMessage['body'] = stripslashes($pSendMessage['body']); 
    19170 
    192    function requireContacts() 
    193    { 
    194       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['getContacts'] = NULL; 
    195    } 
    196     
    197   /* 
    198    * Presence  
    199    */ 
     71                $patterns = array('/&nbsp;| +/i', '/<br[^>]*>/i'); 
     72                $replace = array(' ', '<br />'); 
     73                $pSendMessage['body'] = preg_replace($patterns, $replace, $pSendMessage['body']); 
    20074 
    201    function setPresence($pPresence) 
    202    { 
    203       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['setPresence'] = $pPresence; 
    204       foreach($pPresence as $key=>$presence) 
    205         if($key == 'show' || $key == 'type') 
    206         { 
    207                 $_SESSION['phpgw_info']['instant_messenger']['MyPresence'] = $presence; 
    208         } 
    209    } 
    210     
    211    function MyPresence() 
    212    { 
    213         if(isset($_SESSION['phpgw_info']['instant_messenger']['MyPresence'])) 
    214                 return $_SESSION['phpgw_info']['instant_messenger']['MyPresence']; 
    215    } 
    216     
    217    function getPresence(array $pPresence) 
    218    { 
    219       $offline = array(); 
    220       foreach ( $pPresence[1] as $key => $val ) 
    221       { 
    222          if ( empty($val) ) 
    223             continue; 
     75                $_emotions  = '/<img emotion="(\S+)?"[^>]+>/'; 
     76                $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); 
    22477 
    225          $_offline = true; 
    226          for ( $i = $key; $i < sizeof($pPresence[1]); $i++ ) 
    227             if ( $pPresence[1][$key] == $pPresence[3][$i] || $pPresence[1][$key] == $pPresence[5][$i] ) 
    228                $_offline = false; 
     78                foreach ( $emotions[0] as $key => $val ) 
     79                        $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; 
    22980 
    230          if ( $_offline ) 
    231             $offline[$key] = $val; 
    232       } 
     81                $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); 
    23382 
    234       $online = array(); 
    235       foreach ( $pPresence[3] as $key => $val ) 
    236       { 
    237          if ( empty($val) ) 
    238             continue; 
     83                $to = $pSendMessage['to']; 
     84                $type = "chat"; 
     85                $id = ""; 
     86                $content = array( 
     87                        "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", 
     88                        "thread"  => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", 
     89                        "body"    => $pSendMessage['body'] ? $pSendMessage['body'] : "" 
     90                ); 
    23991 
    240          $_online = true; 
    241          for ( $i = ($key + 1); $i < sizeof($pPresence[3]); $i++ ) 
    242             if ( in_array($val, $offline) || $pPresence[3][$key] == $pPresence[3][$i] ) 
    243                $_online = false; 
     92                $payload = ""; 
    24493 
    245          if ( $_online ) 
    246             $online[$key] = $val; 
    247       } 
     94                if ($to && is_array($content)) 
     95                { 
     96                        if (!$id) 
     97                        { 
     98                                $id = $type . "_" . time(); 
     99                        } 
    248100 
    249       $return = NULL; 
     101                        $xml = "<message to='$to' type='$type' id='$id'>"; 
    250102 
    251       foreach ( $offline as $key => $val ) 
    252       { 
    253          $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
    254          $return .= "<presence from='" . $val . "' type='unavailable' />"; 
    255       } 
    256        
    257       foreach ( $online as $key => $val ) 
    258       { 
    259          $val = ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
     103                        if ($content['subject']) 
     104                        { 
     105                                $xml .= "<subject>" . $content['subject'] . "</subject>"; 
     106                        } 
    260107 
    261          if ( empty($pPresence[4][$key]) ) 
    262             $pPresence[4][$key] = ( empty($pPresence[5][$key]) ) ? 
    263                'available' : $pPresence[5][$key]; 
     108                        if ($content['thread']) 
     109                        { 
     110                                $xml .= "<thread>" . $content['thread'] . "</thread>"; 
     111                        } 
    264112 
    265          $return .= "<presence from='" . $val . "' type='" . $pPresence[4][$key]; 
    266          if ( empty($pPresence[6][$key]) ) 
    267             $return .= "' />"; 
    268          else 
    269             $return .= "'>" . $pPresence[6][$key] . "</presence>"; 
     113                        //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
     114                        //o PSI não seguem o padrão assim ocorre problemas de comunicação 
     115                        //descomentar e retirar a seguinte para voltar ao padrão assim 
     116                        //que possível 
     117                        //24/10/2007 - problema verificado por usuários do SERPRO na 
     118                        //plataforma Windows ocorrendo também no cliente Linux 
     119                        //por Alexandre e Rodrigo 
    270120 
    271          if ( strpos($pPresence[4][$key], 'subscribe') === false ) 
    272          { 
    273             $session .= "<presence from='" . $val . "'><show>" . $pPresence[4][$key] . "</show>"; 
    274             if ( !empty($pPresence[6][$key]) ) 
    275                $session .= "<status>" . $pPresence[6][$key] . "</status>"; 
    276             $session .= "</presence>"; 
    277          } 
    278       } 
     121                        //$xml .= "<html><body>" . $content['body'] . "</body></html>"; 
    279122 
    280       $_SESSION['phpgw_info']['instant_messenger']['presences'] = $session; 
     123                        //retirar a linha abaixo para voltar ao padrão conforme acima 
     124                        $xml .= "<body>" . $content['body'] . "</body>"; 
     125                        $xml .= $payload; 
     126                        $xml .= "</message>"; 
     127                        unset($id); 
    281128 
    282       return $return; 
    283    } 
    284  
    285    /* 
    286     * GetMessage 
    287     */ 
    288     
    289    function getMessages(array $pMessages) 
    290    { 
    291       $_messages = array(); 
    292       $return = NULL; 
    293  
    294       foreach ( $pMessages[1] as $key => $val ) 
    295       { 
    296          trim($pMessages[3][$key]); 
    297          if ( !empty($pMessages[3][$key]) ) 
    298             $_messages[$val][] = $pMessages[3][$key]; 
    299              
    300          if ( !empty($pMessages[2][$key]) ) 
    301          { 
    302             $return .= '<' . $pMessages[2][$key] . ' from="'; 
    303             $return .= ( strpos($val, '/') ) ? substr($val, 0, strpos($val, '/')) : $val; 
    304             $return .= '" />'; 
    305          } 
    306       } 
    307  
    308       foreach ( $_messages as $key => $val ) 
    309       { 
    310          $return .= '<messages from="' . $key . '">'; 
    311          foreach ( $val as $msg ) 
    312             $return .= '<message>' . $msg . '</message>'; 
    313          $return .= '</messages>'; 
    314       } 
    315  
    316       return $return; 
    317    } 
    318  
    319    /* 
    320     * SendMessage 
    321     */ 
    322  
    323    function SendMessage($pSendMessage) 
    324    { 
    325       $pSendMessage['body'] = stripslashes($pSendMessage['body']); 
    326       $_emotions  = '/<img emotion="(\S+)?"[^>]+>/'; 
    327       $_emotions = preg_match_all($_emotions, $pSendMessage['body'], $emotions); 
    328  
    329       foreach ( $emotions[0] as $key => $val ) 
    330          $emotions[0][$key] = '/' . addcslashes($val, './()[]{}^$*&?') . '/i'; 
    331  
    332       $pSendMessage['body'] = preg_replace($emotions[0], $emotions[1], $pSendMessage['body']); 
    333  
    334       $to = $pSendMessage['to']; 
    335       $type = "chat"; 
    336       $id = ""; 
    337       $content = array( 
    338          "subject" => $pSendMessage['subject'] ? $pSendMessage['subject'] : "", 
    339          "thread" => $pSendMessage['thread'] ? $pSendMessage['thread'] : "", 
    340          "body" => $pSendMessage['body'] ? $pSendMessage['body'] : "" 
    341       ); 
    342  
    343       $payload = ""; 
    344  
    345       if ($to && is_array($content)) 
    346       { 
    347          if (!$id) 
    348          { 
    349             $id = $type . "_" . time(); 
    350          } 
    351  
    352          $xml = "<message to='$to' type='$type' id='$id'>"; 
    353  
    354          if ($content['subject']) 
    355          { 
    356             $xml .= "<subject>" . $content['subject'] . "</subject>"; 
    357          } 
    358  
    359          if ($content['thread']) 
    360          { 
    361             $xml .= "<thread>" . $content['thread'] . "</thread>"; 
    362          } 
    363  
    364          //Linha abaixo dentro do padrão xmpp, entretanto clientes como 
    365          //o PSI não seguem o padrão assim ocorre problemas de comunicação 
    366          //descomentar e retirar a seguinte para voltar ao padrão assim 
    367          //que possível 
    368          //24/10/2007 - problema verificado por usuários do SERPRO na 
    369          //plataforma Windows ocorrendo também no cliente Linux 
    370          //por Alexandre e Rodrigo 
    371          //$xml .= "<html><body>" . $content['body'] . "</body></html>"; 
    372          //retirar a linha abaixo para voltar ao padrão conforme acima 
    373          $xml .= "<body>" . $content['body'] . "</body>"; 
    374          $xml .= $payload; 
    375          $xml .= "</message>"; 
    376          unset($id); 
    377  
    378          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    379       } 
    380       else 
    381       { 
    382          $this->writeLog("ERROR: SendMessage() #2"); 
    383          return FALSE; 
    384       } 
    385    } 
    386  
    387    /* 
    388     * Composing / Paused Message 
    389     */ 
    390  
    391    function composingMessage($pComposing) 
    392    { 
    393  
    394                 $xml  = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; 
    395                 $xml .= "<x xmlns='jabber:x:event'>"; 
    396                 $xml .= "<composing/>"; 
    397                 $xml .= "</x>"; 
    398                 $xml .= "<composing xmlns='http://jabber.org/protocol/chatstates'/>"; 
    399                 $xml .= "</message>"; 
    400         $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    401    } 
    402     
    403    function pausedMessage($pComposing) 
    404    { 
    405                 $xml  = "<message xmlns='jabber:client' to='".$pComposing['to']."' id='".time()."' type='chat'>"; 
    406                 $xml .= "<x xmlns='jabber:x:event'/>"; 
    407                 $xml .= "<paused xmlns='http://jabber.org/protocol/chatstates'/>"; 
    408                 $xml .= "</message>"; 
    409  
    410                 $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['message'] .= $xml; 
    411    } 
    412     
    413    /* 
    414     * UpdateContact 
    415     */ 
    416     
    417    function updateContact($pUser) 
    418    { 
    419       $jid   = $pUser['jid']; 
    420       $name  = $pUser['name']; 
    421       $group = $pUser['group']; 
    422        
    423       if ( $jid ) 
    424       { 
    425          $updatecontact  = "<item jid='$jid'"; 
    426          $updatecontact .= " name='" . $name . "'"; 
    427          $updatecontact .= "><group>" . $group . "</group></item>"; 
    428          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['updateContact'] = $updatecontact; 
    429       } 
    430       $this->requireContacts(); 
    431    } 
    432     
    433    /* 
    434     * AddContact 
    435     */ 
    436     
    437    function addContacts($pUser) 
    438    { 
    439       $jid = explode("@",$pUser['email']); 
    440       $pJid = $jid[0]."@".$_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    441       $pName = $pUser['name']; 
    442       $pGroup = $pUser['group']; 
    443  
    444       if(trim($jid[0]) != trim($this->username)) 
    445       { 
    446          if ( $pJid ) 
    447          { 
    448             $newcontact  = "<item jid='$pJid'"; 
    449             $newcontact .= " name='" . $pName . "'"; 
    450             $newcontact .= "><group>" . $pGroup . "</group></item>"; 
    451             $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['addContacts'] = $newcontact; 
    452             $this->subscribe($pJid); 
    453             $this->requireContacts();            
    454          } 
    455       } 
    456    } 
    457     
    458    /* 
    459     * RemoveContact 
    460     */ 
    461      
    462     function removeContact($pUser) 
    463     { 
    464          $pJid = $pUser['jid']; 
    465          $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['removeContact'] = $pJid; 
    466          $this->unsubscribed($pJid); 
    467          $this->requireContacts(); 
    468     } 
    469  
    470    /* 
    471     * Vcard 
    472     */ 
    473  
    474    function newVcard($pVcardUser) 
    475    { 
    476       $pVcard = explode("_vkrd_", $pVcardUser['vcard']); 
    477  
    478       $xmlVcard  = "<FN>".$pVcard[0]."</FN>"; 
    479       $xmlVcard .= "<NICKNAME>".$pVcard[1]."</NICKNAME>"; 
    480       $xmlVcard .= "<ORG>"; 
    481       $xmlVcard .= "<ORGNAME>".$pVcard[2]."</ORGNAME>"; 
    482       $xmlVcard .= "<ORGUNIT>".$pVcard[3]."</ORGUNIT>"; 
    483       $xmlVcard .= "</ORG>"; 
    484       $xmlVcard .= "<ROLE>".$pVcard[4]."</ROLE>"; 
    485       $xmlVcard .= "<BDAY>".$pVcard[5]."</BDAY>"; 
    486       $xmlVcard .= "<DESC>".$pVcard[6]."</DESC>"; 
    487        
    488       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['newVcard'] = $xmlVcard; 
    489  
    490    } 
    491     
    492    function getVcard(array $Vcard) 
    493    { 
    494       $div = ""; 
    495       $_expr = "/<[^<vCard xmlns=\'vcard\-temp\'>].*[^<\/vCard>]>/"; 
    496       array_shift($Vcard); 
    497       $div = '<vcard>'; 
    498       $jid_user = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    499       $jid_user .= "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    500       for($i = 0 ; $i < count($Vcard[0]) ; $i++) 
    501       { 
    502          preg_match($_expr,$Vcard[1][$i],$div_vcard); 
    503          $div_new[] = $div_vcard; 
    504  
    505          if ( $jid_user == $Vcard[0][$i] ) 
    506             $_SESSION['phpgw_info']['instant_messenger']['vcard'] = $div_new[$i][0]; 
    507           
    508          $div .= '<div id="vcard_'.$Vcard[0][$i].'">'.urldecode($div_new[$i][0]).'</div>'; 
    509       } 
    510       $div .= '</vcard>'; 
    511           
    512       return $div; 
    513    } 
    514     
    515    function Vcard() 
    516    { 
    517       $contacts = array(); 
    518       $contacts = $_SESSION['phpgw_info']['instant_messenger']['contacts']; 
    519       $jid_user = $this->getJid(); 
    520  
    521       if( count($contacts) > 0 ) 
    522       { 
    523          array_unshift($contacts,$jid_user); 
    524  
    525          foreach($contacts as $user) 
    526             $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $user; 
    527          return "true"; 
    528       }else{ 
    529          return "false"; 
    530       } 
    531    } 
    532     
    533    function VcardUser() 
    534    { 
    535         $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['vcard'][] = $this->getJid();; 
    536    } 
    537     
    538    function getJid() 
    539    { 
    540       $jid = $_SESSION['phpgw_info']['instant_messenger']['user'] . "@" . $_SESSION['phpgw_info']['instant_messenger']['name_jabber']; 
    541       return $jid;    
    542    } 
    543     
    544    function subscribe($pJid) 
    545    { 
    546       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    547       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Subscribe'] = $jid; 
    548    } 
    549     
    550    function subscribed($pJid) 
    551    { 
    552       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    553       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionAcceptRequest'] = $jid; 
    554    } 
    555     
    556    function unsubscribe($pJid) 
    557    { 
    558       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    559       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['Unsubscribe'] = $jid; 
    560    } 
    561     
    562    function unsubscribed($pJid) 
    563    { 
    564       $jid = (is_array($pJid)) ? $pJid['jid'] : $pJid ; 
    565       $_SESSION['phpgw_info']['instant_messenger']['socket']['out']['SubscriptionDenyRequest'] = $jid;    
    566    } 
     129                        echo $xml; 
     130                        $this->writeSocket($xml); 
     131                        $this->close(); 
     132                } 
     133                else 
     134                { 
     135                        //$this->writeLog("ERROR: SendMessage() #2"); 
     136                        return false; 
     137                } 
     138        } 
    567139} 
    568140?> 
  • trunk/instant_messenger/inc/class.contacts_im.inc.php

    r86 r151  
    2020                 
    2121                $search_uids = "|"; 
    22                 foreach($db_acls as $tmp) 
    23                         $search_uids .= "(uidNumber=".$tmp['acl_account'].")"; 
     22                if(count($db_acls) > 0) 
     23                        foreach($db_acls as $tmp) 
     24                                $search_uids .= "(uidNumber=".$tmp['acl_account'].")"; 
    2425 
    2526                // Busca Usuarios 
     
    2728                 
    2829                $search_groups = "|"; 
    29                 foreach($db_acls as $tmp) 
    30                         $search_groups .= "(gidNumber=".$tmp['acl_account'].")"; 
     30                if(count($db_acls) > 0) 
     31                        foreach($db_acls as $tmp) 
     32                                $search_groups .= "(gidNumber=".$tmp['acl_account'].")"; 
    3133  
    3234                // Busca Grupos 
     
    5961        function list_contacts($param) 
    6062        { 
    61                 $users = $this->users_auth_im(); 
    62                 $ordenar = array(); 
    63                 $return = array(); 
    64                 $i = 0; 
     63                $users  = $this->users_auth_im(); 
     64                $order  = array(); 
     65                $return = "<uids>"; 
    6566                 
    6667                foreach($users as $tmp) 
    67                         $ordenar[] = $tmp['cn'].";".$tmp['mail'].";".$tmp['uid'].";".$tmp['dn']; 
     68                        $order[] = $tmp['cn'].";".$tmp['mail'].";".$tmp['uid'].";".$tmp['dn']; 
    6869                                         
    69                 natsort($ordenar); 
    70                 $uid_unique = @array_values(@array_unique($ordenar)); 
     70                natsort($order); 
     71                $uid_unique = @array_values(@array_unique($order)); 
    7172                 
    7273                foreach($uid_unique as $tmp) 
     
    7576                        if(strtolower($result[3]) == strtolower($param['ou'])) 
    7677                        { 
    77                                 $return[$i]['cn']   = $result[0]; 
    78                                 $return[$i]['mail'] = $result[1]; 
    79                                 $return[$i]['uid']  = $result[2]; 
    80                                 $i++; 
     78                                $return .= "<data>"; 
     79                                $return .= "<cn>" . $result[0] . "</cn>"; 
     80                                $return .= "<mail>" . $result[1] . "</mail>";                            
     81                                $return .= "<uid>" . $result[2] . "</uid>"; 
     82                                $return .= "</data>"; 
    8183                        } 
    8284                        unset($result); 
    8385                }                        
    84          
    85                 if(count($return) > 0) 
    86                         return $return; 
    87                 else 
    88                         return 0; 
     86                 
     87                $return .= "</uids>"; 
     88                return $return; 
    8989        } 
    9090         
  • trunk/instant_messenger/inc/class.db_im.inc.php

    r55 r151  
    1414        var $db_pass; 
    1515        var $db_type; 
     16        var $user_id; 
    1617        var $teste; 
    1718         
    18         function db_im(){ 
     19        function db_im() 
     20        { 
     21                session_start();                 
    1922                $this->db_name = $_SESSION['phpgw_info']['instant_messenger']['server']['db_name']; 
    2023                $this->db_host = $_SESSION['phpgw_info']['instant_messenger']['server']['db_host']; 
     
    2326                $this->db_pass = $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass']; 
    2427                $this->db_type = $_SESSION['phpgw_info']['instant_messenger']['server']['db_type']; 
     28                $this->user_id = $_SESSION['phpgw_info']['instant_messenger']['user_id']; 
    2529                 
    26                 $this->db = new db();            
     30                $this->db = new db(); 
    2731                $this->db->connect($this->db_name,$this->db_host,$this->db_port,$this->db_user,$this->db_pass,$this->db_type); 
     32                session_write_close();           
    2833        } 
    2934 
     
    5358        { 
    5459                $preferences = $param['preferences']; 
    55                 $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id'];  
     60                $user_id  = $this->user_id; 
    5661                $app_name = $this->name_app(); 
    57  
     62                 
    5863                $query = "insert into phpgw_preferences values('".$user_id."','".$app_name."','".serialize($preferences)."')"; 
    5964                 
    60                 if($this->query_db($query))       
     65                if($this->query_db($query)) 
     66                {  
    6167                        return "true"; 
    62                 else{ 
     68                } 
     69                else 
     70                { 
    6371                        $query = "update phpgw_preferences set preference_value = '".serialize($preferences)."' where preference_app='".$app_name."' and preference_owner='".$user_id."'"; 
    6472                        if($this->query_db($query)) 
     
    7280        { 
    7381                $result = array(); 
    74                 $user_id  = $_SESSION['phpgw_info']['instant_messenger']['user_id']; 
     82                $user_id  = $this->user_id; 
    7583                $app_name = $this->name_app(); 
    7684                 
     
    8391                        $result[] = $this->db->row(); 
    8492 
    85                 if(count($result) > 0){ 
     93                if(count($result) > 0) 
    8694                        return unserialize($result[0]['preference_value']); 
    87                 }else{ 
    88                         return "ch_offline:true;in_time:1;rd_nm:true;rd_ch:false"; 
    89                 } 
    90         } 
     95                else 
     96                        return "ch_offline:true;time_xa_im:1;rd_nm:true;rd_ch:false"; 
     97        }                
    9198         
    9299        function name_app() 
  • trunk/instant_messenger/inc/class.ldap_im.inc.php

    r68 r151  
    66        private $conn; 
    77        private $user; 
     8        private $jid; 
    89        private $password; 
    910         
    1011        function __construct() 
    1112        { 
    12                 $this->ldap_host        = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; 
    13                 $this->ldap_context = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; 
    14                 $this->user             = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 
    15                 $this->password         = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 
     13                session_start(); 
     14                $this->ldap_host                = $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']; 
     15                $this->ldap_context     = $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']; 
     16                $this->user                     = $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']; 
     17                $this->password                 = $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber']; 
     18                $this->jid                              = $_SESSION['phpgw_info']['instant_messenger']['user']; 
    1619                $this->connect_ldap(false); 
     20                session_write_close(); 
    1721        } 
    1822         
     
    3337        } 
    3438         
    35         function get_photo_ldap($user,$getPhoto) 
     39        function get_photo_ldap($pUser,$getPhoto) 
    3640        { 
    37                 $user = ( $user == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user ; 
     41                $user = ( $pUser == "im_avatar" ) ? $this->jid : $pUser ; 
    3842                 
    39                 if ($this->conn) { 
     43                if ($this->conn)  
     44                { 
    4045                        $filter="(&(uid=".$user.")(phpgwAccountType=u))";                
    4146                        $justthese = array("jpegphoto"); 
    42                         $search = ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
    43                         $entry = ldap_first_entry($this->conn, $search); 
     47                        $search = @ldap_search($this->conn,$this->ldap_context, $filter, $justthese); 
     48                        $entry = @ldap_first_entry($this->conn, $search); 
    4449                        $jpeg_data = @ldap_get_values_len($this->conn, $entry, "jpegphoto"); 
    4550                         
    46                         if( count($jpeg_data) > 1){ 
    47  
     51                        if( count($jpeg_data) > 1) 
     52                        { 
    4853                                $photo = imagecreatefromstring($jpeg_data[0]); 
    49                                 if($photo){ 
    50                                         if($getPhoto){ 
     54                                if($photo) 
     55                                { 
     56                                        if($getPhoto) 
     57                                        { 
    5158                                                header("Content-Type: image/jpeg"); 
    5259                                                $width = imagesx($photo); 
     
    5966                                                return;          
    6067                                        }else{ 
    61                                                 return 1; 
     68                                                return "true"; 
    6269                                        }                                
    6370                                }else{ 
    64                                         return 0; 
     71                                        return "false"; 
    6572                                } 
    6673                        }else{ 
    67                                 return 0; 
     74                                return "false"; 
    6875                        } 
    6976                } 
     
    7279        function photo_ldap($user) 
    7380        { 
    74                 $uid = ( $user['uid'] == "user" ) ? $_SESSION['phpgw_info']['instant_messenger']['user'] : $user['uid'] ; 
     81                $uid = ( $user['uid'] == "im_avatar" ) ? $this->jid : $user['uid'] ; 
    7582                return $this->get_photo_ldap($uid,false); 
    7683        } 
     
    143150        function list_organizations_ldap() 
    144151        { 
    145                 $result_org = array(); 
    146                 $i = 0; 
    147                 if ($this->conn) { 
     152                $result_org = "<organizations><ou></ou>"; 
     153 
     154                if ($this->conn)  
     155                { 
    148156                        $filter="ou=*";          
    149157                        $justthese = array("ou"); 
     
    152160                } 
    153161                 
    154                 foreach($entry as $tmp){ 
    155                         if($tmp['ou'][0] != ""){ 
    156                                 $result_org[$i] = $tmp['ou'][0]; 
    157                                 $i++; 
    158                         } 
    159                 } 
    160                 sort($result_org); 
     162                foreach($entry as $tmp) 
     163                        if($tmp['ou'][0] != "") 
     164                                $result_org .= "<ou>" . $tmp['ou'][0] . "</ou>";   
     165 
     166                $result_org .= "</organizations>"; 
     167                 
    161168                return $result_org; 
    162169        } 
     
    176183} 
    177184 
    178 if(trim($_REQUEST['user']) != ""){ 
     185if(trim($_REQUEST['user']) != "") 
     186{ 
    179187        $obj_img = new ldap_im(); 
    180188        $obj_img->get_photo_ldap($_REQUEST['user'],true); 
  • trunk/instant_messenger/inc/im_acl.inc.php

    r75 r151  
    44      if ( $GLOBALS['phpgw_info']['user']['acl'][$i]['appname'] == 'instant_messenger') 
    55      { 
    6                         require_once("im_sessions.inc.php"); 
    7           
     6                   session_start(); 
    87         $webserver_url = $GLOBALS['phpgw_info']['server']['webserver_url']; 
    9          $wz_dragdrop = $webserver_url."/phpgwapi/js/wz_dragdrop/"; 
    108         $webserver_url = ( !empty($webserver_url) ) ? $webserver_url : '/'; 
    11  
    129         if ( strrpos($webserver_url, '/') === false || strrpos($webserver_url, '/') != (strlen($webserver_url)-1) ) 
    13             $webserver_url .= '/'; 
     10                                $webserver_url .= '/'; 
    1411 
    1512         $webserver_url = $webserver_url . 'instant_messenger/'; 
    1613 
    17          require_once("IMConfigure.php"); 
     14                        require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/im_sessions.inc.php'; 
     15                        require_once PHPGW_SERVER_ROOT . '/instant_messenger/inc/load_lang.php'; 
     16                         
     17                        $DOCUMENT_ROOT = PHPGW_SERVER_ROOT .'/instant_messenger/'; 
     18          
     19         $js = array( 
     20                                                        'js/connector.js', 
     21                                                        'js/xtools.js', 
     22                                                        'js/jabber.js', 
     23                                                        'js/client.js', 
     24                                                        'js/images.js', 
     25                                                        'js/dragdrop.js', 
     26                                                        'js/build_win.js', 
     27                                                        'js/templates.js', 
     28                                                        'js/fcommon.js', 
     29                                                        'js/menu_action.js', 
     30                                                        'js/functions.js', 
     31                                                        'js/images.js', 
     32                                                        'js/cookies_im.js', 
     33                                                        'js/load.js',                                                    
     34                    ); 
    1835 
    19          $_transport = TRANSPORT_NON_SECURITY; 
    20          $_port = PORT_NON_SECURITY; 
     36                        print '<script type="text/javascript">var path_im = "'.$webserver_url.'";</script>'; 
     37                        foreach ( $js as $key => $val ) 
     38                                print '<script src="' . $webserver_url . $val . '?' . filemtime($DOCUMENT_ROOT . $val) . '"></script>'; 
     39                         
     40                        print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/window.css">'; 
     41                        print   '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/chat.css">'; 
     42                        print '<link rel="stylesheet" type="text/css" href="' . $webserver_url . 'templates/default/css/common.css">'; 
     43                        print '<script type="text/javascript">setTimeout("client()",1000);</script>';  
    2144 
    22                         $SERVER = "127.0.0.1"; 
    23  
    24                         $fp  = ""; 
    25                         @$fp = stream_socket_client($_transport . "://" . $SERVER . ":" . $_port, $errno, $errstr, 10); 
    26  
    27          if ( $fp ) 
    28          { 
    29             fwrite($fp, "GET /" . CONNECT . ";" . session_id() . " HTTP/1.1\r\nHost: " . $SERVER . ":" . $_port . "\r\nAccept: */*\r\n\r\n"); 
    30  
    31             $js = array( 
    32                         $webserver_url . 'js/XMLTools.js', 
    33                         $webserver_url . 'js/im_functions.js', 
    34                         $webserver_url . 'js/im_fcommon.js', 
    35                         $webserver_url . 'js/im_var_globals.js', 
    36                         $webserver_url . 'js/im_images.js', 
    37                         $webserver_url . 'js/im_smiles.js', 
    38                         $webserver_url . 'js/im_templates.js', 
    39                         $webserver_url . 'js/im_win.js', 
    40                         $webserver_url . 'js/im_menu_action.js', 
    41                         $webserver_url . 'js/im_conf_font.js', 
    42                         $webserver_url . 'js/im_preferences.js', 
    43                         $webserver_url . 'js/im_init.js', 
    44                                                       $webserver_url . 'js/im_subscription.js', 
    45                        ); 
    46  
    47             require_once('load_lang.php'); 
    48  
    49                 print ' 
    50                <link rel="stylesheet" href="' . $webserver_url . 'templates/default/css.css" /> 
    51                <link rel="stylesheet" href="' . $webserver_url . 'templates/default/messenger.css" /> 
    52                <script> 
    53                   var im_path="' . $webserver_url . '"; 
    54                   var ini_wzdd = false; 
    55                   if ( !window.dd ) 
    56                   { 
    57                      ini_wzdd = true; 
    58                      document.write(\'\<script src="' . $wz_dragdrop . 'wz_dragdrop.js"\>\<\/script\>\'); 
    59                      var im_path="' . $webserver_url . '"; 
    60                   } 
    61                </script>'; 
    62           
    63           print ' 
    64                <script> 
    65                   if ( ini_wzdd ) 
    66                      SET_DHTML("backFantom"+NO_DRAG); 
    67                </script>'; 
    68  
    69           foreach ( $js as $key => $val ) 
    70              print '<script src="' . $val . '?' . filemtime($_SERVER['DOCUMENT_ROOT'] . '/' . $val) . '"></script>'; 
    71            
    72          } 
    73          break; 
     45                        session_write_close(); 
    7446      } 
    7547   } 
  • trunk/instant_messenger/inc/im_sessions.inc.php

    r67 r151  
    11<?php 
    22 
    3           $_SESSION['phpgw_info']['instant_messenger']['user']             = $GLOBALS['phpgw_info']['user']['account_lid']; 
    4           $_SESSION['phpgw_info']['instant_messenger']['user_id']                        = $GLOBALS['phpgw_info']['user']['account_id'];          
    5      $_SESSION['phpgw_info']['instant_messenger']['passwd']           = $GLOBALS['phpgw_info']['user']['passwd']; 
    6      $_SESSION['phpgw_info']['instant_messenger']['name_jabber']      = $GLOBALS['phpgw_info']['server']['name_jabber']; 
    7      $_SESSION['phpgw_info']['instant_messenger']['port_jabber']      = $GLOBALS['phpgw_info']['server']['port_jabber']; 
    8      $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']  = $GLOBALS['phpgw_info']['server']['resource_jabber']; 
    9  
    10      # Conf. Ldap 
    11      $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 
    12      $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 
    13      $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 
    14      $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabber']; 
    15      $_SESSION['phpgw_info']['instant_messenger']['size_file_jabber']   = $GLOBALS['phpgw_info']['server']['size_file_jabber'];  
    16  
    17      $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
    18      $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; 
    19      $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; 
    20      $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; 
    21      $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
    22      $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
     3                $_SESSION['phpgw_info']['instant_messenger']['user']             = $GLOBALS['phpgw_info']['user']['account_lid']; 
     4                $_SESSION['phpgw_info']['instant_messenger']['user_id']                   = $GLOBALS['phpgw_info']['user']['account_id'];                
     5                $_SESSION['phpgw_info']['instant_messenger']['passwd']           = $GLOBALS['phpgw_info']['user']['passwd']; 
     6                $_SESSION['phpgw_info']['instant_messenger']['name_jabber']      = $GLOBALS['phpgw_info']['server']['name_jabber']; 
     7                $_SESSION['phpgw_info']['instant_messenger']['port_jabber']      = $GLOBALS['phpgw_info']['server']['port_jabber']; 
     8                $_SESSION['phpgw_info']['instant_messenger']['resource_jabber']  = $GLOBALS['phpgw_info']['server']['resource_jabber']; 
     9                 
     10                $_SESSION['phpgw_info']['instant_messenger']['server_ldap_jabber']   = $GLOBALS['phpgw_info']['server']['server_ldap_jabber']; 
     11                $_SESSION['phpgw_info']['instant_messenger']['context_ldap_jabber']  = $GLOBALS['phpgw_info']['server']['context_ldap_jabber']; 
     12                $_SESSION['phpgw_info']['instant_messenger']['user_ldap_jabber']     = $GLOBALS['phpgw_info']['server']['user_ldap_jabber']; 
     13                $_SESSION['phpgw_info']['instant_messenger']['password_ldap_jabber'] = $GLOBALS['phpgw_info']['server']['password_ldap_jabber']; 
     14                 
     15                $_SESSION['phpgw_info']['instant_messenger']['server']['db_name'] = $GLOBALS['phpgw_info']['server']['db_name']; 
     16                $_SESSION['phpgw_info']['instant_messenger']['server']['db_host'] = $GLOBALS['phpgw_info']['server']['db_host']; 
     17                $_SESSION['phpgw_info']['instant_messenger']['server']['db_port'] = $GLOBALS['phpgw_info']['server']['db_port']; 
     18                $_SESSION['phpgw_info']['instant_messenger']['server']['db_user'] = $GLOBALS['phpgw_info']['server']['db_user']; 
     19                $_SESSION['phpgw_info']['instant_messenger']['server']['db_pass'] = $GLOBALS['phpgw_info']['server']['db_pass']; 
     20                $_SESSION['phpgw_info']['instant_messenger']['server']['db_type'] = $GLOBALS['phpgw_info']['server']['db_type']; 
    2321 
    2422?> 
Note: See TracChangeset for help on using the changeset viewer.