Index: chan_sip.c =================================================================== RCS file: /usr/cvsroot/asterisk/channels/chan_sip.c,v retrieving revision 1.797 diff -u -r1.797 chan_sip.c --- chan_sip.c 28 Jul 2005 18:24:04 -0000 1.797 +++ chan_sip.c 29 Jul 2005 16:12:38 -0000 @@ -71,30 +71,30 @@ #define DEFAULT_USERAGENT "Asterisk PBX" #endif -#define VIDEO_CODEC_MASK 0x1fc0000 /* Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */ +#define VIDEO_CODEC_MASK 0x1fc0000 /* Video codecs from H.261 thru AST_FORMAT_MAX_VIDEO */ #ifndef IPTOS_MINCOST -#define IPTOS_MINCOST 0x02 +#define IPTOS_MINCOST 0x02 #endif /* #define VOCAL_DATA_HACK */ #define SIPDUMPER -#define DEFAULT_DEFAULT_EXPIRY 120 -#define DEFAULT_MAX_EXPIRY 3600 -#define DEFAULT_REGISTRATION_TIMEOUT 20 -#define DEFAULT_REGATTEMPTS_MAX 10 +#define DEFAULT_DEFAULT_EXPIRY 120 +#define DEFAULT_MAX_EXPIRY 3600 +#define DEFAULT_REGISTRATION_TIMEOUT 20 +#define DEFAULT_REGATTEMPTS_MAX 10 +#define DEFAULT_MAX_FORWARDS 70 /* guard limit must be larger than guard secs */ /* 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 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 */ static int max_expiry = DEFAULT_MAX_EXPIRY; static int default_expiry = DEFAULT_DEFAULT_EXPIRY; @@ -103,28 +103,25 @@ #define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif -#define CALLERID_UNKNOWN "Unknown" +#define CALLERID_UNKNOWN "Unknown" +#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */ +#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */ +#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */ +#define DEFAULT_RETRANS 2000 /* How frequently to retransmit */ +#define MAX_RETRANS 5 /* Try only 5 times for retransmissions */ -#define DEFAULT_MAXMS 2000 /* Must be faster than 2 seconds by default */ -#define DEFAULT_FREQ_OK 60 * 1000 /* How often to check for the host to be up */ -#define DEFAULT_FREQ_NOTOK 10 * 1000 /* How often to check, if the host is down... */ - -#define DEFAULT_RETRANS 2000 /* How frequently to retransmit */ -#define MAX_RETRANS 5 /* Try only 5 times for retransmissions */ - - -#define DEBUG_READ 0 /* Recieved data */ -#define DEBUG_SEND 1 /* Transmit data */ +#define DEBUG_READ 0 /* Recieved data */ +#define DEBUG_SEND 1 /* Transmit data */ static const char desc[] = "Session Initiation Protocol (SIP)"; static const char channeltype[] = "SIP"; static const char config[] = "sip.conf"; static const char notify_config[] = "sip_notify.conf"; -#define RTP 1 -#define NO_RTP 0 +#define RTP 1 +#define NO_RTP 0 /* 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 @@ -158,22 +155,22 @@ int need_rtp; /* when this is the 'primary' use for a pvt structure, does it need RTP? */ char * const text; } 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_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" } + { 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" } }; /* Structure for conversion between compressed SIP and "normal" SIP */ @@ -181,20 +178,24 @@ 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" }, + { "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" }, + { "Session-Expires", "x" }, }; /* Define SIP option tags, used in Require: and Supported: headers */ @@ -207,23 +208,23 @@ 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 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) +#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) /* List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly. */ @@ -232,45 +233,30 @@ 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" }, - /* Not yet RFC, but registred with IANA */ - { 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" }, + { SIP_OPT_REPLACES, SUPPORTED, "replaces" }, /* Replaces: header for transfer */ + { SIP_OPT_100REL, NOT_SUPPORTED, "100rel" }, /* RFC3262: PRACK 100% reliability */ + { SIP_OPT_TIMER, NOT_SUPPORTED, "timer" }, /* SIP Session Timers */ + { SIP_OPT_EARLY_SESSION, NOT_SUPPORTED, "early-session" }, /* RFC3959: SIP Early session support */ + { SIP_OPT_JOIN, NOT_SUPPORTED, "join" }, /* SIP Join header support */ + { SIP_OPT_PATH, NOT_SUPPORTED, "path" }, /* RFC3327: Path support */ + { SIP_OPT_PREF, NOT_SUPPORTED, "pref" }, /* RFC3840: Callee preferences */ + { SIP_OPT_PRECONDITION, NOT_SUPPORTED, "precondition" }, /* RFC3312: Precondition support */ + { SIP_OPT_PRIVACY, NOT_SUPPORTED, "privacy" }, /* RFC3323: Privacy with proxies*/ + { SIP_OPT_SDP_ANAT, NOT_SUPPORTED, "sdp_anat" }, /* Not yet RFC, but registred with IANA */ + { SIP_OPT_SEC_AGREE, NOT_SUPPORTED, "sec_agree" }, /* RFC3329: Security agreement mechanism */ + { SIP_OPT_EVENTLIST, NOT_SUPPORTED, "eventlist" }, /* SIMPLE events: draft-ietf-simple-event-list-07.txt */ + { SIP_OPT_GRUU, NOT_SUPPORTED, "gruu" }, /* GRUU: Globally Routable User Agent URI's */ + { SIP_OPT_TARGET_DIALOG, NOT_SUPPORTED, "target-dialog" }, /* Target-dialog: draft-ietf-sip-target-dialog-00.txt */ }; - /* SIP Methods we support */ #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, NOTIFY" /* SIP Extensions we support */ #define SUPPORTED_EXTENSIONS "replaces" -#define DEFAULT_SIP_PORT 5060 /* From RFC 3261 (former 2543) */ -#define SIP_MAX_PACKET 4096 /* Also from RFC 3261 (2543), should sub headers tho */ +#define DEFAULT_SIP_PORT 5060 /* From RFC 3261 (former 2543) */ +#define SIP_MAX_PACKET 4096 /* Also from RFC 3261 (2543), should sub headers tho */ static char default_useragent[AST_MAX_EXTENSION] = DEFAULT_USERAGENT; @@ -287,17 +273,16 @@ #define DEFAULT_NOTIFYMIME "application/simple-message-summary" static char default_notifymime[AST_MAX_EXTENSION] = DEFAULT_NOTIFYMIME; +static int default_qualify = 0; /* Default Qualify= setting */ -static int default_qualify = 0; /* Default Qualify= setting */ - -static struct ast_flags global_flags = {0}; /* global SIP_ flags */ -static struct ast_flags global_flags_page2 = {0}; /* more global SIP_ flags */ +static struct ast_flags global_flags = {0}; /* global SIP_ flags */ +static struct ast_flags global_flags_page2 = {0}; /* more global SIP_ flags */ -static int srvlookup = 0; /* SRV Lookup on or off. Default is off, RFC behavior is on */ +static int srvlookup = 0; /* SRV Lookup on or off. Default is off, RFC behavior is on */ -static int pedanticsipchecking = 0; /* Extra checking ? Default off */ +static int pedanticsipchecking = 0; /* Extra checking ? Default off */ -static int autocreatepeer = 0; /* Auto creation of peers at registration? Default off. */ +static int autocreatepeer = 0; /* Auto creation of peers at registration? Default off. */ static int relaxdtmf = 0; @@ -318,15 +303,14 @@ static int apeerobjs = 0; static int regobjs = 0; -static int global_allowguest = 1; /* allow unauthenticated users/peers to connect? */ +static int global_allowguest = 1; /* allow unauthenticated users/peers to connect? */ #define DEFAULT_MWITIME 10 -static int global_mwitime = DEFAULT_MWITIME; /* Time between MWI checks for peers */ +static int global_mwitime = DEFAULT_MWITIME; /* Time between MWI checks for peers */ static int usecnt =0; AST_MUTEX_DEFINE_STATIC(usecnt_lock); - /* Protect the interface list (of sip_pvt's) */ AST_MUTEX_DEFINE_STATIC(iflock); @@ -357,14 +341,14 @@ static int videosupport = 0; -static int compactheaders = 0; /* send compact sip headers */ +static int compactheaders = 0; /* send compact sip headers */ -static int recordhistory = 0; /* Record SIP history. Off by default */ +static int recordhistory = 0; /* Record SIP history. Off by default */ -static char global_musicclass[MAX_MUSICCLASS] = ""; /* Global music on hold class */ -#define DEFAULT_REALM "asterisk" -static char global_realm[MAXHOSTNAMELEN] = DEFAULT_REALM; /* Default realm */ -static char regcontext[AST_MAX_CONTEXT] = ""; /* Context for auto-extensions */ +static char global_musicclass[MAX_MUSICCLASS] = ""; /* Global music on hold class */ +#define DEFAULT_REALM "asterisk" +static char global_realm[MAXHOSTNAMELEN] = DEFAULT_REALM; /* Default realm */ +static char regcontext[AST_MAX_CONTEXT] = ""; /* Context for auto-extensions */ /* Expire slowly */ #define DEFAULT_EXPIRY 900 @@ -375,8 +359,8 @@ /* The private structures of the sip channels are linked for selecting outgoing channels */ -#define SIP_MAX_HEADERS 64 -#define SIP_MAX_LINES 64 +#define SIP_MAX_HEADERS 64 +#define SIP_MAX_LINES 64 #define DEC_IN_USE 0 #define INC_IN_USE 1 @@ -385,19 +369,18 @@ static struct ast_codec_pref prefs; - /* sip_request: The data grabbed from the UDP socket */ struct sip_request { - 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 *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 *header[SIP_MAX_HEADERS]; - int lines; /* SDP Content */ + int lines; /* SDP Content */ char *line[SIP_MAX_LINES]; char data[SIP_MAX_PACKET]; - int debug; /* Debug flag for this packet */ + int debug; /* Debug flag for this packet */ }; struct sip_pkt; @@ -432,165 +415,165 @@ struct sip_auth *next; /* Next auth structure in list */ }; -#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? */ -#define SIP_SELFDESTRUCT (1 << 14) -#define SIP_DYNAMIC (1 << 15) /* Is this a dynamic peer? */ +#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? */ +#define SIP_SELFDESTRUCT (1 << 14) +#define SIP_DYNAMIC (1 << 15) /* Is this a dynamic peer? */ /* --- Choices for DTMF support in SIP channel */ -#define SIP_DTMF (3 << 16) /* three settings, uses two bits */ -#define SIP_DTMF_RFC2833 (0 << 16) /* RTP DTMF */ -#define SIP_DTMF_INBAND (1 << 16) /* Inband audio, only for ULAW/ALAW */ -#define SIP_DTMF_INFO (2 << 16) /* SIP Info messages */ +#define SIP_DTMF (3 << 16) /* three settings, uses two bits */ +#define SIP_DTMF_RFC2833 (0 << 16) /* RTP DTMF */ +#define SIP_DTMF_INBAND (1 << 16) /* Inband audio, only for ULAW/ALAW */ +#define SIP_DTMF_INFO (2 << 16) /* SIP Info messages */ /* NAT settings */ -#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) -#define SIP_NAT_ROUTE (2 << 18) -#define SIP_NAT_ALWAYS (3 << 18) +#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) +#define SIP_NAT_ROUTE (2 << 18) +#define SIP_NAT_ALWAYS (3 << 18) /* 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_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 */ /* "insecure" settings */ -#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 */ +#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_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) /* Open Settlement Protocol authentication */ -#define SIP_OSPAUTH (3 << 26) /* three settings, uses two bits */ -#define SIP_OSPAUTH_NO (0 << 26) -#define SIP_OSPAUTH_YES (1 << 26) -#define SIP_OSPAUTH_EXCLUSIVE (2 << 26) +#define SIP_OSPAUTH (3 << 26) /* three settings, uses two bits */ +#define SIP_OSPAUTH_NO (0 << 26) +#define SIP_OSPAUTH_YES (1 << 26) +#define SIP_OSPAUTH_EXCLUSIVE (2 << 26) /* Call states */ -#define SIP_CALL_ONHOLD (1 << 28) -#define SIP_CALL_LIMIT (1 << 29) +#define SIP_CALL_ONHOLD (1 << 28) +#define SIP_CALL_LIMIT (1 << 29) /* a new page of flags for peer */ -#define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) -#define SIP_PAGE2_RTNOUPDATE (1 << 1) -#define SIP_PAGE2_RTAUTOCLEAR (1 << 2) -#define SIP_PAGE2_RTIGNOREREGEXPIRE (1 << 3) +#define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) +#define SIP_PAGE2_RTNOUPDATE (1 << 1) +#define SIP_PAGE2_RTAUTOCLEAR (1 << 2) +#define SIP_PAGE2_RTIGNOREREGEXPIRE (1 << 3) static int global_rtautoclear = 120; /* sip_pvt: PVT structures are used for each SIP conversation, ie. a call */ static struct sip_pvt { - ast_mutex_t lock; /* Channel private lock */ - int method; /* SIP method of this packet */ - char callid[80]; /* Global CallID */ - char randdata[80]; /* Random data */ - 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 */ - unsigned int flags; /* SIP_ flags */ - 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) */ + ast_mutex_t lock; /* Channel private lock */ + int method; /* SIP method of this packet */ + char callid[80]; /* Global CallID */ + char randdata[80]; /* Random data */ + 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 */ + unsigned int flags; /* SIP_ flags */ + 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 noncodeccapability; - int callingpres; /* Calling presentation */ - int authtries; /* Times we've tried to authenticate */ - int expiry; /* How long we take to expire */ - int branch; /* One random number */ - int tag; /* 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 */ - char exten[AST_MAX_EXTENSION]; /* Extension where to start */ - char refer_to[AST_MAX_EXTENSION]; /* Place to store REFER-TO extension */ - char referred_by[AST_MAX_EXTENSION]; /* Place to store REFERRED-BY extension */ - char refer_contact[AST_MAX_EXTENSION]; /* Place to store Contact info from a REFER extension */ - 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? */ - char from[256]; /* The From: header */ - char useragent[256]; /* User agent in SIP request */ - char context[AST_MAX_CONTEXT]; /* Context for this call */ - char fromdomain[MAXHOSTNAMELEN]; /* Domain to show in the from field */ - char fromuser[AST_MAX_EXTENSION]; /* User to show in the user field */ - char fromname[AST_MAX_EXTENSION]; /* Name to show in the user field */ - char tohost[MAXHOSTNAMELEN]; /* Host we should put in the "to" field */ - char language[MAX_LANGUAGE]; /* Default language for this call */ - char musicclass[MAX_MUSICCLASS]; /* Music on Hold class */ - char rdnis[256]; /* Referring DNIS */ - char theirtag[256]; /* Their tag */ - char username[256]; /* [user] name */ - char peername[256]; /* [peer] name, not set if [user] */ - char authname[256]; /* Who we use for authentication */ - char uri[256]; /* Original requested URI */ - char okcontacturi[256]; /* URI from the 200 OK on INVITE */ - char peersecret[256]; /* Password */ + int callingpres; /* Calling presentation */ + int authtries; /* Times we've tried to authenticate */ + int expiry; /* How long we take to expire */ + int branch; /* One random number */ + int tag; /* 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 */ + char exten[AST_MAX_EXTENSION]; /* Extension where to start */ + char refer_to[AST_MAX_EXTENSION]; /* Place to store REFER-TO extension */ + char referred_by[AST_MAX_EXTENSION]; /* Place to store REFERRED-BY extension */ + char refer_contact[AST_MAX_EXTENSION]; /* Place to store Contact info from a REFER extension */ + 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? */ + char from[256]; /* The From: header */ + char useragent[256]; /* User agent in SIP request */ + char context[AST_MAX_CONTEXT]; /* Context for this call */ + char fromdomain[MAXHOSTNAMELEN]; /* Domain to show in the from field */ + char fromuser[AST_MAX_EXTENSION]; /* User to show in the user field */ + char fromname[AST_MAX_EXTENSION]; /* Name to show in the user field */ + char tohost[MAXHOSTNAMELEN]; /* Host we should put in the "to" field */ + char language[MAX_LANGUAGE]; /* Default language for this call */ + char musicclass[MAX_MUSICCLASS]; /* Music on Hold class */ + char rdnis[256]; /* Referring DNIS */ + char theirtag[256]; /* Their tag */ + char username[256]; /* [user] name */ + char peername[256]; /* [peer] name, not set if [user] */ + char authname[256]; /* Who we use for authentication */ + char uri[256]; /* Original requested URI */ + char okcontacturi[256]; /* URI from the 200 OK on INVITE */ + char peersecret[256]; /* Password */ char peermd5secret[256]; - struct sip_auth *peerauth; /* Realm authentication */ - char cid_num[256]; /* Caller*ID */ - char cid_name[256]; /* Caller*ID */ - char via[256]; /* Via: header */ - char fullcontact[128]; /* The Contact: that the UA registers with us */ + struct sip_auth *peerauth; /* Realm authentication */ + char cid_num[256]; /* Caller*ID */ + char cid_name[256]; /* Caller*ID */ + char via[256]; /* Via: header */ + char fullcontact[128]; /* The Contact: that the UA registers with us */ char accountcode[AST_MAX_ACCOUNT_CODE]; /* Account code */ - char our_contact[256]; /* Our contact header */ - char realm[MAXHOSTNAMELEN]; /* Authorization realm */ - char nonce[256]; /* Authorization nonce */ - char opaque[256]; /* Opaque nonsense */ - char qop[80]; /* Quality of Protection, since SIP wasn't complicated enough yet. */ - char domain[MAXHOSTNAMELEN]; /* Authorization domain */ - char lastmsg[256]; /* Last Message sent/received */ - int amaflags; /* AMA Flags */ - int pendinginvite; /* Any pending invite */ + char our_contact[256]; /* Our contact header */ + char realm[MAXHOSTNAMELEN]; /* Authorization realm */ + char nonce[256]; /* Authorization nonce */ + char opaque[256]; /* Opaque nonsense */ + char qop[80]; /* Quality of Protection, since SIP wasn't complicated enough yet. */ + char domain[MAXHOSTNAMELEN]; /* Authorization domain */ + char lastmsg[256]; /* Last Message sent/received */ + int amaflags; /* AMA Flags */ + int pendinginvite; /* Any pending invite */ #ifdef OSP_SUPPORT - int osphandle; /* OSP Handle for call */ - time_t ospstart; /* OSP Start time */ + int osphandle; /* OSP Handle for call */ + time_t ospstart; /* OSP Start time */ #endif - struct sip_request initreq; /* Initial request */ + struct sip_request initreq; /* Initial request */ - int maxtime; /* Max time for first response */ - int maxforwards; /* keep the max-forwards info */ - 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 */ + int maxtime; /* Max time for first response */ + int maxforwards; /* keep the max-forwards info */ + 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 */ - int subscribed; /* Is this call a subscription? */ + int subscribed; /* Is this call a subscription? */ int stateid; int dialogver; - struct ast_dsp *vad; /* Voice Activation Detection dsp */ + struct ast_dsp *vad; /* Voice Activation Detection dsp */ - struct sip_peer *peerpoke; /* If this calls is to poke a peer, which one */ - struct sip_registry *registry; /* If this is a REGISTER call, 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 */ - struct sip_history *history; /* History of this SIP dialog */ - struct ast_variable *chanvars; /* Channel variables to set for call */ - struct sip_pvt *next; /* Next call in chain */ + struct sip_peer *peerpoke; /* If this calls is to poke a peer, which one */ + struct sip_registry *registry; /* If this is a REGISTER call, 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 */ + struct sip_history *history; /* History of this SIP dialog */ + struct ast_variable *chanvars; /* Channel variables to set for call */ + struct sip_pvt *next; /* Next call in chain */ } *iflist = NULL; #define FLAG_RESPONSE (1 << 0) @@ -598,14 +581,14 @@ /* sip packet - read in sipsock_read, transmitted in send_request */ struct sip_pkt { - 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) */ - struct sip_pvt *owner; /* Owner call */ - int retransid; /* Retransmission ID */ - int packetlen; /* Length of packet */ + 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) */ + struct sip_pvt *owner; /* Owner call */ + int retransid; /* Retransmission ID */ + int packetlen; /* Length of packet */ char data[0]; }; @@ -613,87 +596,87 @@ struct sip_user { /* Users who can access various contexts */ 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 */ - char cid_num[80]; /* Caller ID num */ - char cid_name[80]; /* Caller ID name */ + char secret[80]; /* Password */ + char md5secret[80]; /* Password in md5 */ + char context[AST_MAX_CONTEXT]; /* Default context for incoming calls */ + 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 flags; /* SIP flags */ - unsigned int sipoptions; /* Supported SIP options */ - struct ast_flags flags_page2; /* SIP_PAGE2 flags */ - int amaflags; /* AMA flags for billing */ - int callingpres; /* Calling id presentation */ - int capability; /* Codec capability */ - int inUse; /* Number of calls in use */ - int incominglimit; /* Limit of incoming calls */ - int outUse; /* disabled */ - int outgoinglimit; /* disabled */ - struct ast_ha *ha; /* ACL setting */ - struct ast_variable *chanvars; /* Variables to set for channel created by user */ + 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 flags; /* SIP flags */ + unsigned int sipoptions; /* Supported SIP options */ + struct ast_flags flags_page2; /* SIP_PAGE2 flags */ + int amaflags; /* AMA flags for billing */ + int callingpres; /* Calling id presentation */ + int capability; /* Codec capability */ + int inUse; /* Number of calls in use */ + int incominglimit; /* Limit of incoming calls */ + int outUse; /* disabled */ + int outgoinglimit; /* disabled */ + struct ast_ha *ha; /* ACL setting */ + struct ast_variable *chanvars; /* Variables to set for channel created by user */ }; /* Structure for SIP peer data, we place calls to peers if registred or fixed IP address (host) */ struct sip_peer { - 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 username[80]; /* Temporary username until registration */ + 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 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 registred 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 incominglimit; /* Limit of incoming calls */ - int outUse; /* disabled */ - int outgoinglimit; /* disabled */ - 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 */ + 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 registred 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 incominglimit; /* Limit of incoming calls */ + int outUse; /* disabled */ + int outgoinglimit; /* disabled */ + 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 */ int lastmsgssent; - time_t lastmsgcheck; /* Last time we checked for MWI */ - unsigned int flags; /* SIP flags */ - unsigned int sipoptions; /* Supported SIP options */ - struct ast_flags flags_page2; /* SIP_PAGE2 flags */ - int expire; /* When to expire this peer registration */ - int expiry; /* Duration of 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 */ + time_t lastmsgcheck; /* Last time we checked for MWI */ + unsigned int flags; /* SIP flags */ + unsigned int sipoptions; /* Supported SIP options */ + struct ast_flags flags_page2; /* SIP_PAGE2 flags */ + int expire; /* When to expire this peer registration */ + int expiry; /* Duration of 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 */ struct in_addr mask; /* Qualification */ - 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 */ + 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 */ int lastmsg; }; @@ -701,46 +684,45 @@ static int sip_reloading = 0; /* States for outbound registrations (with register= lines in sip.conf */ -#define REG_STATE_UNREGISTERED 0 -#define REG_STATE_REGSENT 1 -#define REG_STATE_AUTHSENT 2 -#define REG_STATE_REGISTERED 3 -#define REG_STATE_REJECTED 4 -#define REG_STATE_TIMEOUT 5 -#define REG_STATE_NOAUTH 6 -#define REG_STATE_FAILED 7 - +#define REG_STATE_UNREGISTERED 0 +#define REG_STATE_REGSENT 1 +#define REG_STATE_AUTHSENT 2 +#define REG_STATE_REGISTERED 3 +#define REG_STATE_REJECTED 4 +#define REG_STATE_TIMEOUT 5 +#define REG_STATE_NOAUTH 6 +#define REG_STATE_FAILED 7 /* sip_registry: Registrations with other SIP proxies */ struct sip_registry { ASTOBJ_COMPONENTS_FULL(struct sip_registry,1,1); - int portno; /* Optional port override */ - char username[80]; /* Who we are registering as */ - char authuser[80]; /* Who we *authenticate* as */ - char hostname[MAXHOSTNAMELEN]; /* Domain or host we register to */ - char secret[80]; /* Password or key name in []'s */ + int portno; /* Optional port override */ + char username[80]; /* Who we are registering as */ + char authuser[80]; /* Who we *authenticate* as */ + char hostname[MAXHOSTNAMELEN]; /* Domain or host we register to */ + char secret[80]; /* Password or key name in []'s */ char md5secret[80]; - char contact[256]; /* Contact extension */ + char contact[256]; /* Contact extension */ char random[80]; - 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 */ - struct sip_pvt *call; /* create a sip_pvt structure for each outbound "registration call" in progress */ - int regstate; /* Registration state (see above) */ - int callid_valid; /* 0 means we haven't chosen callid for this registry yet. */ - char callid[80]; /* Global CallID for this registry */ - unsigned int ocseq; /* Sequence number we got to for REGISTERs for this registry */ - struct sockaddr_in us; /* Who the server thinks we are */ + 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 */ + struct sip_pvt *call; /* create a sip_pvt structure for each outbound "registration call" in progress */ + int regstate; /* Registration state (see above) */ + int callid_valid; /* 0 means we haven't chosen callid for this registry yet. */ + char callid[80]; /* Global CallID for this registry */ + unsigned int ocseq; /* Sequence number we got to for REGISTERs for this registry */ + struct sockaddr_in us; /* Who the server thinks we are */ - /* Saved headers */ - char realm[MAXHOSTNAMELEN]; /* Authorization realm */ - char nonce[256]; /* Authorization nonce */ - char domain[MAXHOSTNAMELEN]; /* Authorization domain */ - char opaque[256]; /* Opaque nonsense */ - char qop[80]; /* Quality of Protection. */ - - char lastmsg[256]; /* Last Message sent/received */ + /* Saved headers */ + char realm[MAXHOSTNAMELEN]; /* Authorization realm */ + char nonce[256]; /* Authorization nonce */ + char domain[MAXHOSTNAMELEN]; /* Authorization domain */ + char opaque[256]; /* Opaque nonsense */ + char qop[80]; /* Quality of Protection. */ + + char lastmsg[256]; /* Last Message sent/received */ }; /*--- The user list: Users and friends ---*/ @@ -759,11 +741,7 @@ int recheck; } regl; - -static int __sip_do_register(struct sip_registry *r); - -static int sipsock = -1; - +static int sipsock = -1; static struct sockaddr_in bindaddr; static struct sockaddr_in externip; @@ -771,13 +749,15 @@ static time_t externexpire = 0; static int externrefresh = 10; static struct ast_ha *localaddr; +static int callevents = 0; /* The list of manual NOTIFY types we know how to send */ struct ast_config *notify_types; -static struct sip_auth *authl; /* Authentication list */ - +static struct sip_auth *authl; /* Authentication list */ +/* forward declarations */ +static int __sip_do_register(struct sip_registry *r); static struct ast_frame *sip_read(struct ast_channel *ast); 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, int retrans); @@ -800,8 +780,6 @@ static struct sip_user *build_user(const char *name, struct ast_variable *v, int realtime); static int sip_do_reload(void); static int expire_register(void *data); -static int callevents = 0; - 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); @@ -814,11 +792,20 @@ 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, char *realm); /* Find authentication for a specific realm */ -static void append_date(struct sip_request *req); /* Append date to SIP packet */ +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, char *realm); /* Find authentication for a specific realm */ +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_destroy(struct sip_pvt *p); +static void parse_request(struct sip_request *req); +static char *get_header(struct sip_request *req, 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, int fatal); +static int sip_poke_peer(struct sip_peer *peer); +static int _sip_show_peer(int type, int fd, struct mansession *s, struct message *m, int argc, char *argv[]); +static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[]); +static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len); /* Definition of this channel for channel registration */ static const struct ast_channel_tech sip_tech = { @@ -927,7 +914,6 @@ return sip_debug_test_addr(((ast_test_flag(p, SIP_NAT) & SIP_NAT_ROUTE) ? &p->recv : &p->sa)); } - /*--- __sip_xmit: Transmit SIP message ---*/ static int __sip_xmit(struct sip_pvt *p, char *data, int len) { @@ -944,8 +930,6 @@ return res; } -static void sip_destroy(struct sip_pvt *p); - /*--- build_via: Build a Via header for a request ---*/ static void build_via(struct sip_pvt *p, char *buf, int len) { @@ -958,7 +942,7 @@ snprintf(buf, len, "SIP/2.0/UDP %s:%d;branch=z9hG4bK%08x", ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip), ourport, p->branch); } -/*--- ast_sip_ouraddrfor: NAT fix - decide which IP address to use for ASterisk server? ---*/ +/*--- ast_sip_ouraddrfor: NAT fix - decide which IP address to use for Asterisk server? ---*/ /* Only used for outbound registrations */ static int ast_sip_ouraddrfor(struct in_addr *them, struct in_addr *us) { @@ -1002,7 +986,7 @@ if (!recordhistory) return 0; - if(!(hist = malloc(sizeof(struct sip_history)))) { + if (!(hist = malloc(sizeof(struct sip_history)))) { ast_log(LOG_WARNING, "Can't allocate memory for history"); return 0; } @@ -1010,7 +994,7 @@ snprintf(hist->event, sizeof(hist->event), "%-15s %s", event, data); /* Trim up nicely */ c = hist->event; - while(*c) { + while (*c) { if ((*c == '\r') || (*c == '\n')) { *c = '\0'; break; @@ -1020,7 +1004,7 @@ /* Enqueue into history */ prev = p->history; if (prev) { - while(prev->next) + while (prev->next) prev = prev->next; prev->next = hist; } else { @@ -1052,7 +1036,7 @@ append_history(pkt->owner, "MaxRetries", (ast_test_flag(pkt, FLAG_FATAL)) ? "(Critical)" : "(Non-critical)"); pkt->retransid = -1; if (ast_test_flag(pkt, FLAG_FATAL)) { - while(pkt->owner->owner && ast_mutex_trylock(&pkt->owner->owner->lock)) { + while (pkt->owner->owner && ast_mutex_trylock(&pkt->owner->owner->lock)) { ast_mutex_unlock(&pkt->owner->lock); usleep(1); ast_mutex_lock(&pkt->owner->lock); @@ -1069,7 +1053,7 @@ /* In any case, go ahead and remove the packet */ prev = NULL; cur = pkt->owner->packets; - while(cur) { + while (cur) { if (cur == pkt) break; prev = cur; @@ -1177,10 +1161,10 @@ msg = sip_methods[sipmethod].text; cur = p->packets; - while(cur) { + while (cur) { if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) && - ((ast_test_flag(cur, FLAG_RESPONSE)) || - (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { + ((ast_test_flag(cur, FLAG_RESPONSE)) || + (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { if (!resp && (seqno == p->pendinginvite)) { ast_log(LOG_DEBUG, "Acked pending invite %d\n", p->pendinginvite); p->pendinginvite = 0; @@ -1210,7 +1194,7 @@ char method[128]=""; struct sip_pkt *cur=NULL; char *c; - while(p->packets) { + while (p->packets) { if (cur == p->packets) { ast_log(LOG_WARNING, "Have a packet that doesn't want to give up!\n"); return -1; @@ -1232,10 +1216,10 @@ char *msg = sip_methods[sipmethod].text; cur = p->packets; - while(cur) { + while (cur) { if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) && - ((ast_test_flag(cur, FLAG_RESPONSE)) || - (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { + ((ast_test_flag(cur, FLAG_RESPONSE)) || + (!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) { /* this is our baby */ if (cur->retransid > -1) ast_sched_del(sched, cur->retransid); @@ -1249,10 +1233,6 @@ return res; } -static void parse_request(struct sip_request *req); -static char *get_header(struct sip_request *req, char *name); -static void copy_request(struct sip_request *dst,struct sip_request *src); - /*--- parse_copy: Copy SIP request, parse it */ static void parse_copy(struct sip_request *dst, struct sip_request *src) { @@ -1407,16 +1387,16 @@ } /*--- realtime_update_peer: Update peer object in realtime storage ---*/ -static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, int expirey) +static void realtime_update_peer(const char *peername, struct sockaddr_in *sin, const char *username, int expiry) { char port[10] = ""; char ipaddr[20] = ""; char regseconds[20] = "0"; - if (expirey) { /* Registration */ + if (expiry) { /* Registration */ time_t nowtime; time(&nowtime); - nowtime += expirey; + nowtime += expiry; snprintf(regseconds, sizeof(regseconds), "%ld", nowtime); /* Expiration time */ ast_inet_ntoa(ipaddr, sizeof(ipaddr), sin->sin_addr); snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port)); @@ -1432,7 +1412,7 @@ if (!ast_strlen_zero(regcontext)) { ast_copy_string(multi, ast_strlen_zero(peer->regexten) ? peer->name : peer->regexten, sizeof(multi)); stringp = multi; - while((ext = strsep(&stringp, "&"))) { + while ((ext = strsep(&stringp, "&"))) { if (onoff) ast_add_extension(regcontext, 1, ext, 1, NULL, NULL, "Noop", strdup(peer->name), free, channeltype); else @@ -1480,7 +1460,6 @@ } } - /*--- realtime_peer: Get peer from realtime storage ---*/ /* Checks the "sippeers" realtime family from extconfig.conf */ static struct sip_peer *realtime_peer(const char *peername, struct sockaddr_in *sin) @@ -1505,7 +1484,7 @@ tmp = var; /* If this is type=user, then skip this object. */ - while(tmp) { + while (tmp) { if (!strcasecmp(tmp->name, "type") && !strcasecmp(tmp->value, "user")) { ast_variables_destroy(var); @@ -1613,8 +1592,6 @@ } tmp = tmp->next; } - - user = build_user(username, var, !ast_test_flag((&global_flags_page2), SIP_PAGE2_RTCACHEFRIENDS)); @@ -1672,9 +1649,8 @@ return -1; } - ast_copy_flags(r, peer, - SIP_PROMISCREDIR | SIP_USEREQPHONE | SIP_DTMF | SIP_NAT | SIP_REINVITE | - SIP_INSECURE_PORT | SIP_INSECURE_INVITE); + ast_copy_flags(r, peer, SIP_PROMISCREDIR | SIP_USEREQPHONE | SIP_DTMF | SIP_NAT | + SIP_REINVITE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE); r->capability = peer->capability; if (r->rtp) { ast_log(LOG_DEBUG, "Setting NAT on RTP to %d\n", (ast_test_flag(r, SIP_NAT) & SIP_NAT_ROUTE)); @@ -1803,9 +1779,6 @@ return 0; } - - - /*--- sip_call: Initiate SIP call from PBX ---*/ /* used from the dial() application */ static int sip_call(struct ast_channel *ast, char *dest, int timeout) @@ -1828,7 +1801,7 @@ } /* Check whether there is vxml_url, distinctive ring variables */ - headp=&ast->varshead; + headp = &ast->varshead; AST_LIST_TRAVERSE(headp,current,entries) { /* Check whether there is a VXML_URL variable */ if (!options.vxml_url && !strcasecmp(ast_var_name(current),"VXML_URL")) { @@ -1841,7 +1814,6 @@ options.addsipheaders = 1; } - #ifdef OSP_SUPPORT else if (!options.osptoken && !strcasecmp(ast_var_name(current), "OSPTOKEN")) { options.osptoken = ast_var_value(current); @@ -1937,13 +1909,13 @@ ast_mutex_unlock(&p->owner->lock); } /* Clear history */ - while(p->history) { + while (p->history) { hist = p->history; p->history = p->history->next; free(hist); } cur = iflist; - while(cur) { + while (cur) { if (cur == p) { if (prev) prev->next = cur->next; @@ -1960,7 +1932,7 @@ } if (p->initid > -1) ast_sched_del(sched, p->initid); - while((cp = p->packets)) { + while ((cp = p->packets)) { p->packets = p->packets->next; if (cp->retransid > -1) ast_sched_del(sched, cp->retransid); @@ -2010,60 +1982,58 @@ return 0; } } - switch(event) { - /* incoming and outgoing affects the inUse counter */ - case DEC_OUT_USE: - case DEC_IN_USE: - if ( *inuse > 0 ) { - (*inuse)--; - } else { - *inuse = 0; - } - break; - case INC_IN_USE: - case INC_OUT_USE: - if (*incominglimit > 0 ) { - if (*inuse >= *incominglimit) { - ast_log(LOG_ERROR, "Call from %s '%s' rejected due to usage limit of %d\n", u?"user":"peer", name, *incominglimit); - /* inc inUse as well */ - if ( event == INC_OUT_USE ) { - (*inuse)++; - } - if (u) - ASTOBJ_UNREF(u,sip_destroy_user); - else - ASTOBJ_UNREF(p,sip_destroy_peer); - return -1; + switch (event) { /* incoming and outgoing affects the inUse counter */ + case DEC_OUT_USE: + case DEC_IN_USE: + if (*inuse > 0) { + (*inuse)--; + } else { + *inuse = 0; + } + break; + case INC_IN_USE: + case INC_OUT_USE: + if (*incominglimit > 0 ) { + if (*inuse >= *incominglimit) { + ast_log(LOG_ERROR, "Call from %s '%s' rejected due to usage limit of %d\n", u?"user":"peer", name, *incominglimit); + /* inc inUse as well */ + if (event == INC_OUT_USE) + (*inuse)++; + if (u) { + ASTOBJ_UNREF(u,sip_destroy_user); + } else { + ASTOBJ_UNREF(p,sip_destroy_peer); } + return -1; } - (*inuse)++; - ast_log(LOG_DEBUG, "Call from %s '%s' is %d out of %d\n", u?"user":"peer", name, *inuse, *incominglimit); - break; + } + (*inuse)++; + ast_log(LOG_DEBUG, "Call from %s '%s' is %d out of %d\n", u?"user":"peer", name, *inuse, *incominglimit); + break; #ifdef DISABLED_CODE /* we don't use these anymore */ - case DEC_OUT_USE: - if ( u->outUse > 0 ) { - u->outUse--; - } else { - u->outUse = 0; - } - break; - case INC_OUT_USE: - if ( u->outgoinglimit > 0 ) { - if ( u->outUse >= u->outgoinglimit ) { - ast_log(LOG_ERROR, "Outgoing call from user '%s' rejected due to usage limit of %d\n", u->name, u->outgoinglimit); - ast_mutex_unlock(&userl.lock); - if (u->temponly) { - destroy_user(u); - } - return -1; - } + case DEC_OUT_USE: + if (u->outUse > 0) { + u->outUse--; + } else { + u->outUse = 0; + } + break; + case INC_OUT_USE: + if ( u->outgoinglimit > 0 ) { + if ( u->outUse >= u->outgoinglimit ) { + ast_log(LOG_ERROR, "Outgoing call from user '%s' rejected due to usage limit of %d\n", u->name, u->outgoinglimit); + ast_mutex_unlock(&userl.lock); + if (u->temponly) + destroy_user(u); + return -1; } - u->outUse++; - break; + } + u->outUse++; + break; #endif - default: - ast_log(LOG_ERROR, "update_user_counter(%s,%d) called with no event!\n",name,event); + default: + ast_log(LOG_ERROR, "update_user_counter(%s,%d) called with no event!\n",name,event); } if (u) ASTOBJ_UNREF(u,sip_destroy_user); @@ -2080,45 +2050,41 @@ ast_mutex_unlock(&iflock); } - -static int transmit_response_reliable(struct sip_pvt *p, char *msg, struct sip_request *req, int fatal); - /*--- hangup_sip2cause: Convert SIP hangup causes to Asterisk hangup causes ---*/ static int hangup_sip2cause(int cause) { /* Possible values taken from causes.h */ - switch(cause) { - case 403: /* Not found */ - return AST_CAUSE_CALL_REJECTED; - case 404: /* Not found */ - return AST_CAUSE_UNALLOCATED; - case 408: /* No reaction */ - return AST_CAUSE_NO_USER_RESPONSE; - case 480: /* No answer */ - return AST_CAUSE_FAILURE; - case 483: /* Too many hops */ - return AST_CAUSE_NO_ANSWER; - case 486: /* Busy everywhere */ - return AST_CAUSE_BUSY; - case 488: /* No codecs approved */ - return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; - case 500: /* Server internal failure */ - return AST_CAUSE_FAILURE; - case 501: /* Call rejected */ - return AST_CAUSE_FACILITY_REJECTED; - case 502: - return AST_CAUSE_DESTINATION_OUT_OF_ORDER; - case 503: /* Service unavailable */ - return AST_CAUSE_CONGESTION; - default: - return AST_CAUSE_NORMAL; + switch (cause) { + case 403: /* Not found */ + return AST_CAUSE_CALL_REJECTED; + case 404: /* Not found */ + return AST_CAUSE_UNALLOCATED; + case 408: /* No reaction */ + return AST_CAUSE_NO_USER_RESPONSE; + case 480: /* No answer */ + return AST_CAUSE_FAILURE; + case 483: /* Too many hops */ + return AST_CAUSE_NO_ANSWER; + case 486: /* Busy everywhere */ + return AST_CAUSE_BUSY; + case 488: /* No codecs approved */ + return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; + case 500: /* Server internal failure */ + return AST_CAUSE_FAILURE; + case 501: /* Call rejected */ + return AST_CAUSE_FACILITY_REJECTED; + case 502: + return AST_CAUSE_DESTINATION_OUT_OF_ORDER; + case 503: /* Service unavailable */ + return AST_CAUSE_CONGESTION; + default: + return AST_CAUSE_NORMAL; } /* Never reached */ return 0; } - /*--- hangup_cause2sip: Convert Asterisk hangup causes to SIP codes ---*/ /* Possible values from causes.h AST_CAUSE_NOTDEFINED AST_CAUSE_NORMAL AST_CAUSE_BUSY @@ -2147,56 +2113,53 @@ 27 destination out of order 502 Bad Gateway 28 address incomplete 484 Address incomplete 29 facility rejected 501 Not implemented - 31 normal unspecified 480 Temporarily unavailable + 31 normal unspecified 480 Temporarily unavailable */ static char *hangup_cause2sip(int cause) { - switch(cause) - { - case AST_CAUSE_UNALLOCATED: /* 1 */ - case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ - case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ - return "404 Not Found"; - case AST_CAUSE_CONGESTION: /* 34 */ - case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ - return "503 Service Unavailable"; - case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ - return "408 Request Timeout"; - case AST_CAUSE_NO_ANSWER: /* 19 */ - return "480 Temporarily unavailable"; - case AST_CAUSE_CALL_REJECTED: /* 21 */ - return "403 Forbidden"; - case AST_CAUSE_NUMBER_CHANGED: /* 22 */ - return "410 Gone"; - case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ - return "480 Temporarily unavailable"; - case AST_CAUSE_INVALID_NUMBER_FORMAT: - return "484 Address incomplete"; - case AST_CAUSE_USER_BUSY: - return "486 Busy here"; - case AST_CAUSE_FAILURE: - return "500 Server internal failure"; - case AST_CAUSE_FACILITY_REJECTED: /* 29 */ - return "501 Not Implemented"; - case AST_CAUSE_CHAN_NOT_IMPLEMENTED: - return "503 Service Unavailable"; - /* Used in chan_iax2 */ - case AST_CAUSE_DESTINATION_OUT_OF_ORDER: - return "502 Bad Gateway"; - case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ - return "488 Not Acceptable Here"; - - case AST_CAUSE_NOTDEFINED: - default: - ast_log(LOG_DEBUG, "AST hangup cause %d (no match found in SIP)\n", cause); - return NULL; + switch (cause) { + case AST_CAUSE_UNALLOCATED: /* 1 */ + case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ + case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ + return "404 Not Found"; + case AST_CAUSE_CONGESTION: /* 34 */ + case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ + return "503 Service Unavailable"; + case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ + return "408 Request Timeout"; + case AST_CAUSE_NO_ANSWER: /* 19 */ + return "480 Temporarily unavailable"; + case AST_CAUSE_CALL_REJECTED: /* 21 */ + return "403 Forbidden"; + case AST_CAUSE_NUMBER_CHANGED: /* 22 */ + return "410 Gone"; + case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ + return "480 Temporarily unavailable"; + case AST_CAUSE_INVALID_NUMBER_FORMAT: + return "484 Address incomplete"; + case AST_CAUSE_USER_BUSY: + return "486 Busy here"; + case AST_CAUSE_FAILURE: + return "500 Server internal failure"; + case AST_CAUSE_FACILITY_REJECTED: /* 29 */ + return "501 Not Implemented"; + case AST_CAUSE_CHAN_NOT_IMPLEMENTED: + return "503 Service Unavailable"; + /* Used in chan_iax2 */ + case AST_CAUSE_DESTINATION_OUT_OF_ORDER: + return "502 Bad Gateway"; + case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ + return "488 Not Acceptable Here"; + case AST_CAUSE_NOTDEFINED: + default: + ast_log(LOG_DEBUG, "AST hangup cause %d (no match found in SIP)\n", cause); + return NULL; } /* Never reached */ return 0; } - /*--- sip_hangup: Hangup SIP call ---*/ /* Part of PBX interface */ static int sip_hangup(struct ast_channel *ast) @@ -2259,13 +2222,12 @@ INVITE, but do set an autodestruct just in case we never get it. */ ast_clear_flag(&locflags, SIP_NEEDDESTROY); sip_scheddestroy(p, 15000); - if ( p->initid != -1 ) { + if (p->initid != -1) { /* channel still up - reverse dec of inUse counter only if the channel is not auto-congested */ if (ast_test_flag(p, SIP_OUTGOING)) { update_user_counter(p, INC_OUT_USE); - } - else { + } else { update_user_counter(p, INC_IN_USE); } } @@ -2273,8 +2235,9 @@ char *res; if (ast->hangupcause && ((res = hangup_cause2sip(ast->hangupcause)))) { transmit_response_reliable(p, res, &p->initreq, 1); - } else + } else { transmit_response_reliable(p, "403 Forbidden", &p->initreq, 1); + } } } else { /* Call is in UP state, send BYE */ if (!p->pendinginvite) { @@ -2306,7 +2269,7 @@ #ifdef OSP_SUPPORT time(&p->ospstart); #endif - + codec=pbx_builtin_getvar_helper(p->owner,"SIP_CODEC"); if (codec) { fmt=ast_getformatbyname(codec); @@ -2377,7 +2340,6 @@ ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype); return 0; } - return res; } @@ -2420,9 +2382,6 @@ return res; } -#define DEFAULT_MAX_FORWARDS 70 - - /*--- sip_transfer: Transfer SIP call */ static int sip_transfer(struct ast_channel *ast, const char *dest) { @@ -2447,7 +2406,7 @@ int res = 0; ast_mutex_lock(&p->lock); - switch(condition) { + switch (condition) { case AST_CONTROL_RINGING: if (ast->_state == AST_STATE_RING) { if (!ast_test_flag(p, SIP_PROGRESS_SENT) || @@ -2502,8 +2461,7 @@ ast_set_flag(p, SIP_CALL_ONHOLD); break; case AST_CONTROL_UNHOLD: /* We are back from hold */ - /* Open RTP stream if we decide to close it - */ + /* Open RTP stream if we decide to close it */ if (sipdebug) ast_log(LOG_DEBUG, "SIP dialog off hold: %s\n", p->callid); res = -1; @@ -2521,8 +2479,6 @@ return res; } - - /*--- sip_new: Initiate a call in the SIP channel */ /* called from sip_request (calls from the pbx ) */ static struct ast_channel *sip_new(struct sip_pvt *i, int state, char *title) @@ -2659,14 +2615,12 @@ return ""; } - static void sdpLineNum_iterator_init(int* iterator) { *iterator = 0; } -static char* get_sdp_iterate(int* iterator, - struct sip_request *req, char *name) +static char* get_sdp_iterate(int* iterator, struct sip_request *req, char *name) { int len = strlen(name); char *r; @@ -2692,18 +2646,16 @@ { int pass; - /* - * Technically you can place arbitrary whitespace both before and after the ':' in + /* Technically you can place arbitrary whitespace both before and after the ':' in * a header, although RFC3261 clearly says you shouldn't before, and place just * one afterwards. If you shouldn't do it, what absolute idiot decided it was * a good idea to say you can do it, and if you can do it, why in the hell would. * you say you shouldn't. * Anyways, pedanticsipchecking controls whether we allow spaces before ':', - * and we always allow spaces after that for compatibility. - */ + * and we always allow spaces after that for compatibility. */ for (pass = 0; name && pass < 2;pass++) { int x, len = strlen(name); - for (x=*start; xheaders; x++) { + for (x = *start; xheaders; x++) { if (!strncasecmp(req->header[x], name, len)) { char *r = req->header[x] + len; /* skip name */ if (pedanticsipchecking) @@ -2736,7 +2688,7 @@ /* Retrieve audio/etc from channel. Assumes p->lock is already held. */ struct ast_frame *f; static struct ast_frame null_frame = { AST_FRAME_NULL, }; - switch(ast->fdno) { + switch (ast->fdno) { case 0: f = ast_rtp_read(p->rtp); /* RTP Audio */ break; @@ -2930,13 +2882,14 @@ ast_mutex_lock(&iflock); p = iflist; - while(p) { + while (p) { int found = 0; - if (req->method == SIP_REGISTER) + if (req->method == SIP_REGISTER) { found = (!strcmp(p->callid, callid)); - else - found = (!strcmp(p->callid, callid) && - (!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))) ; + } else { + found = (!strcmp(p->callid, callid) && + (!pedanticsipchecking || !tag || ast_strlen_zero(p->theirtag) || !strcmp(p->theirtag, tag))); + } if (found) { /* Found the call */ ast_mutex_lock(&p->lock); @@ -3082,7 +3035,7 @@ /* First header starts immediately */ req->header[f] = c; - while(*c) { + while (*c) { if (*c == '\n') { /* We've got a new header */ *c = 0; @@ -3112,7 +3065,7 @@ /* Now we process any mime content */ f = 0; req->line[f] = c; - while(*c) { + while (*c) { if (*c == '\n') { /* We've got a new line */ *c = 0; @@ -3201,7 +3154,7 @@ /* Scan through the RTP payload types specified in a "m=" line: */ ast_rtp_pt_clear(p->rtp); codecs = m + len; - while(!ast_strlen_zero(codecs)) { + while (!ast_strlen_zero(codecs)) { if (sscanf(codecs, "%d%n", &codec, &len) != 1) { ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); return -1; @@ -3221,7 +3174,7 @@ vportno = x; /* Scan through the RTP payload types specified in a "m=" line: */ codecs = m + len; - while(!ast_strlen_zero(codecs)) { + while (!ast_strlen_zero(codecs)) { if (sscanf(codecs, "%d%n", &codec, &len) != 1) { ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); return -1; @@ -3689,7 +3642,6 @@ return 0; } - /*--- respprep: Prepare SIP response packet ---*/ static int respprep(struct sip_request *resp, struct sip_pvt *p, char *msg, struct sip_request *req) { @@ -4207,7 +4159,7 @@ return -1; } /* XXX maybe trim_blanks() ? */ - while( isspace( *(--e) ) ) {} + while (isspace(*(--e))) {} if ( *e == '>' ) { *e = '\0'; } else { @@ -4273,71 +4225,73 @@ /*--- initreqprep: Initiate SIP request to peer/user ---*/ static void initreqprep(struct sip_request *req, struct sip_pvt *p, int sipmethod, char *vxml_url) { - char invite[256]=""; + char invite[256] = ""; char from[256]; char to[256]; char tmp[80]; char iabuf[INET_ADDRSTRLEN]; - char *l = default_callerid, *n=NULL; + char *l = default_callerid, *n = NULL; int x; - char urioptions[256]=""; + char urioptions[256] = ""; if (ast_test_flag(p, SIP_USEREQPHONE)) { - char onlydigits = 1; - x=0; - + char onlydigits = 1; + x = 0; /* Test p->username against allowed characters in AST_DIGIT_ANY - If it matches the allowed characters list, then sipuser = ";user=phone" - If not, then sipuser = "" - */ - /* + is allowed in first position in a tel: uri */ - if (p->username && p->username[0] == '+') - x=1; + * If it matches the allowed characters list, then sipuser = ";user=phone" + * If not, then sipuser = "" + * + is allowed in first position in a tel: uri */ + if (p->username && p->username[0] == '+') + x = 1; - for (; xusername); x++) { + for ( ; x < strlen(p->username); x++) { if (!strchr(AST_DIGIT_ANYNUM, p->username[x])) { - onlydigits = 0; + onlydigits = 0; break; } - } + } /* If we have only digits, add ;user=phone to the uri */ - if (onlydigits) + if (onlydigits) { strcpy(urioptions, ";user=phone"); + } } - snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text); if (p->owner) { l = p->owner->cid.cid_num; n = p->owner->cid.cid_name; } - if (!l || (!ast_isphonenumber(l) && default_callerid[0])) - l = default_callerid; + if (!l || (!ast_isphonenumber(l) && default_callerid[0])) { + l = default_callerid; + } /* if user want's his callerid restricted */ if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { l = CALLERID_UNKNOWN; n = l; } - if (!n || ast_strlen_zero(n)) + if (!n || ast_strlen_zero(n)) { n = l; + } /* Allow user to be overridden */ - if (!ast_strlen_zero(p->fromuser)) + if (!ast_strlen_zero(p->fromuser)) { l = p->fromuser; - else /* Save for any further attempts */ + } else { /* Save for any further attempts */ ast_copy_string(p->fromuser, l, sizeof(p->fromuser)); - + } /* Allow user to be overridden */ - if (!ast_strlen_zero(p->fromname)) + if (!ast_strlen_zero(p->fromname)) { n = p->fromname; - else /* Save for any further attempts */ + } else { /* Save for any further attempts */ ast_copy_string(p->fromname, n, sizeof(p->fromname)); + } - if ((ourport != 5060) && ast_strlen_zero(p->fromdomain)) /* Needs to be 5060 */ + if ((ourport != 5060) && ast_strlen_zero(p->fromdomain)) { /* Needs to be 5060 */ snprintf(from, sizeof(from), "\"%s\" ;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, ourport, p->tag); - else + } else { snprintf(from, sizeof(from), "\"%s\" ;tag=as%08x", n, l, ast_strlen_zero(p->fromdomain) ? ast_inet_ntoa(iabuf, sizeof(iabuf), p->ourip) : p->fromdomain, p->tag); + } /* If we're calling a registred SIP peer, use the fullcontact to dial to the peer */ if (!ast_strlen_zero(p->fullcontact)) { @@ -4345,7 +4299,7 @@ ast_copy_string(invite, p->fullcontact, sizeof(invite)); /* Otherwise, use the username while waiting for registration */ } else if (!ast_strlen_zero(p->username)) { - if (ntohs(p->sa.sin_port) != 5060) { /* Needs to be 5060 */ + if (ntohs(p->sa.sin_port) != 5060) { /* Needs to be 5060 */ snprintf(invite, sizeof(invite), "sip:%s@%s:%d%s",p->username, p->tohost, ntohs(p->sa.sin_port), urioptions); } else { snprintf(invite, sizeof(invite), "sip:%s@%s%s",p->username, p->tohost, urioptions); @@ -4357,8 +4311,7 @@ } ast_copy_string(p->uri, invite, sizeof(p->uri)); /* If there is a VXML URL append it to the SIP URL */ - if (vxml_url) - { + if (vxml_url) { snprintf(to, sizeof(to), "<%s>;%s", invite, vxml_url); } else { snprintf(to, sizeof(to), "<%s>", invite); @@ -4426,12 +4379,12 @@ ast = p->owner; /* The owner channel */ if (ast) { - headp=&ast->varshead; - if (!headp) + headp = &ast->varshead; + if (!headp) { ast_log(LOG_WARNING,"No Headp for the channel...ooops!\n"); - else { + } else { AST_LIST_TRAVERSE(headp,current,entries) { - /* SIPADDHEADER: Add SIP header to outgoing call */ + /* SIPADDHEADER: Add SIP header to outgoing call */ if (!strncasecmp(ast_var_name(current),"SIPADDHEADER",strlen("SIPADDHEADER"))) { header = ast_var_value(current); /* Strip of the starting " (if it's there) */ @@ -4606,8 +4559,7 @@ /*--- transmit_notify_with_sipfrag: Notify a transferring party of the status of trasnfer ---*/ /* Apparently the draft SIP REFER structure was too simple, so it was decided that the * status of transfers also needed to be sent via NOTIFY instead of just the 202 Accepted - * that had worked heretofore. - */ + * that had worked heretofore. */ static int transmit_notify_with_sipfrag(struct sip_pvt *p, int cseq) { struct sip_request req; @@ -4636,7 +4588,7 @@ static char *regstate2str(int regstate) { - switch(regstate) { + switch (regstate) { case REG_STATE_FAILED: return "Failed"; case REG_STATE_UNREGISTERED: @@ -4959,7 +4911,7 @@ if (strlen(tmp) && atoi(tmp)) { p->maxforwards = atoi(tmp) - 1; } else { - p->maxforwards = DEFAULT_MAX_FORWARDS - 1; + p->maxforwards = DEFAULT_MAX_FORWARDS - 1; } if (p->maxforwards > -1) { /* save in case we get 407 challenge */ @@ -5042,8 +4994,6 @@ return 0; } -static int sip_poke_peer(struct sip_peer *peer); - static int sip_poke_peer_s(void *data) { struct sip_peer *peer = data; @@ -5092,7 +5042,7 @@ if (option_verbose > 2) ast_verbose(VERBOSE_PREFIX_3 "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n", - peer->name, peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), port, expiry); + peer->name, peer->username, ast_inet_ntoa(iabuf, sizeof(iabuf), in), port, expiry); memset(&peer->addr, 0, sizeof(peer->addr)); peer->addr.sin_family = AF_INET; @@ -5180,7 +5130,6 @@ return 0; } - /*--- parse_contact: Parse contact header and save registration ---*/ static int parse_contact(struct sip_pvt *pvt, struct sip_peer *p, struct sip_request *req) { @@ -5453,7 +5402,7 @@ && !ast_test_flag(p, SIP_OSPAUTH) && global_allowguest != 2 #endif - ) + ) return 0; if (sipmethod == SIP_REGISTER) { /* On a REGISTER, we have to use 401 and its family of headers instead of 407 and its family @@ -5477,7 +5426,6 @@ snprintf(tmp, sizeof(tmp), "%d", p->osphandle); pbx_builtin_setvar_helper(p->owner, "_OSPHANDLE", tmp); - /* If ospauth is 'exclusive' don't require further authentication */ if ((ast_test_flag(p, SIP_OSPAUTH) == SIP_OSPAUTH_EXCLUSIVE) || (ast_strlen_zero(secret) && ast_strlen_zero(md5secret))) @@ -5527,60 +5475,59 @@ ast_copy_string(tmp, authtoken, sizeof(tmp)); c = tmp; - while(c) { + while (c) { c = ast_skip_blanks(c); if (!*c) break; if (!strncasecmp(c, "response=", strlen("response="))) { c+= strlen("response="); if ((*c == '\"')) { - ua_hash=++c; - if ((c = strchr(c,'\"'))) + ua_hash = ++c; + if ((c = strchr(c, '\"'))) *c = '\0'; } else { - ua_hash=c; - if ((c = strchr(c,','))) + ua_hash = c; + if ((c = strchr(c, ','))) *c = '\0'; } - } else if (!strncasecmp(c, "uri=", strlen("uri="))) { c+= strlen("uri="); if ((*c == '\"')) { - resp_uri=++c; - if ((c = strchr(c,'\"'))) + resp_uri = ++c; + if ((c = strchr(c, '\"'))) *c = '\0'; } else { - resp_uri=c; - if ((c = strchr(c,','))) + resp_uri = c; + if ((c = strchr(c, ','))) *c = '\0'; } - } else if (!strncasecmp(c, "username=", strlen("username="))) { c+= strlen("username="); if ((*c == '\"')) { - digestusername=++c; - if((c = strchr(c,'\"'))) + digestusername = ++c; + if ((c = strchr(c, '\"'))) *c = '\0'; } else { digestusername=c; - if((c = strchr(c,','))) + if ((c = strchr(c, ','))) *c = '\0'; } } else if (!strncasecmp(c, "nonce=", strlen("nonce="))) { c+= strlen("nonce="); if ((*c == '\"')) { - nonce=++c; - if ((c = strchr(c,'\"'))) + nonce = ++c; + if ((c = strchr(c, '\"'))) *c = '\0'; } else { - nonce=c; - if ((c = strchr(c,','))) + nonce = c; + if ((c = strchr(c, ','))) *c = '\0'; } - - } else - if ((z = strchr(c,' ')) || (z = strchr(c,','))) c=z; + } else { + if ((z = strchr(c, ' ')) || (z = strchr(c, ','))) + c = z; + } if (c) c++; } @@ -5667,7 +5614,7 @@ char *t; /* Terminate URI */ t = uri; - while(*t && (*t > 32) && (*t != ';')) + while (*t && (*t > 32) && (*t != ';')) t++; *t = '\0'; @@ -5858,12 +5805,12 @@ /* Search interfaces and find the match */ ast_mutex_lock(&iflock); sip_pvt_ptr = iflist; - while(sip_pvt_ptr) { + while (sip_pvt_ptr) { if (!strcmp(sip_pvt_ptr->callid, callid)) { /* Go ahead and lock it (and its owner) before returning */ ast_mutex_lock(&sip_pvt_ptr->lock); if (sip_pvt_ptr->owner) { - while(ast_mutex_trylock(&sip_pvt_ptr->owner->lock)) { + while (ast_mutex_trylock(&sip_pvt_ptr->owner->lock)) { ast_mutex_unlock(&sip_pvt_ptr->lock); usleep(1); ast_mutex_lock(&sip_pvt_ptr->lock); @@ -6125,7 +6072,7 @@ /* clear the empty characters in the begining*/ input = ast_skip_blanks(input); /* clear the empty characters in the end */ - while(*end && (*end < 33) && end > input) + while (*end && (*end < 33) && end > input) end--; if (end >= input) { bytes = (int) (end - input) + 2; @@ -6172,7 +6119,6 @@ return 0; } - /*--- check_user: Check if matching user or peer is defined ---*/ static int check_user_full(struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, int reliable, struct sockaddr_in *sin, int ignore, char *mailbox, int mailboxlen) { @@ -6189,7 +6135,7 @@ /* Terminate URI */ t = uri; - while(*t && (*t > 32) && (*t != ';')) + while (*t && (*t > 32) && (*t != ';')) t++; *t = '\0'; of = get_header(req, "From"); @@ -6409,7 +6355,6 @@ } #endif } - } if (user) @@ -6444,7 +6389,6 @@ return 0; } - /*--- receive_message: Receive SIP MESSAGE method messages ---*/ /* we handle messages within current calls currently */ static void receive_message(struct sip_pvt *p, struct sip_request *req) @@ -6533,7 +6477,7 @@ /*--- nat2str: Convert NAT setting to text string */ static char *nat2str(int nat) { - switch(nat) { + switch (nat) { case SIP_NAT_NEVER: return "No"; case SIP_NAT_ROUTE: @@ -6625,8 +6569,6 @@ "Variables: \n" " ActionID: Action ID for this transaction. Will be returned.\n"; -static int _sip_show_peers(int fd, int *total, struct mansession *s, struct message *m, int argc, char *argv[]); - /*--- manager_sip_show_peers: Show SIP peers in the manager API ---*/ /* Inspired from chan_iax2 */ static int manager_sip_show_peers( struct mansession *s, struct message *m ) @@ -6720,14 +6662,14 @@ ast_copy_string(name, iterator->name, sizeof(name)); pstatus = peer_status(iterator, status, sizeof(status)); - if (pstatus) + if (pstatus) { peers_online++; - else { - if (pstatus == 0) + } else { + if (pstatus == 0) { peers_offline++; - else { /* Unmonitored */ + } else { /* Unmonitored */ /* Checking if port is 0 */ - if ( ntohs(iterator->addr.sin_port) == 0 ) { + if (ntohs(iterator->addr.sin_port) == 0) { peers_offline++; } else { peers_online++; @@ -6747,7 +6689,7 @@ iterator->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), iterator->addr.sin_addr) : "(Unspecified)", ast_test_flag(iterator, SIP_DYNAMIC) ? " D " : " ", /* Dynamic or not? */ (ast_test_flag(iterator, SIP_NAT) & SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ - iterator->ha ? " A " : " ", /* permit/deny */ + iterator->ha ? " A " : " ", /* permit/deny */ nm, ntohs(iterator->addr.sin_port), status); } else { /* Manager format */ @@ -6770,7 +6712,7 @@ ntohs(iterator->addr.sin_port), ast_test_flag(iterator, SIP_DYNAMIC) ? "yes" : "no", /* Dynamic or not? */ (ast_test_flag(iterator, SIP_NAT) & SIP_NAT_ROUTE) ? "yes" : "no", /* NAT=yes? */ - iterator->ha ? "yes" : "no", /* permit/deny */ + iterator->ha ? "yes" : "no", /* permit/deny */ status); ast_mutex_unlock(&s->lock); @@ -6779,11 +6721,10 @@ ASTOBJ_UNLOCK(iterator); total_peers++; - } while(0) ); + } while (0) ); - if (!s) { + if (!s) ast_cli(fd,"%d sip peers [%d online , %d offline]\n",total_peers,peers_online,peers_offline); - } if (havepattern) regfree(®exbuf); @@ -6999,8 +6940,6 @@ " Peer: The peer name you want to check.\n" " ActionID: Optional action ID for this AMI transaction.\n"; -static int _sip_show_peer(int type, int fd, struct mansession *s, struct message *m, int argc, char *argv[]); - /*--- manager_sip_show_peer: Show SIP peers in the manager API ---*/ static int manager_sip_show_peer( struct mansession *s, struct message *m ) { @@ -7028,8 +6967,6 @@ return ret; } - - /*--- sip_show_peer: Show one peer in detail ---*/ static int sip_show_peer(int fd, int argc, char *argv[]) { @@ -7068,7 +7005,7 @@ ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"":""); ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"":""); auth = peer->auth; - while(auth) { + while (auth) { ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s ", auth->realm, auth->username); ast_cli(fd, "%s\n", !ast_strlen_zero(auth->secret)?"":(!ast_strlen_zero(auth->md5secret)?"" : "")); auth = auth->next; @@ -7124,12 +7061,12 @@ ast_cli(fd, "%s\n", codec_buf); ast_cli(fd, " Codec Order : ("); pref = &peer->prefs; - for(x = 0; x < 32 ; x++) { + for (x = 0; x < 32 ; x++) { codec = ast_codec_pref_index(pref,x); if (!codec) break; ast_cli(fd, "%s", ast_getformatname(codec)); - if (x < 31 && ast_codec_pref_index(pref, x+1)) + if (x < 31 && ast_codec_pref_index(pref, x + 1)) ast_cli(fd, "|"); } @@ -7200,7 +7137,7 @@ ast_cli(fd, "%s\r\n", codec_buf); ast_cli(fd, "CodecOrder: "); pref = &peer->prefs; - for(x = 0; x < 32 ; x++) { + for (x = 0; x < 32 ; x++) { codec = ast_codec_pref_index(pref,x); if (!codec) break; @@ -7269,7 +7206,7 @@ ast_cli(fd, " ACL : %s\n", (user->ha?"Yes":"No")); ast_cli(fd, " Codec Order : ("); pref = &user->prefs; - for(x = 0; x < 32 ; x++) { + for (x = 0; x < 32 ; x++) { codec = ast_codec_pref_index(pref,x); if (!codec) break; @@ -7312,7 +7249,7 @@ snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : DEFAULT_SIP_PORT); ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate)); ASTOBJ_UNLOCK(iterator); - } while(0)); + } while (0)); return RESULT_SUCCESS; #undef FORMAT #undef FORMAT2 @@ -7324,13 +7261,13 @@ /*--- sip_show_channels: Show active SIP channels ---*/ static int sip_show_channels(int fd, int argc, char *argv[]) { - return __sip_show_channels(fd, argc, argv, 0); + return __sip_show_channels(fd, argc, argv, 0); } /*--- sip_show_subscriptions: Show active SIP subscriptions ---*/ static int sip_show_subscriptions(int fd, int argc, char *argv[]) { - return __sip_show_channels(fd, argc, argv, 1); + return __sip_show_channels(fd, argc, argv, 1); } static int __sip_show_channels(int fd, int argc, char *argv[], int subscriptions) @@ -7348,24 +7285,21 @@ if (!subscriptions) ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Last Msg"); else - ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "URI"); + ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "URI"); while (cur) { if (!cur->subscribed && !subscriptions) { ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), - ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, - cur->callid, - cur->ocseq, cur->icseq, - ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), - ast_test_flag(cur, SIP_NEEDDESTROY) ? "(d)" : "", - cur->lastmsg ); + ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, + cur->callid, cur->ocseq, cur->icseq, + ast_getformatname(cur->owner ? cur->owner->nativeformats : 0), + ast_test_flag(cur, SIP_NEEDDESTROY) ? "(d)" : "", cur->lastmsg ); numchans++; } if (cur->subscribed && subscriptions) { - ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), - ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, - cur->callid, cur->uri); - - } + ast_cli(fd, FORMAT3, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr), + ast_strlen_zero(cur->username) ? ( ast_strlen_zero(cur->cid_num) ? "(None)" : cur->cid_num ) : cur->username, + cur->callid, cur->uri); + } cur = cur->next; } ast_mutex_unlock(&iflock); @@ -7388,7 +7322,7 @@ ast_mutex_lock(&iflock); cur = iflist; - while(cur) { + while (cur) { if (!strncasecmp(word, cur->callid, strlen(word))) { if (++which > state) { c = strdup(cur->callid); @@ -7417,7 +7351,7 @@ result = strdup(iterator->name); } } - } while(0) ); + } while (0) ); return result; } @@ -7455,7 +7389,7 @@ result = strdup(iterator->name); } } - } while(0) ); + } while (0) ); return result; } @@ -7483,7 +7417,7 @@ return NULL; cat = ast_category_browse(notify_types, NULL); - while(cat) { + while (cat) { if (!strncasecmp(word, cat, strlen(word))) { if (++which > state) { c = strdup(cat); @@ -7531,7 +7465,7 @@ len = strlen(argv[3]); ast_mutex_lock(&iflock); cur = iflist; - while(cur) { + while (cur) { if (!strncasecmp(cur->callid, argv[3],len)) { ast_cli(fd,"\n"); if (cur->subscribed) @@ -7564,7 +7498,7 @@ ast_cli(fd, " Promiscuous Redir: %s\n", ast_test_flag(cur, SIP_PROMISCREDIR) ? "Yes" : "No"); ast_cli(fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); ast_cli(fd, " DTMF Mode: %s\n", dtmfmode2str(ast_test_flag(cur, SIP_DTMF))); - ast_cli(fd, " SIP Options : "); + ast_cli(fd, " SIP Options: "); if (cur->sipoptions) { int x; for (x=0 ; (x < (sizeof(sip_options) / sizeof(sip_options[0]))); x++) { @@ -7600,7 +7534,7 @@ len = strlen(argv[3]); ast_mutex_lock(&iflock); cur = iflist; - while(cur) { + while (cur) { if (!strncasecmp(cur->callid, argv[3],len)) { ast_cli(fd,"\n"); if (cur->subscribed) @@ -7609,7 +7543,7 @@ ast_cli(fd, " * SIP Call\n"); x = 0; hist = cur->history; - while(hist) { + while (hist) { x++; ast_cli(fd, "%d. %s\n", x, hist->event); hist = hist->next; @@ -7626,7 +7560,6 @@ return RESULT_SUCCESS; } - /*--- receive_info: Receive SIP INFO Message ---*/ /* Doesn't read the duration of the DTMF signal */ static void receive_info(struct sip_pvt *p, struct sip_request *req) @@ -7875,8 +7808,6 @@ return RESULT_SUCCESS; } -static int reply_digest(struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len); - /*--- do_register_auth: Authenticate for outbound registration ---*/ static int do_register_auth(struct sip_pvt *p, struct sip_request *req, char *header, char *respheader) { @@ -8050,8 +7981,6 @@ return 0; } - - static char notify_usage[] = "Usage: sip notify [...]\n" " Send a NOTIFY message to a SIP peer or peers\n" @@ -8137,7 +8066,6 @@ "Usage: sip show objects\n" " Shows status of known SIP objects\n"; - /*--- func_header_read: Read SIP header (dialplan function) */ static char *func_header_read(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { @@ -8177,7 +8105,6 @@ return buf; } - static struct ast_custom_function sip_header_function = { .name = "SIP_HEADER", .synopsis = "Gets or sets the specified SIP header", @@ -8246,7 +8173,7 @@ *ptr = '\0'; } index = atoi(codecnum); - if((codec = ast_codec_pref_index(&peer->prefs, index))) { + if ((codec = ast_codec_pref_index(&peer->prefs, index))) { ast_copy_string(buf, ast_getformatname(codec), len); } } @@ -8388,7 +8315,7 @@ ast_log(LOG_DEBUG, "Cancelling timeout %d\n", r->timeout); ast_sched_del(sched, r->timeout); } - r->timeout=-1; + r->timeout = -1; r->call = NULL; p->registry = NULL; /* Let this one hang around until we have all the responses */ @@ -8406,11 +8333,11 @@ char *contact = NULL; char *tmptmp = NULL; int start = 0; - for(;;) { + for (;;) { contact = __get_header(req, "Contact", &start); /* this loop ensures we get a contact header about our register request */ - if(!ast_strlen_zero(contact)) { - if( (tmptmp=strstr(contact, p->our_contact))) { + if (!ast_strlen_zero(contact)) { + if ((tmptmp=strstr(contact, p->our_contact))) { contact=tmptmp; break; } @@ -8554,7 +8481,7 @@ ast_sched_del(sched, p->initid); p->initid = -1; } - switch(resp) { + switch (resp) { case 100: /* 100 Trying */ if (sipmethod == SIP_INVITE) { sip_cancel_destroy(p); @@ -8711,7 +8638,7 @@ ast_rtp_stop(p->vrtp); } /* XXX Locking issues?? XXX */ - switch(resp) { + switch (resp) { case 300: /* Multiple Choices */ case 301: /* Moved permenantly */ case 302: /* Moved temporarily */ @@ -8786,7 +8713,7 @@ } if (sip_debug_test_pvt(p)) ast_verbose("Response message is %s\n", msg); - switch(resp) { + switch (resp) { case 200: /* Change branch since this is a 200 response */ if (sipmethod == SIP_INVITE) @@ -9155,7 +9082,7 @@ if (!ignore && p) p->lastinvite = seqno; if (c) { - switch(c->_state) { + switch (c->_state) { case AST_STATE_DOWN: transmit_response(p, "100 Trying", req); ast_setstate(c, AST_STATE_RING); @@ -9297,6 +9224,7 @@ } return res; } + /*--- handle_request_cancel: Handle incoming CANCEL request ---*/ static int handle_request_cancel(struct sip_pvt *p, struct sip_request *req, int debug, int ignore) { @@ -9391,6 +9319,7 @@ } return 1; } + /*--- handle_request_subscribe: Handle incoming SUBSCRIBE request ---*/ static int handle_request_subscribe(struct sip_pvt *p, struct sip_request *req, int debug, int ignore, struct sockaddr_in *sin, int seqno, char *e) { @@ -9532,6 +9461,7 @@ } return res; } + /*--- handle_request: Handle SIP requests (methods) ---*/ /* this is where all incoming requests go first */ static int handle_request(struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock) @@ -9851,7 +9781,7 @@ /* This thread monitors all the frame relay interfaces which are not yet in use (and thus do not have a separate thread) indefinitely */ /* From here on out, we die whenever asked */ - for(;;) { + for (;;) { /* Check for a reload request */ ast_mutex_lock(&sip_reload_lock); reloading = sip_reloading; @@ -9867,7 +9797,7 @@ restartsearch: time(&t); sip = iflist; - while(sip) { + while (sip) { ast_mutex_lock(&sip->lock); if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) { if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) { @@ -9879,12 +9809,10 @@ /* Might be a timeout now -- see if we're on hold */ struct sockaddr_in sin; ast_rtp_get_peer(sip->rtp, &sin); - if (sin.sin_addr.s_addr || - (sip->rtpholdtimeout && - (t > sip->lastrtprx + sip->rtpholdtimeout))) { + if (sin.sin_addr.s_addr || (sip->rtpholdtimeout && (t > sip->lastrtprx + sip->rtpholdtimeout))) { /* Needs a hangup */ if (sip->rtptimeout) { - while(sip->owner && ast_mutex_trylock(&sip->owner->lock)) { + while (sip->owner && ast_mutex_trylock(&sip->owner->lock)) { ast_mutex_unlock(&sip->lock); usleep(1); ast_mutex_lock(&sip->lock); @@ -10353,7 +10281,7 @@ if (!authlist) { /* No existing list */ return auth; } - while(a) { + while (a) { b = a; a = a->next; } @@ -10407,7 +10335,6 @@ struct ast_flags userflags = {(0)}; struct ast_flags mask = {(0)}; - user = (struct sip_user *)malloc(sizeof(struct sip_user)); if (!user) { return NULL; @@ -10430,7 +10357,7 @@ strcpy(user->context, default_context); strcpy(user->language, default_language); strcpy(user->musicclass, global_musicclass); - while(v) { + while (v) { if (handle_common_options(&userflags, &mask, v)) { v = v->next; continue; @@ -10517,10 +10444,10 @@ peer->expire = -1; peer->pokeexpire = -1; ast_copy_string(peer->name, name, sizeof(peer->name)); - ast_copy_flags(peer, &global_flags, - SIP_PROMISCREDIR | SIP_USEREQPHONE | SIP_TRUSTRPID | SIP_USECLIENTCODE | - SIP_DTMF | SIP_NAT | SIP_REINVITE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE | - SIP_PROG_INBAND | SIP_OSPAUTH); + ast_copy_flags(peer, &global_flags, SIP_PROMISCREDIR | SIP_USEREQPHONE | + SIP_TRUSTRPID | SIP_USECLIENTCODE | SIP_DTMF | SIP_NAT | + SIP_REINVITE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE | + SIP_PROG_INBAND | SIP_OSPAUTH); strcpy(peer->context, default_context); strcpy(peer->language, default_language); strcpy(peer->musicclass, global_musicclass); @@ -10554,7 +10481,6 @@ struct ast_flags peerflags = {(0)}; struct ast_flags mask = {(0)}; - if (!realtime) /* Note we do NOT use find_peer here, to avoid realtime recursion */ peer = ASTOBJ_CONTAINER_FIND_UNLINK(&peerl, name); @@ -10615,14 +10541,13 @@ oldha = peer->ha; peer->ha = NULL; peer->addr.sin_family = AF_INET; - ast_copy_flags(peer, &global_flags, - SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_USECLIENTCODE | - SIP_DTMF | SIP_REINVITE | SIP_INSECURE_PORT | SIP_INSECURE_INVITE | - SIP_PROG_INBAND | SIP_OSPAUTH); + ast_copy_flags(peer, &global_flags, SIP_PROMISCREDIR | SIP_TRUSTRPID | + SIP_USECLIENTCODE | SIP_DTMF | SIP_REINVITE | SIP_INSECURE_PORT | + SIP_INSECURE_INVITE | SIP_PROG_INBAND | SIP_OSPAUTH); peer->capability = global_capability; peer->rtptimeout = global_rtptimeout; peer->rtpholdtimeout = global_rtpholdtimeout; - while(v) { + while (v) { if (handle_common_options(&peerflags, &mask, v)) { v = v->next; continue; @@ -10878,7 +10803,7 @@ /* Read the [general] config section of sip.conf (or from realtime config) */ v = ast_variable_browse(cfg, "general"); - while(v) { + while (v) { if (handle_common_options(&global_flags, &dummy, v)) { v = v->next; continue; @@ -10891,8 +10816,7 @@ ast_copy_string(global_realm, v->value, sizeof(global_realm)); } else if (!strcasecmp(v->name, "useragent")) { ast_copy_string(default_useragent, v->value, sizeof(default_useragent)); - ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n", - default_useragent); + ast_log(LOG_DEBUG, "Setting User Agent Name to %s\n", default_useragent); } else if (!strcasecmp(v->name, "rtcachefriends")) { ast_set2_flag((&global_flags_page2), ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS); } else if (!strcasecmp(v->name, "rtnoupdate")) { @@ -10970,13 +10894,13 @@ default_expiry = atoi(v->value); if (default_expiry < 1) default_expiry = DEFAULT_DEFAULT_EXPIRY; - } else if (!strcasecmp(v->name, "sipdebug")){ + } else if (!strcasecmp(v->name, "sipdebug")) { sipdebug = ast_true(v->value); - } else if (!strcasecmp(v->name, "registertimeout")){ + } else if (!strcasecmp(v->name, "registertimeout")) { global_reg_timeout = atoi(v->value); if (global_reg_timeout < 1) global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; - } else if (!strcasecmp(v->name, "registerattempts")){ + } else if (!strcasecmp(v->name, "registerattempts")) { global_regattempts_max = atoi(v->value); } else if (!strcasecmp(v->name, "bindaddr")) { if (!(hp = ast_gethostbyname(v->value, &ahp))) { @@ -11059,7 +10983,7 @@ /* Build list of authentication to various SIP realms, i.e. service providers */ v = ast_variable_browse(cfg, "authentication"); - while(v) { + while (v) { /* Format for authentication is auth = username:password@realm */ if (!strcasecmp(v->name, "auth")) { authl = add_realm_authentication(authl, v->value, v->lineno); @@ -11069,7 +10993,7 @@ /* Load peers, users and friends */ cat = ast_category_browse(cfg, NULL); - while(cat) { + while (cat) { if (strcasecmp(cat, "general") && strcasecmp(cat, "authentication")) { utype = ast_variable_retrieve(cfg, cat, "type"); if (utype) { @@ -11219,7 +11143,6 @@ static char *app_sipaddheader = "SIPAddHeader"; static char *synopsis_sipaddheader = "Add a SIP header to the outbound call"; - static char *descrip_sipaddheader = "" " SIPAddHeader(Header: Content)\n" "Adds a header to a SIP call placed with DIAL.\n" @@ -11520,12 +11443,12 @@ /*--- sip_reload: Force reload of module from cli ---*/ static int sip_reload(int fd, int argc, char *argv[]) { - ast_mutex_lock(&sip_reload_lock); if (sip_reloading) { ast_verbose("Previous SIP reload not yet done\n"); - } else + } else { sip_reloading = 1; + } ast_mutex_unlock(&sip_reload_lock); restart_monitor(); @@ -11553,12 +11476,9 @@ { { "sip", "debug", "peer", NULL }, sip_do_debug, "Enable SIP debugging on Peername", debug_usage, complete_sip_debug_peer }, { { "sip", "show", "peer", NULL }, sip_show_peer, "Show details on specific SIP peer", show_peer_usage, complete_sip_show_peer }, { { "sip", "show", "peers", NULL }, sip_show_peers, "Show defined SIP peers", show_peers_usage }, - { { "sip", "prune", "realtime", NULL }, sip_prune_realtime, - "Prune cached Realtime object(s)", prune_realtime_usage }, - { { "sip", "prune", "realtime", "peer", NULL }, sip_prune_realtime, - "Prune cached Realtime peer(s)", prune_realtime_usage, complete_sip_prune_realtime_peer }, - { { "sip", "prune", "realtime", "user", NULL }, sip_prune_realtime, - "Prune cached Realtime user(s)", prune_realtime_usage, complete_sip_prune_realtime_user }, + { { "sip", "prune", "realtime", NULL }, sip_prune_realtime, "Prune cached Realtime object(s)", prune_realtime_usage }, + { { "sip", "prune", "realtime", "peer", NULL }, sip_prune_realtime, "Prune cached Realtime peer(s)", prune_realtime_usage, complete_sip_prune_realtime_peer }, + { { "sip", "prune", "realtime", "user", NULL }, sip_prune_realtime, "Prune cached Realtime user(s)", prune_realtime_usage, complete_sip_prune_realtime_user }, { { "sip", "show", "inuse", NULL }, sip_show_inuse, "List all inuse/limits", show_inuse_usage }, { { "sip", "show", "registry", NULL }, sip_show_registry, "Show SIP registration status", show_reg_usage }, { { "sip", "history", NULL }, sip_do_history, "Enable SIP history", history_usage }, @@ -11612,11 +11532,11 @@ /* Register manager commands */ ast_manager_register2("SIPpeers", EVENT_FLAG_SYSTEM, manager_sip_show_peers, - "List SIP peers (text format)", mandescr_show_peers); + "List SIP peers (text format)", mandescr_show_peers); ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM, manager_sip_show_peer, - "Show SIP peer (text format)", mandescr_show_peer); + "Show SIP peer (text format)", mandescr_show_peer); - sip_poke_all_peers(); + sip_poke_all_peers(); sip_send_all_registers(); /* And start the monitor for the first time */ @@ -11725,5 +11645,3 @@ { return (char *) desc; } - -