Merge "res_pjsip_registrar.c: Update remove_existing AOR contact handling."
authorJenkins2 <jenkins2@gerrit.asterisk.org>
Wed, 11 Oct 2017 11:49:54 +0000 (06:49 -0500)
committerGerrit Code Review <gerrit2@gerrit.digium.api>
Wed, 11 Oct 2017 11:49:54 +0000 (06:49 -0500)
16 files changed:
configs/samples/res_config_sqlite.conf.sample
contrib/scripts/sip_to_pjsip/sip_to_pjsip.py
include/asterisk/cdr.h
include/asterisk/res_pjsip.h
include/asterisk/res_pjsip_session.h
main/cdr.c
main/tcptls.c
res/res_pjproject.c
res/res_pjsip.c
res/res_pjsip.exports.in
res/res_pjsip/include/res_pjsip_private.h
res/res_pjsip/pjsip_configuration.c
res/res_pjsip/pjsip_message_filter.c
res/res_pjsip/pjsip_session.c [new file with mode: 0644]
res/res_pjsip_session.c
res/res_pjsip_session.exports.in

index 04e6ae2..2d14d46 100644 (file)
@@ -8,4 +8,4 @@ dbfile => /var/lib/asterisk/sqlite.db
 ; extconfig.conf, the value given here is used. If cdr_table is omitted, CDR
 ; support is simply disabled.
 config_table => ast_config
-cdr_table => ast_cdr
+; cdr_table => ast_cdr
index 98a5e95..eb3aab3 100755 (executable)
@@ -116,6 +116,27 @@ def set_dtmfmode(key, val, section, pjsip, nmapped):
         set_value(key, 'none', section, pjsip, nmapped)
 
 
+def setup_udptl(section, pjsip, nmapped):
+    """Sets values from udptl into the appropriate pjsip.conf options."""
+    try:
+        val = sip.get(section, 't38pt_udptl')[0]
+    except LookupError:
+        try:
+             val = sip.get('general', 't38pt_udptl')[0]
+        except LookupError:
+            return
+
+    ec = 'none'
+    if 'yes' in val:
+        set_value('t38_udptl', 'yes', section, pjsip, nmapped)
+    if 'no' in val:
+        set_value('t38_udptl', 'no', section, pjsip, nmapped)
+    if 'redundancy' in val:
+        ec = 'redundancy'
+    if 'fec' in val:
+        ec = 'fec'
+    set_value('t38_udptl_ec', ec, section, pjsip, nmapped)
+
 def from_nat(key, val, section, pjsip, nmapped):
     """Sets values from nat into the appropriate pjsip.conf options."""
     # nat from sip.conf can be comma separated list of values:
