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).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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} 
Note: See TracChangeset for help on using the changeset viewer.