summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--apps/app_agent_pool.c14
-rw-r--r--apps/app_skel.c18
-rw-r--r--apps/app_transfer.c2
-rw-r--r--apps/app_voicemail.c3
-rw-r--r--apps/confbridge/conf_config_parser.c20
-rw-r--r--channels/chan_console.c2
-rw-r--r--channels/chan_motif.c4
-rw-r--r--channels/chan_pjsip.c46
-rw-r--r--channels/chan_sip.c12
-rw-r--r--channels/chan_skinny.c6
-rw-r--r--configs/samples/confbridge.conf.sample4
-rw-r--r--funcs/func_callerid.c18
-rw-r--r--include/asterisk/config_options.h14
-rw-r--r--include/asterisk/module.h2
-rw-r--r--main/app.c32
-rw-r--r--main/asterisk.c49
-rw-r--r--main/cdr.c45
-rw-r--r--main/cel.c25
-rw-r--r--main/cli.c2
-rw-r--r--main/config_options.c87
-rw-r--r--main/features_config.c22
-rw-r--r--main/loader.c380
-rw-r--r--main/manager_system.c9
-rw-r--r--main/named_acl.c4
-rw-r--r--main/rtp_engine.c60
-rw-r--r--main/stasis.c8
-rw-r--r--main/stdtime/localtime.c46
-rw-r--r--main/translate.c5
-rw-r--r--main/udptl.c4
-rw-r--r--main/utils.c2
-rw-r--r--main/xmldoc.c6
-rw-r--r--res/ari/config.c8
-rw-r--r--res/res_config_ldap.c4
-rw-r--r--res/res_hep.c4
-rw-r--r--res/res_parking.c8
-rw-r--r--res/res_pjsip_notify.c8
-rw-r--r--res/res_rtp_asterisk.c4
-rw-r--r--res/res_statsd.c4
-rw-r--r--res/res_xmpp.c8
-rw-r--r--tests/test_config.c14
41 files changed, 595 insertions, 423 deletions
diff --git a/CHANGES b/CHANGES
index 7dd1aac27..0295e8a31 100644
--- a/CHANGES
+++ b/CHANGES
@@ -21,6 +21,11 @@ Core
Asterisk is compiled with the LOW_MEMORY compile time option enabled because
the cache code does not exist.
+chan_sip
+------------------
+ * Calls to invalid extensions are now reported as an ACL failure security event
+ "no_extension_match".
+
res_pjsip
------------------
* The "identify_by" on endpoints can now be set to "ip" to restrict an endpoint
diff --git a/apps/app_agent_pool.c b/apps/app_agent_pool.c
index a637bbe5f..ef8b95ec8 100644
--- a/apps/app_agent_pool.c
+++ b/apps/app_agent_pool.c
@@ -457,11 +457,17 @@ struct agents_cfg {
struct ao2_container *agents;
};
+static const char *agent_type_blacklist[] = {
+ "general",
+ "agents",
+ NULL,
+};
+
static struct aco_type agent_type = {
.type = ACO_ITEM,
.name = "agent-id",
- .category_match = ACO_BLACKLIST,
- .category = "^(general|agents)$",
+ .category_match = ACO_BLACKLIST_ARRAY,
+ .category = (const char *)agent_type_blacklist,
.item_alloc = agent_cfg_alloc,
.item_find = agent_cfg_find,
.item_offset = offsetof(struct agents_cfg, agents),
@@ -473,8 +479,8 @@ static struct aco_type *agent_types[] = ACO_TYPES(&agent_type);
static struct aco_type general_type = {
.type = ACO_GLOBAL,
.name = "global",
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
static struct aco_file agents_conf = {
diff --git a/apps/app_skel.c b/apps/app_skel.c
index 12afdc726..20e6abfcc 100644
--- a/apps/app_skel.c
+++ b/apps/app_skel.c
@@ -244,8 +244,8 @@ static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "globals",
.item_offset = offsetof(struct skel_config, global),
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
struct aco_type *global_options[] = ACO_TYPES(&global_option);
@@ -255,18 +255,24 @@ static struct aco_type sound_option = {
.type = ACO_GLOBAL,
.name = "sounds",
.item_offset = offsetof(struct skel_config, global),
- .category_match = ACO_WHITELIST,
- .category = "^sounds$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "sounds",
};
struct aco_type *sound_options[] = ACO_TYPES(&sound_option);
+static const char *level_categories[] = {
+ "general",
+ "sounds",
+ NULL,
+};
+
/*! \brief An aco_type structure to link the everything but the "general" and "sounds" categories to the skel_level type */
static struct aco_type level_option = {
.type = ACO_ITEM,
.name = "level",
- .category_match = ACO_BLACKLIST,
- .category = "^(general|sounds)$",
+ .category_match = ACO_BLACKLIST_ARRAY,
+ .category = (const char *)level_categories,
.item_alloc = skel_level_alloc,
.item_find = skel_level_find,
.item_offset = offsetof(struct skel_config, levels),
diff --git a/apps/app_transfer.c b/apps/app_transfer.c
index 1b8108278..9a5fa9e0d 100644
--- a/apps/app_transfer.c
+++ b/apps/app_transfer.c
@@ -53,7 +53,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
</syntax>
<description>
<para>Requests the remote caller be transferred
- to a given destination. If TECH (SIP, IAX2, LOCAL etc) is used, only
+ to a given destination. If TECH (SIP, IAX2, etc) is used, only
an incoming call with the same channel technology will be transferred.
Note that for SIP, if you transfer before call is setup, a 302 redirect
SIP message will be returned to the caller.</para>
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index c080bfee9..4a0dacc05 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -5373,6 +5373,7 @@ plain_message:
static int add_email_attachment(FILE *p, struct ast_vm_user *vmu, char *format, char *attach, char *greeting_attachment, char *mailbox, char *bound, char *filename, int last, int msgnum)
{
char fname[PATH_MAX] = "";
+ char sox_gain_tmpdir[PATH_MAX];
char *file_to_delete = NULL, *dir_to_delete = NULL;
int res;
@@ -5382,7 +5383,6 @@ static int add_email_attachment(FILE *p, struct ast_vm_user *vmu, char *format,
/* This 'while' loop will only execute once. We use it so that we can 'break' */
while (vmu->volgain < -.001 || vmu->volgain > .001) {
char tmpdir[PATH_MAX];
- char sox_gain_tmpdir[PATH_MAX];
create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp");
@@ -13212,6 +13212,7 @@ static void mwi_sub_event_cb(struct stasis_subscription_change *change)
}
if (separate_mailbox(ast_strdupa(stasis_topic_name(change->topic)), &mailbox, &context)) {
+ ast_free(mwist);
return;
}
diff --git a/apps/confbridge/conf_config_parser.c b/apps/confbridge/conf_config_parser.c
index 2de1ec238..16d393526 100644
--- a/apps/confbridge/conf_config_parser.c
+++ b/apps/confbridge/conf_config_parser.c
@@ -377,7 +377,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
regardless if this limit is reached or not.
</para></description>
</configOption>
- <configOption name="^sound_">
+ <configOption name="sound_">
<synopsis>Override the various conference bridge sound files</synopsis>
<description><para>
All sounds in the conference are customizable using the bridge profile options below.
@@ -592,8 +592,8 @@ static void *bridge_profile_find(struct ao2_container *container, const char *ca
static struct aco_type bridge_type = {
.type = ACO_ITEM,
.name = "bridge_profile",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.matchfield = "type",
.matchvalue = "bridge",
.item_alloc = bridge_profile_alloc,
@@ -629,8 +629,8 @@ static void *user_profile_find(struct ao2_container *container, const char *cate
static struct aco_type user_type = {
.type = ACO_ITEM,
.name = "user_profile",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.matchfield = "type",
.matchvalue = "user",
.item_alloc = user_profile_alloc,
@@ -660,8 +660,8 @@ static void *menu_find(struct ao2_container *container, const char *category)
static struct aco_type menu_type = {
.type = ACO_ITEM,
.name = "menu",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.matchfield = "type",
.matchvalue = "menu",
.item_alloc = menu_alloc,
@@ -678,8 +678,8 @@ static struct aco_type *user_types[] = ACO_TYPES(&user_type);
static struct aco_type general_type = {
.type = ACO_GLOBAL,
.name = "global",
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
static struct aco_file confbridge_conf = {
@@ -2149,7 +2149,7 @@ int conf_load_config(void)
aco_option_register(&cfg_info, "record_file", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, rec_file));
aco_option_register(&cfg_info, "regcontext", ACO_EXACT, bridge_types, NULL, OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, regcontext));
aco_option_register(&cfg_info, "language", ACO_EXACT, bridge_types, "en", OPT_CHAR_ARRAY_T, 0, CHARFLDSET(struct bridge_profile, language));
- aco_option_register_custom(&cfg_info, "^sound_", ACO_REGEX, bridge_types, NULL, sound_option_handler, 0);
+ aco_option_register_custom(&cfg_info, "sound_", ACO_PREFIX, bridge_types, NULL, sound_option_handler, 0);
/* This option should only be used with the CONFBRIDGE dialplan function */
aco_option_register_custom(&cfg_info, "template", ACO_EXACT, bridge_types, NULL, bridge_template_handler, 0);
diff --git a/channels/chan_console.c b/channels/chan_console.c
index 02d68870b..d7a72138d 100644
--- a/channels/chan_console.c
+++ b/channels/chan_console.c
@@ -1235,7 +1235,7 @@ static char *cli_console_active(struct ast_cli_entry *e, int cmd, struct ast_cli
return CLI_SUCCESS;
}
- if (!(pvt = find_pvt(a->argv[e->args - 1]))) {
+ if (!(pvt = find_pvt(a->argv[e->args]))) {
ast_cli(a->fd, "Could not find a device called '%s'.\n", a->argv[e->args]);
return CLI_FAILURE;
}
diff --git a/channels/chan_motif.c b/channels/chan_motif.c
index 314103765..939380771 100644
--- a/channels/chan_motif.c
+++ b/channels/chan_motif.c
@@ -543,8 +543,8 @@ static int jingle_endpoint_cmp(void *obj, void *arg, int flags)
static struct aco_type endpoint_option = {
.type = ACO_ITEM,
.name = "endpoint",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.item_alloc = jingle_endpoint_alloc,
.item_find = jingle_endpoint_find,
.item_offset = offsetof(struct jingle_config, endpoints),
diff --git a/channels/chan_pjsip.c b/channels/chan_pjsip.c
index 4324d159b..13cbd5d9d 100644
--- a/channels/chan_pjsip.c
+++ b/channels/chan_pjsip.c
@@ -2132,7 +2132,7 @@ static int request(void *obj)
struct request_data *req_data = obj;
struct ast_sip_session *session = NULL;
char *tmp = ast_strdupa(req_data->dest), *endpoint_name = NULL, *request_user = NULL;
- RAII_VAR(struct ast_sip_endpoint *, endpoint, NULL, ao2_cleanup);
+ struct ast_sip_endpoint *endpoint;
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(endpoint);
@@ -2157,10 +2157,18 @@ static int request(void *obj)
}
if (ast_strlen_zero(endpoint_name)) {
- ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+ if (request_user) {
+ ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
+ request_user);
+ } else {
+ ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+ }
req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
return -1;
- } else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+ }
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+ endpoint_name);
+ if (!endpoint) {
ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
return -1;
@@ -2172,23 +2180,38 @@ static int request(void *obj)
ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
return -1;
- } else if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+ }
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+ endpoint_name);
+ if (!endpoint) {
/* It seems it's not a multi-domain endpoint or single endpoint exact match,
* it's possible that it's a SIP trunk with a specified user (user@trunkname),
* so extract the user before @ sign.
*/
- if ((endpoint_name = strchr(args.endpoint, '@'))) {
- request_user = args.endpoint;
- *endpoint_name++ = '\0';
+ endpoint_name = strchr(args.endpoint, '@');
+ if (!endpoint_name) {
+ /*
+ * Couldn't find an '@' so it had to be an endpoint
+ * name that doesn't exist.
+ */
+ ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n",
+ args.endpoint);
+ req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
+ return -1;
}
+ request_user = args.endpoint;
+ *endpoint_name++ = '\0';
if (ast_strlen_zero(endpoint_name)) {
- ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name\n");
+ ast_log(LOG_ERROR, "Unable to create PJSIP channel with empty endpoint name: %s@<endpoint-name>\n",
+ request_user);
req_data->cause = AST_CAUSE_CHANNEL_UNACCEPTABLE;
return -1;
}
- if (!(endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", endpoint_name))) {
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint",
+ endpoint_name);
+ if (!endpoint) {
ast_log(LOG_ERROR, "Unable to create PJSIP channel - endpoint '%s' was not found\n", endpoint_name);
req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
return -1;
@@ -2196,7 +2219,10 @@ static int request(void *obj)
}
}
- if (!(session = ast_sip_session_create_outgoing(endpoint, NULL, args.aor, request_user, req_data->caps))) {
+ session = ast_sip_session_create_outgoing(endpoint, NULL, args.aor, request_user,
+ req_data->caps);
+ ao2_ref(endpoint, -1);
+ if (!session) {
ast_log(LOG_ERROR, "Failed to create outgoing session to endpoint '%s'\n", endpoint_name);
req_data->cause = AST_CAUSE_NO_ROUTE_DESTINATION;
return -1;
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index 9add42564..e6e82db46 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -23168,6 +23168,8 @@ static void change_redirecting_information(struct sip_pvt *p, struct sip_request
redirecting->from.number.valid = 1;
ast_free(redirecting->from.number.str);
redirecting->from.number.str = redirecting_from_number;
+ } else {
+ ast_free(redirecting_from_number);
}
if (!ast_strlen_zero(redirecting_from_name)) {
ast_debug(3, "Got redirecting from name %s\n", redirecting_from_name);
@@ -23175,6 +23177,8 @@ static void change_redirecting_information(struct sip_pvt *p, struct sip_request
redirecting->from.name.valid = 1;
ast_free(redirecting->from.name.str);
redirecting->from.name.str = redirecting_from_name;
+ } else {
+ ast_free(redirecting_from_name);
}
if (!ast_strlen_zero(p->cid_tag)) {
ast_free(redirecting->from.tag);
@@ -23188,13 +23192,17 @@ static void change_redirecting_information(struct sip_pvt *p, struct sip_request
redirecting->to.number.valid = 1;
ast_free(redirecting->to.number.str);
redirecting->to.number.str = redirecting_to_number;
+ } else {
+ ast_free(redirecting_to_number);
}
if (!ast_strlen_zero(redirecting_to_name)) {
- ast_debug(3, "Got redirecting to name %s\n", redirecting_from_number);
+ ast_debug(3, "Got redirecting to name %s\n", redirecting_to_name);
update_redirecting->to.name = 1;
redirecting->to.name.valid = 1;
ast_free(redirecting->to.name.str);
redirecting->to.name.str = redirecting_to_name;
+ } else {
+ ast_free(redirecting_to_name);
}
redirecting->reason.code = reason;
ast_free(redirecting->reason.str);
@@ -24223,6 +24231,7 @@ static void handle_response_subscribe(struct sip_pvt *p, int resp, const char *r
ast_cc_monitor_failed(monitor_instance->core_id,
monitor_instance->device_name,
"Received error response to our SUBSCRIBE");
+ ao2_ref(monitor_instance, -1);
}
return;
}
@@ -26405,6 +26414,7 @@ static int handle_request_invite(struct sip_pvt *p, struct sip_request *req, str
ast_log(LOG_NOTICE, "Call from '%s' (%s) to extension"
" '%s' rejected because extension not found in context '%s'.\n",
S_OR(p->username, p->peername), ast_sockaddr_stringify(&p->recv), decoded_exten, p->context);
+ sip_report_failed_acl(p, "no_extension_match");
}
break;
case SIP_GET_DEST_REFUSED:
diff --git a/channels/chan_skinny.c b/channels/chan_skinny.c
index ccf6a9464..97634bcbc 100644
--- a/channels/chan_skinny.c
+++ b/channels/chan_skinny.c
@@ -4756,15 +4756,19 @@ static void start_rtp(struct skinny_subchannel *sub)
{
struct skinny_line *l = sub->line;
struct skinny_device *d = l->device;
+#if 0
int hasvideo = 0;
+#endif
struct ast_sockaddr bindaddr_tmp;
skinny_locksub(sub);
SKINNY_DEBUG(DEBUG_AUDIO, 3, "Sub %u - Starting RTP\n", sub->callid);
ast_sockaddr_from_sin(&bindaddr_tmp, &bindaddr);
sub->rtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL);
+#if 0
if (hasvideo)
sub->vrtp = ast_rtp_instance_new("asterisk", sched, &bindaddr_tmp, NULL);
+#endif
if (sub->rtp) {
ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_RTCP, 1);
@@ -4778,11 +4782,13 @@ static void start_rtp(struct skinny_subchannel *sub)
ast_channel_set_fd(sub->owner, 0, ast_rtp_instance_fd(sub->rtp, 0));
ast_channel_set_fd(sub->owner, 1, ast_rtp_instance_fd(sub->rtp, 1));
}
+#if 0
if (hasvideo && sub->vrtp && sub->owner) {
ast_rtp_instance_set_channel_id(sub->vrtp, ast_channel_uniqueid(sub->owner));
ast_channel_set_fd(sub->owner, 2, ast_rtp_instance_fd(sub->vrtp, 0));
ast_channel_set_fd(sub->owner, 3, ast_rtp_instance_fd(sub->vrtp, 1));
}
+#endif
if (sub->rtp) {
ast_rtp_instance_set_qos(sub->rtp, qos.tos_audio, qos.cos_audio, "Skinny RTP");
ast_rtp_instance_set_prop(sub->rtp, AST_RTP_PROPERTY_NAT, l->nat);
diff --git a/configs/samples/confbridge.conf.sample b/configs/samples/confbridge.conf.sample
index 49208c31b..8c06cd9b1 100644
--- a/configs/samples/confbridge.conf.sample
+++ b/configs/samples/confbridge.conf.sample
@@ -228,8 +228,8 @@ type=bridge
; left the conference. This is used for user intros.
; Example "_____ has left the conference"
;sound_kicked ; The sound played to a user who has been kicked from the conference.
-;sound_muted ; The sound played when the mute option it toggled on.
-;sound_unmuted ; The sound played when the mute option it toggled off.
+;sound_muted ; The sound played when the mute option is toggled on using DTMF menu.
+;sound_unmuted ; The sound played when the mute option is toggled off using DTMF menu.
;sound_only_person ; The sound played when the user is the only person in the conference.
;sound_only_one ; The sound played to a user when there is only one other
; person is in the conference.
diff --git a/funcs/func_callerid.c b/funcs/func_callerid.c
index 4db985ecb..aabd70fea 100644
--- a/funcs/func_callerid.c
+++ b/funcs/func_callerid.c
@@ -980,7 +980,7 @@ static int callerpres_write(struct ast_channel *chan, const char *cmd, char *dat
static int callerid_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
char *parms;
- struct ast_party_members member;
+ struct ast_party_members member = { 0, };
AST_DECLARE_APP_ARGS(args,
AST_APP_ARG(member); /*!< Member name */
AST_APP_ARG(cid); /*!< Optional caller id to parse instead of from the channel. */
@@ -1137,8 +1137,8 @@ static int callerid_write(struct ast_channel *chan, const char *cmd, char *data,
enum ID_FIELD_STATUS status;
char *val;
char *parms;
- struct ast_party_func_args args;
- struct ast_party_members member;
+ struct ast_party_func_args args = { 0, };
+ struct ast_party_members member = { 0, };
if (!value || !chan) {
return -1;
@@ -1293,7 +1293,7 @@ static int callerid_write(struct ast_channel *chan, const char *cmd, char *data,
*/
static int connectedline_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
- struct ast_party_members member;
+ struct ast_party_members member = { 0, };
char *read_what;
enum ID_FIELD_STATUS status;
@@ -1361,8 +1361,8 @@ static int connectedline_write(struct ast_channel *chan, const char *cmd, char *
char *val;
char *parms;
void (*set_it)(struct ast_channel *chan, const struct ast_party_connected_line *connected, const struct ast_set_party_connected_line *update);
- struct ast_party_func_args args;
- struct ast_party_members member;
+ struct ast_party_func_args args = { 0, };
+ struct ast_party_members member = { 0, };
struct ast_flags opts;
char *opt_args[CONNECTED_LINE_OPT_ARG_ARRAY_SIZE];
enum ID_FIELD_STATUS status;
@@ -1466,7 +1466,7 @@ static int connectedline_write(struct ast_channel *chan, const char *cmd, char *
*/
static int redirecting_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
{
- struct ast_party_members member;
+ struct ast_party_members member = { 0, };
char *read_what;
const struct ast_party_redirecting *ast_redirecting;
enum ID_FIELD_STATUS status;
@@ -1603,8 +1603,8 @@ static int redirecting_write(struct ast_channel *chan, const char *cmd, char *da
char *val;
char *parms;
void (*set_it)(struct ast_channel *chan, const struct ast_party_redirecting *redirecting, const struct ast_set_party_redirecting *update);
- struct ast_party_func_args args;
- struct ast_party_members member;
+ struct ast_party_func_args args = { 0, };
+ struct ast_party_members member = { 0, };
struct ast_flags opts;
char *opt_args[REDIRECTING_OPT_ARG_ARRAY_SIZE];
diff --git a/include/asterisk/config_options.h b/include/asterisk/config_options.h
index f4c3db188..3227f94eb 100644
--- a/include/asterisk/config_options.h
+++ b/include/asterisk/config_options.h
@@ -40,18 +40,30 @@ struct aco_type_internal;
enum aco_type_t {
ACO_GLOBAL,
ACO_ITEM,
+ ACO_IGNORE,
};
-/*! \brief Whether a category regex is a blackist or a whitelist */
+/*! Type of category matching to perform */
enum aco_category_op {
+ /*! Regex based blacklist. */
ACO_BLACKLIST = 0,
+ /*! Regex based whitelist. */
ACO_WHITELIST,
+ /*! Blacklist with a single string matched with strcasecmp. */
+ ACO_BLACKLIST_EXACT,
+ /*! Whitelist with a single string matched with strcasecmp. */
+ ACO_WHITELIST_EXACT,
+ /*! Blacklist with a NULL terminated array of strings matched with strcasecmp. */
+ ACO_BLACKLIST_ARRAY,
+ /*! Whitelist with a NULL terminated array of strings matched with strcasecmp. */
+ ACO_WHITELIST_ARRAY,
};
/*! \brief What kind of matching should be done on an option name */
enum aco_matchtype {
ACO_EXACT = 1,
ACO_REGEX,
+ ACO_PREFIX,
};
/*! Callback functions for option parsing via aco_process_config() */
diff --git a/include/asterisk/module.h b/include/asterisk/module.h
index b9d7de64d..66de5c6be 100644
--- a/include/asterisk/module.h
+++ b/include/asterisk/module.h
@@ -69,7 +69,7 @@ enum ast_module_load_result {
AST_MODULE_LOAD_SUCCESS = 0, /*!< Module loaded and configured */
AST_MODULE_LOAD_DECLINE = 1, /*!< Module is not configured */
AST_MODULE_LOAD_SKIP = 2, /*!< Module was skipped for some reason (For loader.c use only. Should never be returned by modules)*/
- AST_MODULE_LOAD_PRIORITY = 3, /*!< Module is not loaded yet, but is added to prioity heap */
+ AST_MODULE_LOAD_PRIORITY = 3, /*!< Module is not loaded yet, but is added to priority list */
AST_MODULE_LOAD_FAILURE = -1, /*!< Module could not be loaded properly */
};
diff --git a/main/app.c b/main/app.c
index 04aca2b8c..f01d06513 100644
--- a/main/app.c
+++ b/main/app.c
@@ -1029,30 +1029,42 @@ int ast_linear_stream(struct ast_channel *chan, const char *filename, int fd, in
{
struct linear_state *lin;
char tmpf[256];
- int res = -1;
int autoclose = 0;
+
if (fd < 0) {
if (ast_strlen_zero(filename)) {
return -1;
}
+
autoclose = 1;
+
if (filename[0] == '/') {
ast_copy_string(tmpf, filename, sizeof(tmpf));
} else {
snprintf(tmpf, sizeof(tmpf), "%s/%s/%s", ast_config_AST_DATA_DIR, "sounds", filename);
}
- if ((fd = open(tmpf, O_RDONLY)) < 0) {
+
+ fd = open(tmpf, O_RDONLY);
+ if (fd < 0) {
ast_log(LOG_WARNING, "Unable to open file '%s': %s\n", tmpf, strerror(errno));
return -1;
}
}
- if ((lin = ast_calloc(1, sizeof(*lin)))) {
- lin->fd = fd;
- lin->allowoverride = allowoverride;
- lin->autoclose = autoclose;
- res = ast_activate_generator(chan, &linearstream, lin);
+
+ lin = ast_calloc(1, sizeof(*lin));
+ if (!lin) {
+ if (autoclose) {
+ close(fd);
+ }
+
+ return -1;
}
- return res;
+
+ lin->fd = fd;
+ lin->allowoverride = allowoverride;
+ lin->autoclose = autoclose;
+
+ return ast_activate_generator(chan, &linearstream, lin);
}
static int control_streamfile(struct ast_channel *chan,
@@ -1351,10 +1363,10 @@ int ast_control_tone(struct ast_channel *chan, const char *tone)
ts = ast_get_indication_tone(zone ? zone : ast_channel_zone(chan), tone_indication);
if (ast_playtones_start(chan, 0, ts ? ts->data : tone_indication, 0)) {
- return -1;
+ res = -1;
}
- for (;;) {
+ while (!res) {
struct ast_frame *fr;
if (ast_waitfor(chan, -1) < 0) {
diff --git a/main/asterisk.c b/main/asterisk.c
index 2e06f1984..015c9f35a 100644
--- a/main/asterisk.c
+++ b/main/asterisk.c
@@ -2519,52 +2519,6 @@ static int remoteconsolehandler(const char *s)
(s[4] == '\0' || isspace(s[4]))) {
quit_handler(0, SHUTDOWN_FAST, 0);
ret = 1;
- } else if (s[0]) {
- char *shrunk = ast_strdupa(s);
- char *cur;
- char *prev;
-
- /*
- * Remove duplicate spaces from shrunk for matching purposes.
- *
- * shrunk has at least one character in it to start with or we
- * couldn't get here.
- */
- for (prev = shrunk, cur = shrunk + 1; *cur; ++cur) {
- if (*prev == ' ' && *cur == ' ') {
- /* Skip repeated space delimiter. */
- continue;
- }
- *++prev = *cur;
- }
- *++prev = '\0';
-
- if (strncasecmp(shrunk, "core set verbose ", 17) == 0) {
- /*
- * We need to still set the rasterisk option_verbose in case we are
- * talking to an earlier version which doesn't prefilter verbose
- * levels. This is really a compromise as we should always take
- * whatever the server sends.
- */
-
- if (!strncasecmp(shrunk + 17, "off", 3)) {
- ast_verb_console_set(0);
- } else {
- int verbose_new;
- int atleast;
-
- atleast = 8;
- if (strncasecmp(shrunk + 17, "atleast ", atleast)) {
- atleast = 0;
- }
-
- if (sscanf(shrunk + 17 + atleast, "%30d", &verbose_new) == 1) {
- if (!atleast || ast_verb_console_get() < verbose_new) {
- ast_verb_console_set(verbose_new);
- }
- }
- }
- }
}
return ret;
@@ -2889,6 +2843,9 @@ static void send_rasterisk_connect_commands(void)
fdsend(ast_consock, buf);
}
+ /* Leave verbose filtering to the server. */
+ option_verbose = INT_MAX;
+
if (!ast_opt_mute) {
fdsend(ast_consock, "logger mute silent");
} else {
diff --git a/main/cdr.c b/main/cdr.c
index 60532fe9f..0b571fe0e 100644
--- a/main/cdr.c
+++ b/main/cdr.c
@@ -241,8 +241,29 @@ static struct aco_type general_option = {
.type = ACO_GLOBAL,
.name = "general",
.item_offset = offsetof(struct module_config, general),
- .category = "^general$",
- .category_match = ACO_WHITELIST,
+ .category = "general",
+ .category_match = ACO_WHITELIST_EXACT,
+};
+
+/*! Config sections used by existing modules. Do not add to this list. */
+static const char *ignore_categories[] = {
+ "csv",
+ "custom",
+ "manager",
+ "odbc",
+ "pgsql",
+ "radius",
+ "sqlite",
+ "tds",
+ "mysql",
+ NULL,
+};
+
+static struct aco_type ignore_option = {
+ .type = ACO_IGNORE,
+ .name = "modules",
+ .category = (const char*)ignore_categories,
+ .category_match = ACO_WHITELIST_ARRAY,
};
static void *module_config_alloc(void);
@@ -252,8 +273,7 @@ static void module_config_post_apply(void);
/*! \brief The file definition */
static struct aco_file module_file_conf = {
.filename = "cdr.conf",
- .skip_category = "(^csv$|^custom$|^manager$|^odbc$|^pgsql$|^radius$|^sqlite$|^tds$|^mysql$)",
- .types = ACO_TYPES(&general_option),
+ .types = ACO_TYPES(&general_option, &ignore_option),
};
CONFIG_INFO_CORE("cdr", cfg_info, module_configs, module_config_alloc,
@@ -2454,12 +2474,12 @@ static void bridge_candidate_add_to_cdr(struct cdr_object *cdr,
* \param cand_cdr The \ref cdr_object that is a candidate
*
*/
-static int bridge_candidate_process(struct cdr_object *cdr, struct cdr_object *base_cand_cdr)
+static void bridge_candidate_process(struct cdr_object *cdr, struct cdr_object *base_cand_cdr)
{
struct cdr_object_snapshot *party_a;
struct cdr_object *cand_cdr;
- SCOPED_AO2LOCK(lock, base_cand_cdr);
+ ao2_lock(base_cand_cdr);
for (cand_cdr = base_cand_cdr; cand_cdr; cand_cdr = cand_cdr->next) {
/* Skip any records that are not in this bridge */
@@ -2471,7 +2491,7 @@ static int bridge_candidate_process(struct cdr_object *cdr, struct cdr_object *b
if (!strcasecmp(cdr->party_a.snapshot->name, cand_cdr->party_a.snapshot->name)
|| (cdr->party_b.snapshot
&& !strcasecmp(cdr->party_b.snapshot->name, cand_cdr->party_a.snapshot->name))) {
- return 0;
+ break;
}
party_a = cdr_object_pick_party_a(&cdr->party_a, &cand_cdr->party_a);
@@ -2479,7 +2499,7 @@ static int bridge_candidate_process(struct cdr_object *cdr, struct cdr_object *b
* Party B */
if (!strcasecmp(party_a->snapshot->name, cdr->party_a.snapshot->name)) {
bridge_candidate_add_to_cdr(cdr, &cand_cdr->party_a);
- return 0;
+ break;
}
/* We're Party B. Check if we can add ourselves immediately or if we need
@@ -2499,9 +2519,11 @@ static int bridge_candidate_process(struct cdr_object *cdr, struct cdr_object *b
*/
memset(&cand_cdr->end, 0, sizeof(cand_cdr->end));
}
- return 0;
+
+ break;
}
- return 0;
+
+ ao2_unlock(base_cand_cdr);
}
/*!
@@ -2584,6 +2606,7 @@ static void handle_standard_bridge_enter_message(struct cdr_object *cdr,
ao2_lock(cdr);
+try_again:
for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
if (it_cdr->fn_table->process_party_a) {
CDR_DEBUG("%p - Updating Party A %s snapshot\n", it_cdr,
@@ -2636,7 +2659,7 @@ static void handle_standard_bridge_enter_message(struct cdr_object *cdr,
/* This is guaranteed to succeed: the new CDR is created in the single state
* and will be able to handle the bridge enter message
*/
- handle_standard_bridge_enter_message(cdr, bridge, channel);
+ goto try_again;
}
}
ao2_unlock(cdr);
diff --git a/main/cel.c b/main/cel.c
index 0cdf1be00..24d7faa85 100644
--- a/main/cel.c
+++ b/main/cel.c
@@ -244,15 +244,28 @@ static struct aco_type general_option = {
.type = ACO_GLOBAL,
.name = "general",
.item_offset = offsetof(struct cel_config, general),
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
+};
+
+/*! Config sections used by existing modules. Do not add to this list. */
+static const char *ignore_categories[] = {
+ "manager",
+ "radius",
+ NULL,
+};
+
+static struct aco_type ignore_option = {
+ .type = ACO_IGNORE,
+ .name = "modules",
+ .category = (const char*)ignore_categories,
+ .category_match = ACO_WHITELIST_ARRAY,
};
/*! \brief The config file to be processed for the module. */
static struct aco_file cel_conf = {
.filename = "cel.conf", /*!< The name of the config file */
- .types = ACO_TYPES(&general_option), /*!< The mapping object types to be processed */
- .skip_category = "(^manager$|^radius$)", /*!< Config sections used by existing modules. Do not add to this list. */
+ .types = ACO_TYPES(&general_option, &ignore_option), /*!< The mapping object types to be processed */
};
static int cel_pre_apply_config(void);
@@ -1824,9 +1837,9 @@ void ast_cel_publish_event(struct ast_channel *chan,
struct ast_json *cel_blob;
struct stasis_message *message;
- cel_blob = ast_json_pack("{s: i, s: O}",
+ cel_blob = ast_json_pack("{s: i, s: o}",
"event_type", event_type,
- "event_details", blob);
+ "event_details", ast_json_ref(blob));
message = ast_channel_blob_create_from_cache(ast_channel_uniqueid(chan), cel_generic_type(), cel_blob);
if (message) {
diff --git a/main/cli.c b/main/cli.c
index 8e0cc3bd3..7039b72fc 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -1418,6 +1418,8 @@ static char *handle_core_set_debug_channel(struct ast_cli_entry *e, int cmd, str
} else if (a->pos == 5) {
return ast_cli_complete(a->word, completions_off, a->n);
}
+
+ return NULL;
}
if (cmd == (CLI_HANDLER + 1000)) {
diff --git a/main/config_options.c b/main/config_options.c
index f52d3c410..5f6fcbe85 100644
--- a/main/config_options.c
+++ b/main/config_options.c
@@ -133,7 +133,7 @@ static int noop_handler_fn(const struct aco_option *opt, struct ast_variable *va
static int chararray_handler_fn(const struct aco_option *opt, struct ast_variable *var, void *obj);
#ifdef AST_XML_DOCS
-static int xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, unsigned int matches);
+static int xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, enum aco_category_op category_match);
static int xmldoc_update_config_option(struct aco_type **types, const char *module, const char *name, const char *object_name, const char *default_value, unsigned int regex, enum aco_option_type type);
#endif
@@ -375,6 +375,8 @@ static int find_option_cb(void *obj, void *arg, int flags)
switch (match->match_type) {
case ACO_EXACT:
return strcasecmp(name, match->name) ? 0 : CMP_MATCH | CMP_STOP;
+ case ACO_PREFIX:
+ return strncasecmp(name, match->name, strlen(match->name)) ? 0 : CMP_MATCH | CMP_STOP;
case ACO_REGEX:
return regexec(match->name_regex, name, 0, NULL, 0) ? 0 : CMP_MATCH | CMP_STOP;
}
@@ -404,6 +406,45 @@ struct ao2_container *aco_option_container_alloc(void)
return ao2_container_alloc(CONFIG_OPT_BUCKETS, config_opt_hash, config_opt_cmp);
}
+static int internal_aco_type_category_check(struct aco_type *match, const char *category)
+{
+ const char **categories = (const char **)match->category;
+
+ switch (match->category_match) {
+ case ACO_WHITELIST:
+ return regexec(match->internal->regex, category, 0, NULL, 0);
+
+ case ACO_BLACKLIST:
+ return !regexec(match->internal->regex, category, 0, NULL, 0);
+
+ case ACO_WHITELIST_EXACT:
+ return strcasecmp(match->category, category);
+
+ case ACO_BLACKLIST_EXACT:
+ return !strcasecmp(match->category, category);
+
+ case ACO_WHITELIST_ARRAY:
+ while (*categories) {
+ if (!strcasecmp(*categories, category)) {
+ return 0;
+ }
+ categories++;
+ }
+ return -1;
+
+ case ACO_BLACKLIST_ARRAY:
+ while (*categories) {
+ if (!strcasecmp(*categories, category)) {
+ return -1;
+ }
+ categories++;
+ }
+ return 0;
+ }
+
+ return -1;
+}
+
static struct aco_type *internal_aco_type_find(struct aco_file *file, struct ast_config *cfg, const char *category)
{
size_t x;
@@ -412,7 +453,7 @@ static struct aco_type *internal_aco_type_find(struct aco_file *file, struct ast
for (x = 0, match = file->types[x]; match; match = file->types[++x]) {
/* First make sure we are an object that can service this category */
- if (!regexec(match->internal->regex, category, 0, NULL, 0) == !match->category_match) {
+ if (internal_aco_type_category_check(match, category)) {
continue;
}
@@ -485,6 +526,10 @@ static int process_category(struct ast_config *cfg, struct aco_info *info, struc
return -1;
}
+ if (type->type == ACO_IGNORE) {
+ return 0;
+ }
+
field = info->internal->pending + type->item_offset;
if (!*field) {
ast_log(LOG_ERROR, "In %s: %s - No object to update!\n", file->filename, cat);
@@ -633,6 +678,10 @@ enum aco_process_status aco_process_config(struct aco_info *info, int reload)
for (i = 0, match = file->types[i]; match; match = file->types[++i]) {
void **field = info->internal->pending + match->item_offset;
+ if (match->type == ACO_IGNORE) {
+ continue;
+ }
+
if (match->type != ACO_GLOBAL || !*field) {
continue;
}
@@ -799,9 +848,19 @@ static int internal_type_init(struct aco_type *type)
return -1;
}
- if (!(type->internal->regex = build_regex(type->category))) {
- internal_type_destroy(type);
- return -1;
+ switch (type->category_match) {
+ case ACO_BLACKLIST:
+ case ACO_WHITELIST:
+ if (!(type->internal->regex = build_regex(type->category))) {
+ internal_type_destroy(type);
+ return -1;
+ }
+ break;
+ case ACO_BLACKLIST_EXACT:
+ case ACO_WHITELIST_EXACT:
+ case ACO_BLACKLIST_ARRAY:
+ case ACO_WHITELIST_ARRAY:
+ break;
}
if (!(type->internal->opts = aco_option_container_alloc())) {
@@ -830,7 +889,8 @@ int aco_info_init(struct aco_info *info)
#ifdef AST_XML_DOCS
if (!info->hidden &&
!type->hidden &&
- xmldoc_update_config_type(info->module, type->name, type->category, type->matchfield, type->matchvalue, type->category_match == ACO_WHITELIST)) {
+ type->type != ACO_IGNORE &&
+ xmldoc_update_config_type(info->module, type->name, type->category, type->matchfield, type->matchvalue, type->category_match)) {
goto error;
}
#endif /* AST_XML_DOCS */
@@ -991,7 +1051,7 @@ static char *complete_config_option(const char *module, const char *option, cons
/*! \internal
* \brief Update the XML documentation for a config type based on its registration
*/
-static int xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, unsigned int matches)
+static int xmldoc_update_config_type(const char *module, const char *name, const char *category, const char *matchfield, const char *matchvalue, enum aco_category_op category_match)
{
RAII_VAR(struct ast_xml_xpath_results *, results, NULL, ast_xml_xpath_results_free);
RAII_VAR(struct ast_xml_doc_item *, config_info, ao2_find(xmldocs, module, OBJ_KEY), ao2_cleanup);
@@ -1030,7 +1090,18 @@ static int xmldoc_update_config_type(const char *module, const char *name, const
}
ast_xml_set_text(tmp, category);
- ast_xml_set_attribute(tmp, "match", matches ? "true" : "false");
+ switch (category_match) {
+ case ACO_WHITELIST:
+ case ACO_WHITELIST_EXACT:
+ case ACO_WHITELIST_ARRAY:
+ ast_xml_set_attribute(tmp, "match", "true");
+ break;
+ case ACO_BLACKLIST:
+ case ACO_BLACKLIST_EXACT:
+ case ACO_BLACKLIST_ARRAY:
+ ast_xml_set_attribute(tmp, "match", "false");
+ break;
+ }
if (!ast_strlen_zero(matchfield) && !(tmp = ast_xml_new_child(matchinfo, "field"))) {
ast_log(LOG_WARNING, "Could not add %s attribute for type '%s' in module '%s'\n", matchfield, name, module);
diff --git a/main/features_config.c b/main/features_config.c
index 2689687cc..e2d405740 100644
--- a/main/features_config.c
+++ b/main/features_config.c
@@ -219,7 +219,7 @@
The <replaceable>DYNAMIC_FEATURES</replaceable> is a <literal>#</literal> separated list of
either applicationmap item names or featuregroup names.</para>
</description>
- <configOption name="^.*$" regex="true">
+ <configOption name="">
<synopsis>A custom feature to invoke during a bridged call</synopsis>
<description>
<para>Each item listed here is a comma-separated list of parameters that determine
@@ -272,7 +272,7 @@
DTMF sequence used to invoke an applicationmap item to be overridden with
a different sequence.</para>
</description>
- <configOption name="^.*$" regex="true">
+ <configOption name="">
<synopsis>Applicationmap item to place in the feature group</synopsis>
<description>
<para>Each item here must be a name of an item in the applicationmap. The
@@ -578,24 +578,24 @@ struct features_config {
static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "globals",
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
.item_offset = offsetof(struct features_config, global),
};
static struct aco_type featuremap_option = {
.type = ACO_GLOBAL,
.name = "featuremap",
- .category_match = ACO_WHITELIST,
- .category = "^featuremap$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "featuremap",
.item_offset = offsetof(struct features_config, featuremap),
};
static struct aco_type applicationmap_option = {
.type = ACO_GLOBAL,
.name = "applicationmap",
- .category_match = ACO_WHITELIST,
- .category = "^applicationmap$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "applicationmap",
.item_offset = offsetof(struct features_config, applicationmap),
};
@@ -1851,13 +1851,13 @@ static int load_config(void)
aco_option_register_custom(&cfg_info, "automixmon", ACO_EXACT, featuremap_options,
DEFAULT_FEATUREMAP_AUTOMIXMON, featuremap_handler, 0);
- aco_option_register_custom(&cfg_info, "^.*$", ACO_REGEX, applicationmap_options,
+ aco_option_register_custom(&cfg_info, "", ACO_PREFIX, applicationmap_options,
"", applicationmap_handler, 0);
- aco_option_register_custom(&cfg_info, "^.*$", ACO_REGEX, featuregroup_options,
+ aco_option_register_custom(&cfg_info, "", ACO_PREFIX, featuregroup_options,
"", featuregroup_handler, 0);
- aco_option_register_custom_nodoc(&cfg_info, "^.*$", ACO_REGEX, parkinglot_options,
+ aco_option_register_custom_nodoc(&cfg_info, "", ACO_PREFIX, parkinglot_options,
"", unsupported_handler, 0);
if (aco_process_config(&cfg_info, 0) == ACO_PROCESS_ERROR) {
diff --git a/main/loader.c b/main/loader.c
index b1a02d542..c18fb379f 100644
--- a/main/loader.c
+++ b/main/loader.c
@@ -54,7 +54,7 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
#include "asterisk/features_config.h"
#include "asterisk/dsp.h"
#include "asterisk/udptl.h"
-#include "asterisk/heap.h"
+#include "asterisk/vector.h"
#include "asterisk/app.h"
#include "asterisk/test.h"
#include "asterisk/sounds_index.h"
@@ -112,6 +112,8 @@ static const unsigned char expected_key[] =
static char buildopt_sum[33] = AST_BUILDOPT_SUM;
+AST_VECTOR(module_vector, struct ast_module *);
+
/*!
* \brief Internal flag to indicate all modules have been initially loaded.
*/
@@ -137,13 +139,34 @@ struct ast_module {
/*! This module is being held open until it's time to shutdown. */
unsigned int keepuntilshutdown:1;
} flags;
- AST_LIST_ENTRY(ast_module) list_entry;
AST_DLLIST_ENTRY(ast_module) entry;
char resource[0];
};
static AST_DLLIST_HEAD_STATIC(module_list, ast_module);
+static int module_vector_strcasecmp(struct ast_module *a, struct ast_module *b)
+{
+ return strcasecmp(a->resource, b->resource);
+}
+
+static int module_vector_cmp(struct ast_module *a, struct ast_module *b)
+{
+ /* if load_pri is not set, default is 128. Lower is better */
+ int a_pri = ast_test_flag(a->info, AST_MODFLAG_LOAD_ORDER)
+ ? a->info->load_pri : AST_MODPRI_DEFAULT;
+ int b_pri = ast_test_flag(b->info, AST_MODFLAG_LOAD_ORDER)
+ ? b->info->load_pri : AST_MODPRI_DEFAULT;
+
+ /*
+ * Returns comparison values for a vector sorted by priority.
+ * <0 a_pri < b_pri
+ * =0 a_pri == b_pri
+ * >0 a_pri > b_pri
+ */
+ return a_pri - b_pri;
+}
+
const char *ast_module_name(const struct ast_module *mod)
{
if (!mod || !mod->info) {
@@ -171,38 +194,51 @@ static int do_full_reload = 0;
static AST_DLLIST_HEAD_STATIC(reload_queue, reload_queue_item);
-/* when dynamic modules are being loaded, ast_module_register() will
- need to know what filename the module was loaded from while it
- is being registered
-*/
+/*!
+ * \internal
+ *
+ * This variable is set by load_dynamic_module so ast_module_register
+ * can know what pointer is being registered.
+ *
+ * This is protected by the module_list lock.
+ */
static struct ast_module *resource_being_loaded;
-/* XXX: should we check for duplicate resource names here? */
-
+/*!
+ * \internal
+ * \brief Used by AST_MODULE_INFO to register with the module loader.
+ *
+ * This function is automatically called when each module is opened.
+ * It must never be used from outside AST_MODULE_INFO.
+ */
void ast_module_register(const struct ast_module_info *info)
{
- struct ast_module *mod = resource_being_loaded;
+ struct ast_module *mod;
+
+ /*
+ * This lock protects resource_being_loaded as well as the module
+ * list. Normally we already have a lock on module_list when we
+ * begin the load but locking again from here prevents corruption
+ * if an asterisk module is dlopen'ed from outside the module loader.
+ */
+ AST_DLLIST_LOCK(&module_list);
+ mod = resource_being_loaded;
+ if (!mod) {
+ AST_DLLIST_UNLOCK(&module_list);
+ return;
+ }
ast_debug(5, "Registering module %s\n", info->name);
+ /* This tells load_dynamic_module that we're registered. */
+ resource_being_loaded = NULL;
+
mod->info = info;
#ifdef REF_DEBUG
mod->ref_debug = ao2_t_alloc(0, NULL, info->name);
#endif
AST_LIST_HEAD_INIT(&mod->users);
- /* during startup, before the loader has been initialized,
- there are no threads, so there is no need to take the lock
- on this list to manipulate it. it is also possible that it
- might be unsafe to use the list lock at that point... so
- let's avoid it altogether
- */
- AST_DLLIST_LOCK(&module_list);
- /* it is paramount that the new entry be placed at the tail of
- the list, otherwise the code that uses dlopen() to load
- dynamic modules won't be able to find out if the module it
- just opened was registered or failed to load
- */
AST_DLLIST_INSERT_TAIL(&module_list, mod, entry);
AST_DLLIST_UNLOCK(&module_list);
@@ -210,6 +246,15 @@ void ast_module_register(const struct ast_module_info *info)
*((struct ast_module **) &(info->self)) = mod;
}
+static void module_destroy(struct ast_module *mod)
+{
+ AST_LIST_HEAD_DESTROY(&mod->users);
+#ifdef REF_DEBUG
+ ao2_cleanup(mod->ref_debug);
+#endif
+ ast_free(mod);
+}
+
void ast_module_unregister(const struct ast_module_info *info)
{
struct ast_module *mod = NULL;
@@ -230,11 +275,7 @@ void ast_module_unregister(const struct ast_module_info *info)
if (mod) {
ast_debug(5, "Unregistering module %s\n", info->name);
- AST_LIST_HEAD_DESTROY(&mod->users);
-#ifdef REF_DEBUG
- ao2_cleanup(mod->ref_debug);
-#endif
- ast_free(mod);
+ module_destroy(mod);
}
}
@@ -504,96 +545,93 @@ static void unload_dynamic_module(struct ast_module *mod)
#endif
}
-static enum ast_module_load_result load_resource(const char *resource_name, unsigned int global_symbols_only, unsigned int suppress_logging, struct ast_heap *resource_heap, int required);
-
#define MODULE_LOCAL_ONLY (void *)-1
-static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int global_symbols_only, unsigned int suppress_logging, struct ast_heap *resource_heap)
+/*!
+ * \internal
+ * \brief Attempt to dlopen a module.
+ *
+ * \param resource_in The module name to load.
+ * \param so_ext ".so" or blank if ".so" is already part of resource_in.
+ * \param filename Passed directly to dlopen.
+ * \param flags Passed directly to dlopen.
+ * \param suppress_logging Do not log any error from dlopen.
+ *
+ * \return Pointer to opened module, NULL on error.
+ *
+ * \warning module_list must be locked before calling this function.
+ */
+static struct ast_module *load_dlopen(const char *resource_in, const char *so_ext,
+ const char *filename, int flags, unsigned int suppress_logging)
{
- char fn[PATH_MAX] = "";
- void *lib = NULL;
struct ast_module *mod;
- unsigned int wants_global;
- int space; /* room needed for the descriptor */
- int missing_so = 0;
-
- space = sizeof(*resource_being_loaded) + strlen(resource_in) + 1;
- if (strcasecmp(resource_in + strlen(resource_in) - 3, ".so")) {
- missing_so = 1;
- space += 3; /* room for the extra ".so" */
- }
- snprintf(fn, sizeof(fn), "%s/%s%s", ast_config_AST_MODULE_DIR, resource_in, missing_so ? ".so" : "");
+ ast_assert(!resource_being_loaded);
- /* make a first load of the module in 'quiet' mode... don't try to resolve
- any symbols, and don't export any symbols. this will allow us to peek into
- the module's info block (if available) to see what flags it has set */
-
- resource_being_loaded = ast_calloc(1, space);
- if (!resource_being_loaded)
+ mod = ast_calloc(1, sizeof(*mod) + strlen(resource_in) + strlen(so_ext) + 1);
+ if (!mod) {
return NULL;
- strcpy(resource_being_loaded->resource, resource_in);
- if (missing_so)
- strcat(resource_being_loaded->resource, ".so");
+ }
+
+ sprintf(mod->resource, "%s%s", resource_in, so_ext); /* safe */
- if (!(lib = dlopen(fn, RTLD_LAZY | RTLD_GLOBAL))) {
- if (!suppress_logging) {
+ resource_being_loaded = mod;
+ mod->lib = dlopen(filename, flags);
+ if (resource_being_loaded) {
+ resource_being_loaded = NULL;
+ if (mod->lib) {
+ ast_log(LOG_ERROR, "Module '%s' did not register itself during load\n", resource_in);
+ logged_dlclose(resource_in, mod->lib);
+ } else if (!suppress_logging) {
ast_log(LOG_WARNING, "Error loading module '%s': %s\n", resource_in, dlerror());
}
- ast_free(resource_being_loaded);
- return NULL;
- }
+ ast_free(mod);
- /* the dlopen() succeeded, let's find out if the module
- registered itself */
- /* note that this will only work properly as long as
- ast_module_register() (which is called by the module's
- constructor) places the new module at the tail of the
- module_list
- */
- if (resource_being_loaded != (mod = AST_DLLIST_LAST(&module_list))) {
- ast_log(LOG_WARNING, "Module '%s' did not register itself during load\n", resource_in);
- /* no, it did not, so close it and return */
- logged_dlclose(resource_in, lib);
- /* note that the module's destructor will call ast_module_unregister(),
- which will free the structure we allocated in resource_being_loaded */
return NULL;
}
- wants_global = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);
+ return mod;
+}
- /* if we are being asked only to load modules that provide global symbols,
- and this one does not, then close it and return */
- if (global_symbols_only && !wants_global) {
- logged_dlclose(resource_in, lib);
- return MODULE_LOCAL_ONLY;
+static struct ast_module *load_dynamic_module(const char *resource_in, unsigned int global_symbols_only, unsigned int suppress_logging)
+{
+ char fn[PATH_MAX];
+ struct ast_module *mod;
+ size_t resource_in_len = strlen(resource_in);
+ int exports_globals;
+ const char *so_ext = "";
+
+ if (resource_in_len < 4 || strcasecmp(resource_in + resource_in_len - 3, ".so")) {
+ so_ext = ".so";
}
- logged_dlclose(resource_in, lib);
- resource_being_loaded = NULL;
+ snprintf(fn, sizeof(fn), "%s/%s%s", ast_config_AST_MODULE_DIR, resource_in, so_ext);
- /* start the load process again */
- resource_being_loaded = ast_calloc(1, space);
- if (!resource_being_loaded)
- return NULL;
- strcpy(resource_being_loaded->resource, resource_in);
- if (missing_so)
- strcat(resource_being_loaded->resource, ".so");
+ /* Try loading in quiet mode first with flags to export global symbols.
+ * If the module does not want to export globals we will close and reopen. */
+ mod = load_dlopen(resource_in, so_ext, fn,
+ global_symbols_only ? RTLD_LAZY | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL,
+ suppress_logging);
- if (!(lib = dlopen(fn, wants_global ? RTLD_LAZY | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL))) {
- ast_log(LOG_WARNING, "Error loading module '%s': %s\n", resource_in, dlerror());
- ast_free(resource_being_loaded);
+ if (!mod) {
return NULL;
}
- /* since the module was successfully opened, and it registered itself
- the previous time we did that, we're going to assume it worked this
- time too :) */
+ exports_globals = ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS);
+ if ((global_symbols_only && exports_globals) || (!global_symbols_only && !exports_globals)) {
+ /* The first dlopen had the correct flags. */
+ return mod;
+ }
- AST_DLLIST_LAST(&module_list)->lib = lib;
- resource_being_loaded = NULL;
+ /* Close the module so we can reopen with correct flags. */
+ logged_dlclose(resource_in, mod->lib);
+ if (global_symbols_only) {
+ return MODULE_LOCAL_ONLY;
+ }
- return AST_DLLIST_LAST(&module_list);
+ return load_dlopen(resource_in, so_ext, fn,
+ exports_globals ? RTLD_LAZY | RTLD_GLOBAL : RTLD_NOW | RTLD_LOCAL,
+ 0);
}
int modules_shutdown(void)
@@ -627,11 +665,7 @@ int modules_shutdown(void)
ast_verb(1, "Unloading %s\n", mod->resource);
mod->info->unload();
}
- AST_LIST_HEAD_DESTROY(&mod->users);
-#ifdef REF_DEBUG
- ao2_cleanup(mod->ref_debug);
-#endif
- free(mod);
+ module_destroy(mod);
somethingchanged = 1;
}
AST_DLLIST_TRAVERSE_BACKWARDS_SAFE_END;
@@ -1128,13 +1162,13 @@ static enum ast_module_load_result start_resource(struct ast_module *mod)
/*! loads a resource based upon resource_name. If global_symbols_only is set
* only modules with global symbols will be loaded.
*
- * If the ast_heap is provided (not NULL) the module is found and added to the
- * heap without running the module's load() function. By doing this, modules
- * added to the resource_heap can be initialized later in order by priority.
+ * If the module_vector is provided (not NULL) the module is found and added to the
+ * vector without running the module's load() function. By doing this, modules
+ * can be initialized later in order by priority and dependencies.
*
- * If the ast_heap is not provided, the module's load function will be executed
+ * If the module_vector is not provided, the module's load function will be executed
* immediately */
-static enum ast_module_load_result load_resource(const char *resource_name, unsigned int global_symbols_only, unsigned int suppress_logging, struct ast_heap *resource_heap, int required)
+static enum ast_module_load_result load_resource(const char *resource_name, unsigned int global_symbols_only, unsigned int suppress_logging, struct module_vector *resource_heap, int required)
{
struct ast_module *mod;
enum ast_module_load_result res = AST_MODULE_LOAD_SUCCESS;
@@ -1147,7 +1181,7 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
if (global_symbols_only && !ast_test_flag(mod->info, AST_MODFLAG_GLOBAL_SYMBOLS))
return AST_MODULE_LOAD_SKIP;
} else {
- mod = load_dynamic_module(resource_name, global_symbols_only, suppress_logging, resource_heap);
+ mod = load_dynamic_module(resource_name, global_symbols_only, suppress_logging);
if (mod == MODULE_LOCAL_ONLY) {
return AST_MODULE_LOAD_SKIP;
}
@@ -1160,21 +1194,26 @@ static enum ast_module_load_result load_resource(const char *resource_name, unsi
}
if (inspect_module(mod)) {
- ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);
- unload_dynamic_module(mod);
- return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;
+ goto prestart_error;
}
mod->flags.declined = 0;
if (resource_heap) {
- ast_heap_push(resource_heap, mod);
+ if (AST_VECTOR_ADD_SORTED(resource_heap, mod, module_vector_cmp)) {
+ goto prestart_error;
+ }
res = AST_MODULE_LOAD_PRIORITY;
} else {
res = start_resource(mod);
}
return res;
+
+prestart_error:
+ ast_log(LOG_WARNING, "Module '%s' could not be loaded.\n", resource_name);
+ unload_dynamic_module(mod);
+ return required ? AST_MODULE_LOAD_FAILURE : AST_MODULE_LOAD_DECLINE;
}
int ast_load_resource(const char *resource_name)
@@ -1222,23 +1261,6 @@ static struct load_order_entry *add_to_load_order(const char *resource, struct l
return order;
}
-static int mod_load_cmp(void *a, void *b)
-{
- struct ast_module *a_mod = (struct ast_module *) a;
- struct ast_module *b_mod = (struct ast_module *) b;
- /* if load_pri is not set, default is 128. Lower is better */
- int a_pri = ast_test_flag(a_mod->info, AST_MODFLAG_LOAD_ORDER) ? a_mod->info->load_pri : 128;
- int b_pri = ast_test_flag(b_mod->info, AST_MODFLAG_LOAD_ORDER) ? b_mod->info->load_pri : 128;
-
- /*
- * Returns comparison values for a min-heap
- * <0 a_pri > b_pri
- * =0 a_pri == b_pri
- * >0 a_pri < b_pri
- */
- return b_pri - a_pri;
-}
-
AST_LIST_HEAD_NOLOCK(load_retries, load_order_entry);
/*! loads modules in order by load_pri, updates mod_count
@@ -1246,9 +1268,8 @@ AST_LIST_HEAD_NOLOCK(load_retries, load_order_entry);
*/
static int load_resource_list(struct load_order *load_order, unsigned int global_symbols, int *mod_count)
{
- struct ast_heap *resource_heap;
+ struct module_vector resource_heap;
struct load_order_entry *order;
- struct ast_module *mod;
struct load_retries load_retries;
int count = 0;
int res = 0;
@@ -1257,7 +1278,9 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
AST_LIST_HEAD_INIT_NOLOCK(&load_retries);
- if(!(resource_heap = ast_heap_create(8, mod_load_cmp, -1))) {
+ if (AST_VECTOR_INIT(&resource_heap, 500)) {
+ ast_log(LOG_ERROR, "Failed to initialize module loader.\n");
+
return -1;
}
@@ -1266,7 +1289,7 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
enum ast_module_load_result lres;
/* Suppress log messages unless this is the last pass */
- lres = load_resource(order->resource, global_symbols, 1, resource_heap, order->required);
+ lres = load_resource(order->resource, global_symbols, 1, &resource_heap, order->required);
ast_debug(3, "PASS 0: %-46s %d %d\n", order->resource, lres, global_symbols);
switch (lres) {
case AST_MODULE_LOAD_SUCCESS:
@@ -1290,7 +1313,7 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
*/
break;
case AST_MODULE_LOAD_PRIORITY:
- /* load_resource worked and the module was added to the priority heap */
+ /* load_resource worked and the module was added to the priority vector */
AST_LIST_REMOVE_CURRENT(entry);
ast_free(order->resource);
ast_free(order);
@@ -1305,7 +1328,7 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
enum ast_module_load_result lres;
/* Suppress log messages unless this is the last pass */
- lres = load_resource(order->resource, global_symbols, (i < LOAD_RETRIES - 1), resource_heap, order->required);
+ lres = load_resource(order->resource, global_symbols, (i < LOAD_RETRIES - 1), &resource_heap, order->required);
ast_debug(3, "PASS %d %-46s %d %d\n", i + 1, order->resource, lres, global_symbols);
switch (lres) {
/* These are all retryable. */
@@ -1343,7 +1366,8 @@ static int load_resource_list(struct load_order *load_order, unsigned int global
}
/* second remove modules from heap sorted by priority */
- while ((mod = ast_heap_pop(resource_heap))) {
+ for (i = 0; i < AST_VECTOR_SIZE(&resource_heap); i++) {
+ struct ast_module *mod = AST_VECTOR_GET(&resource_heap, i);
enum ast_module_load_result lres;
lres = start_resource(mod);
@@ -1373,7 +1397,7 @@ done:
if (mod_count) {
*mod_count += count;
}
- ast_heap_destroy(resource_heap);
+ AST_VECTOR_FREE(&resource_heap);
return res;
}
@@ -1511,33 +1535,57 @@ void ast_update_use_count(void)
AST_LIST_UNLOCK(&updaters);
}
+/*!
+ * \internal
+ * \brief Build an alpha sorted list of modules.
+ *
+ * \param alpha_module_list Pointer to uninitialized module_vector.
+ *
+ * This function always initializes alpha_module_list.
+ *
+ * \pre module_list must be locked.
+ */
+static int alpha_module_list_create(struct module_vector *alpha_module_list)
+{
+ struct ast_module *cur;
+
+ if (AST_VECTOR_INIT(alpha_module_list, 32)) {
+ return -1;
+ }
+
+ AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
+ if (AST_VECTOR_ADD_SORTED(alpha_module_list, cur, module_vector_strcasecmp)) {
+ return -1;
+ }
+ }
+
+ return 0;
+}
+
int ast_update_module_list(int (*modentry)(const char *module, const char *description,
int usecnt, const char *status, const char *like,
enum ast_module_support_level support_level),
const char *like)
{
- struct ast_module *cur;
- int unlock = -1;
int total_mod_loaded = 0;
- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+ struct module_vector alpha_module_list;
- if (AST_DLLIST_TRYLOCK(&module_list)) {
- unlock = 0;
- }
+ AST_DLLIST_LOCK(&module_list);
- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
- }
+ if (!alpha_module_list_create(&alpha_module_list)) {
+ int idx;
- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
- total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
- cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
- }
+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
- if (unlock) {
- AST_DLLIST_UNLOCK(&module_list);
+ total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
+ cur->flags.running ? "Running" : "Not Running", like, cur->info->support_level);
+ }
}
+ AST_DLLIST_UNLOCK(&module_list);
+ AST_VECTOR_FREE(&alpha_module_list);
+
return total_mod_loaded;
}
@@ -1547,22 +1595,24 @@ int ast_update_module_list_data(int (*modentry)(const char *module, const char *
void *data),
const char *like, void *data)
{
- struct ast_module *cur;
int total_mod_loaded = 0;
- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+ struct module_vector alpha_module_list;
AST_DLLIST_LOCK(&module_list);
- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
- }
+ if (!alpha_module_list_create(&alpha_module_list)) {
+ int idx;
- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
- total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
- cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);
+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
+
+ total_mod_loaded += modentry(cur->resource, cur->info->description, cur->usecount,
+ cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data);
+ }
}
AST_DLLIST_UNLOCK(&module_list);
+ AST_VECTOR_FREE(&alpha_module_list);
return total_mod_loaded;
}
@@ -1574,23 +1624,25 @@ int ast_update_module_list_condition(int (*modentry)(const char *module, const c
void *data, const char *condition),
const char *like, void *data, const char *condition)
{
- struct ast_module *cur;
int conditions_met = 0;
- AST_LIST_HEAD_NOLOCK(, ast_module) alpha_module_list = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
+ struct module_vector alpha_module_list;
AST_DLLIST_LOCK(&module_list);
- AST_DLLIST_TRAVERSE(&module_list, cur, entry) {
- AST_LIST_INSERT_SORTALPHA(&alpha_module_list, cur, list_entry, resource);
- }
+ if (!alpha_module_list_create(&alpha_module_list)) {
+ int idx;
- while ((cur = AST_LIST_REMOVE_HEAD(&alpha_module_list, list_entry))) {
- conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,
- cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,
- condition);
+ for (idx = 0; idx < AST_VECTOR_SIZE(&alpha_module_list); idx++) {
+ struct ast_module *cur = AST_VECTOR_GET(&alpha_module_list, idx);
+
+ conditions_met += modentry(cur->resource, cur->info->description, cur->usecount,
+ cur->flags.running? "Running" : "Not Running", like, cur->info->support_level, data,
+ condition);
+ }
}
AST_DLLIST_UNLOCK(&module_list);
+ AST_VECTOR_FREE(&alpha_module_list);
return conditions_met;
}
diff --git a/main/manager_system.c b/main/manager_system.c
index b852c52e6..7a4896a68 100644
--- a/main/manager_system.c
+++ b/main/manager_system.c
@@ -44,7 +44,6 @@ static void manager_system_shutdown(void)
int manager_system_init(void)
{
- int ret = 0;
struct stasis_topic *manager_topic;
struct stasis_topic *system_topic;
struct stasis_message_router *message_router;
@@ -69,13 +68,5 @@ int manager_system_init(void)
ast_register_cleanup(manager_system_shutdown);
- /* If somehow we failed to add any routes, just shut down the whole
- * thing and fail it.
- */
- if (ret) {
- manager_system_shutdown();
- return -1;
- }
-
return 0;
}
diff --git a/main/named_acl.c b/main/named_acl.c
index 3b81c8c38..47787e921 100644
--- a/main/named_acl.c
+++ b/main/named_acl.c
@@ -82,8 +82,8 @@ static void *named_acl_find(struct ao2_container *container, const char *cat);
static struct aco_type named_acl_type = {
.type = ACO_ITEM, /*!< named_acls are items stored in containers, not individual global objects */
.name = "named_acl",
- .category_match = ACO_BLACKLIST,
- .category = "^general$", /*!< Match everything but "general" */
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general", /*!< Match everything but "general" */
.item_alloc = named_acl_alloc, /*!< A callback to allocate a new named_acl based on category */
.item_find = named_acl_find, /*!< A callback to find a named_acl in some container of named_acls */
.item_offset = offsetof(struct named_acl_config, named_acl_list), /*!< Could leave this out since 0 */
diff --git a/main/rtp_engine.c b/main/rtp_engine.c
index b12761bc4..67349cefa 100644
--- a/main/rtp_engine.c
+++ b/main/rtp_engine.c
@@ -2501,10 +2501,10 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
const struct stasis_message_sanitizer *sanitize)
{
struct rtcp_message_payload *payload = stasis_message_data(msg);
- RAII_VAR(struct ast_json *, json_rtcp_report, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, json_rtcp_report_blocks, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, json_rtcp_sender_info, NULL, ast_json_unref);
- RAII_VAR(struct ast_json *, json_channel, NULL, ast_json_unref);
+ struct ast_json *json_rtcp_report = NULL;
+ struct ast_json *json_rtcp_report_blocks;
+ struct ast_json *json_rtcp_sender_info = NULL;
+ struct ast_json *json_channel = NULL;
int i;
json_rtcp_report_blocks = ast_json_array_create();
@@ -2515,20 +2515,19 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
for (i = 0; i < payload->report->reception_report_count && payload->report->report_block[i]; i++) {
struct ast_json *json_report_block;
char str_lsr[32];
+
snprintf(str_lsr, sizeof(str_lsr), "%u", payload->report->report_block[i]->lsr);
json_report_block = ast_json_pack("{s: i, s: i, s: i, s: i, s: i, s: s, s: i}",
- "source_ssrc", payload->report->report_block[i]->source_ssrc,
- "fraction_lost", payload->report->report_block[i]->lost_count.fraction,
- "packets_lost", payload->report->report_block[i]->lost_count.packets,
- "highest_seq_no", payload->report->report_block[i]->highest_seq_no,
- "ia_jitter", payload->report->report_block[i]->ia_jitter,
- "lsr", str_lsr,
- "dlsr", payload->report->report_block[i]->dlsr);
- if (!json_report_block) {
- return NULL;
- }
-
- if (ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
+ "source_ssrc", payload->report->report_block[i]->source_ssrc,
+ "fraction_lost", payload->report->report_block[i]->lost_count.fraction,
+ "packets_lost", payload->report->report_block[i]->lost_count.packets,
+ "highest_seq_no", payload->report->report_block[i]->highest_seq_no,
+ "ia_jitter", payload->report->report_block[i]->ia_jitter,
+ "lsr", str_lsr,
+ "dlsr", payload->report->report_block[i]->dlsr);
+ if (!json_report_block
+ || ast_json_array_append(json_rtcp_report_blocks, json_report_block)) {
+ ast_json_unref(json_rtcp_report_blocks);
return NULL;
}
}
@@ -2536,25 +2535,27 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
if (payload->report->type == AST_RTP_RTCP_SR) {
char sec[32];
char usec[32];
+
snprintf(sec, sizeof(sec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_sec);
snprintf(usec, sizeof(usec), "%lu", (unsigned long)payload->report->sender_information.ntp_timestamp.tv_usec);
json_rtcp_sender_info = ast_json_pack("{s: s, s: s, s: i, s: i, s: i}",
- "ntp_timestamp_sec", sec,
- "ntp_timestamp_usec", usec,
- "rtp_timestamp", payload->report->sender_information.rtp_timestamp,
- "packets", payload->report->sender_information.packet_count,
- "octets", payload->report->sender_information.octet_count);
+ "ntp_timestamp_sec", sec,
+ "ntp_timestamp_usec", usec,
+ "rtp_timestamp", payload->report->sender_information.rtp_timestamp,
+ "packets", payload->report->sender_information.packet_count,
+ "octets", payload->report->sender_information.octet_count);
if (!json_rtcp_sender_info) {
+ ast_json_unref(json_rtcp_report_blocks);
return NULL;
}
}
json_rtcp_report = ast_json_pack("{s: i, s: i, s: i, s: o, s: o}",
- "ssrc", payload->report->ssrc,
- "type", payload->report->type,
- "report_count", payload->report->reception_report_count,
- "sender_information", json_rtcp_sender_info ? ast_json_ref(json_rtcp_sender_info) : ast_json_ref(ast_json_null()),
- "report_blocks", ast_json_ref(json_rtcp_report_blocks));
+ "ssrc", payload->report->ssrc,
+ "type", payload->report->type,
+ "report_count", payload->report->reception_report_count,
+ "sender_information", json_rtcp_sender_info ?: ast_json_null(),
+ "report_blocks", json_rtcp_report_blocks);
if (!json_rtcp_report) {
return NULL;
}
@@ -2562,14 +2563,15 @@ static struct ast_json *rtcp_report_to_json(struct stasis_message *msg,
if (payload->snapshot) {
json_channel = ast_channel_snapshot_to_json(payload->snapshot, sanitize);
if (!json_channel) {
+ ast_json_unref(json_rtcp_report);
return NULL;
}
}
return ast_json_pack("{s: o, s: o, s: o}",
- "channel", payload->snapshot ? ast_json_ref(json_channel) : ast_json_ref(ast_json_null()),
- "rtcp_report", ast_json_ref(json_rtcp_report),
- "blob", ast_json_deep_copy(payload->blob));
+ "channel", payload->snapshot ? json_channel : ast_json_null(),
+ "rtcp_report", json_rtcp_report,
+ "blob", ast_json_deep_copy(payload->blob) ?: ast_json_null());
}
static void rtp_rtcp_report_dtor(void *obj)
diff --git a/main/stasis.c b/main/stasis.c
index 63d17dfaf..d9785ce73 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -1436,8 +1436,8 @@ static struct aco_type threadpool_option = {
.type = ACO_GLOBAL,
.name = "threadpool",
.item_offset = offsetof(struct stasis_config, threadpool_options),
- .category = "^threadpool$",
- .category_match = ACO_WHITELIST,
+ .category = "threadpool",
+ .category_match = ACO_WHITELIST_EXACT,
};
static struct aco_type *threadpool_options[] = ACO_TYPES(&threadpool_option);
@@ -1447,8 +1447,8 @@ static struct aco_type declined_option = {
.type = ACO_GLOBAL,
.name = "declined_message_types",
.item_offset = offsetof(struct stasis_config, declined_message_types),
- .category_match = ACO_WHITELIST,
- .category = "^declined_message_types$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "declined_message_types",
};
struct aco_type *declined_options[] = ACO_TYPES(&declined_option);
diff --git a/main/stdtime/localtime.c b/main/stdtime/localtime.c
index 5b5526e6f..64840e826 100644
--- a/main/stdtime/localtime.c
+++ b/main/stdtime/localtime.c
@@ -1508,16 +1508,14 @@ static int tzparse(const char *name, struct state *sp, const int lastditch)
}
} else {
long theirstdoffset;
- long theirdstoffset;
long theiroffset;
- int isdst;
int i;
int j;
if (*name != '\0')
return -1;
/*
- ** Initial values of theirstdoffset and theirdstoffset.
+ ** Initial values of theirstdoffset.
*/
theirstdoffset = 0;
for (i = 0; i < sp->timecnt; ++i) {
@@ -1528,19 +1526,6 @@ static int tzparse(const char *name, struct state *sp, const int lastditch)
break;
}
}
- theirdstoffset = 0;
- for (i = 0; i < sp->timecnt; ++i) {
- j = sp->types[i];
- if (sp->ttis[j].tt_isdst) {
- theirdstoffset =
- -sp->ttis[j].tt_gmtoff;
- break;
- }
- }
- /*
- ** Initially we're assumed to be in standard time.
- */
- isdst = FALSE;
theiroffset = theirstdoffset;
/*
** Now juggle transition times and types
@@ -1552,32 +1537,13 @@ static int tzparse(const char *name, struct state *sp, const int lastditch)
if (sp->ttis[j].tt_ttisgmt) {
/* No adjustment to transition time */
} else {
- /*
- ** If summer time is in effect, and the
- ** transition time was not specified as
- ** standard time, add the summer time
- ** offset to the transition time;
- ** otherwise, add the standard time
- ** offset to the transition time.
- */
- /*
- ** Transitions from DST to DDST
- ** will effectively disappear since
- ** POSIX provides for only one DST
- ** offset.
- */
- if (isdst && !sp->ttis[j].tt_ttisstd) {
- sp->ats[i] += dstoffset -
- theirdstoffset;
- } else {
- sp->ats[i] += stdoffset -
- theirstdoffset;
- }
+ /* Add the standard time offset to the transition time. */
+ sp->ats[i] += stdoffset - theirstdoffset;
}
theiroffset = -sp->ttis[j].tt_gmtoff;
- if (sp->ttis[j].tt_isdst)
- theirdstoffset = theiroffset;
- else theirstdoffset = theiroffset;
+ if (!sp->ttis[j].tt_isdst) {
+ theirstdoffset = theiroffset;
+ }
}
/*
** Finally, fill in ttis.
diff --git a/main/translate.c b/main/translate.c
index 4ffe27c33..0721f07b0 100644
--- a/main/translate.c
+++ b/main/translate.c
@@ -499,6 +499,7 @@ struct ast_trans_pvt *ast_translator_build_path(struct ast_format *dst, struct a
ast_log(LOG_WARNING, "No translator path from %s to %s\n",
ast_format_get_name(src), ast_format_get_name(dst));
AST_RWLIST_UNLOCK(&translators);
+ ast_translator_free_path(head);
return NULL;
}
if ((t->dst_codec.sample_rate == ast_format_get_sample_rate(dst)) && (t->dst_codec.type == ast_format_get_type(dst))) {
@@ -507,9 +508,7 @@ struct ast_trans_pvt *ast_translator_build_path(struct ast_format *dst, struct a
if (!(cur = newpvt(t, explicit_dst))) {
ast_log(LOG_WARNING, "Failed to build translator step from %s to %s\n",
ast_format_get_name(src), ast_format_get_name(dst));
- if (head) {
- ast_translator_free_path(head);
- }
+ ast_translator_free_path(head);
AST_RWLIST_UNLOCK(&translators);
return NULL;
}
diff --git a/main/udptl.c b/main/udptl.c
index 44e9eb9bb..83989f738 100644
--- a/main/udptl.c
+++ b/main/udptl.c
@@ -239,9 +239,9 @@ static int udptl_pre_apply_config(void);
static struct aco_type general_option = {
.type = ACO_GLOBAL,
.name = "global",
- .category_match = ACO_WHITELIST,
+ .category_match = ACO_WHITELIST_EXACT,
.item_offset = offsetof(struct udptl_config, general),
- .category = "^general$",
+ .category = "general",
};
static struct aco_type *general_options[] = ACO_TYPES(&general_option);
diff --git a/main/utils.c b/main/utils.c
index 0b8dc7aeb..b4ecffd7e 100644
--- a/main/utils.c
+++ b/main/utils.c
@@ -2664,7 +2664,7 @@ void ast_set_default_eid(struct ast_eid *eid)
unsigned char full_mac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
s = socket(AF_INET, SOCK_STREAM, 0);
- if (s <= 0) {
+ if (s < 0) {
ast_log(LOG_WARNING, "Unable to open socket for seeding global EID. "
"You will have to set it manually.\n");
return;
diff --git a/main/xmldoc.c b/main/xmldoc.c
index da753cd15..5addb23b4 100644
--- a/main/xmldoc.c
+++ b/main/xmldoc.c
@@ -1413,7 +1413,7 @@ static int xmldoc_parse_example(struct ast_xml_node *fixnode, struct ast_str **b
static int xmldoc_parse_specialtags(struct ast_xml_node *fixnode, const char *tabs, const char *posttabs, struct ast_str **buffer)
{
struct ast_xml_node *node = fixnode;
- int ret = 0, i, count = 0;
+ int ret = 0, i;
if (!node || !ast_xml_node_get_children(node)) {
return ret;
@@ -1440,8 +1440,8 @@ static int xmldoc_parse_specialtags(struct ast_xml_node *fixnode, const char *ta
/* parse <para> elements inside special tags. */
for (node = ast_xml_node_get_children(node); node; node = ast_xml_node_get_next(node)) {
/* first <para> just print it without tabs at the begining. */
- if ((xmldoc_parse_para(node, (!count ? "" : tabs), posttabs, buffer) == 2)
- || (xmldoc_parse_info(node, (!count ? "": tabs), posttabs, buffer) == 2)) {
+ if ((xmldoc_parse_para(node, "", posttabs, buffer) == 2)
+ || (xmldoc_parse_info(node, "", posttabs, buffer) == 2)) {
ret = 2;
}
}
diff --git a/res/ari/config.c b/res/ari/config.c
index 2d3a80d0b..275f41d96 100644
--- a/res/ari/config.c
+++ b/res/ari/config.c
@@ -39,8 +39,8 @@ static struct aco_type general_option = {
.type = ACO_GLOBAL,
.name = "general",
.item_offset = offsetof(struct ast_ari_conf, general),
- .category = "^general$",
- .category_match = ACO_WHITELIST,
+ .category = "general",
+ .category_match = ACO_WHITELIST_EXACT,
};
static struct aco_type *general_options[] = ACO_TYPES(&general_option);
@@ -156,8 +156,8 @@ static void *user_find(struct ao2_container *tmp_container, const char *cat)
static struct aco_type user_option = {
.type = ACO_ITEM,
.name = "user",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.matchfield = "type",
.matchvalue = "user",
.item_alloc = user_alloc,
diff --git a/res/res_config_ldap.c b/res/res_config_ldap.c
index a21aa31a8..c03b84967 100644
--- a/res/res_config_ldap.c
+++ b/res/res_config_ldap.c
@@ -311,8 +311,10 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
BerElement *ber = NULL;
struct ast_variable *var = NULL;
struct ast_variable *prev = NULL;
+#if 0
int is_delimited = 0;
int i = 0;
+#endif
char *ldap_attribute_name;
struct berval *value;
int pos = 0;
@@ -340,6 +342,7 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
ast_debug(2, "md5: %s\n", valptr);
}
if (valptr) {
+#if 0
/* ok, so looping through all delimited values except the last one (not, last character is not delimited...) */
if (is_delimited) {
i = 0;
@@ -360,6 +363,7 @@ static struct ast_variable *realtime_ldap_entry_to_var(struct ldap_table_config
i++;
}
}
+#endif
/* for the last delimited value or if the value is not delimited: */
if (prev) {
prev->next = ast_variable_new(attribute_name, &valptr[pos], table_config->table_name);
diff --git a/res/res_hep.c b/res/res_hep.c
index 3b953b7c1..a91b7ec77 100644
--- a/res/res_hep.c
+++ b/res/res_hep.c
@@ -260,8 +260,8 @@ static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "general",
.item_offset = offsetof(struct module_config, general),
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
struct aco_type *global_options[] = ACO_TYPES(&global_option);
diff --git a/res/res_parking.c b/res/res_parking.c
index 593134b60..ddf801245 100644
--- a/res/res_parking.c
+++ b/res/res_parking.c
@@ -291,8 +291,8 @@ static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "globals",
.item_offset = offsetof(struct parking_config, global),
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
struct aco_type *global_options[] = ACO_TYPES(&global_option);
@@ -300,8 +300,8 @@ struct aco_type *global_options[] = ACO_TYPES(&global_option);
static struct aco_type parking_lot_type = {
.type = ACO_ITEM,
.name = "parking_lot",
- .category_match = ACO_BLACKLIST,
- .category = "^(general)$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.item_alloc = parking_lot_cfg_alloc,
.item_find = named_item_find,
.item_offset = offsetof(struct parking_config, parking_lots),
diff --git a/res/res_pjsip_notify.c b/res/res_pjsip_notify.c
index 8258b3857..fdc7ecf54 100644
--- a/res/res_pjsip_notify.c
+++ b/res/res_pjsip_notify.c
@@ -82,7 +82,7 @@
order; any other header is treated as part of the SIP
request.</para>
</description>
- <configOption name="^.*$">
+ <configOption name="">
<synopsis>A key/value pair to add to a NOTIFY request.</synopsis>
<description>
<para>If the key is <literal>Content</literal>,
@@ -234,8 +234,8 @@ static void *notify_cfg_alloc(void)
static struct aco_type notify_option = {
.type = ACO_ITEM,
.name = "notify",
- .category_match = ACO_BLACKLIST,
- .category = "^general$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.item_offset = offsetof(struct notify_cfg, notify_options),
.item_alloc = notify_option_alloc,
.item_find = notify_option_find
@@ -993,7 +993,7 @@ static int load_module(void)
return AST_MODULE_LOAD_DECLINE;
}
- aco_option_register_custom(&notify_cfg, "^.*$", ACO_REGEX, notify_options,
+ aco_option_register_custom(&notify_cfg, "", ACO_PREFIX, notify_options,
"", notify_option_handler, 0);
if (aco_process_config(&notify_cfg, 0)) {
diff --git a/res/res_rtp_asterisk.c b/res/res_rtp_asterisk.c
index 230d147be..263dbff18 100644
--- a/res/res_rtp_asterisk.c
+++ b/res/res_rtp_asterisk.c
@@ -3247,7 +3247,9 @@ static int ast_rtp_destroy(struct ast_rtp_instance *instance)
* entry at this point since it holds a reference to the
* RTP instance while it's active.
*/
- close(rtp->rtcp->s);
+ if (rtp->rtcp->s > -1 && rtp->s != rtp->rtcp->s) {
+ close(rtp->rtcp->s);
+ }
ast_free(rtp->rtcp->local_addr_str);
ast_free(rtp->rtcp);
}
diff --git a/res/res_statsd.c b/res/res_statsd.c
index b8e4d0475..67166e820 100644
--- a/res/res_statsd.c
+++ b/res/res_statsd.c
@@ -233,8 +233,8 @@ static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "global",
.item_offset = offsetof(struct conf, global),
- .category = "^general$",
- .category_match = ACO_WHITELIST
+ .category = "general",
+ .category_match = ACO_WHITELIST_EXACT,
};
static struct aco_type *global_options[] = ACO_TYPES(&global_option);
diff --git a/res/res_xmpp.c b/res/res_xmpp.c
index 1b0ae427b..41f89961c 100644
--- a/res/res_xmpp.c
+++ b/res/res_xmpp.c
@@ -822,8 +822,8 @@ static struct aco_type global_option = {
.type = ACO_GLOBAL,
.name = "global",
.item_offset = offsetof(struct xmpp_config, global),
- .category_match = ACO_WHITELIST,
- .category = "^general$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "general",
};
struct aco_type *global_options[] = ACO_TYPES(&global_option);
@@ -831,8 +831,8 @@ struct aco_type *global_options[] = ACO_TYPES(&global_option);
static struct aco_type client_option = {
.type = ACO_ITEM,
.name = "client",
- .category_match = ACO_BLACKLIST,
- .category = "^(general)$",
+ .category_match = ACO_BLACKLIST_EXACT,
+ .category = "general",
.item_alloc = ast_xmpp_client_config_alloc,
.item_find = xmpp_config_find,
.item_prelink = xmpp_config_prelink,
diff --git a/tests/test_config.c b/tests/test_config.c
index c58bdc70d..a2ff328ff 100644
--- a/tests/test_config.c
+++ b/tests/test_config.c
@@ -1458,13 +1458,19 @@ static struct aco_type global = {
static struct aco_type global_defaults = {
.type = ACO_GLOBAL,
.item_offset = offsetof(struct test_config, global_defaults),
- .category_match = ACO_WHITELIST,
- .category = "^global_defaults$",
+ .category_match = ACO_WHITELIST_EXACT,
+ .category = "global_defaults",
+};
+static const char *item_blacklist[] = {
+ "global",
+ "global_defaults",
+ NULL,
};
+
static struct aco_type item = {
.type = ACO_ITEM,
- .category_match = ACO_BLACKLIST,
- .category = "^(global|global_defaults)$",
+ .category_match = ACO_BLACKLIST_ARRAY,
+ .category = (const char *)item_blacklist,
.item_alloc = test_item_alloc,
.item_find = test_item_find,
.item_offset = offsetof(struct test_config, items),