diff options
author | Richard Mudgett <rmudgett@digium.com> | 2013-03-28 23:59:20 +0000 |
---|---|---|
committer | Richard Mudgett <rmudgett@digium.com> | 2013-03-28 23:59:20 +0000 |
commit | a1c94fece82f2445e538de0c93345d34c4abdf17 (patch) | |
tree | 5e1f771efae1c221db8ecc3efaa4eb00632e19d8 /main/uuid.c | |
parent | 71206544a770eb4004294ed13613a7cde6e0e056 (diff) |
Add uuid wrapper API call ast_uuid_generate_str().
* Updated test_uuid.c to test the new API call.
* Made system use the new API call to eliminate "10's of lines" where
used.
* Fixed untested ast_strdup() return in stasis_subscribe() by eliminating
the need for it. struct stasis_subscription now contains the uniqueid[]
string.
* Fixed some issues in exchangecal_write_event():
Create uid with enough space for a UUID string to avoid a realloc.
Fix off by one error if the calendar event provided a UUID string.
There is no need to check for NULL before calling ast_free().
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@384302 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/uuid.c')
-rw-r--r-- | main/uuid.c | 37 |
1 files changed, 30 insertions, 7 deletions
diff --git a/main/uuid.c b/main/uuid.c index 46ac63d20..e95a4265e 100644 --- a/main/uuid.c +++ b/main/uuid.c @@ -38,13 +38,17 @@ struct ast_uuid { uuid_t uu; }; -struct ast_uuid *ast_uuid_generate(void) +/*! + * \internal + * \brief Generate a UUID. + * \since 12.0.0 + * + * \param uuid Fill this with a generated UUID. + * + * \return Nothing + */ +static void generate_uuid(struct ast_uuid *uuid) { - struct ast_uuid *uuid = ast_malloc(sizeof(*uuid)); - - if (!uuid) { - return NULL; - } /* libuuid provides three methods of generating uuids, * uuid_generate(), uuid_generate_random(), and uuid_generate_time(). * @@ -114,6 +118,16 @@ struct ast_uuid *ast_uuid_generate(void) if (!has_dev_urandom) { ast_mutex_unlock(&uuid_lock); } +} + +struct ast_uuid *ast_uuid_generate(void) +{ + struct ast_uuid *uuid = ast_malloc(sizeof(*uuid)); + + if (!uuid) { + return NULL; + } + generate_uuid(uuid); return uuid; } @@ -124,10 +138,19 @@ char *ast_uuid_to_str(const struct ast_uuid *uuid, char *buf, size_t size) return buf; } +char *ast_uuid_generate_str(char *buf, size_t size) +{ + struct ast_uuid uuid; + + generate_uuid(&uuid); + return ast_uuid_to_str(&uuid, buf, size); +} + struct ast_uuid *ast_str_to_uuid(const char *str) { struct ast_uuid *uuid = ast_malloc(sizeof(*uuid)); int res; + if (!uuid) { return NULL; } @@ -143,6 +166,7 @@ struct ast_uuid *ast_str_to_uuid(const char *str) struct ast_uuid *ast_uuid_copy(const struct ast_uuid *src) { struct ast_uuid *dst = ast_malloc(sizeof(*dst)); + if (!dst) { return NULL; } @@ -202,5 +226,4 @@ void ast_uuid_init(void) uuid_generate_random(uu); ast_debug(1, "UUID system initiated\n"); - return; } |