[asterisk-commits] trunk r9013 - /trunk/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Tue Jan 31 11:40:09 MST 2006
Author: oej
Date: Tue Jan 31 12:40:07 2006
New Revision: 9013
URL: http://svn.digium.com/view/asterisk?rev=9013&view=rev
Log:
Optimize settings of defaults for a new peer object and make sure
we set the same defaults for autocreated peers and other peers.
Modified:
trunk/channels/chan_sip.c
Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=9013&r1=9012&r2=9013&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Tue Jan 31 12:40:07 2006
@@ -967,6 +967,9 @@
static int sip_poke_peer(struct sip_peer *peer);
static int __sip_do_register(struct sip_registry *r);
static int restart_monitor(void);
+static void set_peer_defaults(struct sip_peer *peer);
+static struct sip_peer *temp_peer(const char *name);
+
/*----- RTP interface functions */
static int sip_set_rtp_peer(struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, int codecs, int nat_active);
@@ -12048,20 +12051,11 @@
return user;
}
-/*! \brief Create temporary peer (used in autocreatepeer mode) */
-static struct sip_peer *temp_peer(const char *name)
-{
- struct sip_peer *peer;
-
- if (!(peer = ast_calloc(1, sizeof(*peer))))
- return NULL;
-
- apeerobjs++;
- ASTOBJ_INIT(peer);
-
+/*! \brief Set peer defaults before configuring specific configurations */
+static void set_peer_defaults(struct sip_peer *peer)
+{
peer->expire = -1;
peer->pokeexpire = -1;
- ast_copy_string(peer->name, name, sizeof(peer->name));
ast_copy_flags(peer, &global_flags, SIP_FLAGS_TO_COPY);
strcpy(peer->context, default_context);
strcpy(peer->subscribecontext, default_subscribecontext);
@@ -12069,76 +12063,12 @@
strcpy(peer->musicclass, default_musicclass);
peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
peer->addr.sin_family = AF_INET;
+ peer->defaddr.sin_family = AF_INET;
peer->capability = global_capability;
peer->rtptimeout = global_rtptimeout;
peer->rtpholdtimeout = global_rtpholdtimeout;
peer->rtpkeepalive = global_rtpkeepalive;
- ast_set_flag((&peer->flags_page2), SIP_PAGE2_SELFDESTRUCT);
- ast_set_flag((&peer->flags_page2), SIP_PAGE2_DYNAMIC);
- peer->prefs = default_prefs;
- reg_source_db(peer);
-
- return peer;
-}
-
-/*! \brief Build peer from configuration (file or realtime static/dynamic) */
-static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime)
-{
- struct sip_peer *peer = NULL;
- struct ast_ha *oldha = NULL;
- int obproxyfound=0;
- int found=0;
- int format=0; /* Ama flags */
- time_t regseconds;
- char *varname = NULL, *varval = NULL;
- struct ast_variable *tmpvar = NULL;
- struct ast_flags peerflags = {(0)};
- struct ast_flags mask = {(0)};
-
-
- if (!realtime)
- /* Note we do NOT use find_peer here, to avoid realtime recursion */
- /* We also use a case-sensitive comparison (unlike find_peer) so
- that case changes made to the peer name will be properly handled
- during reload
- */
- peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp);
-
- if (peer) {
- /* Already in the list, remove it and it will be added back (or FREE'd) */
- found++;
- } else {
- if (!(peer = ast_calloc(1, sizeof(*peer))))
- return NULL;
-
- if (realtime)
- rpeerobjs++;
- else
- speerobjs++;
- ASTOBJ_INIT(peer);
- peer->expire = -1;
- peer->pokeexpire = -1;
- }
- /* Note that our peer HAS had its reference count incrased */
-
- peer->lastmsgssent = -1;
- if (!found) {
- if (name)
- ast_copy_string(peer->name, name, sizeof(peer->name));
- peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
- peer->addr.sin_family = AF_INET;
- peer->defaddr.sin_family = AF_INET;
- }
- /* If we have channel variables, remove them (reload) */
- if (peer->chanvars) {
- ast_variables_destroy(peer->chanvars);
- peer->chanvars = NULL;
- }
- strcpy(peer->context, default_context);
- strcpy(peer->subscribecontext, default_subscribecontext);
strcpy(peer->vmexten, default_vmexten);
- strcpy(peer->language, default_language);
- strcpy(peer->musicclass, default_musicclass);
ast_copy_flags(peer, &global_flags, SIP_USEREQPHONE);
peer->secret[0] = '\0';
peer->md5secret[0] = '\0';
@@ -12150,16 +12080,87 @@
peer->mailbox[0] = '\0';
peer->callgroup = 0;
peer->pickupgroup = 0;
- peer->rtpkeepalive = global_rtpkeepalive;
peer->maxms = default_qualify;
peer->prefs = default_prefs;
+}
+
+/*! \brief Create temporary peer (used in autocreatepeer mode) */
+static struct sip_peer *temp_peer(const char *name)
+{
+ struct sip_peer *peer;
+
+ if (!(peer = ast_calloc(1, sizeof(*peer))))
+ return NULL;
+
+ apeerobjs++;
+ ASTOBJ_INIT(peer);
+ set_peer_defaults(peer);
+
+ ast_copy_string(peer->name, name, sizeof(peer->name));
+
+ ast_set_flag((&peer->flags_page2), SIP_PAGE2_SELFDESTRUCT);
+ ast_set_flag((&peer->flags_page2), SIP_PAGE2_DYNAMIC);
+ peer->prefs = default_prefs;
+ reg_source_db(peer);
+
+ return peer;
+}
+
+/*! \brief Build peer from configuration (file or realtime static/dynamic) */
+static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime)
+{
+ struct sip_peer *peer = NULL;
+ struct ast_ha *oldha = NULL;
+ int obproxyfound=0;
+ int found=0;
+ int format=0; /* Ama flags */
+ time_t regseconds;
+ char *varname = NULL, *varval = NULL;
+ struct ast_variable *tmpvar = NULL;
+ struct ast_flags peerflags = {(0)};
+ struct ast_flags mask = {(0)};
+
+
+ if (!realtime)
+ /* Note we do NOT use find_peer here, to avoid realtime recursion */
+ /* We also use a case-sensitive comparison (unlike find_peer) so
+ that case changes made to the peer name will be properly handled
+ during reload
+ */
+ peer = ASTOBJ_CONTAINER_FIND_UNLINK_FULL(&peerl, name, name, 0, 0, strcmp);
+
+ if (peer) {
+ /* Already in the list, remove it and it will be added back (or FREE'd) */
+ found++;
+ } else {
+ if (!(peer = ast_calloc(1, sizeof(*peer))))
+ return NULL;
+
+ if (realtime)
+ rpeerobjs++;
+ else
+ speerobjs++;
+ ASTOBJ_INIT(peer);
+ peer->expire = -1;
+ peer->pokeexpire = -1;
+ }
+ /* Note that our peer HAS had its reference count incrased */
+
+ peer->lastmsgssent = -1;
oldha = peer->ha;
peer->ha = NULL;
- peer->addr.sin_family = AF_INET;
- ast_copy_flags(peer, &global_flags, SIP_FLAGS_TO_COPY);
- peer->capability = global_capability;
- peer->rtptimeout = global_rtptimeout;
- peer->rtpholdtimeout = global_rtpholdtimeout;
+ set_peer_defaults(peer); /* Set peer defaults */
+ if (!found) {
+ if (name)
+ ast_copy_string(peer->name, name, sizeof(peer->name));
+ peer->addr.sin_port = htons(DEFAULT_SIP_PORT);
+ peer->addr.sin_family = AF_INET;
+ }
+ /* If we have channel variables, remove them (reload) */
+ if (peer->chanvars) {
+ ast_variables_destroy(peer->chanvars);
+ peer->chanvars = NULL;
+ }
while(v) {
if (handle_common_options(&peerflags, &mask, v)) {
v = v->next;
More information about the asterisk-commits
mailing list