}
/**
- * Generates a unique ID for the given information.
- *
- * @param string $type The type of the object to create.
- * @param array $info Any additional information about the object to create.
- *
- * @return string The UID.
- *
- * @throws Horde_Kolab_Server_Exception
- */
- public function generateUid($type, $info)
- {
- if (!class_exists($type)) {
- $result = Horde_Kolab_Server_Object::loadClass($type);
- }
-
- $id = call_user_func(array($type, 'generateId'), $info);
-
- return $this->generateServerUid($type, $id, $info);
- }
-
- /**
* Add a Kolab object.
*
* @param array $info The object to store.
'The type of a new object must be specified!');
}
- $uid = $this->generateUid($info['type'], $info);
-
- $object = &Horde_Kolab_Server_Object::factory($info['type'], $uid, $this);
+ $object = &Horde_Kolab_Server_Object::factory($info['type'], null, $this, $info);
if ($object->exists()) {
throw new Horde_Kolab_Server_Exception(
sprintf(_("The object with the uid \"%s\" does already exist!"),
- $uid));
+ $object->get(Horde_Kolab_Server_Object::ATTRIBUTE_UID)));
}
unset($info['type']);
$object->save($info);
*
* @throws Horde_Kolab_Server_Exception
*/
- protected function generateServerUid($type, $id, $info)
+ public function generateServerUid($type, $id, $info)
{
return $this->structure->generateServerUid($type, $id, $info);
}
* @param string $uid UID of the object.
* @param array $data A possible array of data for the object
*/
- public function __construct(&$server, $uid = null, $data = null)
+ public function __construct(&$server, $uid = null, $data = false)
{
$this->server = &$server;
if (empty($uid)) {
- if (empty($data) || !isset($data[self::ATTRIBUTE_UID])) {
- throw new Horde_Kolab_Server_Exception(_('Specify either the UID or a search result!'));
- }
- if (is_array($data[self::ATTRIBUTE_UID])) {
- $this->uid = $data[self::ATTRIBUTE_UID][0];
+ if (isset($data[self::ATTRIBUTE_UID])) {
+ if (is_array($data[self::ATTRIBUTE_UID])) {
+ $this->uid = $data[self::ATTRIBUTE_UID][0];
+ } else {
+ $this->uid = $data[self::ATTRIBUTE_UID];
+ }
} else {
- $this->uid = $data[self::ATTRIBUTE_UID];
+ $this->uid = $this->server->generateServerUid(get_class($this),
+ $this->generateId($data),
+ $data);
}
- $this->_cache = $data;
} else {
$this->uid = $uid;
}
+ $this->_cache = $data;
list($this->attributes, $this->attribute_map) = $server->getAttributes(get_class($this));
}
*
* @return string The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
if (!empty($info[self::ATTRIBUTE_ID])) {
- return $info[self::ATTRIBUTE_ID];
+ return $this->server->structure->quoteForUid($info[self::ATTRIBUTE_ID]);
}
- return hash('sha256', uniqid(mt_rand(), true));
+ return $this->server->structure->quoteForUid(hash('sha256', uniqid(mt_rand(), true)));
}
/**
*
* @return string|PEAR_Error The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_CN], " \t\n\r\0\x0B,");
}
*
* @return string|PEAR_Error The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
$id_mapfields = array(self::ATTRIBUTE_GIVENNAME,
self::ATTRIBUTE_SN);
$fieldarray = array();
foreach ($id_mapfields as $mapfield) {
if (isset($info[$mapfield])) {
- $fieldarray[] = $info[$mapfield];
+ $fieldarray[] = $this->server->structure->quoteForUid($info[$mapfield]);
} else {
$fieldarray[] = '';
}
return trim(vsprintf($id_format, $fieldarray), " \t\n\r\0\x0B,");
}
+
}
\ No newline at end of file
*
* @return string|PEAR_Error The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
global $conf;
$fieldarray = array();
foreach ($id_mapfields as $mapfield) {
if (isset($info[$mapfield])) {
- $fieldarray[] = $info[$mapfield];
+ $fieldarray[] = $this->server->structure->quoteForUid($info[$mapfield]);
} else {
$fieldarray[] = '';
}
*
* @return string|PEAR_Error The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
if (isset($info[self::ATTRIBUTE_MAIL])) {
- return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_MAIL], " \t\n\r\0\x0B,");
+ return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid(trim($info[self::ATTRIBUTE_MAIL]), " \t\n\r\0\x0B,");
} else {
- return trim(self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_CN], " \t\n\r\0\x0B,");
+ return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid(trim($info[self::ATTRIBUTE_CN]), " \t\n\r\0\x0B,");
}
}
*
* @return string|PEAR_Error The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
- return trim(self::ATTRIBUTE_CN . '=' . $info['cn'], " \t\n\r\0\x0B,");
+ return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid(trim($info['cn'], " \t\n\r\0\x0B,"));
}
/**
*
* @return string The ID.
*/
- public static function generateId($info)
+ public function generateId($info)
{
if (!empty($info[self::ATTRIBUTE_CN])) {
- return self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_CN];
+ return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid($info[self::ATTRIBUTE_CN]);
}
- return self::ATTRIBUTE_CN . '=' . $info[self::ATTRIBUTE_SN];
+ return self::ATTRIBUTE_CN . '=' . $this->server->structure->quoteForUid($info[self::ATTRIBUTE_SN]);
}
/**
* @throws Horde_Kolab_Server_Exception If the given type is unknown.
*/
abstract public function generateServerUid($type, $id, $info);
+
+ /**
+ * Quote an UID part.
+ *
+ * @param string $id The UID part.
+ *
+ * @return string The quoted part.
+ */
+ abstract public function quoteForUid($id);
+
+ /**
+ * Quote an filter part.
+ *
+ * @param string $part The filter part.
+ *
+ * @return string The quoted part.
+ */
+ abstract public function quoteForFilter($part);
}
if (empty($info['user_type'])) {
return parent::generateServerUid($type, $id, $info);
} else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_INTERNAL) {
- return sprintf('%s,cn=internal,%s', $id, $this->server->getBaseUid());
+ return parent::generateServerUid($type,
+ sprintf('%s,cn=internal', $id),
+ $info);
} else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_GROUP) {
- return sprintf('%s,cn=groups,%s', $id, $this->server->getBaseUid());
+ return parent::generateServerUid($type,
+ sprintf('%s,cn=groups', $id),
+ $info);
} else if ($info['user_type'] == Horde_Kolab_Server_Object_Kolab_User::USERTYPE_RESOURCE) {
- return sprintf('%s,cn=resources,%s', $id, $this->server->getBaseUid());
+ return parent::generateServerUid($type,
+ sprintf('%s,cn=resources', $id),
+ $info);
} else {
return parent::generateServerUid($type, $id, $info);
}
case 'Horde_Kolab_Server_Object_Kolab_Address':
- return sprintf('%s,cn=external,%s', $id, $this->server->getBaseUid());
+ return parent::generateServerUid($type,
+ sprintf('%s,cn=external', $id),
+ $info);
case 'Horde_Kolab_Server_Object_Kolabgroupofnames':
case 'Horde_Kolab_Server_Object_Kolab_Distlist':
if (!isset($info['visible']) || !empty($info['visible'])) {
return parent::generateServerUid($type, $id, $info);
} else {
- return sprintf('%s,cn=internal,%s', $id, $this->server->getBaseUid());
+ return parent::generateServerUid($type,
+ sprintf('%s,cn=internal', $id),
+ $info);
}
case 'Horde_Kolab_Server_Object_Kolabsharedfolder':
case 'Horde_Kolab_Server_Object_Kolab_Administrator':
{
return sprintf('%s,%s', $id, $this->server->getBaseUid());
}
+
+ /**
+ * Quote an UID part.
+ *
+ * @param string $id The UID part.
+ *
+ * @return string The UID part.
+ */
+ public function quoteForUid($id)
+ {
+ require_once 'Net/LDAP2/Util.php';
+
+ $id = Net_LDAP2_Util::escape_dn_value($id);
+ return $id[0];
+ }
+
+ /**
+ * Quote an filter part.
+ *
+ * @param string $part The filter part.
+ *
+ * @return string The quoted part.
+ */
+ public function quoteForFilter($part)
+ {
+ require_once 'Net/LDAP2/Util.php';
+
+ $part = Net_LDAP2_Util::escape_filter_value($part);
+ return $part[0];
+ }
}