aboutsummaryrefslogtreecommitdiffstats
path: root/channels
diff options
context:
space:
mode:
authortilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-07 22:59:52 +0000
committertilghman <tilghman@f38db490-d61c-443f-a65b-d21fe96a405b>2010-06-07 22:59:52 +0000
commit0b80de85480b212cd3507f56cdcb5fb5d78a53f7 (patch)
tree5456d71d2851774657ef7623ab02a9ad3e1b1d14 /channels
parent24cb874b7a79658df674e04b210fbe5cba01a60f (diff)
Merged revisions 268817 via svnmerge from
https://origsvn.digium.com/svn/asterisk/trunk ........ r268817 | tilghman | 2010-06-07 17:47:13 -0500 (Mon, 07 Jun 2010) | 9 lines Mailbox list would previously grow at each reload, containing duplicates. Also, optimize the allocation of mailboxes to avoid additional memory structures. (closes issue #16320) Reported by: Marquis Patches: 20100525__issue16320.diff.txt uploaded by tilghman (license 14) ........ git-svn-id: http://svn.digium.com/svn/asterisk/branches/1.6.2@268819 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'channels')
-rw-r--r--channels/chan_sip.c42
1 files changed, 38 insertions, 4 deletions
diff --git a/channels/chan_sip.c b/channels/chan_sip.c
index fd0e47dbb..eafeca652 100644
--- a/channels/chan_sip.c
+++ b/channels/chan_sip.c
@@ -1808,6 +1808,7 @@ struct sip_pkt {
struct sip_mailbox {
char *mailbox;
char *context;
+ unsigned int delme:1;
/*! Associated MWI subscription */
struct ast_event_sub *event_sub;
AST_LIST_ENTRY(sip_mailbox) entry;
@@ -23788,15 +23789,30 @@ static void add_peer_mailboxes(struct sip_peer *peer, const char *value)
while ((mbox = context = strsep(&next, ","))) {
struct sip_mailbox *mailbox;
-
- if (!(mailbox = ast_calloc(1, sizeof(*mailbox))))
- continue;
+ int duplicate = 0;
strsep(&context, "@");
+
if (ast_strlen_zero(mbox)) {
- ast_free(mailbox);
continue;
}
+
+ /* Check whether the mailbox is already in the list */
+ AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
+ if (!strcmp(mailbox->mailbox, mbox) && !strcmp(S_OR(mailbox->context, ""), S_OR(context, ""))) {
+ duplicate = 1;
+ mailbox->delme = 1;
+ break;
+ }
+ }
+ if (duplicate) {
+ continue;
+ }
+
+ if (!(mailbox = ast_calloc(1, sizeof(*mailbox)))) {
+ continue;
+ }
+
mailbox->mailbox = ast_strdup(mbox);
mailbox->context = ast_strdup(context);
@@ -23881,6 +23897,13 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
peer->default_outbound_transport = 0;
peer->transports = 0;
+ if (!devstate_only) {
+ struct sip_mailbox *mailbox;
+ AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) {
+ mailbox->delme = 1;
+ }
+ }
+
for (; v || ((v = alt) && !(alt=NULL)); v = v->next) {
if (!devstate_only) {
if (handle_common_options(&peerflags[0], &mask[0], v)) {
@@ -24230,6 +24253,17 @@ static struct sip_peer *build_peer(const char *name, struct ast_variable *v, str
}
}
+ if (!devstate_only) {
+ struct sip_mailbox *mailbox;
+ AST_LIST_TRAVERSE_SAFE_BEGIN(&peer->mailboxes, mailbox, entry) {
+ if (mailbox->delme) {
+ AST_LIST_REMOVE_CURRENT(entry);
+ destroy_mailbox(mailbox);
+ }
+ }
+ AST_LIST_TRAVERSE_SAFE_END;
+ }
+
if (!peer->default_outbound_transport) {
/* Set default set of transports */
peer->transports = default_transports;