* @revision 03 * @license http://creativecommons.org/licenses/by-sa/3.0/de/ Creative Commons Attribution-Share Alike 3.0 Germany * @homepage http://oss.tiggerswelt.net/oscar/ * @copyright Copyright © 2009 tiggersWelt.net **/ class Oscar_SNAC_Helper_TLV extends Oscar_SNAC { protected $TLVs = array (); protected $Prefered_TLV_Types = null; protected $Prepend = ""; // {{{ parse /** * Parse the response * * @access public * @return void */ public function parse () { if ($this->Prefered_TLV_Types === null) $this->Prefered_TLV_Types = $this->getTLVClasses (); $TLVs = Oscar_TLV::parseTLVs ($this->Data, $this->Parent, $this->Prefered_TLV_Types); foreach ($TLVs as $TLV) self::addTLV ($TLV); } // }}} // {{{ generate /** * Prepare for transmission * * @param bool $Inherit (optional) Inherit to our parent * * @access public * @return string */ public function generate ($Inherit = true) { $this->Data = $this->Prepend; foreach ($this->TLVs as $TLV) if (is_object ($TLV)) $this->Data .= $TLV->generate (); if (!$Inherit) return $this->Data; return parent::generate (); } // }}} // {{{ getTLVClasses /** * Retrive a list of prefered TLV-Types for this SNAC * * @access protected * @return array */ protected function getTLVClasses () { return array (); } // }}} // {{{ findTLV /** * Try to find a specific TLV in our local storage * * @param string $Type * * @access public * @return object */ public function findTLV ($Type) { foreach ($this->TLVs as $ID=>$TLV) if (is_a ($TLV, $Type)) return $this->TLVs [$ID]; return null; } // }}} // {{{ parseBuddyInfo /** * Get NickInfo from our data * * @param protected * @return void */ protected function parseBuddyInfo () { // Get the User-Info $this->Username = Oscar_Common::string08 ($this->Data, 0, true); $this->Warnlevel = Oscar_Common::str2int16 ($this->Data, 0, true); // Get all TLVs $Prefered = Oscar_TLV::getClass ("NICK_INFO_TAGS"); $TLVs = Oscar_TLV::parseTLVBlock ($this->Data, $this->getOSCAR (), true, $Prefered); // Add TLVs to local storage foreach ($TLVs as $TLV) self::addTLV ($TLV); // Forward buddy-info to our roster if (is_object ($Oscar = $this->getParent ()) && is_object ($Roster = $Oscar->getRoster ()) && is_object ($User = $Roster->getContact ($this->Username))) $User->update ($this); } // }}} public function addTLV ($TLV) { $this->TLVs [] = $TLV; } public function addTLVs ($TLVs) { foreach ($TLVs as $TLV) $this->addTLV ($TLV); } function tlvDebug () { foreach ($this->TLVs as $TLV) print " " . $TLV->toString () . "\n"; } // {{{ getTLVs /** * Retrive all TLVs from this object * * @access public * @return array */ public function getTLVs () { return $this->TLVs; } // }}} } ?>