* @revision 04 * @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 */ require_once ("oscar/tlv.php"); require_once ("oscar/common.php"); require_once ("oscar/snac/helper/tlv.php"); /** * Generic container for SSI Items * * @class OSCAR_Item **/ class Oscar_SNAC_Feedbag_Item extends Oscar_SNAC_Helper_TLV { public $Name = ""; public $GroupID = 0; public $ItemID = 0; public $Type = 0; public $TLVs = array (); // {{{ getTLVClasses /** * Retrive a list of prefered TLV-Types for this SNAC * * @access protected * @return array */ protected function getTLVClasses () { return Oscar_TLV::getClass ("FEEDBAG__ATTRIBUTES"); } // }}} // {{{ peek /** * Try to parse an OSCAR_Item from input * * @param string $Data * * @access public * @return object */ public static function peek (&$Data) { // Check for minimum length if (strlen ($Data) < 11) return false; // Make a copy of input $buf = $Data; // Create a new Item $Item = new Oscar_SNAC_Feedbag_Item (null); // Make a copy of input $Item->Data = $Data; if (!$Item->parse ()) return false; // Copy back $Data = $Item->Data; $Item->Data = ""; // Return the new item return $Item; } // }}} // {{{ parse /** * Parse an OSCAR_Item * * @access public * @return bool */ public function parse () { // Get basic properties from data $this->Name = Oscar_Common::string16 ($this->Data, 0, true); $this->GroupID = Oscar_Common::str2int16 ($this->Data, 0, true); $this->ItemID = Oscar_Common::str2int16 ($this->Data, 0, true); $this->Type = Oscar_Common::str2int16 ($this->Data, 0, true); // Check length of additional data $Length = Oscar_Common::str2int16 ($this->Data, 0, true); // Do a small validation #if (($this->Name == "") || ($Length > strlen ($this->Data))) if ($Length > strlen ($this->Data)) return false; // Backup a data-block $Data = substr ($this->Data, $Length); $this->Data = substr ($this->Data, 0, $Length); // Parse TLV-Block parent::parse (); // Copy back the backup $this->Data = $Data; return true; } // }}} // {{{ generate /** * Convert this item to a string * * @access public * @return string */ public function generate () { // Generate TLV-Block $this->Prepend = ""; $TLV_Block = parent::generate (false); return Oscar_Common::toString16 ($this->Name) . Oscar_Common::int16tostr ($this->GroupID) . Oscar_Common::int16tostr ($this->ItemID) . Oscar_Common::int16tostr ($this->Type) . Oscar_Common::toString16 ($TLV_Block); } // }}} } ?>