/** * Generate UID for new subscriber * * @static */ function get_uid($username, $realm) { global $config, $data; $an =& $config->attr_names; $data->add_method('get_new_user_id'); $data->add_method('does_uid_exists'); $ga =& Global_attrs::singleton(); if (false === ($format = $ga->get_attribute($an['uid_format']))) { return false; } switch ($format) { /* numeric UID */ case 1: if (false === ($uid = $data->get_new_user_id(null))) { return false; } break; /* UUID by rfc4122 */ /* UUID by rfc4122 */ case 2: $uid = rfc4122_uuid(); /* check if uid doesn't exists */ if (0 > ($exists = $data->does_uid_exists($uid, null))) { return false; } while ($exists) { $uid = rfc4122_uuid(); if (0 > ($exists = $data->does_uid_exists($uid, null))) { return false; } } break; /* UID in format 'username@realm' */ /* UID in format 'username@realm' */ case 0: default: /* if format of UIDs is not set, assume the first choice */ $uid = $username . "@" . $realm; /* check if uid doesn't exists */ if (0 > ($exists = $data->does_uid_exists($uid, null))) { return false; } $i = 0; while ($exists) { $uid = $username . "@" . $realm . "_" . $i++; if (0 > ($exists = $data->does_uid_exists($uid, null))) { return false; } } break; } return $uid; }
/** * Generate DID for new domain * * @static * @param string domainname new name of domain * @return string did or FALSE on error */ function generate_new_did($domainname) { global $data, $config; $an =& $config->attr_names; $errors = array(); /* get format of did to generate */ $ga =& Global_attrs::singleton(); if (false === ($format = $ga->get_attribute($an['did_format']))) { return false; } switch ($format) { /* numeric DID */ case 1: $data->add_method('get_new_domain_id'); if (false === ($did = $data->get_new_domain_id(null, $errors))) { ErrorHandler::add_error($errors); return false; } break; /* UUID by rfc4122 */ /* UUID by rfc4122 */ case 2: $did = rfc4122_uuid(); /* check if did doesn't exists */ $dh =& Domains::singleton(); if (false === ($dids = $dh->get_all_dids())) { return false; } while (in_array($did, $dids, true)) { $did = rfc4122_uuid(); } break; /* DID as 'domainname' */ /* DID as 'domainname' */ case 0: default: /* if format of UIDs is not set, assume the first choice */ if (!$domainname) { $domainname = "default_domain"; } // if domain name is not provided $did = $domainname; /* check if did doesn't exists */ $dh =& Domains::singleton(); if (false === ($dids = $dh->get_all_dids())) { return false; } $i = 0; while (in_array($did, $dids, true)) { $did = $domainname . "_" . $i++; } break; } return $did; }