mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 12:16:00 +00:00
Simplify UUID generation in several places.
Replace code using ast_uuid_generate() with simpler and faster code using ast_uuid_generate_str(). The new code avoids a malloc(), free(), and copy. ........ Merged revisions 424103 from http://svn.asterisk.org/svn/asterisk/branches/12 ........ Merged revisions 424105 from http://svn.asterisk.org/svn/asterisk/branches/13 git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@424109 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -1978,11 +1978,7 @@ static int sip_dialog_create_from(pj_pool_t *pool, pj_str_t *from, const char *u
|
|||||||
char uuid_str[AST_UUID_STR_LEN];
|
char uuid_str[AST_UUID_STR_LEN];
|
||||||
|
|
||||||
if (ast_strlen_zero(user)) {
|
if (ast_strlen_zero(user)) {
|
||||||
RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
|
user = ast_uuid_generate_str(uuid_str, sizeof(uuid_str));
|
||||||
if (!uuid) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
user = ast_uuid_to_str(uuid, uuid_str, sizeof(uuid_str));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Parse the provided target URI so we can determine what transport it will end up using */
|
/* Parse the provided target URI so we can determine what transport it will end up using */
|
||||||
@@ -2731,14 +2727,9 @@ int ast_sip_append_body(pjsip_tx_data *tdata, const char *body_text)
|
|||||||
struct ast_taskprocessor *ast_sip_create_serializer(void)
|
struct ast_taskprocessor *ast_sip_create_serializer(void)
|
||||||
{
|
{
|
||||||
struct ast_taskprocessor *serializer;
|
struct ast_taskprocessor *serializer;
|
||||||
RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
|
|
||||||
char name[AST_UUID_STR_LEN];
|
char name[AST_UUID_STR_LEN];
|
||||||
|
|
||||||
if (!uuid) {
|
ast_uuid_generate_str(name, sizeof(name));
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
ast_uuid_to_str(uuid, name, sizeof(name));
|
|
||||||
|
|
||||||
serializer = ast_threadpool_serializer(name, sip_threadpool);
|
serializer = ast_threadpool_serializer(name, sip_threadpool);
|
||||||
if (!serializer) {
|
if (!serializer) {
|
||||||
|
@@ -443,15 +443,16 @@ static struct ast_sip_authenticator digest_authenticator = {
|
|||||||
|
|
||||||
static int build_entity_id(void)
|
static int build_entity_id(void)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ast_uuid *, uu, ast_uuid_generate(), ast_free_ptr);
|
char *eid;
|
||||||
RAII_VAR(char *, eid, ao2_alloc(AST_UUID_STR_LEN, NULL), ao2_cleanup);
|
|
||||||
|
|
||||||
if (!uu || !eid) {
|
eid = ao2_alloc(AST_UUID_STR_LEN, NULL);
|
||||||
|
if (!eid) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ast_uuid_to_str(uu, eid, AST_UUID_STR_LEN);
|
ast_uuid_generate_str(eid, AST_UUID_STR_LEN);
|
||||||
ao2_global_obj_replace_unref(entity_id, eid);
|
ao2_global_obj_replace_unref(entity_id, eid);
|
||||||
|
ao2_ref(eid, -1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -2188,6 +2188,7 @@ static void subscription_datastore_destroy(void *obj)
|
|||||||
struct ast_datastore *ast_sip_subscription_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
|
struct ast_datastore *ast_sip_subscription_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
|
RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
|
||||||
|
char uuid_buf[AST_UUID_STR_LEN];
|
||||||
const char *uid_ptr = uid;
|
const char *uid_ptr = uid;
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
@@ -2202,13 +2203,7 @@ struct ast_datastore *ast_sip_subscription_alloc_datastore(const struct ast_data
|
|||||||
datastore->info = info;
|
datastore->info = info;
|
||||||
if (ast_strlen_zero(uid)) {
|
if (ast_strlen_zero(uid)) {
|
||||||
/* They didn't provide an ID so we'll provide one ourself */
|
/* They didn't provide an ID so we'll provide one ourself */
|
||||||
struct ast_uuid *uuid = ast_uuid_generate();
|
uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
|
||||||
char uuid_buf[AST_UUID_STR_LEN];
|
|
||||||
if (!uuid) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
uid_ptr = ast_uuid_to_str(uuid, uuid_buf, sizeof(uuid_buf));
|
|
||||||
ast_free(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datastore->uid = ast_strdup(uid_ptr);
|
datastore->uid = ast_strdup(uid_ptr);
|
||||||
|
@@ -550,6 +550,7 @@ static void session_datastore_destroy(void *obj)
|
|||||||
struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
|
struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore_info *info, const char *uid)
|
||||||
{
|
{
|
||||||
RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
|
RAII_VAR(struct ast_datastore *, datastore, NULL, ao2_cleanup);
|
||||||
|
char uuid_buf[AST_UUID_STR_LEN];
|
||||||
const char *uid_ptr = uid;
|
const char *uid_ptr = uid;
|
||||||
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
@@ -564,13 +565,7 @@ struct ast_datastore *ast_sip_session_alloc_datastore(const struct ast_datastore
|
|||||||
datastore->info = info;
|
datastore->info = info;
|
||||||
if (ast_strlen_zero(uid)) {
|
if (ast_strlen_zero(uid)) {
|
||||||
/* They didn't provide an ID so we'll provide one ourself */
|
/* They didn't provide an ID so we'll provide one ourself */
|
||||||
struct ast_uuid *uuid = ast_uuid_generate();
|
uid_ptr = ast_uuid_generate_str(uuid_buf, sizeof(uuid_buf));
|
||||||
char uuid_buf[AST_UUID_STR_LEN];
|
|
||||||
if (!uuid) {
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
uid_ptr = ast_uuid_to_str(uuid, uuid_buf, sizeof(uuid_buf));
|
|
||||||
ast_free(uuid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
datastore->uid = ast_strdup(uid_ptr);
|
datastore->uid = ast_strdup(uid_ptr);
|
||||||
|
Reference in New Issue
Block a user