]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
stasis: Remove stringfields and lock from change message.
authorJoshua C. Colp <jcolp@digium.com>
Sun, 18 Nov 2018 23:53:14 +0000 (19:53 -0400)
committerJoshua Colp <jcolp@digium.com>
Mon, 19 Nov 2018 17:00:28 +0000 (12:00 -0500)
When a subscribe or unsubscribe occurs a message is published
containing this information. This change makes it so that the
message no longer uses stringfields or a lock, as both are not
really needed for the message.

Change-Id: I3f4831931d79f94fd979baf48048738df5dc1632

include/asterisk/stasis.h
main/stasis.c

index ebd00ee23d19901ef95847f09ab40300fa9ab0c9..85e78dcd11955d51a2da5dc8662350d0b5b3797c 100644 (file)
@@ -806,11 +806,9 @@ int stasis_subscription_final_message(struct stasis_subscription *sub, struct st
  * \since 12
  */
 struct stasis_subscription_change {
-       AST_DECLARE_STRING_FIELDS(
-               AST_STRING_FIELD(uniqueid);     /*!< The unique ID associated with this subscription */
-               AST_STRING_FIELD(description);  /*!< The description of the change to the subscription associated with the uniqueid */
-       );
-       struct stasis_topic *topic;             /*!< The topic the subscription is/was subscribing to */
+       struct stasis_topic *topic; /*!< The topic the subscription is/was subscribing to */
+       char *uniqueid;             /*!< The unique ID associated with this subscription */
+       char description[0];        /*!< The description of the change to the subscription associated with the uniqueid */
 };
 
 /*!
index 93112d98ebb9334c9a48771b05243853eb47052a..417caaf19521c3124aaebd2e6a36436f328d2528 100644 (file)
@@ -1077,22 +1077,23 @@ static void subscription_change_dtor(void *obj)
 {
        struct stasis_subscription_change *change = obj;
 
-       ast_string_field_free_memory(change);
        ao2_cleanup(change->topic);
 }
 
 static struct stasis_subscription_change *subscription_change_alloc(struct stasis_topic *topic, const char *uniqueid, const char *description)
 {
+       size_t description_len = strlen(description) + 1;
        struct stasis_subscription_change *change;
 
-       change = ao2_alloc(sizeof(struct stasis_subscription_change), subscription_change_dtor);
-       if (!change || ast_string_field_init(change, 128)) {
-               ao2_cleanup(change);
+       change = ao2_alloc_options(sizeof(*change) + description_len + strlen(uniqueid) + 1,
+               subscription_change_dtor, AO2_ALLOC_OPT_LOCK_NOLOCK);
+       if (!change) {
                return NULL;
        }
 
-       ast_string_field_set(change, uniqueid, uniqueid);
-       ast_string_field_set(change, description, description);
+       strcpy(change->description, description); /* SAFE */
+       change->uniqueid = change->description + description_len;
+       strcpy(change->uniqueid, uniqueid); /* SAFE */
        ao2_ref(topic, +1);
        change->topic = topic;