[asterisk-commits] oej: branch oej/codename-pineapple r44898 - in
/team/oej/codename-pineapple/c...
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Wed Oct 11 11:05:24 MST 2006
Author: oej
Date: Wed Oct 11 13:05:23 2006
New Revision: 44898
URL: http://svn.digium.com/view/asterisk?rev=44898&view=rev
Log:
Updates. Poking around. Having fun.
Added:
team/oej/codename-pineapple/channels/sip3/sip3_network.c (with props)
team/oej/codename-pineapple/channels/sip3/sip3_refer.c (with props)
team/oej/codename-pineapple/channels/sip3/sip3_subscribe.c (with props)
Modified:
team/oej/codename-pineapple/channels/Makefile
team/oej/codename-pineapple/channels/chan_sip3.c
team/oej/codename-pineapple/channels/sip3/Makefile
team/oej/codename-pineapple/channels/sip3/sip3.h
Modified: team/oej/codename-pineapple/channels/Makefile
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/Makefile?rev=44898&r1=44897&r2=44898&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/Makefile (original)
+++ team/oej/codename-pineapple/channels/Makefile Wed Oct 11 13:05:23 2006
@@ -55,7 +55,7 @@
LOADABLE_MODS:=
endif
-all: _all
+all: _all sip3
include $(ASTTOPDIR)/Makefile.moddir_rules
@@ -114,9 +114,9 @@
$(if $(filter chan_misdn,$(EMBEDDED_MODS)),modules.link,chan_misdn.so): chan_misdn.o misdn_config.o misdn/isdn_lib.o misdn/isdn_msg_parser.o
-sip3/sip3_test.o: sip3/sip3_test.c
+sip3:
$(MAKE) -C sip3
-chan_sip3.so: chan_sip3.o sip3/sip3_test.o
+chan_sip3.so: chan_sip3.o sip3/sip3_network.o sip3/sip3_subscribe.o sip3/sip3_refer.o
$(ECHO_PREFIX) echo " [LD] $^ -> $@"
$(CMD_PREFIX) $(CXX) $(SOLINK) -o $@ $<
Modified: team/oej/codename-pineapple/channels/chan_sip3.c
URL: http://svn.digium.com/view/asterisk/team/oej/codename-pineapple/channels/chan_sip3.c?rev=44898&r1=44897&r2=44898&view=diff
==============================================================================
--- team/oej/codename-pineapple/channels/chan_sip3.c (original)
+++ team/oej/codename-pineapple/channels/chan_sip3.c Wed Oct 11 13:05:23 2006
@@ -127,6 +127,7 @@
- Prove transaction engine by implementing PRACK
- Implement netsock API in this channel
- Add File's multithreading code
+ - Make debugaddr a ha list instead of one address and move it out of sipnet
- ... And much more
*/
@@ -191,10 +192,12 @@
#include "asterisk/abstract_jb.h"
#include "asterisk/compiler.h"
#include "sip3/sip3.h"
+#include "sip3/sip3funcs.h"
#define SIPLABEL sip3
+/*! \brief various expiry times for registrations */
static struct expiry_times expiry = {
.min_expiry = DEFAULT_MIN_EXPIRY, /*!< Minimum accepted registration time */
.max_expiry = DEFAULT_MAX_EXPIRY, /*!< Maximum accepted registration time */
@@ -202,8 +205,6 @@
.expiry = DEFAULT_EXPIRY, /*!< Is this ever used ??? */
};
-#define CALLERID_UNKNOWN "Unknown"
-
/*! \brief Global jitterbuffer configuration - by default, jb is disabled */
static struct ast_jb_conf default_jbconf =
{
@@ -212,158 +213,24 @@
.resync_threshold = -1,
.impl = ""
};
-static struct ast_jb_conf global_jbconf;
static const char config[] = "sip3.conf";
static const char notify_config[] = "sip3_notify.conf";
static int usecnt = 0;
-
-/*! \brief List of subscription event types for SUBSCRIBE requests */
-static const struct cfsubscription_types subscription_types[] = {
- { NONE, "-", "unknown", "unknown" },
- /* RFC 4235: SIP Dialog event package */
- { DIALOG_INFO_XML, "dialog", "application/dialog-info+xml", "dialog-info+xml" },
- { CPIM_PIDF_XML, "presence", "application/cpim-pidf+xml", "cpim-pidf+xml" }, /* RFC 3863 */
- { PIDF_XML, "presence", "application/pidf+xml", "pidf+xml" }, /* RFC 3863 */
- { XPIDF_XML, "presence", "application/xpidf+xml", "xpidf+xml" }, /* Pre-RFC 3863 with MS additions */
- { MWI_NOTIFICATION, "message-summary", "application/simple-message-summary", "mwi" } /* RFC 3842: Mailbox notification */
-};
-
-
-/*! XXX Note that sip_methods[i].id == i must hold or the code breaks */
-static const struct cfsip_methods sip_methods[] = {
- { SIP_UNKNOWN, RTP, "-UNKNOWN-" },
- { SIP_RESPONSE, NO_RTP, "SIP/2.0" },
- { SIP_REGISTER, NO_RTP, "REGISTER" },
- { SIP_OPTIONS, NO_RTP, "OPTIONS" },
- { SIP_NOTIFY, NO_RTP, "NOTIFY" },
- { SIP_INVITE, RTP, "INVITE" },
- { SIP_ACK, NO_RTP, "ACK" },
- { SIP_PRACK, NO_RTP, "PRACK" },
- { SIP_BYE, NO_RTP, "BYE" },
- { SIP_REFER, NO_RTP, "REFER" },
- { SIP_SUBSCRIBE, NO_RTP, "SUBSCRIBE" },
- { SIP_MESSAGE, NO_RTP, "MESSAGE" },
- { SIP_UPDATE, NO_RTP, "UPDATE" },
- { SIP_INFO, NO_RTP, "INFO" },
- { SIP_CANCEL, NO_RTP, "CANCEL" },
- { SIP_PUBLISH, NO_RTP, "PUBLISH" }
-};
-
-/*! \brief List of well-known SIP options. If we get this in a require,
- we should check the list and answer accordingly. */
-static const struct cfsip_options sip_options[] = { /* XXX used in 3 places */
- /* RFC3891: Replaces: header for transfer */
- { SIP_OPT_REPLACES, SUPPORTED, "replaces" },
- /* One version of Polycom firmware has the wrong label */
- { SIP_OPT_REPLACES, SUPPORTED, "replace" },
- /* RFC3262: PRACK 100% reliability */
- { SIP_OPT_100REL, NOT_SUPPORTED, "100rel" },
- /* RFC4028: SIP Session Timers */
- { SIP_OPT_TIMER, NOT_SUPPORTED, "timer" },
- /* RFC3959: SIP Early session support */
- { SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" },
- /* RFC3911: SIP Join header support */
- { SIP_OPT_JOIN, NOT_SUPPORTED, "join" },
- /* RFC3327: Path support */
- { SIP_OPT_PATH, NOT_SUPPORTED, "path" },
- /* RFC3840: Callee preferences */
- { SIP_OPT_PREF, NOT_SUPPORTED, "pref" },
- /* RFC3312: Precondition support */
- { SIP_OPT_PRECONDITION, NOT_SUPPORTED, "precondition" },
- /* RFC3323: Privacy with proxies*/
- { SIP_OPT_PRIVACY, NOT_SUPPORTED, "privacy" },
- /* RFC4092: Usage of the SDP ANAT Semantics in the SIP */
- { SIP_OPT_SDP_ANAT, NOT_SUPPORTED, "sdp-anat" },
- /* RFC3329: Security agreement mechanism */
- { SIP_OPT_SEC_AGREE, NOT_SUPPORTED, "sec_agree" },
- /* SIMPLE events: draft-ietf-simple-event-list-07.txt */
- { SIP_OPT_EVENTLIST, NOT_SUPPORTED, "eventlist" },
- /* GRUU: Globally Routable User Agent URI's */
- { SIP_OPT_GRUU, NOT_SUPPORTED, "gruu" },
- /* Target-dialog: draft-ietf-sip-target-dialog-03.txt */
- { SIP_OPT_TARGET_DIALOG,NOT_SUPPORTED, "tdialog" },
- /* Disable the REFER subscription, RFC 4488 */
- { SIP_OPT_NOREFERSUB, NOT_SUPPORTED, "norefersub" },
- /* ietf-sip-history-info-06.txt */
- { SIP_OPT_HISTINFO, NOT_SUPPORTED, "histinfo" },
- /* ietf-sip-resource-priority-10.txt */
- { SIP_OPT_RESPRIORITY, NOT_SUPPORTED, "resource-priority" },
-};
-
-
/* Default setttings are used as a channel setting and as a default when
configuring devices */
-static int default_qualifycheck_ok; /*!< Default qualify time when status is ok */
-static int default_qualifycheck_notok; /*!< Default qualify time when statusis not ok */
-static int default_qualify; /*!< Default Qualify= setting */
-static char default_context[AST_MAX_CONTEXT];
-static char default_subscribecontext[AST_MAX_CONTEXT];
-static char default_language[MAX_LANGUAGE];
-static char default_callerid[AST_MAX_EXTENSION];
-static char default_fromdomain[AST_MAX_EXTENSION];
-static char default_notifymime[AST_MAX_EXTENSION];
-static char default_vmexten[AST_MAX_EXTENSION];
-static char default_mohinterpret[MAX_MUSICCLASS]; /*!< Global setting for moh class to use when put on hold */
-static char default_mohsuggest[MAX_MUSICCLASS]; /*!< Global setting for moh class to suggest when putting
- * a bridged channel on hold */
-static int default_maxcallbitrate; /*!< Maximum bitrate for call */
-static struct ast_codec_pref default_prefs; /*!< Default codec prefs */
-
/* Global settings only apply to the channel */
-static int global_rtautoclear;
-static int global_notifyringing; /*!< Send notifications on ringing */
-static int global_alwaysauthreject; /*!< Send 401 Unauthorized for all failing requests */
-static int srvlookup; /*!< SRV Lookup on or off. Default is off, RFC behavior is on */
-static int autocreatepeer; /*!< Auto creation of peers at registration? Default off. */
-static int global_relaxdtmf; /*!< Relax DTMF */
-static int global_rtptimeout; /*!< Time out call if no RTP */
-static int global_rtpholdtimeout;
-static int global_rtpkeepalive; /*!< Send RTP keepalives */
-static int global_reg_timeout;
-static int global_regattempts_max; /*!< Registration attempts before giving up */
-static int global_allowguest; /*!< allow unauthenticated users/peers to connect? */
-static int global_allowsubscribe; /*!< Flag for disabling ALL subscriptions, this is FALSE only if all peers are FALSE
- the global setting is in globals_flags[1] */
-static int global_mwitime; /*!< Time between MWI checks for peers */
-static unsigned int global_tos_sip; /*!< IP type of service for SIP packets */
-static unsigned int global_tos_audio; /*!< IP type of service for audio RTP packets */
-static unsigned int global_tos_video; /*!< IP type of service for video RTP packets */
-static unsigned int global_tos_presence; /*!< IP type of service for SIP presence packets */
-static int compactheaders; /*!< send compact sip headers */
-static int recordhistory; /*!< Record SIP history. Off by default */
-static int dumphistory; /*!< Dump history to verbose before destroying SIP dialog */
-static char global_realm[MAXHOSTNAMELEN]; /*!< Default realm */
-static char global_regcontext[AST_MAX_CONTEXT]; /*!< Context for auto-extensions */
-static char global_useragent[AST_MAX_EXTENSION]; /*!< Useragent for the SIP channel */
-static int allow_external_domains; /*!< Accept calls to external SIP domains? */
-static int global_callevents; /*!< Whether we send manager events or not */
-static int global_t1min; /*!< T1 roundtrip time minimum */
-static enum transfermodes global_allowtransfer; /*!< SIP Refer restriction scheme */
-static int global_autoframing = 0;
-
-/*! \brief Codecs that we support by default: */
-static int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263;
-static int noncodeccapability = AST_RTP_DTMF;
+static struct sip_globals global;
/* Object counters */
-static int suserobjs = 0; /*!< Static users */
-static int ruserobjs = 0; /*!< Realtime users */
-static int speerobjs = 0; /*!< Statis peers */
-static int rpeerobjs = 0; /*!< Realtime peers */
-static int apeerobjs = 0; /*!< Autocreated peer objects */
-static int regobjs = 0; /*!< Registry objects */
-
-static struct ast_flags global_flags[2] = {{0}}; /*!< global SIP_ flags */
-
+static struct channel_counters sipcounters = { 0, 0, 0, 0, 0, 0 };
/*! \brief Protect the SIP dialog list (of sip_pvt's) */
AST_MUTEX_DEFINE_STATIC(iflock);
/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
when it's doing something critical. */
-AST_MUTEX_DEFINE_STATIC(netlock);
AST_MUTEX_DEFINE_STATIC(monlock);
@@ -378,36 +245,22 @@
static struct sched_context *sched; /*!< The scheduling context */
static struct io_context *io; /*!< The IO context */
-static int *sipsock_read_id; /*!< ID of IO entry for sipsock FD */
static AST_LIST_HEAD_STATIC(domain_list, domain); /*!< The SIP domain list */
AST_LIST_HEAD_NOLOCK(sip_history_head, sip_history); /*!< history list, entry in sip_pvt */
-/*!< This is default: NO MMR and JBIG trancoding, NO fill bit removal, transferredTCF TCF, UDP FEC, Version 0 and 9600 max fax rate */
-static int global_t38_capability = T38FAX_VERSION_0 | T38FAX_RATE_2400 | T38FAX_RATE_4800 | T38FAX_RATE_7200 | T38FAX_RATE_9600;
-
-static const struct c_referstatusstring {
- enum referstatus status;
- char *text;
-} referstatusstrings[] = {
- { REFER_IDLE, "<none>" },
- { REFER_SENT, "Request sent" },
- { REFER_RECEIVED, "Request received" },
- { REFER_ACCEPTED, "Accepted" },
- { REFER_RINGING, "Target ringing" },
- { REFER_200OK, "Done" },
- { REFER_FAILED, "Failed" },
- { REFER_NOAUTH, "Failed - auth failure" }
-} ;
/* --- Linked lists of various objects --------*/
-/*! \brief The user list: Users and friends */
+/*! \brief List of concurrent SIP dialogs */
+static struct sip_pvt *iflist = NULL;
+
+/*! \brief The user list: Users and friends */
static struct ast_user_list {
ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
} userl;
-/*! \brief The peer list: Peers and Friends */
+/*! \brief The peer list: Peers and Friends */
static struct ast_peer_list {
ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
} peerl;
@@ -421,18 +274,8 @@
/*! \todo Move the sip_auth list to AST_LIST */
static struct sip_auth *authl = NULL; /*!< Authentication list for realm authentication */
-/* --- Sockets and networking --------------*/
-static int sipsock = -1; /*!< Main socket for SIP network communication */
-static struct sockaddr_in bindaddr = { 0, }; /*!< The address we bind to */
-static struct sockaddr_in externip; /*!< External IP address if we are behind NAT */
-static char externhost[MAXHOSTNAMELEN]; /*!< External host name (possibly with dynamic DNS and DHCP */
-static time_t externexpire = 0; /*!< Expiration counter for re-resolving external host name in dynamic DNS */
-static int externrefresh = 10;
-static struct ast_ha *localaddr; /*!< List of local networks, on the same side of NAT as this Asterisk */
-static struct in_addr __ourip;
-static struct sockaddr_in outboundproxyip;
-static int ourport;
-static struct sockaddr_in debugaddr;
+/* This structure needs to be encapsulated */
+extern struct sip_network sipnet; /*!< Sockets and networking */
static struct ast_config *notify_types; /*!< The list of manual NOTIFY types we know how to send */
@@ -440,7 +283,7 @@
/*! \note This is added to help splitting up chan_sip.c into several files
in coming releases */
-/*--- PBX interface functions */
+/*--- PBX interface functions - stays in this source code file */
static struct ast_channel *sip_request_call(const char *type, int format, void *data, int *cause);
static int sip_devicestate(void *data);
static int sip_sendtext(struct ast_channel *ast, const char *text);
@@ -456,7 +299,6 @@
static int sip_senddigit_end(struct ast_channel *ast, char digit);
/*--- Transmitting responses and requests */
-static int sipsock_read(int *id, int fd, short events, void *ignore);
static int __sip_xmit(struct sip_pvt *p, char *data, int len);
static int __sip_reliable_xmit(struct sip_pvt *p, int seqno, int resp, char *data, int len, int fatal, int sipmethod);
static int __transmit_response(struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable);
@@ -605,8 +447,6 @@
static int sip_show_user(int fd, int argc, char *argv[]);
static int sip_show_registry(int fd, int argc, char *argv[]);
static int sip_show_settings(int fd, int argc, char *argv[]);
-static const char *subscription_type2str(enum subscriptiontype subtype) attribute_pure;
-static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions);
static int sip_show_channels(int fd, int argc, char *argv[]);
static int sip_show_subscriptions(int fd, int argc, char *argv[]);
@@ -689,14 +529,9 @@
/*--- Parsing SIP requests and responses */
static void append_date(struct sip_request *req); /* Append date to SIP packet */
static int determine_firstline_parts(struct sip_request *req);
-static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
static const char *gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize);
-static int find_sip_method(const char *msg);
-static unsigned int parse_sip_options(struct sip_pvt *pvt, const char *supported);
static void parse_request(struct sip_request *req);
static const char *get_header(const struct sip_request *req, const char *name);
-static char *referstatus2str(enum referstatus rstatus) attribute_pure;
-static int method_match(enum sipmethod id, const char *name);
static void parse_copy(struct sip_request *dst, const struct sip_request *src);
static char *get_in_brackets(char *tmp);
static const char *find_alias(const char *name, const char *_default);
@@ -784,6 +619,7 @@
static struct ast_udptl *sip_get_udptl_peer(struct ast_channel *chan);
static int sip_set_udptl_peer(struct ast_channel *chan, struct ast_udptl *udptl);
+
/*! \brief Definition of this channel for PBX channel registration */
static const struct ast_channel_tech sip_tech = {
.type = "SIP",
@@ -824,19 +660,6 @@
set_udptl_peer: sip_set_udptl_peer,
};
-/*! \brief Convert transfer status to string */
-static char *referstatus2str(enum referstatus rstatus)
-{
- int i = (sizeof(referstatusstrings) / sizeof(referstatusstrings[0]));
- int x;
-
- for (x = 0; x < i; x++) {
- if (referstatusstrings[x].status == rstatus)
- return (char *) referstatusstrings[x].text;
- }
- return "";
-}
-
/*! \brief Initialize the initital request packet in the pvt structure.
This packet is used for creating replies and future requests in
a dialog */
@@ -852,88 +675,15 @@
ast_verbose("%d headers, %d lines\n", p->initreq.headers, p->initreq.lines);
}
-
-/*! \brief returns true if 'name' (with optional trailing whitespace)
- * matches the sip method 'id'.
- * Strictly speaking, SIP methods are case SENSITIVE, but we do
- * a case-insensitive comparison to be more tolerant.
- * following Jon Postel's rule: Be gentle in what you accept, strict with what you send
- */
-static int method_match(enum sipmethod id, const char *name)
-{
- int len = strlen(sip_methods[id].text);
- int l_name = name ? strlen(name) : 0;
- /* true if the string is long enough, and ends with whitespace, and matches */
- return (l_name >= len && name[len] < 33 &&
- !strncasecmp(sip_methods[id].text, name, len));
-}
-
-/*! \brief find_sip_method: Find SIP method from header */
-static int find_sip_method(const char *msg)
-{
- int i, res = 0;
-
- if (ast_strlen_zero(msg))
- return 0;
- for (i = 1; i < (sizeof(sip_methods) / sizeof(sip_methods[0])) && !res; i++) {
- if (method_match(i, msg))
- res = sip_methods[i].id;
- }
- return res;
-}
-
-/*! \brief Parse supported header in incoming packet */
-static unsigned int parse_sip_options(struct sip_pvt *pvt, const char *supported)
-{
- char *next, *sep;
- char *temp = ast_strdupa(supported);
- unsigned int profile = 0;
- int i, found;
-
- if (ast_strlen_zero(supported) )
- return 0;
-
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported);
-
- for (next = temp; next; next = sep) {
- found = FALSE;
- if ( (sep = strchr(next, ',')) != NULL)
- *sep++ = '\0';
- next = ast_skip_blanks(next);
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next);
- for (i=0; i < (sizeof(sip_options) / sizeof(sip_options[0])); i++) {
- if (!strcasecmp(next, sip_options[i].text)) {
- profile |= sip_options[i].id;
- found = TRUE;
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next);
- break;
- }
- }
- if (!found && option_debug > 2 && sipdebug) {
- if (!strncasecmp(next, "x-", 2))
- ast_log(LOG_DEBUG, "Found private SIP option, not supported: %s\n", next);
- else
- ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
- }
- }
-
- if (pvt)
- pvt->sipoptions = profile;
- return profile;
-}
-
/*! \brief See if we pass debug IP filter */
static inline int sip_debug_test_addr(const struct sockaddr_in *addr)
{
if (!sipdebug)
return 0;
- if (debugaddr.sin_addr.s_addr) {
- if (((ntohs(debugaddr.sin_port) != 0)
- && (debugaddr.sin_port != addr->sin_port))
- || (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
+ if (sipnet.debugaddr.sin_addr.s_addr) {
+ if (((ntohs(sipnet.debugaddr.sin_port) != 0)
+ && (sipnet.debugaddr.sin_port != addr->sin_port))
+ || (sipnet.debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr))
return 0;
}
return 1;
@@ -964,7 +714,7 @@
{
int res;
const struct sockaddr_in *dst = sip_real_dst(p);
- res=sendto(sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
+ res=sendto(sipnet.sipsock, data, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in));
if (res != len)
ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno));
@@ -980,7 +730,7 @@
/* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */
ast_string_field_build(p, via, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x%s",
- ast_inet_ntoa(p->ourip), ourport, p->branch, rport);
+ ast_inet_ntoa(p->ourip), sipnet_ourport(), p->branch, rport);
}
/*! \brief NAT fix - decide which IP address to use for ASterisk server?
@@ -998,32 +748,28 @@
theirs.sin_addr = *them;
ours.sin_addr = *us;
- if (localaddr && externip.sin_addr.s_addr &&
- ast_apply_ha(localaddr, &theirs) &&
- !ast_apply_ha(localaddr, &ours)) {
- if (externexpire && time(NULL) >= externexpire) {
+ if (sipnet.localaddr && sipnet.externip.sin_addr.s_addr &&
+ ast_apply_ha(sipnet.localaddr, &theirs) &&
+ !ast_apply_ha(sipnet.localaddr, &ours)) {
+ if (sipnet.externexpire && time(NULL) >= sipnet.externexpire) {
struct ast_hostent ahp;
struct hostent *hp;
- externexpire = time(NULL) + externrefresh;
- if ((hp = ast_gethostbyname(externhost, &ahp))) {
- memcpy(&externip.sin_addr, hp->h_addr, sizeof(externip.sin_addr));
+ sipnet.externexpire = time(NULL) + sipnet.externrefresh;
+ if ((hp = ast_gethostbyname(sipnet.externhost, &ahp))) {
+ memcpy(&sipnet.externip.sin_addr, hp->h_addr, sizeof(sipnet.externip.sin_addr));
} else
- ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost);
- }
- *us = externip.sin_addr;
+ ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", sipnet.externhost);
+ }
+ *us = sipnet.externip.sin_addr;
if (option_debug) {
ast_log(LOG_DEBUG, "Target address %s is not local, substituting externip\n",
ast_inet_ntoa(*(struct in_addr *)&them->s_addr));
}
- } else if (bindaddr.sin_addr.s_addr)
- *us = bindaddr.sin_addr;
+ } else if (sipnet.bindaddr.sin_addr.s_addr)
+ *us = sipnet.bindaddr.sin_addr;
return AST_SUCCESS;
}
-
-/*! \brief Append to SIP dialog history
- \return Always returns 0 */
-#define append_history(p, event, fmt , args... ) append_history_full(p, "%-15s " fmt, event, ## args)
static void append_history_full(struct sip_pvt *p, const char *fmt, ...)
__attribute__ ((format (printf, 2, 3)));
@@ -1053,7 +799,7 @@
{
va_list ap;
- if (!recordhistory || !p)
+ if (!global.recordhistory || !p)
return;
va_start(ap, fmt);
append_history_va(p, fmt, ap);
@@ -1075,12 +821,12 @@
pkt->retrans++;
if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */
if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method);
+ ast_log(LOG_DEBUG, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_method2txt(pkt->method), pkt->method);
} else {
int siptimer_a;
if (sipdebug && option_debug > 3)
- ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method);
+ ast_log(LOG_DEBUG, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_method2txt(pkt->method), pkt->method);
if (!pkt->timer_a)
pkt->timer_a = 2 ;
else
@@ -1220,7 +966,7 @@
ast_log(LOG_DEBUG, "Auto destroying SIP dialog '%s'\n", p->callid);
append_history(p, "AutoDestroy", "%s", p->callid);
if (p->owner) {
- ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text);
+ ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_method2txt(p->method));
ast_queue_hangup(p->owner);
} else if (p->refer) {
transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
@@ -1239,8 +985,8 @@
ms = p->timer_t1 * 64;
}
if (sip_debug_test_pvt(p))
- ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text);
- if (recordhistory)
+ ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_method2txt(p->method));
+ if (global.recordhistory)
append_history(p, "SchedDestroy", "%d ms", ms);
if (p->autokillid > -1)
@@ -1267,7 +1013,7 @@
char *msg;
int res = FALSE;
- msg = sip_methods[sipmethod].text;
+ msg = sip_method2txt(sipmethod);
ast_mutex_lock(&p->lock);
for (cur = p->packets; cur; prev = cur, cur = cur->next) {
@@ -1306,7 +1052,7 @@
while (p->packets) {
int method;
if (cur == p->packets) {
- ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text);
+ ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_method2txt(cur->method));
return;
}
cur = p->packets;
@@ -1327,7 +1073,7 @@
/* this is our baby */
if (cur->retransid > -1) {
if (option_debug > 3 && sipdebug)
- ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
+ ast_log(LOG_DEBUG, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_method2txt(sipmethod));
ast_sched_del(sched, cur->retransid);
}
cur->retransid = -1;
@@ -1374,11 +1120,11 @@
ast_inet_ntoa(dst->sin_addr),
ntohs(dst->sin_port), req->data);
}
- if (recordhistory) {
+ if (global.recordhistory) {
struct sip_request tmp;
parse_copy(&tmp, req);
append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"),
- (tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? tmp.rlPart2 : sip_methods[tmp.method].text);
+ (tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? tmp.rlPart2 : sip_method2txt(tmp.method));
}
res = (reliable) ?
__sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) :
@@ -1400,10 +1146,10 @@
else
ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data);
}
- if (recordhistory) {
+ if (global.recordhistory) {
struct sip_request tmp;
parse_copy(&tmp, req);
- append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text);
+ append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data, get_header(&tmp, "CSeq"), sip_method2txt(tmp.method));
}
res = (reliable) ?
__sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable > 1), req->method) :
@@ -1496,7 +1242,7 @@
if (ast_strlen_zero(sysname)) /* No system name, disable this */
sysname = NULL;
- else if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTSAVE_SYSNAME))
+ else if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTSAVE_SYSNAME))
syslabel = "regserver";
if (fc)
@@ -1515,11 +1261,11 @@
char multi[256];
char *stringp, *ext, *context;
- /* XXX note that global_regcontext is both a global 'enable' flag and
+ /* XXX note that global.regcontext is both a global 'enable' flag and
* the name of the global regexten context, if not specified
* individually.
*/
- if (ast_strlen_zero(global_regcontext))
+ if (ast_strlen_zero(global.regcontext))
return;
ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
@@ -1532,7 +1278,7 @@
continue;
}
} else {
- context = global_regcontext;
+ context = global.regcontext;
}
if (onoff)
ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop",
@@ -1570,17 +1316,17 @@
clear_realm_authentication(device->auth);
device->auth = (struct sip_auth *) NULL;
if (ast_test_flag((&device->flags[1]), SIP_PAGE2_SELFDESTRUCT))
- apeerobjs--;
+ sipcounters.autocreated_peers--;
else if (ast_test_flag(&device->flags[0], SIP_REALTIME))
- rpeerobjs--;
+ sipcounters.realtime_peers--;
else
- speerobjs--;
+ sipcounters.static_peers--;
}
if (device->type & SIP_USER) { /* SIP_USER */
if (ast_test_flag(&device->flags[0], SIP_REALTIME))
- ruserobjs--;
+ sipcounters.realtime_users--;
else
- suserobjs--;
+ sipcounters.static_users--;
}
if (device->dnsmgr)
ast_dnsmgr_release(device->dnsmgr);
@@ -1591,7 +1337,7 @@
static void update_peer(struct sip_peer *p, int expiry)
{
int rtcachefriends = ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
- if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTUPDATE) &&
+ if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTUPDATE) &&
(ast_test_flag(&p->flags[0], SIP_REALTIME) || rtcachefriends)) {
realtime_update_peer(p->name, &p->addr, p->username, rtcachefriends ? p->fullcontact : NULL, expiry);
}
@@ -1641,20 +1387,20 @@
}
/* Peer found in realtime, now build it in memory */
- peer = build_peer(newpeername, var, NULL, !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS));
+ peer = build_peer(newpeername, var, NULL, !ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS));
if (!peer) {
ast_variables_destroy(var);
return NULL;
}
- if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
+ if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
/* Cache peer */
- ast_copy_flags(&peer->flags[1],&global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
- if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
+ ast_copy_flags(&peer->flags[1],&global.flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS);
+ if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTAUTOCLEAR)) {
if (peer->expire > -1) {
ast_sched_del(sched, peer->expire);
}
- peer->expire = ast_sched_add(sched, (global_rtautoclear) * 1000, expire_register, (void *)peer);
+ peer->expire = ast_sched_add(sched, (global.rtautoclear) * 1000, expire_register, (void *)peer);
}
ASTOBJ_CONTAINER_LINK(&peerl,peer);
} else {
@@ -1715,20 +1461,20 @@
}
}
- user = build_user(username, var, !ast_test_flag((&global_flags[1]), SIP_PAGE2_RTCACHEFRIENDS));
+ user = build_user(username, var, !ast_test_flag((&global.flags[1]), SIP_PAGE2_RTCACHEFRIENDS));
if (!user) { /* No user found */
ast_variables_destroy(var);
return NULL;
}
- if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
+ if (ast_test_flag(&global.flags[1], SIP_PAGE2_RTCACHEFRIENDS)) {
ast_set_flag(&user->flags[1], SIP_PAGE2_RTCACHEFRIENDS);
- suserobjs++;
+ sipcounters.static_users++;
ASTOBJ_CONTAINER_LINK(&userl,user);
} else {
/* Move counter from s to r... */
- suserobjs--;
- ruserobjs++;
+ sipcounters.static_users--;
+ sipcounters.realtime_users++;
ast_set_flag(&user->flags[0], SIP_REALTIME);
}
ast_variables_destroy(var);
@@ -1770,7 +1516,7 @@
}
dialog->prefs = peer->prefs;
if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) {
- dialog->t38.capability = global_t38_capability;
+ dialog->t38.capability = global.t38_capability;
if (dialog->udptl) {
if (ast_udptl_get_error_correction_scheme(dialog->udptl) == UDPTL_ERROR_CORRECTION_FEC )
dialog->t38.capability |= T38FAX_UDP_EC_FEC;
@@ -1842,7 +1588,7 @@
/* Set timer T1 to RTT for this peer (if known by qualify=) */
/* Minimum is settable or default to 100 ms */
if (peer->maxms && peer->lastms)
- dialog->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms;
+ dialog->timer_t1 = peer->lastms < global.t1min ? global.t1min : peer->lastms;
if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
(ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
dialog->noncodeccapability |= AST_RTP_DTMF;
@@ -1886,8 +1632,8 @@
return res;
}
hostn = peer;
- portno = port ? atoi(port) : DEFAULT_SIP_PORT;
- if (srvlookup) {
+ portno = port ? atoi(port) : STANDARD_SIP_PORT;
+ if (global.srvlookup) {
char service[MAXHOSTNAMELEN];
int tportno;
int ret;
@@ -2045,7 +1791,7 @@
if (reg->timeout > -1)
ast_sched_del(sched, reg->timeout);
ast_string_field_free_all(reg);
- regobjs--;
+ sipcounters.registry_objects--;
free(reg);
}
@@ -2057,13 +1803,13 @@
struct sip_pkt *cp;
if (sip_debug_test_pvt(p) || option_debug > 2)
- ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text);
+ ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_method2txt(p->method));
/* Remove link from peer to subscription of MWI */
if (p->relatedpeer && p->relatedpeer->mwipvt)
p->relatedpeer->mwipvt = NULL;
- if (dumphistory)
+ if (global.dumphistory)
sip_dump_history(p);
if (p->options)
@@ -2535,7 +2281,7 @@
transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1);
/* Get RTCP quality before end of call */
- if (recordhistory) {
+ if (global.recordhistory) {
if (p->rtp)
append_history(p, "RTCPaudio", "Quality:%s", audioqos);
if (p->vrtp)
@@ -2907,7 +2653,7 @@
else if (i->capability) /* Our configured capability for this peer */
what = i->capability;
else
- what = global_capability; /* Global codec support */
+ what = global.capability; /* Global codec support */
/* Set the native formats for audio and merge in video */
tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | (i->jointcapability & AST_FORMAT_VIDEO_MASK);
@@ -2953,7 +2699,7 @@
if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) {
i->vad = ast_dsp_new();
ast_dsp_set_features(i->vad, DSP_FEATURE_DTMF_DETECT);
- if (global_relaxdtmf)
+ if (global.relaxdtmf)
ast_dsp_digitmode(i->vad, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF);
}
if (i->rtp) {
@@ -3011,7 +2757,7 @@
pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid);
ast_setstate(tmp, state);
if (i->rtp)
- ast_jb_configure(tmp, &global_jbconf);
+ ast_jb_configure(tmp, &global.jbconf);
if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) {
ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION;
@@ -3022,7 +2768,7 @@
for (v = i->chanvars ; v ; v = v->next)
pbx_builtin_setvar_helper(tmp,v->name,v->value);
- if (recordhistory)
+ if (global.recordhistory)
append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid);
return tmp;
@@ -3311,7 +3057,7 @@
p->autokillid = -1;
p->subscribed = NONE;
p->stateid = -1;
- p->prefs = default_prefs; /* Set default codecs for this call */
+ p->prefs = global.default_prefs; /* Set default codecs for this call */
if (intended_method != SIP_OPTIONS) /* Peerpoke has it's own system */
p->timer_t1 = 500; /* Default SIP retransmission timer T1 (RFC 3261) */
@@ -3319,25 +3065,25 @@
if (sin) {
p->sa = *sin;
if (ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip))
- p->ourip = __ourip;
+ p->ourip = sipnet.__ourip;
} else
- p->ourip = __ourip;
+ p->ourip = sipnet.__ourip;
/* Copy global flags to this PVT at setup. */
- ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY);
- ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY);
+ ast_copy_flags(&p->flags[0], &global.flags[0], SIP_FLAGS_TO_COPY);
+ ast_copy_flags(&p->flags[1], &global.flags[1], SIP_PAGE2_FLAGS_TO_COPY);
p->branch = ast_random();
make_our_tag(p->tag, sizeof(p->tag));
p->ocseq = INITIAL_CSEQ;
- if (sip_methods[intended_method].need_rtp) {
- p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ if (sip_method_needrtp(intended_method)) {
+ p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, sipnet.bindaddr.sin_addr);
/* If the global videosupport flag is on, we always create a RTP interface for video */
if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT))
- p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr);
+ p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, sipnet.bindaddr.sin_addr);
if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT))
- p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr);
+ p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, sipnet.bindaddr.sin_addr);
if (!p->rtp || (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp)) {
ast_log(LOG_WARNING, "Unable to create RTP audio %s session: %s\n",
ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video" : "", strerror(errno));
@@ -3351,24 +3097,24 @@
}
ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_INFO);
ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE));
- ast_rtp_settos(p->rtp, global_tos_audio);
+ ast_rtp_settos(p->rtp, global.tos_audio);
if (p->vrtp) {
- ast_rtp_settos(p->vrtp, global_tos_video);
+ ast_rtp_settos(p->vrtp, global.tos_video);
ast_rtp_setdtmf(p->vrtp, 0);
ast_rtp_setdtmfcompensate(p->vrtp, 0);
}
if (p->udptl)
- ast_udptl_settos(p->udptl, global_tos_audio);
- p->rtptimeout = global_rtptimeout;
- p->rtpholdtimeout = global_rtpholdtimeout;
- p->rtpkeepalive = global_rtpkeepalive;
- p->maxcallbitrate = default_maxcallbitrate;
+ ast_udptl_settos(p->udptl, global.tos_audio);
+ p->rtptimeout = global.rtptimeout;
+ p->rtpholdtimeout = global.rtpholdtimeout;
+ p->rtpkeepalive = global.rtpkeepalive;
+ p->maxcallbitrate = global.default_maxcallbitrate;
}
if (useglobal_nat && sin) {
int natflags;
/* Setup NAT structure according to global settings if we have an address */
- ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT);
+ ast_copy_flags(&p->flags[0], &global.flags[0], SIP_NAT);
p->recv = *sin;
natflags = ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE;
if (p->rtp)
@@ -3380,22 +3126,22 @@
}
if (p->method != SIP_REGISTER)
- ast_string_field_set(p, fromdomain, default_fromdomain);
+ ast_string_field_set(p, fromdomain, global.default_fromdomain);
build_via(p);
if (!callid)
build_callid_pvt(p);
else
ast_string_field_set(p, callid, callid);
/* Assign default music on hold class */
- ast_string_field_set(p, mohinterpret, default_mohinterpret);
- ast_string_field_set(p, mohsuggest, default_mohsuggest);
- p->capability = global_capability;
- p->allowtransfer = global_allowtransfer;
+ ast_string_field_set(p, mohinterpret, global.default_mohinterpret);
+ ast_string_field_set(p, mohsuggest, global.default_mohsuggest);
+ p->capability = global.capability;
+ p->allowtransfer = global.allowtransfer;
if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
(ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO))
p->noncodeccapability |= AST_RTP_DTMF;
if (p->udptl) {
- p->t38.capability = global_t38_capability;
+ p->t38.capability = global.t38_capability;
if (ast_udptl_get_error_correction_scheme(p->udptl) == UDPTL_ERROR_CORRECTION_REDUNDANCY)
p->t38.capability |= T38FAX_UDP_EC_REDUNDANCY;
else if (ast_udptl_get_error_correction_scheme(p->udptl) == UDPTL_ERROR_CORRECTION_FEC)
@@ -3405,7 +3151,7 @@
p->t38.capability |= T38FAX_RATE_MANAGEMENT_TRANSFERED_TCF;
p->t38.jointcapability = p->t38.capability;
}
- ast_string_field_set(p, context, default_context);
[... 2807 lines stripped ...]
More information about the asterisk-commits
mailing list