@@ -387,6 +408,7 @@ peer_map = [
     ['allow',              merge_value],
     ['nat',                from_nat],            # rtp_symmetric, force_rport,
                                                  # rewrite_contact
+    ['rtptimeout',         set_value('rtp_timeout')],
     ['icesupport',         set_value('ice_support')],
     ['autoframing',        set_value('use_ptime')],
     ['outboundproxy',      set_value('outbound_proxy')],
@@ -1068,6 +1090,7 @@ def map_peer(sip, section, pjsip, nmapped):
         except LookupError:
             pass  # key not found in sip.conf
 
+    setup_udptl(section, pjsip, nmapped)
 
 def find_non_mapped(sections, nmapped):
     """
@@ -1101,6 +1124,13 @@ def map_system(sip, pjsip, nmapped):
     except LookupError:
         pass
 
+
+    try:
+        sipdebug = sip.get('general', 'sipdebug')[0]
+        set_value('debug', sipdebug, 'global', pjsip, nmapped, 'global')
+    except LookupError:
+        pass
+
     try:
         useroption_parsing = sip.get('general', 'legacy_useroption_parsing')[0]
         set_value('ignore_uri_user_options', useroption_parsing, 'global', pjsip, nmapped, 'global')
index f752f7f..e10da82 100644 (file)
 
 /*! \brief CDR engine settings */
 enum ast_cdr_settings {
-       CDR_ENABLED = 1 << 0,               /*< Enable CDRs */
-       CDR_BATCHMODE = 1 << 1,             /*< Whether or not we should dispatch CDRs in batches */
-       CDR_UNANSWERED = 1 << 2,            /*< Log unanswered CDRs */
-       CDR_CONGESTION = 1 << 3,            /*< Treat congestion as if it were a failed call */
-       CDR_END_BEFORE_H_EXTEN = 1 << 4,    /*< End the CDR before the 'h' extension runs */
-       CDR_INITIATED_SECONDS = 1 << 5,     /*< Include microseconds into the billing time */
-       CDR_DEBUG = 1 << 6,                 /*< Enables extra debug statements */
+       CDR_ENABLED = 1 << 0,               /*!< Enable CDRs */
+       CDR_BATCHMODE = 1 << 1,             /*!< Whether or not we should dispatch CDRs in batches */
+       CDR_UNANSWERED = 1 << 2,            /*!< Log unanswered CDRs */
+       CDR_CONGESTION = 1 << 3,            /*!< Treat congestion as if it were a failed call */
+       CDR_END_BEFORE_H_EXTEN = 1 << 4,    /*!< End the CDR before the 'h' extension runs */
+       CDR_INITIATED_SECONDS = 1 << 5,     /*!< Include microseconds into the billing time */
+       CDR_DEBUG = 1 << 6,                 /*!< Enables extra debug statements */
 };
 
 /*! \brief CDR Batch Mode settings */
 enum ast_cdr_batch_mode_settings {
-       BATCH_MODE_SCHEDULER_ONLY = 1 << 0, /*< Don't spawn a thread to handle the batches - do it on the scheduler */
-       BATCH_MODE_SAFE_SHUTDOWN = 1 << 1,  /*< During safe shutdown, submit the batched CDRs */
+       BATCH_MODE_SCHEDULER_ONLY = 1 << 0, /*!< Don't spawn a thread to handle the batches - do it on the scheduler */
+       BATCH_MODE_SAFE_SHUTDOWN = 1 << 1,  /*!< During safe shutdown, submit the batched CDRs */
 };
 
 /*!
@@ -237,14 +237,14 @@ enum ast_cdr_batch_mode_settings {
  * state of a CDR object based on these flags.
  */
 enum ast_cdr_options {
-       AST_CDR_FLAG_KEEP_VARS = (1 << 0),   /*< Copy variables during the operation */
-       AST_CDR_FLAG_DISABLE = (1 << 1),     /*< Disable the current CDR */
-       AST_CDR_FLAG_DISABLE_ALL = (3 << 1), /*< Disable the CDR and all future CDRs */
-       AST_CDR_FLAG_PARTY_A = (1 << 3),     /*< Set the channel as party A */
-       AST_CDR_FLAG_FINALIZE = (1 << 4),    /*< Finalize the current CDRs */
-       AST_CDR_FLAG_SET_ANSWER = (1 << 5),  /*< If the channel is answered, set the answer time to now */
-       AST_CDR_FLAG_RESET = (1 << 6),       /*< If set, set the start and answer time to now */
-       AST_CDR_LOCK_APP = (1 << 7),         /*< Prevent any further changes to the application field/data field for this CDR */
+       AST_CDR_FLAG_KEEP_VARS = (1 << 0),   /*!< Copy variables during the operation */
+       AST_CDR_FLAG_DISABLE = (1 << 1),     /*!< Disable the current CDR */
+       AST_CDR_FLAG_DISABLE_ALL = (3 << 1), /*!< Disable the CDR and all future CDRs */
+       AST_CDR_FLAG_PARTY_A = (1 << 3),     /*!< Set the channel as party A */
+       AST_CDR_FLAG_FINALIZE = (1 << 4),    /*!< Finalize the current CDRs */
+       AST_CDR_FLAG_SET_ANSWER = (1 << 5),  /*!< If the channel is answered, set the answer time to now */
+       AST_CDR_FLAG_RESET = (1 << 6),       /*!< If set, set the start and answer time to now */
+       AST_CDR_LOCK_APP = (1 << 7),         /*!< Prevent any further changes to the application field/data field for this CDR */
 };
 
 /*!
@@ -262,11 +262,11 @@ enum ast_cdr_disposition {
 
 /*! \brief The global options available for CDRs */
 struct ast_cdr_config {
-       struct ast_flags settings;                      /*< CDR settings */
+       struct ast_flags settings;                      /*!< CDR settings */
        struct batch_settings {
-               unsigned int time;                              /*< Time between batches */
-               unsigned int size;                              /*< Size to trigger a batch */
-               struct ast_flags settings;              /*< Settings for batches */
+               unsigned int time;                              /*!< Time between batches */
+               unsigned int size;                              /*!< Size to trigger a batch */
+               struct ast_flags settings;              /*!< Settings for batches */
        } batch_settings;
 };
 
@@ -312,7 +312,7 @@ struct ast_cdr {
        unsigned int flags;
        /*! Unique Channel Identifier */
        char uniqueid[AST_MAX_UNIQUEID];
-       /* Linked group Identifier */
+       /*! Linked group Identifier */
        char linkedid[AST_MAX_UNIQUEID];
        /*! User field */
        char userfield[AST_MAX_USER_FIELD];
index b6403d6..e6ccf0a 100644 (file)
@@ -925,7 +925,9 @@ enum ast_sip_contact_filter {
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_register_service(pjsip_module *module);
+#define ast_sip_register_service(module) \
+       __ast_sip_register_service(module, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func);
 
 /*!
  * This is the opposite of ast_sip_register_service().  Unregistering a
@@ -934,7 +936,9 @@ int ast_sip_register_service(pjsip_module *module);
  *
  * \param module The PJSIP module to unregister
  */
-void ast_sip_unregister_service(pjsip_module *module);
+#define ast_sip_unregister_service(module) \
+       __ast_sip_unregister_service(module, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func);
 
 /*!
  * \brief Register a SIP authenticator
@@ -2615,14 +2619,20 @@ struct ast_sip_supplement {
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_register_supplement(struct ast_sip_supplement *supplement);
+#define ast_sip_register_supplement(supplement) \
+       __ast_sip_register_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int __ast_sip_register_supplement(struct ast_sip_supplement *supplement,
+       const char *file, int line, const char *func);
 
 /*!
  * \brief Unregister a an supplement to SIP out of dialog processing
  *
  * \param supplement The supplement to unregister
  */
-void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement);
+#define ast_sip_unregister_supplement(supplement) \
+       __ast_sip_unregister_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement,
+       const char *file, int line, const char *func);
 
 /*!
  * \brief Retrieve the global MWI taskprocessor high water alert trigger level.
index fcb14b7..b7a22b9 100644 (file)
@@ -578,14 +578,27 @@ void ast_sip_session_unregister_sdp_handler(struct ast_sip_session_sdp_handler *
  * \retval 0 Success
  * \retval -1 Failure
  */
-int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
+#define ast_sip_session_register_supplement(supplement) \
+       __ast_sip_session_register_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+int __ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement,
+       const char *file, int line, const char *func);
 
 /*!
  * \brief Unregister a an supplement to SIP session processing
  *
  * \param supplement The supplement to unregister
  */
-void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
+#define ast_sip_session_unregister_supplement(supplement) \
+       __ast_sip_session_unregister_supplement(supplement, __FILE__, __LINE__, __PRETTY_FUNCTION__)
+void __ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement,
+       const char *file, int line, const char *func);
+
+/*!
+ * \brief Add supplements to a SIP session
+ *
+ * \param session The session to initialize
+ */
+int ast_sip_session_add_supplements(struct ast_sip_session *session);
 
 /*!
  * \brief Alternative for ast_datastore_alloc()
index 1817e80..b94bbcf 100644 (file)
@@ -220,7 +220,7 @@ static int cdr_toggle_runtime_options(void);
 
 /*! \brief The configuration settings for this module */
 struct module_config {
-       struct ast_cdr_config *general;         /*< CDR global settings */
+       struct ast_cdr_config *general;         /*!< CDR global settings */
 };
 
 /*! \brief The container for the module configuration */
@@ -751,11 +751,7 @@ static void free_variables(struct varshead *headp)
  */
 static void cdr_object_snapshot_copy(struct cdr_object_snapshot *dst, struct cdr_object_snapshot *src)
 {
-       if (dst->snapshot) {
-               ao2_t_ref(dst->snapshot, -1, "release old snapshot during copy");
-       }
-       dst->snapshot = src->snapshot;
-       ao2_t_ref(dst->snapshot, +1, "bump new snapshot during copy");
+       ao2_t_replace(dst->snapshot, src->snapshot, "CDR snapshot copy");
        strcpy(dst->userfield, src->userfield);
        dst->flags = src->flags;
        copy_variables(&dst->variables, &src->variables);
@@ -785,11 +781,11 @@ static int cdr_object_channel_hash_fn(const void *obj, const int flags)
        const struct cdr_object *cdr;
        const char *key;
 
-       switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
-       case OBJ_KEY:
+       switch (flags & OBJ_SEARCH_MASK) {
+       case OBJ_SEARCH_KEY:
                key = obj;
                break;
-       case OBJ_POINTER:
+       case OBJ_SEARCH_OBJECT:
                cdr = obj;
                key = cdr->uniqueid;
                break;
@@ -810,14 +806,14 @@ static int cdr_object_channel_cmp_fn(void *obj, void *arg, int flags)
     const char *right_key = arg;
     int cmp;
 
-    switch (flags & (OBJ_POINTER | OBJ_KEY | OBJ_PARTIAL_KEY)) {
-    case OBJ_POINTER:
+    switch (flags & OBJ_SEARCH_MASK) {
+    case OBJ_SEARCH_OBJECT:
         right_key = right->uniqueid;
         /* Fall through */
-    case OBJ_KEY:
+    case OBJ_SEARCH_KEY:
         cmp = strcmp(left->uniqueid, right_key);
         break;
-    case OBJ_PARTIAL_KEY:
+    case OBJ_SEARCH_PARTIAL_KEY:
         /*
          * We could also use a partial key struct containing a length
          * so strlen() does not get called for every comparison instead.
@@ -1358,11 +1354,7 @@ static void cdr_object_swap_snapshot(struct cdr_object_snapshot *old_snapshot,
                struct ast_channel_snapshot *new_snapshot)
 {
        cdr_object_update_cid(old_snapshot, new_snapshot);
-       if (old_snapshot->snapshot) {
-               ao2_t_ref(old_snapshot->snapshot, -1, "Drop ref for swap");
-       }
-       ao2_t_ref(new_snapshot, +1, "Bump ref for swap");
-       old_snapshot->snapshot = new_snapshot;
+       ao2_t_replace(old_snapshot->snapshot, new_snapshot, "Swap CDR shapshot");
 }
 
 /* BASE METHOD IMPLEMENTATIONS */
@@ -1458,7 +1450,8 @@ static int base_process_parked_channel(struct cdr_object *cdr, struct ast_parked
 
 /* SINGLE STATE */
 
-static void single_state_init_function(struct cdr_object *cdr) {
+static void single_state_init_function(struct cdr_object *cdr)
+{
        cdr->start = ast_tvnow();
        cdr_object_check_party_a_answer(cdr);
 }
@@ -1572,7 +1565,7 @@ static enum process_bridge_enter_results single_state_process_bridge_enter(struc
                !success && (channel_id = ao2_iterator_next(&it_cdrs));
                ao2_ref(channel_id, -1)) {
                RAII_VAR(struct cdr_object *, cand_cdr_master,
-                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_KEY),
+                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
                        ao2_cleanup);
                struct cdr_object *cand_cdr;
 
@@ -1623,11 +1616,9 @@ static int single_state_process_parking_bridge_enter(struct cdr_object *cdr, str
 static void dial_state_process_party_b(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot)
 {
        ast_assert(snapshot != NULL);
+       ast_assert(cdr->party_b.snapshot
+               && !strcasecmp(cdr->party_b.snapshot->name, snapshot->name));
 
-       if (!cdr->party_b.snapshot
-               || strcasecmp(cdr->party_b.snapshot->name, snapshot->name)) {
-               return;
-       }
        cdr_object_swap_snapshot(&cdr->party_b, snapshot);
 
        /* If party B hangs up, finalize this CDR */
@@ -1722,7 +1713,7 @@ static enum process_bridge_enter_results dial_state_process_bridge_enter(struct
                !success && (channel_id = ao2_iterator_next(&it_cdrs));
                ao2_ref(channel_id, -1)) {
                RAII_VAR(struct cdr_object *, cand_cdr_master,
-                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_KEY),
+                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
                        ao2_cleanup);
                struct cdr_object *cand_cdr;
 
@@ -1823,10 +1814,9 @@ static int dialed_pending_state_process_dial_begin(struct cdr_object *cdr, struc
 
 static void bridge_state_process_party_b(struct cdr_object *cdr, struct ast_channel_snapshot *snapshot)
 {
-       if (!cdr->party_b.snapshot
-               || strcasecmp(cdr->party_b.snapshot->name, snapshot->name)) {
-               return;
-       }
+       ast_assert(cdr->party_b.snapshot
+               && !strcasecmp(cdr->party_b.snapshot->name, snapshot->name));
+
        cdr_object_swap_snapshot(&cdr->party_b, snapshot);
 
        /* If party B hangs up, finalize this CDR */
@@ -1963,9 +1953,9 @@ static void handle_dial_message(void *data, struct stasis_subscription *sub, str
 
        /* Figure out who is running this show */
        if (caller) {
-               cdr = ao2_find(active_cdrs_by_channel, caller->uniqueid, OBJ_KEY);
+               cdr = ao2_find(active_cdrs_by_channel, caller->uniqueid, OBJ_SEARCH_KEY);
        } else {
-               cdr = ao2_find(active_cdrs_by_channel, peer->uniqueid, OBJ_KEY);
+               cdr = ao2_find(active_cdrs_by_channel, peer->uniqueid, OBJ_SEARCH_KEY);
        }
 
        if (!cdr) {
@@ -2023,6 +2013,7 @@ static int cdr_object_finalize_party_b(void *obj, void *arg, int flags)
        struct cdr_object *cdr = obj;
        struct ast_channel_snapshot *party_b = arg;
        struct cdr_object *it_cdr;
+
        for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
                if (it_cdr->party_b.snapshot
                        && !strcasecmp(it_cdr->party_b.snapshot->name, party_b->name)) {
@@ -2040,6 +2031,7 @@ static int cdr_object_update_party_b(void *obj, void *arg, int flags)
        struct cdr_object *cdr = obj;
        struct ast_channel_snapshot *party_b = arg;
        struct cdr_object *it_cdr;
+
        for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
                if (!it_cdr->fn_table->process_party_b) {
                        continue;
@@ -2119,7 +2111,7 @@ static void handle_channel_cache_message(void *data, struct stasis_subscription
 
        /* Handle Party A */
        if (!cdr) {
-               cdr = ao2_find(active_cdrs_by_channel, uniqueid, OBJ_KEY);
+               cdr = ao2_find(active_cdrs_by_channel, uniqueid, OBJ_SEARCH_KEY);
        }
        if (!cdr) {
                ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", name);
@@ -2225,7 +2217,7 @@ static void handle_bridge_leave_message(void *data, struct stasis_subscription *
        RAII_VAR(struct module_config *, mod_cfg,
                        ao2_global_obj_ref(module_configs), ao2_cleanup);
        RAII_VAR(struct cdr_object *, cdr,
-                       ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_KEY),
+                       ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY),
                        ao2_cleanup);
        struct cdr_object *it_cdr;
        struct bridge_leave_data leave_data = {
@@ -2382,7 +2374,7 @@ static void handle_bridge_pairings(struct cdr_object *cdr, struct ast_bridge_sna
        it_channels = ao2_iterator_init(bridge->channels, 0);
        while ((channel_id = ao2_iterator_next(&it_channels))) {
                RAII_VAR(struct cdr_object *, cand_cdr,
-                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_KEY),
+                       ao2_find(active_cdrs_by_channel, channel_id, OBJ_SEARCH_KEY),
                        ao2_cleanup);
 
                if (!cand_cdr) {
@@ -2528,7 +2520,7 @@ static void handle_bridge_enter_message(void *data, struct stasis_subscription *
        struct ast_bridge_snapshot *bridge = update->bridge;
        struct ast_channel_snapshot *channel = update->channel;
        RAII_VAR(struct cdr_object *, cdr,
-                       ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_KEY),
+                       ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY),
                        ao2_cleanup);
        RAII_VAR(struct module_config *, mod_cfg,
                        ao2_global_obj_ref(module_configs), ao2_cleanup);
@@ -2596,7 +2588,7 @@ static void handle_parked_call_message(void *data, struct stasis_subscription *s
                        (unsigned int)stasis_message_timestamp(message)->tv_sec,
                        (unsigned int)stasis_message_timestamp(message)->tv_usec);
 
-       cdr = ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_KEY);
+       cdr = ao2_find(active_cdrs_by_channel, channel->uniqueid, OBJ_SEARCH_KEY);
        if (!cdr) {
                ast_log(AST_LOG_WARNING, "No CDR for channel %s\n", channel->name);
                ast_assert(0);
@@ -2912,7 +2904,7 @@ void ast_cdr_format_var(struct ast_cdr *cdr, const char *name, char **ret, char
        }
 }
 
-/*
+/*!
  * \internal
  * \brief Callback that finds all CDRs that reference a particular channel by name
  */
@@ -2928,7 +2920,7 @@ static int cdr_object_select_all_by_name_cb(void *obj, void *arg, int flags)
        return 0;
 }
 
-/*
+/*!
  * \internal
  * \brief Callback that finds a CDR by channel name
  */
@@ -3165,8 +3157,9 @@ int ast_cdr_serialize_variables(const char *channel_name, struct ast_str **buf,
 
        ao2_lock(cdr);
        for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
-               if (++x > 1)
+               if (++x > 1) {
                        ast_str_append(buf, 0, "\n");
+               }
 
                AST_LIST_TRAVERSE(&it_cdr->party_a.variables, variable, entries) {
                        if (!(var = ast_var_name(variable))) {
@@ -3249,6 +3242,7 @@ static int cdr_object_update_party_b_userfield_cb(void *obj, void *arg, int flag
        struct cdr_object *cdr = obj;
        struct party_b_userfield_update *info = arg;
        struct cdr_object *it_cdr;
+
        for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
                if (it_cdr->fn_table == &finalized_state_fn_table && it_cdr->next != NULL) {
                        continue;
@@ -3830,6 +3824,7 @@ static void cli_show_channel(struct ast_cli_args *a)
        ao2_lock(cdr);
        for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
                struct timeval end;
+
                if (snapshot_is_dialed(it_cdr->party_a.snapshot)) {
                        continue;
                }
@@ -4246,8 +4241,8 @@ int ast_cdr_engine_init(void)
        stasis_message_router_add(stasis_router, ast_parked_call_type(), handle_parked_call_message, NULL);
        stasis_message_router_add(stasis_router, cdr_sync_message_type(), handle_cdr_sync_message, NULL);
 
-       active_cdrs_by_channel = ao2_container_alloc(NUM_CDR_BUCKETS,
-               cdr_object_channel_hash_fn, cdr_object_channel_cmp_fn);
+       active_cdrs_by_channel = ao2_container_alloc_hash(AO2_ALLOC_OPT_LOCK_MUTEX, 0,
+               NUM_CDR_BUCKETS, cdr_object_channel_hash_fn, NULL, cdr_object_channel_cmp_fn);
        if (!active_cdrs_by_channel) {
                return -1;
        }
@@ -4320,5 +4315,3 @@ int ast_cdr_engine_reload(void)
 
        return cdr_toggle_runtime_options();
 }
-
-
index ebe86f3..dbcff9d 100644 (file)
@@ -572,7 +572,8 @@ struct ast_tcptls_session_instance *ast_tcptls_client_create(struct ast_tcptls_s
 
        /* if a local address was specified, bind to it so the connection will
           originate from the desired address */
-       if (!ast_sockaddr_isnull(&desc->local_address)) {
+       if (!ast_sockaddr_isnull(&desc->local_address) &&
+           !ast_sockaddr_is_any(&desc->local_address)) {
                setsockopt(desc->accept_fd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
                if (ast_bind(desc->accept_fd, &desc->local_address)) {
                        ast_log(LOG_ERROR, "Unable to bind %s to %s: %s\n",
index 1d9d73e..46c82aa 100644 (file)
@@ -544,7 +544,7 @@ static int unload_module(void)
        pj_log_set_log_func(log_cb_orig);
        pj_log_set_decor(decor_orig);
 
-       AST_VECTOR_REMOVE_CMP_UNORDERED(&buildopts, NULL, NOT_EQUALS, ast_free);
+       AST_VECTOR_CALLBACK_VOID(&buildopts, ast_free);
        AST_VECTOR_FREE(&buildopts);
 
        ast_debug(3, "Stopped PJPROJECT logging to Asterisk logger\n");
index cbeb5ea..a784e12 100644 (file)
@@ -2448,25 +2448,20 @@ static int register_service_noref(void *data)
        return 0;
 }
 
-static int register_service(void *data)
-{
-       int res;
-
-       if (!(res = register_service_noref(data))) {
-               ast_module_ref(ast_module_info->self);
-       }
-
-       return res;
-}
-
 int internal_sip_register_service(pjsip_module *module)
 {
        return ast_sip_push_task_synchronous(NULL, register_service_noref, &module);
 }
 
-int ast_sip_register_service(pjsip_module *module)
+int __ast_sip_register_service(pjsip_module *module, const char *file, int line, const char *func)
 {
-       return ast_sip_push_task_synchronous(NULL, register_service, &module);
+       int res;
+
+       if (!(res = ast_sip_push_task_synchronous(NULL, register_service_noref, &module))) {
+               __ast_module_ref(ast_module_info->self, file, line, func);
+       }
+
+       return res;
 }
 
 static int unregister_service_noref(void *data)
@@ -2480,25 +2475,16 @@ static int unregister_service_noref(void *data)
        return 0;
 }
 
-static int unregister_service(void *data)
-{
-       int res;
-
-       if (!(res = unregister_service_noref(data))) {
-               ast_module_unref(ast_module_info->self);
-       }
-
-       return res;
-}
-
 int internal_sip_unregister_service(pjsip_module *module)
 {
        return ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module);
 }
 
-void ast_sip_unregister_service(pjsip_module *module)
+void __ast_sip_unregister_service(pjsip_module *module, const char *file, int line, const char *func)
 {
-       ast_sip_push_task_synchronous(NULL, unregister_service, &module);
+       if (!ast_sip_push_task_synchronous(NULL, unregister_service_noref, &module)) {
+               __ast_module_unref(ast_module_info->self, file, line, func);
+       }
 }
 
 static struct ast_sip_authenticator *registered_authenticator;
@@ -3542,7 +3528,7 @@ int ast_sip_create_request(const char *method, struct pjsip_dialog *dlg,
 
 AST_RWLIST_HEAD_STATIC(supplements, ast_sip_supplement);
 
-int ast_sip_register_supplement(struct ast_sip_supplement *supplement)
+void internal_sip_register_supplement(struct ast_sip_supplement *supplement)
 {
        struct ast_sip_supplement *iter;
        int inserted = 0;
@@ -3560,22 +3546,41 @@ int ast_sip_register_supplement(struct ast_sip_supplement *supplement)
        if (!inserted) {
                AST_RWLIST_INSERT_TAIL(&supplements, supplement, next);
        }
-       ast_module_ref(ast_module_info->self);
+}
+
+int __ast_sip_register_supplement(struct ast_sip_supplement *supplement,
+       const char *file, int line, const char *func)
+{
+       internal_sip_register_supplement(supplement);
+       __ast_module_ref(ast_module_info->self, file, line, func);
+
        return 0;
 }
 
-void ast_sip_unregister_supplement(struct ast_sip_supplement *supplement)
+int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement)
 {
        struct ast_sip_supplement *iter;
        SCOPED_LOCK(lock, &supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+       int res = -1;
+
        AST_RWLIST_TRAVERSE_SAFE_BEGIN(&supplements, iter, next) {
                if (supplement == iter) {
                        AST_RWLIST_REMOVE_CURRENT(next);
-                       ast_module_unref(ast_module_info->self);
+                       res = 0;
                        break;
                }
        }
        AST_RWLIST_TRAVERSE_SAFE_END;
+
+       return res;
+}
+
+void __ast_sip_unregister_supplement(struct ast_sip_supplement *supplement,
+       const char *file, int line, const char *func)
+{
+       if (!internal_sip_unregister_supplement(supplement)) {
+               __ast_module_unref(ast_module_info->self, file, line, func);
+       }
 }
 
 static int send_in_dialog_request(pjsip_tx_data *tdata, struct pjsip_dialog *dlg)
index 4adecd4..7ac2b7e 100644 (file)
@@ -1,6 +1,7 @@
 {
        global:
                LINKER_SYMBOL_PREFIXast_sip_*;
+               LINKER_SYMBOL_PREFIX__ast_sip_*;
                LINKER_SYMBOL_PREFIXast_copy_pj_str;
                LINKER_SYMBOL_PREFIXast_copy_pj_str2;
                LINKER_SYMBOL_PREFIXast_pjsip_rdata_get_endpoint;
index 9fd7aed..5ce3c6f 100644 (file)
@@ -328,6 +328,18 @@ int internal_sip_unregister_service(pjsip_module *module);
 
 /*!
  * \internal
+ * \brief Used by res_pjsip.so to register a supplement without adding a self reference
+ */
+void internal_sip_register_supplement(struct ast_sip_supplement *supplement);
+
+/*!
+ * \internal
+ * \brief Used by res_pjsip.so to unregister a supplement without removing a self reference
+ */
+int internal_sip_unregister_supplement(struct ast_sip_supplement *supplement);
+
+/*!
+ * \internal
  * \brief Used by res_pjsip.so to register an endpoint formatter without adding a self reference
  */
 void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
@@ -338,6 +350,20 @@ void internal_sip_register_endpoint_formatter(struct ast_sip_endpoint_formatter
  */
 int internal_sip_unregister_endpoint_formatter(struct ast_sip_endpoint_formatter *obj);
 
+struct ast_sip_session_supplement;
+
+/*!
+ * \internal
+ * \brief Used by res_pjsip.so to register a session supplement without adding a self reference
+ */
+void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement);
+
+/*!
+ * \internal
+ * \brief Used by res_pjsip.so to unregister a session supplement without removing a self reference
+ */
+int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement);
+
 /*!
  * \internal
  * \brief Finds or creates contact_status for a contact
index 3a752c9..653cb98 100644 (file)
@@ -1315,6 +1315,14 @@ static struct ast_endpoint *persistent_endpoint_find_or_create(const struct ast_
                ast_endpoint_set_state(persistent->endpoint, AST_ENDPOINT_OFFLINE);
 
                ao2_link_flags(persistent_endpoints, persistent, OBJ_NOLOCK);
+       } else if (strcmp(persistent->aors, endpoint->aors)) {
+               char *new_aors = ast_strdup(endpoint->aors);
+
+               /* make sure we don't NULL persistent->aors if allocation fails. */
+               if (new_aors) {
+                       ast_free(persistent->aors);
+                       persistent->aors = new_aors;
+               }
        }
 
        ao2_ref(persistent->endpoint, +1);
@@ -1821,20 +1829,12 @@ static struct ast_cli_entry cli_commands[] = {
 struct ast_sip_cli_formatter_entry *channel_formatter;
 struct ast_sip_cli_formatter_entry *endpoint_formatter;
 
-static int on_load_endpoint(void *obj, void *arg, int flags)
-{
-       return sip_endpoint_apply_handler(sip_sorcery, obj);
-}
-
 static void load_all_endpoints(void)
 {
        struct ao2_container *endpoints;
 
        endpoints = ast_sorcery_retrieve_by_fields(sip_sorcery, "endpoint", AST_RETRIEVE_FLAG_MULTIPLE | AST_RETRIEVE_FLAG_ALL, NULL);
-       if (endpoints) {
-               ao2_callback(endpoints, OBJ_NODATA, on_load_endpoint, NULL);
-               ao2_ref(endpoints, -1);
-       }
+       ao2_cleanup(endpoints);
 }
 
 int ast_res_pjsip_initialize_configuration(void)
index d2f9b95..978aeb0 100644 (file)
@@ -505,32 +505,24 @@ static pj_bool_t filter_on_rx_message(pjsip_rx_data *rdata)
 
 void ast_res_pjsip_cleanup_message_filter(void)
 {
-       ast_sip_unregister_service(&filter_module_tsx);
-       ast_sip_unregister_service(&filter_module_transport);
-       ast_sip_unregister_supplement(&filter_supplement);
-       ast_sip_session_unregister_supplement(&filter_session_supplement);
+       internal_sip_unregister_service(&filter_module_tsx);
+       internal_sip_unregister_service(&filter_module_transport);
+       internal_sip_unregister_supplement(&filter_supplement);
+       internal_sip_session_unregister_supplement(&filter_session_supplement);
 }
 
 int ast_res_pjsip_init_message_filter(void)
 {
-       if (ast_sip_session_register_supplement(&filter_session_supplement)) {
-               ast_log(LOG_ERROR, "Could not register message filter session supplement for outgoing requests\n");
-               return -1;
-       }
-
-       if (ast_sip_register_supplement(&filter_supplement)) {
-               ast_log(LOG_ERROR, "Could not register message filter supplement for outgoing requests\n");
-               ast_res_pjsip_cleanup_message_filter();
-               return -1;
-       }
+       internal_sip_session_register_supplement(&filter_session_supplement);
+       internal_sip_register_supplement(&filter_supplement);
 
-       if (ast_sip_register_service(&filter_module_transport)) {
+       if (internal_sip_register_service(&filter_module_transport)) {
                ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
                ast_res_pjsip_cleanup_message_filter();
                return -1;
        }
 
-       if (ast_sip_register_service(&filter_module_tsx)) {
+       if (internal_sip_register_service(&filter_module_tsx)) {
                ast_log(LOG_ERROR, "Could not register message filter module for incoming and outgoing requests\n");
                ast_res_pjsip_cleanup_message_filter();
                return -1;
diff --git a/res/res_pjsip/pjsip_session.c b/res/res_pjsip/pjsip_session.c
new file mode 100644 (file)
index 0000000..4f3e3be
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2017, CFWare, LLC
+ *
+ * Corey Farrell <git@cfware.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+
+#include <pjsip.h>
+#include <pjsip_ua.h>
+#include <pjlib.h>
+
+#include "asterisk/res_pjsip.h"
+#include "asterisk/res_pjsip_session.h"
+#include "include/res_pjsip_private.h"
+#include "asterisk/linkedlists.h"
+#include "asterisk/lock.h"
+#include "asterisk/module.h"
+
+
+AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement);
+
+void internal_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
+{
+       struct ast_sip_session_supplement *iter;
+       int inserted = 0;
+       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+
+       if (!supplement->response_priority) {
+               supplement->response_priority = AST_SIP_SESSION_BEFORE_MEDIA;
+       }
+
+       AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
+               if (iter->priority > supplement->priority) {
+                       AST_RWLIST_INSERT_BEFORE_CURRENT(supplement, next);
+                       inserted = 1;
+                       break;
+               }
+       }
+       AST_RWLIST_TRAVERSE_SAFE_END;
+
+       if (!inserted) {
+               AST_RWLIST_INSERT_TAIL(&session_supplements, supplement, next);
+       }
+}
+
+int __ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement,
+       const char *file, int line, const char *func)
+{
+       internal_sip_session_register_supplement(supplement);
+       __ast_module_ref(AST_MODULE_SELF, file, line, func);
+
+       return 0;
+}
+
+int internal_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
+{
+       struct ast_sip_session_supplement *iter;
+       int res = -1;
+       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
+
+       AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
+               if (supplement == iter) {
+                       AST_RWLIST_REMOVE_CURRENT(next);
+                       res = 0;
+                       break;
+               }
+       }
+       AST_RWLIST_TRAVERSE_SAFE_END;
+
+       return res;
+}
+
+void __ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement,
+       const char *file, int line, const char *func)
+{
+       if (!internal_sip_session_unregister_supplement(supplement)) {
+               __ast_module_unref(AST_MODULE_SELF, file, line, func);
+       }
+}
+
+static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src)
+{
+       struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst));
+
+       if (!dst) {
+               return NULL;
+       }
+       /* Will need to revisit if shallow copy becomes an issue */
+       *dst = *src;
+
+       return dst;
+}
+
+int ast_sip_session_add_supplements(struct ast_sip_session *session)
+{
+       struct ast_sip_session_supplement *iter;
+       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
+
+       AST_RWLIST_TRAVERSE(&session_supplements, iter, next) {
+               struct ast_sip_session_supplement *copy = supplement_dup(iter);
+
+               if (!copy) {
+                       return -1;
+               }
+               AST_LIST_INSERT_TAIL(&session->supplements, copy, next);
+       }
+
+       return 0;
+}
+
index 70c88a5..49f2f17 100644 (file)
@@ -907,59 +907,6 @@ static int handle_negotiated_sdp(struct ast_sip_session *session, const pjmedia_
        return 0;
 }
 
-AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement);
-
-int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
-{
-       struct ast_sip_session_supplement *iter;
-       int inserted = 0;
-       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-
-       if (!supplement->response_priority) {
-               supplement->response_priority = AST_SIP_SESSION_BEFORE_MEDIA;
-       }
-
-       AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
-               if (iter->priority > supplement->priority) {
-                       AST_RWLIST_INSERT_BEFORE_CURRENT(supplement, next);
-                       inserted = 1;
-                       break;
-               }
-       }
-       AST_RWLIST_TRAVERSE_SAFE_END;
-
-       if (!inserted) {
-               AST_RWLIST_INSERT_TAIL(&session_supplements, supplement, next);
-       }
-       ast_module_ref(ast_module_info->self);
-       return 0;
-}
-
-void ast_sip_session_unregister_supplement(struct ast_sip_session_supplement *supplement)
-{
-       struct ast_sip_session_supplement *iter;
-       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_WRLOCK, AST_RWLIST_UNLOCK);
-       AST_RWLIST_TRAVERSE_SAFE_BEGIN(&session_supplements, iter, next) {
-               if (supplement == iter) {
-                       AST_RWLIST_REMOVE_CURRENT(next);
-                       ast_module_unref(ast_module_info->self);
-                       break;
-               }
-       }
-       AST_RWLIST_TRAVERSE_SAFE_END;
-}
-
-static struct ast_sip_session_supplement *supplement_dup(const struct ast_sip_session_supplement *src)
-{
-       struct ast_sip_session_supplement *dst = ast_calloc(1, sizeof(*dst));
-       if (!dst) {
-               return NULL;
-       }
-       /* Will need to revisit if shallow copy becomes an issue */
-       *dst = *src;
-       return dst;
-}
-
 #define DATASTORE_BUCKETS 53
 #define MEDIA_BUCKETS 7
 
@@ -1547,6 +1494,7 @@ int ast_sip_session_refresh(struct ast_sip_session *session,
                                                }
                                        }
                                        ast_stream_set_formats(stream, joint_cap);
+                                       ao2_cleanup(joint_cap);
                                }
 
                                ++type_streams[ast_stream_get_type(stream)];
@@ -2045,21 +1993,6 @@ static void session_destructor(void *obj)
        ast_test_suite_event_notify("SESSION_DESTROYED", "Endpoint: %s", endpoint_name);
 }
 
-static int add_supplements(struct ast_sip_session *session)
-{
-       struct ast_sip_session_supplement *iter;
-       SCOPED_LOCK(lock, &session_supplements, AST_RWLIST_RDLOCK, AST_RWLIST_UNLOCK);
-
-       AST_RWLIST_TRAVERSE(&session_supplements, iter, next) {
-               struct ast_sip_session_supplement *copy = supplement_dup(iter);
-               if (!copy) {
-                       return -1;
-               }
-               AST_LIST_INSERT_TAIL(&session->supplements, copy, next);
-       }
-       return 0;
-}
-
 /*! \brief Destructor for SIP channel */
 static void sip_channel_destroy(void *obj)
 {
@@ -2166,7 +2099,7 @@ struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint,
 
        session->dtmf = endpoint->dtmf;
 
-       if (add_supplements(session)) {
+       if (ast_sip_session_add_supplements(session)) {
                /* Release the ref held by session->inv_session */
                ao2_ref(session, -1);
                return NULL;
index b7bd21b..d65b247 100644 (file)
@@ -1,6 +1,7 @@
 {
        global:
                LINKER_SYMBOL_PREFIXast_sip_session_*;
+               LINKER_SYMBOL_PREFIX__ast_sip_session_*;
                LINKER_SYMBOL_PREFIXast_sip_dialog_get_session;
                LINKER_SYMBOL_PREFIXast_sip_channel_pvt_alloc;
        local: