mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
Make sorcery details opaque and add extended fields.
Sorcery specific object information is now opaque and allocated with the object. This means that modules do not need to be recompiled if the sorcery specific part is changed. It also means that sorcery can store additional information on objects and ensure it is freed or the reference count decreased when the object goes away. To facilitate the above a generic sorcery allocator function has been added which also ensures that allocated objects do not have a lock. Extended fields have been added thanks to all of the above which allows specific fields to be marked as extended, and thus simply stored as-is within the object. Type safety is *NOT* enforced on these fields. A consumer of them has to query and ultimately perform their own safety check. What does this mean? Extra modules can extend already defined structures without having to modify them. Tests have also been included to verify extended field functionality. Review: https://reviewboard.asterisk.org/r/2585/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@392586 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -32,7 +32,7 @@ static void auth_destroy(void *obj)
|
||||
|
||||
static void *auth_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_auth *auth = ao2_alloc(sizeof(*auth), auth_destroy);
|
||||
struct ast_sip_auth *auth = ast_sorcery_generic_alloc(sizeof(*auth), auth_destroy);
|
||||
|
||||
if (!auth) {
|
||||
return NULL;
|
||||
|
@@ -33,7 +33,7 @@ static void domain_alias_destroy(void *obj)
|
||||
|
||||
static void *domain_alias_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_domain_alias *alias = ao2_alloc(sizeof(*alias), domain_alias_destroy);
|
||||
struct ast_sip_domain_alias *alias = ast_sorcery_generic_alloc(sizeof(*alias), domain_alias_destroy);
|
||||
|
||||
if (!alias) {
|
||||
return NULL;
|
||||
|
@@ -62,7 +62,7 @@ static void transport_destroy(void *obj)
|
||||
/*! \brief Allocator for transport */
|
||||
static void *transport_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_transport *transport = ao2_alloc(sizeof(*transport), transport_destroy);
|
||||
struct ast_sip_transport *transport = ast_sorcery_generic_alloc(sizeof(*transport), transport_destroy);
|
||||
|
||||
if (!transport) {
|
||||
return NULL;
|
||||
|
@@ -41,7 +41,7 @@ static void aor_destroy(void *obj)
|
||||
/*! \brief Allocator for AOR */
|
||||
static void *aor_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_aor *aor = ao2_alloc_options(sizeof(struct ast_sip_aor), aor_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
|
||||
struct ast_sip_aor *aor = ast_sorcery_generic_alloc(sizeof(struct ast_sip_aor), aor_destroy);
|
||||
if (!aor) {
|
||||
return NULL;
|
||||
}
|
||||
@@ -60,7 +60,7 @@ static void contact_destroy(void *obj)
|
||||
/*! \brief Allocator for contact */
|
||||
static void *contact_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_contact *contact = ao2_alloc_options(sizeof(*contact), contact_destroy, AO2_ALLOC_OPT_LOCK_NOLOCK);
|
||||
struct ast_sip_contact *contact = ast_sorcery_generic_alloc(sizeof(*contact), contact_destroy);
|
||||
|
||||
if (!contact) {
|
||||
return NULL;
|
||||
|
@@ -515,7 +515,7 @@ static int named_groups_handler(const struct aco_option *opt,
|
||||
|
||||
static void *sip_nat_hook_alloc(const char *name)
|
||||
{
|
||||
return ao2_alloc(sizeof(struct ast_sip_nat_hook), NULL);
|
||||
return ast_sorcery_generic_alloc(sizeof(struct ast_sip_nat_hook), NULL);
|
||||
}
|
||||
|
||||
/*! \brief Destructor function for persistent endpoint information */
|
||||
@@ -722,7 +722,7 @@ static void endpoint_destructor(void* obj)
|
||||
|
||||
void *ast_sip_endpoint_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_endpoint *endpoint = ao2_alloc(sizeof(*endpoint), endpoint_destructor);
|
||||
struct ast_sip_endpoint *endpoint = ast_sorcery_generic_alloc(sizeof(*endpoint), endpoint_destructor);
|
||||
if (!endpoint) {
|
||||
return NULL;
|
||||
}
|
||||
|
@@ -42,8 +42,7 @@ static int qualify_contact(struct ast_sip_contact *contact);
|
||||
*/
|
||||
static void *contact_status_alloc(const char *name)
|
||||
{
|
||||
struct ast_sip_contact_status *status = ao2_alloc_options(
|
||||
sizeof(*status), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
|
||||
struct ast_sip_contact_status *status = ast_sorcery_generic_alloc(sizeof(*status), NULL);
|
||||
|
||||
if (!status) {
|
||||
ast_log(LOG_ERROR, "Unable to allocate ast_sip_contact_status\n");
|
||||
|
Reference in New Issue
Block a user