Newer
Older
* Asterisk -- An open source telephony toolkit.
* Copyright (C) 1999 - 2006, Digium, Inc.
* Mark Spencer <markster@digium.com>
* See http://www.asterisk.org for more information about
* the Asterisk project. Please do not directly contact
* any of the maintainers of this project for assistance;
* the project provides a web site, mailing lists and IRC
* channels for your use.
*
* This program is free software, distributed under the terms of
* the GNU General Public License Version 2. See the LICENSE file
* at the top of the source tree.
*/
/*!
* \file
* \brief Implementation of Session Initiation Protocol
*
* \author Mark Spencer <markster@digium.com>
*
* See Also:
* \arg \ref AstCREDITS
*
* Implementation of RFC 3261 - without S/MIME, TCP and TLS support
* Configuration file \link Config_sip sip.conf \endlink
* \todo SIP over TCP
* \todo SIP over TLS
* \todo Better support of forking
*
* \ingroup channel_drivers
Olle Johansson
committed
*
Kevin P. Fleming
committed
#include <unistd.h>
Kevin P. Fleming
committed
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <netdb.h>
#include <signal.h>
#include <sys/signal.h>
Kevin P. Fleming
committed
#include <netinet/in.h>
Kevin P. Fleming
committed
#include <netinet/in_systm.h>
Kevin P. Fleming
committed
#include <arpa/inet.h>
Kevin P. Fleming
committed
#include <netinet/ip.h>
#include <regex.h>
#include "asterisk.h"
Kevin P. Fleming
committed
Kevin P. Fleming
committed
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/logger.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/options.h"
#include "asterisk/lock.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "asterisk/features.h"
#include "asterisk/acl.h"
#include "asterisk/srv.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj.h"
#include "asterisk/dnsmgr.h"
Kevin P. Fleming
committed
#include "asterisk/devicestate.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/monitor.h"
#ifndef FALSE
#define FALSE 0
#endif
#ifndef TRUE
#define TRUE 1
#define VIDEO_CODEC_MASK 0x1fc0000 /*!< Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */
#define IPTOS_MINCOST 0x02
Olle Johansson
committed
#define DEFAULT_MIN_EXPIRY 60
#define DEFAULT_MAX_EXPIRY 3600
#define DEFAULT_REGISTRATION_TIMEOUT 20
#define DEFAULT_MAX_FORWARDS "70"
/* guard limit must be larger than guard secs */
Mark Spencer
committed
/* guard min must be < 1000, and should be >= 250 */
#define EXPIRY_GUARD_SECS 15 /*!< How long before expiry do we reregister */
#define EXPIRY_GUARD_LIMIT 30 /*!< Below here, we use EXPIRY_GUARD_PCT instead of
EXPIRY_GUARD_SECS */
#define EXPIRY_GUARD_MIN 500 /*!< This is the minimum guard time applied. If
GUARD_PCT turns out to be lower than this, it
will use this time instead.
This is in milliseconds. */
#define EXPIRY_GUARD_PCT 0.20 /*!< Percentage of expires timeout to use when
below EXPIRY_GUARD_LIMIT */
#define DEFAULT_EXPIRY 900 /*!< Expire slowly */
static int min_expiry = DEFAULT_MIN_EXPIRY; /*!< Minimum accepted registration time */
static int max_expiry = DEFAULT_MAX_EXPIRY; /*!< Maximum accepted registration time */
static int default_expiry = DEFAULT_DEFAULT_EXPIRY;
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
Martin Pycko
committed
#define CALLERID_UNKNOWN "Unknown"
#define DEFAULT_MAXMS 2000 /*!< Qualification: Must be faster than 2 seconds by default */
#define DEFAULT_FREQ_OK 60 * 1000 /*!< Qualification: How often to check for the host to be up */
#define DEFAULT_FREQ_NOTOK 10 * 1000 /*!< Qualification: How often to check, if the host is down... */
#define DEFAULT_RETRANS 1000 /*!< How frequently to retransmit Default: 2 * 500 ms in RFC 3261 */
#define MAX_RETRANS 6 /*!< Try only 6 times for retransmissions, a total of 7 transmissions */
#define MAX_AUTHTRIES 3 /*!< Try authentication three times, then fail */
#define SIP_MAX_HEADERS 64 /*!< Max amount of SIP headers to read */
#define SIP_MAX_LINES 64 /*!< Max amount of lines in SIP attachment (like SDP) */
#define SIP_MAX_PACKET 4096 /*!< Also from RFC 3261 (2543), should sub headers tho */
static const char desc[] = "Session Initiation Protocol (SIP)";
static const char config[] = "sip.conf";
static const char notify_config[] = "sip_notify.conf";
Kevin P. Fleming
committed
#define RTP 1
#define NO_RTP 0
Kevin P. Fleming
committed
/* Do _NOT_ make any changes to this enum, or the array following it;
if you think you are doing the right thing, you are probably
not doing the right thing. If you think there are changes
needed, get someone else to review them first _before_
submitting a patch. If these two lists do not match properly
bad things will happen.
*/
enum xmittype {
XMIT_CRITICAL = 2, /*!< Transmit critical SIP message reliably, with re-transmits.
If it fails, it's critical and will cause a teardown of the session */
XMIT_RELIABLE = 1, /*!< Transmit SIP message reliably, with re-transmits */
XMIT_UNRELIABLE = 0, /*!< Transmit SIP message without bothering with re-transmits */
};
Kevin P. Fleming
committed
enum subscriptiontype {
NONE = 0,
TIMEOUT,
XPIDF_XML,
DIALOG_INFO_XML,
CPIM_PIDF_XML,
Kevin P. Fleming
committed
PIDF_XML,
MWI_NOTIFICATION
Kevin P. Fleming
committed
};
static const struct cfsubscription_types {
enum subscriptiontype type;
const char * const event;
const char * const mediatype;
const char * const text;
} subscription_types[] = {
Kevin P. Fleming
committed
/* IETF draft: draft-ietf-sipping-dialog-package-05.txt */
{ 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 */
Kevin P. Fleming
committed
{ XPIDF_XML, "presence", "application/xpidf+xml", "xpidf+xml" }, /* Pre-RFC 3863 with MS additions */
{ MWI_NOTIFICATION, "message-summary", "application/simple-message-summary", "mwi" } /* Mailbox notification */
Kevin P. Fleming
committed
};
Kevin P. Fleming
committed
enum sipmethod {
SIP_UNKNOWN,
SIP_RESPONSE,
SIP_REGISTER,
SIP_OPTIONS,
SIP_NOTIFY,
SIP_INVITE,
SIP_ACK,
SIP_PRACK,
SIP_BYE,
SIP_REFER,
SIP_SUBSCRIBE,
SIP_MESSAGE,
SIP_UPDATE,
SIP_INFO,
SIP_CANCEL,
SIP_PUBLISH,
} sip_method_list;
enum sip_auth_type {
PROXY_AUTH,
WWW_AUTH,
};
/* States for outbound registrations (with register= lines in sip.conf */
enum sipregistrystate {
REG_STATE_UNREGISTERED = 0, /*!< We are not registred */
REG_STATE_REGSENT, /*!< Registration request sent */
REG_STATE_AUTHSENT, /*!< We have tried to authenticate */
REG_STATE_REGISTERED, /*!< Registred and done */
REG_STATE_REJECTED, /*!< Registration rejected */
REG_STATE_TIMEOUT, /*!< Registration timed out */
REG_STATE_NOAUTH, /*!< We have no accepted credentials */
REG_STATE_FAILED, /*!< Registration failed after several tries */
};
/*! XXX Note that sip_methods[i].id == i must hold or the code breaks */
Kevin P. Fleming
committed
enum sipmethod id;
int need_rtp; /*!< when this is the 'primary' use for a pvt structure, does it need RTP? */
} sip_methods[] = {
Kevin P. Fleming
committed
{ SIP_UNKNOWN, RTP, "-UNKNOWN-" },
{ SIP_RESPONSE, NO_RTP, "SIP/2.0" },
Kevin P. Fleming
committed
{ SIP_REGISTER, NO_RTP, "REGISTER" },
{ SIP_OPTIONS, NO_RTP, "OPTIONS" },
{ SIP_NOTIFY, NO_RTP, "NOTIFY" },
Kevin P. Fleming
committed
{ 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 Structure for conversion between compressed SIP and "normal" SIP */
Kevin P. Fleming
committed
static const struct cfalias {
char * const fullname;
char * const shortname;
} aliases[] = {
{ "Content-Type", "c" },
{ "Content-Encoding", "e" },
{ "From", "f" },
{ "Call-ID", "i" },
{ "Contact", "m" },
{ "Content-Length", "l" },
{ "Subject", "s" },
{ "To", "t" },
{ "Supported", "k" },
{ "Refer-To", "r" },
{ "Referred-By", "b" },
{ "Allow-Events", "u" },
{ "Event", "o" },
{ "Via", "v" },
{ "Accept-Contact", "a" },
{ "Reject-Contact", "j" },
{ "Request-Disposition", "d" },
/*! Define SIP option tags, used in Require: and Supported: headers
We need to be aware of these properties in the phones to use
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
the replace: header. We should not do that without knowing
that the other end supports it...
This is nothing we can configure, we learn by the dialog
Supported: header on the REGISTER (peer) or the INVITE
(other devices)
We are not using many of these today, but will in the future.
This is documented in RFC 3261
*/
#define SUPPORTED 1
#define NOT_SUPPORTED 0
#define SIP_OPT_REPLACES (1 << 0)
#define SIP_OPT_100REL (1 << 1)
#define SIP_OPT_TIMER (1 << 2)
#define SIP_OPT_EARLY_SESSION (1 << 3)
#define SIP_OPT_JOIN (1 << 4)
#define SIP_OPT_PATH (1 << 5)
#define SIP_OPT_PREF (1 << 6)
#define SIP_OPT_PRECONDITION (1 << 7)
#define SIP_OPT_PRIVACY (1 << 8)
#define SIP_OPT_SDP_ANAT (1 << 9)
#define SIP_OPT_SEC_AGREE (1 << 10)
#define SIP_OPT_EVENTLIST (1 << 11)
#define SIP_OPT_GRUU (1 << 12)
#define SIP_OPT_TARGET_DIALOG (1 << 13)
/*! \brief List of well-known SIP options. If we get this in a require,
we should check the list and answer accordingly. */
int id; /*!< Bitmap ID */
int supported; /*!< Supported by Asterisk ? */
char * const text; /*!< Text id, as in standard */
} sip_options[] = {
/* Replaces: header for transfer */
{ SIP_OPT_REPLACES, SUPPORTED, "replaces" },
/* RFC3262: PRACK 100% reliability */
{ SIP_OPT_100REL, NOT_SUPPORTED, "100rel" },
/* SIP Session Timers */
{ SIP_OPT_TIMER, NOT_SUPPORTED, "timer" },
/* RFC3959: SIP Early session support */
{ SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" },
/* 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-00.txt */
{ SIP_OPT_TARGET_DIALOG,NOT_SUPPORTED, "target-dialog" },
};
/*! \brief SIP Methods we support */
Kevin P. Fleming
committed
#define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY"
/*! \brief SIP Extensions we support */
#define SUPPORTED_EXTENSIONS "replaces"
/* Default values, set and reset in reload_config before reading configuration */
/* These are default values in the source. There are other recommended values in the
sip.conf.sample for new installations. These may differ to keep backwards compatibility,
yet encouraging new behaviour on new installations
*/
#define DEFAULT_SIP_PORT 5060 /*!< From RFC 3261 (former 2543) */
#define DEFAULT_CONTEXT "default"
#define DEFAULT_MUSICCLASS "default"
#define DEFAULT_VMEXTEN "asterisk"
#define DEFAULT_CALLERID "asterisk"
#define DEFAULT_NOTIFYMIME "application/simple-message-summary"
#define DEFAULT_MWITIME 10
#define DEFAULT_ALLOWGUEST TRUE
#define DEFAULT_SRVLOOKUP FALSE /*!< Recommended setting is ON */
#define DEFAULT_COMPACTHEADERS FALSE
Kevin P. Fleming
committed
#define DEFAULT_TOS_SIP 0 /*!< Call signalling packets should be marked as DSCP CS3, but the default is 0 to be compatible with previous versions. */
#define DEFAULT_TOS_AUDIO 0 /*!< Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions. */
#define DEFAULT_TOS_VIDEO 0 /*!< Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions. */
#define DEFAULT_ALLOW_EXT_DOM TRUE
#define DEFAULT_REALM "asterisk"
#define DEFAULT_NOTIFYRINGING TRUE
#define DEFAULT_PEDANTIC FALSE
#define DEFAULT_AUTOCREATEPEER FALSE
#define DEFAULT_QUALIFY FALSE
#define DEFAULT_T1MIN 100 /*!< 100 MS for minimal roundtrip time */
#define DEFAULT_MAX_CALL_BITRATE (384) /*!< Max bitrate for video */
#ifndef DEFAULT_USERAGENT
#define DEFAULT_USERAGENT "Asterisk PBX" /*!< Default Useragent: header unless re-defined in sip.conf */
#endif
/* Default setttings are used as a channel setting and as a default when
configuring devices */
Olle Johansson
committed
static char default_context[AST_MAX_CONTEXT];
Kevin P. Fleming
committed
static char default_subscribecontext[AST_MAX_CONTEXT];
Olle Johansson
committed
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 int default_qualify; /*!< Default Qualify= setting */
static char default_vmexten[AST_MAX_EXTENSION];
static char default_musicclass[MAX_MUSICCLASS]; /*!< Global music on hold class */
static int default_maxcallbitrate; /*!< Maximum bitrate for call */
Olle Johansson
committed
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 */
Olle Johansson
committed
static int srvlookup; /*!< SRV Lookup on or off. Default is off, RFC behavior is on */
static int pedanticsipchecking; /*!< Extra checking ? Default off */
static int autocreatepeer; /*!< Auto creation of peers at registration? Default off. */
static int global_relaxdtmf; /*!< Relax DTMF */
Olle Johansson
committed
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
Kevin P. Fleming
committed
the global setting is in globals_flags[1] */
Olle Johansson
committed
static int global_mwitime; /*!< Time between MWI checks for peers */
Kevin P. Fleming
committed
static int global_tos_sip; /*!< IP type of service for SIP packets */
static int global_tos_audio; /*!< IP type of service for audio RTP packets */
static int global_tos_video; /*!< IP type of service for video RTP 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 */
Olle Johansson
committed
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 */
/*! \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;
Mark Spencer
committed
/* 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 */
Mark Spencer
committed
static struct ast_flags global_flags[2] = {{0}}; /*!< global SIP_ flags */
AST_MUTEX_DEFINE_STATIC(usecnt_lock);
Olle Johansson
committed
/*! \brief Protect the SIP dialog list (of sip_pvt's) */
/*! \brief Protect the monitoring thread, so only one process can kill or start it, and not
AST_MUTEX_DEFINE_STATIC(netlock);
AST_MUTEX_DEFINE_STATIC(monlock);
AST_MUTEX_DEFINE_STATIC(sip_reload_lock);
/*! \brief This is the thread for the monitor which checks for input on the channels
static pthread_t monitor_thread = AST_PTHREADT_NULL;
static int sip_reloading = FALSE; /*!< Flag for avoiding multiple reloads at the same time */
static enum channelreloadreason sip_reloadreason; /*!< Reason for last reload/load of configuration */
Olle Johansson
committed
static struct sched_context *sched; /*!< The scheduling context */
static struct io_context *io; /*!< The IO context */
Kevin P. Fleming
committed
#define DEC_CALL_LIMIT 0
#define INC_CALL_LIMIT 1
/*! \brief sip_request: The data grabbed from the UDP socket */
char *rlPart1; /*!< SIP Method Name or "SIP/2.0" protocol version */
char *rlPart2; /*!< The Request URI or Response Status */
int len; /*!< Length */
int headers; /*!< # of SIP Headers */
int method; /*!< Method of this request */
char *line[SIP_MAX_LINES];
char data[SIP_MAX_PACKET];
int debug; /*!< Debug flag for this packet */
unsigned int flags; /*!< SIP_PKT Flags for this packet */
/*! \brief structure used in transfers */
struct sip_dual {
struct ast_channel *chan1;
struct ast_channel *chan2;
struct sip_request req;
};
/*! \brief Parameters to the transmit_invite function */
struct sip_invite_param {
const char *distinctive_ring; /*!< Distinctive ring header */
int addsipheaders; /*!< Add extra SIP headers */
const char *uri_options; /*!< URI options to add to the URI */
const char *vxml_url; /*!< VXML url for Cisco phones */
char *auth; /*!< Authentication */
char *authheader; /*!< Auth header */
enum sip_auth_type auth_type; /*!< Authentication type */
};
Olle Johansson
committed
/*! \brief Structure to save routing information for a SIP session */
struct sip_route {
struct sip_route *next;
char hop[0];
};
Olle Johansson
committed
/*! \brief Modes for SIP domain handling in the PBX */
enum domain_mode {
SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */
SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */
};
struct domain {
char domain[MAXHOSTNAMELEN]; /*!< SIP domain we are responsible for */
char context[AST_MAX_EXTENSION]; /*!< Incoming context for this domain */
enum domain_mode mode; /*!< How did we find this domain? */
AST_LIST_ENTRY(domain) list; /*!< List mechanics */
static AST_LIST_HEAD_STATIC(domain_list, domain); /*!< The SIP domain list */
/*! \brief sip_history: Structure for saving transactions within a SIP dialog */
Mark Spencer
committed
struct sip_history {
Olle Johansson
committed
AST_LIST_ENTRY(sip_history) list;
char event[0]; /* actually more, depending on needs */
Mark Spencer
committed
};
Olle Johansson
committed
AST_LIST_HEAD_NOLOCK(sip_history_head, sip_history); /*!< history list, entry in sip_pvt */
/*! \brief sip_auth: Creadentials for authentication to other SIP services */
char realm[AST_MAX_EXTENSION]; /*!< Realm in which these credentials are valid */
char username[256]; /*!< Username */
char secret[256]; /*!< Secret */
char md5secret[256]; /*!< MD5Secret */
struct sip_auth *next; /*!< Next auth structure in list */
Olle Johansson
committed
/*--- Various flags for the flags field in the pvt structure
Peer only flags should be set in PAGE2 below
*/
#define SIP_ALREADYGONE (1 << 0) /*!< Whether or not we've already been destroyed by our peer */
#define SIP_NEEDDESTROY (1 << 1) /*!< if we need to be destroyed */
#define SIP_NOVIDEO (1 << 2) /*!< Didn't get video in invite, don't offer */
#define SIP_RINGING (1 << 3) /*!< Have sent 180 ringing */
#define SIP_PROGRESS_SENT (1 << 4) /*!< Have sent 183 message progress */
#define SIP_NEEDREINVITE (1 << 5) /*!< Do we need to send another reinvite? */
#define SIP_PENDINGBYE (1 << 6) /*!< Need to send bye after we ack? */
#define SIP_GOTREFER (1 << 7) /*!< Got a refer? */
#define SIP_PROMISCREDIR (1 << 8) /*!< Promiscuous redirection */
#define SIP_TRUSTRPID (1 << 9) /*!< Trust RPID headers? */
#define SIP_USEREQPHONE (1 << 10) /*!< Add user=phone to numeric URI. Default off */
#define SIP_REALTIME (1 << 11) /*!< Flag for realtime users */
#define SIP_USECLIENTCODE (1 << 12) /*!< Trust X-ClientCode info message */
#define SIP_OUTGOING (1 << 13) /*!< Is this an outgoing call? */
Olle Johansson
committed
#define SIP_FREEBIT (1 << 14) /*!< Free for session-related use */
#define SIP_FREEBIT3 (1 << 15) /*!< Free for session-related use */
#define SIP_DTMF (3 << 16) /*!< DTMF Support: four settings, uses two bits */
#define SIP_DTMF_RFC2833 (0 << 16) /*!< DTMF Support: RTP DTMF - "rfc2833" */
#define SIP_DTMF_INBAND (1 << 16) /*!< DTMF Support: Inband audio, only for ULAW/ALAW - "inband" */
#define SIP_DTMF_INFO (2 << 16) /*!< DTMF Support: SIP Info messages - "info" */
#define SIP_DTMF_AUTO (3 << 16) /*!< DTMF Support: AUTO switch between rfc2833 and in-band DTMF */
#define SIP_NAT (3 << 18) /*!< four settings, uses two bits */
#define SIP_NAT_NEVER (0 << 18) /*!< No nat support */
#define SIP_NAT_RFC3581 (1 << 18) /*!< NAT RFC3581 */
#define SIP_NAT_ROUTE (2 << 18) /*!< NAT Only ROUTE */
#define SIP_NAT_ALWAYS (3 << 18) /*!< NAT Both ROUTE and RFC3581 */
/* re-INVITE related settings */
#define SIP_REINVITE (3 << 20) /*!< two bits used */
#define SIP_CAN_REINVITE (1 << 20) /*!< allow peers to be reinvited to send media directly p2p */
#define SIP_REINVITE_UPDATE (2 << 20) /*!< use UPDATE (RFC3311) when reinviting this peer */
#define SIP_INSECURE_PORT (1 << 22) /*!< don't require matching port for incoming requests */
#define SIP_INSECURE_INVITE (1 << 23) /*!< don't require authentication for incoming INVITEs */
/* Sending PROGRESS in-band settings */
#define SIP_PROG_INBAND (3 << 24) /*!< three settings, uses two bits */
#define SIP_PROG_INBAND_NEVER (0 << 24)
#define SIP_PROG_INBAND_NO (1 << 24)
#define SIP_PROG_INBAND_YES (2 << 24)
#define SIP_CALL_ONHOLD (1 << 26) /*!< Call states */
#define SIP_CALL_LIMIT (1 << 27) /*!< Call limit enforced for this call */
#define SIP_SENDRPID (1 << 28) /*!< Remote Party-ID Support */
#define SIP_INC_COUNT (1 << 29) /*!< Did this connection increment the counter of in-use calls? */
Kevin P. Fleming
committed
#define SIP_FLAGS_TO_COPY \
(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \
SIP_PROG_INBAND | SIP_USECLIENTCODE | SIP_NAT | \
SIP_USEREQPHONE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE)
Kevin P. Fleming
committed
Olle Johansson
committed
/* a new page of flags for peers */
Kevin P. Fleming
committed
#define SIP_PAGE2_RTCACHEFRIENDS (1 << 0)
#define SIP_PAGE2_RTUPDATE (1 << 1)
#define SIP_PAGE2_RTAUTOCLEAR (1 << 2)
Mark Spencer
committed
#define SIP_PAGE2_IGNOREREGEXPIRE (1 << 3)
#define SIP_PAGE2_RT_FROMCONTACT (1 << 4)
Russell Bryant
committed
#define SIP_PAGE2_DEBUG (3 << 5)
#define SIP_PAGE2_DEBUG_CONFIG (1 << 5)
#define SIP_PAGE2_DEBUG_CONSOLE (1 << 6)
Olle Johansson
committed
#define SIP_PAGE2_DYNAMIC (1 << 7) /*!< Dynamic Peers register with Asterisk */
#define SIP_PAGE2_SELFDESTRUCT (1 << 8) /*!< Automatic peers need to destruct themselves */
#define SIP_PAGE2_ALLOWSUBSCRIBE (1 << 10) /*!< Allow subscriptions from this peer? */
#define SIP_PAGE2_ALLOWOVERLAP (1 << 11) /*!< Allow overlap dialing ? */
Kevin P. Fleming
committed
#define SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 12) /*!< Only issue MWI notification if subscribed to */
(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_VIDEOSUPPORT)
/* SIP packet flags */
#define SIP_PKT_DEBUG (1 << 0) /*!< Debug this packet */
#define SIP_PKT_WITH_TOTAG (1 << 1) /*!< This packet has a to-tag */
#define sipdebug ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG)
#define sipdebug_config ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONFIG)
#define sipdebug_console ast_test_flag(&global_flags[1], SIP_PAGE2_DEBUG_CONSOLE)
Russell Bryant
committed
Olle Johansson
committed
/*! \brief sip_pvt: PVT structures are used for each SIP dialog, ie. a call, a registration, a subscribe */
Olle Johansson
committed
ast_mutex_t lock; /*!< Dialog private lock */
int method; /*!< SIP method that opened this dialog */
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(callid); /*!< Global CallID */
AST_STRING_FIELD(randdata); /*!< Random data */
AST_STRING_FIELD(accountcode); /*!< Account code */
AST_STRING_FIELD(realm); /*!< Authorization realm */
AST_STRING_FIELD(nonce); /*!< Authorization nonce */
AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
AST_STRING_FIELD(domain); /*!< Authorization domain */
AST_STRING_FIELD(refer_to); /*!< Place to store REFER-TO extension */
AST_STRING_FIELD(referred_by); /*!< Place to store REFERRED-BY extension */
AST_STRING_FIELD(refer_contact);/*!< Place to store Contact info from a REFER extension */
AST_STRING_FIELD(from); /*!< The From: header */
AST_STRING_FIELD(useragent); /*!< User agent in SIP request */
AST_STRING_FIELD(exten); /*!< Extension where to start */
AST_STRING_FIELD(context); /*!< Context for this call */
AST_STRING_FIELD(subscribecontext); /*!< Subscribecontext */
AST_STRING_FIELD(fromdomain); /*!< Domain to show in the from field */
AST_STRING_FIELD(fromuser); /*!< User to show in the user field */
AST_STRING_FIELD(fromname); /*!< Name to show in the user field */
AST_STRING_FIELD(tohost); /*!< Host we should put in the "to" field */
AST_STRING_FIELD(language); /*!< Default language for this call */
AST_STRING_FIELD(musicclass); /*!< Music on Hold class */
AST_STRING_FIELD(rdnis); /*!< Referring DNIS */
AST_STRING_FIELD(theirtag); /*!< Their tag */
AST_STRING_FIELD(username); /*!< [user] name */
AST_STRING_FIELD(peername); /*!< [peer] name, not set if [user] */
AST_STRING_FIELD(authname); /*!< Who we use for authentication */
AST_STRING_FIELD(uri); /*!< Original requested URI */
AST_STRING_FIELD(okcontacturi); /*!< URI from the 200 OK on INVITE */
AST_STRING_FIELD(peersecret); /*!< Password */
AST_STRING_FIELD(peermd5secret);
AST_STRING_FIELD(cid_num); /*!< Caller*ID */
AST_STRING_FIELD(cid_name); /*!< Caller*ID */
AST_STRING_FIELD(via); /*!< Via: header */
AST_STRING_FIELD(fullcontact); /*!< The Contact: that the UA registers with us */
AST_STRING_FIELD(our_contact); /*!< Our contact header */
AST_STRING_FIELD(rpid); /*!< Our RPID header */
AST_STRING_FIELD(rpid_from); /*!< Our RPID From header */
);
struct ast_codec_pref prefs; /*!< codec prefs */
unsigned int ocseq; /*!< Current outgoing seqno */
unsigned int icseq; /*!< Current incoming seqno */
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup group */
int lastinvite; /*!< Last Cseq of invite */
struct ast_flags flags[2]; /*!< SIP_ flags */
int timer_t1; /*!< SIP timer T1, ms rtt */
unsigned int sipoptions; /*!< Supported SIP sipoptions on the other end */
int capability; /*!< Special capability (codec) */
int jointcapability; /*!< Supported capability at both ends (codecs ) */
int peercapability; /*!< Supported peer capability */
int prefcodec; /*!< Preferred codec (outbound only) */
int maxcallbitrate; /*!< Maximum Call Bitrate for Video Calls */
int callingpres; /*!< Calling presentation */
int authtries; /*!< Times we've tried to authenticate */
int expiry; /*!< How long we take to expire */
Tilghman Lesher
committed
long branch; /*!< One random number */
char tag[11]; /*!< Another random number */
int sessionid; /*!< SDP Session ID */
int sessionversion; /*!< SDP Session Version */
struct sockaddr_in sa; /*!< Our peer */
struct sockaddr_in redirip; /*!< Where our RTP should be going if not to us */
struct sockaddr_in vredirip; /*!< Where our Video RTP should be going if not to us */
int redircodecs; /*!< Redirect codecs */
struct sockaddr_in recv; /*!< Received as */
struct in_addr ourip; /*!< Our IP */
struct ast_channel *owner; /*!< Who owns us */
struct sip_pvt *refer_call; /*!< Call we are referring */
struct sip_route *route; /*!< Head of linked list of routing steps (fm Record-Route) */
int route_persistant; /*!< Is this the "real" route? */
struct sip_auth *peerauth; /*!< Realm authentication */
int noncecount; /*!< Nonce-count */
char lastmsg[256]; /*!< Last Message sent/received */
int amaflags; /*!< AMA Flags */
int pendinginvite; /*!< Any pending invite */
struct sip_request initreq; /*!< Initial request that opened the SIP dialog */
int maxtime; /*!< Max time for first response */
int initid; /*!< Auto-congest ID if appropriate */
int autokillid; /*!< Auto-kill ID */
time_t lastrtprx; /*!< Last RTP received */
time_t lastrtptx; /*!< Last RTP sent */
int rtptimeout; /*!< RTP timeout time */
int rtpholdtimeout; /*!< RTP timeout when on hold */
int rtpkeepalive; /*!< Send RTP packets for keepalive */
Olle Johansson
committed
enum subscriptiontype subscribed; /*!< Is this dialog a subscription? */
int dialogver;
struct ast_dsp *vad; /*!< Voice Activation Detection dsp */
Kevin P. Fleming
committed
struct sip_peer *relatedpeer; /*!< If this dialog is related to a peer, which one
Used in peerpoke, mwi subscriptions */
Olle Johansson
committed
struct sip_registry *registry; /*!< If this is a REGISTER dialog, to which registry */
struct ast_rtp *rtp; /*!< RTP Session */
struct ast_rtp *vrtp; /*!< Video RTP session */
struct sip_pkt *packets; /*!< Packets scheduled for re-transmission */
Olle Johansson
committed
struct sip_history_head *history; /*!< History of this SIP dialog */
struct ast_variable *chanvars; /*!< Channel variables to set for call */
Olle Johansson
committed
struct sip_pvt *next; /*!< Next dialog in chain */
struct sip_invite_param *options; /*!< Options for INVITE */
#define FLAG_RESPONSE (1 << 0)
#define FLAG_FATAL (1 << 1)
Olle Johansson
committed
/*! \brief sip packet - read in sipsock_read(), transmitted in send_request() */
struct sip_pkt *next; /*!< Next packet */
int retrans; /*!< Retransmission number */
int method; /*!< SIP method for this packet */
int seqno; /*!< Sequence number */
unsigned int flags; /*!< non-zero if this is a response packet (e.g. 200 OK) */
Olle Johansson
committed
struct sip_pvt *owner; /*!< Owner AST call */
int retransid; /*!< Retransmission ID */
int timer_a; /*!< SIP timer A, retransmission timer */
int timer_t1; /*!< SIP Timer T1, estimated RTT or 500 ms */
int packetlen; /*!< Length of packet */
/*! \brief Structure for SIP user data. User's place calls to us */
struct sip_user {
/* Users who can access various contexts */
Mark Spencer
committed
ASTOBJ_COMPONENTS(struct sip_user);
char secret[80]; /*!< Password */
char md5secret[80]; /*!< Password in md5 */
char context[AST_MAX_CONTEXT]; /*!< Default context for incoming calls */
Kevin P. Fleming
committed
char subscribecontext[AST_MAX_CONTEXT]; /* Default context for subscriptions */
char cid_num[80]; /*!< Caller ID num */
char cid_name[80]; /*!< Caller ID name */
char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */
char language[MAX_LANGUAGE]; /*!< Default language for this user */
char musicclass[MAX_MUSICCLASS];/*!< Music on Hold class */
char useragent[256]; /*!< User agent in SIP request */
struct ast_codec_pref prefs; /*!< codec prefs */
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup Group */
unsigned int sipoptions; /*!< Supported SIP options */
struct ast_flags flags[2]; /*!< SIP_ flags */
int amaflags; /*!< AMA flags for billing */
int callingpres; /*!< Calling id presentation */
int capability; /*!< Codec capability */
int inUse; /*!< Number of calls in use */
int call_limit; /*!< Limit of concurrent calls */
struct ast_ha *ha; /*!< ACL setting */
struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
int maxcallbitrate; /*!< Maximum Bitrate for a video call */
/*! \brief Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host) */
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
ASTOBJ_COMPONENTS(struct sip_peer); /*!< name, refcount, objflags, object pointers */
/*!< peer->name is the unique name of this object */
char secret[80]; /*!< Password */
char md5secret[80]; /*!< Password in MD5 */
struct sip_auth *auth; /*!< Realm authentication list */
char context[AST_MAX_CONTEXT]; /*!< Default context for incoming calls */
char subscribecontext[AST_MAX_CONTEXT]; /*!< Default context for subscriptions */
char username[80]; /*!< Temporary username until registration */
char accountcode[AST_MAX_ACCOUNT_CODE]; /*!< Account code */
int amaflags; /*!< AMA Flags (for billing) */
char tohost[MAXHOSTNAMELEN]; /*!< If not dynamic, IP address */
char regexten[AST_MAX_EXTENSION]; /*!< Extension to register (if regcontext is used) */
char fromuser[80]; /*!< From: user when calling this peer */
char fromdomain[MAXHOSTNAMELEN]; /*!< From: domain when calling this peer */
char fullcontact[256]; /*!< Contact registered with us (not in sip.conf) */
char cid_num[80]; /*!< Caller ID num */
char cid_name[80]; /*!< Caller ID name */
int callingpres; /*!< Calling id presentation */
int inUse; /*!< Number of calls in use */
int call_limit; /*!< Limit of concurrent calls */
char vmexten[AST_MAX_EXTENSION]; /*!< Dialplan extension for MWI notify message*/
char mailbox[AST_MAX_EXTENSION]; /*!< Mailbox setting for MWI checks */
char language[MAX_LANGUAGE]; /*!< Default language for prompts */
char musicclass[MAX_MUSICCLASS];/*!< Music on Hold class */
char useragent[256]; /*!< User agent in SIP request (saved from registration) */
struct ast_codec_pref prefs; /*!< codec prefs */
time_t lastmsgcheck; /*!< Last time we checked for MWI */
unsigned int sipoptions; /*!< Supported SIP options */
struct ast_flags flags[2]; /*!< SIP_ flags */
int expire; /*!< When to expire this peer registration */
int capability; /*!< Codec capability */
int rtptimeout; /*!< RTP timeout */
int rtpholdtimeout; /*!< RTP Hold Timeout */
int rtpkeepalive; /*!< Send RTP packets for keepalive */
ast_group_t callgroup; /*!< Call group */
ast_group_t pickupgroup; /*!< Pickup group */
struct ast_dnsmgr_entry *dnsmgr;/*!< DNS refresh manager for peer */
struct sockaddr_in addr; /*!< IP address of peer */
int maxcallbitrate; /*!< Maximum Bitrate for a video call */
struct sip_pvt *call; /*!< Call pointer */
int pokeexpire; /*!< When to expire poke (qualify= checking) */
int lastms; /*!< How long last response took (in ms), or -1 for no response */
int maxms; /*!< Max ms we will accept for the host to be up, 0 to not monitor */
struct timeval ps; /*!< Ping send time */
struct sockaddr_in defaddr; /*!< Default IP address, used until registration */
struct ast_ha *ha; /*!< Access control list */
struct ast_variable *chanvars; /*!< Variables to set for channel created by user */
Kevin P. Fleming
committed
struct sip_pvt *mwipvt; /*!< Subscription for MWI */
/*! \brief Registrations with other SIP proxies */
Mark Spencer
committed
ASTOBJ_COMPONENTS_FULL(struct sip_registry,1,1);
AST_DECLARE_STRING_FIELDS(
AST_STRING_FIELD(callid); /*!< Global Call-ID */
AST_STRING_FIELD(realm); /*!< Authorization realm */
AST_STRING_FIELD(nonce); /*!< Authorization nonce */
AST_STRING_FIELD(opaque); /*!< Opaque nonsense */
AST_STRING_FIELD(qop); /*!< Quality of Protection, since SIP wasn't complicated enough yet. */
AST_STRING_FIELD(domain); /*!< Authorization domain */
AST_STRING_FIELD(username); /*!< Who we are registering as */
AST_STRING_FIELD(authuser); /*!< Who we *authenticate* as */
AST_STRING_FIELD(hostname); /*!< Domain or host we register to */
AST_STRING_FIELD(secret); /*!< Password in clear text */
AST_STRING_FIELD(md5secret); /*!< Password in md5 */
AST_STRING_FIELD(contact); /*!< Contact extension */
AST_STRING_FIELD(random);
);
int portno; /*!< Optional port override */
int expire; /*!< Sched ID of expiration */
int regattempts; /*!< Number of attempts (since the last success) */
int timeout; /*!< sched id of sip_reg_timeout */
int refresh; /*!< How often to refresh */
Olle Johansson
committed
struct sip_pvt *call; /*!< create a sip_pvt structure for each outbound "registration dialog" in progress */
enum sipregistrystate regstate; /*!< Registration state (see above) */
int callid_valid; /*!< 0 means we haven't chosen callid for this registry yet. */
unsigned int ocseq; /*!< Sequence number we got to for REGISTERs for this registry */
struct sockaddr_in us; /*!< Who the server thinks we are */
int noncecount; /*!< Nonce-count */
char lastmsg[256]; /*!< Last Message sent/received */
/* --- Linked lists of various objects --------*/
/*! \brief The user list: Users and friends */
static struct ast_user_list {
Mark Spencer
committed
ASTOBJ_CONTAINER_COMPONENTS(struct sip_user);
/*! \brief The peer list: Peers and Friends */
static struct ast_peer_list {
Mark Spencer
committed
ASTOBJ_CONTAINER_COMPONENTS(struct sip_peer);
Olle Johansson
committed
/*! \brief The register list: Other SIP proxys we register with and place calls to */
static struct ast_register_list {
Mark Spencer
committed
ASTOBJ_CONTAINER_COMPONENTS(struct sip_registry);
/*! \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 */
Mark Spencer
committed
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;
struct ast_config *notify_types; /*!< The list of manual NOTIFY types we know how to send */
/*---------------------------- Forward declarations of functions in chan_sip.c */
static int transmit_response(struct sip_pvt *p, char *msg, struct sip_request *req);
static int transmit_response_with_sdp(struct sip_pvt *p, char *msg, struct sip_request *req, enum xmittype reliable);
static int transmit_response_with_unsupported(struct sip_pvt *p, char *msg, struct sip_request *req, char *unsupported);
static int transmit_response_with_auth(struct sip_pvt *p, const char *msg, struct sip_request *req, const char *rand, enum xmittype reliable, const char *header, int stale);
static int transmit_request(struct sip_pvt *p, int sipmethod, int inc, enum xmittype reliable, int newbranch);
static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, int inc, enum xmittype reliable, int newbranch);
Kevin P. Fleming
committed
static int transmit_invite(struct sip_pvt *p, int sipmethod, int sendsdp, int init);
static int transmit_reinvite_with_sdp(struct sip_pvt *p);
static int transmit_info_with_digit(struct sip_pvt *p, char digit);
static int transmit_info_with_vidupdate(struct sip_pvt *p);
Mark Spencer
committed
static int transmit_message_with_text(struct sip_pvt *p, const char *text);
static int transmit_refer(struct sip_pvt *p, const char *dest);
static int sip_sipredirect(struct sip_pvt *p, const char *dest);
static struct sip_peer *temp_peer(const char *name);
static int do_proxy_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader, int sipmethod, int init);
static void free_old_route(struct sip_route *route);
static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len);
static int build_reply_digest(struct sip_pvt *p, int method, char *digest, int digest_len);
Kevin P. Fleming
committed
static int update_call_counter(struct sip_pvt *fup, int event);
static struct sip_peer *build_peer(const char *name, struct ast_variable *v, int realtime);
static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime);
static int sip_do_reload(enum channelreloadreason reason);
static int expire_register(void *data);
static struct ast_channel *sip_request_call(const char *type, int format, void *data, int *cause);
static int sip_devicestate(void *data);
Mark Spencer
committed
static int sip_sendtext(struct ast_channel *ast, const char *text);
static int sip_call(struct ast_channel *ast, char *dest, int timeout);
static int sip_hangup(struct ast_channel *ast);
static int sip_answer(struct ast_channel *ast);
static struct ast_frame *sip_read(struct ast_channel *ast);
static int sip_write(struct ast_channel *ast, struct ast_frame *frame);
static int sip_indicate(struct ast_channel *ast, int condition);
Mark Spencer
committed
static int sip_transfer(struct ast_channel *ast, const char *dest);
static int sip_fixup(struct ast_channel *oldchan, struct ast_channel *newchan);
static int sip_senddigit(struct ast_channel *ast, char digit);
static int clear_realm_authentication(struct sip_auth *authlist); /* Clear realm authentication list (at reload) */
static struct sip_auth *add_realm_authentication(struct sip_auth *authlist, char *configuration, int lineno); /* Add realm authentication in list */
static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, const char *realm); /* Find authentication for a specific realm */
static int check_auth(struct sip_pvt *p, struct sip_request *req, const char *username,
const char *secret, const char *md5secret, int sipmethod,
char *uri, enum xmittype reliable, int ignore);
static int check_sip_domain(const char *domain, char *context, size_t len); /* Check if domain is one of our local domains */
static void append_date(struct sip_request *req); /* Append date to SIP packet */
static int determine_firstline_parts(struct sip_request *req);
static void sip_dump_history(struct sip_pvt *dialog); /* Dump history to LOG_DEBUG at end of dialog, before destroying data */
Kevin P. Fleming
committed
static const struct cfsubscription_types *find_subscription_type(enum subscriptiontype subtype);
static int transmit_state_notify(struct sip_pvt *p, int state, int full);
static char *gettag(struct sip_request *req, char *header, char *tagbuf, int tagbufsize);
static int find_sip_method(char *msg);
static unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported);
static void sip_destroy(struct sip_pvt *p);
Kevin P. Fleming
committed
static void sip_destroy_peer(struct sip_peer *peer);
static void sip_destroy_user(struct sip_user *user);
static void parse_request(struct sip_request *req);
static char *get_header(struct sip_request *req, const char *name);
static void copy_request(struct sip_request *dst,struct sip_request *src);
static int transmit_response_reliable(struct sip_pvt *p, char *msg, struct sip_request *req);
static int transmit_register(struct sip_registry *r, int sipmethod, char *auth, char *authheader);
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);
Kevin P. Fleming
committed
static int sip_send_mwi_to_peer(struct sip_peer *peer);
static int sip_scheddestroy(struct sip_pvt *p, int ms);
/*----- 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);
static struct ast_rtp *sip_get_rtp_peer(struct ast_channel *chan);
static struct ast_rtp *sip_get_vrtp_peer(struct ast_channel *chan);
static int sip_get_codec(struct ast_channel *chan);
/*! \brief Definition of this channel for PBX channel registration */
static const struct ast_channel_tech sip_tech = {
.description = "Session Initiation Protocol (SIP)",
.capabilities = ((AST_FORMAT_MAX_AUDIO << 1) - 1),
Mark Spencer
committed
.properties = AST_CHAN_TP_WANTSJITTER,
.requester = sip_request_call,
.devicestate = sip_devicestate,