#include "asterisk.h"
#include <ctype.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/signal.h>
#include <regex.h>
#include <time.h>
#include "asterisk/network.h"
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/channel.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/app.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "asterisk/features.h"
#include "asterisk/srv.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj.h"
#include "asterisk/astobj2.h"
#include "asterisk/dnsmgr.h"
#include "asterisk/devicestate.h"
#include "asterisk/linkedlists.h"
#include "asterisk/stringfields.h"
#include "asterisk/monitor.h"
#include "asterisk/netsock.h"
#include "asterisk/localtime.h"
#include "asterisk/abstract_jb.h"
#include "asterisk/threadstorage.h"
#include "asterisk/translate.h"
#include "asterisk/ast_version.h"
#include "asterisk/event.h"
#include "asterisk/tcptls.h"
#include "asterisk/strings.h"

Go to the source code of this file.
Data Structures | |
| struct | __show_chan_arg |
| argument for the 'show channels|subscriptions' callback. More... | |
| struct | _map_x_s |
| generic struct to map between strings and integers. Fill it with x-s pairs, terminate with an entry with s = NULL; Then you can call map_x_s(...) to map an integer to a string, and map_s_x() for the string -> integer mapping. More... | |
| struct | ast_register_list |
| The register list: Other SIP proxies we register with and place calls to. More... | |
| struct | ast_subscription_mwi_list |
| The MWI subscription list. More... | |
| struct | cfsip_methods |
| The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type. More... | |
| struct | cfsip_options |
| List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly. More... | |
| struct | cfsubscription_types |
Subscription types that we support. We support
| |
| struct | domain |
| Domain data structure. More... | |
| struct | domain_list |
| struct | find_call_cb_arg |
| argument to the helper function to identify a call More... | |
| struct | invstate2stringtable |
| Readable descriptions of device states. More... | |
| struct | offered_media |
| struct | request_queue |
| struct | sip_auth |
| sip_auth: Credentials for authentication to other SIP services More... | |
| struct | sip_dual |
| structure used in transfers More... | |
| struct | sip_history |
| sip_history: Structure for saving transactions within a SIP dialog More... | |
| struct | sip_history_head |
| struct | sip_invite_param |
| Parameters to the transmit_invite function. More... | |
| struct | sip_mailbox |
| A peer's mailbox. More... | |
| struct | sip_peer |
| Structure for SIP peer data, we place calls to peers if registered or fixed IP address (host). More... | |
| struct | sip_pkt |
| sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are linked in a list, whose head is in the struct sip_pvt they belong to. Each packet holds a reference to the parent struct sip_pvt. This structure is allocated in __sip_reliable_xmit() and only for packets that require retransmissions. More... | |
| struct | sip_proxy |
| definition of a sip proxy server More... | |
| struct | sip_pvt |
| Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized by sip_alloc(), the descriptor goes into the list of descriptors (dialoglist). More... | |
| struct | sip_refer |
| Structure to handle SIP transfers. Dynamically allocated when needed. More... | |
| struct | sip_registry |
| Registrations with other SIP proxies. More... | |
| struct | sip_request |
| sip_request: The data grabbed from the UDP socket More... | |
| struct | sip_route |
| Structure to save routing information for a SIP session. More... | |
| struct | sip_settings |
| a place to store all global settings for the sip channel driver These are settings that will be possibly to apply on a group level later on. More... | |
| struct | sip_socket |
| The SIP socket definition. More... | |
| struct | sip_st_cfg |
| Structure that encapsulates all attributes related to configuration of SIP Session-Timers feature on a per user/peer basis. More... | |
| struct | sip_st_dlg |
| Structure that encapsulates all attributes related to running SIP Session-Timers feature on a per dialog basis. More... | |
| struct | sip_subscription_mwi |
| Definition of an MWI subscription to another server. More... | |
| struct | sip_threadinfo |
| Definition of a thread that handles a socket. More... | |
| struct | t38properties |
| T.38 channel settings (at some point we need to make this alloc'ed. More... | |
| struct | tcptls_packet |
Defines | |
| #define | ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO" |
| SIP Methods we support. | |
| #define | append_history(p, event, fmt, args...) append_history_full(p, "%-15s " fmt, event, ## args) |
| Append to SIP dialog history. | |
| #define | CALLERID_UNKNOWN "Anonymous" |
| #define | CHECK_AUTH_BUF_INITLEN 256 |
| #define | check_request_transport(peer, tmpl) |
| generic function for determining if a correct transport is being used to contact a peer | |
| #define | DEFAULT_DEFAULT_EXPIRY 120 |
| #define | DEFAULT_EXPIRY 900 |
| #define | DEFAULT_FREQ_NOTOK 10 * 1000 |
| #define | DEFAULT_MAX_EXPIRY 3600 |
| #define | DEFAULT_MAX_FORWARDS "70" |
| #define | DEFAULT_MAX_SE 1800 |
| #define | DEFAULT_MAXMS 2000 |
| #define | DEFAULT_MIN_EXPIRY 60 |
| #define | DEFAULT_MIN_SE 90 |
| #define | DEFAULT_MWI_EXPIRY 3600 |
| #define | DEFAULT_QUALIFY_GAP 100 |
| #define | DEFAULT_QUALIFY_PEERS 1 |
| #define | DEFAULT_QUALIFYFREQ 60 * 1000 |
| #define | DEFAULT_REGISTRATION_TIMEOUT 20 |
| #define | DEFAULT_RETRANS 1000 |
| #define | DEFAULT_TIMER_T1 500 |
| #define | DEFAULT_TRANS_TIMEOUT -1 |
| #define | EXPIRY_GUARD_LIMIT 30 |
| #define | EXPIRY_GUARD_MIN 500 |
| #define | EXPIRY_GUARD_PCT 0.20 |
| #define | EXPIRY_GUARD_SECS 15 |
| #define | FALSE 0 |
| #define | FINDALLDEVICES (FINDUSERS | FINDPEERS) |
| #define | FINDPEERS (1 << 1) |
| #define | FINDUSERS (1 << 0) |
| #define | FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" |
| #define | FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" |
| #define | FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u\n" |
| #define | FORMAT "%-30.30s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" |
| #define | FORMAT "%-40.40s %-20.20s %-16.16s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
| #define | FORMAT "%-30.30s %-6d %-9.9s %-6.6s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-6.6s\n" |
| #define | FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" |
| #define | FORMAT2 "%-30.30s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" |
| #define | FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %s\n" |
| #define | FORMAT2 "%-30.30s %3.6s %9.9s %6.6s\n" |
| #define | FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT3 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n" |
| #define | FORMAT4 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n" |
| #define | FROMDOMAIN_INVALID "anonymous.invalid" |
| #define | INITIAL_CSEQ 101 |
| #define | IS_SIP_TECH(t) ((t) == &sip_tech || (t) == &sip_tech_info) |
| #define | MAX_AUTHTRIES 3 |
| #define | MAX_HISTORY_ENTRIES 50 |
| #define | MAX_RETRANS 6 |
| #define | NO_RTP 0 |
| #define | NOT_SUPPORTED 0 |
| #define | PROVIS_KEEPALIVE_TIMEOUT 60000 |
| #define | RTP 1 |
| #define | SDP_MAX_RTPMAP_CODECS 32 |
| #define | SIP_MAX_HEADERS 64 |
| #define | SIP_MAX_LINES 256 |
| #define | SIP_MIN_PACKET 4096 |
| #define | SIP_OPT_100REL (1 << 1) |
| #define | SIP_OPT_EARLY_SESSION (1 << 3) |
| #define | SIP_OPT_EVENTLIST (1 << 11) |
| #define | SIP_OPT_FROMCHANGE (1 << 17) |
| #define | SIP_OPT_GRUU (1 << 12) |
| #define | SIP_OPT_HISTINFO (1 << 15) |
| #define | SIP_OPT_JOIN (1 << 4) |
| #define | SIP_OPT_NOREFERSUB (1 << 14) |
| #define | SIP_OPT_OUTBOUND (1 << 20) |
| #define | SIP_OPT_PATH (1 << 5) |
| #define | SIP_OPT_PRECONDITION (1 << 7) |
| #define | SIP_OPT_PREF (1 << 6) |
| #define | SIP_OPT_PRIVACY (1 << 8) |
| #define | SIP_OPT_RECLISTINV (1 << 18) |
| #define | SIP_OPT_RECLISTSUB (1 << 19) |
| #define | SIP_OPT_REPLACES (1 << 0) |
| #define | SIP_OPT_RESPRIORITY (1 << 16) |
| #define | SIP_OPT_SDP_ANAT (1 << 9) |
| #define | SIP_OPT_SEC_AGREE (1 << 10) |
| #define | SIP_OPT_TARGET_DIALOG (1 << 13) |
| #define | SIP_OPT_TIMER (1 << 2) |
| #define | SIP_OPT_UNKNOWN (1 << 21) |
| #define | sip_pvt_lock(x) ao2_lock(x) |
| #define | sip_pvt_trylock(x) ao2_trylock(x) |
| #define | sip_pvt_unlock(x) ao2_unlock(x) |
| #define | SIP_RESERVED ";/?:@&=+$,# " |
| #define | SIP_TRANS_TIMEOUT 64 * DEFAULT_TIMER_T1 |
| #define | SIPBUFSIZE 512 |
| #define | STANDARD_SIP_PORT 5060 |
| Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS. | |
| #define | STANDARD_TLS_PORT 5061 |
| Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS. | |
| #define | SUPPORTED 1 |
| #define | TRUE 1 |
| #define | UNLINK(element, head, prev) |
| #define | XMIT_ERROR -2 |
DefaultValues Default values, set and reset in reload_config before reading configuration | |
| |
| #define | DEFAULT_ALLOW_EXT_DOM TRUE |
| #define | DEFAULT_ALLOWGUEST TRUE |
| #define | DEFAULT_ALWAYSAUTHREJECT FALSE |
| #define | DEFAULT_AUTOCREATEPEER FALSE |
| #define | DEFAULT_CALLCOUNTER FALSE |
| #define | DEFAULT_CALLERID "asterisk" |
| #define | DEFAULT_CALLEVENTS FALSE |
| #define | DEFAULT_COMPACTHEADERS FALSE |
| #define | DEFAULT_CONTEXT "default" |
| #define | DEFAULT_COS_AUDIO 5 |
| #define | DEFAULT_COS_SIP 4 |
| #define | DEFAULT_COS_TEXT 5 |
| #define | DEFAULT_COS_VIDEO 6 |
| #define | DEFAULT_MATCHEXTERNIPLOCALLY FALSE |
| #define | DEFAULT_MAX_CALL_BITRATE (384) |
| #define | DEFAULT_MOHINTERPRET "default" |
| #define | DEFAULT_MOHSUGGEST "" |
| #define | DEFAULT_NOTIFYCID DISABLED |
| #define | DEFAULT_NOTIFYMIME "application/simple-message-summary" |
| #define | DEFAULT_NOTIFYRINGING TRUE |
| #define | DEFAULT_PEDANTIC FALSE |
| #define | DEFAULT_QUALIFY FALSE |
| #define | DEFAULT_REALM "asterisk" |
| #define | DEFAULT_REGEXTENONQUALIFY FALSE |
| #define | DEFAULT_RTPKEEPALIVE 0 |
| #define | DEFAULT_SDPOWNER "root" |
| #define | DEFAULT_SDPSESSION "Asterisk PBX" |
| #define | DEFAULT_SRVLOOKUP TRUE |
| #define | DEFAULT_T1MIN 100 |
| #define | DEFAULT_TOS_AUDIO 0 |
| #define | DEFAULT_TOS_SIP 0 |
| #define | DEFAULT_TOS_TEXT 0 |
| #define | DEFAULT_TOS_VIDEO 0 |
| #define | DEFAULT_USERAGENT "Asterisk PBX" |
| #define | DEFAULT_VMEXTEN "asterisk" |
SIPflags | |
Various flags for the flags field in the pvt structure Trying to sort these up (one or more of the following): D: Dialog P: Peer/user G: Global flag When flags are used by multiple structures, it is important that they have a common layout so it is easy to copy them. | |
| #define | SIP_CALL_LIMIT (1 << 7) |
| #define | SIP_DEFER_BYE_ON_TRANSFER (1 << 10) |
| #define | SIP_DIRECT_MEDIA (1 << 20) |
| #define | SIP_DIRECT_MEDIA_NAT (2 << 20) |
| #define | SIP_DTMF (7 << 15) |
| #define | SIP_DTMF_AUTO (3 << 15) |
| #define | SIP_DTMF_INBAND (1 << 15) |
| #define | SIP_DTMF_INFO (2 << 15) |
| #define | SIP_DTMF_RFC2833 (0 << 15) |
| #define | SIP_DTMF_SHORTINFO (4 << 15) |
| #define | SIP_FLAGS_TO_COPY |
| Flags to copy from peer/user to dialog. | |
| #define | SIP_G726_NONSTANDARD (1 << 31) |
| #define | SIP_GOTREFER (1 << 6) |
| #define | SIP_INC_COUNT (1 << 8) |
| #define | SIP_INC_RINGING (1 << 9) |
| #define | SIP_INSECURE (3 << 23) |
| #define | SIP_INSECURE_INVITE (1 << 24) |
| #define | SIP_INSECURE_NONE (0 << 23) |
| #define | SIP_INSECURE_PORT (1 << 23) |
| #define | SIP_NAT (3 << 18) |
| #define | SIP_NAT_ALWAYS (3 << 18) |
| #define | SIP_NAT_NEVER (0 << 18) |
| #define | SIP_NAT_RFC3581 (1 << 18) |
| #define | SIP_NAT_ROUTE (2 << 18) |
| #define | SIP_NEEDREINVITE (1 << 4) |
| #define | SIP_OUTGOING (1 << 0) |
| #define | SIP_PENDINGBYE (1 << 5) |
| #define | SIP_PROG_INBAND (3 << 25) |
| #define | SIP_PROG_INBAND_NEVER (0 << 25) |
| #define | SIP_PROG_INBAND_NO (1 << 25) |
| #define | SIP_PROG_INBAND_YES (2 << 25) |
| #define | SIP_PROGRESS_SENT (1 << 3) |
| #define | SIP_PROMISCREDIR (1 << 11) |
| #define | SIP_REINVITE (7 << 20) |
| #define | SIP_REINVITE_NONE (0 << 20) |
| #define | SIP_REINVITE_UPDATE (4 << 20) |
| #define | SIP_RINGING (1 << 2) |
| #define | SIP_SENDRPID (1 << 29) |
| #define | SIP_TRUSTRPID (1 << 12) |
| #define | SIP_USECLIENTCODE (1 << 14) |
| #define | SIP_USEREQPHONE (1 << 13) |
SIPflags2 | |
a second page of flags (for flags[1] | |
| #define | SIP_PAGE2_ALLOWOVERLAP (1 << 17) |
| #define | SIP_PAGE2_ALLOWSUBSCRIBE (1 << 16) |
| #define | SIP_PAGE2_BUGGY_MWI (1 << 26) |
| #define | SIP_PAGE2_CALL_ONHOLD (3 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 23) |
| #define | SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 23) |
| #define | SIP_PAGE2_DIALOG_ESTABLISHED (1 << 27) |
| #define | SIP_PAGE2_FAX_DETECT (3 << 28) |
| #define | SIP_PAGE2_FAX_DETECT_BOTH (3 << 28) |
| #define | SIP_PAGE2_FAX_DETECT_CNG (1 << 28) |
| #define | SIP_PAGE2_FAX_DETECT_T38 (2 << 28) |
| #define | SIP_PAGE2_FLAGS_TO_COPY |
| #define | SIP_PAGE2_FORWARD_LOOP_DETECTED (1 << 8) |
| #define | SIP_PAGE2_HAVEPEERCONTEXT (1 << 3) |
| #define | SIP_PAGE2_IGNORESDPVERSION (1 << 19) |
| #define | SIP_PAGE2_REGISTERTRYING (1 << 29) |
| #define | SIP_PAGE2_RFC2833_COMPENSATE (1 << 25) |
| #define | SIP_PAGE2_RPORT_PRESENT (1 << 10) |
| #define | SIP_PAGE2_RTAUTOCLEAR (1 << 2) |
| #define | SIP_PAGE2_RTCACHEFRIENDS (1 << 0) |
| #define | SIP_PAGE2_STATECHANGEQUEUE (1 << 9) |
| #define | SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 18) |
| #define | SIP_PAGE2_T38SUPPORT (3 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_UDPTL (1 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_UDPTL_FEC (2 << 20) |
| #define | SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY (3 << 20) |
| #define | SIP_PAGE2_TEXTSUPPORT (1 << 15) |
| #define | SIP_PAGE2_UDPTL_DESTINATION (1 << 30) |
| #define | SIP_PAGE2_VIDEOSUPPORT (1 << 14) |
| #define | SIP_PAGE2_VIDEOSUPPORT_ALWAYS (1 << 31) |
Enumerations | |
| enum | can_create_dialog { CAN_NOT_CREATE_DIALOG, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD } |
| States whether a SIP message can create a dialog in Asterisk. More... | |
| enum | check_auth_result { AUTH_DONT_KNOW = -100, AUTH_SUCCESSFUL = 0, AUTH_CHALLENGE_SENT = 1, AUTH_SECRET_FAILED = -1, AUTH_USERNAME_MISMATCH = -2, AUTH_NOT_FOUND = -3, AUTH_FAKE_AUTH = -4, AUTH_UNKNOWN_DOMAIN = -5, AUTH_PEER_NOT_DYNAMIC = -6, AUTH_ACL_FAILED = -7, AUTH_BAD_TRANSPORT = -8 } |
| Authentication result from check_auth* functions. More... | |
| enum | invitestates { INV_NONE = 0, INV_CALLING = 1, INV_PROCEEDING = 2, INV_EARLY_MEDIA = 3, INV_COMPLETED = 4, INV_CONFIRMED = 5, INV_TERMINATED = 6, INV_CANCELLED = 7 } |
| States for the INVITE transaction, not the dialog. More... | |
| enum | media_type { SDP_AUDIO, SDP_VIDEO, SDP_IMAGE, SDP_TEXT } |
| enum | notifycid_setting { DISABLED = 0, ENABLED = 1, IGNORE_CONTEXT = 2 } |
| Settings for the 'notifycid' option, see sip.conf.sample for details. More... | |
| enum | parse_register_result { PARSE_REGISTER_DENIED, PARSE_REGISTER_FAILED, PARSE_REGISTER_UPDATE, PARSE_REGISTER_QUERY } |
| Results from the parse_register() function. More... | |
| enum | referstatus { REFER_IDLE, REFER_SENT, REFER_RECEIVED, REFER_CONFIRMED, REFER_ACCEPTED, REFER_RINGING, REFER_200OK, REFER_FAILED, REFER_NOAUTH } |
| Parameters to know status of transfer. More... | |
| enum | sip_auth_type { PROXY_AUTH = 407, WWW_AUTH = 401 } |
| Authentication types - proxy or www authentication. More... | |
| enum | sip_debug_e { sip_debug_none = 0, sip_debug_config = 1, sip_debug_console = 2 } |
| debugging state We store separately the debugging requests from the config file and requests from the CLI. Debugging is enabled if either is set (which means that if sipdebug is set in the config file, we can only turn it off by reloading the config). More... | |
| enum | sip_peer_type { SIP_TYPE_PEER = (1 << 0), SIP_TYPE_USER = (1 << 1) } |
| enum | sip_result { AST_SUCCESS = 0, AST_FAILURE = -1 } |
| The result of a lot of functions. More... | |
| enum | sip_tcptls_alert { TCPTLS_ALERT_DATA, TCPTLS_ALERT_STOP } |
| enum | sip_transport { SIP_TRANSPORT_UDP = 1, SIP_TRANSPORT_TCP = 1 << 1, SIP_TRANSPORT_TLS = 1 << 2 } |
| Define some implemented SIP transports. More... | |
| enum | sipmethod { SIP_UNKNOWN, SIP_RESPONSE, SIP_REGISTER, SIP_OPTIONS, SIP_NOTIFY, SIP_INVITE, SIP_ACK, SIP_PRACK, SIP_BYE, SIP_REFER, SIP_SUBSCRIBE, SIP_MESSAGE, SIP_UPDATE, SIP_INFO, SIP_CANCEL, SIP_PUBLISH, SIP_PING } |
| SIP Request methods known by Asterisk. More... | |
| enum | sipregistrystate { REG_STATE_UNREGISTERED = 0, REG_STATE_REGSENT, REG_STATE_AUTHSENT, REG_STATE_REGISTERED, REG_STATE_REJECTED, REG_STATE_TIMEOUT, REG_STATE_NOAUTH, REG_STATE_FAILED } |
| States for outbound registrations (with register= lines in sip.conf. More... | |
| enum | st_mode { SESSION_TIMER_MODE_INVALID = 0, SESSION_TIMER_MODE_ACCEPT, SESSION_TIMER_MODE_ORIGINATE, SESSION_TIMER_MODE_REFUSE } |
| Modes in which Asterisk can be configured to run SIP Session-Timers. More... | |
| enum | st_refresher { SESSION_TIMER_REFRESHER_AUTO, SESSION_TIMER_REFRESHER_UAC, SESSION_TIMER_REFRESHER_UAS } |
| The entity playing the refresher role for Session-Timers. More... | |
| enum | subscriptiontype { NONE = 0, XPIDF_XML, DIALOG_INFO_XML, CPIM_PIDF_XML, PIDF_XML, MWI_NOTIFICATION } |
| Type of subscription, based on the packages we do support, see subscription_types. More... | |
| enum | t38_action_flag { SDP_T38_NONE = 0, SDP_T38_INITIATE, SDP_T38_ACCEPT } |
| enum | t38state { T38_DISABLED = 0, T38_LOCAL_REINVITE, T38_PEER_REINVITE, T38_ENABLED } |
| T38 States for a call. More... | |
| enum | transfermodes { TRANSFER_OPENFORALL, TRANSFER_CLOSED } |
| Authorization scheme for call transfers. More... | |
| enum | xmittype { XMIT_CRITICAL = 2, XMIT_RELIABLE = 1, XMIT_UNRELIABLE = 0 } |
| When sending a SIP message, we can send with a few options, depending on type of SIP request. UNRELIABLE is moslty used for responses to repeated requests, where the original response would be sent RELIABLE in an INVITE transaction. More... | |
Functions | |
| static const char * | __get_header (const struct sip_request *req, const char *name, int *start) |
| static void | __init_check_auth_buf (void) |
| static void | __init_ts_temp_pvt (void) |
| A per-thread temporary pvt structure. | |
| static void | __reg_module (void) |
| static int | __set_address_from_contact (const char *fullcontact, struct sockaddr_in *sin, int tcp) |
| static int | __sip_ack (struct sip_pvt *p, int seqno, int resp, int sipmethod) |
| Acknowledges receipt of a packet and stops retransmission called with p locked. | |
| static int | __sip_autodestruct (const void *data) |
| Kill a SIP dialog (called only by the scheduler) The scheduler has a reference to this dialog when p->autokillid != -1, and we are called using that reference. So if the event is not rescheduled, we need to call dialog_unref(). | |
| static void | __sip_destroy (struct sip_pvt *p, int lockowner, int lockdialoglist) |
| Execute destruction of SIP dialog structure, release memory. | |
| static int | __sip_do_register (struct sip_registry *r) |
| Register with SIP proxy. | |
| static void | __sip_pretend_ack (struct sip_pvt *p) |
| Pretend to ack all packets called with p locked. | |
| static int | __sip_reliable_xmit (struct sip_pvt *p, int seqno, int resp, struct ast_str *data, int len, int fatal, int sipmethod) |
| Transmit packet with retransmits. | |
| static int | __sip_semi_ack (struct sip_pvt *p, int seqno, int resp, int sipmethod) |
| Acks receipt of packet, keep it around (used for provisional responses). | |
| static int | __sip_subscribe_mwi_do (struct sip_subscription_mwi *mwi) |
| Actually setup an MWI subscription or resubscribe. | |
| static int | __sip_xmit (struct sip_pvt *p, struct ast_str *data, int len) |
| Transmit SIP message Sends a SIP request or response on a given socket (in the pvt) Called by retrans_pkt, send_request, send_response and __sip_reliable_xmit. | |
| static int | __transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Base transmit response function. | |
| static void | __unreg_module (void) |
| static char * | _sip_qualify_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Send qualify message to peer from cli or manager. Mostly for debugging. | |
| static char * | _sip_show_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Show one peer in detail (main function). | |
| static char * | _sip_show_peers (int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Execute sip show peers command. | |
| static void * | _sip_tcp_helper_thread (struct sip_pvt *pvt, struct ast_tcptls_session_instance *tcptls_session) |
| SIP TCP thread management function This function reads from the socket, parses the packet into a request. | |
| static int | acf_channel_read (struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen) |
| static void | add_blank (struct sip_request *req) |
| add a blank line if no body | |
| static void | add_codec_to_sdp (const struct sip_pvt *p, int codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_content (struct sip_request *req, const char *line) |
| Add content (not header) to SIP message. | |
| static int | add_digit (struct sip_request *req, char digit, unsigned int duration, int mode) |
| Add DTMF INFO tone to sip message Mode = 0 for application/dtmf-relay (Cisco) 1 for application/dtmf. | |
| static int | add_header (struct sip_request *req, const char *var, const char *value) |
| Add header to SIP message. | |
| static void | add_noncodec_to_sdp (const struct sip_pvt *p, int format, struct ast_str **m_buf, struct ast_str **a_buf, int debug) |
| Add RFC 2833 DTMF offer to SDP. | |
| static void | add_peer_mailboxes (struct sip_peer *peer, const char *value) |
| static void | add_peer_mwi_subs (struct sip_peer *peer) |
| static struct sip_auth * | add_realm_authentication (struct sip_auth *authlist, const char *configuration, int lineno) |
| Add realm authentication in list. | |
| static void | add_route (struct sip_request *req, struct sip_route *route) |
| Add route header into request per learned route. | |
| static enum sip_result | add_sdp (struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38) |
| Add Session Description Protocol message. | |
| static int | add_sip_domain (const char *domain, const enum domain_mode mode, const char *context) |
| Add SIP domain to list of domains we are responsible for. | |
| static int | add_supported_header (struct sip_pvt *pvt, struct sip_request *req) |
| Add "Supported" header to sip message. Since some options may be disabled in the config, the sip_pvt must be inspected to determine what is supported for this dialog. | |
| static void | add_tcodec_to_sdp (const struct sip_pvt *p, int codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add text codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_text (struct sip_request *req, const char *text) |
| Add text body to SIP message. | |
| static struct ast_variable * | add_var (const char *buf, struct ast_variable *list) |
| implement the setvar config line | |
| static void | add_vcodec_to_sdp (const struct sip_pvt *p, int codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add video codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_vidupdate (struct sip_request *req) |
| add XML encoded media control with update | |
| static void | append_date (struct sip_request *req) |
| Append date to SIP message. | |
| static void | append_history_full (struct sip_pvt *p, const char *fmt,...) |
| Append to SIP dialog history with arg list. | |
| static void | append_history_va (struct sip_pvt *p, const char *fmt, va_list ap) |
| Append to SIP dialog history with arg list. | |
| static void | ast_quiet_chan (struct ast_channel *chan) |
| Turn off generator data XXX Does this function belong in the SIP channel? | |
| static void | ast_sip_ouraddrfor (struct in_addr *them, struct sockaddr_in *us, struct sip_pvt *p) |
| NAT fix - decide which IP address to use for Asterisk server? | |
| static int | attempt_transfer (struct sip_dual *transferer, struct sip_dual *target) |
| Attempt transfer of SIP call This fix for attended transfers on a local PBX. | |
| static void | auth_headers (enum sip_auth_type code, char **header, char **respheader) |
| return the request and response heade for a 401 or 407 code | |
| static int | auto_congest (const void *arg) |
| Scheduled congestion on a call. Only called by the scheduler, must return the reference when done. | |
| static void | build_callid_pvt (struct sip_pvt *pvt) |
| Build SIP Call-ID value for a non-REGISTER transaction. | |
| static void | build_callid_registry (struct sip_registry *reg, struct in_addr ourip, const char *fromdomain) |
| Build SIP Call-ID value for a REGISTER transaction. | |
| static void | build_contact (struct sip_pvt *p) |
| Build contact header - the contact header we send out. | |
| static struct sip_peer * | build_peer (const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime, int devstate_only) |
| Build peer from configuration (file or realtime static/dynamic). | |
| static int | build_reply_digest (struct sip_pvt *p, int method, char *digest, int digest_len) |
| Build reply digest. | |
| static void | build_route (struct sip_pvt *p, struct sip_request *req, int backwards) |
| Build route list from Record-Route header. | |
| static void | build_rpid (struct sip_pvt *p) |
| Build the Remote Party-ID & From using callingpres options. | |
| static void | build_via (struct sip_pvt *p) |
| Build a Via header for a request. | |
| static int | cb_extensionstate (char *context, char *exten, int state, void *data) |
| Callback for the devicestate notification (SUBSCRIBE) support subsystem. | |
| static void | change_hold_state (struct sip_pvt *dialog, struct sip_request *req, int holdstate, int sendonly) |
| Change hold state for a call. | |
| static void | change_t38_state (struct sip_pvt *p, int state) |
| Change the T38 state on a SIP dialog. | |
| static enum check_auth_result | check_auth (struct sip_pvt *p, struct sip_request *req, const char *username, const char *secret, const char *md5secret, int sipmethod, char *uri, enum xmittype reliable, int ignore) |
| Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set). | |
| static enum check_auth_result | check_peer_ok (struct sip_pvt *p, char *of, struct sip_request *req, int sipmethod, struct sockaddr_in *sin, struct sip_peer **authpeer, enum xmittype reliable, char *rpid_num, char *calleridname, char *uri2) |
| Validate device authentication. | |
| static void | check_pendings (struct sip_pvt *p) |
| Check pending actions on SIP call. | |
| static void | check_rtp_timeout (struct sip_pvt *dialog, time_t t) |
| helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked | |
| static int | check_sip_domain (const char *domain, char *context, size_t len) |
| check_sip_domain: Check if domain part of uri is local to our server | |
| static int | check_user (struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, enum xmittype reliable, struct sockaddr_in *sin) |
| Find user If we get a match, this will add a reference pointer to the user object in ASTOBJ, that needs to be unreferenced. | |
| static enum check_auth_result | check_user_full (struct sip_pvt *p, struct sip_request *req, int sipmethod, char *uri, enum xmittype reliable, struct sockaddr_in *sin, struct sip_peer **authpeer) |
| Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests. | |
| static void | check_via (struct sip_pvt *p, struct sip_request *req) |
| check Via: header for hostname, port and rport request/answer | |
| static attribute_unused void | check_via_response (struct sip_pvt *p, struct sip_request *req) |
| check received= and rport= in a SIP response. If we get a response with received= and/or rport= in the Via: line, use them as 'p->ourip' (see RFC 3581 for rport, and RFC 3261 for received). Using these two fields SIP can produce the correct address and port in the SIP headers without the need for STUN. The address part is also reused for the media sessions. Note that ast_sip_ouraddrfor() still rewrites p->ourip if you specify externip/seternaddr/stunaddr. | |
| static void | cleanup_stale_contexts (char *new, char *old) |
| Destroy disused contexts between reloads Only used in reload_config so the code for regcontext doesn't get ugly. | |
| static void | clear_peer_mailboxes (struct sip_peer *peer) |
| static int | clear_realm_authentication (struct sip_auth *authlist) |
| Clear realm authentication list (at reload). | |
| static void | clear_sip_domains (void) |
| Clear our domain list (at reload). | |
| static const char * | cli_yesno (int x) |
| return Yes or No depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point). | |
| static char * | complete_sip_peer (const char *word, int state, int flags2) |
| Do completion on peer name. | |
| static char * | complete_sip_registered_peer (const char *word, int state, int flags2) |
| Do completion on registered peer name. | |
| static char * | complete_sip_show_history (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show history' CLI. | |
| static char * | complete_sip_show_peer (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show peer' CLI. | |
| static char * | complete_sip_show_user (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show user' CLI. | |
| static char * | complete_sip_unregister (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip unregister' CLI. | |
| static char * | complete_sip_user (const char *word, int state) |
| Do completion on user name. | |
| static char * | complete_sipch (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show channel' and 'sip show history' CLI This is in charge of generating all strings that match a prefix in the given position. As many functions of this kind, each invokation has O(state) time complexity so be careful in using it. | |
| static char * | complete_sipnotify (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip notify' CLI. | |
| static int | copy_all_header (struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy all headers from one request to another. | |
| static int | copy_header (struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy one header field from one request to another. | |
| static void | copy_request (struct sip_request *dst, const struct sip_request *src) |
| copy SIP request (mostly used to save request for responses) | |
| static void | copy_socket_data (struct sip_socket *to_sock, const struct sip_socket *from_sock) |
| static struct ast_variable * | copy_vars (struct ast_variable *src) |
| static int | copy_via_headers (struct sip_pvt *p, struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy SIP VIA Headers from the request to the response. | |
| static int | create_addr (struct sip_pvt *dialog, const char *opeer, struct sockaddr_in *sin, int newdialog) |
| create address structure from device name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success | |
| static int | create_addr_from_peer (struct sip_pvt *dialog, struct sip_peer *peer) |
| Create address structure from peer reference. This function copies data from peer to the dialog, so we don't have to look up the peer again from memory or database during the life time of the dialog. | |
| static void | deinit_req (struct sip_request *req) |
| Deinitialize SIP response/request. | |
| static void | destroy_association (struct sip_peer *peer) |
| Remove registration data from realtime database or AST/DB when registration expires. | |
| static void | destroy_mailbox (struct sip_mailbox *mailbox) |
| static int | determine_firstline_parts (struct sip_request *req) |
| Parse first line of incoming SIP request. | |
| static int | dialog_cmp_cb (void *obj, void *arg, int flags) |
| static int | dialog_dump_func (void *userobj, void *arg, int flags) |
| static int | dialog_hash_cb (const void *obj, const int flags) |
| static int | dialog_needdestroy (void *dialogobj, void *arg, int flags) |
| Match dialogs that need to be destroyed. | |
| static struct sip_pvt * | dialog_ref (struct sip_pvt *p, char *tag) |
| when we create or delete references, make sure to use these functions so we keep track of the refcounts. To simplify the code, we allow a NULL to be passed to dialog_unref(). | |
| static void * | dialog_unlink_all (struct sip_pvt *dialog, int lockowner, int lockdialoglist) |
| Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored. | |
| static struct sip_pvt * | dialog_unref (struct sip_pvt *p, char *tag) |
| static int | do_magic_pickup (struct ast_channel *channel, const char *extension, const char *context) |
| static void * | do_monitor (void *data) |
| The SIP monitoring thread. | |
| static int | do_proxy_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init) |
| Add authentication on outbound SIP packet. | |
| static int | do_register_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code) |
| Authenticate for outbound registration. | |
| static void | do_setnat (struct sip_pvt *p, int natflags) |
| Set nat mode on the various data sockets. | |
| static const char * | domain_mode_to_text (const enum domain_mode mode) |
| Print domain mode to cli. | |
| static const char * | dtmfmode2str (int mode) |
| Convert DTMF mode to printable string. | |
| static int | expire_register (const void *data) |
| Expire registration of SIP peer. | |
| static void | extract_uri (struct sip_pvt *p, struct sip_request *req) |
| Check Contact: URI of SIP message. | |
| static const char * | faxec2str (int faxec) |
| static int | finalize_content (struct sip_request *req) |
| Add 'Content-Length' header and content to SIP message. | |
| static const char * | find_alias (const char *name, const char *_default) |
| Find compressed SIP alias. | |
| static int | find_by_name (void *obj, void *arg, void *data, int flags) |
| static struct sip_pvt * | find_call (struct sip_request *req, struct sockaddr_in *sin, const int intended_method) |
| find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_incoming(), sipsock_read | |
| static int | find_call_cb (void *__pvt, void *__arg, int flags) |
| static int | find_calling_channel (struct ast_channel *c, void *data) |
| static const char * | find_closing_quote (const char *start, const char *lim) |
| Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote. | |
| static struct sip_peer * | find_peer (const char *peer, struct sockaddr_in *sin, int realtime, int which_objects, int devstate_only, int transport) |
| Locate device by name or ip address. | |
| static struct sip_auth * | find_realm_authentication (struct sip_auth *authlist, const char *realm) |
| Find authentication for a specific realm. | |
| static int | find_sdp (struct sip_request *req) |
| Determine whether a SIP message contains an SDP in its body. | |
| static int | find_sip_method (const char *msg) |
| find_sip_method: Find SIP method from header | |
| static struct cfsubscription_types * | find_subscription_type (enum subscriptiontype subtype) |
| Find subscription type in array. | |
| static void | free_old_route (struct sip_route *route) |
| Remove route from route list. | |
| static int | func_check_sipdomain (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Dial plan function to check if domain is local. | |
| static int | func_header_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| Read SIP header (dialplan function). | |
| static int | function_sipchaninfo_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| ${SIPCHANINFO()} Dialplan function - reads sip channel data | |
| static int | function_sippeer (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| ${SIPPEER()} Dialplan function - reads peer data | |
| static char * | generate_random_string (char *buf, size_t size) |
| Generate 32 byte random string for callid's etc. | |
| static int | get_also_info (struct sip_pvt *p, struct sip_request *oreq) |
| Call transfer support (old way, deprecated by the IETF). | |
| static char * | get_body (struct sip_request *req, char *name, char delimiter) |
| Get a specific line from the message body. | |
| static char * | get_body_by_line (const char *line, const char *name, int nameLen, char delimiter) |
| Reads one line of SIP message body. | |
| static int | get_cached_mwi (struct sip_peer *peer, int *new, int *old) |
| Get cached MWI info. | |
| static char * | get_calleridname (const char *input, char *output, size_t outputsize) |
| Get caller id name from SIP headers. | |
| static int | get_destination (struct sip_pvt *p, struct sip_request *oreq) |
| Find out who the call is for. We use the request uri as a destination. This code assumes authentication has been done, so that the device (peer/user) context is already set. | |
| static const char * | get_header (const struct sip_request *req, const char *name) |
| Get header from SIP request. | |
| static char * | get_in_brackets (char *tmp) |
| Pick out text in brackets from character string. | |
| static struct ast_variable * | get_insecure_variable_from_config (struct ast_config *config) |
| static int | get_ip_and_port_from_sdp (struct sip_request *req, const enum media_type media, struct sockaddr_in *sin) |
| static int | get_msg_text (char *buf, int len, struct sip_request *req, int addnewline) |
| Get text out of a SIP MESSAGE packet. | |
| static const char * | get_name_from_variable (struct ast_variable *var, const char *newpeername) |
| static void | get_our_media_address (struct sip_pvt *p, int needvideo, struct sockaddr_in *sin, struct sockaddr_in *vsin, struct sockaddr_in *tsin, struct sockaddr_in *dest, struct sockaddr_in *vdest) |
| Set all IP media addresses for this call. | |
| static int | get_rdnis (struct sip_pvt *p, struct sip_request *oreq) |
| Get referring dnis. | |
| static int | get_refer_info (struct sip_pvt *transferer, struct sip_request *outgoing_req) |
| Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure. | |
| static int | get_rpid_num (const char *input, char *output, int maxlen) |
| Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found. | |
| static const char * | get_sdp_iterate (int *start, struct sip_request *req, const char *name) |
| Lookup 'name' in the SDP starting at the 'start' line. Returns the matching line, and 'start' is updated with the next line number. | |
| static char | get_sdp_line (int *start, int stop, struct sip_request *req, const char **value) |
| Fetches the next valid SDP line between the 'start' line (inclusive) and the 'stop' line (exclusive). Returns the type ('a', 'c', ...) and matching line in reference 'start' is updated with the next line number. | |
| static struct sip_pvt * | get_sip_pvt_byid_locked (const char *callid, const char *totag, const char *fromtag) |
| Lock dialog lock and find matching pvt lock. | |
| static const char * | get_srv_protocol (enum sip_transport t) |
| Return protocol string for srv dns query. | |
| static const char * | get_srv_service (enum sip_transport t) |
| Return service string for srv dns query. | |
| static const char * | get_transport (enum sip_transport t) |
| Return transport as string. | |
| static const char * | get_transport_list (unsigned int transports) |
| Return configuration of transports for a device. | |
| static const char * | get_transport_pvt (struct sip_pvt *p) |
| Return transport of dialog. | |
| static int | get_transport_str2enum (const char *transport) |
| Return int representing a bit field of transport types found in const char *transport. | |
| static const char * | gettag (const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize) |
| Get tag from packet. | |
| static int | handle_common_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v) |
| Handle flag-type options common to configuration of devices - peers. | |
| static int | handle_incoming (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int *recount, int *nounlock) |
| Handle incoming SIP requests (methods). | |
| static int | handle_invite_replaces (struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *nounlock) |
| Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer. Used only once. XXX 'ignore' is unused. | |
| static int | handle_request_bye (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming BYE request. | |
| static int | handle_request_cancel (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming CANCEL request. | |
| static int | handle_request_do (struct sip_request *req, struct sockaddr_in *sin) |
| Handle incoming SIP message - request or response. | |
| static void | handle_request_info (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP INFO Message. | |
| static int | handle_request_invite (struct sip_pvt *p, struct sip_request *req, int debug, int seqno, struct sockaddr_in *sin, int *recount, char *e, int *nounlock) |
| Handle incoming INVITE request. | |
| static int | handle_request_message (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming MESSAGE request. | |
| static int | handle_request_notify (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e) |
| Handle incoming notifications. | |
| static int | handle_request_options (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming OPTIONS request An OPTIONS request should be answered like an INVITE from the same UA, including SDP. | |
| static int | handle_request_refer (struct sip_pvt *p, struct sip_request *req, int debug, int seqno, int *nounlock) |
| static int | handle_request_register (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, char *e) |
| Handle incoming REGISTER request. | |
| static int | handle_request_subscribe (struct sip_pvt *p, struct sip_request *req, struct sockaddr_in *sin, int seqno, char *e) |
| Handle incoming SUBSCRIBE request. | |
| static void | handle_response (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| Handle SIP response in dialogue. | |
| static void | handle_response_invite (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| Handle SIP response to INVITE dialogue. | |
| static void | handle_response_notify (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| static void | handle_response_peerpoke (struct sip_pvt *p, int resp, struct sip_request *req) |
| Handle qualification responses (OPTIONS). | |
| static void | handle_response_refer (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| static int | handle_response_register (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| Handle responses on REGISTER to services. | |
| static void | handle_response_subscribe (struct sip_pvt *p, int resp, char *rest, struct sip_request *req, int seqno) |
| static int | handle_t38_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v, int *maxdatagram) |
| Handle T.38 configuration options common to users and peers. | |
| static const char * | hangup_cause2sip (int cause) |
| Convert Asterisk hangup causes to SIP codes. | |
| static int | hangup_sip2cause (int cause) |
| Convert SIP hangup causes to Asterisk hangup causes. | |
| static int | init_req (struct sip_request *req, int sipmethod, const char *recip) |
| Initialize SIP request. | |
| static int | init_resp (struct sip_request *resp, const char *msg) |
| Initialize SIP response, based on SIP request. | |
| static void | initialize_initreq (struct sip_pvt *p, struct sip_request *req) |
| Initialize the initital request packet in the pvt structure. This packet is used for creating replies and future requests in a dialog. | |
| static void | initreqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod) |
| Initiate new SIP request to peer/user. | |
| static const char * | insecure2str (int mode) |
| Convert Insecure setting to printable string. | |
| static int | interpret_t38_parameters (struct sip_pvt *p, const struct ast_control_t38_parameters *parameters) |
| Helper function which updates T.38 capability information and triggers a reinvite. | |
| static void | list_route (struct sip_route *route) |
| List all routes - mostly for debugging. | |
| static int | load_module (void) |
| PBX load module - initialization. | |
| static int | local_attended_transfer (struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, int seqno) |
| Find all call legs and bridge transferee with target called from handle_request_refer. | |
| static int | lws2sws (char *msgbuf, int len) |
| Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled. | |
| static void | make_our_tag (char *tagbuf, size_t len) |
| Make our SIP dialog tag. | |
| static int | manager_show_registry (struct mansession *s, const struct message *m) |
| Show SIP registrations in the manager API. | |
| static int | manager_sip_qualify_peer (struct mansession *s, const struct message *m) |
| Qualify SIP peers in the manager API. | |
| static int | manager_sip_show_peer (struct mansession *s, const struct message *m) |
| Show SIP peers in the manager API. | |
| static int | manager_sip_show_peers (struct mansession *s, const struct message *m) |
| Show SIP peers in the manager API. | |
| static int | manager_sipnotify (struct mansession *s, const struct message *m) |
| static int | map_s_x (const struct _map_x_s *table, const char *s, int errorvalue) |
| map from a string to an integer value, case insensitive. If no match is found, return errorvalue. | |
| static const char * | map_x_s (const struct _map_x_s *table, int x, const char *errorstring) |
| map from an integer value to a string. If no match is found, return errorstring | |
| static int | method_match (enum sipmethod id, const char *name) |
| returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'. Strictly speaking, SIP methods are case SENSITIVE, but we do a case-insensitive comparison to be more tolerant. following Jon Postel's rule: Be gentle in what you accept, strict with what you send | |
| static void | mwi_event_cb (const struct ast_event *event, void *userdata) |
| Receive MWI events that we have subscribed to. | |
| static const char * | nat2str (int nat) |
| Convert NAT setting to text string. | |
| static struct sip_proxy * | obproxy_get (struct sip_pvt *dialog, struct sip_peer *peer) |
| Get default outbound proxy or global proxy. | |
| static void | parse_copy (struct sip_request *dst, const struct sip_request *src) |
| Copy SIP request, parse it. | |
| static int | parse_minse (const char *p_hdrval, int *const p_interval) |
| Session-Timers: Function for parsing Min-SE header. | |
| static void | parse_moved_contact (struct sip_pvt *p, struct sip_request *req) |
| Parse 302 Moved temporalily response. | |
| static int | parse_ok_contact (struct sip_pvt *pvt, struct sip_request *req) |
| Save contact header for 200 OK on INVITE. | |
| static enum parse_register_result | parse_register_contact (struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req) |
| Parse contact header and save registration (peer registration). | |
| static int | parse_request (struct sip_request *req) |
| Parse a SIP message. | |
| static int | parse_session_expires (const char *p_hdrval, int *const p_interval, enum st_refresher *const p_ref) |
| Session-Timers: Function for parsing Session-Expires header. | |
| static unsigned int | parse_sip_options (struct sip_pvt *pvt, const char *supported) |
| Parse supported header in incoming packet. | |
| static int | parse_uri (char *uri, const char *scheme, char **ret_name, char **pass, char **domain, char **port, char **options, char **transport) |
| * parses a URI in its components. | |
| static int | peer_cmp_cb (void *obj, void *arg, int flags) |
| static int | peer_dump_func (void *userobj, void *arg, int flags) |
| static int | peer_hash_cb (const void *obj, const int flags) |
| static int | peer_ipcmp_cb (void *obj, void *arg, int flags) |
| static int | peer_iphash_cb (const void *obj, const int flags) |
| static int | peer_is_marked (void *peerobj, void *arg, int flags) |
| static void | peer_mailboxes_to_str (struct ast_str **mailbox_str, struct sip_peer *peer) |
| list peer mailboxes to CLI | |
| static int | peer_markall_func (void *device, void *arg, int flags) |
| static int | peer_status (struct sip_peer *peer, char *status, int statuslen) |
| int | peercomparefunc (const void *a, const void *b) |
| static int | port_str2int (const char *pt, unsigned int standard) |
| converts ascii port to int representation. If no pt buffer is provided or the pt has errors when being converted to an int value, the port provided as the standard is used. | |
| static void | print_codec_to_cli (int fd, struct ast_codec_pref *pref) |
| Print codec list from preference to CLI/manager. | |
| static void | print_group (int fd, ast_group_t group, int crlf) |
| Print call group and pickup group. | |
| static void | proc_422_rsp (struct sip_pvt *p, struct sip_request *rsp) |
| Handle 422 response to INVITE with session-timer requested. | |
| static int | proc_session_timer (const void *vp) |
| Session-Timers: Process session refresh timeout event. | |
| static void | process_request_queue (struct sip_pvt *p, int *recount, int *nounlock) |
| static int | process_sdp (struct sip_pvt *p, struct sip_request *req, int t38action) |
| Process SIP SDP offer, select formats and activate RTP channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. Must be called after find_sdp(). | |
| static int | process_sdp_a_audio (const char *a, struct sip_pvt *p, struct ast_rtp *newaudiortp, int *last_rtpmap_codec) |
| static int | process_sdp_a_image (const char *a, struct sip_pvt *p) |
| static int | process_sdp_a_sendonly (const char *a, int *sendonly) |
| static int | process_sdp_a_text (const char *a, struct sip_pvt *p, struct ast_rtp *newtextrtp, char *red_fmtp, int *red_num_gen, int *red_data_pt, int *last_rtpmap_codec) |
| static int | process_sdp_a_video (const char *a, struct sip_pvt *p, struct ast_rtp *newvideortp, int *last_rtpmap_codec) |
| static int | process_sdp_c (const char *c, struct ast_hostent *hp) |
| static int | process_sdp_o (const char *o, struct sip_pvt *p) |
| static struct sip_proxy * | proxy_allocate (char *name, char *port, int force) |
| Allocate and initialize sip proxy. | |
| static int | proxy_update (struct sip_proxy *proxy) |
| static void | pvt_set_needdestroy (struct sip_pvt *pvt, const char *reason) |
| static int | queue_request (struct sip_pvt *p, const struct sip_request *req) |
| static struct sip_peer * | realtime_peer (const char *newpeername, struct sockaddr_in *sin, int devstate_only) |
| realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf Checks the "sipregs" realtime family from extconfig.conf if it's configured. This returns a pointer to a peer and because we use build_peer, we can rest assured that the refcount is bumped. | |
| static void | realtime_update_peer (const char *peername, struct sockaddr_in *sin, const char *defaultuser, const char *fullcontact, const char *useragent, int expirey, int deprecated_username, int lastms) |
| Update peer object in realtime storage If the Asterisk system name is set in asterisk.conf, we will use that name and store that in the "regserver" field in the sippeers table to facilitate multi-server setups. | |
| static void | receive_message (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP MESSAGE method messages. | |
| static struct sip_peer * | ref_peer (struct sip_peer *peer, char *tag) |
| static void | ref_proxy (struct sip_pvt *pvt, struct sip_proxy *proxy) |
| maintain proper refcounts for a sip_pvt's outboundproxy | |
| static const char * | referstatus2str (enum referstatus rstatus) |
| Convert transfer status to string. | |
| static void | reg_source_db (struct sip_peer *peer) |
| Get registration details from Asterisk DB. | |
| static void | register_peer_exten (struct sip_peer *peer, int onoff) |
| Automatically add peer extension to dial plan. | |
| static enum check_auth_result | register_verify (struct sip_pvt *p, struct sockaddr_in *sin, struct sip_request *req, char *uri) |
Verify registration of user
| |
| static struct sip_registry * | registry_addref (struct sip_registry *reg, char *tag) |
| Add object reference to SIP registry. | |
| static void * | registry_unref (struct sip_registry *reg, char *tag) |
| static const char * | regstate2str (enum sipregistrystate regstate) |
| Convert registration state status to string. | |
| static int | reload (void) |
| Part of Asterisk module interface. | |
| static int | reload_config (enum channelreloadreason reason) |
| Re-read SIP.conf config file. | |
| static char * | remove_uri_parameters (char *uri) |
| static void | replace_cid (struct sip_pvt *p, const char *rpid_num, const char *calleridname) |
| helper function for check_{user|peer}_ok() | |
| static int | reply_digest (struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len) |
| reply to authentication for outbound registrations | |
| static int | reqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, int seqno, int newbranch) |
| Initialize a SIP request message (not the initial one in a dialog). | |
| static int | resp_needs_contact (const char *msg, enum sipmethod method) |
| Test if this response needs a contact header. | |
| static int | respprep (struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Prepare SIP response packet. | |
| static int | restart_monitor (void) |
| Start the channel monitor thread. | |
| static void | restart_session_timer (struct sip_pvt *p) |
| Session-Timers: Restart session timer. | |
| static int | retrans_pkt (const void *data) |
| Retransmit SIP message if no answer (Called from scheduler). | |
| static int | scheduler_process_request_queue (const void *data) |
| static int | send_provisional_keepalive (const void *data) |
| static int | send_provisional_keepalive_full (struct sip_pvt *pvt, int with_sdp) |
| static int | send_provisional_keepalive_with_sdp (const void *data) |
| static int | send_request (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno) |
| Send SIP Request to the other part of the dialogue. | |
| static int | send_response (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, int seqno) |
| Transmit response on SIP request. | |
| static int | set_address_from_contact (struct sip_pvt *pvt) |
| Change the other partys IP address based on given contact. | |
| static void | set_destination (struct sip_pvt *p, char *uri) |
| Set destination from SIP URI. | |
| static void | set_insecure_flags (struct ast_flags *flags, const char *value, int lineno) |
| Parse insecure= setting in sip.conf and set flags according to setting. | |
| static void | set_nonce_randdata (struct sip_pvt *p, int forceupdate) |
| builds the sip_pvt's randdata field which is used for the nonce challenge. When forceupdate is not set, the nonce is only updated if the current one is stale. In this case, a stalenonce is one which has already received a response, if a nonce has not received a response it is not always necessary or beneficial to create a new one. | |
| static void | set_peer_defaults (struct sip_peer *peer) |
| Set peer defaults before configuring specific configurations. | |
| static void | set_socket_transport (struct sip_socket *socket, int transport) |
| static void | set_t38_capabilities (struct sip_pvt *p) |
| Set the global T38 capabilities on a SIP dialog structure. | |
| static int | show_channels_cb (void *__cur, void *__arg, int flags) |
| callback for show channel|subscription | |
| static int | show_chanstats_cb (void *__cur, void *__arg, int flags) |
| Callback for show_chanstats. | |
| static int | sip_addheader (struct ast_channel *chan, void *data) |
| Add a SIP header to an outbound INVITE. | |
| static struct sip_pvt * | sip_alloc (ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, struct sip_request *req) |
| Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference. | |
| static void | sip_alreadygone (struct sip_pvt *dialog) |
| Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging. | |
| static int | sip_answer (struct ast_channel *ast) |
| sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface | |
| static int | sip_call (struct ast_channel *ast, char *dest, int timeout) |
| Initiate SIP call from PBX used from the dial() application. | |
| static int | sip_cancel_destroy (struct sip_pvt *p) |
| Cancel destruction of SIP dialog. Be careful as this also absorbs the reference - if you call it from within the scheduler, this might be the last reference. | |
| static char * | sip_cli_notify (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Cli command to send SIP notify to peer. | |
| static int | sip_debug_test_addr (const struct sockaddr_in *addr) |
| See if we pass debug IP filter. | |
| static int | sip_debug_test_pvt (struct sip_pvt *p) |
| Test PVT for debugging output. | |
| static struct sip_pvt * | sip_destroy (struct sip_pvt *p) |
| Destroy SIP call structure. Make it return NULL so the caller can do things like foo = sip_destroy(foo); and reduce the chance of bugs due to dangling pointers. | |
| static void | sip_destroy_fn (void *p) |
| static void | sip_destroy_peer (struct sip_peer *peer) |
| Destroy peer object from memory. | |
| static void | sip_destroy_peer_fn (void *peer) |
| static int | sip_devicestate (void *data) |
| Part of PBX channel interface. | |
| static char * | sip_do_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Turn on SIP debugging (CLI command). | |
| static char * | sip_do_debug_ip (int fd, char *arg) |
| Enable SIP Debugging for a single IP. | |
| static char * | sip_do_debug_peer (int fd, char *arg) |
| Turn on SIP debugging for a given peer. | |
| static int | sip_do_reload (enum channelreloadreason reason) |
| Reload module. | |
| static int | sip_dtmfmode (struct ast_channel *chan, void *data) |
| Set the DTMFmode for an outbound SIP call (application). | |
| static void | sip_dump_history (struct sip_pvt *dialog) |
| Dump SIP history to debug log file at end of lifespan for SIP dialog. | |
| static int | sip_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
| sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links | |
| static const char * | sip_get_callid (struct ast_channel *chan) |
| Deliver SIP call ID for the call. | |
| static int | sip_get_codec (struct ast_channel *chan) |
| Return SIP UA's codec (part of the RTP interface). | |
| static enum ast_rtp_get_result | sip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
| Returns null if we can't reinvite audio (part of RTP interface). | |
| static enum ast_rtp_get_result | sip_get_trtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
| Returns null if we can't reinvite text (part of RTP interface). | |
| static struct ast_udptl * | sip_get_udptl_peer (struct ast_channel *chan) |
| static enum ast_rtp_get_result | sip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp **rtp) |
| Returns null if we can't reinvite video (part of RTP interface). | |
| static int | sip_hangup (struct ast_channel *ast) |
| sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup | |
| static int | sip_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen) |
| Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc. | |
| static const char * | sip_nat_mode (const struct sip_pvt *p) |
| Display SIP nat mode. | |
| static struct ast_channel * | sip_new (struct sip_pvt *i, int state, const char *title) |
| Initiate a call in the SIP channel called from sip_request_call (calls from the pbx ) for outbound channels and from handle_request_invite for inbound channels. | |
| static int | sip_park (struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, int seqno) |
| Park a call using the subsystem in res_features.c This is executed in a separate thread. | |
| static void * | sip_park_thread (void *stuff) |
| Park SIP call support function Starts in a new thread, then parks the call XXX Should we add a wait period after streaming audio and before hangup?? Sometimes the audio can't be heard before hangup. | |
| static int | sip_parse_host (char *line, int lineno, char **hostname, int *portnum, enum sip_transport *transport) |
| Small function to parse a config line for a host with a transport i.e. tls://www.google.com:8056. | |
| static void | sip_peer_hold (struct sip_pvt *p, int hold) |
| Change onhold state of a peer using a pvt structure. | |
| static void | sip_poke_all_peers (void) |
| Send a poke to all known peers. | |
| static int | sip_poke_noanswer (const void *data) |
| React to lack of answer to Qualify poke. | |
| static int | sip_poke_peer (struct sip_peer *peer, int force) |
| Check availability of peer, also keep NAT open. | |
| static int | sip_poke_peer_s (const void *data) |
| Poke peer (send qualify to check if peer is alive and well). | |
| static int | sip_prepare_socket (struct sip_pvt *p) |
| static char * | sip_prune_realtime (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Remove temporary realtime objects from memory (CLI). | |
| static char * | sip_qualify_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Send an OPTIONS packet to a SIP peer. | |
| static int | sip_queryoption (struct ast_channel *chan, int option, void *data, int *datalen) |
| Query an option on a SIP dialog. | |
| static struct ast_frame * | sip_read (struct ast_channel *ast) |
| Read SIP RTP from channel. | |
| static struct sockaddr_in * | sip_real_dst (const struct sip_pvt *p) |
| The real destination address for a write. | |
| static int | sip_refer_allocate (struct sip_pvt *p) |
| Allocate SIP refer structure. | |
| static int | sip_reg_timeout (const void *data) |
| Registration timeout, register again Registered as a timeout handler during transmit_register(), to retransmit the packet if a reply does not come back. This is called by the scheduler so the event is not pending anymore when we are called. | |
| static int | sip_register (const char *value, int lineno) |
| Parse register=> line in sip.conf and add to registry. | |
| static void | sip_registry_destroy (struct sip_registry *reg) |
| Destroy registry object Objects created with the register= statement in static configuration. | |
| static int | sip_reinvite_retry (const void *data) |
| Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. Called from the scheduler. | |
| static char * | sip_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Force reload of module from cli. | |
| static int | sip_removeheader (struct ast_channel *chan, void *data) |
| Remove SIP headers added previously with SipAddHeader application. | |
| static struct ast_channel * | sip_request_call (const char *type, int format, void *data, int *cause) |
| PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here. | |
| static int | sip_reregister (const void *data) |
| Update registration with SIP Proxy. Called from the scheduler when the previous registration expires, so we don't have to cancel the pending event. We assume the reference so the sip_registry is valid, since it is stored in the scheduled event anyways. | |
| static struct ast_frame * | sip_rtp_read (struct ast_channel *ast, struct sip_pvt *p, int *faxdetect) |
| Read RTP from network. | |
| static void | sip_scheddestroy (struct sip_pvt *p, int ms) |
| Schedule destruction of SIP dialog. | |
| static void | sip_send_all_mwi_subscriptions (void) |
| Send all MWI subscriptions. | |
| static void | sip_send_all_registers (void) |
| Send all known registrations. | |
| static int | sip_send_mwi_to_peer (struct sip_peer *peer, const struct ast_event *event, int cache_only) |
| Send message waiting indication to alert peer that they've got voicemail. | |
| static int | sip_senddigit_begin (struct ast_channel *ast, char digit) |
| static int | sip_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration) |
| Send DTMF character on SIP channel within one call, we're able to transmit in many methods simultaneously. | |
| static int | sip_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen) |
| Send message with Access-URL header, if this is an HTML URL only! | |
| static int | sip_sendtext (struct ast_channel *ast, const char *text) |
| Send SIP MESSAGE text within a call Called from PBX core sendtext() application. | |
| static char * | sip_set_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Enable/Disable SIP History logging (CLI). | |
| static void | sip_set_redirstr (struct sip_pvt *p, char *reason) |
| Translate referring cause. | |
| static int | sip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp *rtp, struct ast_rtp *vrtp, struct ast_rtp *trtp, int codecs, int nat_active) |
| Set the RTP peer for this call. | |
| static int | sip_set_udptl_peer (struct ast_channel *chan, struct ast_udptl *udptl) |
| static char * | sip_show_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show details of one active dialog. | |
| static char * | sip_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI for show channels or subscriptions. This is a new-style CLI handler so a single function contains the prototype for the function, the 'generator' to produce multiple entries in case it is required, and the actual handler for the command. | |
| static char * | sip_show_channelstats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| SIP show channelstats CLI (main function). | |
| static char * | sip_show_domains (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command to list local domains. | |
| static char * | sip_show_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show history details of one dialog. | |
| static char * | sip_show_inuse (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Command to show calls within limits set by call_limit. | |
| static char * | sip_show_mwi (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | sip_show_objects (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| List all allocated SIP Objects (realtime or static). | |
| static char * | sip_show_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show one peer in detail. | |
| static char * | sip_show_peers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Show Peers command. | |
| static char * | sip_show_registry (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show SIP Registry (registrations with other SIP proxies. | |
| static char * | sip_show_sched (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | sip_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| List global settings for the SIP channel. | |
| static char * | sip_show_tcp (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show active TCP connections. | |
| static char * | sip_show_user (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show one user in detail. | |
| static char * | sip_show_users (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Command 'SIP Show Users'. | |
| static int | sip_sipredirect (struct sip_pvt *p, const char *dest) |
| Transfer call before connect with a 302 redirect. | |
| static struct sip_st_dlg * | sip_st_alloc (struct sip_pvt *const p) |
| Allocate Session-Timers struct w/in dialog. | |
| static int | sip_standard_port (enum sip_transport type, int port) |
| Returns the port to use for this socket. | |
| static int | sip_subscribe_mwi (const char *value, int lineno) |
| Parse mwi=> line in sip.conf and add to list. | |
| static void | sip_subscribe_mwi_destroy (struct sip_subscription_mwi *mwi) |
| Destroy MWI subscription object. | |
| static int | sip_subscribe_mwi_do (const void *data) |
| Send a subscription or resubscription for MWI. | |
| static int | sip_t38_abort (const void *data) |
| Called to deny a T38 reinvite if the core does not respond to our request. | |
| static struct ast_tcptls_session_instance * | sip_tcp_locate (struct sockaddr_in *s) |
| Find thread for TCP/TLS session (based on IP/Port. | |
| static void * | sip_tcp_worker_fn (void *data) |
| SIP TCP connection handler. | |
| static void | sip_tcptls_client_args_destructor (void *obj) |
| static int | sip_tcptls_write (struct ast_tcptls_session_instance *tcptls_session, const void *buf, size_t len) |
| used to indicate to a tcptls thread that data is ready to be written | |
| static struct sip_threadinfo * | sip_threadinfo_create (struct ast_tcptls_session_instance *tcptls_session, int transport) |
| creates a sip_threadinfo object and links it into the threadt table. | |
| static void | sip_threadinfo_destructor (void *obj) |
| static int | sip_transfer (struct ast_channel *ast, const char *dest) |
| Transfer SIP call. | |
| static char * | sip_unregister (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Unregister (force expiration) a SIP peer in the registry via CLI. | |
| static int | sip_uri_cmp (const char *input1, const char *input2) |
| static int | sip_uri_headers_cmp (const char *input1, const char *input2) |
| helper routine for sip_uri_cmp | |
| static int | sip_uri_params_cmp (const char *input1, const char *input2) |
| helper routine for sip_uri_cmp to compare URI parameters | |
| static int | sip_write (struct ast_channel *ast, struct ast_frame *frame) |
| Send frame to media channel (rtp). | |
| static int | sipsock_read (int *id, int fd, short events, void *ignore) |
| Read data from SIP UDP socket. | |
| static enum st_mode | st_get_mode (struct sip_pvt *p) |
| Get the session-timer mode. | |
| static enum st_refresher | st_get_refresher (struct sip_pvt *p) |
| Get the entity (UAC or UAS) that's acting as the session-timer refresher. | |
| static int | st_get_se (struct sip_pvt *p, int max) |
| Get Max or Min SE (session timer expiry). | |
| static void | start_session_timer (struct sip_pvt *p) |
| Session-Timers: Start session timer. | |
| static const char * | stmode2str (enum st_mode m) |
| static void | stop_media_flows (struct sip_pvt *p) |
| Immediately stop RTP, VRTP and UDPTL as applicable. | |
| static void | stop_session_timer (struct sip_pvt *p) |
| Session-Timers: Stop session timer. | |
| static int | str2dtmfmode (const char *str) |
| maps a string to dtmfmode, returns -1 on error | |
| static enum st_mode | str2stmode (const char *s) |
| static enum st_refresher | str2strefresher (const char *s) |
| static const char * | strefresher2str (enum st_refresher r) |
| static const char * | subscription_type2str (enum subscriptiontype subtype) |
| Show subscription type in string format. | |
| static unsigned int | t38_get_rate (enum ast_control_t38_rate rate) |
| Get Max T.38 Transmission rate from T38 capabilities. | |
| static void | tcptls_packet_destructor (void *obj) |
| static struct sip_peer * | temp_peer (const char *name) |
| Create temporary peer (used in autocreatepeer mode). | |
| static void | temp_pvt_cleanup (void *) |
| static int | temp_pvt_init (void *) |
| static char * | terminate_uri (char *uri) |
| static int | threadinfo_locate_cb (void *obj, void *arg, int flags) |
| static int | threadt_cmp_cb (void *obj, void *arg, int flags) |
| static int | threadt_hash_cb (const void *obj, const int flags) |
| static char * | transfermode2str (enum transfermodes mode) |
| Convert transfer mode to text string. | |
| static void | transmit_fake_auth_response (struct sip_pvt *p, int sipmethod, struct sip_request *req, enum xmittype reliable) |
| Send a fake 401 Unauthorized response when the administrator wants to hide the names of local devices from fishers. | |
| static int | transmit_info_with_digit (struct sip_pvt *p, const char digit, unsigned int duration) |
| Send SIP INFO dtmf message, see Cisco documentation on cisco.com. | |
| static int | transmit_info_with_vidupdate (struct sip_pvt *p) |
| Send SIP INFO with video update request. | |
| static int | transmit_invite (struct sip_pvt *p, int sipmethod, int sdp, int init) |
| Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it. | |
| static int | transmit_message_with_text (struct sip_pvt *p, const char *text) |
| Transmit text with SIP MESSAGE method. | |
| static int | transmit_notify_custom (struct sip_pvt *p, struct ast_variable *vars) |
| Notify device with custom headers from sip_notify.conf. | |
| static int | transmit_notify_with_mwi (struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten) |
| Notify user of messages waiting in voicemail (RFC3842). | |
| static int | transmit_notify_with_sipfrag (struct sip_pvt *p, int cseq, char *message, int terminate) |
| Notify a transferring party of the status of transfer (RFC3515). | |
| static int | transmit_provisional_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp) |
| static int | transmit_refer (struct sip_pvt *p, const char *dest) |
| Transmit SIP REFER message (initiated by the transfer() dialplan application. | |
| static int | transmit_register (struct sip_registry *r, int sipmethod, const char *auth, const char *authheader) |
| Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister()). | |
| static int | transmit_reinvite_with_sdp (struct sip_pvt *p, int t38version, int oldsdp) |
| Transmit reinvite with SDP. | |
| static int | transmit_request (struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch) |
| Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry). | |
| static int | transmit_request_with_auth (struct sip_pvt *p, int sipmethod, int seqno, enum xmittype reliable, int newbranch) |
| Transmit SIP request, auth added. | |
| static int | transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, no retransmits. | |
| static int | transmit_response_reliable (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK. | |
| static int | transmit_response_using_temp (ast_string_field callid, struct sockaddr_in *sin, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg) |
| Transmit response, no retransmits, using a temporary pvt structure. | |
| static int | transmit_response_with_allow (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Append Accept header, content length before transmitting response. | |
| static int | transmit_response_with_auth (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *randdata, enum xmittype reliable, const char *header, int stale) |
| Respond with authorization request. | |
| static int | transmit_response_with_date (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Append date and content length before transmitting response. | |
| static int | transmit_response_with_minse (struct sip_pvt *p, const char *msg, const struct sip_request *req, int minse_int) |
| Transmit 422 response with Min-SE header (Session-Timers). | |
| static int | transmit_response_with_sdp (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp) |
| Used for 200 OK and 183 early media. | |
| static int | transmit_response_with_t38_sdp (struct sip_pvt *p, char *msg, struct sip_request *req, int retrans) |
| Used for 200 OK and 183 early media. | |
| static int | transmit_response_with_unsupported (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported) |
| Transmit response, no retransmits. | |
| static int | transmit_state_notify (struct sip_pvt *p, int state, int full, int timeout) |
| Used in the SUBSCRIBE notification subsystem (RFC3265). | |
| static void | try_suggested_sip_codec (struct sip_pvt *p) |
| Try setting codec suggested by the SIP_CODEC channel variable. | |
| static void | unlink_marked_peers_from_tables (void) |
| static void | unlink_peer_from_tables (struct sip_peer *peer) |
| static int | unload_module (void) |
| PBX unload module API. | |
| static void * | unref_peer (struct sip_peer *peer, char *tag) |
| static int | update_call_counter (struct sip_pvt *fup, int event) |
| update_call_counter: Handle call_limit for SIP devices Setting a call-limit will cause calls above the limit not to be accepted. | |
| static void | update_peer (struct sip_peer *p, int expire) |
| Update peer data in database (if used). | |
| static void | update_provisional_keepalive (struct sip_pvt *pvt, int with_sdp) |
Variables | |
| static struct ast_module_info | __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Session Initiation Protocol (SIP)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } |
| static char * | app_dtmfmode = "SIPDtmfMode" |
| static char * | app_sipaddheader = "SIPAddHeader" |
| static char * | app_sipremoveheader = "SIPRemoveHeader" |
| static struct ast_module_info * | ast_module_info = &__mod_info |
| static struct sip_auth * | authl = NULL |
| Authentication list for realm authentication. | |
| static struct sockaddr_in | bindaddr |
| static unsigned int | chan_idx |
| static struct ast_threadstorage | check_auth_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_check_auth_buf , .custom_init = NULL , } |
| static struct ast_custom_function | checksipdomain_function |
| static struct ast_cli_entry | cli_sip [] |
| SIP Cli commands definition. | |
| static const char | config [] = "sip.conf" |
| static struct sockaddr_in | debugaddr |
| static int | default_expiry = DEFAULT_DEFAULT_EXPIRY |
| static struct ast_jb_conf | default_jbconf |
| Global jitterbuffer configuration - by default, jb is disabled. | |
| static struct ast_tls_config | default_tls_cfg |
| Default TLS connection configuration. | |
| struct ao2_container * | dialogs |
| Here we implement the container for dialogs (sip_pvt), defining generic wrapper functions to ease the transition from the current implementation (a single linked list) to a different container. In addition to a reference to the container, we need functions to lock/unlock the container and individual items, and functions to add/remove references to the individual items. | |
| static struct _map_x_s | dtmfstr [] |
| mapping between dtmf flags and strings | |
| static time_t | externexpire |
| static char | externhost [MAXHOSTNAMELEN] |
| static struct sockaddr_in | externip |
| our external IP address/port for SIP sessions. externip.sin_addr is only set when we know we might be behind a NAT, and this is done using a variety of (mutually exclusive) ways from the config file: | |
| static int | externrefresh = 10 |
| static struct _map_x_s | faxecmodes [] |
| static struct ast_ha * | global_contact_ha = NULL |
| Global list of addresses dynamic peers are not allowed to use. | |
| static struct ast_jb_conf | global_jbconf |
| static const int | HASH_DIALOG_SIZE = 563 |
| static const int | HASH_PEER_SIZE = 563 |
| static struct _map_x_s | insecurestr [] |
| static struct sockaddr_in | internip |
| our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suitable address from one of the interfaces, and the same port number we bind to. It is used as the default address/port in SIP messages, and as the default address (but not port) in SDP messages. | |
| static struct invstate2stringtable | invitestate2string [] |
| Readable descriptions of device states. | |
| static struct ast_ha * | localaddr |
| List of local networks We store "localnet" addresses from the config file into an access list, marked as 'DENY', so the call to ast_apply_ha() will return AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local' (i.e. presumably public) addresses. | |
| static char | mandescr_show_peer [] |
| static char | mandescr_show_peers [] |
| static char | mandescr_show_registry [] |
| Manager Action SIPShowRegistry description. | |
| static char | mandescr_sipnotify [] |
| static int | max_expiry = DEFAULT_MAX_EXPIRY |
| static int | min_expiry = DEFAULT_MIN_EXPIRY |
| static int | mwi_expiry = DEFAULT_MWI_EXPIRY |
| static struct _map_x_s | natmodes [] |
| static const char | notify_config [] = "sip_notify.conf" |
| static struct ast_config * | notify_types = NULL |
| static int | ourport_tcp |
| static int | ourport_tls |
| struct ao2_container * | peers |
| The peer list: Users, Peers and Friends. | |
| struct ao2_container * | peers_by_ip |
| static struct _map_x_s | referstatusstrings [] |
| static struct ast_register_list | regl |
| The register list: Other SIP proxies we register with and place calls to. | |
| static struct _map_x_s | regstatestrings [] |
| static struct ast_custom_function | sip_header_function |
| static struct cfsip_methods | sip_methods [] |
| The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type. | |
| static struct cfsip_options | sip_options [] |
| List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly. | |
| static struct ast_rtp_protocol | sip_rtp |
| Interface structure with callbacks used to connect to RTP module. | |
| static struct ast_tcptls_session_args | sip_tcp_desc |
| The TCP server definition. | |
| static struct ast_channel_tech | sip_tech |
| Definition of this channel for PBX channel registration. | |
| static struct ast_channel_tech | sip_tech_info |
| This version of the sip channel tech has no send_digit_begin callback so that the core knows that the channel does not want DTMF BEGIN frames. The struct is initialized just before registering the channel driver, and is for use with channels using SIP INFO DTMF. | |
| static struct ast_tls_config | sip_tls_cfg |
| Working TLS connection configuration. | |
| static struct ast_tcptls_session_args | sip_tls_desc |
| The TCP/TLS server definition. | |
| static struct ast_udptl_protocol | sip_udptl |
| Interface structure with callbacks used to connect to UDPTL module. | |
| static struct ast_custom_function | sipchaninfo_function |
| Structure to declare a dialplan function: SIPCHANINFO. | |
| static enum sip_debug_e | sipdebug |
| static int | sipdebug_text |
| extra debugging for 'text' related events. At the moment this is set together with sip_debug_console. | |
| static struct ast_custom_function | sippeer_function |
| Structure to declare a dialplan function: SIPPEER. | |
| static int | sipsock = -1 |
| Main socket for UDP SIP communication. | |
| static struct _map_x_s | stmodes [] |
| Report Peer status in character string. | |
| static struct _map_x_s | strefreshers [] |
| static struct sockaddr_in | stunaddr |
| static struct ast_subscription_mwi_list | submwil |
| The MWI subscription list. | |
| static struct cfsubscription_types | subscription_types [] |
Subscription types that we support. We support
| |
| static struct ao2_container * | threadt |
| static struct ast_threadstorage | ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ts_temp_pvt , .custom_init = temp_pvt_init , } |
DefaultSettings | |
| static char | default_callerid [AST_MAX_EXTENSION] |
| static char | default_fromdomain [AST_MAX_EXTENSION] |
| static char | default_language [MAX_LANGUAGE] |
| static int | default_maxcallbitrate |
| static char | default_mohinterpret [MAX_MUSICCLASS] |
| static char | default_mohsuggest [MAX_MUSICCLASS] |
| static char | default_notifymime [AST_MAX_EXTENSION] |
| static char | default_parkinglot [AST_MAX_CONTEXT] |
| static struct ast_codec_pref | default_prefs |
| static unsigned int | default_primary_transport |
| static int | default_qualify |
| static unsigned int | default_transports |
| static char | default_vmexten [AST_MAX_EXTENSION] |
GlobalSettings | |
Global settings apply to the channel (often settings you can change in the general section of sip.conf | |
| static int | dumphistory |
| static int | global_authfailureevents |
| static int | global_autoframing |
| static int | global_callcounter |
| static int | global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263 |
| Codecs that we support by default:. | |
| static unsigned int | global_cos_audio |
| static unsigned int | global_cos_sip |
| static unsigned int | global_cos_text |
| static unsigned int | global_cos_video |
| static int | global_dynamic_exclude_static = 0 |
| static int | global_match_auth_username |
| static int | global_max_se |
| static int | global_min_se |
| static int | global_prematuremediafilter |
| static int | global_qualify_gap |
| static int | global_qualify_peers |
| static int | global_qualifyfreq |
| static int | global_reg_timeout |
| static int | global_regattempts_max |
| static char | global_regcontext [AST_MAX_CONTEXT] |
| static int | global_relaxdtmf |
| static int | global_rtpholdtimeout |
| static int | global_rtpkeepalive |
| static int | global_rtptimeout |
| static char | global_sdpowner [AST_MAX_EXTENSION] |
| static char | global_sdpsession [AST_MAX_EXTENSION] |
| static int | global_shrinkcallerid |
| static enum st_mode | global_st_mode |
| static enum st_refresher | global_st_refresher |
| static int | global_t1 |
| static int | global_t1min |
| static int | global_timer_b |
| static unsigned int | global_tos_audio |
| static unsigned int | global_tos_sip |
| static unsigned int | global_tos_text |
| static unsigned int | global_tos_video |
| static char | global_useragent [AST_MAX_EXTENSION] |
| static int | recordhistory |
| static struct sip_settings | sip_cfg |
Object counters @{ | |
| |
| #define | DEC_CALL_LIMIT 0 |
| #define | DEC_CALL_RINGING 2 |
| #define | INC_CALL_LIMIT 1 |
| #define | INC_CALL_RINGING 3 |
| #define | REQ_OFFSET_TO_STR(req, offset) (ast_str_buffer((req)->data) + ((req)->offset)) |
| enum | domain_mode { SIP_DOMAIN_AUTO, SIP_DOMAIN_CONFIG } |
| Modes for SIP domain handling in the PBX. More... | |
| static int | apeerobjs = 0 |
| static struct ast_flags | global_flags [2] = {{0}} |
| static int | global_t38_maxdatagram |
| static struct io_context * | io |
| static pthread_t | monitor_thread = AST_PTHREADT_NULL |
| This is the thread for the monitor which checks for input on the channels which are not currently in use. | |
| static ast_mutex_t | monlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
| Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. | |
| static ast_mutex_t | netlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
| static int | regobjs = 0 |
| static int | rpeerobjs = 0 |
| static struct sched_context * | sched |
| static ast_mutex_t | sip_reload_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) |
| static int | sip_reloading = FALSE |
| static enum channelreloadreason | sip_reloadreason |
| static int * | sipsock_read_id |
| static int | speerobjs = 0 |
| static char | used_context [AST_MAX_CONTEXT] |
See Also: Implementation of RFC 3261 - without S/MIME, and experimental TCP and TLS support Configuration file sip.conf
********** IMPORTANT *
VIA branch tag transaction checking
Transaction support
A new INVITE is sent to handle_request_invite(), that will end up starting a new channel in the PBX, the new channel after that executing in a separate channel thread. This is an incoming "call". When the call is answered, either by a bridged channel or the PBX itself the sip_answer() function is called.
The actual media - Video or Audio - is mostly handled by the RTP subsystem in rtp.c
Definition in file chan_sip.c.
| #define ALLOWED_METHODS "INVITE, ACK, CANCEL, OPTIONS, BYE, REFER, SUBSCRIBE, NOTIFY, INFO" |
SIP Methods we support.
Definition at line 949 of file chan_sip.c.
Referenced by respprep(), transmit_invite(), transmit_notify_with_sipfrag(), transmit_refer(), and transmit_reinvite_with_sdp().
| #define append_history | ( | p, | |||
| event, | |||||
| fmt, | |||||
| args... | ) | append_history_full(p, "%-15s " fmt, event, ## args) |
Append to SIP dialog history.
Definition at line 2485 of file chan_sip.c.
Referenced by __sip_autodestruct(), __sip_reliable_xmit(), auto_congest(), build_reply_digest(), cb_extensionstate(), change_hold_state(), check_auth(), do_register_auth(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_invite(), local_attended_transfer(), obproxy_get(), pvt_set_needdestroy(), retrans_pkt(), send_request(), send_response(), sip_cancel_destroy(), sip_fixup(), sip_hangup(), sip_new(), sip_park_thread(), sip_reregister(), sip_scheddestroy(), sip_set_rtp_peer(), transmit_register(), transmit_reinvite_with_sdp(), and transmit_response_with_auth().
| #define CALLERID_UNKNOWN "Anonymous" |
| #define CHECK_AUTH_BUF_INITLEN 256 |
Definition at line 12740 of file chan_sip.c.
Referenced by check_auth(), and transmit_fake_auth_response().
| #define check_request_transport | ( | peer, | |||
| tmpl | ) |
generic function for determining if a correct transport is being used to contact a peer
this is done as a macro so that the "tmpl" var can be passed either a sip_request or a sip_peer
Definition at line 2392 of file chan_sip.c.
Referenced by create_addr_from_peer(), and register_verify().
| #define DEC_CALL_LIMIT 0 |
Definition at line 1159 of file chan_sip.c.
Referenced by __sip_destroy(), handle_request_cancel(), handle_request_invite(), handle_response_invite(), sip_hangup(), and update_call_counter().
| #define DEC_CALL_RINGING 2 |
Definition at line 1161 of file chan_sip.c.
Referenced by handle_response_invite(), and update_call_counter().
| #define DEFAULT_ALLOW_EXT_DOM TRUE |
| #define DEFAULT_ALLOWGUEST TRUE |
| #define DEFAULT_ALWAYSAUTHREJECT FALSE |
Don't reject authentication requests always
Definition at line 1000 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_AUTOCREATEPEER FALSE |
Don't create peers automagically
Definition at line 996 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_CALLCOUNTER FALSE |
| #define DEFAULT_CALLERID "asterisk" |
| #define DEFAULT_CALLEVENTS FALSE |
Extra manager SIP call events
Definition at line 999 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_COMPACTHEADERS FALSE |
Send compact (one-character) SIP headers. Default off
Definition at line 982 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_CONTEXT "default" |
The default context for [general] section as well as devices
Definition at line 972 of file chan_sip.c.
| #define DEFAULT_COS_AUDIO 5 |
Level 2 class of service for audio media
Definition at line 988 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_COS_SIP 4 |
Level 2 class of service for SIP signalling
Definition at line 987 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_COS_TEXT 5 |
Level 2 class of service for text media (T.140)
Definition at line 990 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_COS_VIDEO 6 |
Level 2 class of service for video media
Definition at line 989 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_DEFAULT_EXPIRY 120 |
| #define DEFAULT_EXPIRY 900 |
Expire slowly
Definition at line 515 of file chan_sip.c.
| #define DEFAULT_FREQ_NOTOK 10 * 1000 |
Qualification: How often to check, if the host is down...
Definition at line 531 of file chan_sip.c.
| #define DEFAULT_MATCHEXTERNIPLOCALLY FALSE |
Match extern IP locally default setting
Definition at line 997 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_MAX_CALL_BITRATE (384) |
| #define DEFAULT_MAX_EXPIRY 3600 |
| #define DEFAULT_MAX_FORWARDS "70" |
Definition at line 502 of file chan_sip.c.
Referenced by initreqprep(), reqprep(), and transmit_register().
| #define DEFAULT_MAX_SE 1800 |
Session-Timer Default Session-Expires period (RFC 4028)
Definition at line 550 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_MAXMS 2000 |
Qualification: Must be faster than 2 seconds by default
Definition at line 529 of file chan_sip.c.
| #define DEFAULT_MIN_EXPIRY 60 |
| #define DEFAULT_MIN_SE 90 |
Session-Timer Default Min-SE period (RFC 4028)
Definition at line 551 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_MOHINTERPRET "default" |
| #define DEFAULT_MOHSUGGEST "" |
| #define DEFAULT_MWI_EXPIRY 3600 |
| #define DEFAULT_NOTIFYCID DISABLED |
Include CID with ringing notifications
Definition at line 994 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_NOTIFYMIME "application/simple-message-summary" |
| #define DEFAULT_NOTIFYRINGING TRUE |
Notify devicestate system on ringing state
Definition at line 993 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_PEDANTIC FALSE |
Avoid following SIP standards for dialog matching
Definition at line 995 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_QUALIFY FALSE |
| #define DEFAULT_QUALIFY_GAP 100 |
| #define DEFAULT_QUALIFY_PEERS 1 |
| #define DEFAULT_QUALIFYFREQ 60 * 1000 |
Qualification: How often to check for the host to be up
Definition at line 530 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_REALM "asterisk" |
Realm for HTTP digest authentication
Definition at line 992 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_REGEXTENONQUALIFY FALSE |
| #define DEFAULT_REGISTRATION_TIMEOUT 20 |
| #define DEFAULT_RETRANS 1000 |
How frequently to retransmit Default: 2 * 500 ms in RFC 3261
Definition at line 533 of file chan_sip.c.
| #define DEFAULT_RTPKEEPALIVE 0 |
Default RTPkeepalive setting
Definition at line 979 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_SDPOWNER "root" |
Default SDP username field in (o=) header unless re-defined in sip.conf
Definition at line 1007 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_SDPSESSION "Asterisk PBX" |
Default SDP session name, (s=) header unless re-defined in sip.conf
Definition at line 1006 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_SRVLOOKUP TRUE |
| #define DEFAULT_T1MIN 100 |
100 MS for minimal roundtrip time
Definition at line 1002 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TIMER_T1 500 |
SIP timer T1 (according to RFC 3261)
Definition at line 535 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_AUDIO 0 |
Audio packets should be marked as DSCP EF (Expedited Forwarding), but the default is 0 to be compatible with previous versions.
Definition at line 984 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_SIP 0 |
Call signalling packets should be marked as DSCP CS3, but the default is 0 to be compatible with previous versions.
Definition at line 983 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_TEXT 0 |
Text packets should be marked as XXXX XXXX, but the default is 0 to be compatible with previous versions.
Definition at line 986 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TOS_VIDEO 0 |
Video packets should be marked as DSCP AF41, but the default is 0 to be compatible with previous versions.
Definition at line 985 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_TRANS_TIMEOUT -1 |
Use default SIP transaction timeout
Definition at line 539 of file chan_sip.c.
Referenced by __sip_autodestruct(), auto_congest(), cb_extensionstate(), check_auth(), check_pendings(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_register(), handle_response_invite(), handle_response_register(), receive_message(), sip_hangup(), sip_send_mwi_to_peer(), and transmit_fake_auth_response().
| #define DEFAULT_USERAGENT "Asterisk PBX" |
Default Useragent: header unless re-defined in sip.conf
Definition at line 1005 of file chan_sip.c.
Referenced by reload_config().
| #define DEFAULT_VMEXTEN "asterisk" |
Default voicemail extension
Definition at line 975 of file chan_sip.c.
Referenced by reload_config().
| #define EXPIRY_GUARD_LIMIT 30 |
Below here, we use EXPIRY_GUARD_PCT instead of EXPIRY_GUARD_SECS
Definition at line 507 of file chan_sip.c.
Referenced by handle_response_register().
| #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.
Definition at line 509 of file chan_sip.c.
Referenced by handle_response_register().
| #define EXPIRY_GUARD_PCT 0.20 |
Percentage of expires timeout to use when below EXPIRY_GUARD_LIMIT
Definition at line 513 of file chan_sip.c.
Referenced by handle_response_register().
| #define EXPIRY_GUARD_SECS 15 |
How long before expiry do we reregister
Definition at line 506 of file chan_sip.c.
Referenced by handle_response_register().
| #define FALSE 0 |
Definition at line 477 of file chan_sip.c.
| #define FINDALLDEVICES (FINDUSERS | FINDPEERS) |
Definition at line 487 of file chan_sip.c.
Referenced by check_peer_ok(), find_by_name(), find_peer(), sip_devicestate(), sip_peer_hold(), and update_call_counter().
| #define FINDPEERS (1 << 1) |
Definition at line 486 of file chan_sip.c.
Referenced by _sip_qualify_peer(), _sip_show_peer(), check_peer_ok(), create_addr(), find_by_name(), find_peer(), function_sippeer(), register_verify(), sip_do_debug_peer(), sip_unregister(), st_get_mode(), st_get_refresher(), st_get_se(), and transmit_register().
| #define FINDUSERS (1 << 0) |
Definition at line 485 of file chan_sip.c.
Referenced by check_peer_ok(), find_by_name(), find_peer(), and sip_show_user().
| #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-30.30s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-40.40s %-20.20s %-16.16s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-30.30s %-6d %-9.9s %-6.6s\n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT "%-25.25s %-15.15s %-15.15s \n" |
Definition at line 16396 of file chan_sip.c.
| #define FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-6.6s\n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT2 "%-30.30s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %s\n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT2 "%-30.30s %3.6s %9.9s %6.6s\n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
Definition at line 16395 of file chan_sip.c.
| #define FORMAT3 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n" |
| #define FORMAT4 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n" |
| #define FROMDOMAIN_INVALID "anonymous.invalid" |
| #define INC_CALL_LIMIT 1 |
Definition at line 1160 of file chan_sip.c.
Referenced by handle_request_invite(), and update_call_counter().
| #define INC_CALL_RINGING 3 |
| #define INITIAL_CSEQ 101 |
Our initial sip sequence number
Definition at line 548 of file chan_sip.c.
Referenced by sip_alloc(), sip_register(), and transmit_response_using_temp().
| #define IS_SIP_TECH | ( | t | ) | ((t) == &sip_tech || (t) == &sip_tech_info) |
Definition at line 2717 of file chan_sip.c.
Referenced by acf_channel_read(), func_header_read(), function_sipchaninfo_read(), handle_request_bye(), sip_dtmfmode(), and sip_hangup().
| #define MAX_AUTHTRIES 3 |
Try authentication three times, then fail
Definition at line 541 of file chan_sip.c.
Referenced by handle_response(), handle_response_invite(), and handle_response_register().
| #define MAX_HISTORY_ENTRIES 50 |
Max entires in the history list for a sip_pvt
Definition at line 546 of file chan_sip.c.
Referenced by append_history_va().
| #define MAX_RETRANS 6 |
Try only 6 times for retransmissions, a total of 7 transmissions
Definition at line 534 of file chan_sip.c.
| #define NO_RTP 0 |
Definition at line 570 of file chan_sip.c.
| #define NOT_SUPPORTED 0 |
Definition at line 864 of file chan_sip.c.
| #define PROVIS_KEEPALIVE_TIMEOUT 60000 |
How long to wait before retransmitting a provisional response (rfc 3261 13.3.1.1)
Definition at line 540 of file chan_sip.c.
Referenced by send_provisional_keepalive_full(), and update_provisional_keepalive().
| #define REQ_OFFSET_TO_STR | ( | req, | |||
| offset | ) | (ast_str_buffer((req)->data) + ((req)->offset)) |
Definition at line 1226 of file chan_sip.c.
Referenced by __get_header(), _sip_tcp_helper_thread(), find_sdp(), get_body(), get_destination(), get_msg_text(), get_sdp_iterate(), get_sdp_line(), handle_incoming(), handle_request_do(), handle_request_invite(), reqprep(), and send_response().
| #define RTP 1 |
Definition at line 569 of file chan_sip.c.
| #define SDP_MAX_RTPMAP_CODECS 32 |
Maximum number of codecs allowed in received SDP
Definition at line 553 of file chan_sip.c.
Referenced by process_sdp_a_audio(), process_sdp_a_text(), and process_sdp_a_video().
| #define SIP_CALL_LIMIT (1 << 7) |
D: Call limit enforced for this call
Definition at line 1309 of file chan_sip.c.
Referenced by check_peer_ok(), create_addr_from_peer(), and update_call_counter().
| #define SIP_DEFER_BYE_ON_TRANSFER (1 << 10) |
D: Do not hangup at first ast_hangup
Definition at line 1312 of file chan_sip.c.
Referenced by handle_invite_replaces(), handle_request_refer(), local_attended_transfer(), sip_hangup(), and sip_set_rtp_peer().
| #define SIP_DIRECT_MEDIA (1 << 20) |
DP: allow peers to be reinvited to send media directly p2p
Definition at line 1337 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), reload_config(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), and sip_get_vrtp_peer().
| #define SIP_DIRECT_MEDIA_NAT (2 << 20) |
DP: allow media reinvite when new peer is behind NAT
Definition at line 1338 of file chan_sip.c.
Referenced by handle_common_options(), sip_get_rtp_peer(), and sip_set_rtp_peer().
| #define SIP_DTMF (7 << 15) |
DP: DTMF Support: five settings, uses three bits
Definition at line 1320 of file chan_sip.c.
Referenced by _sip_show_peer(), check_peer_ok(), create_addr_from_peer(), handle_common_options(), handle_request_invite(), process_sdp(), sip_alloc(), sip_dtmfmode(), sip_new(), sip_rtp_read(), sip_senddigit_begin(), sip_senddigit_end(), sip_show_channel(), sip_show_settings(), and transmit_info_with_digit().
| #define SIP_DTMF_AUTO (3 << 15) |
DP: DTMF Support: AUTO switch between rfc2833 and in-band DTMF
Definition at line 1324 of file chan_sip.c.
Referenced by check_peer_ok(), create_addr_from_peer(), handle_common_options(), process_sdp(), sip_alloc(), and sip_new().
| #define SIP_DTMF_INBAND (1 << 15) |
DP: DTMF Support: Inband audio, only for ULAW/ALAW - "inband"
Definition at line 1322 of file chan_sip.c.
Referenced by handle_common_options(), process_sdp(), sip_dtmfmode(), sip_new(), sip_rtp_read(), sip_senddigit_begin(), and sip_senddigit_end().
| #define SIP_DTMF_INFO (2 << 15) |
DP: DTMF Support: SIP Info messages - "info"
Definition at line 1323 of file chan_sip.c.
Referenced by handle_common_options(), sip_dtmfmode(), sip_new(), and sip_senddigit_end().
| #define SIP_DTMF_RFC2833 (0 << 15) |
DP: DTMF Support: RTP DTMF - "rfc2833"
Definition at line 1321 of file chan_sip.c.
Referenced by check_peer_ok(), create_addr_from_peer(), handle_common_options(), handle_request_invite(), process_sdp(), reload_config(), sip_alloc(), sip_dtmfmode(), sip_rtp_read(), sip_senddigit_begin(), and sip_senddigit_end().
| #define SIP_DTMF_SHORTINFO (4 << 15) |
DP: DTMF Support: SIP Info messages - "info" - short variant
Definition at line 1325 of file chan_sip.c.
Referenced by handle_common_options(), sip_dtmfmode(), sip_new(), sip_senddigit_end(), and transmit_info_with_digit().
| #define SIP_FLAGS_TO_COPY |
Value:
(SIP_PROMISCREDIR | SIP_TRUSTRPID | SIP_SENDRPID | SIP_DTMF | SIP_REINVITE | \ SIP_PROG_INBAND | SIP_USECLIENTCODE | SIP_NAT | SIP_G726_NONSTANDARD | \ SIP_USEREQPHONE | SIP_INSECURE)
Definition at line 1357 of file chan_sip.c.
Referenced by check_peer_ok(), create_addr_from_peer(), set_peer_defaults(), sip_alloc(), and sip_poke_peer().
| #define SIP_G726_NONSTANDARD (1 << 31) |
DP: Use non-standard packing for G726-32 data
Definition at line 1354 of file chan_sip.c.
Referenced by add_codec_to_sdp(), handle_common_options(), and process_sdp_a_audio().
| #define SIP_GOTREFER (1 << 6) |
D: Got a refer?
Definition at line 1308 of file chan_sip.c.
Referenced by handle_request_refer(), local_attended_transfer(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_INC_COUNT (1 << 8) |
D: Did this dialog increment the counter of in-use calls?
Definition at line 1310 of file chan_sip.c.
Referenced by __sip_destroy(), handle_request_cancel(), sip_hangup(), and update_call_counter().
| #define SIP_INC_RINGING (1 << 9) |
D: Did this connection increment the counter of in-use calls?
Definition at line 1311 of file chan_sip.c.
Referenced by update_call_counter().
| #define SIP_INSECURE (3 << 23) |
DP: three settings, uses two bits
Definition at line 1342 of file chan_sip.c.
Referenced by _sip_show_peer(), and handle_common_options().
| #define SIP_INSECURE_INVITE (1 << 24) |
DP: don't require authentication for incoming INVITEs
Definition at line 1345 of file chan_sip.c.
Referenced by check_peer_ok(), and set_insecure_flags().
| #define SIP_INSECURE_NONE (0 << 23) |
DP: secure mode
Definition at line 1343 of file chan_sip.c.
| #define SIP_INSECURE_PORT (1 << 23) |
DP: don't require matching port for incoming requests
Definition at line 1344 of file chan_sip.c.
Referenced by find_peer(), get_insecure_variable_from_config(), peer_ipcmp_cb(), and set_insecure_flags().
| #define SIP_MAX_HEADERS 64 |
Max amount of SIP headers to read
Definition at line 543 of file chan_sip.c.
Referenced by add_header(), and parse_request().
| #define SIP_MAX_LINES 256 |
Max amount of lines in SIP attachment (like SDP)
Definition at line 544 of file chan_sip.c.
Referenced by parse_request().
| #define SIP_MIN_PACKET 4096 |
Initialize size of memory to allocate for packets
Definition at line 545 of file chan_sip.c.
Referenced by _sip_tcp_helper_thread(), init_req(), init_resp(), and sipsock_read().
| #define SIP_NAT (3 << 18) |
DP: four settings, uses two bits
Definition at line 1328 of file chan_sip.c.
Referenced by _sip_show_peer(), build_via(), copy_via_headers(), create_addr(), create_addr_from_peer(), handle_common_options(), process_sdp(), register_verify(), sip_alloc(), sip_nat_mode(), sip_real_dst(), sip_show_channel(), sip_show_settings(), sip_show_users(), and transmit_response_using_temp().
| #define SIP_NAT_ALWAYS (3 << 18) |
DP: NAT Both ROUTE and RFC3581
Definition at line 1332 of file chan_sip.c.
Referenced by copy_via_headers(), and handle_common_options().
| #define SIP_NAT_NEVER (0 << 18) |
DP: No nat support
Definition at line 1329 of file chan_sip.c.
Referenced by handle_common_options().
| #define SIP_NAT_RFC3581 (1 << 18) |
DP: NAT RFC3581
Definition at line 1330 of file chan_sip.c.
Referenced by build_via(), copy_via_headers(), handle_common_options(), and reload_config().
| #define SIP_NAT_ROUTE (2 << 18) |
DP: NAT Only ROUTE
Definition at line 1331 of file chan_sip.c.
Referenced by _sip_show_peers(), build_peer(), check_peer_ok(), check_user_full(), create_addr(), create_addr_from_peer(), handle_common_options(), parse_register_contact(), send_request(), set_address_from_contact(), sip_alloc(), sip_nat_mode(), sip_real_dst(), and transmit_response_using_temp().
| #define SIP_NEEDREINVITE (1 << 4) |
D: Do we need to send another reinvite?
Definition at line 1306 of file chan_sip.c.
Referenced by check_pendings(), interpret_t38_parameters(), sip_hangup(), sip_reinvite_retry(), sip_sendhtml(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_OPT_100REL (1 << 1) |
Definition at line 868 of file chan_sip.c.
| #define SIP_OPT_EARLY_SESSION (1 << 3) |
Definition at line 870 of file chan_sip.c.
| #define SIP_OPT_EVENTLIST (1 << 11) |
Definition at line 878 of file chan_sip.c.
| #define SIP_OPT_FROMCHANGE (1 << 17) |
Definition at line 884 of file chan_sip.c.
| #define SIP_OPT_GRUU (1 << 12) |
Definition at line 879 of file chan_sip.c.
| #define SIP_OPT_HISTINFO (1 << 15) |
Definition at line 882 of file chan_sip.c.
| #define SIP_OPT_JOIN (1 << 4) |
Definition at line 871 of file chan_sip.c.
| #define SIP_OPT_NOREFERSUB (1 << 14) |
Definition at line 881 of file chan_sip.c.
| #define SIP_OPT_OUTBOUND (1 << 20) |
Definition at line 887 of file chan_sip.c.
| #define SIP_OPT_PATH (1 << 5) |
Definition at line 872 of file chan_sip.c.
| #define SIP_OPT_PRECONDITION (1 << 7) |
Definition at line 874 of file chan_sip.c.
| #define SIP_OPT_PREF (1 << 6) |
Definition at line 873 of file chan_sip.c.
| #define SIP_OPT_PRIVACY (1 << 8) |
Definition at line 875 of file chan_sip.c.
| #define SIP_OPT_RECLISTINV (1 << 18) |
Definition at line 885 of file chan_sip.c.
| #define SIP_OPT_RECLISTSUB (1 << 19) |
Definition at line 886 of file chan_sip.c.
| #define SIP_OPT_REPLACES (1 << 0) |
| #define SIP_OPT_RESPRIORITY (1 << 16) |
Definition at line 883 of file chan_sip.c.
| #define SIP_OPT_SDP_ANAT (1 << 9) |
Definition at line 876 of file chan_sip.c.
| #define SIP_OPT_SEC_AGREE (1 << 10) |
Definition at line 877 of file chan_sip.c.
| #define SIP_OPT_TARGET_DIALOG (1 << 13) |
Definition at line 880 of file chan_sip.c.
| #define SIP_OPT_TIMER (1 << 2) |
| #define SIP_OPT_UNKNOWN (1 << 21) |
| #define SIP_OUTGOING (1 << 0) |
D: Direction of the last transaction in this dialog
Definition at line 1303 of file chan_sip.c.
Referenced by __sip_subscribe_mwi_do(), handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), manager_sipnotify(), reqprep(), respprep(), sip_call(), sip_cli_notify(), sip_hangup(), sip_indicate(), sip_poke_peer(), sip_send_mwi_to_peer(), sip_show_channel(), sip_write(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), and transmit_response_with_sdp().
| #define SIP_PAGE2_ALLOWOVERLAP (1 << 17) |
DP: Allow overlap dialing ?
Definition at line 1378 of file chan_sip.c.
Referenced by _sip_show_peer(), get_destination(), handle_common_options(), handle_request_invite(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_ALLOWSUBSCRIBE (1 << 16) |
GP: Allow subscriptions from this peer?
Definition at line 1377 of file chan_sip.c.
Referenced by _sip_show_peer(), build_peer(), handle_common_options(), handle_request_subscribe(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_BUGGY_MWI (1 << 26) |
DP: Buggy CISCO MWI fix
Definition at line 1393 of file chan_sip.c.
Referenced by handle_common_options(), and transmit_notify_with_mwi().
| #define SIP_PAGE2_CALL_ONHOLD (3 << 23) |
D: Call hold states:
Definition at line 1387 of file chan_sip.c.
Referenced by __sip_destroy(), add_sdp(), change_hold_state(), check_rtp_timeout(), handle_request_cancel(), handle_request_invite(), process_sdp(), show_channels_cb(), sip_hangup(), and update_call_counter().
| #define SIP_PAGE2_CALL_ONHOLD_ACTIVE (1 << 23) |
| #define SIP_PAGE2_CALL_ONHOLD_INACTIVE (3 << 23) |
D: Inactive hold
Definition at line 1390 of file chan_sip.c.
Referenced by add_sdp(), and change_hold_state().
| #define SIP_PAGE2_CALL_ONHOLD_ONEDIR (2 << 23) |
D: One directional hold
Definition at line 1389 of file chan_sip.c.
Referenced by add_sdp(), and change_hold_state().
| #define SIP_PAGE2_DIALOG_ESTABLISHED (1 << 27) |
29: Has a dialog been established?
Definition at line 1394 of file chan_sip.c.
Referenced by find_call_cb(), handle_request_bye(), handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), and sip_answer().
| #define SIP_PAGE2_FAX_DETECT (3 << 28) |
DP: Fax Detection support
Definition at line 1395 of file chan_sip.c.
Referenced by handle_common_options(), reload_config(), sip_new(), and sip_rtp_read().
| #define SIP_PAGE2_FAX_DETECT_BOTH (3 << 28) |
DP: Fax Detection support - detect both
Definition at line 1398 of file chan_sip.c.
Referenced by handle_common_options().
| #define SIP_PAGE2_FAX_DETECT_CNG (1 << 28) |
DP: Fax Detection support - detect CNG in audio
Definition at line 1396 of file chan_sip.c.
Referenced by handle_common_options(), and sip_read().
| #define SIP_PAGE2_FAX_DETECT_T38 (2 << 28) |
DP: Fax Detection support - detect T.38 reinvite from peer
Definition at line 1397 of file chan_sip.c.
Referenced by handle_common_options(), process_sdp(), and sip_call().
| #define SIP_PAGE2_FLAGS_TO_COPY |
Value:
(SIP_PAGE2_ALLOWSUBSCRIBE | SIP_PAGE2_ALLOWOVERLAP | SIP_PAGE2_IGNORESDPVERSION | \ SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_T38SUPPORT | SIP_PAGE2_RFC2833_COMPENSATE | \ SIP_PAGE2_BUGGY_MWI | SIP_PAGE2_TEXTSUPPORT | SIP_PAGE2_FAX_DETECT | \ SIP_PAGE2_UDPTL_DESTINATION | SIP_PAGE2_VIDEOSUPPORT_ALWAYS | \ SIP_PAGE2_HAVEPEERCONTEXT | SIP_PAGE2_FORWARD_LOOP_DETECTED)
Definition at line 1403 of file chan_sip.c.
Referenced by check_peer_ok(), create_addr_from_peer(), set_peer_defaults(), sip_alloc(), and sip_poke_peer().
| #define SIP_PAGE2_FORWARD_LOOP_DETECTED (1 << 8) |
31: Do call forward when receiving 482 Loop Detected
Definition at line 1371 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_response(), handle_t38_options(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_HAVEPEERCONTEXT (1 << 3) |
| #define SIP_PAGE2_IGNORESDPVERSION (1 << 19) |
GDP: Ignore the SDP session version number we receive and treat all sessions as new
Definition at line 1380 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), process_sdp_o(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_REGISTERTRYING (1 << 29) |
DP: Send 100 Trying on REGISTER attempts
Definition at line 1399 of file chan_sip.c.
Referenced by _sip_show_peer(), build_peer(), and register_verify().
| #define SIP_PAGE2_RFC2833_COMPENSATE (1 << 25) |
DP: Compensate for buggy RFC2833 implementations
Definition at line 1392 of file chan_sip.c.
Referenced by create_addr_from_peer(), handle_common_options(), handle_request_invite(), process_sdp(), sip_alloc(), and sip_show_settings().
| #define SIP_PAGE2_RPORT_PRESENT (1 << 10) |
Was rport received in the Via header?
Definition at line 1374 of file chan_sip.c.
Referenced by check_user_full(), and check_via().
| #define SIP_PAGE2_RTAUTOCLEAR (1 << 2) |
GP: Should we clean memory from peers after expiry?
Definition at line 1368 of file chan_sip.c.
Referenced by expire_register(), realtime_peer(), reload_config(), and sip_show_settings().
| #define SIP_PAGE2_RTCACHEFRIENDS (1 << 0) |
GP: Should we keep RT objects in memory for extended time?
Definition at line 1367 of file chan_sip.c.
Referenced by build_peer(), parse_register_contact(), realtime_peer(), reload_config(), sip_prune_realtime(), sip_show_settings(), and update_peer().
| #define SIP_PAGE2_STATECHANGEQUEUE (1 << 9) |
D: Unsent state pending change exists
Definition at line 1372 of file chan_sip.c.
Referenced by cb_extensionstate(), handle_response(), and handle_response_notify().
| #define SIP_PAGE2_SUBSCRIBEMWIONLY (1 << 18) |
GP: Only issue MWI notification if subscribed to
Definition at line 1379 of file chan_sip.c.
Referenced by build_peer(), handle_request_subscribe(), register_verify(), and sip_send_mwi_to_peer().
| #define SIP_PAGE2_T38SUPPORT (3 << 20) |
GDP: T.38 Fax Support
Definition at line 1382 of file chan_sip.c.
Referenced by _sip_show_peer(), check_peer_ok(), create_addr_from_peer(), handle_request_invite(), handle_t38_options(), interpret_t38_parameters(), set_t38_capabilities(), sip_alloc(), sip_queryoption(), and sip_show_settings().
| #define SIP_PAGE2_T38SUPPORT_UDPTL (1 << 20) |
GDP: T.38 Fax Support (no error correction)
Definition at line 1383 of file chan_sip.c.
Referenced by handle_t38_options(), and set_t38_capabilities().
| #define SIP_PAGE2_T38SUPPORT_UDPTL_FEC (2 << 20) |
GDP: T.38 Fax Support (FEC error correction)
Definition at line 1384 of file chan_sip.c.
Referenced by handle_t38_options(), and set_t38_capabilities().
| #define SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY (3 << 20) |
GDP: T.38 Fax Support (redundancy error correction)
Definition at line 1385 of file chan_sip.c.
Referenced by handle_t38_options(), and set_t38_capabilities().
| #define SIP_PAGE2_TEXTSUPPORT (1 << 15) |
GDP: Global text enable
Definition at line 1376 of file chan_sip.c.
Referenced by _sip_show_peer(), _sip_show_peers(), check_peer_ok(), create_addr_from_peer(), handle_common_options(), reload_config(), sip_alloc(), and sip_show_settings().
| #define SIP_PAGE2_UDPTL_DESTINATION (1 << 30) |
DP: Use source IP of RTP as destination if NAT is enabled
Definition at line 1400 of file chan_sip.c.
Referenced by handle_t38_options(), and process_sdp().
| #define SIP_PAGE2_VIDEOSUPPORT (1 << 14) |
DP: Video supported if offered?
Definition at line 1375 of file chan_sip.c.
Referenced by _sip_show_peer(), _sip_show_peers(), check_peer_ok(), create_addr_from_peer(), handle_common_options(), reload_config(), sip_alloc(), sip_new(), and sip_show_settings().
| #define SIP_PAGE2_VIDEOSUPPORT_ALWAYS (1 << 31) |
DP: Always set up video, even if endpoints don't support it
Definition at line 1401 of file chan_sip.c.
Referenced by _sip_show_peer(), check_peer_ok(), create_addr_from_peer(), handle_common_options(), reload_config(), and sip_alloc().
| #define SIP_PENDINGBYE (1 << 5) |
D: Need to send bye after we ack?
Definition at line 1307 of file chan_sip.c.
Referenced by check_pendings(), handle_response_invite(), interpret_t38_parameters(), register_verify(), sip_hangup(), sip_sendhtml(), sip_set_rtp_peer(), and sip_set_udptl_peer().
| #define SIP_PROG_INBAND (3 << 25) |
DP: three settings, uses two bits
Definition at line 1348 of file chan_sip.c.
Referenced by handle_common_options(), sip_indicate(), and sip_show_settings().
| #define SIP_PROG_INBAND_NEVER (0 << 25) |
| #define SIP_PROG_INBAND_NO (1 << 25) |
Definition at line 1350 of file chan_sip.c.
Referenced by handle_common_options(), and sip_show_settings().
| #define SIP_PROG_INBAND_YES (2 << 25) |
Definition at line 1351 of file chan_sip.c.
Referenced by handle_common_options(), and sip_indicate().
| #define SIP_PROGRESS_SENT (1 << 3) |
D: Have sent 183 message progress
Definition at line 1305 of file chan_sip.c.
Referenced by sip_indicate(), and sip_write().
| #define SIP_PROMISCREDIR (1 << 11) |
DP: Promiscuous redirection
Definition at line 1314 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), parse_moved_contact(), sip_show_channel(), and sip_show_settings().
| #define sip_pvt_lock | ( | x | ) | ao2_lock(x) |
Definition at line 1729 of file chan_sip.c.
Referenced by __sip_ack(), __sip_autodestruct(), auto_congest(), cb_extensionstate(), check_rtp_timeout(), complete_sipch(), find_call(), get_sip_pvt_byid_locked(), handle_invite_replaces(), handle_request_bye(), handle_request_invite(), proc_session_timer(), retrans_pkt(), scheduler_process_request_queue(), sip_answer(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_new(), sip_park(), sip_queryoption(), sip_read(), sip_reg_timeout(), sip_reinvite_retry(), sip_request_call(), sip_senddigit_begin(), sip_senddigit_end(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_show_channel(), sip_show_history(), sip_t38_abort(), sip_transfer(), sip_write(), and update_call_counter().
| #define sip_pvt_trylock | ( | x | ) | ao2_trylock(x) |
Definition at line 1730 of file chan_sip.c.
Referenced by dialog_needdestroy(), find_call(), and sip_hangup().
| #define sip_pvt_unlock | ( | x | ) | ao2_unlock(x) |
Definition at line 1731 of file chan_sip.c.
Referenced by __sip_ack(), __sip_autodestruct(), auto_congest(), cb_extensionstate(), check_rtp_timeout(), complete_sipch(), dialog_needdestroy(), get_sip_pvt_byid_locked(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), local_attended_transfer(), proc_session_timer(), retrans_pkt(), scheduler_process_request_queue(), sip_answer(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_new(), sip_park(), sip_queryoption(), sip_read(), sip_reg_timeout(), sip_reinvite_retry(), sip_request_call(), sip_senddigit_begin(), sip_senddigit_end(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_show_channel(), sip_show_history(), sip_t38_abort(), sip_transfer(), sip_write(), and update_call_counter().
| #define SIP_REINVITE (7 << 20) |
DP: four settings, uses three bits
Definition at line 1335 of file chan_sip.c.
Referenced by handle_common_options().
| #define SIP_REINVITE_NONE (0 << 20) |
DP: no reinvite allowed
Definition at line 1336 of file chan_sip.c.
| #define SIP_REINVITE_UPDATE (4 << 20) |
DP: use UPDATE (RFC3311) when reinviting this peer
Definition at line 1339 of file chan_sip.c.
Referenced by handle_common_options(), and transmit_reinvite_with_sdp().
| #define SIP_RESERVED ";/?:@&=+$,# " |
Reserved characters in the username part of the URI
Definition at line 493 of file chan_sip.c.
| #define SIP_RINGING (1 << 2) |
| #define SIP_SENDRPID (1 << 29) |
DP: Remote Party-ID Support
Definition at line 1353 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), and initreqprep().
| #define SIP_TRANS_TIMEOUT 64 * DEFAULT_TIMER_T1 |
SIP request timeout (rfc 3261) 64*T1
Definition at line 536 of file chan_sip.c.
Referenced by manager_sipnotify(), sip_cli_notify(), and sip_sipredirect().
| #define SIP_TRUSTRPID (1 << 12) |
DP: Trust RPID headers?
Definition at line 1315 of file chan_sip.c.
Referenced by _sip_show_peer(), handle_common_options(), and replace_cid().
| #define SIP_USECLIENTCODE (1 << 14) |
DP: Trust X-ClientCode info message
Definition at line 1317 of file chan_sip.c.
Referenced by handle_common_options(), handle_request_info(), and sip_show_settings().
| #define SIP_USEREQPHONE (1 << 13) |
DP: Add user=phone to numeric URI. Default off
Definition at line 1316 of file chan_sip.c.
Referenced by _sip_show_peer(), build_peer(), initreqprep(), reload_config(), and sip_show_settings().
| #define SIPBUFSIZE 512 |
Buffer size for many operations
Definition at line 489 of file chan_sip.c.
Referenced by add_route(), add_sdp(), extract_uri(), handle_request_refer(), initreqprep(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), process_sdp(), respprep(), show_channels_cb(), sip_call(), sip_new(), sip_show_channel(), sip_show_settings(), transmit_invite(), and transmit_notify_with_sipfrag().
| #define STANDARD_SIP_PORT 5060 |
Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS.
Definition at line 952 of file chan_sip.c.
Referenced by __set_address_from_contact(), build_peer(), check_via(), create_addr(), manager_show_registry(), parse_register_contact(), proxy_allocate(), reload_config(), set_destination(), set_peer_defaults(), sip_parse_host(), sip_register(), sip_show_mwi(), sip_show_registry(), sip_standard_port(), and transmit_register().
| #define STANDARD_TLS_PORT 5061 |
Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS.
Definition at line 954 of file chan_sip.c.
Referenced by __set_address_from_contact(), build_peer(), create_addr(), parse_register_contact(), reload_config(), set_destination(), sip_parse_host(), sip_register(), and sip_standard_port().
| #define SUPPORTED 1 |
Define SIP option tags, used in Require: and Supported: headers We need to be aware of these properties in the phones to use the replace: header. We should not do that without knowing that the other end supports it... This is nothing we can configure, we learn by the dialog Supported: header on the REGISTER (peer) or the INVITE (other devices) We are not using many of these today, but will in the future. This is documented in RFC 3261
Definition at line 863 of file chan_sip.c.
| #define TRUE 1 |
Definition at line 481 of file chan_sip.c.
| #define UNLINK | ( | element, | |||
| head, | |||||
| prev | ) |
some list management macros.
Definition at line 2222 of file chan_sip.c.
Referenced by __sip_ack(), handle_request_cancel(), and retrans_pkt().
| #define XMIT_ERROR -2 |
Definition at line 491 of file chan_sip.c.
Referenced by __sip_reliable_xmit(), __sip_xmit(), handle_response_invite(), retrans_pkt(), sip_call(), sip_poke_peer(), and sip_tcptls_write().
| enum can_create_dialog |
States whether a SIP message can create a dialog in Asterisk.
Definition at line 779 of file chan_sip.c.
00779 { 00780 CAN_NOT_CREATE_DIALOG, 00781 CAN_CREATE_DIALOG, 00782 CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, 00783 };
| enum check_auth_result |
Authentication result from check_auth* functions.
Definition at line 679 of file chan_sip.c.
00679 { 00680 AUTH_DONT_KNOW = -100, /*!< no result, need to check further */ 00681 /* XXX maybe this is the same as AUTH_NOT_FOUND */ 00682 00683 AUTH_SUCCESSFUL = 0, 00684 AUTH_CHALLENGE_SENT = 1, 00685 AUTH_SECRET_FAILED = -1, 00686 AUTH_USERNAME_MISMATCH = -2, 00687 AUTH_NOT_FOUND = -3, /*!< returned by register_verify */ 00688 AUTH_FAKE_AUTH = -4, 00689 AUTH_UNKNOWN_DOMAIN = -5, 00690 AUTH_PEER_NOT_DYNAMIC = -6, 00691 AUTH_ACL_FAILED = -7, 00692 AUTH_BAD_TRANSPORT = -8, 00693 };
| enum domain_mode |
Modes for SIP domain handling in the PBX.
| SIP_DOMAIN_AUTO | This domain is auto-configured |
| SIP_DOMAIN_CONFIG | This domain is from configuration |
Definition at line 1257 of file chan_sip.c.
01257 { 01258 SIP_DOMAIN_AUTO, /*!< This domain is auto-configured */ 01259 SIP_DOMAIN_CONFIG, /*!< This domain is from configuration */ 01260 };
| enum invitestates |
States for the INVITE transaction, not the dialog.
| INV_NONE | No state at all, maybe not an INVITE dialog |
| INV_CALLING | Invite sent, no answer |
| INV_PROCEEDING | We got/sent 1xx message |
| INV_EARLY_MEDIA | We got 18x message with to-tag back |
| INV_COMPLETED | Got final response with error. Wait for ACK, then CONFIRMED |
| INV_CONFIRMED | Confirmed response - we've got an ack (Incoming calls only) |
| INV_TERMINATED | Transaction done - either successful (AST_STATE_UP) or failed, but done The only way out of this is a BYE from one side |
| INV_CANCELLED | Transaction cancelled by client or server in non-terminated state |
Definition at line 591 of file chan_sip.c.
00591 { 00592 INV_NONE = 0, /*!< No state at all, maybe not an INVITE dialog */ 00593 INV_CALLING = 1, /*!< Invite sent, no answer */ 00594 INV_PROCEEDING = 2, /*!< We got/sent 1xx message */ 00595 INV_EARLY_MEDIA = 3, /*!< We got 18x message with to-tag back */ 00596 INV_COMPLETED = 4, /*!< Got final response with error. Wait for ACK, then CONFIRMED */ 00597 INV_CONFIRMED = 5, /*!< Confirmed response - we've got an ack (Incoming calls only) */ 00598 INV_TERMINATED = 6, /*!< Transaction done - either successful (AST_STATE_UP) or failed, but done 00599 The only way out of this is a BYE from one side */ 00600 INV_CANCELLED = 7, /*!< Transaction cancelled by client or server in non-terminated state */ 00601 };
| enum media_type |
| enum notifycid_setting |
Settings for the 'notifycid' option, see sip.conf.sample for details.
Definition at line 816 of file chan_sip.c.
00816 { 00817 DISABLED = 0, 00818 ENABLED = 1, 00819 IGNORE_CONTEXT = 2, 00820 };
Results from the parse_register() function.
Definition at line 630 of file chan_sip.c.
00630 { 00631 PARSE_REGISTER_DENIED, 00632 PARSE_REGISTER_FAILED, 00633 PARSE_REGISTER_UPDATE, 00634 PARSE_REGISTER_QUERY, 00635 };
| enum referstatus |
Parameters to know status of transfer.
| REFER_IDLE | No REFER is in progress |
| REFER_SENT | Sent REFER to transferee |
| REFER_RECEIVED | Received REFER from transferrer |
| REFER_CONFIRMED | Refer confirmed with a 100 TRYING (unused) |
| REFER_ACCEPTED | Accepted by transferee |
| REFER_RINGING | Target Ringing |
| REFER_200OK | Answered by transfer target |
| REFER_FAILED | REFER declined - go on |
| REFER_NOAUTH | We had no auth for REFER |
Definition at line 1448 of file chan_sip.c.
01448 { 01449 REFER_IDLE, /*!< No REFER is in progress */ 01450 REFER_SENT, /*!< Sent REFER to transferee */ 01451 REFER_RECEIVED, /*!< Received REFER from transferrer */ 01452 REFER_CONFIRMED, /*!< Refer confirmed with a 100 TRYING (unused) */ 01453 REFER_ACCEPTED, /*!< Accepted by transferee */ 01454 REFER_RINGING, /*!< Target Ringing */ 01455 REFER_200OK, /*!< Answered by transfer target */ 01456 REFER_FAILED, /*!< REFER declined - go on */ 01457 REFER_NOAUTH /*!< We had no auth for REFER */ 01458 };
| enum sip_auth_type |
Authentication types - proxy or www authentication.
Definition at line 673 of file chan_sip.c.
00673 { 00674 PROXY_AUTH = 407, 00675 WWW_AUTH = 401, 00676 };
| enum sip_debug_e |
debugging state We store separately the debugging requests from the config file and requests from the CLI. Debugging is enabled if either is set (which means that if sipdebug is set in the config file, we can only turn it off by reloading the config).
Definition at line 1418 of file chan_sip.c.
01418 { 01419 sip_debug_none = 0, 01420 sip_debug_config = 1, 01421 sip_debug_console = 2, 01422 };
| enum sip_peer_type |
Definition at line 1812 of file chan_sip.c.
01812 { 01813 SIP_TYPE_PEER = (1 << 0), 01814 SIP_TYPE_USER = (1 << 1), 01815 };
| enum sip_result |
The result of a lot of functions.
Definition at line 583 of file chan_sip.c.
00583 { 00584 AST_SUCCESS = 0, /*!< FALSE means success, funny enough */ 00585 AST_FAILURE = -1, /*!< Failure code */ 00586 };
| enum sip_tcptls_alert |
| TCPTLS_ALERT_DATA | There is new data to be sent out. |
| TCPTLS_ALERT_STOP | A request to stop the tcp_handler thread. |
Definition at line 1958 of file chan_sip.c.
01958 { 01959 /*! \brief There is new data to be sent out */ 01960 TCPTLS_ALERT_DATA, 01961 /*! \brief A request to stop the tcp_handler thread */ 01962 TCPTLS_ALERT_STOP, 01963 };
| enum sip_transport |
Define some implemented SIP transports.
| SIP_TRANSPORT_UDP | Unreliable transport for SIP, needs retransmissions |
| SIP_TRANSPORT_TCP | Reliable, but unsecure |
| SIP_TRANSPORT_TLS | TCP/TLS - reliable and secure transport for signalling |
Definition at line 748 of file chan_sip.c.
00748 { 00749 SIP_TRANSPORT_UDP = 1, /*!< Unreliable transport for SIP, needs retransmissions */ 00750 SIP_TRANSPORT_TCP = 1 << 1, /*!< Reliable, but unsecure */ 00751 SIP_TRANSPORT_TLS = 1 << 2, /*!< TCP/TLS - reliable and secure transport for signalling */ 00752 };
| enum sipmethod |
SIP Request methods known by Asterisk.
Definition at line 795 of file chan_sip.c.
00795 { 00796 SIP_UNKNOWN, /*!< Unknown response */ 00797 SIP_RESPONSE, /*!< Not request, response to outbound request */ 00798 SIP_REGISTER, /*!< Registration to the mothership, tell us where you are located */ 00799 SIP_OPTIONS, /*!< Check capabilities of a device, used for "ping" too */ 00800 SIP_NOTIFY, /*!< Status update, Part of the event package standard, result of a SUBSCRIBE or a REFER */ 00801 SIP_INVITE, /*!< Set up a session */ 00802 SIP_ACK, /*!< End of a three-way handshake started with INVITE. */ 00803 SIP_PRACK, /*!< Reliable pre-call signalling. Not supported in Asterisk. */ 00804 SIP_BYE, /*!< End of a session */ 00805 SIP_REFER, /*!< Refer to another URI (transfer) */ 00806 SIP_SUBSCRIBE, /*!< Subscribe for updates (voicemail, session status, device status, presence) */ 00807 SIP_MESSAGE, /*!< Text messaging */ 00808 SIP_UPDATE, /*!< Update a dialog. We can send UPDATE; but not accept it */ 00809 SIP_INFO, /*!< Information updates during a session */ 00810 SIP_CANCEL, /*!< Cancel an INVITE */ 00811 SIP_PUBLISH, /*!< Not supported in Asterisk */ 00812 SIP_PING, /*!< Not supported at all, no standard but still implemented out there */ 00813 };
| enum sipregistrystate |
States for outbound registrations (with register= lines in sip.conf.
| REG_STATE_UNREGISTERED |
We are not registered
|
| REG_STATE_REGSENT |
Registration request sent
|
| REG_STATE_AUTHSENT |
We have tried to authenticate
|
| REG_STATE_REGISTERED | Registered and done |
| REG_STATE_REJECTED |
Registration rejected *
|
| REG_STATE_TIMEOUT |
Registration timed out *
|
| REG_STATE_NOAUTH |
We have no accepted credentials
|
| REG_STATE_FAILED |
Registration failed after several tries
|
Definition at line 696 of file chan_sip.c.
00696 { 00697 REG_STATE_UNREGISTERED = 0, /*!< We are not registered 00698 * \note Initial state. We should have a timeout scheduled for the initial 00699 * (or next) registration transmission, calling sip_reregister 00700 */ 00701 00702 REG_STATE_REGSENT, /*!< Registration request sent 00703 * \note sent initial request, waiting for an ack or a timeout to 00704 * retransmit the initial request. 00705 */ 00706 00707 REG_STATE_AUTHSENT, /*!< We have tried to authenticate 00708 * \note entered after transmit_register with auth info, 00709 * waiting for an ack. 00710 */ 00711 00712 REG_STATE_REGISTERED, /*!< Registered and done */ 00713 00714 REG_STATE_REJECTED, /*!< Registration rejected * 00715 * \note only used when the remote party has an expire larger than 00716 * our max-expire. This is a final state from which we do not 00717 * recover (not sure how correctly). 00718 */ 00719 00720 REG_STATE_TIMEOUT, /*!< Registration timed out * 00721 * \note XXX unused */ 00722 00723 REG_STATE_NOAUTH, /*!< We have no accepted credentials 00724 * \note fatal - no chance to proceed */ 00725 00726 REG_STATE_FAILED, /*!< Registration failed after several tries 00727 * \note fatal - no chance to proceed */ 00728 };
| enum st_mode |
Modes in which Asterisk can be configured to run SIP Session-Timers.
| SESSION_TIMER_MODE_INVALID | Invalid value |
| SESSION_TIMER_MODE_ACCEPT | Honor inbound Session-Timer requests |
| SESSION_TIMER_MODE_ORIGINATE | Originate outbound and honor inbound requests |
| SESSION_TIMER_MODE_REFUSE | Ignore inbound Session-Timers requests |
Definition at line 731 of file chan_sip.c.
00731 { 00732 SESSION_TIMER_MODE_INVALID = 0, /*!< Invalid value */ 00733 SESSION_TIMER_MODE_ACCEPT, /*!< Honor inbound Session-Timer requests */ 00734 SESSION_TIMER_MODE_ORIGINATE, /*!< Originate outbound and honor inbound requests */ 00735 SESSION_TIMER_MODE_REFUSE /*!< Ignore inbound Session-Timers requests */ 00736 };
| enum st_refresher |
The entity playing the refresher role for Session-Timers.
| SESSION_TIMER_REFRESHER_AUTO | Negotiated |
| SESSION_TIMER_REFRESHER_UAC | Session is refreshed by the UAC |
| SESSION_TIMER_REFRESHER_UAS | Session is refreshed by the UAS |
Definition at line 739 of file chan_sip.c.
00739 { 00740 SESSION_TIMER_REFRESHER_AUTO, /*!< Negotiated */ 00741 SESSION_TIMER_REFRESHER_UAC, /*!< Session is refreshed by the UAC */ 00742 SESSION_TIMER_REFRESHER_UAS /*!< Session is refreshed by the UAS */ 00743 };
| enum subscriptiontype |
Type of subscription, based on the packages we do support, see subscription_types.
Definition at line 638 of file chan_sip.c.
00638 { 00639 NONE = 0, 00640 XPIDF_XML, 00641 DIALOG_INFO_XML, 00642 CPIM_PIDF_XML, 00643 PIDF_XML, 00644 MWI_NOTIFICATION 00645 };
| enum t38_action_flag |
| SDP_T38_NONE | Do not modify T38 information at all |
| SDP_T38_INITIATE | Remote side has requested T38 with us |
| SDP_T38_ACCEPT | Remote side accepted our T38 request |
Definition at line 2229 of file chan_sip.c.
02229 { 02230 SDP_T38_NONE = 0, /*!< Do not modify T38 information at all */ 02231 SDP_T38_INITIATE, /*!< Remote side has requested T38 with us */ 02232 SDP_T38_ACCEPT, /*!< Remote side accepted our T38 request */ 02233 };
| enum t38state |
T38 States for a call.
| T38_DISABLED | Not enabled |
| T38_LOCAL_REINVITE | Offered from local - REINVITE |
| T38_PEER_REINVITE | Offered from peer - REINVITE |
| T38_ENABLED | Negotiated (enabled) |
Definition at line 1433 of file chan_sip.c.
01433 { 01434 T38_DISABLED = 0, /*!< Not enabled */ 01435 T38_LOCAL_REINVITE, /*!< Offered from local - REINVITE */ 01436 T38_PEER_REINVITE, /*!< Offered from peer - REINVITE */ 01437 T38_ENABLED /*!< Negotiated (enabled) */ 01438 };
| enum transfermodes |
Authorization scheme for call transfers.
Definition at line 576 of file chan_sip.c.
00576 { 00577 TRANSFER_OPENFORALL, /*!< Allow all SIP transfers */ 00578 TRANSFER_CLOSED, /*!< Allow no SIP transfers */ 00579 };
| enum xmittype |
When sending a SIP message, we can send with a few options, depending on type of SIP request. UNRELIABLE is moslty used for responses to repeated requests, where the original response would be sent RELIABLE in an INVITE transaction.
| XMIT_CRITICAL | Transmit critical SIP message reliably, with re-transmits. If it fails, it's critical and will cause a teardown of the session |
| XMIT_RELIABLE | Transmit SIP message reliably, with re-transmits |
| XMIT_UNRELIABLE | Transmit SIP message without bothering with re-transmits |
Definition at line 622 of file chan_sip.c.
00622 { 00623 XMIT_CRITICAL = 2, /*!< Transmit critical SIP message reliably, with re-transmits. 00624 If it fails, it's critical and will cause a teardown of the session */ 00625 XMIT_RELIABLE = 1, /*!< Transmit SIP message reliably, with re-transmits */ 00626 XMIT_UNRELIABLE = 0, /*!< Transmit SIP message without bothering with re-transmits */ 00627 };
| static const char * __get_header | ( | const struct sip_request * | req, | |
| const char * | name, | |||
| int * | start | |||
| ) | [static] |
Definition at line 7013 of file chan_sip.c.
References ast_skip_blanks(), find_alias(), sip_request::header, sip_request::headers, pass, sip_settings::pedanticsipchecking, REQ_OFFSET_TO_STR, and sip_cfg.
Referenced by build_route(), copy_all_header(), copy_via_headers(), func_header_read(), get_header(), handle_request_subscribe(), and handle_response_register().
07014 { 07015 int pass; 07016 07017 /* 07018 * Technically you can place arbitrary whitespace both before and after the ':' in 07019 * a header, although RFC3261 clearly says you shouldn't before, and place just 07020 * one afterwards. If you shouldn't do it, what absolute idiot decided it was 07021 * a good idea to say you can do it, and if you can do it, why in the hell would. 07022 * you say you shouldn't. 07023 * Anyways, pedanticsipchecking controls whether we allow spaces before ':', 07024 * and we always allow spaces after that for compatibility. 07025 */ 07026 for (pass = 0; name && pass < 2;pass++) { 07027 int x, len = strlen(name); 07028 for (x = *start; x < req->headers; x++) { 07029 char *header = REQ_OFFSET_TO_STR(req, header[x]); 07030 if (!strncasecmp(header, name, len)) { 07031 char *r = header + len; /* skip name */ 07032 if (sip_cfg.pedanticsipchecking) 07033 r = ast_skip_blanks(r); 07034 07035 if (*r == ':') { 07036 *start = x+1; 07037 return ast_skip_blanks(r+1); 07038 } 07039 } 07040 } 07041 if (pass == 0) /* Try aliases */ 07042 name = find_alias(name, NULL); 07043 } 07044 07045 /* Don't return NULL, so get_header is always a valid pointer */ 07046 return ""; 07047 }
| static void __init_check_auth_buf | ( | void | ) | [static] |
| static void __init_ts_temp_pvt | ( | void | ) | [static] |
| static void __reg_module | ( | void | ) | [static] |
Definition at line 26250 of file chan_sip.c.
| static int __set_address_from_contact | ( | const char * | fullcontact, | |
| struct sockaddr_in * | sin, | |||
| int | tcp | |||
| ) | [static] |
Definition at line 12330 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_log(), get_transport_str2enum(), hp, LOG_WARNING, parse_uri(), port_str2int(), SIP_TRANSPORT_TLS, STANDARD_SIP_PORT, and STANDARD_TLS_PORT.
Referenced by build_peer(), and set_address_from_contact().
12331 { 12332 struct hostent *hp; 12333 struct ast_hostent ahp; 12334 int port = STANDARD_SIP_PORT; 12335 char *host, *pt, *transport; 12336 char contact_buf[256]; 12337 char *contact; 12338 12339 /* Work on a copy */ 12340 ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf)); 12341 contact = contact_buf; 12342 12343 /* 12344 * We have only the part in <brackets> here so we just need to parse a SIP URI. 12345 * 12346 * Note: The outbound proxy could be using UDP between the proxy and Asterisk. 12347 * We still need to be able to send to the remote agent through the proxy. 12348 */ 12349 12350 if (parse_uri(contact, "sip:,sips:", &contact, NULL, &host, &pt, NULL, &transport)) { 12351 ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact); 12352 } 12353 12354 /* set port */ 12355 if (((get_transport_str2enum(transport) == SIP_TRANSPORT_TLS)) || !(strncasecmp(fullcontact, "sips", 4))) { 12356 port = port_str2int(pt, STANDARD_TLS_PORT); 12357 } else { 12358 port = port_str2int(pt, STANDARD_SIP_PORT); 12359 } 12360 12361 12362 /* XXX This could block for a long time XXX */ 12363 /* We should only do this if it's a name, not an IP */ 12364 /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records 12365 to find transport, port address and hostname. If there's a port number, we have to 12366 assume that the domain part is a host name and only look for an A/AAAA record in DNS. 12367 */ 12368 hp = ast_gethostbyname(host, &ahp); 12369 if (!hp) { 12370 ast_log(LOG_WARNING, "Invalid host name in Contact: (can't resolve in DNS) : '%s'\n", host); 12371 return -1; 12372 } 12373 sin->sin_family = AF_INET; 12374 memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr)); 12375 sin->sin_port = htons(port); 12376 12377 return 0; 12378 }
| static int __sip_ack | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| int | sipmethod | |||
| ) | [static] |
Acknowledges receipt of a packet and stops retransmission called with p locked.
Definition at line 4094 of file chan_sip.c.
References ast_debug, ast_free, ast_sched_del(), sip_pvt::callid, sip_pkt::data, dialog_unref(), FALSE, sip_proxy::force, sip_pkt::is_resp, sip_pkt::method, msg, sip_pkt::next, sip_pvt::outboundproxy, sip_pkt::owner, sip_pvt::packets, sip_pvt::pendinginvite, ref_proxy(), sip_pkt::retransid, sip_pkt::seqno, sip_pvt_lock, sip_pvt_unlock, TRUE, and UNLINK.
Referenced by __sip_pretend_ack(), handle_incoming(), handle_request_invite(), and handle_response().
04095 { 04096 struct sip_pkt *cur, *prev = NULL; 04097 const char *msg = "Not Found"; /* used only for debugging */ 04098 int res = FALSE; 04099 04100 /* If we have an outbound proxy for this dialog, then delete it now since 04101 the rest of the requests in this dialog needs to follow the routing. 04102 If obforcing is set, we will keep the outbound proxy during the whole 04103 dialog, regardless of what the SIP rfc says 04104 */ 04105 if (p->outboundproxy && !p->outboundproxy->force){ 04106 ref_proxy(p, NULL); 04107 } 04108 04109 for (cur = p->packets; cur; prev = cur, cur = cur->next) { 04110 if (cur->seqno != seqno || cur->is_resp != resp) 04111 continue; 04112 if (cur->is_resp || cur->method == sipmethod) { 04113 res = TRUE; 04114 msg = "Found"; 04115 if (!resp && (seqno == p->pendinginvite)) { 04116 ast_debug(1, "Acked pending invite %d\n", p->pendinginvite); 04117 p->pendinginvite = 0; 04118 } 04119 if (cur->retransid > -1) { 04120 if (sipdebug) 04121 ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid); 04122 } 04123 /* This odd section is designed to thwart a 04124 * race condition in the packet scheduler. There are 04125 * two conditions under which deleting the packet from the 04126 * scheduler can fail. 04127 * 04128 * 1. The packet has been removed from the scheduler because retransmission 04129 * is being attempted. The problem is that if the packet is currently attempting 04130 * retransmission and we are at this point in the code, then that MUST mean 04131 * that retrans_pkt is waiting on p's lock. Therefore we will relinquish the 04132 * lock temporarily to allow retransmission. 04133 * 04134 * 2. The packet has reached its maximum number of retransmissions and has 04135 * been permanently removed from the packet scheduler. If this is the case, then 04136 * the packet's retransid will be set to -1. The atomicity of the setting and checking 04137 * of the retransid to -1 is ensured since in both cases p's lock is held. 04138 */ 04139 while (cur->retransid > -1 && ast_sched_del(sched, cur->retransid)) { 04140 sip_pvt_unlock(p); 04141 usleep(1); 04142 sip_pvt_lock(p); 04143 } 04144 UNLINK(cur, p->packets, prev); 04145 dialog_unref(cur->owner, "unref pkt cur->owner dialog from sip ack before freeing pkt"); 04146 if (cur->data) 04147 ast_free(cur->data); 04148 ast_free(cur); 04149 break; 04150 } 04151 } 04152 ast_debug(1, "Stopping retransmission on '%s' of %s %d: Match %s\n", 04153 p->callid, resp ? "Response" : "Request", seqno, msg); 04154 return res; 04155 }
| static int __sip_autodestruct | ( | const void * | data | ) | [static] |
Kill a SIP dialog (called only by the scheduler) The scheduler has a reference to this dialog when p->autokillid != -1, and we are called using that reference. So if the event is not rescheduled, we need to call dialog_unref().
Definition at line 3980 of file chan_sip.c.
References __sip_pretend_ack(), sip_pvt::alreadygone, append_history, AST_CAUSE_PROTOCOL_ERROR, ast_channel_trylock, ast_channel_unlock, ast_debug, AST_EXTENSION_DEACTIVATED, ast_log(), ast_queue_hangup_with_cause(), sip_pvt::autokillid, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, dialog_unlink_all(), dialog_unref(), sip_pvt::lastmsg, LOG_WARNING, sip_pvt::method, method_match(), sip_pvt::needdestroy, NONE, sip_pvt::owner, sip_pvt::packets, pvt_set_needdestroy(), sip_pvt::refer, SIP_BYE, SIP_CANCEL, sip_methods, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), sip_pvt::subscribed, cfsip_methods::text, transmit_request_with_auth(), transmit_state_notify(), TRUE, and XMIT_RELIABLE.
Referenced by sip_scheddestroy(), and sip_show_sched().
03981 { 03982 struct sip_pvt *p = (struct sip_pvt *)data; 03983 03984 /* If this is a subscription, tell the phone that we got a timeout */ 03985 if (p->subscribed) { 03986 transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, TRUE); /* Send last notification */ 03987 p->subscribed = NONE; 03988 append_history(p, "Subscribestatus", "timeout"); 03989 ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>"); 03990 return 10000; /* Reschedule this destruction so that we know that it's gone */ 03991 } 03992 03993 /* If there are packets still waiting for delivery, delay the destruction */ 03994 if (p->packets) { 03995 if (!p->needdestroy) { 03996 char method_str[31]; 03997 ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>"); 03998 append_history(p, "ReliableXmit", "timeout"); 03999 if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) { 04000 if (method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) { 04001 pvt_set_needdestroy(p, "autodestruct"); 04002 } 04003 } 04004 return 10000; 04005 } else { 04006 /* They've had their chance to respond. Time to bail */ 04007 __sip_pretend_ack(p); 04008 } 04009 } 04010 04011 /* Reset schedule ID */ 04012 p->autokillid = -1; 04013 04014 04015 /* 04016 * Lock both the pvt and the channel safely so that we can queue up a frame. 04017 */ 04018 sip_pvt_lock(p); 04019 while (p->owner && ast_channel_trylock(p->owner)) { 04020 sip_pvt_unlock(p); 04021 sched_yield(); 04022 sip_pvt_lock(p); 04023 } 04024 04025 if (p->owner) { 04026 ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s)\n", p->callid, sip_methods[p->method].text); 04027 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR); 04028 ast_channel_unlock(p->owner); 04029 } else if (p->refer && !p->alreadygone) { 04030 ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid); 04031 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 04032 append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid); 04033 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 04034 } else { 04035 append_history(p, "AutoDestroy", "%s", p->callid); 04036 ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid); 04037 dialog_unlink_all(p, TRUE, TRUE); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */ 04038 /* dialog_unref(p, "unref dialog-- no other matching conditions"); -- unlink all now should finish off the dialog's references and free it. */ 04039 /* sip_destroy(p); */ /* Go ahead and destroy dialog. All attempts to recover is done */ 04040 /* sip_destroy also absorbs the reference */ 04041 } 04042 04043 sip_pvt_unlock(p); 04044 04045 dialog_unref(p, "The ref to a dialog passed to this sched callback is going out of scope; unref it."); 04046 04047 return 0; 04048 }
| static void __sip_destroy | ( | struct sip_pvt * | p, | |
| int | lockowner, | |||
| int | lockdialoglist | |||
| ) | [static] |
Execute destruction of SIP dialog structure, release memory.
Definition at line 5573 of file chan_sip.c.
References ast_channel::_softhangup, ao2_ref, ast_channel_lock, ast_channel_unlock, ast_debug, ast_free, AST_LIST_REMOVE_HEAD, ast_log(), ast_rtp_destroy(), ast_rtp_get_bridged(), AST_SCHED_DEL_UNREF, AST_SOFTHANGUP_DEV, ast_string_field_free_memory, ast_test_flag, ast_udptl_destroy(), ast_variables_destroy(), ast_verbose, sip_subscription_mwi::call, sip_registry::call, sip_peer::call, sip_pvt::callid, sip_pvt::chanvars, DEC_CALL_LIMIT, deinit_req(), dialog_unref(), sip_pvt::flags, free_old_route(), sip_pvt::history, sip_pvt::history_entries, sip_pvt::initreq, LOG_DEBUG, sip_pvt::method, sip_pvt::mwi, sip_peer::mwipvt, ast_channel::name, sip_pvt::notify_headers, option_debug, sip_pvt::options, sip_pvt::owner, sip_st_dlg::quit_flag, sip_pvt::refer, sip_pvt::registry, registry_unref(), sip_pvt::relatedpeer, sip_pvt::request_queue, sip_pvt::route, sip_pvt::rtp, sip_debug_test_pvt(), sip_dump_history(), SIP_INC_COUNT, sip_methods, SIP_PAGE2_CALL_ONHOLD, sip_pvt::socket, sip_st_dlg::st_active, sip_st_dlg::st_schedid, sip_pvt::stimer, sip_socket::tcptls_session, ast_channel::tech_pvt, cfsip_methods::text, sip_pvt::trtp, TRUE, sip_pvt::udptl, unref_peer(), update_call_counter(), and sip_pvt::vrtp.
Referenced by sip_destroy().
05574 { 05575 struct sip_request *req; 05576 05577 if (p->stimer) { 05578 ast_free(p->stimer); 05579 p->stimer = NULL; 05580 } 05581 05582 if (sip_debug_test_pvt(p)) 05583 ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text); 05584 05585 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 05586 update_call_counter(p, DEC_CALL_LIMIT); 05587 ast_debug(2, "This call did not properly clean up call limits. Call ID %s\n", p->callid); 05588 } 05589 05590 /* Unlink us from the owner if we have one */ 05591 if (p->owner) { 05592 if (lockowner) 05593 ast_channel_lock(p->owner); 05594 if (option_debug) 05595 ast_log(LOG_DEBUG, "Detaching from %s\n", p->owner->name); 05596 p->owner->tech_pvt = NULL; 05597 /* Make sure that the channel knows its backend is going away */ 05598 p->owner->_softhangup |= AST_SOFTHANGUP_DEV; 05599 if (lockowner) 05600 ast_channel_unlock(p->owner); 05601 /* Give the channel a chance to react before deallocation */ 05602 usleep(1); 05603 } 05604 05605 /* Remove link from peer to subscription of MWI */ 05606 if (p->relatedpeer && p->relatedpeer->mwipvt) 05607 p->relatedpeer->mwipvt = dialog_unref(p->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt"); 05608 if (p->relatedpeer && p->relatedpeer->call == p) 05609 p->relatedpeer->call = dialog_unref(p->relatedpeer->call, "unset the relatedpeer->call field in tandem with relatedpeer field itself"); 05610 05611 if (p->relatedpeer) 05612 p->relatedpeer = unref_peer(p->relatedpeer,"unsetting a dialog relatedpeer field in sip_destroy"); 05613 05614 if (p->registry) { 05615 if (p->registry->call == p) 05616 p->registry->call = dialog_unref(p->registry->call, "nulling out the registry's call dialog field in unlink_all"); 05617 p->registry = registry_unref(p->registry, "delete p->registry"); 05618 } 05619 05620 if (p->mwi) { 05621 p->mwi->call = NULL; 05622 } 05623 05624 if (dumphistory) 05625 sip_dump_history(p); 05626 05627 if (p->options) 05628 ast_free(p->options); 05629 05630 if (p->notify_headers) { 05631 ast_variables_destroy(p->notify_headers); 05632 p->notify_headers = NULL; 05633 } 05634 if (p->rtp) { 05635 ast_rtp_destroy(p->rtp); 05636 } 05637 if (p->vrtp) { 05638 ast_rtp_destroy(p->vrtp); 05639 } 05640 if (p->trtp) { 05641 while (ast_rtp_get_bridged(p->trtp)) 05642 usleep(1); 05643 ast_rtp_destroy(p->trtp); 05644 } 05645 if (p->udptl) 05646 ast_udptl_destroy(p->udptl); 05647 if (p->refer) 05648 ast_free(p->refer); 05649 if (p->route) { 05650 free_old_route(p->route); 05651 p->route = NULL; 05652 } 05653 deinit_req(&p->initreq); 05654 05655 /* Destroy Session-Timers if allocated */ 05656 if (p->stimer) { 05657 p->stimer->quit_flag = 1; 05658 if (p->stimer->st_active == TRUE && p->stimer->st_schedid > -1) { 05659 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 05660 dialog_unref(p, "removing session timer ref")); 05661 } 05662 ast_free(p->stimer); 05663 p->stimer = NULL; 05664 } 05665 05666 /* Clear history */ 05667 if (p->history) { 05668 struct sip_history *hist; 05669 while ( (hist = AST_LIST_REMOVE_HEAD(p->history, list)) ) { 05670 ast_free(hist); 05671 p->history_entries--; 05672 } 05673 ast_free(p->history); 05674 p->history = NULL; 05675 } 05676 05677 while ((req = AST_LIST_REMOVE_HEAD(&p->request_queue, next))) { 05678 ast_free(req); 05679 } 05680 05681 if (p->chanvars) { 05682 ast_variables_destroy(p->chanvars); 05683 p->chanvars = NULL; 05684 } 05685 05686 ast_string_field_free_memory(p); 05687 05688 if (p->socket.tcptls_session) { 05689 ao2_ref(p->socket.tcptls_session, -1); 05690 p->socket.tcptls_session = NULL; 05691 } 05692 }
| static int __sip_do_register | ( | struct sip_registry * | r | ) | [static] |
Register with SIP proxy.
Definition at line 11649 of file chan_sip.c.
References SIP_REGISTER, and transmit_register().
Referenced by sip_reregister().
11650 { 11651 int res; 11652 11653 res = transmit_register(r, SIP_REGISTER, NULL, NULL); 11654 return res; 11655 }
| static void __sip_pretend_ack | ( | struct sip_pvt * | p | ) | [static] |
Pretend to ack all packets called with p locked.
Definition at line 4159 of file chan_sip.c.
References __sip_ack(), ast_log(), sip_pkt::data, find_sip_method(), sip_pkt::is_resp, LOG_WARNING, sip_pkt::method, sip_request::method, sip_pvt::packets, sip_pkt::seqno, sip_methods, and cfsip_methods::text.
Referenced by __sip_autodestruct(), handle_request_bye(), handle_request_cancel(), and sip_reg_timeout().
04160 { 04161 struct sip_pkt *cur = NULL; 04162 04163 while (p->packets) { 04164 int method; 04165 if (cur == p->packets) { 04166 ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text); 04167 return; 04168 } 04169 cur = p->packets; 04170 method = (cur->method) ? cur->method : find_sip_method(cur->data->str); 04171 __sip_ack(p, cur->seqno, cur->is_resp, method); 04172 } 04173 }
| static enum sip_result __sip_reliable_xmit | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| struct ast_str * | data, | |||
| int | len, | |||
| int | fatal, | |||
| int | sipmethod | |||
| ) | [static] |
Transmit packet with retransmits.
Definition at line 3901 of file chan_sip.c.
References __sip_xmit(), append_history, ast_calloc, ast_debug, AST_FAILURE, ast_free, ast_log(), AST_SCHED_DEL, AST_SCHED_REPLACE_VARIABLE, ast_str_buffer(), ast_str_create(), ast_str_set(), AST_SUCCESS, sip_pkt::data, DEFAULT_RETRANS, dialog_ref(), dialog_unref(), sip_pkt::is_fatal, sip_pkt::is_resp, LOG_ERROR, sip_pkt::method, sip_pkt::next, sip_pkt::owner, sip_pkt::packetlen, sip_pvt::packets, sip_pvt::pendinginvite, sip_pkt::response_code, retrans_pkt(), sip_pkt::retransid, sip_pkt::seqno, SIP_INVITE, SIP_TRANSPORT_UDP, sip_pvt::socket, sip_pvt::timer_t1, sip_pkt::timer_t1, sip_socket::type, and XMIT_ERROR.
Referenced by send_request(), and send_response().
03902 { 03903 struct sip_pkt *pkt = NULL; 03904 int siptimer_a = DEFAULT_RETRANS; 03905 int xmitres = 0; 03906 int respid; 03907 03908 if (sipmethod == SIP_INVITE) { 03909 /* Note this is a pending invite */ 03910 p->pendinginvite = seqno; 03911 } 03912 03913 /* If the transport is something reliable (TCP or TLS) then don't really send this reliably */ 03914 /* I removed the code from retrans_pkt that does the same thing so it doesn't get loaded into the scheduler */ 03915 /*! \todo According to the RFC some packets need to be retransmitted even if its TCP, so this needs to get revisited */ 03916 if (!(p->socket.type & SIP_TRANSPORT_UDP)) { 03917 xmitres = __sip_xmit(p, data, len); /* Send packet */ 03918 if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ 03919 append_history(p, "XmitErr", "%s", fatal ? "(Critical)" : "(Non-critical)"); 03920 return AST_FAILURE; 03921 } else { 03922 return AST_SUCCESS; 03923 } 03924 } 03925 03926 if (!(pkt = ast_calloc(1, sizeof(*pkt) + len + 1))) 03927 return AST_FAILURE; 03928 /* copy data, add a terminator and save length */ 03929 if (!(pkt->data = ast_str_create(len))) { 03930 ast_free(pkt); 03931 return AST_FAILURE; 03932 } 03933 ast_str_set(&pkt->data, 0, "%s%s", data->str, "\0"); 03934 pkt->packetlen = len; 03935 /* copy other parameters from the caller */ 03936 pkt->method = sipmethod; 03937 pkt->seqno = seqno; 03938 pkt->is_resp = resp; 03939 pkt->is_fatal = fatal; 03940 pkt->owner = dialog_ref(p, "__sip_reliable_xmit: setting pkt->owner"); 03941 pkt->next = p->packets; 03942 p->packets = pkt; /* Add it to the queue */ 03943 if (resp) { 03944 /* Parse out the response code */ 03945 if (sscanf(ast_str_buffer(pkt->data), "SIP/2.0 %30u", &respid) == 1) { 03946 pkt->response_code = respid; 03947 } 03948 } 03949 pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */ 03950 pkt->retransid = -1; 03951 if (pkt->timer_t1) 03952 siptimer_a = pkt->timer_t1 * 2; 03953 03954 /* Schedule retransmission */ 03955 AST_SCHED_REPLACE_VARIABLE(pkt->retransid, sched, siptimer_a, retrans_pkt, pkt, 1); 03956 if (sipdebug) 03957 ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid); 03958 03959 xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); /* Send packet */ 03960 03961 if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ 03962 append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03963 ast_log(LOG_ERROR, "Serious Network Trouble; __sip_xmit returns error for pkt data\n"); 03964 AST_SCHED_DEL(sched, pkt->retransid); 03965 p->packets = pkt->next; 03966 pkt->owner = dialog_unref(pkt->owner,"pkt is being freed, its dialog ref is dead now"); 03967 ast_free(pkt->data); 03968 ast_free(pkt); 03969 return AST_FAILURE; 03970 } else { 03971 return AST_SUCCESS; 03972 } 03973 }
| static int __sip_semi_ack | ( | struct sip_pvt * | p, | |
| int | seqno, | |||
| int | resp, | |||
| int | sipmethod | |||
| ) | [static] |
Acks receipt of packet, keep it around (used for provisional responses).
Definition at line 4176 of file chan_sip.c.
References ast_debug, AST_SCHED_DEL, sip_pvt::callid, sip_pkt::data, FALSE, sip_pkt::is_resp, method_match(), sip_pkt::next, sip_pvt::packets, sip_pkt::retransid, sip_pkt::seqno, sip_methods, cfsip_methods::text, and TRUE.
Referenced by handle_response(), and sip_hangup().
04177 { 04178 struct sip_pkt *cur; 04179 int res = FALSE; 04180 04181 for (cur = p->packets; cur; cur = cur->next) { 04182 if (cur->seqno == seqno && cur->is_resp == resp && 04183 (cur->is_resp || method_match(sipmethod, cur->data->str))) { 04184 /* this is our baby */ 04185 if (cur->retransid > -1) { 04186 if (sipdebug) 04187 ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text); 04188 } 04189 AST_SCHED_DEL(sched, cur->retransid); 04190 res = TRUE; 04191 break; 04192 } 04193 } 04194 ast_debug(1, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found"); 04195 return res; 04196 }
| static int __sip_subscribe_mwi_do | ( | struct sip_subscription_mwi * | mwi | ) | [static] |
Actually setup an MWI subscription or resubscribe.
Definition at line 11130 of file chan_sip.c.
References ast_dnsmgr_lookup(), ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_set, ast_strlen_zero(), ASTOBJ_REF, sip_subscription_mwi::authuser, build_callid_pvt(), build_contact(), build_via(), sip_subscription_mwi::call, create_addr(), dialog_unlink_all(), dialog_unref(), sip_subscription_mwi::dnsmgr, sip_pvt::flags, get_srv_protocol(), get_srv_service(), sip_subscription_mwi::hostname, MAXHOSTNAMELEN, sip_pvt::mwi, obproxy_get(), sip_pvt::ourip, sip_socket::port, sip_subscription_mwi::portno, sip_pvt::recv, ref_proxy(), sip_pvt::sa, sip_subscription_mwi::secret, set_socket_transport(), sip_alloc(), sip_cfg, SIP_OUTGOING, SIP_SUBSCRIBE, sip_pvt::socket, sip_settings::srvlookup, transmit_invite(), sip_subscription_mwi::transport, TRUE, sip_subscription_mwi::us, and sip_subscription_mwi::username.
Referenced by sip_subscribe_mwi_do().
11131 { 11132 /* If we have no DNS manager let's do a lookup */ 11133 if (!mwi->dnsmgr) { 11134 char transport[MAXHOSTNAMELEN]; 11135 snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport)); 11136 ast_dnsmgr_lookup(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL); 11137 } 11138 11139 /* If we already have a subscription up simply send a resubscription */ 11140 if (mwi->call) { 11141 transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0); 11142 return 0; 11143 } 11144 11145 /* Create a dialog that we will use for the subscription */ 11146 if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) { 11147 return -1; 11148 } 11149 11150 ref_proxy(mwi->call, obproxy_get(mwi->call, NULL)); 11151 11152 if (!mwi->us.sin_port && mwi->portno) { 11153 mwi->us.sin_port = htons(mwi->portno); 11154 } 11155 11156 /* Setup the destination of our subscription */ 11157 if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0)) { 11158 dialog_unlink_all(mwi->call, TRUE, TRUE); 11159 mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all"); 11160 return 0; 11161 } 11162 11163 if (!mwi->dnsmgr && mwi->portno) { 11164 mwi->call->sa.sin_port = htons(mwi->portno); 11165 mwi->call->recv.sin_port = htons(mwi->portno); 11166 } else { 11167 mwi->portno = ntohs(mwi->call->sa.sin_port); 11168 } 11169 11170 /* Set various other information */ 11171 if (!ast_strlen_zero(mwi->authuser)) { 11172 ast_string_field_set(mwi->call, peername, mwi->authuser); 11173 ast_string_field_set(mwi->call, authname, mwi->authuser); 11174 ast_string_field_set(mwi->call, fromuser, mwi->authuser); 11175 } else { 11176 ast_string_field_set(mwi->call, peername, mwi->username); 11177 ast_string_field_set(mwi->call, authname, mwi->username); 11178 ast_string_field_set(mwi->call, fromuser, mwi->username); 11179 } 11180 ast_string_field_set(mwi->call, username, mwi->username); 11181 if (!ast_strlen_zero(mwi->secret)) { 11182 ast_string_field_set(mwi->call, peersecret, mwi->secret); 11183 } 11184 set_socket_transport(&mwi->call->socket, mwi->transport); 11185 mwi->call->socket.port = htons(mwi->portno); 11186 ast_sip_ouraddrfor(&mwi->call->sa.sin_addr, &mwi->call->ourip, mwi->call); 11187 build_contact(mwi->call); 11188 build_via(mwi->call); 11189 build_callid_pvt(mwi->call); 11190 ast_set_flag(&mwi->call->flags[0], SIP_OUTGOING); 11191 11192 /* Associate the call with us */ 11193 mwi->call->mwi = ASTOBJ_REF(mwi); 11194 11195 /* Actually send the packet */ 11196 transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2); 11197 11198 return 0; 11199 }
Transmit SIP message Sends a SIP request or response on a given socket (in the pvt) Called by retrans_pkt, send_request, send_response and __sip_reliable_xmit.
Definition at line 3599 of file chan_sip.c.
References ast_debug, ast_inet_ntoa(), ast_log(), errno, sip_socket::fd, get_transport_pvt(), LOG_WARNING, sip_prepare_socket(), sip_real_dst(), sip_tcptls_write(), SIP_TRANSPORT_UDP, sip_pvt::socket, sip_socket::tcptls_session, sip_socket::type, and XMIT_ERROR.
Referenced by __sip_reliable_xmit(), retrans_pkt(), send_request(), and send_response().
03600 { 03601 int res = 0; 03602 const struct sockaddr_in *dst = sip_real_dst(p); 03603 03604 ast_debug(2, "Trying to put '%.11s' onto %s socket destined for %s:%d\n", data->str, get_transport_pvt(p), ast_inet_ntoa(dst->sin_addr), htons(dst->sin_port)); 03605 03606 if (sip_prepare_socket(p) < 0) 03607 return XMIT_ERROR; 03608 03609 if (p->socket.type == SIP_TRANSPORT_UDP) { 03610 res = sendto(p->socket.fd, data->str, len, 0, (const struct sockaddr *)dst, sizeof(struct sockaddr_in)); 03611 } else if (p->socket.tcptls_session) { 03612 res = sip_tcptls_write(p->socket.tcptls_session, data->str, len); 03613 } else { 03614 ast_debug(2, "Socket type is TCP but no tcptls_session is present to write to\n"); 03615 return XMIT_ERROR; 03616 } 03617 03618 if (res == -1) { 03619 switch (errno) { 03620 case EBADF: /* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */ 03621 case EHOSTUNREACH: /* Host can't be reached */ 03622 case ENETDOWN: /* Inteface down */ 03623 case ENETUNREACH: /* Network failure */ 03624 case ECONNREFUSED: /* ICMP port unreachable */ 03625 res = XMIT_ERROR; /* Don't bother with trying to transmit again */ 03626 } 03627 } 03628 if (res != len) 03629 ast_log(LOG_WARNING, "sip_xmit of %p (len %d) to %s:%d returned %d: %s\n", data, len, ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), res, strerror(errno)); 03630 03631 return res; 03632 }
| static int __transmit_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Base transmit response function.
Definition at line 9747 of file chan_sip.c.
References add_header(), ast_cause2str(), ast_log(), buf, get_header(), ast_channel::hangupcause, LOG_WARNING, sip_pvt::method, sip_pvt::owner, respprep(), send_response(), and SIP_INVITE.
Referenced by transmit_response(), transmit_response_reliable(), and transmit_response_using_temp().
09748 { 09749 struct sip_request resp; 09750 int seqno = 0; 09751 09752 if (reliable && (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1)) { 09753 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 09754 return -1; 09755 } 09756 respprep(&resp, p, msg, req); 09757 /* If we are cancelling an incoming invite for some reason, add information 09758 about the reason why we are doing this in clear text */ 09759 if (p->method == SIP_INVITE && msg[0] != '1' && p->owner && p->owner->hangupcause) { 09760 char buf[10]; 09761 09762 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); 09763 snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); 09764 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 09765 } 09766 return send_response(p, &resp, reliable, seqno); 09767 }
| static void __unreg_module | ( | void | ) | [static] |
Definition at line 26250 of file chan_sip.c.
| static char * _sip_qualify_peer | ( | int | type, | |
| int | fd, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Send qualify message to peer from cli or manager. Mostly for debugging.
Definition at line 15474 of file chan_sip.c.
References ast_cli(), astman_send_error(), CLI_SHOWUSAGE, CLI_SUCCESS, FALSE, find_peer(), FINDPEERS, sip_poke_peer(), TRUE, and unref_peer().
Referenced by manager_sip_qualify_peer(), and sip_qualify_peer().
15475 { 15476 struct sip_peer *peer; 15477 int load_realtime; 15478 15479 if (argc < 4) 15480 return CLI_SHOWUSAGE; 15481 15482 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 15483 if ((peer = find_peer(argv[3], NULL, load_realtime, FINDPEERS, FALSE, 0))) { 15484 sip_poke_peer(peer, 1); 15485 unref_peer(peer, "qualify: done with peer"); 15486 } else if (type == 0) { 15487 ast_cli(fd, "Peer '%s' not found\n", argv[3]); 15488 } else { 15489 astman_send_error(s, m, "Peer not found"); 15490 } 15491 return CLI_SUCCESS; 15492 }
| static char * _sip_show_peer | ( | int | type, | |
| int | fd, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Show one peer in detail (main function).
Definition at line 15559 of file chan_sip.c.
References sip_peer::accountcode, sip_peer::addr, sip_peer::allowtransfer, sip_peer::amaflags, ARRAY_LEN, ast_callerid_merge(), ast_cdr_flags2str(), ast_check_realtime(), ast_cli(), ast_codec_pref_index(), ast_describe_caller_presentation(), ast_getformatname(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_print_group(), ast_sched_when(), ast_str_alloca, ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), astman_send_error(), sip_peer::auth, sip_peer::autoframing, sip_peer::busy_level, sip_peer::call_limit, sip_peer::callgroup, sip_peer::callingpres, sip_peer::capability, sip_peer::chanvars, sip_peer::cid_name, sip_peer::cid_num, CLI_SHOWUSAGE, CLI_SUCCESS, cli_yesno(), sip_peer::context, sip_peer::defaddr, dtmfmode2str(), sip_peer::expire, FALSE, faxec2str(), find_peer(), FINDPEERS, sip_peer::flags, sip_proxy::force, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::fullcontact, get_transport(), get_transport_list(), sip_peer::ha, sip_peer::host_dynamic, cfsip_options::id, insecure2str(), sip_peer::is_realtime, sip_peer::language, sip_peer::lastmsgssent, sip_peer::maxcallbitrate, sip_auth::md5secret, sip_peer::md5secret, ast_variable::name, sip_proxy::name, sip_peer::name, nat2str(), ast_variable::next, sip_auth::next, sip_peer::outboundproxy, sip_peer::parkinglot, peer_mailboxes_to_str(), peer_status(), sip_peer::pickupgroup, sip_peer::prefs, print_codec_to_cli(), print_group(), sip_peer::qualifyfreq, sip_auth::realm, sip_peer::regexten, sip_peer::remotesecret, S_OR, sip_auth::secret, sip_peer::secret, SIP_DIRECT_MEDIA, SIP_DTMF, SIP_INSECURE, SIP_NAT, sip_options, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_FORWARD_LOOP_DETECTED, SIP_PAGE2_IGNORESDPVERSION, SIP_PAGE2_REGISTERTRYING, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, SIP_PROMISCREDIR, SIP_SENDRPID, SIP_TRUSTRPID, SIP_USEREQPHONE, sip_peer::sipoptions, sip_peer::socket, sip_st_cfg::st_max_se, sip_st_cfg::st_min_se, sip_st_cfg::st_mode_oper, sip_st_cfg::st_ref, status, sip_peer::stimer, stmode2str(), strefresher2str(), sip_peer::subscribecontext, sip_peer::t38_maxdatagram, text, sip_peer::timer_b, sip_peer::timer_t1, sip_peer::tohost, transfermode2str(), sip_peer::transports, TRUE, sip_socket::type, unref_peer(), sip_peer::useragent, sip_peer::username, sip_auth::username, ast_variable::value, and sip_peer::vmexten.
Referenced by manager_sip_show_peer(), and sip_show_peer().
15560 { 15561 char status[30] = ""; 15562 char cbuf[256]; 15563 struct sip_peer *peer; 15564 char codec_buf[512]; 15565 struct ast_codec_pref *pref; 15566 struct ast_variable *v; 15567 struct sip_auth *auth; 15568 int x = 0, codec = 0, load_realtime; 15569 int realtimepeers; 15570 15571 realtimepeers = ast_check_realtime("sippeers"); 15572 15573 if (argc < 4) 15574 return CLI_SHOWUSAGE; 15575 15576 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 15577 peer = find_peer(argv[3], NULL, load_realtime, FINDPEERS, FALSE, 0); 15578 15579 if (s) { /* Manager */ 15580 if (peer) { 15581 const char *id = astman_get_header(m, "ActionID"); 15582 15583 astman_append(s, "Response: Success\r\n"); 15584 if (!ast_strlen_zero(id)) 15585 astman_append(s, "ActionID: %s\r\n", id); 15586 } else { 15587 snprintf (cbuf, sizeof(cbuf), "Peer %s not found.", argv[3]); 15588 astman_send_error(s, m, cbuf); 15589 return CLI_SUCCESS; 15590 } 15591 } 15592 if (peer && type==0 ) { /* Normal listing */ 15593 struct ast_str *mailbox_str = ast_str_alloca(512); 15594 ast_cli(fd, "\n\n"); 15595 ast_cli(fd, " * Name : %s\n", peer->name); 15596 if (realtimepeers) { /* Realtime is enabled */ 15597 ast_cli(fd, " Realtime peer: %s\n", peer->is_realtime ? "Yes, cached" : "No"); 15598 } 15599 ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>"); 15600 ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>"); 15601 ast_cli(fd, " Remote Secret: %s\n", ast_strlen_zero(peer->remotesecret)?"<Not set>":"<Set>"); 15602 for (auth = peer->auth; auth; auth = auth->next) { 15603 ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s ", auth->realm, auth->username); 15604 ast_cli(fd, "%s\n", !ast_strlen_zero(auth->secret)?"<Secret set>":(!ast_strlen_zero(auth->md5secret)?"<MD5secret set>" : "<Not set>")); 15605 } 15606 ast_cli(fd, " Context : %s\n", peer->context); 15607 ast_cli(fd, " Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") ); 15608 ast_cli(fd, " Language : %s\n", peer->language); 15609 if (!ast_strlen_zero(peer->accountcode)) 15610 ast_cli(fd, " Accountcode : %s\n", peer->accountcode); 15611 ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(peer->amaflags)); 15612 ast_cli(fd, " Transfer mode: %s\n", transfermode2str(peer->allowtransfer)); 15613 ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(peer->callingpres)); 15614 if (!ast_strlen_zero(peer->fromuser)) 15615 ast_cli(fd, " FromUser : %s\n", peer->fromuser); 15616 if (!ast_strlen_zero(peer->fromdomain)) 15617 ast_cli(fd, " FromDomain : %s\n", peer->fromdomain); 15618 ast_cli(fd, " Callgroup : "); 15619 print_group(fd, peer->callgroup, 0); 15620 ast_cli(fd, " Pickupgroup : "); 15621 print_group(fd, peer->pickupgroup, 0); 15622 peer_mailboxes_to_str(&mailbox_str, peer); 15623 ast_cli(fd, " Mailbox : %s\n", mailbox_str->str); 15624 ast_cli(fd, " VM Extension : %s\n", peer->vmexten); 15625 ast_cli(fd, " LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff); 15626 ast_cli(fd, " Call limit : %d\n", peer->call_limit); 15627 if (peer->busy_level) 15628 ast_cli(fd, " Busy level : %d\n", peer->busy_level); 15629 ast_cli(fd, " Dynamic : %s\n", cli_yesno(peer->host_dynamic)); 15630 ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>")); 15631 ast_cli(fd, " MaxCallBR : %d kbps\n", peer->maxcallbitrate); 15632 ast_cli(fd, " Expire : %ld\n", ast_sched_when(sched, peer->expire)); 15633 ast_cli(fd, " Insecure : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE))); 15634 ast_cli(fd, " Nat : %s\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT))); 15635 ast_cli(fd, " ACL : %s\n", cli_yesno(peer->ha != NULL)); 15636 ast_cli(fd, " T.38 support : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 15637 ast_cli(fd, " T.38 EC mode : %s\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 15638 ast_cli(fd, " T.38 MaxDtgrm: %d\n", peer->t38_maxdatagram); 15639 ast_cli(fd, " DirectMedia : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA))); 15640 ast_cli(fd, " PromiscRedir : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR))); 15641 ast_cli(fd, " User=Phone : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_USEREQPHONE))); 15642 ast_cli(fd, " Video Support: %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) || ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS))); 15643 ast_cli(fd, " Text Support : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT))); 15644 ast_cli(fd, " Ign SDP ver : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_IGNORESDPVERSION))); 15645 ast_cli(fd, " Trust RPID : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_TRUSTRPID))); 15646 ast_cli(fd, " Send RPID : %s\n", cli_yesno(ast_test_flag(&peer->flags[0], SIP_SENDRPID))); 15647 ast_cli(fd, " Subscriptions: %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); 15648 ast_cli(fd, " Overlap dial : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP))); 15649 ast_cli(fd, " Forward Loop : %s\n", cli_yesno(ast_test_flag(&peer->flags[1], SIP_PAGE2_FORWARD_LOOP_DETECTED))); 15650 if (peer->outboundproxy) 15651 ast_cli(fd, " Outb. proxy : %s %s\n", ast_strlen_zero(peer->outboundproxy->name) ? "<not set>" : peer->outboundproxy->name, 15652 peer->outboundproxy->force ? "(forced)" : ""); 15653 15654 /* - is enumerated */ 15655 ast_cli(fd, " DTMFmode : %s\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 15656 ast_cli(fd, " Timer T1 : %d\n", peer->timer_t1); 15657 ast_cli(fd, " Timer B : %d\n", peer->timer_b); 15658 ast_cli(fd, " ToHost : %s\n", peer->tohost); 15659 ast_cli(fd, " Addr->IP : %s Port %d\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", ntohs(peer->addr.sin_port)); 15660 ast_cli(fd, " Defaddr->IP : %s Port %d\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port)); 15661 ast_cli(fd, " Prim.Transp. : %s\n", get_transport(peer->socket.type)); 15662 ast_cli(fd, " Allowed.Trsp : %s\n", get_transport_list(peer->transports)); 15663 if (!ast_strlen_zero(global_regcontext)) 15664 ast_cli(fd, " Reg. exten : %s\n", peer->regexten); 15665 ast_cli(fd, " Def. Username: %s\n", peer->username); 15666 ast_cli(fd, " SIP Options : "); 15667 if (peer->sipoptions) { 15668 int lastoption = -1; 15669 for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { 15670 if (sip_options[x].id != lastoption) { 15671 if (peer->sipoptions & sip_options[x].id) 15672 ast_cli(fd, "%s ", sip_options[x].text); 15673 lastoption = x; 15674 } 15675 } 15676 } else 15677 ast_cli(fd, "(none)"); 15678 15679 ast_cli(fd, "\n"); 15680 ast_cli(fd, " Codecs : "); 15681 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 15682 ast_cli(fd, "%s\n", codec_buf); 15683 ast_cli(fd, " Codec Order : ("); 15684 print_codec_to_cli(fd, &peer->prefs); 15685 ast_cli(fd, ")\n"); 15686 15687 ast_cli(fd, " Auto-Framing : %s \n", cli_yesno(peer->autoframing)); 15688 ast_cli(fd, " 100 on REG : %s\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_REGISTERTRYING) ? "Yes" : "No"); 15689 ast_cli(fd, " Status : "); 15690 peer_status(peer, status, sizeof(status)); 15691 ast_cli(fd, "%s\n", status); 15692 ast_cli(fd, " Useragent : %s\n", peer->useragent); 15693 ast_cli(fd, " Reg. Contact : %s\n", peer->fullcontact); 15694 ast_cli(fd, " Qualify Freq : %d ms\n", peer->qualifyfreq); 15695 if (peer->chanvars) { 15696 ast_cli(fd, " Variables :\n"); 15697 for (v = peer->chanvars ; v ; v = v->next) 15698 ast_cli(fd, " %s = %s\n", v->name, v->value); 15699 } 15700 15701 ast_cli(fd, " Sess-Timers : %s\n", stmode2str(peer->stimer.st_mode_oper)); 15702 ast_cli(fd, " Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref)); 15703 ast_cli(fd, " Sess-Expires : %d secs\n", peer->stimer.st_max_se); 15704 ast_cli(fd, " Min-Sess : %d secs\n", peer->stimer.st_min_se); 15705 ast_cli(fd, " Parkinglot : %s\n", peer->parkinglot); 15706 ast_cli(fd, "\n"); 15707 peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr"); 15708 } else if (peer && type == 1) { /* manager listing */ 15709 char buffer[256]; 15710 struct ast_str *mailbox_str = ast_str_alloca(512); 15711 astman_append(s, "Channeltype: SIP\r\n"); 15712 astman_append(s, "ObjectName: %s\r\n", peer->name); 15713 astman_append(s, "ChanObjectType: peer\r\n"); 15714 astman_append(s, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y"); 15715 astman_append(s, "RemoteSecretExist: %s\r\n", ast_strlen_zero(peer->remotesecret)?"N":"Y"); 15716 astman_append(s, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y"); 15717 astman_append(s, "Context: %s\r\n", peer->context); 15718 astman_append(s, "Language: %s\r\n", peer->language); 15719 if (!ast_strlen_zero(peer->accountcode)) 15720 astman_append(s, "Accountcode: %s\r\n", peer->accountcode); 15721 astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags)); 15722 astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres)); 15723 if (!ast_strlen_zero(peer->fromuser)) 15724 astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser); 15725 if (!ast_strlen_zero(peer->fromdomain)) 15726 astman_append(s, "SIP-FromDomain: %s\r\n", peer->fromdomain); 15727 astman_append(s, "Callgroup: "); 15728 astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->callgroup)); 15729 astman_append(s, "Pickupgroup: "); 15730 astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->pickupgroup)); 15731 peer_mailboxes_to_str(&mailbox_str, peer); 15732 astman_append(s, "VoiceMailbox: %s\r\n", mailbox_str->str); 15733 astman_append(s, "TransferMode: %s\r\n", transfermode2str(peer->allowtransfer)); 15734 astman_append(s, "LastMsgsSent: %d\r\n", peer->lastmsgssent); 15735 astman_append(s, "Call-limit: %d\r\n", peer->call_limit); 15736 astman_append(s, "Busy-level: %d\r\n", peer->busy_level); 15737 astman_append(s, "MaxCallBR: %d kbps\r\n", peer->maxcallbitrate); 15738 astman_append(s, "Dynamic: %s\r\n", peer->host_dynamic?"Y":"N"); 15739 astman_append(s, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); 15740 astman_append(s, "RegExpire: %ld seconds\r\n", ast_sched_when(sched, peer->expire)); 15741 astman_append(s, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE))); 15742 astman_append(s, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(&peer->flags[0], SIP_NAT))); 15743 astman_append(s, "ACL: %s\r\n", (peer->ha?"Y":"N")); 15744 astman_append(s, "SIP-CanReinvite: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)?"Y":"N")); 15745 astman_append(s, "SIP-DirectMedia: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)?"Y":"N")); 15746 astman_append(s, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Y":"N")); 15747 astman_append(s, "SIP-UserPhone: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Y":"N")); 15748 astman_append(s, "SIP-VideoSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Y":"N")); 15749 astman_append(s, "SIP-TextSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)?"Y":"N")); 15750 astman_append(s, "SIP-T.38Support: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)?"Y":"N")); 15751 astman_append(s, "SIP-T.38EC: %s\r\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 15752 astman_append(s, "SIP-T.38MaxDtgrm: %d\r\n", peer->t38_maxdatagram); 15753 astman_append(s, "SIP-Sess-Timers: %s\r\n", stmode2str(peer->stimer.st_mode_oper)); 15754 astman_append(s, "SIP-Sess-Refresh: %s\r\n", strefresher2str(peer->stimer.st_ref)); 15755 astman_append(s, "SIP-Sess-Expires: %d\r\n", peer->stimer.st_max_se); 15756 astman_append(s, "SIP-Sess-Min: %d\r\n", peer->stimer.st_min_se); 15757 15758 /* - is enumerated */ 15759 astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 15760 astman_append(s, "ToHost: %s\r\n", peer->tohost); 15761 astman_append(s, "Address-IP: %s\r\nAddress-Port: %d\r\n", peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port)); 15762 astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port)); 15763 astman_append(s, "Default-Username: %s\r\n", peer->username); 15764 if (!ast_strlen_zero(global_regcontext)) 15765 astman_append(s, "RegExtension: %s\r\n", peer->regexten); 15766 astman_append(s, "Codecs: "); 15767 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 15768 astman_append(s, "%s\r\n", codec_buf); 15769 astman_append(s, "CodecOrder: "); 15770 pref = &peer->prefs; 15771 for(x = 0; x < 32 ; x++) { 15772 codec = ast_codec_pref_index(pref, x); 15773 if (!codec) 15774 break; 15775 astman_append(s, "%s", ast_getformatname(codec)); 15776 if (x < 31 && ast_codec_pref_index(pref, x+1)) 15777 astman_append(s, ","); 15778 } 15779 15780 astman_append(s, "\r\n"); 15781 astman_append(s, "Status: "); 15782 peer_status(peer, status, sizeof(status)); 15783 astman_append(s, "%s\r\n", status); 15784 astman_append(s, "SIP-Useragent: %s\r\n", peer->useragent); 15785 astman_append(s, "Reg-Contact: %s\r\n", peer->fullcontact); 15786 astman_append(s, "QualifyFreq: %d ms\r\n", peer->qualifyfreq); 15787 astman_append(s, "Parkinglot: %s\r\n", peer->parkinglot); 15788 if (peer->chanvars) { 15789 for (v = peer->chanvars ; v ; v = v->next) { 15790 astman_append(s, "ChanVariable: %s=%s\r\n", v->name, v->value); 15791 } 15792 } 15793 15794 peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer"); 15795 15796 } else { 15797 ast_cli(fd, "Peer %s not found.\n", argv[3]); 15798 ast_cli(fd, "\n"); 15799 } 15800 15801 return CLI_SUCCESS; 15802 }
| static char * _sip_show_peers | ( | int | fd, | |
| int * | total, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Execute sip show peers command.
Definition at line 14885 of file chan_sip.c.
References sip_peer::addr, ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock(), ao2_t_iterator_next, ao2_unlock(), ast_calloc, ast_check_realtime(), ast_cli(), ast_copy_string(), ast_free, ast_inet_ntoa(), ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), CLI_SHOWUSAGE, CLI_SUCCESS, FALSE, sip_peer::flags, FORMAT, FORMAT2, sip_peer::ha, sip_peer::host_dynamic, id, sip_peer::is_realtime, sip_peer::name, name, peer_status(), peercomparefunc(), SIP_NAT_ROUTE, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_TYPE_PEER, status, TRUE, sip_peer::type, unref_peer(), and sip_peer::username.
Referenced by manager_sip_show_peers(), and sip_show_peers().
14886 { 14887 regex_t regexbuf; 14888 int havepattern = FALSE; 14889 struct sip_peer *peer; 14890 struct ao2_iterator i; 14891 14892 /* the last argument is left-aligned, so we don't need a size anyways */ 14893 #define FORMAT2 "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8s %-10s %s\n" 14894 #define FORMAT "%-25.25s %-15.15s %-3.3s %-3.3s %-3.3s %-8d %-10s %s\n" 14895 14896 char name[256]; 14897 int total_peers = 0; 14898 int peers_mon_online = 0; 14899 int peers_mon_offline = 0; 14900 int peers_unmon_offline = 0; 14901 int peers_unmon_online = 0; 14902 const char *id; 14903 char idtext[256] = ""; 14904 int realtimepeers; 14905 int objcount = ao2_container_count(peers); 14906 struct sip_peer **peerarray; 14907 int k; 14908 14909 14910 realtimepeers = ast_check_realtime("sippeers"); 14911 peerarray = ast_calloc(sizeof(struct sip_peer *), objcount); 14912 14913 if (s) { /* Manager - get ActionID */ 14914 id = astman_get_header(m, "ActionID"); 14915 if (!ast_strlen_zero(id)) 14916 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 14917 } 14918 14919 switch (argc) { 14920 case 5: 14921 if (!strcasecmp(argv[3], "like")) { 14922 if (regcomp(®exbuf, argv[4], REG_EXTENDED | REG_NOSUB)) 14923 return CLI_SHOWUSAGE; 14924 havepattern = TRUE; 14925 } else 14926 return CLI_SHOWUSAGE; 14927 case 3: 14928 break; 14929 default: 14930 return CLI_SHOWUSAGE; 14931 } 14932 14933 if (!s) /* Normal list */ 14934 ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Nat", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : "")); 14935 14936 14937 i = ao2_iterator_init(peers, 0); 14938 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 14939 ao2_lock(peer); 14940 14941 if (!(peer->type & SIP_TYPE_PEER)) { 14942 ao2_unlock(peer); 14943 unref_peer(peer, "unref peer because it's actually a user"); 14944 continue; 14945 } 14946 14947 if (havepattern && regexec(®exbuf, peer->name, 0, NULL, 0)) { 14948 objcount--; 14949 ao2_unlock(peer); 14950 unref_peer(peer, "toss iterator peer ptr before continue"); 14951 continue; 14952 } 14953 14954 peerarray[total_peers++] = peer; 14955 ao2_unlock(peer); 14956 } 14957 ao2_iterator_destroy(&i); 14958 14959 qsort(peerarray, total_peers, sizeof(struct sip_peer *), peercomparefunc); 14960 14961 for(k=0; k < total_peers; k++) { 14962 char status[20] = ""; 14963 char srch[2000]; 14964 char pstatus; 14965 peer = peerarray[k]; 14966 14967 ao2_lock(peer); 14968 if (havepattern && regexec(®exbuf, peer->name, 0, NULL, 0)) { 14969 ao2_unlock(peer); 14970 unref_peer(peer, "toss iterator peer ptr before continue"); 14971 continue; 14972 } 14973 14974 if (!ast_strlen_zero(peer->username) && !s) 14975 snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username); 14976 else 14977 ast_copy_string(name, peer->name, sizeof(name)); 14978 14979 pstatus = peer_status(peer, status, sizeof(status)); 14980 if (pstatus == 1) 14981 peers_mon_online++; 14982 else if (pstatus == 0) 14983 peers_mon_offline++; 14984 else { 14985 if (peer->addr.sin_port == 0) 14986 peers_unmon_offline++; 14987 else 14988 peers_unmon_online++; 14989 } 14990 14991 snprintf(srch, sizeof(srch), FORMAT, name, 14992 peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", 14993 peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ 14994 ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ 14995 peer->ha ? " A " : " ", /* permit/deny */ 14996 ntohs(peer->addr.sin_port), status, 14997 realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); 14998 14999 if (!s) {/* Normal CLI list */ 15000 ast_cli(fd, FORMAT, name, 15001 peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "(Unspecified)", 15002 peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ 15003 ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE) ? " N " : " ", /* NAT=yes? */ 15004 peer->ha ? " A " : " ", /* permit/deny */ 15005 15006 ntohs(peer->addr.sin_port), status, 15007 realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); 15008 } else { /* Manager format */ 15009 /* The names here need to be the same as other channels */ 15010 astman_append(s, 15011 "Event: PeerEntry\r\n%s" 15012 "Channeltype: SIP\r\n" 15013 "ObjectName: %s\r\n" 15014 "ChanObjectType: peer\r\n" /* "peer" or "user" */ 15015 "IPaddress: %s\r\n" 15016 "IPport: %d\r\n" 15017 "Dynamic: %s\r\n" 15018 "Natsupport: %s\r\n" 15019 "VideoSupport: %s\r\n" 15020 "TextSupport: %s\r\n" 15021 "ACL: %s\r\n" 15022 "Status: %s\r\n" 15023 "RealtimeDevice: %s\r\n\r\n", 15024 idtext, 15025 peer->name, 15026 peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "-none-", 15027 ntohs(peer->addr.sin_port), 15028 peer->host_dynamic ? "yes" : "no", /* Dynamic or not? */ 15029 ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE) ? "yes" : "no", /* NAT=yes? */ 15030 ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */ 15031 ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no", /* TEXTSUPPORT=yes? */ 15032 peer->ha ? "yes" : "no", /* permit/deny */ 15033 status, 15034 realtimepeers ? (peer->is_realtime ? "yes":"no") : "no"); 15035 } 15036 ao2_unlock(peer); 15037 unref_peer(peer, "toss iterator peer ptr"); 15038 } 15039 15040 if (!s) 15041 ast_cli(fd, "%d sip peers [Monitored: %d online, %d offline Unmonitored: %d online, %d offline]\n", 15042 total_peers, peers_mon_online, peers_mon_offline, peers_unmon_online, peers_unmon_offline); 15043 15044 if (havepattern) 15045 regfree(®exbuf); 15046 15047 if (total) 15048 *total = total_peers; 15049 15050 ast_free(peerarray); 15051 15052 return CLI_SUCCESS; 15053 #undef FORMAT 15054 #undef FORMAT2 15055 }
| static void * _sip_tcp_helper_thread | ( | struct sip_pvt * | pvt, | |
| struct ast_tcptls_session_instance * | tcptls_session | |||
| ) | [static] |
SIP TCP thread management function This function reads from the socket, parses the packet into a request.
Definition at line 2906 of file chan_sip.c.
References sip_threadinfo::alert_pipe, ao2_lock(), ao2_ref, ao2_t_find, ao2_t_ref, ao2_t_unlink, ao2_unlock(), ast_debug, AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_poll, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_tcptls_client_start(), ast_tcptls_server_write(), buf, cleanup(), ast_tcptls_session_instance::client, copy_request(), tcptls_packet::data, sip_request::data, deinit_req(), errno, ast_tcptls_session_instance::f, sip_socket::fd, ast_tcptls_session_instance::fd, get_header(), handle_request_do(), tcptls_packet::len, sip_request::len, ast_tcptls_session_instance::lock, LOG_ERROR, LOG_WARNING, me, MIN, OBJ_POINTER, sip_threadinfo::packet_q, ast_tcptls_session_instance::parent, parse_request(), sip_socket::port, ast_tcptls_session_instance::remote_address, REQ_OFFSET_TO_STR, set_socket_transport(), SIP_MIN_PACKET, sip_threadinfo_create(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, sip_request::socket, ast_tcptls_session_instance::ssl, sip_threadinfo::stop, TCPTLS_ALERT_DATA, TCPTLS_ALERT_STOP, sip_socket::tcptls_session, sip_threadinfo::tcptls_session, and sip_threadinfo::threadid.
Referenced by sip_tcp_worker_fn().
02907 { 02908 int res, cl; 02909 struct sip_request req = { 0, } , reqcpy = { 0, }; 02910 struct sip_threadinfo *me = NULL; 02911 char buf[1024] = ""; 02912 struct pollfd fds[2] = { { 0 }, { 0 }, }; 02913 struct ast_tcptls_session_args *ca = NULL; 02914 02915 /* If this is a server session, then the connection has already been setup, 02916 * simply create the threadinfo object so we can access this thread for writing. 02917 * 02918 * if this is a client connection more work must be done. 02919 * 1. We own the parent session args for a client connection. This pointer needs 02920 * to be held on to so we can decrement it's ref count on thread destruction. 02921 * 2. The threadinfo object was created before this thread was launched, however 02922 * it must be found within the threadt table. 02923 * 3. Last, the tcptls_session must be started. 02924 */ 02925 if (!tcptls_session->client) { 02926 if (!(me = sip_threadinfo_create(tcptls_session, tcptls_session->ssl ? SIP_TRANSPORT_TLS : SIP_TRANSPORT_TCP))) { 02927 goto cleanup; 02928 } 02929 ao2_t_ref(me, +1, "Adding threadinfo ref for tcp_helper_thread"); 02930 } else { 02931 struct sip_threadinfo tmp = { 02932 .tcptls_session = tcptls_session, 02933 }; 02934 02935 if ((!(ca = tcptls_session->parent)) || 02936 (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) || 02937 (!(tcptls_session = ast_tcptls_client_start(tcptls_session)))) { 02938 goto cleanup; 02939 } 02940 } 02941 02942 me->threadid = pthread_self(); 02943 ast_debug(2, "Starting thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP"); 02944 02945 /* set up pollfd to watch for reads on both the socket and the alert_pipe */ 02946 fds[0].fd = tcptls_session->fd; 02947 fds[1].fd = me->alert_pipe[0]; 02948 fds[0].events = fds[1].events = POLLIN | POLLPRI; 02949 02950 if (!(req.data = ast_str_create(SIP_MIN_PACKET))) 02951 goto cleanup; 02952 if (!(reqcpy.data = ast_str_create(SIP_MIN_PACKET))) 02953 goto cleanup; 02954 02955 for (;;) { 02956 struct ast_str *str_save; 02957 02958 res = ast_poll(fds, 2, -1); /* polls for both socket and alert_pipe */ 02959 02960 if (res < 0) { 02961 ast_debug(2, "SIP %s server :: ast_wait_for_input returned %d\n", tcptls_session->ssl ? "SSL": "TCP", res); 02962 goto cleanup; 02963 } 02964 02965 /* handle the socket event, check for both reads from the socket fd, 02966 * and writes from alert_pipe fd */ 02967 if (fds[0].revents) { /* there is data on the socket to be read */ 02968 02969 fds[0].revents = 0; 02970 02971 /* clear request structure */ 02972 str_save = req.data; 02973 memset(&req, 0, sizeof(req)); 02974 req.data = str_save; 02975 ast_str_reset(req.data); 02976 02977 str_save = reqcpy.data; 02978 memset(&reqcpy, 0, sizeof(reqcpy)); 02979 reqcpy.data = str_save; 02980 ast_str_reset(reqcpy.data); 02981 02982 memset(buf, 0, sizeof(buf)); 02983 02984 if (tcptls_session->ssl) { 02985 set_socket_transport(&req.socket, SIP_TRANSPORT_TLS); 02986 req.socket.port = htons(ourport_tls); 02987 } else { 02988 set_socket_transport(&req.socket, SIP_TRANSPORT_TCP); 02989 req.socket.port = htons(ourport_tcp); 02990 } 02991 req.socket.fd = tcptls_session->fd; 02992 02993 /* Read in headers one line at a time */ 02994 while (req.len < 4 || strncmp(REQ_OFFSET_TO_STR(&req, len - 4), "\r\n\r\n", 4)) { 02995 ast_mutex_lock(&tcptls_session->lock); 02996 if (!fgets(buf, sizeof(buf), tcptls_session->f)) { 02997 ast_mutex_unlock(&tcptls_session->lock); 02998 goto cleanup; 02999 } 03000 ast_mutex_unlock(&tcptls_session->lock); 03001 if (me->stop) 03002 goto cleanup; 03003 ast_str_append(&req.data, 0, "%s", buf); 03004 req.len = req.data->used; 03005 } 03006 copy_request(&reqcpy, &req); 03007 parse_request(&reqcpy); 03008 /* In order to know how much to read, we need the content-length header */ 03009 if (sscanf(get_header(&reqcpy, "Content-Length"), "%30d", &cl)) { 03010 while (cl > 0) { 03011 size_t bytes_read; 03012 ast_mutex_lock(&tcptls_session->lock); 03013 if (!(bytes_read = fread(buf, 1, MIN(sizeof(buf) - 1, cl), tcptls_session->f))) { 03014 ast_mutex_unlock(&tcptls_session->lock); 03015 goto cleanup; 03016 } 03017 buf[bytes_read] = '\0'; 03018 ast_mutex_unlock(&tcptls_session->lock); 03019 if (me->stop) 03020 goto cleanup; 03021 cl -= strlen(buf); 03022 ast_str_append(&req.data, 0, "%s", buf); 03023 req.len = req.data->used; 03024 } 03025 } 03026 /*! \todo XXX If there's no Content-Length or if the content-length and what 03027 we receive is not the same - we should generate an error */ 03028 03029 req.socket.tcptls_session = tcptls_session; 03030 handle_request_do(&req, &tcptls_session->remote_address); 03031 } 03032 03033 if (fds[1].revents) { /* alert_pipe indicates there is data in the send queue to be sent */ 03034 enum sip_tcptls_alert alert; 03035 struct tcptls_packet *packet; 03036 03037 fds[1].revents = 0; 03038 03039 if (read(me->alert_pipe[0], &alert, sizeof(alert)) == -1) { 03040 ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno)); 03041 continue; 03042 } 03043 03044 switch (alert) { 03045 case TCPTLS_ALERT_STOP: 03046 goto cleanup; 03047 case TCPTLS_ALERT_DATA: 03048 ao2_lock(me); 03049 if (!(packet = AST_LIST_REMOVE_HEAD(&me->packet_q, entry))) { 03050 ast_log(LOG_WARNING, "TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty"); 03051 } else if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) { 03052 ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n"); 03053 } 03054 03055 if (packet) { 03056 ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed"); 03057 } 03058 ao2_unlock(me); 03059 break; 03060 default: 03061 ast_log(LOG_ERROR, "Unknown tcptls thread alert '%d'\n", alert); 03062 } 03063 } 03064 } 03065 03066 ast_debug(2, "Shutting down thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP"); 03067 03068 cleanup: 03069 if (me) { 03070 ao2_t_unlink(threadt, me, "Removing tcptls helper thread, thread is closing"); 03071 ao2_t_ref(me, -1, "Removing tcp_helper_threads threadinfo ref"); 03072 } 03073 deinit_req(&reqcpy); 03074 deinit_req(&req); 03075 03076 /* if client, we own the parent session arguments and must decrement ref */ 03077 if (ca) { 03078 ao2_t_ref(ca, -1, "closing tcptls thread, getting rid of client tcptls_session arguments"); 03079 } 03080 03081 if (tcptls_session) { 03082 ast_mutex_lock(&tcptls_session->lock); 03083 if (tcptls_session->f) { 03084 fclose(tcptls_session->f); 03085 tcptls_session->f = NULL; 03086 } 03087 if (tcptls_session->fd != -1) { 03088 close(tcptls_session->fd); 03089 tcptls_session->fd = -1; 03090 } 03091 tcptls_session->parent = NULL; 03092 ast_mutex_unlock(&tcptls_session->lock); 03093 03094 ao2_ref(tcptls_session, -1); 03095 tcptls_session = NULL; 03096 } 03097 return NULL; 03098 }
| static int acf_channel_read | ( | struct ast_channel * | chan, | |
| const char * | funcname, | |||
| char * | preparse, | |||
| char * | buf, | |||
| size_t | buflen | |||
| ) | [static] |
Definition at line 21148 of file chan_sip.c.
References AST_APP_ARG, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_inet_ntoa(), ast_log(), ast_rtp_get_peer(), ast_rtp_get_qos(), ast_rtp_get_quality(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), sip_pvt::from, IS_SIP_TECH, ast_rtp_quality::local_count, ast_rtp_quality::local_jitter, ast_rtp_quality::local_lostpackets, ast_rtp_quality::local_ssrc, LOG_ERROR, LOG_WARNING, parse(), sip_pvt::peername, sip_pvt::recv, ast_rtp_quality::remote_count, ast_rtp_quality::remote_jitter, ast_rtp_quality::remote_lostpackets, ast_rtp_quality::remote_ssrc, sip_pvt::rtp, RTPQOS_SUMMARY, ast_rtp_quality::rtt, sip_pvt::sa, t38properties::state, sip_pvt::t38, T38_DISABLED, ast_channel::tech, ast_channel::tech_pvt, sip_pvt::trtp, sip_pvt::uri, sip_pvt::useragent, and sip_pvt::vrtp.
21149 { 21150 struct sip_pvt *p = chan->tech_pvt; 21151 char *all = "", *parse = ast_strdupa(preparse); 21152 int res = 0; 21153 AST_DECLARE_APP_ARGS(args, 21154 AST_APP_ARG(param); 21155 AST_APP_ARG(type); 21156 AST_APP_ARG(field); 21157 ); 21158 AST_STANDARD_APP_ARGS(args, parse); 21159 21160 /* Sanity check */ 21161 if (!IS_SIP_TECH(chan->tech)) { 21162 ast_log(LOG_ERROR, "Cannot call %s on a non-SIP channel\n", funcname); 21163 return 0; 21164 } 21165 21166 memset(buf, 0, buflen); 21167 21168 if (p == NULL) { 21169 return -1; 21170 } 21171 21172 if (!strcasecmp(args.param, "peerip")) { 21173 ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", buflen); 21174 } else if (!strcasecmp(args.param, "recvip")) { 21175 ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", buflen); 21176 } else if (!strcasecmp(args.param, "from")) { 21177 ast_copy_string(buf, p->from, buflen); 21178 } else if (!strcasecmp(args.param, "uri")) { 21179 ast_copy_string(buf, p->uri, buflen); 21180 } else if (!strcasecmp(args.param, "useragent")) { 21181 ast_copy_string(buf, p->useragent, buflen); 21182 } else if (!strcasecmp(args.param, "peername")) { 21183 ast_copy_string(buf, p->peername, buflen); 21184 } else if (!strcasecmp(args.param, "t38passthrough")) { 21185 ast_copy_string(buf, (p->t38.state == T38_DISABLED) ? "0" : "1", buflen); 21186 } else if (!strcasecmp(args.param, "rtpdest")) { 21187 struct sockaddr_in sin; 21188 struct ast_rtp *stream = NULL; 21189 21190 if (ast_strlen_zero(args.type)) 21191 args.type = "audio"; 21192 21193 if (!strcasecmp(args.type, "audio")) { 21194 stream = p->rtp; 21195 } else if (!strcasecmp(args.type, "video")) { 21196 stream = p->vrtp; 21197 } else if (!strcasecmp(args.type, "text")) { 21198 stream = p->trtp; 21199 } else { 21200 return -1; 21201 } 21202 21203 if (!stream) { 21204 return -1; 21205 } 21206 21207 ast_rtp_get_peer(stream, &sin); 21208 snprintf(buf, buflen, "%s:%d", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 21209 } else if (!strcasecmp(args.param, "rtpqos")) { 21210 struct ast_rtp_quality qos; 21211 struct ast_rtp *rtp = p->rtp; 21212 21213 memset(&qos, 0, sizeof(qos)); 21214 21215 if (ast_strlen_zero(args.type)) 21216 args.type = "audio"; 21217 if (ast_strlen_zero(args.field)) 21218 args.field = "all"; 21219 21220 if (!strcasecmp(args.type, "AUDIO")) { 21221 all = ast_rtp_get_quality(rtp = p->rtp, &qos, RTPQOS_SUMMARY); 21222 } else if (!strcasecmp(args.type, "VIDEO")) { 21223 all = ast_rtp_get_quality(rtp = p->vrtp, &qos, RTPQOS_SUMMARY); 21224 } else if (!strcasecmp(args.type, "TEXT")) { 21225 all = ast_rtp_get_quality(rtp = p->trtp, &qos, RTPQOS_SUMMARY); 21226 } else { 21227 return -1; 21228 } 21229 21230 if (!strcasecmp(args.field, "local_ssrc")) 21231 snprintf(buf, buflen, "%u", qos.local_ssrc); 21232 else if (!strcasecmp(args.field, "local_lostpackets")) 21233 snprintf(buf, buflen, "%u", qos.local_lostpackets); 21234 else if (!strcasecmp(args.field, "local_jitter")) 21235 snprintf(buf, buflen, "%.0f", qos.local_jitter * 1000.0); 21236 else if (!strcasecmp(args.field, "local_count")) 21237 snprintf(buf, buflen, "%u", qos.local_count); 21238 else if (!strcasecmp(args.field, "remote_ssrc")) 21239 snprintf(buf, buflen, "%u", qos.remote_ssrc); 21240 else if (!strcasecmp(args.field, "remote_lostpackets")) 21241 snprintf(buf, buflen, "%u", qos.remote_lostpackets); 21242 else if (!strcasecmp(args.field, "remote_jitter")) 21243 snprintf(buf, buflen, "%.0f", qos.remote_jitter * 1000.0); 21244 else if (!strcasecmp(args.field, "remote_count")) 21245 snprintf(buf, buflen, "%u", qos.remote_count); 21246 else if (!strcasecmp(args.field, "rtt")) 21247 snprintf(buf, buflen, "%.0f", qos.rtt * 1000.0); 21248 else if (!strcasecmp(args.field, "all")) 21249 ast_copy_string(buf, all, buflen); 21250 else if (!ast_rtp_get_qos(rtp, args.field, buf, buflen)) 21251 ; 21252 else { 21253 ast_log(LOG_WARNING, "Unrecognized argument '%s' to %s\n", preparse, funcname); 21254 return -1; 21255 } 21256 } else { 21257 res = -1; 21258 } 21259 return res; 21260 }
| static void add_blank | ( | struct sip_request * | req | ) | [static] |
add a blank line if no body
Definition at line 4207 of file chan_sip.c.
References ast_str_append(), ast_str_strlen(), sip_request::data, sip_request::len, and sip_request::lines.
Referenced by send_request(), and send_response().
04208 { 04209 if (!req->lines) { 04210 /* Add extra empty return. add_header() reserves 4 bytes so cannot be truncated */ 04211 ast_str_append(&req->data, 0, "\r\n"); 04212 req->len = ast_str_strlen(req->data); 04213 } 04214 }
| static void add_codec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 9999 of file chan_sip.c.
References ast_codec_pref_getsize(), AST_FORMAT_G723_1, AST_FORMAT_G729A, AST_FORMAT_ILBC, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, ast_getformatname(), ast_rtp_codec_getpref(), ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_rtp_lookup_sample_rate(), AST_RTP_OPT_G726_NONSTANDARD, ast_str_append(), ast_test_flag, ast_verbose, ast_format_list::cur_ms, sip_pvt::flags, sip_pvt::rtp, and SIP_G726_NONSTANDARD.
Referenced by add_sdp().
10002 { 10003 int rtp_code; 10004 struct ast_format_list fmt; 10005 10006 10007 if (debug) 10008 ast_verbose("Adding codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec)); 10009 if ((rtp_code = ast_rtp_lookup_code(p->rtp, 1, codec)) == -1) 10010 return; 10011 10012 if (p->rtp) { 10013 struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp); 10014 fmt = ast_codec_pref_getsize(pref, codec); 10015 } else /* I dont see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */ 10016 return; 10017 ast_str_append(m_buf, 0, " %d", rtp_code); 10018 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 10019 ast_rtp_lookup_mime_subtype(1, codec, 10020 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0), 10021 ast_rtp_lookup_sample_rate(1, codec)); 10022 10023 switch (codec) { 10024 case AST_FORMAT_G729A: 10025 /* Indicate that we don't support VAD (G.729 annex B) */ 10026 ast_str_append(a_buf, 0, "a=fmtp:%d annexb=no\r\n", rtp_code); 10027 break; 10028 case AST_FORMAT_G723_1: 10029 /* Indicate that we don't support VAD (G.723.1 annex A) */ 10030 ast_str_append(a_buf, 0, "a=fmtp:%d annexa=no\r\n", rtp_code); 10031 break; 10032 case AST_FORMAT_ILBC: 10033 /* Add information about us using only 20/30 ms packetization */ 10034 ast_str_append(a_buf, 0, "a=fmtp:%d mode=%d\r\n", rtp_code, fmt.cur_ms); 10035 break; 10036 case AST_FORMAT_SIREN7: 10037 /* Indicate that we only expect 32Kbps */ 10038 ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=32000\r\n", rtp_code); 10039 break; 10040 case AST_FORMAT_SIREN14: 10041 /* Indicate that we only expect 48Kbps */ 10042 ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code); 10043 break; 10044 } 10045 10046 if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size)) 10047 *min_packet_size = fmt.cur_ms; 10048 10049 /* Our first codec packetization processed cannot be zero */ 10050 if ((*min_packet_size)==0 && fmt.cur_ms) 10051 *min_packet_size = fmt.cur_ms; 10052 }
| static int add_content | ( | struct sip_request * | req, | |
| const char * | line | |||
| ) | [static] |
Add content (not header) to SIP message.
Definition at line 9211 of file chan_sip.c.
References ast_log(), ast_str_append(), sip_request::content, sip_request::lines, and LOG_WARNING.
Referenced by add_digit(), add_sdp(), add_text(), add_vidupdate(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), and transmit_state_notify().
09212 { 09213 if (req->lines) { 09214 ast_log(LOG_WARNING, "Can't add more content when the content has been finalized\n"); 09215 return -1; 09216 } 09217 09218 ast_str_append(&req->content, 0, "%s", line); 09219 return 0; 09220 }
| static int add_digit | ( | struct sip_request * | req, | |
| char | digit, | |||
| unsigned int | duration, | |||
| int | mode | |||
| ) | [static] |
Add DTMF INFO tone to sip message Mode = 0 for application/dtmf-relay (Cisco) 1 for application/dtmf.
Definition at line 9953 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_info_with_digit().
09954 { 09955 char tmp[256]; 09956 int event; 09957 if (mode) { 09958 /* Application/dtmf short version used by some implementations */ 09959 if (digit == '*') 09960 event = 10; 09961 else if (digit == '#') 09962 event = 11; 09963 else if ((digit >= 'A') && (digit <= 'D')) 09964 event = 12 + digit - 'A'; 09965 else 09966 event = atoi(&digit); 09967 snprintf(tmp, sizeof(tmp), "%d\r\n", event); 09968 add_header(req, "Content-Type", "application/dtmf"); 09969 add_content(req, tmp); 09970 } else { 09971 /* Application/dtmf-relay as documented by Cisco */ 09972 snprintf(tmp, sizeof(tmp), "Signal=%c\r\nDuration=%u\r\n", digit, duration); 09973 add_header(req, "Content-Type", "application/dtmf-relay"); 09974 add_content(req, tmp); 09975 } 09976 return 0; 09977 }
| static int add_header | ( | struct sip_request * | req, | |
| const char * | var, | |||
| const char * | value | |||
| ) | [static] |
Add header to SIP message.
Definition at line 9164 of file chan_sip.c.
References ast_log(), ast_str_append(), ast_str_strlen(), sip_settings::compactheaders, sip_request::data, find_alias(), sip_request::header, sip_request::headers, sip_request::len, sip_request::lines, LOG_WARNING, sip_cfg, and SIP_MAX_HEADERS.
Referenced by __transmit_response(), add_digit(), add_route(), add_sdp(), add_supported_header(), add_text(), add_vidupdate(), append_date(), copy_all_header(), copy_header(), copy_via_headers(), finalize_content(), initreqprep(), reqprep(), respprep(), transmit_invite(), transmit_notify_custom(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_minse(), transmit_response_with_unsupported(), and transmit_state_notify().
09165 { 09166 if (req->headers == SIP_MAX_HEADERS) { 09167 ast_log(LOG_WARNING, "Out of SIP header space\n"); 09168 return -1; 09169 } 09170 09171 if (req->lines) { 09172 ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n"); 09173 return -1; 09174 } 09175 09176 if (sip_cfg.compactheaders) { 09177 var = find_alias(var, var); 09178 } 09179 09180 ast_str_append(&req->data, 0, "%s: %s\r\n", var, value); 09181 req->header[req->headers] = req->len; 09182 09183 req->len = ast_str_strlen(req->data); 09184 req->headers++; 09185 09186 return 0; 09187 }
| static void add_noncodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | format, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug | |||
| ) | [static] |
Add RFC 2833 DTMF offer to SDP.
Definition at line 10132 of file chan_sip.c.
References AST_RTP_DTMF, ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_rtp_lookup_sample_rate(), ast_str_append(), ast_verbose, and sip_pvt::rtp.
Referenced by add_sdp().
10135 { 10136 int rtp_code; 10137 10138 if (debug) 10139 ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype(0, format, 0)); 10140 if ((rtp_code = ast_rtp_lookup_code(p->rtp, 0, format)) == -1) 10141 return; 10142 10143 ast_str_append(m_buf, 0, " %d", rtp_code); 10144 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 10145 ast_rtp_lookup_mime_subtype(0, format, 0), 10146 ast_rtp_lookup_sample_rate(0, format)); 10147 if (format == AST_RTP_DTMF) /* Indicate we support DTMF and FLASH... */ 10148 ast_str_append(a_buf, 0, "a=fmtp:%d 0-16\r\n", rtp_code); 10149 }
| static void add_peer_mailboxes | ( | struct sip_peer * | peer, | |
| const char * | value | |||
| ) | [static] |
Definition at line 23937 of file chan_sip.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_strdup, ast_strdupa, ast_strlen_zero(), sip_mailbox::context, context, sip_mailbox::delme, sip_mailbox::mailbox, mailbox, sip_peer::mailboxes, mbox(), S_OR, and strsep().
Referenced by build_peer().
23938 { 23939 char *next, *mbox, *context; 23940 23941 next = ast_strdupa(value); 23942 23943 while ((mbox = context = strsep(&next, ","))) { 23944 struct sip_mailbox *mailbox; 23945 int duplicate = 0; 23946 23947 strsep(&context, "@"); 23948 23949 if (ast_strlen_zero(mbox)) { 23950 continue; 23951 } 23952 23953 /* Check whether the mailbox is already in the list */ 23954 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 23955 if (!strcmp(mailbox->mailbox, mbox) && !strcmp(S_OR(mailbox->context, ""), S_OR(context, ""))) { 23956 duplicate = 1; 23957 mailbox->delme = 1; 23958 break; 23959 } 23960 } 23961 if (duplicate) { 23962 continue; 23963 } 23964 23965 if (!(mailbox = ast_calloc(1, sizeof(*mailbox)))) { 23966 continue; 23967 } 23968 23969 mailbox->mailbox = ast_strdup(mbox); 23970 mailbox->context = ast_strdup(context); 23971 23972 AST_LIST_INSERT_TAIL(&peer->mailboxes, mailbox, entry); 23973 } 23974 }
| static void add_peer_mwi_subs | ( | struct sip_peer * | peer | ) | [static] |
Definition at line 21401 of file chan_sip.c.
References AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, ast_event_subscribe(), AST_LIST_TRAVERSE, sip_mailbox::context, sip_mailbox::event_sub, sip_mailbox::mailbox, mailbox, sip_peer::mailboxes, mwi_event_cb(), and S_OR.
Referenced by build_peer(), and handle_request_subscribe().
21402 { 21403 struct sip_mailbox *mailbox; 21404 21405 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 21406 mailbox->event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, peer, 21407 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox, 21408 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"), 21409 AST_EVENT_IE_END); 21410 } 21411 }
| static struct sip_auth * add_realm_authentication | ( | struct sip_auth * | authlist, | |
| const char * | configuration, | |||
| int | lineno | |||
| ) | [static, read] |
Add realm authentication in list.
Definition at line 23753 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_debug, ast_log(), ast_strlen_zero(), ast_verb, LOG_WARNING, sip_auth::md5secret, sip_auth::next, sip_auth::realm, sip_auth::secret, secret, and sip_auth::username.
Referenced by build_peer(), and reload_config().
23754 { 23755 char authcopy[256]; 23756 char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL; 23757 struct sip_auth *a, *b, *auth; 23758 23759 if (ast_strlen_zero(configuration)) 23760 return authlist; 23761 23762 ast_debug(1, "Auth config :: %s\n", configuration); 23763 23764 ast_copy_string(authcopy, configuration, sizeof(authcopy)); 23765 username = authcopy; 23766 23767 /* split user[:secret] and relm */ 23768 realm = strrchr(username, '@'); 23769 if (realm) 23770 *realm++ = '\0'; 23771 if (ast_strlen_zero(username) || ast_strlen_zero(realm)) { 23772 ast_log(LOG_WARNING, "Format for authentication entry is user[:secret]@realm at line %d\n", lineno); 23773 return authlist; 23774 } 23775 23776 /* parse username at ':' for secret, or '#" for md5secret */ 23777 if ((secret = strchr(username, ':'))) { 23778 *secret++ = '\0'; 23779 } else if ((md5secret = strchr(username, '#'))) { 23780 *md5secret++ = '\0'; 23781 } 23782 23783 if (!(auth = ast_calloc(1, sizeof(*auth)))) 23784 return authlist; 23785 23786 ast_copy_string(auth->realm, realm, sizeof(auth->realm)); 23787 ast_copy_string(auth->username, username, sizeof(auth->username)); 23788 if (secret) 23789 ast_copy_string(auth->secret, secret, sizeof(auth->secret)); 23790 if (md5secret) 23791 ast_copy_string(auth->md5secret, md5secret, sizeof(auth->md5secret)); 23792 23793 /* find the end of the list */ 23794 for (b = NULL, a = authlist; a ; b = a, a = a->next) 23795 ; 23796 if (b) 23797 b->next = auth; /* Add structure add end of list */ 23798 else 23799 authlist = auth; 23800 23801 ast_verb(3, "Added authentication for realm %s\n", realm); 23802 23803 return authlist; 23804 23805 }
| static void add_route | ( | struct sip_request * | req, | |
| struct sip_route * | route | |||
| ) | [static] |
Add route header into request per learned route.
Definition at line 9323 of file chan_sip.c.
References add_header(), ast_copy_string(), sip_route::hop, sip_route::next, and SIPBUFSIZE.
Referenced by initreqprep(), and reqprep().
09324 { 09325 char r[SIPBUFSIZE*2], *p; 09326 int n, rem = sizeof(r); 09327 09328 if (!route) 09329 return; 09330 09331 p = r; 09332 for (;route ; route = route->next) { 09333 n = strlen(route->hop); 09334 if (rem < n+3) /* we need room for ",<route>" */ 09335 break; 09336 if (p != r) { /* add a separator after fist route */ 09337 *p++ = ','; 09338 --rem; 09339 } 09340 *p++ = '<'; 09341 ast_copy_string(p, route->hop, rem); /* cannot fail */ 09342 p += n; 09343 *p++ = '>'; 09344 rem -= (n+2); 09345 } 09346 *p = '\0'; 09347 add_header(req, "Route", r); 09348 }
| static enum sip_result add_sdp | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p, | |||
| int | oldsdp, | |||
| int | add_audio, | |||
| int | add_t38 | |||
| ) | [static] |
Add Session Description Protocol message.
If oldsdp is TRUE, then the SDP version number is not incremented. This mechanism is used in Session-Timers where RE-INVITEs are used for refreshing SIP sessions without modifying the media session in any way.
Definition at line 10193 of file chan_sip.c.
References add_codec_to_sdp(), add_content(), add_header(), add_noncodec_to_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_codec_pref_index(), ast_debug, AST_FAILURE, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname_multiple(), ast_inet_ntoa(), ast_internal_timing_enabled(), ast_log(), ast_random(), AST_RTP_MAX, ast_str_alloca, ast_str_append(), ast_strlen_zero(), AST_SUCCESS, AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_test_flag, ast_udptl_get_error_correction_scheme(), ast_udptl_get_local_max_datagram(), ast_udptl_get_us(), ast_verbose, buf, sip_request::debug, FALSE, ast_control_t38_parameters::fill_bit_removal, sip_pvt::flags, get_our_media_address(), sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, sip_pvt::lastrtprx, sip_pvt::lastrtptx, LOG_WARNING, sip_pvt::maxcallbitrate, sip_pvt::notext, sip_pvt::novideo, offered_media::offered, sip_pvt::offered_media, t38properties::our_parms, sip_pvt::ourip, sip_pvt::owner, sip_pvt::prefcodec, sip_pvt::prefs, ast_control_t38_parameters::rate, ast_control_t38_parameters::rate_management, sip_pvt::rtp, SDP_AUDIO, SDP_IMAGE, SDP_TEXT, SDP_VIDEO, sip_pvt::sessionid, sip_pvt::sessionversion, sip_debug_test_pvt(), SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_CALL_ONHOLD_INACTIVE, SIP_PAGE2_CALL_ONHOLD_ONEDIR, SIPBUFSIZE, sip_pvt::t38, t38_get_rate(), offered_media::text, ast_control_t38_parameters::transcoding_jbig, ast_control_t38_parameters::transcoding_mmr, sip_pvt::tredirip, sip_pvt::trtp, TRUE, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, sip_pvt::udptlredirip, ast_control_t38_parameters::version, version, and sip_pvt::vrtp.
Referenced by transmit_invite(), transmit_reinvite_with_sdp(), transmit_response_with_sdp(), and transmit_response_with_t38_sdp().
10194 { 10195 int alreadysent = 0; 10196 10197 struct sockaddr_in sin; 10198 struct sockaddr_in vsin; 10199 struct sockaddr_in tsin; 10200 struct sockaddr_in dest; 10201 struct sockaddr_in udptlsin; 10202 struct sockaddr_in vdest = { 0, }; 10203 struct sockaddr_in tdest = { 0, }; 10204 struct sockaddr_in udptldest = { 0, }; 10205 10206 /* SDP fields */ 10207 char *version = "v=0\r\n"; /* Protocol version */ 10208 char subject[256]; /* Subject of the session */ 10209 char owner[256]; /* Session owner/creator */ 10210 char connection[256]; /* Connection data */ 10211 char *session_time = "t=0 0\r\n"; /* Time the session is active */ 10212 char bandwidth[256] = ""; /* Max bitrate */ 10213 char *hold = ""; 10214 struct ast_str *m_audio = ast_str_alloca(256); /* Media declaration line for audio */ 10215 struct ast_str *m_video = ast_str_alloca(256); /* Media declaration line for video */ 10216 struct ast_str *m_text = ast_str_alloca(256); /* Media declaration line for text */ 10217 struct ast_str *m_modem = ast_str_alloca(256); /* Media declaration line for modem */ 10218 struct ast_str *a_audio = ast_str_alloca(1024); /* Attributes for audio */ 10219 struct ast_str *a_video = ast_str_alloca(1024); /* Attributes for video */ 10220 struct ast_str *a_text = ast_str_alloca(1024); /* Attributes for text */ 10221 struct ast_str *a_modem = ast_str_alloca(1024); /* Attributes for modem */ 10222 10223 int x; 10224 int capability = 0; 10225 int needaudio = FALSE; 10226 int needvideo = FALSE; 10227 int needtext = FALSE; 10228 int debug = sip_debug_test_pvt(p); 10229 int min_audio_packet_size = 0; 10230 int min_video_packet_size = 0; 10231 int min_text_packet_size = 0; 10232 10233 char codecbuf[SIPBUFSIZE]; 10234 char buf[SIPBUFSIZE]; 10235 char dummy_answer[256]; 10236 10237 /* Set the SDP session name */ 10238 snprintf(subject, sizeof(subject), "s=%s\r\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession); 10239 10240 if (!p->rtp) { 10241 ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n"); 10242 return AST_FAILURE; 10243 } 10244 /* XXX We should not change properties in the SIP dialog until 10245 we have acceptance of the offer if this is a re-invite */ 10246 10247 /* Set RTP Session ID and version */ 10248 if (!p->sessionid) { 10249 p->sessionid = (int)ast_random(); 10250 p->sessionversion = p->sessionid; 10251 } else { 10252 if (oldsdp == FALSE) 10253 p->sessionversion++; 10254 } 10255 10256 if (add_audio) { 10257 /* Check if we need video in this call */ 10258 if ((p->jointcapability & AST_FORMAT_VIDEO_MASK) && !p->novideo) { 10259 if (p->vrtp) { 10260 needvideo = TRUE; 10261 ast_debug(2, "This call needs video offers!\n"); 10262 } else 10263 ast_debug(2, "This call needs video offers, but there's no video support enabled!\n"); 10264 } 10265 /* Check if we need text in this call */ 10266 if ((p->jointcapability & AST_FORMAT_TEXT_MASK) && !p->notext) { 10267 if (sipdebug_text) 10268 ast_verbose("We think we can do text\n"); 10269 if (p->trtp) { 10270 if (sipdebug_text) { 10271 ast_verbose("And we have a text rtp object\n"); 10272 } 10273 needtext = TRUE; 10274 ast_debug(2, "This call needs text offers! \n"); 10275 } else { 10276 ast_debug(2, "This call needs text offers, but there's no text support enabled ! \n"); 10277 } 10278 } 10279 } 10280 10281 get_our_media_address(p, needvideo, &sin, &vsin, &tsin, &dest, &vdest); 10282 10283 snprintf(owner, sizeof(owner), "o=%s %d %d IN IP4 %s\r\n", ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner, p->sessionid, p->sessionversion, ast_inet_ntoa(dest.sin_addr)); 10284 snprintf(connection, sizeof(connection), "c=IN IP4 %s\r\n", ast_inet_ntoa(dest.sin_addr)); 10285 10286 if (add_audio) { 10287 capability = p->jointcapability; 10288 10289 /* XXX note, Video and Text are negated - 'true' means 'no' */ 10290 ast_debug(1, "** Our capability: %s Video flag: %s Text flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), 10291 p->novideo ? "True" : "False", p->notext ? "True" : "False"); 10292 ast_debug(1, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec)); 10293 10294 /* Check if we need audio */ 10295 if (capability & AST_FORMAT_AUDIO_MASK) 10296 needaudio = TRUE; 10297 10298 if (debug) 10299 ast_verbose("Audio is at %s port %d\n", ast_inet_ntoa(p->ourip.sin_addr), ntohs(sin.sin_port)); 10300 10301 /* Ok, we need video. Let's add what we need for video and set codecs. 10302 Video is handled differently than audio since we can not transcode. */ 10303 if (needvideo) { 10304 ast_str_append(&m_video, 0, "m=video %d RTP/AVP", ntohs(vdest.sin_port)); 10305 10306 /* Build max bitrate string */ 10307 if (p->maxcallbitrate) 10308 snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate); 10309 if (debug) 10310 ast_verbose("Video is at %s port %d\n", ast_inet_ntoa(p->ourip.sin_addr), ntohs(vdest.sin_port)); 10311 } 10312 10313 /* Ok, we need text. Let's add what we need for text and set codecs. 10314 Text is handled differently than audio since we can not transcode. */ 10315 if (needtext) { 10316 if (sipdebug_text) 10317 ast_verbose("Lets set up the text sdp\n"); 10318 /* Determine text destination */ 10319 if (p->tredirip.sin_addr.s_addr) { 10320 tdest.sin_addr = p->tredirip.sin_addr; 10321 tdest.sin_port = p->tredirip.sin_port; 10322 } else { 10323 tdest.sin_addr = p->ourip.sin_addr; 10324 tdest.sin_port = tsin.sin_port; 10325 } 10326 ast_str_append(&m_text, 0, "m=text %d RTP/AVP", ntohs(tdest.sin_port)); 10327 if (debug) /* XXX should I use tdest below ? */ 10328 ast_verbose("Text is at %s port %d\n", ast_inet_ntoa(p->ourip.sin_addr), ntohs(tsin.sin_port)); 10329 10330 } 10331 10332 /* Start building generic SDP headers */ 10333 10334 /* We break with the "recommendation" and send our IP, in order that our 10335 peer doesn't have to ast_gethostbyname() us */ 10336 10337 ast_str_append(&m_audio, 0, "m=audio %d RTP/AVP", ntohs(dest.sin_port)); 10338 10339 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR) 10340 hold = "a=recvonly\r\n"; 10341 else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE) 10342 hold = "a=inactive\r\n"; 10343 else 10344 hold = "a=sendrecv\r\n"; 10345 10346 /* Now, start adding audio codecs. These are added in this order: 10347 - First what was requested by the calling channel 10348 - Then preferences in order from sip.conf device config for this peer/user 10349 - Then other codecs in capabilities, including video 10350 */ 10351 10352 /* Prefer the audio codec we were requested to use, first, no matter what 10353 Note that p->prefcodec can include video codecs, so mask them out 10354 */ 10355 if (capability & p->prefcodec) { 10356 int codec = p->prefcodec & AST_FORMAT_AUDIO_MASK; 10357 10358 add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size); 10359 alreadysent |= codec; 10360 } 10361 10362 /* Start by sending our preferred audio/video codecs */ 10363 for (x = 0; x < 32; x++) { 10364 int codec; 10365 10366 if (!(codec = ast_codec_pref_index(&p->prefs, x))) 10367 break; 10368 10369 if (!(capability & codec)) 10370 continue; 10371 10372 if (alreadysent & codec) 10373 continue; 10374 10375 add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size); 10376 alreadysent |= codec; 10377 } 10378 10379 /* Now send any other common audio and video codecs, and non-codec formats: */ 10380 for (x = 1; x <= (needtext ? AST_FORMAT_TEXT_MASK : (needvideo ? AST_FORMAT_VIDEO_MASK : AST_FORMAT_AUDIO_MASK)); x <<= 1) { 10381 if (!(capability & x)) /* Codec not requested */ 10382 continue; 10383 10384 if (alreadysent & x) /* Already added to SDP */ 10385 continue; 10386 10387 if (x & AST_FORMAT_AUDIO_MASK) 10388 add_codec_to_sdp(p, x, &m_audio, &a_audio, debug, &min_audio_packet_size); 10389 else if (x & AST_FORMAT_VIDEO_MASK) 10390 add_vcodec_to_sdp(p, x, &m_video, &a_video, debug, &min_video_packet_size); 10391 else if (x & AST_FORMAT_TEXT_MASK) 10392 add_tcodec_to_sdp(p, x, &m_text, &a_text, debug, &min_text_packet_size); 10393 } 10394 10395 /* Now add DTMF RFC2833 telephony-event as a codec */ 10396 for (x = 1; x <= AST_RTP_MAX; x <<= 1) { 10397 if (!(p->jointnoncodeccapability & x)) 10398 continue; 10399 10400 add_noncodec_to_sdp(p, x, &m_audio, &a_audio, debug); 10401 } 10402 10403 ast_debug(3, "-- Done with adding codecs to SDP\n"); 10404 10405 if (!p->owner || !ast_internal_timing_enabled(p->owner)) 10406 ast_str_append(&a_audio, 0, "a=silenceSupp:off - - - -\r\n"); 10407 10408 if (min_audio_packet_size) 10409 ast_str_append(&a_audio, 0, "a=ptime:%d\r\n", min_audio_packet_size); 10410 10411 /* XXX don't think you can have ptime for video */ 10412 if (min_video_packet_size) 10413 ast_str_append(&a_video, 0, "a=ptime:%d\r\n", min_video_packet_size); 10414 10415 /* XXX don't think you can have ptime for text */ 10416 if (min_text_packet_size) 10417 ast_str_append(&a_text, 0, "a=ptime:%d\r\n", min_text_packet_size); 10418 10419 if (m_audio->len - m_audio->used < 2 || m_video->len - m_video->used < 2 || 10420 m_text->len - m_text->used < 2 || a_text->len - a_text->used < 2 || 10421 a_audio->len - a_audio->used < 2 || a_video->len - a_video->used < 2) 10422 ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n"); 10423 } 10424 10425 if (add_t38) { 10426 /* Our T.38 end is */ 10427 ast_udptl_get_us(p->udptl, &udptlsin); 10428 10429 /* Determine T.38 UDPTL destination */ 10430 if (p->udptlredirip.sin_addr.s_addr) { 10431 udptldest.sin_port = p->udptlredirip.sin_port; 10432 udptldest.sin_addr = p->udptlredirip.sin_addr; 10433 } else { 10434 udptldest.sin_addr = p->ourip.sin_addr; 10435 udptldest.sin_port = udptlsin.sin_port; 10436 } 10437 10438 if (debug) 10439 ast_debug(1, "T.38 UDPTL is at %s port %d\n", ast_inet_ntoa(p->ourip.sin_addr), ntohs(udptlsin.sin_port)); 10440 10441 /* We break with the "recommendation" and send our IP, in order that our 10442 peer doesn't have to ast_gethostbyname() us */ 10443 10444 ast_str_append(&m_modem, 0, "m=image %d udptl t38\r\n", ntohs(udptldest.sin_port)); 10445 10446 ast_str_append(&a_modem, 0, "a=T38FaxVersion:%d\r\n", p->t38.our_parms.version); 10447 ast_str_append(&a_modem, 0, "a=T38MaxBitRate:%d\r\n", t38_get_rate(p->t38.our_parms.rate)); 10448 if (p->t38.our_parms.fill_bit_removal) { 10449 ast_str_append(&a_modem, 0, "a=T38FaxFillBitRemoval\r\n"); 10450 } 10451 if (p->t38.our_parms.transcoding_mmr) { 10452 ast_str_append(&a_modem, 0, "a=T38FaxTranscodingMMR\r\n"); 10453 } 10454 if (p->t38.our_parms.transcoding_jbig) { 10455 ast_str_append(&a_modem, 0, "a=T38FaxTranscodingJBIG\r\n"); 10456 } 10457 switch (p->t38.our_parms.rate_management) { 10458 case AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF: 10459 ast_str_append(&a_modem, 0, "a=T38FaxRateManagement:transferredTCF\r\n"); 10460 break; 10461 case AST_T38_RATE_MANAGEMENT_LOCAL_TCF: 10462 ast_str_append(&a_modem, 0, "a=T38FaxRateManagement:localTCF\r\n"); 10463 break; 10464 } 10465 ast_str_append(&a_modem, 0, "a=T38FaxMaxDatagram:%u\r\n", ast_udptl_get_local_max_datagram(p->udptl)); 10466 switch (ast_udptl_get_error_correction_scheme(p->udptl)) { 10467 case UDPTL_ERROR_CORRECTION_NONE: 10468 break; 10469 case UDPTL_ERROR_CORRECTION_FEC: 10470 ast_str_append(&a_modem, 0, "a=T38FaxUdpEC:t38UDPFEC\r\n"); 10471 break; 10472 case UDPTL_ERROR_CORRECTION_REDUNDANCY: 10473 ast_str_append(&a_modem, 0, "a=T38FaxUdpEC:t38UDPRedundancy\r\n"); 10474 break; 10475 } 10476 } 10477 10478 if (needaudio) 10479 ast_str_append(&m_audio, 0, "\r\n"); 10480 if (needvideo) 10481 ast_str_append(&m_video, 0, "\r\n"); 10482 if (needtext) 10483 ast_str_append(&m_text, 0, "\r\n"); 10484 10485 add_header(resp, "Content-Type", "application/sdp"); 10486 add_content(resp, version); 10487 add_content(resp, owner); 10488 add_content(resp, subject); 10489 add_content(resp, connection); 10490 if (needvideo) /* only if video response is appropriate */ 10491 add_content(resp, bandwidth); 10492 add_content(resp, session_time); 10493 if (needaudio) { 10494 add_content(resp, m_audio->str); 10495 add_content(resp, a_audio->str); 10496 add_content(resp, hold); 10497 } else if (p->offered_media[SDP_AUDIO].offered) { 10498 snprintf(dummy_answer, sizeof(dummy_answer), "m=audio 0 RTP/AVP %s\r\n", p->offered_media[SDP_AUDIO].text); 10499 add_content(resp, dummy_answer); 10500 } 10501 if (needvideo) { /* only if video response is appropriate */ 10502 add_content(resp, m_video->str); 10503 add_content(resp, a_video->str); 10504 add_content(resp, hold); /* Repeat hold for the video stream */ 10505 } else if (p->offered_media[SDP_VIDEO].offered) { 10506 snprintf(dummy_answer, sizeof(dummy_answer), "m=video 0 RTP/AVP %s\r\n", p->offered_media[SDP_VIDEO].text); 10507 add_content(resp, dummy_answer); 10508 } 10509 if (needtext) { /* only if text response is appropriate */ 10510 add_content(resp, m_text->str); 10511 add_content(resp, a_text->str); 10512 add_content(resp, hold); /* Repeat hold for the text stream */ 10513 } else if (p->offered_media[SDP_TEXT].offered) { 10514 snprintf(dummy_answer, sizeof(dummy_answer), "m=text 0 RTP/AVP %s\r\n", p->offered_media[SDP_TEXT].text); 10515 add_content(resp, dummy_answer); 10516 } 10517 if (add_t38) { 10518 add_content(resp, m_modem->str); 10519 add_content(resp, a_modem->str); 10520 } else if (p->offered_media[SDP_IMAGE].offered) { 10521 add_content(resp, "m=image 0 udptl t38\r\n"); 10522 } 10523 10524 /* Update lastrtprx when we send our SDP */ 10525 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 10526 10527 ast_debug(3, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, capability)); 10528 10529 return AST_SUCCESS; 10530 }
| static int add_sip_domain | ( | const char * | domain, | |
| const enum domain_mode | mode, | |||
| const char * | context | |||
| ) | [static] |
Add SIP domain to list of domains we are responsible for.
Definition at line 23689 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), domain::context, domain::domain, LOG_WARNING, and domain::mode.
Referenced by reload_config().
23690 { 23691 struct domain *d; 23692 23693 if (ast_strlen_zero(domain)) { 23694 ast_log(LOG_WARNING, "Zero length domain.\n"); 23695 return 1; 23696 } 23697 23698 if (!(d = ast_calloc(1, sizeof(*d)))) 23699 return 0; 23700 23701 ast_copy_string(d->domain, domain, sizeof(d->domain)); 23702 23703 if (!ast_strlen_zero(context)) 23704 ast_copy_string(d->context, context, sizeof(d->context)); 23705 23706 d->mode = mode; 23707 23708 AST_LIST_LOCK(&domain_list); 23709 AST_LIST_INSERT_TAIL(&domain_list, d, list); 23710 AST_LIST_UNLOCK(&domain_list); 23711 23712 if (sipdebug) 23713 ast_debug(1, "Added local SIP domain '%s'\n", domain); 23714 23715 return 1; 23716 }
| static int add_supported_header | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
Add "Supported" header to sip message. Since some options may be disabled in the config, the sip_pvt must be inspected to determine what is supported for this dialog.
Definition at line 9152 of file chan_sip.c.
References add_header(), SESSION_TIMER_MODE_REFUSE, and st_get_mode().
Referenced by respprep(), transmit_invite(), transmit_notify_with_sipfrag(), transmit_refer(), and transmit_reinvite_with_sdp().
09153 { 09154 int res; 09155 if (st_get_mode(pvt) != SESSION_TIMER_MODE_REFUSE) { 09156 res = add_header(req, "Supported", "replaces, timer"); 09157 } else { 09158 res = add_header(req, "Supported", "replaces"); 09159 } 09160 return res; 09161 }
| static void add_tcodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add text codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 10079 of file chan_sip.c.
References AST_FORMAT_T140, AST_FORMAT_T140RED, ast_getformatname(), ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_rtp_lookup_sample_rate(), ast_str_append(), ast_verbose, and sip_pvt::trtp.
Referenced by add_sdp().
10082 { 10083 int rtp_code; 10084 10085 if (!p->trtp) 10086 return; 10087 10088 if (debug) 10089 ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec)); 10090 10091 if ((rtp_code = ast_rtp_lookup_code(p->trtp, 1, codec)) == -1) 10092 return; 10093 10094 ast_str_append(m_buf, 0, " %d", rtp_code); 10095 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 10096 ast_rtp_lookup_mime_subtype(1, codec, 0), 10097 ast_rtp_lookup_sample_rate(1, codec)); 10098 /* Add fmtp code here */ 10099 10100 if (codec == AST_FORMAT_T140RED) { 10101 ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code, 10102 ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140), 10103 ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140), 10104 ast_rtp_lookup_code(p->trtp, 1, AST_FORMAT_T140)); 10105 10106 } 10107 }
| static int add_text | ( | struct sip_request * | req, | |
| const char * | text | |||
| ) | [static] |
Add text body to SIP message.
Definition at line 9941 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_message_with_text().
09942 { 09943 /* XXX Convert \n's to \r\n's XXX */ 09944 add_header(req, "Content-Type", "text/plain;charset=UTF-8"); 09945 add_content(req, text); 09946 return 0; 09947 }
| static struct ast_variable* add_var | ( | const char * | buf, | |
| struct ast_variable * | list | |||
| ) | [static, read] |
implement the setvar config line
Definition at line 23838 of file chan_sip.c.
References ast_strdupa, ast_variable_new(), and ast_variable::next.
Referenced by build_peer().
23839 { 23840 struct ast_variable *tmpvar = NULL; 23841 char *varname = ast_strdupa(buf), *varval = NULL; 23842 23843 if ((varval = strchr(varname, '='))) { 23844 *varval++ = '\0'; 23845 if ((tmpvar = ast_variable_new(varname, varval, ""))) { 23846 tmpvar->next = list; 23847 list = tmpvar; 23848 } 23849 } 23850 return list; 23851 }
| static void add_vcodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add video codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 10056 of file chan_sip.c.
References ast_getformatname(), ast_rtp_lookup_code(), ast_rtp_lookup_mime_subtype(), ast_rtp_lookup_sample_rate(), ast_str_append(), ast_verbose, and sip_pvt::vrtp.
Referenced by add_sdp().
10059 { 10060 int rtp_code; 10061 10062 if (!p->vrtp) 10063 return; 10064 10065 if (debug) 10066 ast_verbose("Adding video codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec)); 10067 10068 if ((rtp_code = ast_rtp_lookup_code(p->vrtp, 1, codec)) == -1) 10069 return; 10070 10071 ast_str_append(m_buf, 0, " %d", rtp_code); 10072 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 10073 ast_rtp_lookup_mime_subtype(1, codec, 0), 10074 ast_rtp_lookup_sample_rate(1, codec)); 10075 /* Add fmtp code here */ 10076 }
| static int add_vidupdate | ( | struct sip_request * | req | ) | [static] |
add XML encoded media control with update
Definition at line 9981 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_info_with_vidupdate().
09982 { 09983 const char *xml_is_a_huge_waste_of_space = 09984 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" 09985 " <media_control>\r\n" 09986 " <vc_primitive>\r\n" 09987 " <to_encoder>\r\n" 09988 " <picture_fast_update>\r\n" 09989 " </picture_fast_update>\r\n" 09990 " </to_encoder>\r\n" 09991 " </vc_primitive>\r\n" 09992 " </media_control>\r\n"; 09993 add_header(req, "Content-Type", "application/media_control+xml"); 09994 add_content(req, xml_is_a_huge_waste_of_space); 09995 return 0; 09996 }
| static void append_date | ( | struct sip_request * | req | ) | [static] |
Append date to SIP message.
Definition at line 9878 of file chan_sip.c.
References add_header().
Referenced by transmit_invite(), transmit_response_with_date(), transmit_response_with_minse(), and transmit_response_with_unsupported().
09879 { 09880 char tmpdat[256]; 09881 struct tm tm; 09882 time_t t = time(NULL); 09883 09884 gmtime_r(&t, &tm); 09885 strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T GMT", &tm); 09886 add_header(req, "Date", tmpdat); 09887 }
| static void append_history_full | ( | struct sip_pvt * | p, | |
| const char * | fmt, | |||
| ... | ||||
| ) | [static] |
Append to SIP dialog history with arg list.
Definition at line 3756 of file chan_sip.c.
References append_history_va(), and sip_pvt::do_history.
03757 { 03758 va_list ap; 03759 03760 if (!p) 03761 return; 03762 03763 if (!p->do_history && !recordhistory && !dumphistory) 03764 return; 03765 03766 va_start(ap, fmt); 03767 append_history_va(p, fmt, ap); 03768 va_end(ap); 03769 03770 return; 03771 }
| static void append_history_va | ( | struct sip_pvt * | p, | |
| const char * | fmt, | |||
| va_list | ap | |||
| ) | [static] |
Append to SIP dialog history with arg list.
Definition at line 3729 of file chan_sip.c.
References ast_calloc, ast_free, AST_LIST_INSERT_TAIL, AST_LIST_REMOVE_HEAD, buf, sip_history::event, MAX_HISTORY_ENTRIES, and strsep().
Referenced by append_history_full().
03730 { 03731 char buf[80], *c = buf; /* max history length */ 03732 struct sip_history *hist; 03733 int l; 03734 03735 vsnprintf(buf, sizeof(buf), fmt, ap); 03736 strsep(&c, "\r\n"); /* Trim up everything after \r or \n */ 03737 l = strlen(buf) + 1; 03738 if (!(hist = ast_calloc(1, sizeof(*hist) + l))) 03739 return; 03740 if (!p->history && !(p->history = ast_calloc(1, sizeof(*p->history)))) { 03741 ast_free(hist); 03742 return; 03743 } 03744 memcpy(hist->event, buf, l); 03745 if (p->history_entries == MAX_HISTORY_ENTRIES) { 03746 struct sip_history *oldest; 03747 oldest = AST_LIST_REMOVE_HEAD(p->history, list); 03748 p->history_entries--; 03749 ast_free(oldest); 03750 } 03751 AST_LIST_INSERT_TAIL(p->history, hist, list); 03752 p->history_entries++; 03753 }
| static void ast_quiet_chan | ( | struct ast_channel * | chan | ) | [static] |
Turn off generator data XXX Does this function belong in the SIP channel?
Definition at line 19107 of file chan_sip.c.
References ast_channel::_state, ast_deactivate_generator(), AST_FLAG_MOH, ast_moh_stop(), AST_STATE_UP, ast_test_flag, and ast_channel::generatordata.
Referenced by attempt_transfer(), and handle_invite_replaces().
19108 { 19109 if (chan && chan->_state == AST_STATE_UP) { 19110 if (ast_test_flag(chan, AST_FLAG_MOH)) 19111 ast_moh_stop(chan); 19112 else if (chan->generatordata) 19113 ast_deactivate_generator(chan); 19114 } 19115 }
| static void ast_sip_ouraddrfor | ( | struct in_addr * | them, | |
| struct sockaddr_in * | us, | |||
| struct sip_pvt * | p | |||
| ) | [static] |
NAT fix - decide which IP address to use for Asterisk server?
Using the localaddr structure built up with localnet statements in sip.conf apply it to their address to see if we need to substitute our externip or can get away with our internal bindaddr 'us' is always overwritten.
Definition at line 3654 of file chan_sip.c.
References ast_apply_ha(), ast_debug, ast_inet_ntoa(), ast_log(), ast_ouraddrfor(), ast_parse_arg(), AST_SENSE_ALLOW, ast_stun_request(), bindaddr, externip, get_transport(), internip, ast_tcptls_session_args::local_address, LOG_NOTICE, LOG_WARNING, sip_settings::matchexterniplocally, PARSE_INADDR, sip_cfg, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, sip_pvt::socket, stunaddr, and sip_socket::type.
Referenced by __sip_subscribe_mwi_do(), manager_sipnotify(), sip_alloc(), sip_cli_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_register(), and transmit_response_using_temp().
03655 { 03656 struct sockaddr_in theirs; 03657 /* Set want_remap to non-zero if we want to remap 'us' to an externally 03658 * reachable IP address and port. This is done if: 03659 * 1. we have a localaddr list (containing 'internal' addresses marked 03660 * as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on them, 03661 * and AST_SENSE_ALLOW on 'external' ones); 03662 * 2. either stunaddr or externip is set, so we know what to use as the 03663 * externally visible address; 03664 * 3. the remote address, 'them', is external; 03665 * 4. the address returned by ast_ouraddrfor() is 'internal' (AST_SENSE_DENY 03666 * when passed to ast_apply_ha() so it does need to be remapped. 03667 * This fourth condition is checked later. 03668 */ 03669 int want_remap; 03670 03671 *us = internip; /* starting guess for the internal address */ 03672 /* now ask the system what would it use to talk to 'them' */ 03673 ast_ouraddrfor(them, &us->sin_addr); 03674 theirs.sin_addr = *them; 03675 03676 want_remap = localaddr && 03677 (externip.sin_addr.s_addr || stunaddr.sin_addr.s_addr) && 03678 ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ; 03679 03680 if (want_remap && 03681 (!sip_cfg.matchexterniplocally || !ast_apply_ha(localaddr, us)) ) { 03682 /* if we used externhost or stun, see if it is time to refresh the info */ 03683 if (externexpire && time(NULL) >= externexpire) { 03684 if (stunaddr.sin_addr.s_addr) { 03685 ast_stun_request(sipsock, &stunaddr, NULL, &externip); 03686 } else { 03687 if (ast_parse_arg(externhost, PARSE_INADDR, &externip)) 03688 ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost); 03689 } 03690 externexpire = time(NULL) + externrefresh; 03691 } 03692 if (externip.sin_addr.s_addr) 03693 *us = externip; 03694 else 03695 ast_log(LOG_WARNING, "stun failed\n"); 03696 ast_debug(1, "Target address %s is not local, substituting externip\n", 03697 ast_inet_ntoa(*(struct in_addr *)&them->s_addr)); 03698 } else if (p) { 03699 /* no remapping, but we bind to a specific address, so use it. */ 03700 switch (p->socket.type) { 03701 case SIP_TRANSPORT_TCP: 03702 if (sip_tcp_desc.local_address.sin_addr.s_addr) { 03703 *us = sip_tcp_desc.local_address; 03704 } else { 03705 us->sin_port = sip_tcp_desc.local_address.sin_port; 03706 } 03707 break; 03708 case SIP_TRANSPORT_TLS: 03709 if (sip_tls_desc.local_address.sin_addr.s_addr) { 03710 *us = sip_tls_desc.local_address; 03711 } else { 03712 us->sin_port = sip_tls_desc.local_address.sin_port; 03713 } 03714 break; 03715 case SIP_TRANSPORT_UDP: 03716 /* fall through on purpose */ 03717 default: 03718 if (bindaddr.sin_addr.s_addr) { 03719 *us = bindaddr; 03720 } 03721 } 03722 } else if (bindaddr.sin_addr.s_addr) { 03723 *us = bindaddr; 03724 } 03725 ast_debug(3, "Setting SIP_TRANSPORT_%s with address %s:%d\n", get_transport(p->socket.type), ast_inet_ntoa(us->sin_addr), ntohs(us->sin_port)); 03726 }
Attempt transfer of SIP call This fix for attended transfers on a local PBX.
Definition at line 19119 of file chan_sip.c.
References ast_channel::_state, ast_channel_masquerade(), ast_debug, ast_log(), ast_quiet_chan(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), ast_state2str(), sip_dual::chan1, sip_dual::chan2, LOG_NOTICE, LOG_WARNING, and ast_channel::name.
Referenced by local_attended_transfer().
19120 { 19121 int res = 0; 19122 struct ast_channel *peera = NULL, 19123 *peerb = NULL, 19124 *peerc = NULL, 19125 *peerd = NULL; 19126 19127 19128 /* We will try to connect the transferee with the target and hangup 19129 all channels to the transferer */ 19130 ast_debug(4, "Sip transfer:--------------------\n"); 19131 if (transferer->chan1) 19132 ast_debug(4, "-- Transferer to PBX channel: %s State %s\n", transferer->chan1->name, ast_state2str(transferer->chan1->_state)); 19133 else 19134 ast_debug(4, "-- No transferer first channel - odd??? \n"); 19135 if (target->chan1) 19136 ast_debug(4, "-- Transferer to PBX second channel (target): %s State %s\n", target->chan1->name, ast_state2str(target->chan1->_state)); 19137 else 19138 ast_debug(4, "-- No target first channel ---\n"); 19139 if (transferer->chan2) 19140 ast_debug(4, "-- Bridged call to transferee: %s State %s\n", transferer->chan2->name, ast_state2str(transferer->chan2->_state)); 19141 else 19142 ast_debug(4, "-- No bridged call to transferee\n"); 19143 if (target->chan2) 19144 ast_debug(4, "-- Bridged call to transfer target: %s State %s\n", target->chan2 ? target->chan2->name : "<none>", target->chan2 ? ast_state2str(target->chan2->_state) : "(none)"); 19145 else 19146 ast_debug(4, "-- No target second channel ---\n"); 19147 ast_debug(4, "-- END Sip transfer:--------------------\n"); 19148 if (transferer->chan2) { /* We have a bridge on the transferer's channel */ 19149 peera = transferer->chan1; /* Transferer - PBX -> transferee channel * the one we hangup */ 19150 peerb = target->chan1; /* Transferer - PBX -> target channel - This will get lost in masq */ 19151 peerc = transferer->chan2; /* Asterisk to Transferee */ 19152 peerd = target->chan2; /* Asterisk to Target */ 19153 ast_debug(3, "SIP transfer: Four channels to handle\n"); 19154 } else if (target->chan2) { /* Transferer has no bridge (IVR), but transferee */ 19155 peera = target->chan1; /* Transferer to PBX -> target channel */ 19156 peerb = transferer->chan1; /* Transferer to IVR*/ 19157 peerc = target->chan2; /* Asterisk to Target */ 19158 peerd = transferer->chan2; /* Nothing */ 19159 ast_debug(3, "SIP transfer: Three channels to handle\n"); 19160 } 19161 19162 if (peera && peerb && peerc && (peerb != peerc)) { 19163 ast_quiet_chan(peera); /* Stop generators */ 19164 ast_quiet_chan(peerb); 19165 ast_quiet_chan(peerc); 19166 if (peerd) 19167 ast_quiet_chan(peerd); 19168 19169 ast_debug(4, "SIP transfer: trying to masquerade %s into %s\n", peerc->name, peerb->name); 19170 if (ast_channel_masquerade(peerb, peerc)) { 19171 ast_log(LOG_WARNING, "Failed to masquerade %s into %s\n", peerb->name, peerc->name); 19172 res = -1; 19173 } else 19174 ast_debug(4, "SIP transfer: Succeeded to masquerade channels.\n"); 19175 return res; 19176 } else { 19177 ast_log(LOG_NOTICE, "SIP Transfer attempted with no appropriate bridged calls to transfer\n"); 19178 if (transferer->chan1) 19179 ast_softhangup_nolock(transferer->chan1, AST_SOFTHANGUP_DEV); 19180 if (target->chan1) 19181 ast_softhangup_nolock(target->chan1, AST_SOFTHANGUP_DEV); 19182 return -1; 19183 } 19184 return 0; 19185 }
| static void auth_headers | ( | enum sip_auth_type | code, | |
| char ** | header, | |||
| char ** | respheader | |||
| ) | [static] |
return the request and response heade for a 401 or 407 code
Definition at line 12106 of file chan_sip.c.
References ast_verbose, PROXY_AUTH, and WWW_AUTH.
Referenced by check_auth(), do_proxy_auth(), do_register_auth(), and transmit_request_with_auth().
12107 { 12108 if (code == WWW_AUTH) { /* 401 */ 12109 *header = "WWW-Authenticate"; 12110 *respheader = "Authorization"; 12111 } else if (code == PROXY_AUTH) { /* 407 */ 12112 *header = "Proxy-Authenticate"; 12113 *respheader = "Proxy-Authorization"; 12114 } else { 12115 ast_verbose("-- wrong response code %d\n", code); 12116 *header = *respheader = "Invalid"; 12117 } 12118 }
| static int auto_congest | ( | const void * | arg | ) | [static] |
Scheduled congestion on a call. Only called by the scheduler, must return the reference when done.
Definition at line 5418 of file chan_sip.c.
References append_history, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_CONGESTION, ast_queue_control(), DEFAULT_TRANS_TIMEOUT, dialog_unref(), sip_pvt::initid, sip_pvt::owner, sip_pvt_lock, sip_pvt_unlock, and sip_scheddestroy().
Referenced by sip_call(), and sip_show_sched().
05419 { 05420 struct sip_pvt *p = (struct sip_pvt *)arg; 05421 05422 sip_pvt_lock(p); 05423 p->initid = -1; /* event gone, will not be rescheduled */ 05424 if (p->owner) { 05425 /* XXX fails on possible deadlock */ 05426 if (!ast_channel_trylock(p->owner)) { 05427 append_history(p, "Cong", "Auto-congesting (timer)"); 05428 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 05429 ast_channel_unlock(p->owner); 05430 } 05431 05432 /* Give the channel a chance to act before we proceed with destruction */ 05433 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 05434 } 05435 sip_pvt_unlock(p); 05436 dialog_unref(p, "unreffing arg passed into auto_congest callback (p->initid)"); 05437 return 0; 05438 }
| static void build_callid_pvt | ( | struct sip_pvt * | pvt | ) | [static] |
Build SIP Call-ID value for a non-REGISTER transaction.
Definition at line 7205 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, buf, sip_pvt::callid, sip_pvt::fromdomain, generate_random_string(), sip_pvt::ourip, and S_OR.
Referenced by __sip_subscribe_mwi_do(), manager_sipnotify(), sip_alloc(), sip_cli_notify(), sip_poke_peer(), sip_request_call(), and sip_send_mwi_to_peer().
07206 { 07207 char buf[33]; 07208 07209 const char *host = S_OR(pvt->fromdomain, ast_inet_ntoa(pvt->ourip.sin_addr)); 07210 07211 ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 07212 07213 }
| static void build_callid_registry | ( | struct sip_registry * | reg, | |
| struct in_addr | ourip, | |||
| const char * | fromdomain | |||
| ) | [static] |
Build SIP Call-ID value for a REGISTER transaction.
Definition at line 7216 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, buf, sip_pvt::callid, generate_random_string(), and S_OR.
Referenced by transmit_register().
07217 { 07218 char buf[33]; 07219 07220 const char *host = S_OR(fromdomain, ast_inet_ntoa(ourip)); 07221 07222 ast_string_field_build(reg, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 07223 }
| static void build_contact | ( | struct sip_pvt * | p | ) | [static] |
Build contact header - the contact header we send out.
Definition at line 10727 of file chan_sip.c.
References ast_inet_ntoa(), ast_string_field_build, ast_strlen_zero(), sip_pvt::exten, get_transport(), sip_pvt::ourip, ourport, sip_standard_port(), SIP_TRANSPORT_UDP, sip_pvt::socket, and sip_socket::type.
Referenced by __sip_subscribe_mwi_do(), check_user_full(), handle_request_invite(), handle_request_options(), handle_request_subscribe(), initreqprep(), register_verify(), and transmit_register().
10728 { 10729 10730 int ourport = ntohs(p->ourip.sin_port); 10731 /* only add port if it's non-standard for the transport type */ 10732 if (!sip_standard_port(p->socket.type, ourport)) { 10733 if (p->socket.type == SIP_TRANSPORT_UDP) 10734 ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ourport); 10735 else 10736 ast_string_field_build(p, our_contact, "<sip:%s%s%s:%d;transport=%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), ourport, get_transport(p->socket.type)); 10737 } else { 10738 if (p->socket.type == SIP_TRANSPORT_UDP) 10739 ast_string_field_build(p, our_contact, "<sip:%s%s%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr)); 10740 else 10741 ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", p->exten, ast_strlen_zero(p->exten) ? "" : "@", ast_inet_ntoa(p->ourip.sin_addr), get_transport(p->socket.type)); 10742 } 10743 }
| static struct sip_peer * build_peer | ( | const char * | name, | |
| struct ast_variable * | v, | |||
| struct ast_variable * | alt, | |||
| int | realtime, | |||
| int | devstate_only | |||
| ) | [static, read] |
Build peer from configuration (file or realtime static/dynamic).
< The first transport listed should be default outbound
Definition at line 23977 of file chan_sip.c.
References __set_address_from_contact(), accountcode, add_peer_mailboxes(), add_peer_mwi_subs(), add_realm_authentication(), add_var(), sip_peer::addr, sip_settings::allowsubscribe, sip_peer::allowtransfer, sip_peer::amaflags, ao2_t_alloc, ao2_t_find, ao2_t_ref, asprintf, ast_append_ha(), ast_atomic_fetchadd_int(), ast_callerid_split(), ast_cdr_amaflags2int(), ast_copy_flags, ast_copy_string(), ast_debug, ast_dnsmgr_lookup(), ast_free, ast_free_ha(), ast_get_group(), ast_get_ip(), ast_get_time_t(), ast_inet_ntoa(), AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_parse_allow_disallow(), ast_parse_caller_presentation(), AST_SCHED_DEL_UNREF, ast_set2_flag, ast_set_flag, ast_skip_blanks(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_set(), ast_str_strlen(), ast_strdupa, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_true(), ast_variables_destroy(), sip_peer::auth, sip_peer::autoframing, sip_peer::busy_level, sip_peer::call_limit, sip_peer::callgroup, sip_peer::callingpres, sip_peer::capability, sip_peer::chanvars, cid_name, cid_num, clear_realm_authentication(), sip_peer::contactha, context, sip_peer::defaddr, DEFAULT_MAXMS, sip_peer::default_outbound_transport, sip_mailbox::delme, sip_peer::deprecated_username, destroy_association(), destroy_mailbox(), sip_peer::dnsmgr, errno, sip_peer::expire, FALSE, ast_flags::flags, sip_peer::flags, format, get_srv_protocol(), get_srv_service(), sip_peer::ha, handle_common_options(), handle_t38_options(), sip_peer::host_dynamic, sip_settings::ignore_regexpire, inet_aton(), sip_peer::is_realtime, language, sip_peer::lastms, sip_peer::lastmsgssent, ast_variable::lineno, LOG_ERROR, LOG_NOTICE, LOG_WARNING, mailbox, sip_peer::mailboxes, sip_peer::maxcallbitrate, MAXHOSTNAMELEN, sip_peer::maxms, mohinterpret, mohsuggest, ast_variable::name, sip_peer::name, ast_variable::next, OBJ_POINTER, OBJ_UNLINK, sip_peer::outboundproxy, parkinglot, sip_peer::pickupgroup, sip_socket::port, port_str2int(), sip_peer::portinuri, sip_peer::prefs, proxy_allocate(), sip_peer::qualifyfreq, ref_peer(), reg_source_db(), sip_peer::remotesecret, sip_peer::rt_fromcontact, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_peer::rtptimeout, sip_peer::secret, secret, set_peer_defaults(), set_socket_transport(), sip_cfg, sip_destroy_peer_fn(), SIP_NAT_ROUTE, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_HAVEPEERCONTEXT, SIP_PAGE2_REGISTERTRYING, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_SUBSCRIBEMWIONLY, sip_poke_peer(), sip_register(), sip_send_mwi_to_peer(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, SIP_TYPE_PEER, SIP_TYPE_USER, SIP_USEREQPHONE, sip_peer::socket, sip_settings::srvlookup, srvlookup, sip_st_cfg::st_max_se, sip_st_cfg::st_min_se, sip_st_cfg::st_mode_oper, sip_st_cfg::st_ref, STANDARD_SIP_PORT, STANDARD_TLS_PORT, sip_peer::stimer, str2stmode(), str2strefresher(), strsep(), sip_peer::t38_maxdatagram, sip_peer::the_mark, sip_peer::timer_b, sip_peer::timer_t1, sip_peer::tohost, TRANSFER_CLOSED, TRANSFER_OPENFORALL, sip_peer::transports, TRUE, sip_socket::type, sip_peer::type, unref_peer(), sip_peer::username, and ast_variable::value.
Referenced by realtime_peer(), and reload_config().
23978 { 23979 struct sip_peer *peer = NULL; 23980 struct ast_ha *oldha = NULL; 23981 int found = 0; 23982 int firstpass = 1; 23983 uint16_t port = 0; 23984 int format = 0; /* Ama flags */ 23985 time_t regseconds = 0; 23986 struct ast_flags peerflags[2] = {{(0)}}; 23987 struct ast_flags mask[2] = {{(0)}}; 23988 char callback[256] = ""; 23989 struct sip_peer tmp_peer; 23990 const char *srvlookup = NULL; 23991 static int deprecation_warning = 1; 23992 int alt_fullcontact = alt ? 1 : 0; 23993 struct ast_str *fullcontact = ast_str_alloca(512); 23994 23995 if (!realtime || ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 23996 /* Note we do NOT use find_peer here, to avoid realtime recursion */ 23997 /* We also use a case-sensitive comparison (unlike find_peer) so 23998 that case changes made to the peer name will be properly handled 23999 during reload 24000 */ 24001 ast_copy_string(tmp_peer.name, name, sizeof(tmp_peer.name)); 24002 peer = ao2_t_find(peers, &tmp_peer, OBJ_POINTER | OBJ_UNLINK, "find and unlink peer from peers table"); 24003 } 24004 24005 if (peer) { 24006 /* Already in the list, remove it and it will be added back (or FREE'd) */ 24007 found++; 24008 if (!(peer->the_mark)) 24009 firstpass = 0; 24010 } else { 24011 if (!(peer = ao2_t_alloc(sizeof(*peer), sip_destroy_peer_fn, "allocate a peer struct"))) 24012 return NULL; 24013 24014 if (ast_string_field_init(peer, 512)) { 24015 ao2_t_ref(peer, -1, "failed to string_field_init, drop peer"); 24016 return NULL; 24017 } 24018 24019 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 24020 ast_atomic_fetchadd_int(&rpeerobjs, 1); 24021 ast_debug(3, "-REALTIME- peer built. Name: %s. Peer objects: %d\n", name, rpeerobjs); 24022 } else 24023 ast_atomic_fetchadd_int(&speerobjs, 1); 24024 } 24025 24026 /* Note that our peer HAS had its reference count increased */ 24027 if (firstpass) { 24028 peer->lastmsgssent = -1; 24029 oldha = peer->ha; 24030 peer->ha = NULL; 24031 set_peer_defaults(peer); /* Set peer defaults */ 24032 peer->type = 0; 24033 } 24034 if (!found && name) 24035 ast_copy_string(peer->name, name, sizeof(peer->name)); 24036 24037 /* If we have channel variables, remove them (reload) */ 24038 if (peer->chanvars) { 24039 ast_variables_destroy(peer->chanvars); 24040 peer->chanvars = NULL; 24041 /* XXX should unregister ? */ 24042 } 24043 24044 if (found) 24045 peer->portinuri = 0; 24046 24047 /* If we have realm authentication information, remove them (reload) */ 24048 clear_realm_authentication(peer->auth); 24049 peer->auth = NULL; 24050 /* clear the transport information. We will detect if a default value is required after parsing the config */ 24051 peer->default_outbound_transport = 0; 24052 peer->transports = 0; 24053 24054 if (!devstate_only) { 24055 struct sip_mailbox *mailbox; 24056 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 24057 mailbox->delme = 1; 24058 } 24059 } 24060 24061 for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { 24062 if (!devstate_only) { 24063 if (handle_common_options(&peerflags[0], &mask[0], v)) { 24064 continue; 24065 } 24066 if (handle_t38_options(&peerflags[0], &mask[0], v, &peer->t38_maxdatagram)) { 24067 continue; 24068 } 24069 if (!strcasecmp(v->name, "transport") && !ast_strlen_zero(v->value)) { 24070 char *val = ast_strdupa(v->value); 24071 char *trans; 24072 24073 while ((trans = strsep(&val, ","))) { 24074 trans = ast_skip_blanks(trans); 24075 24076 if (!strncasecmp(trans, "udp", 3)) { 24077 peer->transports |= SIP_TRANSPORT_UDP; 24078 } else if (!strncasecmp(trans, "tcp", 3)) { 24079 peer->transports |= SIP_TRANSPORT_TCP; 24080 } else if (!strncasecmp(trans, "tls", 3)) { 24081 peer->transports |= SIP_TRANSPORT_TLS; 24082 } else { 24083 ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, udp will be used.\n", trans); 24084 } 24085 24086 if (!peer->default_outbound_transport) { /*!< The first transport listed should be default outbound */ 24087 peer->default_outbound_transport = peer->transports; 24088 } 24089 } 24090 } else if (realtime && !strcasecmp(v->name, "regseconds")) { 24091 ast_get_time_t(v->value, ®seconds, 0, NULL); 24092 } else if (realtime && !strcasecmp(v->name, "name")) { 24093 ast_copy_string(peer->name, v->value, sizeof(peer->name)); 24094 } else if (realtime && !strcasecmp(v->name, "useragent")) { 24095 ast_string_field_set(peer, useragent, v->value); 24096 } else if (!strcasecmp(v->name, "type")) { 24097 if (!strcasecmp(v->value, "peer")) { 24098 peer->type |= SIP_TYPE_PEER; 24099 } else if (!strcasecmp(v->value, "user")) { 24100 peer->type |= SIP_TYPE_USER; 24101 } else if (!strcasecmp(v->value, "friend")) { 24102 peer->type = SIP_TYPE_USER | SIP_TYPE_PEER; 24103 } 24104 } else if (!strcasecmp(v->name, "remotesecret")) { 24105 ast_string_field_set(peer, remotesecret, v->value); 24106 } else if (!strcasecmp(v->name, "secret")) { 24107 ast_string_field_set(peer, secret, v->value); 24108 } else if (!strcasecmp(v->name, "md5secret")) { 24109 ast_string_field_set(peer, md5secret, v->value); 24110 } else if (!strcasecmp(v->name, "auth")) { 24111 peer->auth = add_realm_authentication(peer->auth, v->value, v->lineno); 24112 } else if (!strcasecmp(v->name, "callerid")) { 24113 char cid_name[80] = { '\0' }, cid_num[80] = { '\0' }; 24114 24115 ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num)); 24116 ast_string_field_set(peer, cid_name, cid_name); 24117 ast_string_field_set(peer, cid_num, cid_num); 24118 } else if (!strcasecmp(v->name, "fullname")) { 24119 ast_string_field_set(peer, cid_name, v->value); 24120 } else if (!strcasecmp(v->name, "trunkname")) { 24121 /* This is actually for a trunk, so we don't want to override callerid */ 24122 ast_string_field_set(peer, cid_name, ""); 24123 } else if (!strcasecmp(v->name, "cid_number")) { 24124 ast_string_field_set(peer, cid_num, v->value); 24125 } else if (!strcasecmp(v->name, "context")) { 24126 ast_string_field_set(peer, context, v->value); 24127 ast_set_flag(&peer->flags[1], SIP_PAGE2_HAVEPEERCONTEXT); 24128 } else if (!strcasecmp(v->name, "subscribecontext")) { 24129 ast_string_field_set(peer, subscribecontext, v->value); 24130 } else if (!strcasecmp(v->name, "fromdomain")) { 24131 ast_string_field_set(peer, fromdomain, v->value); 24132 } else if (!strcasecmp(v->name, "usereqphone")) { 24133 ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE); 24134 } else if (!strcasecmp(v->name, "fromuser")) { 24135 ast_string_field_set(peer, fromuser, v->value); 24136 } else if (!strcasecmp(v->name, "outboundproxy")) { 24137 char *port, *next, *force, *proxyname; 24138 int forceopt = FALSE; 24139 /* Set peer channel variable */ 24140 next = proxyname = ast_strdupa(v->value); 24141 if ((port = strchr(proxyname, ':'))) { 24142 *port++ = '\0'; 24143 next = port; 24144 } 24145 if ((force = strchr(next, ','))) { 24146 *force++ = '\0'; 24147 forceopt = strcmp(force, "force"); 24148 } 24149 /* Allocate proxy object */ 24150 peer->outboundproxy = proxy_allocate(proxyname, port, forceopt); 24151 } else if (!strcasecmp(v->name, "host")) { 24152 if (!strcasecmp(v->value, "dynamic")) { 24153 /* They'll register with us */ 24154 if (!found || !peer->host_dynamic) { 24155 /* Initialize stuff if this is a new peer, or if it used to 24156 * not be dynamic before the reload. */ 24157 memset(&peer->addr.sin_addr, 0, 4); 24158 peer->addr.sin_port = 0; 24159 } 24160 peer->host_dynamic = TRUE; 24161 } else { 24162 /* Non-dynamic. Make sure we become that way if we're not */ 24163 AST_SCHED_DEL_UNREF(sched, peer->expire, 24164 unref_peer(peer, "removing register expire ref")); 24165 /* the port will either be set to a default value or a config specified value once all option parsing is complete */ 24166 peer->addr.sin_port = 0; 24167 peer->host_dynamic = FALSE; 24168 srvlookup = v->value; 24169 } 24170 } else if (!strcasecmp(v->name, "defaultip")) { 24171 if (!ast_strlen_zero(v->value) && ast_get_ip(&peer->defaddr, v->value)) { 24172 unref_peer(peer, "unref_peer: from build_peer defaultip"); 24173 return NULL; 24174 } 24175 } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) { 24176 int ha_error = 0; 24177 if (!ast_strlen_zero(v->value)) { 24178 peer->ha = ast_append_ha(v->name, v->value, peer->ha, &ha_error); 24179 } 24180 if (ha_error) { 24181 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 24182 } 24183 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 24184 int ha_error = 0; 24185 if (!ast_strlen_zero(v->value)) { 24186 peer->contactha = ast_append_ha(v->name + 7, v->value, peer->contactha, &ha_error); 24187 } 24188 if (ha_error) { 24189 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 24190 } 24191 } else if (!strcasecmp(v->name, "port")) { 24192 peer->portinuri = 1; 24193 if (!(port = port_str2int(v->value, 0))) { 24194 if (realtime) { 24195 /* If stored as integer, could be 0 for some DBs (notably MySQL) */ 24196 peer->portinuri = 0; 24197 } else { 24198 ast_log(LOG_WARNING, "Invalid peer port configuration at line %d : %s\n", v->lineno, v->value); 24199 } 24200 } 24201 } else if (!strcasecmp(v->name, "callingpres")) { 24202 peer->callingpres = ast_parse_caller_presentation(v->value); 24203 if (peer->callingpres == -1) { 24204 peer->callingpres = atoi(v->value); 24205 } 24206 } else if (!strcasecmp(v->name, "username") || !strcmp(v->name, "defaultuser")) { /* "username" is deprecated */ 24207 ast_string_field_set(peer, username, v->value); 24208 if (!strcasecmp(v->name, "username")) { 24209 if (deprecation_warning) { 24210 ast_log(LOG_NOTICE, "The 'username' field for sip peers has been deprecated in favor of the term 'defaultuser'\n"); 24211 deprecation_warning = 0; 24212 } 24213 peer->deprecated_username = 1; 24214 } 24215 } else if (!strcasecmp(v->name, "language")) { 24216 ast_string_field_set(peer, language, v->value); 24217 } else if (!strcasecmp(v->name, "regexten")) { 24218 ast_string_field_set(peer, regexten, v->value); 24219 } else if (!strcasecmp(v->name, "callbackextension")) { 24220 ast_copy_string(callback, v->value, sizeof(callback)); 24221 } else if (!strcasecmp(v->name, "amaflags")) { 24222 format = ast_cdr_amaflags2int(v->value); 24223 if (format < 0) { 24224 ast_log(LOG_WARNING, "Invalid AMA Flags for peer: %s at line %d\n", v->value, v->lineno); 24225 } else { 24226 peer->amaflags = format; 24227 } 24228 } else if (!strcasecmp(v->name, "accountcode")) { 24229 ast_string_field_set(peer, accountcode, v->value); 24230 } else if (!strcasecmp(v->name, "mohinterpret")) { 24231 ast_string_field_set(peer, mohinterpret, v->value); 24232 } else if (!strcasecmp(v->name, "mohsuggest")) { 24233 ast_string_field_set(peer, mohsuggest, v->value); 24234 } else if (!strcasecmp(v->name, "parkinglot")) { 24235 ast_string_field_set(peer, parkinglot, v->value); 24236 } else if (!strcasecmp(v->name, "mailbox")) { 24237 add_peer_mailboxes(peer, v->value); 24238 } else if (!strcasecmp(v->name, "hasvoicemail")) { 24239 /* People expect that if 'hasvoicemail' is set, that the mailbox will 24240 * be also set, even if not explicitly specified. */ 24241 if (ast_true(v->value) && AST_LIST_EMPTY(&peer->mailboxes)) { 24242 add_peer_mailboxes(peer, name); 24243 } 24244 } else if (!strcasecmp(v->name, "subscribemwi")) { 24245 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_SUBSCRIBEMWIONLY); 24246 } else if (!strcasecmp(v->name, "vmexten")) { 24247 ast_string_field_set(peer, vmexten, v->value); 24248 } else if (!strcasecmp(v->name, "callgroup")) { 24249 peer->callgroup = ast_get_group(v->value); 24250 } else if (!strcasecmp(v->name, "allowtransfer")) { 24251 peer->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 24252 } else if (!strcasecmp(v->name, "pickupgroup")) { 24253 peer->pickupgroup = ast_get_group(v->value); 24254 } else if (!strcasecmp(v->name, "allow")) { 24255 int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, TRUE); 24256 if (error) { 24257 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 24258 } 24259 } else if (!strcasecmp(v->name, "disallow")) { 24260 int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, FALSE); 24261 if (error) { 24262 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 24263 } 24264 } else if (!strcasecmp(v->name, "registertrying")) { 24265 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_REGISTERTRYING); 24266 } else if (!strcasecmp(v->name, "autoframing")) { 24267 peer->autoframing = ast_true(v->value); 24268 } else if (!strcasecmp(v->name, "rtptimeout")) { 24269 if ((sscanf(v->value, "%30d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) { 24270 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 24271 peer->rtptimeout = global_rtptimeout; 24272 } 24273 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 24274 if ((sscanf(v->value, "%30d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) { 24275 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 24276 peer->rtpholdtimeout = global_rtpholdtimeout; 24277 } 24278 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 24279 if ((sscanf(v->value, "%30d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) { 24280 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 24281 peer->rtpkeepalive = global_rtpkeepalive; 24282 } 24283 } else if (!strcasecmp(v->name, "timert1")) { 24284 if ((sscanf(v->value, "%30d", &peer->timer_t1) != 1) || (peer->timer_t1 < 0)) { 24285 ast_log(LOG_WARNING, "'%s' is not a valid T1 time at line %d. Using default.\n", v->value, v->lineno); 24286 peer->timer_t1 = global_t1; 24287 } 24288 /* Note that Timer B is dependent upon T1 and MUST NOT be lower 24289 * than T1 * 64, according to RFC 3261, Section 17.1.1.2 */ 24290 if (peer->timer_b < peer->timer_t1 * 64) { 24291 peer->timer_b = peer->timer_t1 * 64; 24292 } 24293 } else if (!strcasecmp(v->name, "timerb")) { 24294 if ((sscanf(v->value, "%30d", &peer->timer_b) != 1) || (peer->timer_b < 0)) { 24295 ast_log(LOG_WARNING, "'%s' is not a valid Timer B time at line %d. Using default.\n", v->value, v->lineno); 24296 peer->timer_b = global_timer_b; 24297 } 24298 if (peer->timer_b < peer->timer_t1 * 64) { 24299 static int warning = 0; 24300 if (warning++ % 20 == 0) { 24301 ast_log(LOG_WARNING, "Timer B has been set lower than recommended. (RFC 3261, 17.1.1.2)\n"); 24302 } 24303 } 24304 } else if (!strcasecmp(v->name, "setvar")) { 24305 peer->chanvars = add_var(v->value, peer->chanvars); 24306 } else if (!strcasecmp(v->name, "qualifyfreq")) { 24307 int i; 24308 if (sscanf(v->value, "%30d", &i) == 1) { 24309 peer->qualifyfreq = i * 1000; 24310 } else { 24311 ast_log(LOG_WARNING, "Invalid qualifyfreq number '%s' at line %d of %s\n", v->value, v->lineno, config); 24312 peer->qualifyfreq = global_qualifyfreq; 24313 } 24314 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 24315 peer->maxcallbitrate = atoi(v->value); 24316 if (peer->maxcallbitrate < 0) { 24317 peer->maxcallbitrate = default_maxcallbitrate; 24318 } 24319 } else if (!strcasecmp(v->name, "session-timers")) { 24320 int i = (int) str2stmode(v->value); 24321 if (i < 0) { 24322 ast_log(LOG_WARNING, "Invalid session-timers '%s' at line %d of %s\n", v->value, v->lineno, config); 24323 peer->stimer.st_mode_oper = global_st_mode; 24324 } else { 24325 peer->stimer.st_mode_oper = i; 24326 } 24327 } else if (!strcasecmp(v->name, "session-expires")) { 24328 if (sscanf(v->value, "%30d", &peer->stimer.st_max_se) != 1) { 24329 ast_log(LOG_WARNING, "Invalid session-expires '%s' at line %d of %s\n", v->value, v->lineno, config); 24330 peer->stimer.st_max_se = global_max_se; 24331 } 24332 } else if (!strcasecmp(v->name, "session-minse")) { 24333 if (sscanf(v->value, "%30d", &peer->stimer.st_min_se) != 1) { 24334 ast_log(LOG_WARNING, "Invalid session-minse '%s' at line %d of %s\n", v->value, v->lineno, config); 24335 peer->stimer.st_min_se = global_min_se; 24336 } 24337 if (peer->stimer.st_min_se < 90) { 24338 ast_log(LOG_WARNING, "session-minse '%s' at line %d of %s is not allowed to be < 90 secs\n", v->value, v->lineno, config); 24339 peer->stimer.st_min_se = global_min_se; 24340 } 24341 } else if (!strcasecmp(v->name, "session-refresher")) { 24342 int i = (int) str2strefresher(v->value); 24343 if (i < 0) { 24344 ast_log(LOG_WARNING, "Invalid session-refresher '%s' at line %d of %s\n", v->value, v->lineno, config); 24345 peer->stimer.st_ref = global_st_refresher; 24346 } else { 24347 peer->stimer.st_ref = i; 24348 } 24349 } 24350 } 24351 24352 /* These apply to devstate lookups */ 24353 if (realtime && !strcasecmp(v->name, "lastms")) { 24354 sscanf(v->value, "%30d", &peer->lastms); 24355 } else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) { 24356 inet_aton(v->value, &(peer->addr.sin_addr)); 24357 } else if (realtime && !strcasecmp(v->name, "fullcontact")) { 24358 if (alt_fullcontact && !alt) { 24359 /* Reset, because the alternate also has a fullcontact and we 24360 * do NOT want the field value to be doubled. It might be 24361 * tempting to skip this, but the first table might not have 24362 * fullcontact and since we're here, we know that the alternate 24363 * absolutely does. */ 24364 alt_fullcontact = 0; 24365 ast_str_reset(fullcontact); 24366 } 24367 /* Reconstruct field, because realtime separates our value at the ';' */ 24368 if (fullcontact->used > 0) { 24369 ast_str_append(&fullcontact, 0, ";%s", v->value); 24370 } else { 24371 ast_str_set(&fullcontact, 0, "%s", v->value); 24372 } 24373 } else if (!strcasecmp(v->name, "qualify")) { 24374 if (!strcasecmp(v->value, "no")) { 24375 peer->maxms = 0; 24376 } else if (!strcasecmp(v->value, "yes")) { 24377 peer->maxms = default_qualify ? default_qualify : DEFAULT_MAXMS; 24378 } else if (sscanf(v->value, "%30d", &peer->maxms) != 1) { 24379 ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno); 24380 peer->maxms = 0; 24381 } 24382 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->maxms > 0) { 24383 /* This would otherwise cause a network storm, where the 24384 * qualify response refreshes the peer from the database, 24385 * which in turn causes another qualify to be sent, ad 24386 * infinitum. */ 24387 ast_log(LOG_WARNING, "Qualify is incompatible with dynamic uncached realtime. Please either turn rtcachefriends on or turn qualify off on peer '%s'\n", peer->name); 24388 peer->maxms = 0; 24389 } 24390 } else if (!strcasecmp(v->name, "callcounter")) { 24391 peer->call_limit = ast_true(v->value) ? INT_MAX : 0; 24392 } else if (!strcasecmp(v->name, "call-limit")) { 24393 peer->call_limit = atoi(v->value); 24394 if (peer->call_limit < 0) { 24395 peer->call_limit = 0; 24396 } 24397 } else if (!strcasecmp(v->name, "busylevel")) { 24398 peer->busy_level = atoi(v->value); 24399 if (peer->busy_level < 0) { 24400 peer->busy_level = 0; 24401 } 24402 } 24403 } 24404 24405 if (!devstate_only) { 24406 struct sip_mailbox *mailbox; 24407 AST_LIST_TRAVERSE_SAFE_BEGIN(&peer->mailboxes, mailbox, entry) { 24408 if (mailbox->delme) { 24409 AST_LIST_REMOVE_CURRENT(entry); 24410 destroy_mailbox(mailbox); 24411 } 24412 } 24413 AST_LIST_TRAVERSE_SAFE_END; 24414 } 24415 24416 if (!peer->default_outbound_transport) { 24417 /* Set default set of transports */ 24418 peer->transports = default_transports; 24419 /* Set default primary transport */ 24420 peer->default_outbound_transport = default_primary_transport; 24421 } 24422 24423 /* The default transport type set during build_peer should only replace the socket.type when... 24424 * 1. Registration is not present and the socket.type and default transport types are different. 24425 * 2. The socket.type is not an acceptable transport type after rebuilding peer. 24426 * 3. The socket.type is not set yet. */ 24427 if (((peer->socket.type != peer->default_outbound_transport) && (peer->expire == -1)) || 24428 !(peer->socket.type & peer->transports) || !(peer->socket.type)) { 24429 24430 set_socket_transport(&peer->socket, peer->default_outbound_transport); 24431 } 24432 24433 if (port && !realtime && peer->host_dynamic) { 24434 peer->defaddr.sin_port = htons(port); 24435 } else if (port) { 24436 peer->addr.sin_port = htons(port); 24437 } 24438 24439 if (ast_str_strlen(fullcontact)) { 24440 ast_string_field_set(peer, fullcontact, ast_str_buffer(fullcontact)); 24441 peer->rt_fromcontact = TRUE; 24442 /* We have a hostname in the fullcontact, but if we don't have an 24443 * address listed on the entry (or if it's 'dynamic'), then we need to 24444 * parse the entry to obtain the IP address, so a dynamic host can be 24445 * contacted immediately after reload (as opposed to waiting for it to 24446 * register once again). But if we have an address for this peer and NAT was 24447 * specified, use that address instead. */ 24448 /* XXX May need to revisit the final argument; does the realtime DB store whether 24449 * the original contact was over TLS or not? XXX */ 24450 if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE) || !peer->addr.sin_addr.s_addr) { 24451 __set_address_from_contact(fullcontact->str, &peer->addr, 0); 24452 } 24453 } 24454 24455 if (srvlookup && peer->dnsmgr == NULL) { 24456 char transport[MAXHOSTNAMELEN]; 24457 char _srvlookup[MAXHOSTNAMELEN]; 24458 char *params; 24459 24460 ast_copy_string(_srvlookup, srvlookup, sizeof(_srvlookup)); 24461 if ((params = strchr(_srvlookup, ';'))) { 24462 *params++ = '\0'; 24463 } 24464 24465 snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(peer->socket.type), get_srv_protocol(peer->socket.type)); 24466 24467 if (ast_dnsmgr_lookup(_srvlookup, &peer->addr, &peer->dnsmgr, sip_cfg.srvlookup && !peer->portinuri ? transport : NULL)) { 24468 ast_log(LOG_ERROR, "srvlookup failed for host: %s, on peer %s, removing peer\n", _srvlookup, peer->name); 24469 unref_peer(peer, "getting rid of a peer pointer"); 24470 return NULL; 24471 } 24472 24473 ast_string_field_set(peer, tohost, srvlookup); 24474 if (global_dynamic_exclude_static) { 24475 int err = 0; 24476 global_contact_ha = ast_append_ha("deny", (char *)ast_inet_ntoa(peer->addr.sin_addr), global_contact_ha, &err); 24477 if (err) { 24478 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 24479 } 24480 } 24481 } 24482 24483 if (!peer->addr.sin_port) { 24484 peer->addr.sin_port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT)); 24485 } 24486 if (!peer->defaddr.sin_port) { 24487 peer->defaddr.sin_port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT)); 24488 } 24489 if (!peer->socket.port) { 24490 peer->socket.port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT)); 24491 } 24492 24493 if (!sip_cfg.ignore_regexpire && peer->host_dynamic && realtime) { 24494 time_t nowtime = time(NULL); 24495 24496 if ((nowtime - regseconds) > 0) { 24497 destroy_association(peer); 24498 memset(&peer->addr, 0, sizeof(peer->addr)); 24499 peer->lastms = -1; 24500 ast_debug(1, "Bah, we're expired (%d/%d/%d)!\n", (int)(nowtime - regseconds), (int)regseconds, (int)nowtime); 24501 } 24502 } 24503 24504 /* Startup regular pokes */ 24505 if (!devstate_only && realtime && peer->lastms > 0) { 24506 ref_peer(peer, "schedule qualify"); 24507 sip_poke_peer(peer, 0); 24508 } 24509 24510 ast_copy_flags(&peer->flags[0], &peerflags[0], mask[0].flags); 24511 ast_copy_flags(&peer->flags[1], &peerflags[1], mask[1].flags); 24512 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { 24513 sip_cfg.allowsubscribe = TRUE; /* No global ban any more */ 24514 } 24515 if (peer->host_dynamic && !peer->is_realtime) { 24516 reg_source_db(peer); 24517 } 24518 24519 /* If they didn't request that MWI is sent *only* on subscribe, go ahead and 24520 * subscribe to it now. */ 24521 if (!devstate_only && !ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && 24522 !AST_LIST_EMPTY(&peer->mailboxes)) { 24523 add_peer_mwi_subs(peer); 24524 /* Send MWI from the event cache only. This is so we can send initial 24525 * MWI if app_voicemail got loaded before chan_sip. If it is the other 24526 * way, then we will get events when app_voicemail gets loaded. */ 24527 sip_send_mwi_to_peer(peer, NULL, 1); 24528 } 24529 24530 peer->the_mark = 0; 24531 24532 ast_free_ha(oldha); 24533 if (!ast_strlen_zero(callback)) { /* build string from peer info */ 24534 char *reg_string; 24535 if (asprintf(®_string, "%s?%s:%s@%s/%s", peer->name, peer->username, !ast_strlen_zero(peer->remotesecret) ? peer->remotesecret : peer->secret, peer->tohost, callback) < 0) { 24536 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 24537 } else if (reg_string) { 24538 sip_register(reg_string, 0); /* XXX TODO: count in registry_count */ 24539 ast_free(reg_string); 24540 } 24541 } 24542 return peer; 24543 }
| static int build_reply_digest | ( | struct sip_pvt * | p, | |
| int | method, | |||
| char * | digest, | |||
| int | digest_len | |||
| ) | [static] |
Build reply digest.
Definition at line 17323 of file chan_sip.c.
References append_history, ast_copy_string(), ast_debug, ast_inet_ntoa(), ast_md5_hash(), ast_random(), ast_strlen_zero(), sip_pvt::authname, sip_pvt::callid, sip_pvt::domain, find_realm_authentication(), sip_auth::md5secret, sip_registry::md5secret, sip_pvt::nonce, sip_pvt::noncecount, sip_pvt::opaque, sip_registry::opaque, sip_pvt::peerauth, sip_pvt::peermd5secret, sip_pvt::peername, sip_pvt::peersecret, sip_pvt::qop, sip_pvt::realm, sip_pvt::sa, sip_auth::secret, secret, sip_methods, text, sip_pvt::uri, sip_auth::username, sip_pvt::username, and sip_registry::username.
Referenced by reply_digest(), transmit_register(), and transmit_request_with_auth().
17324 { 17325 char a1[256]; 17326 char a2[256]; 17327 char a1_hash[256]; 17328 char a2_hash[256]; 17329 char resp[256]; 17330 char resp_hash[256]; 17331 char uri[256]; 17332 char opaque[256] = ""; 17333 char cnonce[80]; 17334 const char *username; 17335 const char *secret; 17336 const char *md5secret; 17337 struct sip_auth *auth = NULL; /* Realm authentication */ 17338 17339 if (!ast_strlen_zero(p->domain)) 17340 ast_copy_string(uri, p->domain, sizeof(uri)); 17341 else if (!ast_strlen_zero(p->uri)) 17342 ast_copy_string(uri, p->uri, sizeof(uri)); 17343 else 17344 snprintf(uri, sizeof(uri), "sip:%s@%s", p->username, ast_inet_ntoa(p->sa.sin_addr)); 17345 17346 snprintf(cnonce, sizeof(cnonce), "%08lx", ast_random()); 17347 17348 /* Check if we have separate auth credentials */ 17349 if(!(auth = find_realm_authentication(p->peerauth, p->realm))) /* Start with peer list */ 17350 auth = find_realm_authentication(authl, p->realm); /* If not, global list */ 17351 17352 if (auth) { 17353 ast_debug(3, "use realm [%s] from peer [%s][%s]\n", auth->username, p->peername, p->username); 17354 username = auth->username; 17355 secret = auth->secret; 17356 md5secret = auth->md5secret; 17357 if (sipdebug) 17358 ast_debug(1, "Using realm %s authentication for call %s\n", p->realm, p->callid); 17359 } else { 17360 /* No authentication, use peer or register= config */ 17361 username = p->authname; 17362 secret = p->peersecret; 17363 md5secret = p->peermd5secret; 17364 } 17365 if (ast_strlen_zero(username)) /* We have no authentication */ 17366 return -1; 17367 17368 /* Calculate SIP digest response */ 17369 snprintf(a1, sizeof(a1), "%s:%s:%s", username, p->realm, secret); 17370 snprintf(a2, sizeof(a2), "%s:%s", sip_methods[method].text, uri); 17371 if (!ast_strlen_zero(md5secret)) 17372 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 17373 else 17374 ast_md5_hash(a1_hash, a1); 17375 ast_md5_hash(a2_hash, a2); 17376 17377 p->noncecount++; 17378 if (!ast_strlen_zero(p->qop)) 17379 snprintf(resp, sizeof(resp), "%s:%s:%08x:%s:%s:%s", a1_hash, p->nonce, p->noncecount, cnonce, "auth", a2_hash); 17380 else 17381 snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, p->nonce, a2_hash); 17382 ast_md5_hash(resp_hash, resp); 17383 17384 /* only include the opaque string if it's set */ 17385 if (!ast_strlen_zero(p->opaque)) { 17386 snprintf(opaque, sizeof(opaque), ", opaque=\"%s\"", p->opaque); 17387 } 17388 17389 /* XXX We hard code our qop to "auth" for now. XXX */ 17390 if (!ast_strlen_zero(p->qop)) 17391 snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\"%s, qop=auth, cnonce=\"%s\", nc=%08x", username, p->realm, uri, p->nonce, resp_hash, opaque, cnonce, p->noncecount); 17392 else 17393 snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\"%s", username, p->realm, uri, p->nonce, resp_hash, opaque); 17394 17395 append_history(p, "AuthResp", "Auth response sent for %s in realm %s - nc %d", username, p->realm, p->noncecount); 17396 17397 return 0; 17398 }
| static void build_route | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | backwards | |||
| ) | [static] |
Build route list from Record-Route header.
Definition at line 12623 of file chan_sip.c.
References __get_header(), ast_copy_string(), ast_debug, ast_malloc, ast_strlen_zero(), free_old_route(), get_header(), sip_route::hop, list_route(), sip_route::next, sip_pvt::route, sip_pvt::route_persistant, and sip_debug_test_pvt().
Referenced by handle_request_invite(), handle_request_subscribe(), and handle_response_invite().
12624 { 12625 struct sip_route *thishop, *head, *tail; 12626 int start = 0; 12627 int len; 12628 const char *rr, *contact, *c; 12629 12630 /* Once a persistant route is set, don't fool with it */ 12631 if (p->route && p->route_persistant) { 12632 ast_debug(1, "build_route: Retaining previous route: <%s>\n", p->route->hop); 12633 return; 12634 } 12635 12636 if (p->route) { 12637 free_old_route(p->route); 12638 p->route = NULL; 12639 } 12640 12641 /* We only want to create the route set the first time this is called */ 12642 p->route_persistant = 1; 12643 12644 /* Build a tailq, then assign it to p->route when done. 12645 * If backwards, we add entries from the head so they end up 12646 * in reverse order. However, we do need to maintain a correct 12647 * tail pointer because the contact is always at the end. 12648 */ 12649 head = NULL; 12650 tail = head; 12651 /* 1st we pass through all the hops in any Record-Route headers */ 12652 for (;;) { 12653 /* Each Record-Route header */ 12654 rr = __get_header(req, "Record-Route", &start); 12655 if (*rr == '\0') 12656 break; 12657 for (; (rr = strchr(rr, '<')) ; rr += len) { /* Each route entry */ 12658 ++rr; 12659 len = strcspn(rr, ">") + 1; 12660 /* Make a struct route */ 12661 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 12662 /* ast_calloc is not needed because all fields are initialized in this block */ 12663 ast_copy_string(thishop->hop, rr, len); 12664 ast_debug(2, "build_route: Record-Route hop: <%s>\n", thishop->hop); 12665 /* Link in */ 12666 if (backwards) { 12667 /* Link in at head so they end up in reverse order */ 12668 thishop->next = head; 12669 head = thishop; 12670 /* If this was the first then it'll be the tail */ 12671 if (!tail) 12672 tail = thishop; 12673 } else { 12674 thishop->next = NULL; 12675 /* Link in at the end */ 12676 if (tail) 12677 tail->next = thishop; 12678 else 12679 head = thishop; 12680 tail = thishop; 12681 } 12682 } 12683 } 12684 } 12685 12686 /* Only append the contact if we are dealing with a strict router */ 12687 if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop, ";lr") == NULL) ) { 12688 /* 2nd append the Contact: if there is one */ 12689 /* Can be multiple Contact headers, comma separated values - we just take the first */ 12690 contact = get_header(req, "Contact"); 12691 if (!ast_strlen_zero(contact)) { 12692 ast_debug(2, "build_route: Contact hop: %s\n", contact); 12693 /* Look for <: delimited address */ 12694 c = strchr(contact, '<'); 12695 if (c) { 12696 /* Take to > */ 12697 ++c; 12698 len = strcspn(c, ">") + 1; 12699 } else { 12700 /* No <> - just take the lot */ 12701 c = contact; 12702 len = strlen(contact) + 1; 12703 } 12704 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 12705 /* ast_calloc is not needed because all fields are initialized in this block */ 12706 ast_copy_string(thishop->hop, c, len); 12707 thishop->next = NULL; 12708 /* Goes at the end */ 12709 if (tail) 12710 tail->next = thishop; 12711 else 12712 head = thishop; 12713 } 12714 } 12715 } 12716 12717 /* Store as new route */ 12718 p->route = head; 12719 12720 /* For debugging dump what we ended up with */ 12721 if (sip_debug_test_pvt(p)) 12722 list_route(p->route); 12723 }
| static void build_rpid | ( | struct sip_pvt * | p | ) | [static] |
Build the Remote Party-ID & From using callingpres options.
Definition at line 10746 of file chan_sip.c.
References ast_inet_ntoa(), ast_log(), AST_PRES_ALLOWED, AST_PRES_ALLOWED_NETWORK_NUMBER, AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRES_NUMBER_NOT_AVAILABLE, AST_PRES_PROHIB_NETWORK_NUMBER, AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, AST_PRES_RESTRICTION, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), buf, sip_pvt::callingpres, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, FALSE, sip_pvt::fromdomain, sip_pvt::fromuser, LOG_WARNING, sip_pvt::ourip, sip_pvt::owner, sip_pvt::rpid, sip_pvt::rpid_from, S_OR, sip_pvt::tag, and TRUE.
Referenced by initreqprep().
10747 { 10748 int send_pres_tags = TRUE; 10749 const char *privacy=NULL; 10750 const char *screen=NULL; 10751 char buf[256]; 10752 const char *clid = default_callerid; 10753 const char *clin = NULL; 10754 const char *fromdomain; 10755 10756 if (!ast_strlen_zero(p->rpid) || !ast_strlen_zero(p->rpid_from)) 10757 return; 10758 10759 if (p->owner && !ast_strlen_zero(p->owner->cid.cid_num)) 10760 clid = p->owner->cid.cid_num; 10761 if (p->owner && p->owner->cid.cid_name) 10762 clin = p->owner->cid.cid_name; 10763 if (ast_strlen_zero(clin)) 10764 clin = clid; 10765 10766 switch (p->callingpres) { 10767 case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: 10768 privacy = "off"; 10769 screen = "no"; 10770 break; 10771 case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: 10772 privacy = "off"; 10773 screen = "yes"; 10774 break; 10775 case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN: 10776 privacy = "off"; 10777 screen = "no"; 10778 break; 10779 case AST_PRES_ALLOWED_NETWORK_NUMBER: 10780 privacy = "off"; 10781 screen = "yes"; 10782 break; 10783 case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED: 10784 privacy = "full"; 10785 screen = "no"; 10786 break; 10787 case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN: 10788 privacy = "full"; 10789 screen = "yes"; 10790 break; 10791 case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN: 10792 privacy = "full"; 10793 screen = "no"; 10794 break; 10795 case AST_PRES_PROHIB_NETWORK_NUMBER: 10796 privacy = "full"; 10797 screen = "yes"; 10798 break; 10799 case AST_PRES_NUMBER_NOT_AVAILABLE: 10800 send_pres_tags = FALSE; 10801 break; 10802 default: 10803 ast_log(LOG_WARNING, "Unsupported callingpres (%d)\n", p->callingpres); 10804 if ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) 10805 privacy = "full"; 10806 else 10807 privacy = "off"; 10808 screen = "no"; 10809 break; 10810 } 10811 10812 fromdomain = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr)); 10813 10814 snprintf(buf, sizeof(buf), "\"%s\" <sip:%s@%s>", clin, clid, fromdomain); 10815 if (send_pres_tags) 10816 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), ";privacy=%s;screen=%s", privacy, screen); 10817 ast_string_field_set(p, rpid, buf); 10818 10819 ast_string_field_build(p, rpid_from, "\"%s\" <sip:%s@%s>;tag=%s", clin, 10820 S_OR(p->fromuser, clid), 10821 fromdomain, p->tag); 10822 }
| static void build_via | ( | struct sip_pvt * | p | ) | [static] |
Build a Via header for a request.
Definition at line 3635 of file chan_sip.c.
References ast_inet_ntoa(), ast_test_flag, sip_pvt::branch, sip_pvt::flags, get_transport_pvt(), sip_pvt::ourip, SIP_NAT, SIP_NAT_RFC3581, and sip_pvt::via.
Referenced by __sip_subscribe_mwi_do(), manager_sipnotify(), reqprep(), sip_alloc(), sip_cli_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_invite(), transmit_register(), and transmit_response_using_temp().
03636 { 03637 /* Work around buggy UNIDEN UIP200 firmware */ 03638 const char *rport = ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_RFC3581 ? ";rport" : ""; 03639 03640 /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ 03641 snprintf(p->via, sizeof(p->via), "SIP/2.0/%s %s:%d;branch=z9hG4bK%08x%s", 03642 get_transport_pvt(p), 03643 ast_inet_ntoa(p->ourip.sin_addr), 03644 ntohs(p->ourip.sin_port), (int) p->branch, rport); 03645 }
| static int cb_extensionstate | ( | char * | context, | |
| char * | exten, | |||
| int | state, | |||
| void * | data | |||
| ) | [static] |
Callback for the devicestate notification (SUBSCRIBE) support subsystem.
Definition at line 12955 of file chan_sip.c.
References append_history, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_REMOVED, ast_extension_state2str(), ast_log(), ast_set_flag, ast_test_flag, ast_verb, sip_pvt::autokillid, DEFAULT_TRANS_TIMEOUT, FALSE, sip_pvt::flags, sip_pvt::laststate, LOG_WARNING, NONE, sip_pvt::pendinginvite, sip_cancel_destroy(), SIP_PAGE2_STATECHANGEQUEUE, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), sip_pvt::stateid, sip_pvt::subscribed, transmit_state_notify(), and sip_pvt::username.
Referenced by handle_request_subscribe(), handle_response(), and handle_response_notify().
12956 { 12957 struct sip_pvt *p = data; 12958 12959 sip_pvt_lock(p); 12960 12961 switch(state) { 12962 case AST_EXTENSION_DEACTIVATED: /* Retry after a while */ 12963 case AST_EXTENSION_REMOVED: /* Extension is gone */ 12964 if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */ 12965 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 12966 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); /* Delete subscription in 32 secs */ 12967 ast_verb(2, "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username); 12968 p->stateid = -1; 12969 p->subscribed = NONE; 12970 append_history(p, "Subscribestatus", "%s", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated"); 12971 break; 12972 default: /* Tell user */ 12973 p->laststate = state; 12974 break; 12975 } 12976 if (p->subscribed != NONE) { /* Only send state NOTIFY if we know the format */ 12977 if (!p->pendinginvite) { 12978 transmit_state_notify(p, state, 1, FALSE); 12979 } else { 12980 /* We already have a NOTIFY sent that is not answered. Queue the state up. 12981 if many state changes happen meanwhile, we will only send a notification of the last one */ 12982 ast_set_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 12983 } 12984 } 12985 ast_verb(2, "Extension Changed %s[%s] new state %s for Notify User %s %s\n", exten, context, ast_extension_state2str(state), p->username, 12986 ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE) ? "(queued)" : ""); 12987 12988 sip_pvt_unlock(p); 12989 12990 return 0; 12991 }
| static void change_hold_state | ( | struct sip_pvt * | dialog, | |
| struct sip_request * | req, | |||
| int | holdstate, | |||
| int | sendonly | |||
| ) | [static] |
Change hold state for a call.
Definition at line 8087 of file chan_sip.c.
References append_history, ast_clear_flag, ast_set_flag, ast_test_flag, sip_settings::callevents, sip_request::data, EVENT_FLAG_CALL, sip_pvt::flags, manager_event, ast_channel::name, sip_settings::notifyhold, sip_pvt::owner, sip_cfg, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_CALL_ONHOLD_ACTIVE, SIP_PAGE2_CALL_ONHOLD_INACTIVE, SIP_PAGE2_CALL_ONHOLD_ONEDIR, sip_peer_hold(), and ast_channel::uniqueid.
Referenced by handle_request_invite(), and process_sdp().
08088 { 08089 if (sip_cfg.notifyhold && (!holdstate || !ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD))) 08090 sip_peer_hold(dialog, holdstate); 08091 if (sip_cfg.callevents) 08092 manager_event(EVENT_FLAG_CALL, "Hold", 08093 "Status: %s\r\n" 08094 "Channel: %s\r\n" 08095 "Uniqueid: %s\r\n", 08096 holdstate ? "On" : "Off", 08097 dialog->owner->name, 08098 dialog->owner->uniqueid); 08099 append_history(dialog, holdstate ? "Hold" : "Unhold", "%s", req->data->str); 08100 if (!holdstate) { /* Put off remote hold */ 08101 ast_clear_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD); /* Clear both flags */ 08102 return; 08103 } 08104 /* No address for RTP, we're on hold */ 08105 08106 if (sendonly == 1) /* One directional hold (sendonly/recvonly) */ 08107 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ONEDIR); 08108 else if (sendonly == 2) /* Inactive stream */ 08109 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_INACTIVE); 08110 else 08111 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ACTIVE); 08112 return; 08113 }
| static void change_t38_state | ( | struct sip_pvt * | p, | |
| int | state | |||
| ) | [static] |
Change the T38 state on a SIP dialog.
Definition at line 5091 of file chan_sip.c.
References AST_CONTROL_T38_PARAMETERS, ast_debug, ast_queue_control_data(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_TERMINATED, ast_udptl_get_far_max_ifp(), ast_udptl_set_tag(), chan, ast_control_t38_parameters::max_ifp, ast_channel::name, sip_pvt::owner, ast_control_t38_parameters::request_response, t38properties::state, sip_pvt::t38, T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_PEER_REINVITE, t38properties::their_parms, sip_pvt::udptl, and sip_pvt::username.
Referenced by handle_response_invite(), interpret_t38_parameters(), process_sdp(), and sip_t38_abort().
05092 { 05093 int old = p->t38.state; 05094 struct ast_channel *chan = p->owner; 05095 struct ast_control_t38_parameters parameters = { .request_response = 0 }; 05096 05097 /* Don't bother changing if we are already in the state wanted */ 05098 if (old == state) 05099 return; 05100 05101 p->t38.state = state; 05102 ast_debug(2, "T38 state changed to %d on channel %s\n", p->t38.state, chan ? chan->name : "<none>"); 05103 05104 /* If no channel was provided we can't send off a control frame */ 05105 if (!chan) 05106 return; 05107 05108 /* Given the state requested and old state determine what control frame we want to queue up */ 05109 switch (state) { 05110 case T38_PEER_REINVITE: 05111 parameters = p->t38.their_parms; 05112 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 05113 parameters.request_response = AST_T38_REQUEST_NEGOTIATE; 05114 ast_udptl_set_tag(p->udptl, "SIP/%s", p->username); 05115 break; 05116 case T38_ENABLED: 05117 parameters = p->t38.their_parms; 05118 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 05119 parameters.request_response = AST_T38_NEGOTIATED; 05120 ast_udptl_set_tag(p->udptl, "SIP/%s", p->username); 05121 break; 05122 case T38_DISABLED: 05123 if (old == T38_ENABLED) { 05124 parameters.request_response = AST_T38_TERMINATED; 05125 } else if (old == T38_LOCAL_REINVITE) { 05126 parameters.request_response = AST_T38_REFUSED; 05127 } 05128 break; 05129 case T38_LOCAL_REINVITE: 05130 /* wait until we get a peer response before responding to local reinvite */ 05131 break; 05132 } 05133 05134 /* Woot we got a message, create a control frame and send it on! */ 05135 if (parameters.request_response) 05136 ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters)); 05137 }
| static enum check_auth_result check_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| const char * | username, | |||
| const char * | secret, | |||
| const char * | md5secret, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| int | ignore | |||
| ) | [static] |
Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set).
XXX
XXX
Definition at line 12747 of file chan_sip.c.
References append_history, ast_copy_string(), AST_DYNSTR_BUILD_FAILED, ast_log(), ast_md5_hash(), ast_skip_blanks(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero(), AUTH_CHALLENGE_SENT, auth_headers(), AUTH_SECRET_FAILED, AUTH_SUCCESSFUL, AUTH_USERNAME_MISMATCH, buf, check_auth_buf, CHECK_AUTH_BUF_INITLEN, DEFAULT_TRANS_TIMEOUT, FALSE, get_header(), sip_request::ignore, LOG_NOTICE, LOG_WARNING, sip_pvt::randdata, sip_settings::realm, s, S_OR, set_nonce_randdata(), sip_cfg, sip_methods, sip_scheddestroy(), sip_pvt::stalenonce, strsep(), text, transmit_response_with_auth(), TRUE, and WWW_AUTH.
Referenced by check_peer_ok(), and register_verify().
12750 { 12751 const char *response; 12752 char *reqheader, *respheader; 12753 const char *authtoken; 12754 char a1_hash[256]; 12755 char resp_hash[256]=""; 12756 char *c; 12757 int wrongnonce = FALSE; 12758 int good_response; 12759 const char *usednonce = p->randdata; 12760 struct ast_str *buf; 12761 int res; 12762 12763 /* table of recognised keywords, and their value in the digest */ 12764 enum keys { K_RESP, K_URI, K_USER, K_NONCE, K_LAST }; 12765 struct x { 12766 const char *key; 12767 const char *s; 12768 } *i, keys[] = { 12769 [K_RESP] = { "response=", "" }, 12770 [K_URI] = { "uri=", "" }, 12771 [K_USER] = { "username=", "" }, 12772 [K_NONCE] = { "nonce=", "" }, 12773 [K_LAST] = { NULL, NULL} 12774 }; 12775 12776 /* Always OK if no secret */ 12777 if (ast_strlen_zero(secret) && ast_strlen_zero(md5secret)) 12778 return AUTH_SUCCESSFUL; 12779 12780 /* Always auth with WWW-auth since we're NOT a proxy */ 12781 /* Using proxy-auth in a B2BUA may block proxy authorization in the same transaction */ 12782 response = "401 Unauthorized"; 12783 12784 /* 12785 * Note the apparent swap of arguments below, compared to other 12786 * usages of auth_headers(). 12787 */ 12788 auth_headers(WWW_AUTH, &respheader, &reqheader); 12789 12790 authtoken = get_header(req, reqheader); 12791 if (ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) { 12792 /* This is a retransmitted invite/register/etc, don't reconstruct authentication 12793 information */ 12794 if (!reliable) { 12795 /* Resend message if this was NOT a reliable delivery. Otherwise the 12796 retransmission should get it */ 12797 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 12798 /* Schedule auto destroy in 32 seconds (according to RFC 3261) */ 12799 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12800 } 12801 return AUTH_CHALLENGE_SENT; 12802 } else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) { 12803 /* We have no auth, so issue challenge and request authentication */ 12804 set_nonce_randdata(p, 1); /* Create nonce for challenge */ 12805 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 12806 /* Schedule auto destroy in 32 seconds */ 12807 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12808 return AUTH_CHALLENGE_SENT; 12809 } 12810 12811 /* --- We have auth, so check it */ 12812 12813 /* Whoever came up with the authentication section of SIP can suck my %&#$&* for not putting 12814 an example in the spec of just what it is you're doing a hash on. */ 12815 12816 if (!(buf = ast_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) 12817 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 12818 12819 /* Make a copy of the response and parse it */ 12820 res = ast_str_set(&buf, 0, "%s", authtoken); 12821 12822 if (res == AST_DYNSTR_BUILD_FAILED) 12823 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 12824 12825 c = buf->str; 12826 12827 while(c && *(c = ast_skip_blanks(c)) ) { /* lookup for keys */ 12828 for (i = keys; i->key != NULL; i++) { 12829 const char *separator = ","; /* default */ 12830 12831 if (strncasecmp(c, i->key, strlen(i->key)) != 0) 12832 continue; 12833 /* Found. Skip keyword, take text in quotes or up to the separator. */ 12834 c += strlen(i->key); 12835 if (*c == '"') { /* in quotes. Skip first and look for last */ 12836 c++; 12837 separator = "\""; 12838 } 12839 i->s = c; 12840 strsep(&c, separator); 12841 break; 12842 } 12843 if (i->key == NULL) /* not found, jump after space or comma */ 12844 strsep(&c, " ,"); 12845 } 12846 12847 /* Verify that digest username matches the username we auth as */ 12848 if (strcmp(username, keys[K_USER].s)) { 12849 ast_log(LOG_WARNING, "username mismatch, have <%s>, digest has <%s>\n", 12850 username, keys[K_USER].s); 12851 /* Oops, we're trying something here */ 12852 return AUTH_USERNAME_MISMATCH; 12853 } 12854 12855 /* Verify nonce from request matches our nonce, and the nonce has not already been responded to. 12856 * If this check fails, send 401 with new nonce */ 12857 if (strcasecmp(p->randdata, keys[K_NONCE].s) || p->stalenonce) { /* XXX it was 'n'casecmp ? */ 12858 wrongnonce = TRUE; 12859 usednonce = keys[K_NONCE].s; 12860 } else { 12861 p->stalenonce = 1; /* now, since the nonce has a response, mark it as stale so it can't be sent or responded to again */ 12862 } 12863 12864 if (!ast_strlen_zero(md5secret)) 12865 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 12866 else { 12867 char a1[256]; 12868 snprintf(a1, sizeof(a1), "%s:%s:%s", username, sip_cfg.realm, secret); 12869 ast_md5_hash(a1_hash, a1); 12870 } 12871 12872 /* compute the expected response to compare with what we received */ 12873 { 12874 char a2[256]; 12875 char a2_hash[256]; 12876 char resp[256]; 12877 12878 snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text, 12879 S_OR(keys[K_URI].s, uri)); 12880 ast_md5_hash(a2_hash, a2); 12881 snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash); 12882 ast_md5_hash(resp_hash, resp); 12883 } 12884 12885 good_response = keys[K_RESP].s && 12886 !strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash)); 12887 if (wrongnonce) { 12888 if (good_response) { 12889 if (sipdebug) 12890 ast_log(LOG_NOTICE, "Correct auth, but based on stale nonce received from '%s'\n", get_header(req, "From")); 12891 /* We got working auth token, based on stale nonce . */ 12892 set_nonce_randdata(p, 0); 12893 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, TRUE); 12894 } else { 12895 /* Everything was wrong, so give the device one more try with a new challenge */ 12896 if (!req->ignore) { 12897 if (sipdebug) 12898 ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To")); 12899 set_nonce_randdata(p, 1); 12900 } else { 12901 if (sipdebug) 12902 ast_log(LOG_NOTICE, "Duplicate authentication received from '%s'\n", get_header(req, "To")); 12903 } 12904 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE); 12905 } 12906 12907 /* Schedule auto destroy in 32 seconds */ 12908 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 12909 return AUTH_CHALLENGE_SENT; 12910 } 12911 if (good_response) { 12912 append_history(p, "AuthOK", "Auth challenge successful for %s", username); 12913 return AUTH_SUCCESSFUL; 12914 } 12915 12916 /* Ok, we have a bad username/secret pair */ 12917 /* Tell the UAS not to re-send this authentication data, because 12918 it will continue to fail 12919 */ 12920 12921 return AUTH_SECRET_FAILED; 12922 }
| static enum check_auth_result check_peer_ok | ( | struct sip_pvt * | p, | |
| char * | of, | |||
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| struct sockaddr_in * | sin, | |||
| struct sip_peer ** | authpeer, | |||
| enum xmittype | reliable, | |||
| char * | rpid_num, | |||
| char * | calleridname, | |||
| char * | uri2 | |||
| ) | [static] |
Validate device authentication.
Definition at line 14142 of file chan_sip.c.
References sip_peer::accountcode, accountcode, sip_peer::amaflags, sip_pvt::amaflags, ao2_t_ref, ast_apply_ha(), ast_copy_flags, ast_debug, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_inet_ntoa(), ast_is_shrinkable_phonenumber(), ast_rtp_codec_setpref(), ast_rtp_destroy(), AST_RTP_DTMF, ast_set_flag, ast_shrink_phone_number(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose, AUTH_ACL_FAILED, AUTH_DONT_KNOW, sip_peer::autoframing, sip_pvt::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_pvt::callgroup, sip_pvt::callingpres, sip_peer::callingpres, sip_peer::capability, sip_pvt::capability, sip_peer::chanvars, sip_pvt::chanvars, check_auth(), cid_name, sip_peer::cid_name, cid_num, sip_peer::cid_num, context, sip_peer::context, copy_vars(), sip_request::debug, do_setnat(), FALSE, find_peer(), FINDALLDEVICES, FINDPEERS, FINDUSERS, sip_peer::flags, sip_pvt::flags, sip_peer::fullcontact, sip_peer::ha, sip_request::ignore, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, sip_peer::language, language, sip_peer::lastms, sip_peer::maxcallbitrate, sip_pvt::maxcallbitrate, sip_peer::maxms, sip_peer::md5secret, sip_peer::mohinterpret, mohinterpret, sip_peer::mohsuggest, mohsuggest, sip_peer::name, sip_pvt::noncodeccapability, sip_peer::parkinglot, parkinglot, sip_pvt::peercapability, sip_pvt::peermd5secret, sip_pvt::peersecret, sip_peer::pickupgroup, sip_pvt::pickupgroup, sip_pvt::prefs, sip_peer::prefs, sip_pvt::recv, replace_cid(), sip_pvt::rtp, sip_peer::secret, set_t38_capabilities(), SIP_CALL_LIMIT, sip_debug_test_addr(), SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, SIP_INSECURE_INVITE, SIP_INVITE, SIP_NAT_ROUTE, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, SIP_SUBSCRIBE, sip_peer::sipoptions, sip_pvt::sipoptions, sip_pvt::socket, sip_peer::subscribecontext, sip_peer::t38_maxdatagram, sip_pvt::t38_maxdatagram, sip_pvt::timer_b, sip_peer::timer_b, sip_peer::timer_t1, sip_pvt::timer_t1, sip_pvt::trtp, TRUE, sip_socket::type, sip_pvt::udptl, unref_peer(), sip_peer::username, and sip_pvt::vrtp.
Referenced by check_user_full().
14147 { 14148 enum check_auth_result res; 14149 int debug=sip_debug_test_addr(sin); 14150 struct sip_peer *peer; 14151 14152 if (sipmethod == SIP_SUBSCRIBE) { 14153 /* For subscribes, match on device name only; for other methods, 14154 * match on IP address-port of the incoming request. 14155 */ 14156 peer = find_peer(of, NULL, TRUE, FINDALLDEVICES, FALSE, 0); 14157 } else { 14158 /* First find devices based on username (avoid all type=peer's) */ 14159 peer = find_peer(of, NULL, TRUE, FINDUSERS, FALSE, 0); 14160 14161 /* Then find devices based on IP */ 14162 if (!peer) { 14163 peer = find_peer(NULL, &p->recv, TRUE, FINDPEERS, FALSE, p->socket.type); 14164 } 14165 } 14166 14167 if (!peer) { 14168 if (debug) 14169 ast_verbose("No matching peer for '%s' from '%s:%d'\n", 14170 of, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 14171 return AUTH_DONT_KNOW; 14172 } 14173 if (!ast_apply_ha(peer->ha, sin)) { 14174 ast_debug(2, "Found peer '%s' for '%s', but fails host access\n", peer->name, of); 14175 unref_peer(peer, "unref_peer: check_peer_ok: from find_peer call, early return of AUTH_ACL_FAILED"); 14176 return AUTH_ACL_FAILED; 14177 } 14178 if (debug) 14179 ast_verbose("Found peer '%s' for '%s' from %s:%d\n", 14180 peer->name, of, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 14181 14182 /* XXX what about p->prefs = peer->prefs; ? */ 14183 /* Set Frame packetization */ 14184 if (p->rtp) { 14185 ast_rtp_codec_setpref(p->rtp, &peer->prefs); 14186 p->autoframing = peer->autoframing; 14187 } 14188 14189 /* Take the peer */ 14190 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 14191 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 14192 14193 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && p->udptl) { 14194 p->t38_maxdatagram = peer->t38_maxdatagram; 14195 set_t38_capabilities(p); 14196 } 14197 14198 /* Copy SIP extensions profile to peer */ 14199 /* XXX is this correct before a successful auth ? */ 14200 if (p->sipoptions) 14201 peer->sipoptions = p->sipoptions; 14202 14203 replace_cid(p, rpid_num, calleridname); 14204 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT_ROUTE)); 14205 14206 ast_string_field_set(p, peersecret, peer->secret); 14207 ast_string_field_set(p, peermd5secret, peer->md5secret); 14208 ast_string_field_set(p, subscribecontext, peer->subscribecontext); 14209 ast_string_field_set(p, mohinterpret, peer->mohinterpret); 14210 ast_string_field_set(p, mohsuggest, peer->mohsuggest); 14211 ast_string_field_set(p, parkinglot, peer->parkinglot); 14212 if (peer->callingpres) /* Peer calling pres setting will override RPID */ 14213 p->callingpres = peer->callingpres; 14214 if (peer->maxms && peer->lastms) 14215 p->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 14216 else 14217 p->timer_t1 = peer->timer_t1; 14218 14219 /* Set timer B to control transaction timeouts */ 14220 if (peer->timer_b) 14221 p->timer_b = peer->timer_b; 14222 else 14223 p->timer_b = 64 * p->timer_t1; 14224 14225 if (ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE)) { 14226 /* Pretend there is no required authentication */ 14227 ast_string_field_set(p, peersecret, NULL); 14228 ast_string_field_set(p, peermd5secret, NULL); 14229 } 14230 if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req->ignore))) { 14231 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 14232 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 14233 /* If we have a call limit, set flag */ 14234 if (peer->call_limit) 14235 ast_set_flag(&p->flags[0], SIP_CALL_LIMIT); 14236 ast_string_field_set(p, peername, peer->name); 14237 ast_string_field_set(p, authname, peer->name); 14238 14239 if (sipmethod == SIP_INVITE) { 14240 /* copy channel vars */ 14241 p->chanvars = copy_vars(peer->chanvars); 14242 } 14243 14244 if (authpeer) { 14245 ao2_t_ref(peer, 1, "copy pointer into (*authpeer)"); 14246 (*authpeer) = peer; /* Add a ref to the object here, to keep it in memory a bit longer if it is realtime */ 14247 } 14248 14249 if (!ast_strlen_zero(peer->username)) { 14250 ast_string_field_set(p, username, peer->username); 14251 /* Use the default username for authentication on outbound calls */ 14252 /* XXX this takes the name from the caller... can we override ? */ 14253 ast_string_field_set(p, authname, peer->username); 14254 } 14255 if (!ast_strlen_zero(peer->cid_num)) { 14256 char *tmp = ast_strdupa(peer->cid_num); 14257 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) 14258 ast_shrink_phone_number(tmp); 14259 ast_string_field_set(p, cid_num, tmp); 14260 } 14261 if (!ast_strlen_zero(peer->cid_name)) 14262 ast_string_field_set(p, cid_name, peer->cid_name); 14263 ast_string_field_set(p, fullcontact, peer->fullcontact); 14264 if (!ast_strlen_zero(peer->context)) 14265 ast_string_field_set(p, context, peer->context); 14266 ast_string_field_set(p, peersecret, peer->secret); 14267 ast_string_field_set(p, peermd5secret, peer->md5secret); 14268 ast_string_field_set(p, language, peer->language); 14269 ast_string_field_set(p, accountcode, peer->accountcode); 14270 p->amaflags = peer->amaflags; 14271 p->callgroup = peer->callgroup; 14272 p->pickupgroup = peer->pickupgroup; 14273 p->capability = peer->capability; 14274 p->prefs = peer->prefs; 14275 p->jointcapability = peer->capability; 14276 if (p->peercapability) 14277 p->jointcapability &= p->peercapability; 14278 p->maxcallbitrate = peer->maxcallbitrate; 14279 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) && 14280 (!ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) || 14281 !(p->capability & AST_FORMAT_VIDEO_MASK)) && 14282 p->vrtp) { 14283 ast_rtp_destroy(p->vrtp); 14284 p->vrtp = NULL; 14285 } 14286 if ((!ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) || !(p->capability & AST_FORMAT_TEXT_MASK)) && p->trtp) { 14287 ast_rtp_destroy(p->trtp); 14288 p->trtp = NULL; 14289 } 14290 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 14291 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 14292 p->noncodeccapability |= AST_RTP_DTMF; 14293 else 14294 p->noncodeccapability &= ~AST_RTP_DTMF; 14295 p->jointnoncodeccapability = p->noncodeccapability; 14296 } 14297 unref_peer(peer, "check_peer_ok: unref_peer: tossing temp ptr to peer from find_peer"); 14298 return res; 14299 }
| static void check_pendings | ( | struct sip_pvt * | p | ) | [static] |
Check pending actions on SIP call.
Definition at line 17736 of file chan_sip.c.
References ast_clear_flag, ast_debug, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), ast_test_flag, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, FALSE, sip_pvt::flags, INV_CALLING, INV_CANCELLED, INV_EARLY_MEDIA, INV_PROCEEDING, sip_pvt::invitestate, sip_pvt::lastinvite, sip_pvt::owner, sip_pvt::pendinginvite, SIP_BYE, SIP_CANCEL, SIP_NEEDREINVITE, SIP_PENDINGBYE, sip_scheddestroy(), t38properties::state, sip_pvt::t38, T38_LOCAL_REINVITE, transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), TRUE, sip_pvt::waitid, and XMIT_RELIABLE.
Referenced by handle_incoming(), handle_response_invite(), and sip_reinvite_retry().
17737 { 17738 if (ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 17739 /* if we can't BYE, then this is really a pending CANCEL */ 17740 if (p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA) { 17741 p->invitestate = INV_CANCELLED; 17742 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 17743 /* Actually don't destroy us yet, wait for the 487 on our original 17744 INVITE, but do set an autodestruct just in case we never get it. */ 17745 } else { 17746 /* We have a pending outbound invite, don't send something 17747 new in-transaction */ 17748 if (p->pendinginvite) 17749 return; 17750 17751 if (p->owner) { 17752 ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV); 17753 } 17754 /* Perhaps there is an SD change INVITE outstanding */ 17755 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE); 17756 } 17757 ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); 17758 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 17759 } else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) { 17760 /* if we can't REINVITE, hold it for later */ 17761 if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) { 17762 ast_debug(2, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid); 17763 } else { 17764 ast_debug(2, "Sending pending reinvite on '%s'\n", p->callid); 17765 /* Didn't get to reinvite yet, so do it now */ 17766 transmit_reinvite_with_sdp(p, (p->t38.state == T38_LOCAL_REINVITE ? TRUE : FALSE), FALSE); 17767 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 17768 } 17769 } 17770 }
| static void check_rtp_timeout | ( | struct sip_pvt * | dialog, | |
| time_t | t | |||
| ) | [static] |
helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked
Definition at line 22590 of file chan_sip.c.
References ast_channel::_state, ast_channel_trylock, ast_channel_unlock, ast_log(), ast_rtp_get_peer(), ast_rtp_get_rtpholdtimeout(), ast_rtp_get_rtpkeepalive(), ast_rtp_get_rtptimeout(), ast_rtp_sendcng(), ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtptimeout(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, ast_test_flag, sip_pvt::flags, sip_pvt::lastrtprx, sip_pvt::lastrtptx, LOG_NOTICE, ast_channel::name, sip_pvt::owner, sip_pvt::redirip, sip_pvt::rtp, SIP_PAGE2_CALL_ONHOLD, sip_pvt_lock, sip_pvt_unlock, t38properties::state, sip_pvt::t38, T38_ENABLED, and sip_pvt::vrtp.
Referenced by dialog_needdestroy().
22591 { 22592 /* If we have no RTP or no active owner, no need to check timers */ 22593 if (!dialog->rtp || !dialog->owner) 22594 return; 22595 /* If the call is not in UP state or redirected outside Asterisk, no need to check timers */ 22596 22597 if (dialog->owner->_state != AST_STATE_UP || dialog->redirip.sin_addr.s_addr) 22598 return; 22599 22600 /* If the call is involved in a T38 fax session do not check RTP timeout */ 22601 if (dialog->t38.state == T38_ENABLED) 22602 return; 22603 22604 /* If we have no timers set, return now */ 22605 if ((ast_rtp_get_rtpkeepalive(dialog->rtp) == 0) && (ast_rtp_get_rtptimeout(dialog->rtp) == 0) && (ast_rtp_get_rtpholdtimeout(dialog->rtp) == 0)) 22606 return; 22607 22608 /* Check AUDIO RTP keepalives */ 22609 if (dialog->lastrtptx && ast_rtp_get_rtpkeepalive(dialog->rtp) && 22610 (t > dialog->lastrtptx + ast_rtp_get_rtpkeepalive(dialog->rtp))) { 22611 /* Need to send an empty RTP packet */ 22612 dialog->lastrtptx = time(NULL); 22613 ast_rtp_sendcng(dialog->rtp, 0); 22614 } 22615 22616 /*! \todo Check video RTP keepalives 22617 22618 Do we need to move the lastrtptx to the RTP structure to have one for audio and one 22619 for video? It really does belong to the RTP structure. 22620 */ 22621 22622 /* Check AUDIO RTP timers */ 22623 if (dialog->lastrtprx && (ast_rtp_get_rtptimeout(dialog->rtp) || ast_rtp_get_rtpholdtimeout(dialog->rtp)) && 22624 (t > dialog->lastrtprx + ast_rtp_get_rtptimeout(dialog->rtp))) { 22625 22626 /* Might be a timeout now -- see if we're on hold */ 22627 struct sockaddr_in sin; 22628 ast_rtp_get_peer(dialog->rtp, &sin); 22629 if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (ast_rtp_get_rtpholdtimeout(dialog->rtp) && 22630 (t > dialog->lastrtprx + ast_rtp_get_rtpholdtimeout(dialog->rtp)))) { 22631 /* Needs a hangup */ 22632 if (ast_rtp_get_rtptimeout(dialog->rtp)) { 22633 while (dialog->owner && ast_channel_trylock(dialog->owner)) { 22634 sip_pvt_unlock(dialog); 22635 usleep(1); 22636 sip_pvt_lock(dialog); 22637 } 22638 if (!dialog->owner) { 22639 return; /* channel hangup can occur during deadlock avoidance. */ 22640 } 22641 ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", 22642 dialog->owner->name, (long) (t - dialog->lastrtprx)); 22643 /* Issue a softhangup */ 22644 ast_softhangup_nolock(dialog->owner, AST_SOFTHANGUP_DEV); 22645 ast_channel_unlock(dialog->owner); 22646 /* forget the timeouts for this call, since a hangup 22647 has already been requested and we don't want to 22648 repeatedly request hangups 22649 */ 22650 ast_rtp_set_rtptimeout(dialog->rtp, 0); 22651 ast_rtp_set_rtpholdtimeout(dialog->rtp, 0); 22652 if (dialog->vrtp) { 22653 ast_rtp_set_rtptimeout(dialog->vrtp, 0); 22654 ast_rtp_set_rtpholdtimeout(dialog->vrtp, 0); 22655 } 22656 } 22657 } 22658 } 22659 }
| static int check_sip_domain | ( | const char * | domain, | |
| char * | context, | |||
| size_t | len | |||
| ) | [static] |
check_sip_domain: Check if domain part of uri is local to our server
Definition at line 23719 of file chan_sip.c.
References ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, ast_strlen_zero(), domain::context, and domain::domain.
Referenced by func_check_sipdomain(), get_destination(), handle_request_refer(), and register_verify().
23720 { 23721 struct domain *d; 23722 int result = 0; 23723 23724 AST_LIST_LOCK(&domain_list); 23725 AST_LIST_TRAVERSE(&domain_list, d, list) { 23726 if (strcasecmp(d->domain, domain)) 23727 continue; 23728 23729 if (len && !ast_strlen_zero(d->context)) 23730 ast_copy_string(context, d->context, len); 23731 23732 result = 1; 23733 break; 23734 } 23735 AST_LIST_UNLOCK(&domain_list); 23736 23737 return result; 23738 }
| static int check_user | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| struct sockaddr_in * | sin | |||
| ) | [static] |
Find user If we get a match, this will add a reference pointer to the user object in ASTOBJ, that needs to be unreferenced.
Definition at line 14423 of file chan_sip.c.
References check_user_full().
Referenced by handle_request_invite().
14424 { 14425 return check_user_full(p, req, sipmethod, uri, reliable, sin, NULL); 14426 }
| static enum check_auth_result check_user_full | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| char * | uri, | |||
| enum xmittype | reliable, | |||
| struct sockaddr_in * | sin, | |||
| struct sip_peer ** | authpeer | |||
| ) | [static] |
Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests.
Definition at line 14307 of file chan_sip.c.
References sip_settings::allowguest, sip_settings::alwaysauthreject, ast_copy_string(), ast_is_shrinkable_phonenumber(), ast_log(), ast_set_flag, ast_shrink_phone_number(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), AUTH_DONT_KNOW, AUTH_FAKE_AUTH, AUTH_SECRET_FAILED, AUTH_SUCCESSFUL, build_contact(), sip_pvt::callingpres, check_peer_ok(), cid_name, cid_num, dummy(), exten, sip_pvt::exten, sip_pvt::flags, get_calleridname(), get_header(), get_in_brackets(), get_rpid_num(), LOG_NOTICE, sip_pvt::our_contact, parse_uri(), sip_settings::pedanticsipchecking, replace_cid(), sip_cfg, SIP_NAT_ROUTE, SIP_PAGE2_RPORT_PRESENT, strsep(), and terminate_uri().
Referenced by check_user(), and handle_request_subscribe().
14310 { 14311 char from[256]; 14312 char *dummy; /* dummy return value for parse_uri */ 14313 char *domain; /* dummy return value for parse_uri */ 14314 char *of; 14315 char rpid_num[50]; 14316 const char *rpid; 14317 enum check_auth_result res; 14318 char calleridname[50]; 14319 char *uri2 = ast_strdupa(uri); 14320 14321 terminate_uri(uri2); /* trim extra stuff */ 14322 14323 ast_copy_string(from, get_header(req, "From"), sizeof(from)); 14324 if (sip_cfg.pedanticsipchecking) 14325 ast_uri_decode(from); 14326 /* XXX here tries to map the username for invite things */ 14327 memset(calleridname, 0, sizeof(calleridname)); 14328 get_calleridname(from, calleridname, sizeof(calleridname)); 14329 if (calleridname[0]) 14330 ast_string_field_set(p, cid_name, calleridname); 14331 14332 rpid = get_header(req, "Remote-Party-ID"); 14333 memset(rpid_num, 0, sizeof(rpid_num)); 14334 if (!ast_strlen_zero(rpid)) 14335 p->callingpres = get_rpid_num(rpid, rpid_num, sizeof(rpid_num)); 14336 14337 of = get_in_brackets(from); 14338 if (ast_strlen_zero(p->exten)) { 14339 char *t = uri2; 14340 if (!strncasecmp(t, "sip:", 4)) 14341 t+= 4; 14342 else if (!strncasecmp(t, "sips:", 5)) 14343 t += 5; 14344 ast_string_field_set(p, exten, t); 14345 t = strchr(p->exten, '@'); 14346 if (t) 14347 *t = '\0'; 14348 if (ast_strlen_zero(p->our_contact)) 14349 build_contact(p); 14350 } 14351 /* save the URI part of the From header */ 14352 ast_string_field_set(p, from, of); 14353 14354 /* ignore all fields but name */ 14355 if (parse_uri(of, "sip:,sips:", &of, &dummy, &domain, &dummy, &dummy, NULL)) { 14356 ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); 14357 } 14358 14359 if (ast_strlen_zero(of)) { 14360 /* XXX note: the original code considered a missing @host 14361 * as a username-only URI. The SIP RFC (19.1.1) says that 14362 * this is wrong, and it should be considered as a domain-only URI. 14363 * For backward compatibility, we keep this block, but it is 14364 * really a mistake and should go away. 14365 */ 14366 of = domain; 14367 } else { 14368 char *tmp = ast_strdupa(of); 14369 /* We need to be able to handle auth-headers looking like 14370 <sip:8164444422;phone-context=+1@1.2.3.4:5060;user=phone;tag=SDadkoa01-gK0c3bdb43> 14371 */ 14372 tmp = strsep(&tmp, ";"); 14373 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) 14374 ast_shrink_phone_number(tmp); 14375 ast_string_field_set(p, cid_num, tmp); 14376 } 14377 14378 if (global_match_auth_username) { 14379 /* 14380 * XXX This is experimental code to grab the search key from the 14381 * Auth header's username instead of the 'From' name, if available. 14382 * Do not enable this block unless you understand the side effects (if any!) 14383 * Note, the search for "username" should be done in a more robust way. 14384 * Note2, at the moment we check both fields, though maybe we should 14385 * pick one or another depending on the request ? XXX 14386 */ 14387 const char *hdr = get_header(req, "Authorization"); 14388 if (ast_strlen_zero(hdr)) 14389 hdr = get_header(req, "Proxy-Authorization"); 14390 14391 if ( !ast_strlen_zero(hdr) && (hdr = strstr(hdr, "username=\"")) ) { 14392 ast_copy_string(from, hdr + strlen("username=\""), sizeof(from)); 14393 of = from; 14394 of = strsep(&of, "\""); 14395 } 14396 } 14397 14398 res = check_peer_ok(p, of, req, sipmethod, sin, 14399 authpeer, reliable, rpid_num, calleridname, uri2); 14400 if (res != AUTH_DONT_KNOW) 14401 return res; 14402 14403 /* Finally, apply the guest policy */ 14404 if (sip_cfg.allowguest) { 14405 replace_cid(p, rpid_num, calleridname); 14406 res = AUTH_SUCCESSFUL; 14407 } else if (sip_cfg.alwaysauthreject) 14408 res = AUTH_FAKE_AUTH; /* reject with fake authorization request */ 14409 else 14410 res = AUTH_SECRET_FAILED; /* we don't want any guests, authentication will fail */ 14411 14412 14413 if (ast_test_flag(&p->flags[1], SIP_PAGE2_RPORT_PRESENT)) { 14414 ast_set_flag(&p->flags[0], SIP_NAT_ROUTE); 14415 } 14416 14417 return res; 14418 }
| static void check_via | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
check Via: header for hostname, port and rport request/answer
Definition at line 13989 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_set_flag, ast_skip_blanks(), ast_verbose, sip_pvt::flags, get_header(), hp, LOG_WARNING, port_str2int(), sip_pvt::sa, sip_debug_test_pvt(), sip_nat_mode(), SIP_PAGE2_RPORT_PRESENT, sip_real_dst(), and STANDARD_SIP_PORT.
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_register(), and handle_request_subscribe().
13990 { 13991 char via[512]; 13992 char *c, *pt, *maddr; 13993 struct hostent *hp; 13994 struct ast_hostent ahp; 13995 13996 ast_copy_string(via, get_header(req, "Via"), sizeof(via)); 13997 13998 /* Work on the leftmost value of the topmost Via header */ 13999 c = strchr(via, ','); 14000 if (c) 14001 *c = '\0'; 14002 14003 /* Check for rport */ 14004 c = strstr(via, ";rport"); 14005 if (c && (c[6] != '=')) /* rport query, not answer */ 14006 ast_set_flag(&p->flags[1], SIP_PAGE2_RPORT_PRESENT); 14007 14008 /* Check for maddr */ 14009 maddr = strstr(via, "maddr="); 14010 if (maddr) { 14011 maddr += 6; 14012 c = maddr + strspn(maddr, "0123456789."); 14013 *c = '\0'; 14014 } 14015 14016 c = strchr(via, ';'); 14017 if (c) 14018 *c = '\0'; 14019 14020 c = strchr(via, ' '); 14021 if (c) { 14022 *c = '\0'; 14023 c = ast_skip_blanks(c+1); 14024 if (strcasecmp(via, "SIP/2.0/UDP") && strcasecmp(via, "SIP/2.0/TCP") && strcasecmp(via, "SIP/2.0/TLS")) { 14025 ast_log(LOG_WARNING, "Don't know how to respond via '%s'\n", via); 14026 return; 14027 } 14028 pt = strchr(c, ':'); 14029 if (pt) 14030 *pt++ = '\0'; /* remember port pointer */ 14031 /* Use maddr if found */ 14032 if (maddr) 14033 c = maddr; 14034 hp = ast_gethostbyname(c, &ahp); 14035 if (!hp) { 14036 ast_log(LOG_WARNING, "'%s' is not a valid host\n", c); 14037 return; 14038 } 14039 memset(&p->sa, 0, sizeof(p->sa)); 14040 p->sa.sin_family = AF_INET; 14041 memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); 14042 p->sa.sin_port = htons(port_str2int(pt, STANDARD_SIP_PORT)); 14043 14044 if (sip_debug_test_pvt(p)) { 14045 const struct sockaddr_in *dst = sip_real_dst(p); 14046 ast_verbose("Sending to %s : %d (%s)\n", ast_inet_ntoa(dst->sin_addr), ntohs(dst->sin_port), sip_nat_mode(p)); 14047 } 14048 } 14049 }
| static attribute_unused void check_via_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
check received= and rport= in a SIP response. If we get a response with received= and/or rport= in the Via: line, use them as 'p->ourip' (see RFC 3581 for rport, and RFC 3261 for received). Using these two fields SIP can produce the correct address and port in the SIP headers without the need for STUN. The address part is also reused for the media sessions. Note that ast_sip_ouraddrfor() still rewrites p->ourip if you specify externip/seternaddr/stunaddr.
Definition at line 13959 of file chan_sip.c.
References ast_copy_string(), ast_parse_arg(), get_header(), sip_pvt::ourip, PARSE_INADDR, and strsep().
13960 { 13961 char via[256]; 13962 char *cur, *opts; 13963 13964 ast_copy_string(via, get_header(req, "Via"), sizeof(via)); 13965 13966 /* Work on the leftmost value of the topmost Via header */ 13967 opts = strchr(via, ','); 13968 if (opts) 13969 *opts = '\0'; 13970 13971 /* parse all relevant options */ 13972 opts = strchr(via, ';'); 13973 if (!opts) 13974 return; /* no options to parse */ 13975 *opts++ = '\0'; 13976 while ( (cur = strsep(&opts, ";")) ) { 13977 if (!strncmp(cur, "rport=", 6)) { 13978 int port = strtol(cur+6, NULL, 10); 13979 /* XXX add error checking */ 13980 p->ourip.sin_port = ntohs(port); 13981 } else if (!strncmp(cur, "received=", 9)) { 13982 if (ast_parse_arg(cur+9, PARSE_INADDR, &p->ourip)) 13983 ; /* XXX add error checking */ 13984 } 13985 } 13986 }
| static void cleanup_stale_contexts | ( | char * | new, | |
| char * | old | |||
| ) | [static] |
Destroy disused contexts between reloads Only used in reload_config so the code for regcontext doesn't get ugly.
Definition at line 15152 of file chan_sip.c.
References ast_context_destroy(), ast_context_find(), ast_copy_string(), AST_MAX_CONTEXT, and strsep().
Referenced by reload_config().
15153 { 15154 char *oldcontext, *newcontext, *stalecontext, *stringp, newlist[AST_MAX_CONTEXT]; 15155 15156 while ((oldcontext = strsep(&old, "&"))) { 15157 stalecontext = '\0'; 15158 ast_copy_string(newlist, new, sizeof(newlist)); 15159 stringp = newlist; 15160 while ((newcontext = strsep(&stringp, "&"))) { 15161 if (!strcmp(newcontext, oldcontext)) { 15162 /* This is not the context you're looking for */ 15163 stalecontext = '\0'; 15164 break; 15165 } else if (strcmp(newcontext, oldcontext)) { 15166 stalecontext = oldcontext; 15167 } 15168 15169 } 15170 if (stalecontext) 15171 ast_context_destroy(ast_context_find(stalecontext), "SIP"); 15172 } 15173 }
| static void clear_peer_mailboxes | ( | struct sip_peer * | peer | ) | [static] |
Destroy all peer-related mailbox subscriptions
Definition at line 4699 of file chan_sip.c.
References AST_LIST_REMOVE_HEAD, destroy_mailbox(), mailbox, and sip_peer::mailboxes.
Referenced by set_peer_defaults(), and sip_destroy_peer().
04700 { 04701 struct sip_mailbox *mailbox; 04702 04703 while ((mailbox = AST_LIST_REMOVE_HEAD(&peer->mailboxes, entry))) 04704 destroy_mailbox(mailbox); 04705 }
| static int clear_realm_authentication | ( | struct sip_auth * | authlist | ) | [static] |
Clear realm authentication list (at reload).
Definition at line 23808 of file chan_sip.c.
References ast_free, and sip_auth::next.
Referenced by build_peer(), reload_config(), sip_destroy_peer(), and unload_module().
23809 { 23810 struct sip_auth *a = authlist; 23811 struct sip_auth *b; 23812 23813 while (a) { 23814 b = a; 23815 a = a->next; 23816 ast_free(b); 23817 } 23818 23819 return 1; 23820 }
| static void clear_sip_domains | ( | void | ) | [static] |
Clear our domain list (at reload).
Definition at line 23741 of file chan_sip.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, and AST_LIST_UNLOCK.
Referenced by reload_config(), and unload_module().
23742 { 23743 struct domain *d; 23744 23745 AST_LIST_LOCK(&domain_list); 23746 while ((d = AST_LIST_REMOVE_HEAD(&domain_list, list))) 23747 ast_free(d); 23748 AST_LIST_UNLOCK(&domain_list); 23749 }
| static const char* cli_yesno | ( | int | x | ) | [static] |
return Yes or No depending on the argument. This is used in many places in CLI command, having a function to generate this helps maintaining a consistent output (and possibly emitting the output in other languages, at some point).
Definition at line 14663 of file chan_sip.c.
Referenced by _sip_show_peer(), show_channels_cb(), sip_show_channel(), sip_show_settings(), sip_show_user(), and sip_show_users().
| static char * complete_sip_peer | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on peer name.
Definition at line 16518 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, ast_test_flag, sip_peer::flags, sip_peer::name, and unref_peer().
Referenced by complete_sip_show_peer(), complete_sipnotify(), sip_do_debug(), and sip_prune_realtime().
16519 { 16520 char *result = NULL; 16521 int wordlen = strlen(word); 16522 int which = 0; 16523 struct ao2_iterator i = ao2_iterator_init(peers, 0); 16524 struct sip_peer *peer; 16525 16526 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 16527 /* locking of the object is not required because only the name and flags are being compared */ 16528 if (!strncasecmp(word, peer->name, wordlen) && 16529 (!flags2 || ast_test_flag(&peer->flags[1], flags2)) && 16530 ++which > state) 16531 result = ast_strdup(peer->name); 16532 unref_peer(peer, "toss iterator peer ptr before break"); 16533 if (result) { 16534 break; 16535 } 16536 } 16537 ao2_iterator_destroy(&i); 16538 return result; 16539 }
| static char * complete_sip_registered_peer | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on registered peer name.
Definition at line 16542 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, ast_test_flag, sip_peer::expire, sip_peer::flags, sip_peer::name, and unref_peer().
Referenced by complete_sip_unregister().
16543 { 16544 char *result = NULL; 16545 int wordlen = strlen(word); 16546 int which = 0; 16547 struct ao2_iterator i; 16548 struct sip_peer *peer; 16549 16550 i = ao2_iterator_init(peers, 0); 16551 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 16552 if (!strncasecmp(word, peer->name, wordlen) && 16553 (!flags2 || ast_test_flag(&peer->flags[1], flags2)) && 16554 ++which > state && peer->expire > 0) 16555 result = ast_strdup(peer->name); 16556 if (result) { 16557 unref_peer(peer, "toss iterator peer ptr before break"); 16558 break; 16559 } 16560 unref_peer(peer, "toss iterator peer ptr"); 16561 } 16562 ao2_iterator_destroy(&i); 16563 return result; 16564 }
| static char * complete_sip_show_history | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show history' CLI.
Definition at line 16567 of file chan_sip.c.
References complete_sipch().
Referenced by sip_show_history().
16568 { 16569 if (pos == 3) 16570 return complete_sipch(line, word, pos, state); 16571 16572 return NULL; 16573 }
| static char * complete_sip_show_peer | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show peer' CLI.
Definition at line 16576 of file chan_sip.c.
References complete_sip_peer().
Referenced by sip_qualify_peer(), and sip_show_peer().
16577 { 16578 if (pos == 3) { 16579 return complete_sip_peer(word, state, 0); 16580 } 16581 16582 return NULL; 16583 }
| static char* complete_sip_show_user | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show user' CLI.
Definition at line 15832 of file chan_sip.c.
References complete_sip_user().
Referenced by sip_show_user().
15833 { 15834 if (pos == 3) 15835 return complete_sip_user(word, state); 15836 15837 return NULL; 15838 }
| static char * complete_sip_unregister | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip unregister' CLI.
Definition at line 16586 of file chan_sip.c.
References complete_sip_registered_peer().
Referenced by sip_unregister().
16587 { 16588 if (pos == 2) 16589 return complete_sip_registered_peer(word, state, 0); 16590 16591 return NULL; 16592 }
| static char* complete_sip_user | ( | const char * | word, | |
| int | state | |||
| ) | [static] |
Do completion on user name.
Definition at line 15805 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock(), ao2_unlock(), ast_strdup, sip_peer::name, SIP_TYPE_USER, sip_peer::type, and unref_peer().
Referenced by complete_sip_show_user().
15806 { 15807 char *result = NULL; 15808 int wordlen = strlen(word); 15809 int which = 0; 15810 struct ao2_iterator user_iter; 15811 struct sip_peer *user; 15812 15813 user_iter = ao2_iterator_init(peers, 0); 15814 while ((user = ao2_iterator_next(&user_iter))) { 15815 ao2_lock(user); 15816 if (!(user->type & SIP_TYPE_USER)) { 15817 ao2_unlock(user); 15818 unref_peer(user, "complete sip user"); 15819 continue; 15820 } 15821 /* locking of the object is not required because only the name and flags are being compared */ 15822 if (!strncasecmp(word, user->name, wordlen) && ++which > state) { 15823 result = ast_strdup(user->name); 15824 } 15825 ao2_unlock(user); 15826 unref_peer(user, "complete sip user"); 15827 } 15828 ao2_iterator_destroy(&user_iter); 15829 return result; 15830 }
| static char* complete_sipch | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show channel' and 'sip show history' CLI This is in charge of generating all strings that match a prefix in the given position. As many functions of this kind, each invokation has O(state) time complexity so be careful in using it.
Definition at line 16488 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, sip_pvt::callid, dialog_unref(), sip_pvt_lock, and sip_pvt_unlock.
Referenced by complete_sip_show_history(), and sip_show_channel().
16489 { 16490 int which=0; 16491 struct sip_pvt *cur; 16492 char *c = NULL; 16493 int wordlen = strlen(word); 16494 struct ao2_iterator i; 16495 16496 if (pos != 3) { 16497 return NULL; 16498 } 16499 16500 i = ao2_iterator_init(dialogs, 0); 16501 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 16502 sip_pvt_lock(cur); 16503 if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) { 16504 c = ast_strdup(cur->callid); 16505 sip_pvt_unlock(cur); 16506 dialog_unref(cur, "drop ref in iterator loop break"); 16507 break; 16508 } 16509 sip_pvt_unlock(cur); 16510 dialog_unref(cur, "drop ref in iterator loop"); 16511 } 16512 ao2_iterator_destroy(&i); 16513 return c; 16514 }
| static char * complete_sipnotify | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip notify' CLI.
Definition at line 16595 of file chan_sip.c.
References ast_category_browse(), ast_strdup, and complete_sip_peer().
Referenced by sip_cli_notify().
16596 { 16597 char *c = NULL; 16598 16599 if (pos == 2) { 16600 int which = 0; 16601 char *cat = NULL; 16602 int wordlen = strlen(word); 16603 16604 /* do completion for notify type */ 16605 16606 if (!notify_types) 16607 return NULL; 16608 16609 while ( (cat = ast_category_browse(notify_types, cat)) ) { 16610 if (!strncasecmp(word, cat, wordlen) && ++which > state) { 16611 c = ast_strdup(cat); 16612 break; 16613 } 16614 } 16615 return c; 16616 } 16617 16618 if (pos > 2) 16619 return complete_sip_peer(word, state, 0); 16620 16621 return NULL; 16622 }
| static int copy_all_header | ( | struct sip_request * | req, | |
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy all headers from one request to another.
Definition at line 9234 of file chan_sip.c.
References __get_header(), add_header(), and ast_strlen_zero().
Referenced by respprep().
09235 { 09236 int start = 0; 09237 int copied = 0; 09238 for (;;) { 09239 const char *tmp = __get_header(orig, field, &start); 09240 09241 if (ast_strlen_zero(tmp)) 09242 break; 09243 /* Add what we're responding to */ 09244 add_header(req, field, tmp); 09245 copied++; 09246 } 09247 return copied ? 0 : -1; 09248 }
| static int copy_header | ( | struct sip_request * | req, | |
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy one header field from one request to another.
Definition at line 9223 of file chan_sip.c.
References add_header(), ast_log(), ast_strlen_zero(), get_header(), and LOG_NOTICE.
Referenced by reqprep(), and respprep().
09224 { 09225 const char *tmp = get_header(orig, field); 09226 09227 if (!ast_strlen_zero(tmp)) /* Add what we're responding to */ 09228 return add_header(req, field, tmp); 09229 ast_log(LOG_NOTICE, "No field '%s' present to copy\n", field); 09230 return -1; 09231 }
| static void copy_request | ( | struct sip_request * | dst, | |
| const struct sip_request * | src | |||
| ) | [static] |
copy SIP request (mostly used to save request for responses)
Definition at line 10553 of file chan_sip.c.
References ast_str_copy_string(), ast_str_create(), ast_str_strlen(), sip_request::content, and sip_request::data.
Referenced by _sip_tcp_helper_thread(), handle_request_bye(), handle_request_invite(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), initialize_initreq(), parse_copy(), queue_request(), sip_park(), and sip_park_thread().
10554 { 10555 /* XXX this function can encounter memory allocation errors, perhaps it 10556 * should return a value */ 10557 10558 struct ast_str *duplicate = dst->data; 10559 struct ast_str *duplicate_content = dst->content; 10560 10561 /* copy the entire request then restore the original data and content 10562 * members from the dst request */ 10563 memcpy(dst, src, sizeof(*dst)); 10564 dst->data = duplicate; 10565 dst->content = duplicate_content; 10566 10567 /* copy the data into the dst request */ 10568 if (!dst->data && !(dst->data = ast_str_create(ast_str_strlen(src->data) + 1))) 10569 return; 10570 ast_str_copy_string(&dst->data, src->data); 10571 10572 /* copy the content into the dst request (if it exists) */ 10573 if (src->content) { 10574 if (!dst->content && !(dst->content = ast_str_create(ast_str_strlen(src->content) + 1))) 10575 return; 10576 ast_str_copy_string(&dst->content, src->content); 10577 } 10578 }
| static void copy_socket_data | ( | struct sip_socket * | to_sock, | |
| const struct sip_socket * | from_sock | |||
| ) | [static] |
Definition at line 5153 of file chan_sip.c.
References ao2_ref, and sip_socket::tcptls_session.
Referenced by create_addr_from_peer(), handle_request_do(), parse_register_contact(), sip_poke_peer(), and transmit_response_using_temp().
05154 { 05155 if (to_sock->tcptls_session) { 05156 ao2_ref(to_sock->tcptls_session, -1); 05157 to_sock->tcptls_session = NULL; 05158 } 05159 05160 if (from_sock->tcptls_session) { 05161 ao2_ref(from_sock->tcptls_session, +1); 05162 } 05163 05164 *to_sock = *from_sock; 05165 }
| static struct ast_variable * copy_vars | ( | struct ast_variable * | src | ) | [static, read] |
duplicate a list of channel variables,
Definition at line 2759 of file chan_sip.c.
References ast_variable_new(), and ast_variable::next.
Referenced by check_peer_ok(), and create_addr_from_peer().
02760 { 02761 struct ast_variable *res = NULL, *tmp, *v = NULL; 02762 02763 for (v = src ; v ; v = v->next) { 02764 if ((tmp = ast_variable_new(v->name, v->value, v->file))) { 02765 tmp->next = res; 02766 res = tmp; 02767 } 02768 } 02769 return res; 02770 }
| static int copy_via_headers | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy SIP VIA Headers from the request to the response.
We always add ;received=<ip address> to the topmost via header.
Definition at line 9258 of file chan_sip.c.
References __get_header(), add_header(), ast_copy_string(), ast_inet_ntoa(), ast_log(), ast_strlen_zero(), ast_test_flag, sip_pvt::flags, LOG_NOTICE, sip_pvt::recv, SIP_NAT, SIP_NAT_ALWAYS, and SIP_NAT_RFC3581.
Referenced by respprep().
09259 { 09260 int copied = 0; 09261 int start = 0; 09262 09263 for (;;) { 09264 char new[512]; 09265 const char *oh = __get_header(orig, field, &start); 09266 09267 if (ast_strlen_zero(oh)) 09268 break; 09269 09270 if (!copied) { /* Only check for empty rport in topmost via header */ 09271 char leftmost[512], *others, *rport; 09272 09273 /* Only work on leftmost value */ 09274 ast_copy_string(leftmost, oh, sizeof(leftmost)); 09275 others = strchr(leftmost, ','); 09276 if (others) 09277 *others++ = '\0'; 09278 09279 /* Find ;rport; (empty request) */ 09280 rport = strstr(leftmost, ";rport"); 09281 if (rport && *(rport+6) == '=') 09282 rport = NULL; /* We already have a parameter to rport */ 09283 09284 /* Check rport if NAT=yes or NAT=rfc3581 (which is the default setting) */ 09285 if (rport && ((ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_ALWAYS) || (ast_test_flag(&p->flags[0], SIP_NAT) == SIP_NAT_RFC3581))) { 09286 /* We need to add received port - rport */ 09287 char *end; 09288 09289 rport = strstr(leftmost, ";rport"); 09290 09291 if (rport) { 09292 end = strchr(rport + 1, ';'); 09293 if (end) 09294 memmove(rport, end, strlen(end) + 1); 09295 else 09296 *rport = '\0'; 09297 } 09298 09299 /* Add rport to first VIA header if requested */ 09300 snprintf(new, sizeof(new), "%s;received=%s;rport=%d%s%s", 09301 leftmost, ast_inet_ntoa(p->recv.sin_addr), 09302 ntohs(p->recv.sin_port), 09303 others ? "," : "", others ? others : ""); 09304 } else { 09305 /* We should *always* add a received to the topmost via */ 09306 snprintf(new, sizeof(new), "%s;received=%s%s%s", 09307 leftmost, ast_inet_ntoa(p->recv.sin_addr), 09308 others ? "," : "", others ? others : ""); 09309 } 09310 oh = new; /* the header to copy */ 09311 } /* else add the following via headers untouched */ 09312 add_header(req, field, oh); 09313 copied++; 09314 } 09315 if (!copied) { 09316 ast_log(LOG_NOTICE, "No header field '%s' present to copy\n", field); 09317 return -1; 09318 } 09319 return 0; 09320 }
| static int create_addr | ( | struct sip_pvt * | dialog, | |
| const char * | opeer, | |||
| struct sockaddr_in * | sin, | |||
| int | newdialog | |||
| ) | [static] |
create address structure from device name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success
Definition at line 5321 of file chan_sip.c.
References ast_copy_string(), ast_get_srv(), ast_gethostbyname(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, bindaddr, create_addr_from_peer(), do_setnat(), FALSE, find_peer(), FINDPEERS, sip_pvt::flags, get_srv_protocol(), get_srv_service(), hp, LOG_WARNING, MAXHOSTNAMELEN, obproxy_get(), sip_socket::port, port_str2int(), sip_pvt::portinuri, sip_pvt::recv, ref_proxy(), sip_pvt::sa, service, set_socket_transport(), sip_cfg, SIP_NAT, SIP_NAT_ROUTE, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, sip_pvt::socket, sip_settings::srvlookup, STANDARD_SIP_PORT, STANDARD_TLS_PORT, sip_pvt::timer_b, sip_pvt::timer_t1, sip_peer::tohost, TRUE, sip_socket::type, and unref_peer().
Referenced by __sip_subscribe_mwi_do(), manager_sipnotify(), sip_cli_notify(), sip_request_call(), and transmit_register().
05322 { 05323 struct hostent *hp; 05324 struct ast_hostent ahp; 05325 struct sip_peer *peer; 05326 char *port; 05327 int portno = 0; 05328 char host[MAXHOSTNAMELEN], *hostn; 05329 char peername[256]; 05330 int srv_ret = 0; 05331 05332 ast_copy_string(peername, opeer, sizeof(peername)); 05333 port = strchr(peername, ':'); 05334 if (port) { 05335 *port++ = '\0'; 05336 dialog->portinuri = 1; 05337 } 05338 dialog->sa.sin_family = AF_INET; 05339 dialog->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */ 05340 dialog->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */ 05341 peer = find_peer(peername, NULL, TRUE, FINDPEERS, FALSE, 0); 05342 05343 if (peer) { 05344 int res; 05345 if (newdialog) { 05346 set_socket_transport(&dialog->socket, 0); 05347 } 05348 res = create_addr_from_peer(dialog, peer); 05349 if (!ast_strlen_zero(port)) { 05350 if ((portno = atoi(port))) { 05351 dialog->sa.sin_port = dialog->recv.sin_port = htons(portno); 05352 } 05353 } 05354 unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup"); 05355 return res; 05356 } 05357 05358 do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 05359 05360 ast_string_field_set(dialog, tohost, peername); 05361 05362 /* Get the outbound proxy information */ 05363 ref_proxy(dialog, obproxy_get(dialog, NULL)); 05364 05365 if (sin) { 05366 /* This address should be updated using dnsmgr */ 05367 memcpy(&dialog->sa.sin_addr, &sin->sin_addr, sizeof(dialog->sa.sin_addr)); 05368 if (!sin->sin_port) { 05369 portno = port_str2int(port, (dialog->socket.type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT); 05370 } else { 05371 portno = ntohs(sin->sin_port); 05372 } 05373 } else { 05374 05375 /* Let's see if we can find the host in DNS. First try DNS SRV records, 05376 then hostname lookup */ 05377 /*! \todo Fix this function. When we ask for SRV, we should check all transports 05378 In the future, we should first check NAPTR to find out transport preference 05379 */ 05380 hostn = peername; 05381 /* Section 4.2 of RFC 3263 specifies that if a port number is specified, then 05382 * an A record lookup should be used instead of SRV. 05383 */ 05384 if (!port && sip_cfg.srvlookup) { 05385 char service[MAXHOSTNAMELEN]; 05386 int tportno; 05387 snprintf(service, sizeof(service), "_%s._%s.%s", 05388 get_srv_service(dialog->socket.type), 05389 get_srv_protocol(dialog->socket.type), peername); 05390 srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, service); 05391 if (srv_ret > 0) { 05392 hostn = host; 05393 portno = tportno; 05394 } 05395 } 05396 if (!portno) 05397 portno = port_str2int(port, (dialog->socket.type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT); 05398 hp = ast_gethostbyname(hostn, &ahp); 05399 if (!hp) { 05400 ast_log(LOG_WARNING, "No such host: %s\n", peername); 05401 return -1; 05402 } 05403 memcpy(&dialog->sa.sin_addr, hp->h_addr, sizeof(dialog->sa.sin_addr)); 05404 } 05405 05406 if (!dialog->socket.type) 05407 set_socket_transport(&dialog->socket, SIP_TRANSPORT_UDP); 05408 if (!dialog->socket.port) 05409 dialog->socket.port = bindaddr.sin_port; 05410 dialog->sa.sin_port = htons(portno); 05411 dialog->recv = dialog->sa; 05412 return 0; 05413 }
Create address structure from peer reference. This function copies data from peer to the dialog, so we don't have to look up the peer again from memory or database during the life time of the dialog.
Definition at line 5174 of file chan_sip.c.
References sip_peer::addr, sip_peer::allowtransfer, sip_pvt::allowtransfer, ao2_t_link, ao2_t_unlink, ast_clear_flag, ast_copy_flags, ast_debug, AST_FORMAT_VIDEO_MASK, ast_inet_ntoa(), ast_rtp_codec_setpref(), ast_rtp_destroy(), AST_RTP_DTMF, ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtpkeepalive(), ast_rtp_set_rtptimeout(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_set_flag, ast_strdupa, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_destroy(), ast_udptl_new_with_bindaddr(), sip_peer::auth, sip_peer::autoframing, sip_pvt::autoframing, bindaddr, sip_peer::call_limit, sip_peer::callgroup, sip_pvt::callgroup, sip_pvt::callid, sip_peer::capability, sip_pvt::capability, sip_peer::chanvars, sip_pvt::chanvars, check_request_transport, sip_peer::context, context, copy_socket_data(), copy_vars(), sip_peer::defaddr, do_setnat(), sip_peer::flags, sip_pvt::flags, sip_peer::fromdomain, sip_peer::fromuser, sip_peer::fullcontact, sip_request::headers, sip_pvt::initreq, sip_pvt::jointnoncodeccapability, language, sip_peer::language, sip_peer::lastms, sip_peer::maxcallbitrate, sip_pvt::maxcallbitrate, sip_peer::maxms, sip_peer::md5secret, sip_peer::mohinterpret, mohinterpret, sip_peer::mohsuggest, mohsuggest, sip_peer::name, sip_pvt::noncodeccapability, obproxy_get(), sip_peer::parkinglot, parkinglot, sip_pvt::peerauth, sip_peer::pickupgroup, sip_pvt::pickupgroup, sip_peer::portinuri, sip_pvt::portinuri, sip_peer::prefs, sip_pvt::prefs, sip_pvt::recv, ref_proxy(), sip_pvt::rtp, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_pvt::rtptimeout, sip_peer::rtptimeout, sip_pvt::sa, sip_peer::secret, set_t38_capabilities(), SIP_CALL_LIMIT, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, SIP_NAT, SIP_NAT_ROUTE, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, sip_peer::socket, sip_pvt::socket, sip_peer::t38_maxdatagram, sip_pvt::t38_maxdatagram, sip_pvt::timer_b, sip_peer::timer_b, sip_peer::timer_t1, sip_pvt::timer_t1, sip_pvt::tohost, sip_peer::tohost, sip_pvt::trtp, sip_socket::type, sip_pvt::udptl, sip_peer::username, and sip_pvt::vrtp.
Referenced by create_addr(), and sip_send_mwi_to_peer().
05175 { 05176 05177 /* this checks that the dialog is contacting the peer on a valid 05178 * transport type based on the peers transport configuration, 05179 * otherwise, this function bails out */ 05180 if (dialog->socket.type && check_request_transport(peer, dialog)) 05181 return -1; 05182 copy_socket_data(&dialog->socket, &peer->socket); 05183 05184 if ((peer->addr.sin_addr.s_addr || peer->defaddr.sin_addr.s_addr) && 05185 (!peer->maxms || ((peer->lastms >= 0) && (peer->lastms <= peer->maxms)))) { 05186 dialog->sa = (peer->addr.sin_addr.s_addr) ? peer->addr : peer->defaddr; 05187 dialog->recv = dialog->sa; 05188 } else 05189 return -1; 05190 05191 ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 05192 ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 05193 dialog->capability = peer->capability; 05194 if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) && 05195 (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) || 05196 !(dialog->capability & AST_FORMAT_VIDEO_MASK)) && 05197 dialog->vrtp) { 05198 ast_rtp_destroy(dialog->vrtp); 05199 dialog->vrtp = NULL; 05200 } 05201 if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT) && dialog->trtp) { 05202 ast_rtp_destroy(dialog->trtp); 05203 dialog->trtp = NULL; 05204 } 05205 dialog->prefs = peer->prefs; 05206 if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT)) { 05207 /* t38pt_udptl was enabled in the peer and not in [general] */ 05208 if (dialog->udptl || (!dialog->udptl && (dialog->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr)))) { 05209 dialog->t38_maxdatagram = peer->t38_maxdatagram; 05210 set_t38_capabilities(dialog); 05211 } else { 05212 /* It is impossible to support T38 without udptl */ 05213 ast_debug(1, "UDPTL creation failed on dialog.\n"); 05214 ast_clear_flag(&dialog->flags[1], SIP_PAGE2_T38SUPPORT); 05215 } 05216 } else if (dialog->udptl) { 05217 ast_udptl_destroy(dialog->udptl); 05218 dialog->udptl = NULL; 05219 } 05220 do_setnat(dialog, ast_test_flag(&dialog->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 05221 05222 if (dialog->rtp) { /* Audio */ 05223 ast_rtp_setdtmf(dialog->rtp, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 05224 ast_rtp_setdtmfcompensate(dialog->rtp, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 05225 ast_rtp_set_rtptimeout(dialog->rtp, peer->rtptimeout); 05226 ast_rtp_set_rtpholdtimeout(dialog->rtp, peer->rtpholdtimeout); 05227 ast_rtp_set_rtpkeepalive(dialog->rtp, peer->rtpkeepalive); 05228 /* Set Frame packetization */ 05229 ast_rtp_codec_setpref(dialog->rtp, &dialog->prefs); 05230 dialog->autoframing = peer->autoframing; 05231 } 05232 if (dialog->vrtp) { /* Video */ 05233 ast_rtp_setdtmf(dialog->vrtp, 0); 05234 ast_rtp_setdtmfcompensate(dialog->vrtp, 0); 05235 ast_rtp_set_rtptimeout(dialog->vrtp, peer->rtptimeout); 05236 ast_rtp_set_rtpholdtimeout(dialog->vrtp, peer->rtpholdtimeout); 05237 ast_rtp_set_rtpkeepalive(dialog->vrtp, peer->rtpkeepalive); 05238 } 05239 if (dialog->trtp) { /* Realtime text */ 05240 ast_rtp_setdtmf(dialog->trtp, 0); 05241 ast_rtp_setdtmfcompensate(dialog->trtp, 0); 05242 ast_rtp_set_rtptimeout(dialog->trtp, peer->rtptimeout); 05243 ast_rtp_set_rtpholdtimeout(dialog->trtp, peer->rtpholdtimeout); 05244 ast_rtp_set_rtpkeepalive(dialog->trtp, peer->rtpkeepalive); 05245 } 05246 05247 ast_string_field_set(dialog, peername, peer->name); 05248 ast_string_field_set(dialog, authname, peer->username); 05249 ast_string_field_set(dialog, username, peer->username); 05250 ast_string_field_set(dialog, peersecret, peer->secret); 05251 ast_string_field_set(dialog, peermd5secret, peer->md5secret); 05252 ast_string_field_set(dialog, mohsuggest, peer->mohsuggest); 05253 ast_string_field_set(dialog, mohinterpret, peer->mohinterpret); 05254 ast_string_field_set(dialog, tohost, peer->tohost); 05255 ast_string_field_set(dialog, fullcontact, peer->fullcontact); 05256 ast_string_field_set(dialog, context, peer->context); 05257 ast_string_field_set(dialog, parkinglot, peer->parkinglot); 05258 ref_proxy(dialog, obproxy_get(dialog, peer)); 05259 dialog->callgroup = peer->callgroup; 05260 dialog->pickupgroup = peer->pickupgroup; 05261 dialog->allowtransfer = peer->allowtransfer; 05262 dialog->jointnoncodeccapability = dialog->noncodeccapability; 05263 dialog->rtptimeout = peer->rtptimeout; 05264 dialog->peerauth = peer->auth; 05265 dialog->maxcallbitrate = peer->maxcallbitrate; 05266 if (ast_strlen_zero(dialog->tohost)) 05267 ast_string_field_set(dialog, tohost, ast_inet_ntoa(dialog->sa.sin_addr)); 05268 if (!ast_strlen_zero(peer->fromdomain)) { 05269 ast_string_field_set(dialog, fromdomain, peer->fromdomain); 05270 if (!dialog->initreq.headers) { 05271 char *c; 05272 char *tmpcall = ast_strdupa(dialog->callid); 05273 /* this sure looks to me like we are going to change the callid on this dialog!! */ 05274 c = strchr(tmpcall, '@'); 05275 if (c) { 05276 *c = '\0'; 05277 ao2_t_unlink(dialogs, dialog, "About to change the callid -- remove the old name"); 05278 ast_string_field_build(dialog, callid, "%s@%s", tmpcall, peer->fromdomain); 05279 ao2_t_link(dialogs, dialog, "New dialog callid -- inserted back into table"); 05280 } 05281 } 05282 } 05283 if (!ast_strlen_zero(peer->fromuser)) 05284 ast_string_field_set(dialog, fromuser, peer->fromuser); 05285 if (!ast_strlen_zero(peer->language)) 05286 ast_string_field_set(dialog, language, peer->language); 05287 /* Set timer T1 to RTT for this peer (if known by qualify=) */ 05288 /* Minimum is settable or default to 100 ms */ 05289 /* If there is a maxms and lastms from a qualify use that over a manual T1 05290 value. Otherwise, use the peer's T1 value. */ 05291 if (peer->maxms && peer->lastms) 05292 dialog->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 05293 else 05294 dialog->timer_t1 = peer->timer_t1; 05295 05296 /* Set timer B to control transaction timeouts, the peer setting is the default and overrides 05297 the known timer */ 05298 if (peer->timer_b) 05299 dialog->timer_b = peer->timer_b; 05300 else 05301 dialog->timer_b = 64 * dialog->timer_t1; 05302 05303 if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 05304 (ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 05305 dialog->noncodeccapability |= AST_RTP_DTMF; 05306 else 05307 dialog->noncodeccapability &= ~AST_RTP_DTMF; 05308 if (peer->call_limit) 05309 ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT); 05310 if (!dialog->portinuri) 05311 dialog->portinuri = peer->portinuri; 05312 05313 dialog->chanvars = copy_vars(peer->chanvars); 05314 05315 return 0; 05316 }
| static void deinit_req | ( | struct sip_request * | req | ) | [static] |
Deinitialize SIP response/request.
Definition at line 9472 of file chan_sip.c.
References ast_free, sip_request::content, and sip_request::data.
Referenced by __sip_destroy(), _sip_tcp_helper_thread(), send_request(), send_response(), sip_park(), sip_park_thread(), and sipsock_read().
09473 { 09474 if (req->data) { 09475 ast_free(req->data); 09476 req->data = NULL; 09477 } 09478 if (req->content) { 09479 ast_free(req->content); 09480 req->content = NULL; 09481 } 09482 }
| static void destroy_association | ( | struct sip_peer * | peer | ) | [static] |
Remove registration data from realtime database or AST/DB when registration expires.
Definition at line 12152 of file chan_sip.c.
References ast_check_realtime(), ast_db_del(), ast_update_realtime(), sip_settings::ignore_regexpire, sip_peer::name, sip_settings::peer_rtupdate, sip_peer::rt_fromcontact, SENTINEL, and sip_cfg.
Referenced by build_peer(), expire_register(), and parse_register_contact().
12153 { 12154 int realtimeregs = ast_check_realtime("sipregs"); 12155 char *tablename = (realtimeregs) ? "sipregs" : "sippeers"; 12156 12157 if (!sip_cfg.ignore_regexpire) { 12158 if (peer->rt_fromcontact && sip_cfg.peer_rtupdate) { 12159 ast_update_realtime(tablename, "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "regserver", "", "useragent", "", "lastms", "", SENTINEL); 12160 } else { 12161 ast_db_del("SIP/Registry", peer->name); 12162 } 12163 } 12164 }
| static void destroy_mailbox | ( | struct sip_mailbox * | mailbox | ) | [static] |
Destroy mailbox subscriptions
Definition at line 4687 of file chan_sip.c.
References ast_event_unsubscribe(), ast_free, sip_mailbox::context, sip_mailbox::event_sub, and sip_mailbox::mailbox.
Referenced by build_peer(), and clear_peer_mailboxes().
04688 { 04689 if (mailbox->mailbox) 04690 ast_free(mailbox->mailbox); 04691 if (mailbox->context) 04692 ast_free(mailbox->context); 04693 if (mailbox->event_sub) 04694 ast_event_unsubscribe(mailbox->event_sub); 04695 ast_free(mailbox); 04696 }
| static int determine_firstline_parts | ( | struct sip_request * | req | ) | [static] |
Parse first line of incoming SIP request.
Definition at line 10611 of file chan_sip.c.
References ast_debug, ast_skip_blanks(), ast_skip_nonblanks(), ast_trim_blanks(), sip_request::data, sip_request::rlPart1, and sip_request::rlPart2.
Referenced by parse_request().
10612 { 10613 char *e = ast_skip_blanks(req->data->str); /* there shouldn't be any */ 10614 char *local_rlPart1; 10615 10616 if (!*e) 10617 return -1; 10618 req->rlPart1 = e - req->data->str; /* method or protocol */ 10619 local_rlPart1 = e; 10620 e = ast_skip_nonblanks(e); 10621 if (*e) 10622 *e++ = '\0'; 10623 /* Get URI or status code */ 10624 e = ast_skip_blanks(e); 10625 if ( !*e ) 10626 return -1; 10627 ast_trim_blanks(e); 10628 10629 if (!strcasecmp(local_rlPart1, "SIP/2.0") ) { /* We have a response */ 10630 if (strlen(e) < 3) /* status code is 3 digits */ 10631 return -1; 10632 req->rlPart2 = e - req->data->str; 10633 } else { /* We have a request */ 10634 if ( *e == '<' ) { /* XXX the spec says it must not be in <> ! */ 10635 ast_debug(3, "Oops. Bogus uri in <> %s\n", e); 10636 e++; 10637 if (!*e) 10638 return -1; 10639 } 10640 req->rlPart2 = e - req->data->str; /* URI */ 10641 e = ast_skip_nonblanks(e); 10642 if (*e) 10643 *e++ = '\0'; 10644 e = ast_skip_blanks(e); 10645 if (strcasecmp(e, "SIP/2.0") ) { 10646 ast_debug(3, "Skipping packet - Bad request protocol %s\n", e); 10647 return -1; 10648 } 10649 } 10650 return 1; 10651 }
| static int dialog_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 2127 of file chan_sip.c.
References sip_pvt::callid, CMP_MATCH, and CMP_STOP.
Referenced by load_module().
02128 { 02129 struct sip_pvt *pvt = obj, *pvt2 = arg; 02130 02131 return !strcasecmp(pvt->callid, pvt2->callid) ? CMP_MATCH | CMP_STOP : 0; 02132 }
| static int dialog_dump_func | ( | void * | userobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 15068 of file chan_sip.c.
References ao2_t_ref, ast_cli(), and sip_pvt::callid.
Referenced by sip_show_objects().
15069 { 15070 struct sip_pvt *pvt = userobj; 15071 int refc = ao2_t_ref(userobj, 0, ""); 15072 int *fd = arg; 15073 15074 ast_cli(*fd, "name: %s\ntype: dialog\nobjflags: %d\nrefcount: %d\n\n", 15075 pvt->callid, 0, refc); 15076 return 0; 15077 }
| static int dialog_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 2117 of file chan_sip.c.
References ast_str_case_hash(), and sip_pvt::callid.
Referenced by load_module().
02118 { 02119 const struct sip_pvt *pvt = obj; 02120 02121 return ast_str_case_hash(pvt->callid); 02122 }
| static int dialog_needdestroy | ( | void * | dialogobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Match dialogs that need to be destroyed.
This is used with ao2_callback to unlink/delete all dialogs that are marked needdestroy. It will return CMP_MATCH for candidates, and they will be unlinked.
Definition at line 15187 of file chan_sip.c.
References ast_debug, ast_rtp_get_bridged(), sip_pvt::callid, check_rtp_timeout(), dialog_unlink_all(), FALSE, sip_pvt::method, sip_pvt::needdestroy, sip_pvt::owner, sip_pvt::packets, sip_pvt::rtp, sip_methods, sip_pvt_trylock, sip_pvt_unlock, cfsip_methods::text, TRUE, and sip_pvt::vrtp.
Referenced by do_monitor().
15188 { 15189 struct sip_pvt *dialog = dialogobj; 15190 time_t *t = arg; 15191 15192 if (sip_pvt_trylock(dialog)) { 15193 /* Don't block the monitor thread. This function is called often enough 15194 * that we can wait for the next time around. */ 15195 return 0; 15196 } 15197 15198 /* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */ 15199 check_rtp_timeout(dialog, *t); 15200 15201 /* If we have sessions that needs to be destroyed, do it now */ 15202 /* Check if we have outstanding requests not responsed to or an active call 15203 - if that's the case, wait with destruction */ 15204 if (dialog->needdestroy && !dialog->packets && !dialog->owner) { 15205 /* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */ 15206 if (dialog->rtp && ast_rtp_get_bridged(dialog->rtp)) { 15207 ast_debug(2, "Bridge still active. Delaying destruction of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 15208 sip_pvt_unlock(dialog); 15209 return 0; 15210 } 15211 15212 if (dialog->vrtp && ast_rtp_get_bridged(dialog->vrtp)) { 15213 ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 15214 sip_pvt_unlock(dialog); 15215 return 0; 15216 } 15217 15218 sip_pvt_unlock(dialog); 15219 /* no, the unlink should handle this: dialog_unref(dialog, "needdestroy: one more refcount decrement to allow dialog to be destroyed"); */ 15220 /* the CMP_MATCH will unlink this dialog from the dialog hash table */ 15221 dialog_unlink_all(dialog, TRUE, FALSE); 15222 return 0; /* the unlink_all should unlink this from the table, so.... no need to return a match */ 15223 } 15224 15225 sip_pvt_unlock(dialog); 15226 15227 return 0; 15228 }
when we create or delete references, make sure to use these functions so we keep track of the refcounts. To simplify the code, we allow a NULL to be passed to dialog_unref().
Definition at line 1758 of file chan_sip.c.
References ao2_ref, ast_log(), and LOG_ERROR.
Referenced by __sip_reliable_xmit(), dialog_unlink_all(), handle_request_invite(), handle_request_subscribe(), handle_response_invite(), manager_sipnotify(), queue_request(), sip_call(), sip_cli_notify(), sip_new(), sip_poke_peer(), sip_scheddestroy(), sip_send_mwi_to_peer(), start_session_timer(), transmit_register(), and update_provisional_keepalive().
01759 { 01760 if (p) 01761 ao2_ref(p, 1); 01762 else 01763 ast_log(LOG_ERROR, "Attempt to Ref a null pointer\n"); 01764 return p; 01765 }
| static void * dialog_unlink_all | ( | struct sip_pvt * | dialog, | |
| int | lockowner, | |||
| int | lockdialoglist | |||
| ) | [static] |
Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored.
Definition at line 3180 of file chan_sip.c.
References ao2_t_unlink, ast_channel_lock, ast_channel_unlock, ast_debug, ast_extension_state_del(), ast_free, AST_SCHED_DEL, AST_SCHED_DEL_UNREF, sip_pvt::autokillid, sip_peer::call, sip_registry::call, sip_pkt::data, dialog_ref(), dialog_unref(), sip_pvt::initid, sip_peer::mwipvt, ast_channel::name, sip_pkt::next, sip_pkt::owner, sip_pvt::owner, sip_pvt::packets, sip_pvt::provisional_keepalive_sched_id, sip_pvt::registry, registry_unref(), sip_pvt::relatedpeer, sip_pvt::request_queue_sched_id, sip_pkt::retransid, sip_pvt::stateid, sip_pvt::t38id, ast_channel::tech_pvt, and sip_pvt::waitid.
Referenced by __sip_autodestruct(), __sip_subscribe_mwi_do(), dialog_needdestroy(), handle_request_subscribe(), manager_sipnotify(), reload_config(), sip_cli_notify(), sip_destroy_peer(), sip_poke_noanswer(), sip_poke_peer(), sip_registry_destroy(), sip_request_call(), sip_send_mwi_to_peer(), transmit_register(), and unload_module().
03181 { 03182 struct sip_pkt *cp; 03183 03184 dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done"); 03185 03186 ao2_t_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink"); 03187 03188 /* Unlink us from the owner (channel) if we have one */ 03189 if (dialog->owner) { 03190 if (lockowner) 03191 ast_channel_lock(dialog->owner); 03192 ast_debug(1, "Detaching from channel %s\n", dialog->owner->name); 03193 dialog->owner->tech_pvt = dialog_unref(dialog->owner->tech_pvt, "resetting channel dialog ptr in unlink_all"); 03194 if (lockowner) 03195 ast_channel_unlock(dialog->owner); 03196 } 03197 if (dialog->registry) { 03198 if (dialog->registry->call == dialog) 03199 dialog->registry->call = dialog_unref(dialog->registry->call, "nulling out the registry's call dialog field in unlink_all"); 03200 dialog->registry = registry_unref(dialog->registry, "delete dialog->registry"); 03201 } 03202 if (dialog->stateid > -1) { 03203 ast_extension_state_del(dialog->stateid, NULL); 03204 dialog_unref(dialog, "removing extension_state, should unref the associated dialog ptr that was stored there."); 03205 dialog->stateid = -1; /* shouldn't we 'zero' this out? */ 03206 } 03207 /* Remove link from peer to subscription of MWI */ 03208 if (dialog->relatedpeer && dialog->relatedpeer->mwipvt == dialog) 03209 dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt"); 03210 if (dialog->relatedpeer && dialog->relatedpeer->call == dialog) 03211 dialog->relatedpeer->call = dialog_unref(dialog->relatedpeer->call, "unset the relatedpeer->call field in tandem with relatedpeer field itself"); 03212 03213 /* remove all current packets in this dialog */ 03214 while((cp = dialog->packets)) { 03215 dialog->packets = dialog->packets->next; 03216 AST_SCHED_DEL(sched, cp->retransid); 03217 dialog_unref(cp->owner, "remove all current packets in this dialog, and the pointer to the dialog too as part of __sip_destroy"); 03218 if (cp->data) { 03219 ast_free(cp->data); 03220 } 03221 ast_free(cp); 03222 } 03223 03224 AST_SCHED_DEL_UNREF(sched, dialog->waitid, dialog_unref(dialog, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr")); 03225 03226 AST_SCHED_DEL_UNREF(sched, dialog->initid, dialog_unref(dialog, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr")); 03227 03228 if (dialog->autokillid > -1) 03229 AST_SCHED_DEL_UNREF(sched, dialog->autokillid, dialog_unref(dialog, "when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr")); 03230 03231 if (dialog->request_queue_sched_id > -1) { 03232 AST_SCHED_DEL_UNREF(sched, dialog->request_queue_sched_id, dialog_unref(dialog, "when you delete the request_queue_sched_id sched, you should dec the refcount for the stored dialog ptr")); 03233 } 03234 03235 AST_SCHED_DEL_UNREF(sched, dialog->provisional_keepalive_sched_id, dialog_unref(dialog, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 03236 03237 if (dialog->t38id > -1) { 03238 AST_SCHED_DEL_UNREF(sched, dialog->t38id, dialog_unref(dialog, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 03239 } 03240 03241 dialog_unref(dialog, "Let's unbump the count in the unlink so the poor pvt can disappear if it is time"); 03242 return NULL; 03243 }
Definition at line 1767 of file chan_sip.c.
References ao2_ref.
Referenced by __sip_ack(), __sip_autodestruct(), __sip_destroy(), __sip_reliable_xmit(), __sip_subscribe_mwi_do(), auto_congest(), complete_sipch(), dialog_unlink_all(), get_also_info(), handle_invite_replaces(), handle_request_do(), handle_request_invite(), handle_request_subscribe(), handle_response_invite(), handle_response_peerpoke(), handle_response_register(), interpret_t38_parameters(), manager_sipnotify(), proc_session_timer(), queue_request(), reload_config(), restart_session_timer(), retrans_pkt(), scheduler_process_request_queue(), send_response(), sip_call(), sip_cancel_destroy(), sip_cli_notify(), sip_destroy_peer(), sip_hangup(), sip_poke_noanswer(), sip_poke_peer(), sip_reg_timeout(), sip_registry_destroy(), sip_reinvite_retry(), sip_request_call(), sip_send_mwi_to_peer(), sip_t38_abort(), start_session_timer(), stop_session_timer(), transmit_register(), and update_provisional_keepalive().
01768 { 01769 if (p) 01770 ao2_ref(p, -1); 01771 return NULL; 01772 }
| static int do_magic_pickup | ( | struct ast_channel * | channel, | |
| const char * | extension, | |||
| const char * | context | |||
| ) | [static] |
Definition at line 19817 of file chan_sip.c.
References ast_debug, ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_str_alloca, ast_str_set(), IGNORE_CONTEXT, LOG_ERROR, sip_settings::notifycid, pbx_exec(), pbx_findapp(), sip_cfg, and str.
Referenced by handle_request_invite().
19818 { 19819 struct ast_str *str = ast_str_alloca(AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2); 19820 struct ast_app *pickup = pbx_findapp("Pickup"); 19821 19822 if (!pickup) { 19823 ast_log(LOG_ERROR, "Unable to perform pickup: Application 'Pickup' not loaded (app_directed_pickup.so).\n"); 19824 return -1; 19825 } 19826 19827 ast_str_set(&str, 0, "%s@%s", extension, sip_cfg.notifycid == IGNORE_CONTEXT ? "PICKUPMARK" : context); 19828 19829 ast_debug(2, "About to call Pickup(%s)\n", str->str); 19830 19831 /* There is no point in capturing the return value since pickup_exec 19832 doesn't return anything meaningful unless the passed data is an empty 19833 string (which in our case it will not be) */ 19834 pbx_exec(channel, pickup, str->str); 19835 19836 return 0; 19837 }
| static void * do_monitor | ( | void * | data | ) | [static] |
The SIP monitoring thread.
Definition at line 22665 of file chan_sip.c.
References ao2_t_callback, ast_debug, ast_io_add(), ast_io_change(), AST_IO_IN, ast_io_remove(), ast_io_wait(), ast_mutex_lock(), ast_mutex_unlock(), ast_sched_runq(), ast_sched_wait(), ast_verb, dialog_needdestroy(), FALSE, monlock, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, sip_do_reload(), sip_reload_lock, and sipsock_read().
Referenced by restart_monitor().
22666 { 22667 int res; 22668 time_t t; 22669 int reloading; 22670 22671 /* Add an I/O event to our SIP UDP socket */ 22672 if (sipsock > -1) 22673 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 22674 22675 /* From here on out, we die whenever asked */ 22676 for(;;) { 22677 /* Check for a reload request */ 22678 ast_mutex_lock(&sip_reload_lock); 22679 reloading = sip_reloading; 22680 sip_reloading = FALSE; 22681 ast_mutex_unlock(&sip_reload_lock); 22682 if (reloading) { 22683 ast_verb(1, "Reloading SIP\n"); 22684 sip_do_reload(sip_reloadreason); 22685 22686 /* Change the I/O fd of our UDP socket */ 22687 if (sipsock > -1) { 22688 if (sipsock_read_id) 22689 sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL); 22690 else 22691 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 22692 } else if (sipsock_read_id) { 22693 ast_io_remove(io, sipsock_read_id); 22694 sipsock_read_id = NULL; 22695 } 22696 } 22697 22698 /* Check for dialogs needing to be killed */ 22699 t = time(NULL); 22700 /* don't scan the dialogs list if it hasn't been a reasonable period 22701 of time since the last time we did it (when MWI is being sent, we can 22702 get back to this point every millisecond or less) 22703 */ 22704 ao2_t_callback(dialogs, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, dialog_needdestroy, &t, 22705 "callback to remove dialogs w/needdestroy"); 22706 22707 /* the old methodology would be to restart the search for dialogs to delete with every 22708 dialog that was found and destroyed, probably because the list contents would change, 22709 so we'd need to restart. This isn't the best thing to do with callbacks. */ 22710 22711 /* XXX TODO The scheduler usage in this module does not have sufficient 22712 * synchronization being done between running the scheduler and places 22713 * scheduling tasks. As it is written, any scheduled item may not run 22714 * any sooner than about 1 second, regardless of whether a sooner time 22715 * was asked for. */ 22716 22717 pthread_testcancel(); 22718 /* Wait for sched or io */ 22719 res = ast_sched_wait(sched); 22720 if ((res < 0) || (res > 1000)) 22721 res = 1000; 22722 res = ast_io_wait(io, res); 22723 if (res > 20) 22724 ast_debug(1, "chan_sip: ast_io_wait ran %d all at once\n", res); 22725 ast_mutex_lock(&monlock); 22726 res = ast_sched_runq(sched); 22727 if (res >= 20) 22728 ast_debug(1, "chan_sip: ast_sched_runq ran %d all at once\n", res); 22729 ast_mutex_unlock(&monlock); 22730 } 22731 22732 /* Never reached */ 22733 return NULL; 22734 }
| static int do_proxy_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum sip_auth_type | code, | |||
| int | sipmethod, | |||
| int | init | |||
| ) | [static] |
Add authentication on outbound SIP packet.
Definition at line 17223 of file chan_sip.c.
References ast_calloc, ast_debug, sip_invite_param::auth, auth_headers(), sip_invite_param::authheader, sip_pvt::authtries, sip_request::header, sip_pvt::options, reply_digest(), SIP_INVITE, sip_methods, cfsip_methods::text, and transmit_invite().
Referenced by handle_response(), handle_response_invite(), handle_response_notify(), handle_response_refer(), and handle_response_subscribe().
17224 { 17225 char *header, *respheader; 17226 char digest[1024]; 17227 17228 if (!p->options && !(p->options = ast_calloc(1, sizeof(*p->options)))) 17229 return -2; 17230 17231 p->authtries++; 17232 auth_headers(code, &header, &respheader); 17233 ast_debug(2, "Auth attempt %d on %s\n", p->authtries, sip_methods[sipmethod].text); 17234 memset(digest, 0, sizeof(digest)); 17235 if (reply_digest(p, req, header, sipmethod, digest, sizeof(digest) )) { 17236 /* No way to authenticate */ 17237 return -1; 17238 } 17239 /* Now we have a reply digest */ 17240 p->options->auth = digest; 17241 p->options->authheader = respheader; 17242 return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init); 17243 }
| static int do_register_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum sip_auth_type | code | |||
| ) | [static] |
Authenticate for outbound registration.
Definition at line 17199 of file chan_sip.c.
References append_history, ast_verbose, auth_headers(), sip_pvt::authtries, sip_pvt::do_history, sip_request::header, sip_registry::hostname, sip_pvt::registry, reply_digest(), sip_debug_test_pvt(), SIP_REGISTER, and transmit_register().
Referenced by handle_response_register().
17200 { 17201 char *header, *respheader; 17202 char digest[1024]; 17203 17204 p->authtries++; 17205 auth_headers(code, &header, &respheader); 17206 memset(digest, 0, sizeof(digest)); 17207 if (reply_digest(p, req, header, SIP_REGISTER, digest, sizeof(digest))) { 17208 /* There's nothing to use for authentication */ 17209 /* No digest challenge in request */ 17210 if (sip_debug_test_pvt(p) && p->registry) 17211 ast_verbose("No authentication challenge, sending blank registration to domain/host name %s\n", p->registry->hostname); 17212 /* No old challenge */ 17213 return -1; 17214 } 17215 if (p->do_history) 17216 append_history(p, "RegistryAuth", "Try: %d", p->authtries); 17217 if (sip_debug_test_pvt(p) && p->registry) 17218 ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname); 17219 return transmit_register(p->registry, SIP_REGISTER, digest, respheader); 17220 }
| static void do_setnat | ( | struct sip_pvt * | p, | |
| int | natflags | |||
| ) | [static] |
Set nat mode on the various data sockets.
Definition at line 5068 of file chan_sip.c.
References ast_debug, ast_rtp_setnat(), ast_udptl_setnat(), sip_pvt::rtp, sip_pvt::trtp, sip_pvt::udptl, and sip_pvt::vrtp.
Referenced by check_peer_ok(), create_addr(), create_addr_from_peer(), sip_alloc(), and transmit_response_using_temp().
05069 { 05070 const char *mode = natflags ? "On" : "Off"; 05071 05072 if (p->rtp) { 05073 ast_debug(1, "Setting NAT on RTP to %s\n", mode); 05074 ast_rtp_setnat(p->rtp, natflags); 05075 } 05076 if (p->vrtp) { 05077 ast_debug(1, "Setting NAT on VRTP to %s\n", mode); 05078 ast_rtp_setnat(p->vrtp, natflags); 05079 } 05080 if (p->udptl) { 05081 ast_debug(1, "Setting NAT on UDPTL to %s\n", mode); 05082 ast_udptl_setnat(p->udptl, natflags); 05083 } 05084 if (p->trtp) { 05085 ast_debug(1, "Setting NAT on TRTP to %s\n", mode); 05086 ast_rtp_setnat(p->trtp, natflags); 05087 } 05088 }
| static const char * domain_mode_to_text | ( | const enum domain_mode | mode | ) | [static] |
Print domain mode to cli.
Definition at line 15383 of file chan_sip.c.
References SIP_DOMAIN_AUTO, and SIP_DOMAIN_CONFIG.
Referenced by sip_show_domains().
15384 { 15385 switch (mode) { 15386 case SIP_DOMAIN_AUTO: 15387 return "[Automatic]"; 15388 case SIP_DOMAIN_CONFIG: 15389 return "[Configured]"; 15390 } 15391 15392 return ""; 15393 }
| static const char * dtmfmode2str | ( | int | mode | ) | [static] |
Convert DTMF mode to printable string.
Definition at line 15124 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), sip_show_channel(), and sip_show_settings().
| static int expire_register | ( | const void * | data | ) | [static] |
Expire registration of SIP peer.
Definition at line 12180 of file chan_sip.c.
References sip_peer::addr, ao2_ref, ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_test_flag, sip_peer::default_outbound_transport, destroy_association(), EVENT_FLAG_SYSTEM, sip_peer::expire, FALSE, sip_peer::flags, sip_peer::is_realtime, manager_event, sip_peer::name, sip_peer::portinuri, register_peer_exten(), sip_peer::selfdestruct, set_socket_transport(), SIP_PAGE2_RTAUTOCLEAR, sip_peer::socket, sip_socket::tcptls_session, unlink_peer_from_tables(), and unref_peer().
Referenced by parse_register_contact(), realtime_peer(), reg_source_db(), sip_show_sched(), and sip_unregister().
12181 { 12182 struct sip_peer *peer = (struct sip_peer *)data; 12183 12184 if (!peer) /* Hmmm. We have no peer. Weird. */ 12185 return 0; 12186 12187 peer->expire = -1; 12188 peer->portinuri = 0; 12189 12190 destroy_association(peer); /* remove registration data from storage */ 12191 set_socket_transport(&peer->socket, peer->default_outbound_transport); 12192 12193 if (peer->socket.tcptls_session) { 12194 ao2_ref(peer->socket.tcptls_session, -1); 12195 peer->socket.tcptls_session = NULL; 12196 } 12197 12198 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name); 12199 register_peer_exten(peer, FALSE); /* Remove regexten */ 12200 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 12201 12202 /* Do we need to release this peer from memory? 12203 Only for realtime peers and autocreated peers 12204 */ 12205 if (peer->is_realtime) 12206 ast_debug(3, "-REALTIME- peer expired registration. Name: %s. Realtime peer objects now %d\n", peer->name, rpeerobjs); 12207 12208 if (peer->selfdestruct || 12209 ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 12210 unlink_peer_from_tables(peer); 12211 } 12212 12213 /* Only clear the addr after we check for destruction. The addr must remain 12214 * in order to unlink from the peers_by_ip container correctly */ 12215 memset(&peer->addr, 0, sizeof(peer->addr)); 12216 12217 unref_peer(peer, "removing peer ref for expire_register"); 12218 12219 return 0; 12220 }
| static void extract_uri | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Check Contact: URI of SIP message.
Definition at line 10712 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, ast_strlen_zero(), get_header(), get_in_brackets(), remove_uri_parameters(), and SIPBUFSIZE.
Referenced by handle_incoming(), and handle_request_invite().
10713 { 10714 char stripped[SIPBUFSIZE]; 10715 char *c; 10716 10717 ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped)); 10718 c = get_in_brackets(stripped); 10719 /* Cut the URI at the at sign after the @, not in the username part */ 10720 c = remove_uri_parameters(c); 10721 if (!ast_strlen_zero(c)) 10722 ast_string_field_set(p, uri, c); 10723 10724 }
| static const char* faxec2str | ( | int | faxec | ) | [static] |
Definition at line 15553 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), and sip_show_settings().
15554 { 15555 return map_x_s(faxecmodes, faxec, "Unknown"); 15556 }
| static int finalize_content | ( | struct sip_request * | req | ) | [static] |
Add 'Content-Length' header and content to SIP message.
Definition at line 9190 of file chan_sip.c.
References add_header(), ast_log(), ast_str_append(), ast_str_buffer(), ast_str_strlen(), sip_request::content, sip_request::data, sip_request::len, sip_request::lines, and LOG_WARNING.
Referenced by send_request(), and send_response().
09191 { 09192 char clen[10]; 09193 09194 if (req->lines) { 09195 ast_log(LOG_WARNING, "finalize_content() called on a message that has already been finalized\n"); 09196 return -1; 09197 } 09198 09199 snprintf(clen, sizeof(clen), "%zd", ast_str_strlen(req->content)); 09200 add_header(req, "Content-Length", clen); 09201 09202 if (ast_str_strlen(req->content)) { 09203 ast_str_append(&req->data, 0, "\r\n%s", ast_str_buffer(req->content)); 09204 req->len = ast_str_strlen(req->data); 09205 } 09206 req->lines = ast_str_strlen(req->content) ? 1 : 0; 09207 return 0; 09208 }
| static const char * find_alias | ( | const char * | name, | |
| const char * | _default | |||
| ) | [static] |
Find compressed SIP alias.
Structure for conversion between compressed SIP and "normal" SIP
Definition at line 6975 of file chan_sip.c.
References aliases, and ARRAY_LEN.
Referenced by __get_header(), and add_header().
06976 { 06977 /*! \brief Structure for conversion between compressed SIP and "normal" SIP */ 06978 static const struct cfalias { 06979 char * const fullname; 06980 char * const shortname; 06981 } aliases[] = { 06982 { "Content-Type", "c" }, 06983 { "Content-Encoding", "e" }, 06984 { "From", "f" }, 06985 { "Call-ID", "i" }, 06986 { "Contact", "m" }, 06987 { "Content-Length", "l" }, 06988 { "Subject", "s" }, 06989 { "To", "t" }, 06990 { "Supported", "k" }, 06991 { "Refer-To", "r" }, 06992 { "Referred-By", "b" }, 06993 { "Allow-Events", "u" }, 06994 { "Event", "o" }, 06995 { "Via", "v" }, 06996 { "Accept-Contact", "a" }, 06997 { "Reject-Contact", "j" }, 06998 { "Request-Disposition", "d" }, 06999 { "Session-Expires", "x" }, 07000 { "Identity", "y" }, 07001 { "Identity-Info", "n" }, 07002 }; 07003 int x; 07004 07005 for (x = 0; x < ARRAY_LEN(aliases); x++) { 07006 if (!strcasecmp(aliases[x].fullname, name)) 07007 return aliases[x].shortname; 07008 } 07009 07010 return _default; 07011 }
| static int find_by_name | ( | void * | obj, | |
| void * | arg, | |||
| void * | data, | |||
| int | flags | |||
| ) | [static] |
Definition at line 4978 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, FINDALLDEVICES, FINDPEERS, FINDUSERS, match(), sip_peer::name, SIP_TYPE_PEER, SIP_TYPE_USER, and sip_peer::type.
Referenced by find_peer().
04979 { 04980 struct sip_peer *search = obj, *match = arg; 04981 int *which_objects = data; 04982 04983 /* Usernames in SIP uri's are case sensitive. Domains are not */ 04984 if (strcmp(search->name, match->name)) { 04985 return 0; 04986 } 04987 04988 switch (*which_objects) { 04989 case FINDUSERS: 04990 if (!(search->type & SIP_TYPE_USER)) { 04991 return 0; 04992 } 04993 break; 04994 case FINDPEERS: 04995 if (!(search->type & SIP_TYPE_PEER)) { 04996 return 0; 04997 } 04998 break; 04999 case FINDALLDEVICES: 05000 break; 05001 } 05002 05003 return CMP_MATCH | CMP_STOP; 05004 }
| static struct sip_pvt * find_call | ( | struct sip_request * | req, | |
| struct sockaddr_in * | sin, | |||
| const int | intended_method | |||
| ) | [static, read] |
find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_incoming(), sipsock_read
Definition at line 7458 of file chan_sip.c.
References ao2_lock(), ao2_t_callback, ao2_t_find, ao2_unlock(), ast_debug, ast_strlen_zero(), sip_pvt::callid, find_call_cb_arg::callid, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, find_call_cb(), find_call_cb_arg::fromtag, get_header(), gettag(), sip_request::has_to_tag, sip_request::method, find_call_cb_arg::method, OBJ_POINTER, sip_settings::pedanticsipchecking, SIP_ACK, sip_alloc(), SIP_BYE, sip_cfg, SIP_INFO, sip_methods, SIP_NOTIFY, sip_pvt_lock, sip_pvt_trylock, SIP_REFER, SIP_RESPONSE, find_call_cb_arg::tag, cfsip_methods::text, find_call_cb_arg::totag, and transmit_response_using_temp().
Referenced by handle_request_do().
07459 { 07460 struct sip_pvt *p = NULL; 07461 char *tag = ""; /* note, tag is never NULL */ 07462 char totag[128]; 07463 char fromtag[128]; 07464 struct find_call_cb_arg arg; 07465 const char *callid = get_header(req, "Call-ID"); 07466 const char *from = get_header(req, "From"); 07467 const char *to = get_header(req, "To"); 07468 const char *cseq = get_header(req, "Cseq"); 07469 struct sip_pvt *sip_pvt_ptr; 07470 07471 /* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */ 07472 /* get_header always returns non-NULL so we must use ast_strlen_zero() */ 07473 if (ast_strlen_zero(callid) || ast_strlen_zero(to) || 07474 ast_strlen_zero(from) || ast_strlen_zero(cseq)) 07475 return NULL; /* Invalid packet */ 07476 07477 arg.method = req->method; 07478 arg.callid = callid; 07479 arg.fromtag = fromtag; 07480 arg.totag = totag; 07481 arg.tag = ""; /* make sure tag is never NULL */ 07482 07483 if (sip_cfg.pedanticsipchecking) { 07484 /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy 07485 we need more to identify a branch - so we have to check branch, from 07486 and to tags to identify a call leg. 07487 For Asterisk to behave correctly, you need to turn on pedanticsipchecking 07488 in sip.conf 07489 */ 07490 if (gettag(req, "To", totag, sizeof(totag))) 07491 req->has_to_tag = 1; /* Used in handle_request/response */ 07492 gettag(req, "From", fromtag, sizeof(fromtag)); 07493 07494 tag = (req->method == SIP_RESPONSE) ? totag : fromtag; 07495 07496 ast_debug(5, "= Looking for Call ID: %s (Checking %s) --From tag %s --To-tag %s \n", callid, req->method==SIP_RESPONSE ? "To" : "From", fromtag, totag); 07497 07498 /* All messages must always have From: tag */ 07499 if (ast_strlen_zero(fromtag)) { 07500 ast_debug(5, "%s request has no from tag, dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from ); 07501 return NULL; 07502 } 07503 /* reject requests that must always have a To: tag */ 07504 if (ast_strlen_zero(totag) && (req->method == SIP_ACK || req->method == SIP_BYE || req->method == SIP_INFO )) { 07505 ast_debug(5, "%s must have a to tag. dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from ); 07506 return NULL; 07507 } 07508 } 07509 07510 restartsearch: 07511 if (!sip_cfg.pedanticsipchecking) { 07512 struct sip_pvt tmp_dialog = { 07513 .callid = callid, 07514 }; 07515 sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find in dialogs"); 07516 if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */ 07517 /* Found the call */ 07518 sip_pvt_lock(sip_pvt_ptr); 07519 return sip_pvt_ptr; 07520 } 07521 } else { /* in pedantic mode! -- do the fancy linear search */ 07522 ao2_lock(dialogs); 07523 p = ao2_t_callback(dialogs, 0 /* single, data */, find_call_cb, &arg, "pedantic linear search for dialog"); 07524 if (p) { 07525 if (sip_pvt_trylock(p)) { 07526 ao2_unlock(dialogs); 07527 usleep(1); 07528 goto restartsearch; 07529 } 07530 ao2_unlock(dialogs); 07531 return p; 07532 } 07533 ao2_unlock(dialogs); 07534 } 07535 07536 /* See if the method is capable of creating a dialog */ 07537 if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) { 07538 if (intended_method == SIP_REFER) { 07539 /* We do support REFER, but not outside of a dialog yet */ 07540 transmit_response_using_temp(callid, sin, 1, intended_method, req, "603 Declined (no dialog)"); 07541 } else if (intended_method == SIP_NOTIFY) { 07542 /* We do not support out-of-dialog NOTIFY either, 07543 like voicemail notification, so cancel that early */ 07544 transmit_response_using_temp(callid, sin, 1, intended_method, req, "489 Bad event"); 07545 } else { 07546 /* Ok, time to create a new SIP dialog object, a pvt */ 07547 if ((p = sip_alloc(callid, sin, 1, intended_method, req))) { 07548 /* Ok, we've created a dialog, let's go and process it */ 07549 sip_pvt_lock(p); 07550 } else { 07551 /* We have a memory or file/socket error (can't allocate RTP sockets or something) so we're not 07552 getting a dialog from sip_alloc. 07553 07554 Without a dialog we can't retransmit and handle ACKs and all that, but at least 07555 send an error message. 07556 07557 Sorry, we apologize for the inconvienience 07558 */ 07559 transmit_response_using_temp(callid, sin, 1, intended_method, req, "500 Server internal error"); 07560 ast_debug(4, "Failed allocating SIP dialog, sending 500 Server internal error and giving up\n"); 07561 } 07562 } 07563 return p; /* can be NULL */ 07564 } else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) { 07565 /* A method we do not support, let's take it on the volley */ 07566 transmit_response_using_temp(callid, sin, 1, intended_method, req, "501 Method Not Implemented"); 07567 ast_debug(2, "Got a request with unsupported SIP method.\n"); 07568 } else if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) { 07569 /* This is a request outside of a dialog that we don't know about */ 07570 transmit_response_using_temp(callid, sin, 1, intended_method, req, "481 Call leg/transaction does not exist"); 07571 ast_debug(2, "That's odd... Got a request in unknown dialog. Callid %s\n", callid ? callid : "<unknown>"); 07572 } 07573 /* We do not respond to responses for dialogs that we don't know about, we just drop 07574 the session quickly */ 07575 if (intended_method == SIP_RESPONSE) 07576 ast_debug(2, "That's odd... Got a response on a call we don't know about. Callid %s\n", callid ? callid : "<unknown>"); 07577 07578 return NULL; 07579 }
| static int find_call_cb | ( | void * | __pvt, | |
| void * | __arg, | |||
| int | flags | |||
| ) | [static] |
code to determine whether this is the pvt that we are looking for. Return FALSE if not found, true otherwise. p is unlocked.
Definition at line 7417 of file chan_sip.c.
References ast_debug, ast_strlen_zero(), ast_test_flag, find_call_cb_arg::callid, sip_pvt::callid, FALSE, sip_pvt::flags, find_call_cb_arg::method, sip_settings::pedanticsipchecking, sip_cfg, sip_methods, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_REGISTER, SIP_RESPONSE, sip_pvt::tag, find_call_cb_arg::tag, cfsip_methods::text, sip_pvt::theirtag, and find_call_cb_arg::totag.
Referenced by find_call().
07418 { 07419 struct sip_pvt *p = __pvt; 07420 struct find_call_cb_arg *arg = __arg; 07421 /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */ 07422 int found = FALSE; 07423 07424 if (!ast_strlen_zero(p->callid)) { /* XXX double check, do we allow match on empty p->callid ? */ 07425 if (arg->method == SIP_REGISTER) 07426 found = (!strcmp(p->callid, arg->callid)); 07427 else { 07428 found = !strcmp(p->callid, arg->callid); 07429 if (sip_cfg.pedanticsipchecking && found) { 07430 found = ast_strlen_zero(arg->tag) || ast_strlen_zero(p->theirtag) || !ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED) || !strcmp(p->theirtag, arg->tag); 07431 } 07432 } 07433 07434 ast_debug(5, "= %s Their Call ID: %s Their Tag %s Our tag: %s\n", found ? "Found" : "No match", p->callid, p->theirtag, p->tag); 07435 07436 /* If we get a new request within an existing to-tag - check the to tag as well */ 07437 if (sip_cfg.pedanticsipchecking && found && arg->method != SIP_RESPONSE) { /* SIP Request */ 07438 if (p->tag[0] == '\0' && arg->totag[0]) { 07439 /* We have no to tag, but they have. Wrong dialog */ 07440 found = FALSE; 07441 } else if (arg->totag[0]) { /* Both have tags, compare them */ 07442 if (strcmp(arg->totag, p->tag)) { 07443 found = FALSE; /* This is not our packet */ 07444 } 07445 } 07446 if (!found) 07447 ast_debug(5, "= Being pedantic: This is not our match on request: Call ID: %s Ourtag <null> Totag %s Method %s\n", p->callid, arg->totag, sip_methods[arg->method].text); 07448 } 07449 } 07450 return found; 07451 }
| static int find_calling_channel | ( | struct ast_channel * | c, | |
| void * | data | |||
| ) | [static] |
Definition at line 11201 of file chan_sip.c.
References sip_pvt::context, ast_channel::context, ast_channel::exten, sip_pvt::exten, IGNORE_CONTEXT, ast_channel::macroexten, sip_settings::notifycid, ast_channel::pbx, and sip_cfg.
Referenced by transmit_state_notify().
11201 { 11202 struct sip_pvt *p = data; 11203 11204 return (c->pbx && 11205 (!strcasecmp(c->macroexten, p->exten) || !strcasecmp(c->exten, p->exten)) && 11206 (sip_cfg.notifycid == IGNORE_CONTEXT || !strcasecmp(c->context, p->context))); 11207 }
| static const char* find_closing_quote | ( | const char * | start, | |
| const char * | lim | |||
| ) | [static] |
Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote.
Definition at line 4375 of file chan_sip.c.
References s.
Referenced by get_in_brackets().
04376 { 04377 char last_char = '\0'; 04378 const char *s; 04379 for (s = start; *s && s != lim; last_char = *s++) { 04380 if (*s == '"' && last_char != '\\') 04381 break; 04382 } 04383 return s; 04384 }
| static struct sip_peer * find_peer | ( | const char * | peer, | |
| struct sockaddr_in * | sin, | |||
| int | realtime, | |||
| int | which_objects, | |||
| int | devstate_only, | |||
| int | transport | |||
| ) | [static, read] |
Locate device by name or ip address.
| which_objects | Define which objects should be matched when doing a lookup by name. Valid options are FINDUSERS, FINDPEERS, or FINDALLDEVICES. Note that this option is not used at all when doing a lookup by IP. |
Definition at line 5019 of file chan_sip.c.
References sip_peer::addr, ao2_t_callback_data, ao2_t_find, ast_copy_string(), ast_set_flag, find_by_name(), FINDALLDEVICES, FINDPEERS, FINDUSERS, ast_flags::flags, sip_peer::flags, sip_peer::name, OBJ_POINTER, realtime_peer(), SIP_INSECURE_PORT, SIP_TYPE_PEER, SIP_TYPE_USER, sip_peer::transports, sip_peer::type, and unref_peer().
Referenced by _sip_qualify_peer(), _sip_show_peer(), check_peer_ok(), create_addr(), function_sippeer(), register_verify(), sip_devicestate(), sip_do_debug_peer(), sip_peer_hold(), sip_show_user(), sip_unregister(), st_get_mode(), st_get_refresher(), st_get_se(), transmit_register(), and update_call_counter().
05020 { 05021 struct sip_peer *p = NULL; 05022 struct sip_peer tmp_peer; 05023 05024 if (peer) { 05025 ast_copy_string(tmp_peer.name, peer, sizeof(tmp_peer.name)); 05026 p = ao2_t_callback_data(peers, OBJ_POINTER, find_by_name, &tmp_peer, &which_objects, "ao2_find in peers table"); 05027 } else if (sin) { /* search by addr? */ 05028 tmp_peer.addr.sin_addr.s_addr = sin->sin_addr.s_addr; 05029 tmp_peer.addr.sin_port = sin->sin_port; 05030 tmp_peer.flags[0].flags = 0; 05031 tmp_peer.transports = transport; 05032 p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ 05033 if (!p) { 05034 ast_set_flag(&tmp_peer.flags[0], SIP_INSECURE_PORT); 05035 p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table 2"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ 05036 if (p) { 05037 return p; 05038 } 05039 } 05040 } 05041 05042 if (!p && (realtime || devstate_only)) { 05043 p = realtime_peer(peer, sin, devstate_only); 05044 if (p) { 05045 switch (which_objects) { 05046 case FINDUSERS: 05047 if (!(p->type & SIP_TYPE_USER)) { 05048 unref_peer(p, "Wrong type of realtime SIP endpoint"); 05049 return NULL; 05050 } 05051 break; 05052 case FINDPEERS: 05053 if (!(p->type & SIP_TYPE_PEER)) { 05054 unref_peer(p, "Wrong type of realtime SIP endpoint"); 05055 return NULL; 05056 } 05057 break; 05058 case FINDALLDEVICES: 05059 break; 05060 } 05061 } 05062 } 05063 05064 return p; 05065 }
| static struct sip_auth * find_realm_authentication | ( | struct sip_auth * | authlist, | |
| const char * | realm | |||
| ) | [static, read] |
Find authentication for a specific realm.
Definition at line 23823 of file chan_sip.c.
References sip_auth::next, and sip_auth::realm.
Referenced by build_reply_digest().
23824 { 23825 struct sip_auth *a; 23826 23827 for (a = authlist; a; a = a->next) { 23828 if (!strcasecmp(a->realm, realm)) 23829 break; 23830 } 23831 23832 return a; 23833 }
| static int find_sdp | ( | struct sip_request * | req | ) | [static] |
Determine whether a SIP message contains an SDP in its body.
| req | the SIP request to process |
Definition at line 7994 of file chan_sip.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), FALSE, get_header(), sip_request::lines, LOG_WARNING, REQ_OFFSET_TO_STR, sip_request::sdp_count, sip_request::sdp_start, strcasestr(), and TRUE.
Referenced by handle_incoming(), handle_request_invite(), handle_response(), and handle_response_invite().
07995 { 07996 const char *content_type; 07997 const char *content_length; 07998 const char *search; 07999 char *boundary; 08000 unsigned int x; 08001 int boundaryisquoted = FALSE; 08002 int found_application_sdp = FALSE; 08003 int found_end_of_headers = FALSE; 08004 08005 content_length = get_header(req, "Content-Length"); 08006 08007 if (!ast_strlen_zero(content_length)) { 08008 if (sscanf(content_length, "%30u", &x) != 1) { 08009 ast_log(LOG_WARNING, "Invalid Content-Length: %s\n", content_length); 08010 return 0; 08011 } 08012 08013 /* Content-Length of zero means there can't possibly be an 08014 SDP here, even if the Content-Type says there is */ 08015 if (x == 0) 08016 return 0; 08017 } 08018 08019 content_type = get_header(req, "Content-Type"); 08020 08021 /* if the body contains only SDP, this is easy */ 08022 if (!strncasecmp(content_type, "application/sdp", 15)) { 08023 req->sdp_start = 0; 08024 req->sdp_count = req->lines; 08025 return req->lines ? 1 : 0; 08026 } 08027 08028 /* if it's not multipart/mixed, there cannot be an SDP */ 08029 if (strncasecmp(content_type, "multipart/mixed", 15)) 08030 return 0; 08031 08032 /* if there is no boundary marker, it's invalid */ 08033 if ((search = strcasestr(content_type, ";boundary="))) 08034 search += 10; 08035 else if ((search = strcasestr(content_type, "; boundary="))) 08036 search += 11; 08037 else 08038 return 0; 08039 08040 if (ast_strlen_zero(search)) 08041 return 0; 08042 08043 /* If the boundary is quoted with ", remove quote */ 08044 if (*search == '\"') { 08045 search++; 08046 boundaryisquoted = TRUE; 08047 } 08048 08049 /* make a duplicate of the string, with two extra characters 08050 at the beginning */ 08051 boundary = ast_strdupa(search - 2); 08052 boundary[0] = boundary[1] = '-'; 08053 /* Remove final quote */ 08054 if (boundaryisquoted) 08055 boundary[strlen(boundary) - 1] = '\0'; 08056 08057 /* search for the boundary marker, the empty line delimiting headers from 08058 sdp part and the end boundry if it exists */ 08059 08060 for (x = 0; x < (req->lines); x++) { 08061 char *line = REQ_OFFSET_TO_STR(req, line[x]); 08062 if (!strncasecmp(line, boundary, strlen(boundary))){ 08063 if (found_application_sdp && found_end_of_headers) { 08064 req->sdp_count = (x - 1) - req->sdp_start; 08065 return 1; 08066 } 08067 found_application_sdp = FALSE; 08068 } 08069 if (!strcasecmp(line, "Content-Type: application/sdp")) 08070 found_application_sdp = TRUE; 08071 08072 if (ast_strlen_zero(line)) { 08073 if (found_application_sdp && !found_end_of_headers){ 08074 req->sdp_start = x; 08075 found_end_of_headers = TRUE; 08076 } 08077 } 08078 } 08079 if (found_application_sdp && found_end_of_headers) { 08080 req->sdp_count = x - req->sdp_start; 08081 return TRUE; 08082 } 08083 return FALSE; 08084 }
| static int find_sip_method | ( | const char * | msg | ) | [static] |
find_sip_method: Find SIP method from header
Definition at line 3392 of file chan_sip.c.
References ARRAY_LEN, ast_strlen_zero(), method_match(), and sip_methods.
Referenced by __sip_pretend_ack(), handle_request_do(), handle_response(), and sip_hangup().
03393 { 03394 int i, res = 0; 03395 03396 if (ast_strlen_zero(msg)) 03397 return 0; 03398 for (i = 1; i < ARRAY_LEN(sip_methods) && !res; i++) { 03399 if (method_match(i, msg)) 03400 res = sip_methods[i].id; 03401 } 03402 return res; 03403 }
| static struct cfsubscription_types * find_subscription_type | ( | enum subscriptiontype | subtype | ) | [static, read] |
Find subscription type in array.
Definition at line 16374 of file chan_sip.c.
References ARRAY_LEN, and subscription_types.
Referenced by transmit_state_notify().
16375 { 16376 int i; 16377 16378 for (i = 1; i < ARRAY_LEN(subscription_types); i++) { 16379 if (subscription_types[i].type == subtype) { 16380 return &subscription_types[i]; 16381 } 16382 } 16383 return &subscription_types[0]; 16384 }
| static void free_old_route | ( | struct sip_route * | route | ) | [static] |
Remove route from route list.
Definition at line 12600 of file chan_sip.c.
References ast_free, and sip_route::next.
Referenced by __sip_destroy(), and build_route().
12601 { 12602 struct sip_route *next; 12603 12604 while (route) { 12605 next = route->next; 12606 ast_free(route); 12607 route = next; 12608 } 12609 }
| static int func_check_sipdomain | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dial plan function to check if domain is local.
Definition at line 17460 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), check_sip_domain(), and LOG_WARNING.
17461 { 17462 if (ast_strlen_zero(data)) { 17463 ast_log(LOG_WARNING, "CHECKSIPDOMAIN requires an argument - A domain name\n"); 17464 return -1; 17465 } 17466 if (check_sip_domain(data, NULL, 0)) 17467 ast_copy_string(buf, data, len); 17468 else 17469 buf[0] = '\0'; 17470 return 0; 17471 }
| static int func_header_read | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Read SIP header (dialplan function).
Definition at line 17401 of file chan_sip.c.
References __get_header(), AST_APP_ARG, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), sip_request::content, sip_request::header, sip_pvt::initreq, IS_SIP_TECH, LOG_WARNING, ast_channel::tech, and ast_channel::tech_pvt.
17402 { 17403 struct sip_pvt *p; 17404 const char *content = NULL; 17405 AST_DECLARE_APP_ARGS(args, 17406 AST_APP_ARG(header); 17407 AST_APP_ARG(number); 17408 ); 17409 int i, number, start = 0; 17410 17411 if (ast_strlen_zero(data)) { 17412 ast_log(LOG_WARNING, "This function requires a header name.\n"); 17413 return -1; 17414 } 17415 17416 ast_channel_lock(chan); 17417 if (!IS_SIP_TECH(chan->tech)) { 17418 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 17419 ast_channel_unlock(chan); 17420 return -1; 17421 } 17422 17423 AST_STANDARD_APP_ARGS(args, data); 17424 if (!args.number) { 17425 number = 1; 17426 } else { 17427 sscanf(args.number, "%30d", &number); 17428 if (number < 1) 17429 number = 1; 17430 } 17431 17432 p = chan->tech_pvt; 17433 17434 /* If there is no private structure, this channel is no longer alive */ 17435 if (!p) { 17436 ast_channel_unlock(chan); 17437 return -1; 17438 } 17439 17440 for (i = 0; i < number; i++) 17441 content = __get_header(&p->initreq, args.header, &start); 17442 17443 if (ast_strlen_zero(content)) { 17444 ast_channel_unlock(chan); 17445 return -1; 17446 } 17447 17448 ast_copy_string(buf, content, len); 17449 ast_channel_unlock(chan); 17450 17451 return 0; 17452 }
| static int function_sipchaninfo_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPCHANINFO()} Dialplan function - reads sip channel data
Definition at line 17574 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_inet_ntoa(), ast_log(), sip_pvt::from, IS_SIP_TECH, LOG_WARNING, sip_pvt::peername, sip_pvt::recv, sip_pvt::sa, t38properties::state, sip_pvt::t38, T38_DISABLED, ast_channel::tech, ast_channel::tech_pvt, sip_pvt::uri, and sip_pvt::useragent.
17575 { 17576 struct sip_pvt *p; 17577 static int deprecated = 0; 17578 17579 *buf = 0; 17580 17581 if (!data) { 17582 ast_log(LOG_WARNING, "This function requires a parameter name.\n"); 17583 return -1; 17584 } 17585 17586 ast_channel_lock(chan); 17587 if (!IS_SIP_TECH(chan->tech)) { 17588 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 17589 ast_channel_unlock(chan); 17590 return -1; 17591 } 17592 17593 if (deprecated++ % 20 == 0) { 17594 /* Deprecated in 1.6.1 */ 17595 ast_log(LOG_WARNING, "SIPCHANINFO() is deprecated. Please transition to using CHANNEL().\n"); 17596 } 17597 17598 p = chan->tech_pvt; 17599 17600 /* If there is no private structure, this channel is no longer alive */ 17601 if (!p) { 17602 ast_channel_unlock(chan); 17603 return -1; 17604 } 17605 17606 if (!strcasecmp(data, "peerip")) { 17607 ast_copy_string(buf, p->sa.sin_addr.s_addr ? ast_inet_ntoa(p->sa.sin_addr) : "", len); 17608 } else if (!strcasecmp(data, "recvip")) { 17609 ast_copy_string(buf, p->recv.sin_addr.s_addr ? ast_inet_ntoa(p->recv.sin_addr) : "", len); 17610 } else if (!strcasecmp(data, "from")) { 17611 ast_copy_string(buf, p->from, len); 17612 } else if (!strcasecmp(data, "uri")) { 17613 ast_copy_string(buf, p->uri, len); 17614 } else if (!strcasecmp(data, "useragent")) { 17615 ast_copy_string(buf, p->useragent, len); 17616 } else if (!strcasecmp(data, "peername")) { 17617 ast_copy_string(buf, p->peername, len); 17618 } else if (!strcasecmp(data, "t38passthrough")) { 17619 if (p->t38.state == T38_DISABLED) { 17620 ast_copy_string(buf, "0", len); 17621 } else { /* T38 is offered or enabled in this call */ 17622 ast_copy_string(buf, "1", len); 17623 } 17624 } else { 17625 ast_channel_unlock(chan); 17626 return -1; 17627 } 17628 ast_channel_unlock(chan); 17629 17630 return 0; 17631 }
| static int function_sippeer | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPPEER()} Dialplan function - reads peer data
Definition at line 17479 of file chan_sip.c.
References sip_peer::accountcode, sip_peer::addr, ast_codec_pref_index(), ast_copy_string(), ast_getformatname(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_log(), ast_print_group(), ast_str_alloca, sip_peer::busy_level, sip_peer::call_limit, sip_peer::callgroup, sip_peer::capability, chanvar, sip_peer::chanvars, sip_peer::cid_name, sip_peer::cid_num, sip_peer::context, sip_peer::expire, FALSE, find_peer(), FINDPEERS, sip_peer::host_dynamic, sip_peer::inUse, sip_peer::language, LOG_WARNING, ast_variable::name, ast_variable::next, peer_mailboxes_to_str(), peer_status(), sip_peer::pickupgroup, sip_peer::prefs, sip_peer::regexten, strsep(), TRUE, unref_peer(), sip_peer::useragent, and ast_variable::value.
17480 { 17481 struct sip_peer *peer; 17482 char *colname; 17483 17484 if ((colname = strchr(data, ':'))) { /*! \todo Will be deprecated after 1.4 */ 17485 static int deprecation_warning = 0; 17486 *colname++ = '\0'; 17487 if (deprecation_warning++ % 10 == 0) 17488 ast_log(LOG_WARNING, "SIPPEER(): usage of ':' to separate arguments is deprecated. Please use ',' instead.\n"); 17489 } else if ((colname = strchr(data, ','))) 17490 *colname++ = '\0'; 17491 else 17492 colname = "ip"; 17493 17494 if (!(peer = find_peer(data, NULL, TRUE, FINDPEERS, FALSE, 0))) 17495 return -1; 17496 17497 if (!strcasecmp(colname, "ip")) { 17498 ast_copy_string(buf, peer->addr.sin_addr.s_addr ? ast_inet_ntoa(peer->addr.sin_addr) : "", len); 17499 } else if (!strcasecmp(colname, "port")) { 17500 snprintf(buf, len, "%d", ntohs(peer->addr.sin_port)); 17501 } else if (!strcasecmp(colname, "status")) { 17502 peer_status(peer, buf, len); 17503 } else if (!strcasecmp(colname, "language")) { 17504 ast_copy_string(buf, peer->language, len); 17505 } else if (!strcasecmp(colname, "regexten")) { 17506 ast_copy_string(buf, peer->regexten, len); 17507 } else if (!strcasecmp(colname, "limit")) { 17508 snprintf(buf, len, "%d", peer->call_limit); 17509 } else if (!strcasecmp(colname, "busylevel")) { 17510 snprintf(buf, len, "%d", peer->busy_level); 17511 } else if (!strcasecmp(colname, "curcalls")) { 17512 snprintf(buf, len, "%d", peer->inUse); 17513 } else if (!strcasecmp(colname, "accountcode")) { 17514 ast_copy_string(buf, peer->accountcode, len); 17515 } else if (!strcasecmp(colname, "callgroup")) { 17516 ast_print_group(buf, len, peer->callgroup); 17517 } else if (!strcasecmp(colname, "pickupgroup")) { 17518 ast_print_group(buf, len, peer->pickupgroup); 17519 } else if (!strcasecmp(colname, "useragent")) { 17520 ast_copy_string(buf, peer->useragent, len); 17521 } else if (!strcasecmp(colname, "mailbox")) { 17522 struct ast_str *mailbox_str = ast_str_alloca(512); 17523 peer_mailboxes_to_str(&mailbox_str, peer); 17524 ast_copy_string(buf, mailbox_str->str, len); 17525 } else if (!strcasecmp(colname, "context")) { 17526 ast_copy_string(buf, peer->context, len); 17527 } else if (!strcasecmp(colname, "expire")) { 17528 snprintf(buf, len, "%d", peer->expire); 17529 } else if (!strcasecmp(colname, "dynamic")) { 17530 ast_copy_string(buf, peer->host_dynamic ? "yes" : "no", len); 17531 } else if (!strcasecmp(colname, "callerid_name")) { 17532 ast_copy_string(buf, peer->cid_name, len); 17533 } else if (!strcasecmp(colname, "callerid_num")) { 17534 ast_copy_string(buf, peer->cid_num, len); 17535 } else if (!strcasecmp(colname, "codecs")) { 17536 ast_getformatname_multiple(buf, len -1, peer->capability); 17537 } else if (!strncasecmp(colname, "chanvar[", 8)) { 17538 char *chanvar=colname + 8; 17539 struct ast_variable *v; 17540 17541 chanvar = strsep(&chanvar, "]"); 17542 for (v = peer->chanvars ; v ; v = v->next) { 17543 if (!strcasecmp(v->name, chanvar)) { 17544 ast_copy_string(buf, v->value, len); 17545 } 17546 } 17547 } else if (!strncasecmp(colname, "codec[", 6)) { 17548 char *codecnum; 17549 int codec = 0; 17550 17551 codecnum = colname + 6; /* move past the '[' */ 17552 codecnum = strsep(&codecnum, "]"); /* trim trailing ']' if any */ 17553 if((codec = ast_codec_pref_index(&peer->prefs, atoi(codecnum)))) { 17554 ast_copy_string(buf, ast_getformatname(codec), len); 17555 } else { 17556 buf[0] = '\0'; 17557 } 17558 } else { 17559 buf[0] = '\0'; 17560 } 17561 17562 unref_peer(peer, "unref_peer from function_sippeer, just before return"); 17563 17564 return 0; 17565 }
| static char * generate_random_string | ( | char * | buf, | |
| size_t | size | |||
| ) | [static] |
Generate 32 byte random string for callid's etc.
Definition at line 7192 of file chan_sip.c.
References ast_random().
Referenced by build_callid_pvt(), and build_callid_registry().
07193 { 07194 long val[4]; 07195 int x; 07196 07197 for (x=0; x<4; x++) 07198 val[x] = ast_random(); 07199 snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); 07200 07201 return buf; 07202 }
| static int get_also_info | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Call transfer support (old way, deprecated by the IETF).
Definition at line 13886 of file chan_sip.c.
References ast_canmatch_extension(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_uri_decode(), ast_verbose, context, sip_pvt::context, sip_settings::default_context, dialog_unref(), get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, ast_channel::macrocontext, sip_pvt::owner, pbx_builtin_getvar_helper(), sip_settings::pedanticsipchecking, sip_pvt::refer, sip_refer::refer_call, sip_refer::refer_contact, sip_refer::refer_to, sip_refer::refer_to_domain, sip_refer::referred_by, S_OR, sip_cfg, sip_debug_test_pvt(), and sip_refer_allocate().
Referenced by handle_request_bye().
13887 { 13888 char tmp[256] = "", *c, *a; 13889 struct sip_request *req = oreq ? oreq : &p->initreq; 13890 struct sip_refer *referdata = NULL; 13891 const char *transfer_context = NULL; 13892 13893 if (!p->refer && !sip_refer_allocate(p)) 13894 return -1; 13895 13896 referdata = p->refer; 13897 13898 ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp)); 13899 c = get_in_brackets(tmp); 13900 13901 if (sip_cfg.pedanticsipchecking) 13902 ast_uri_decode(c); 13903 13904 if (!strncasecmp(c, "sip:", 4)) { 13905 c += 4; 13906 } else if (!strncasecmp(c, "sips:", 5)) { 13907 c += 5; 13908 } else { 13909 ast_log(LOG_WARNING, "Huh? Not a SIP header in Also: transfer (%s)?\n", c); 13910 return -1; 13911 } 13912 13913 if ((a = strchr(c, ';'))) /* Remove arguments */ 13914 *a = '\0'; 13915 13916 if ((a = strchr(c, '@'))) { /* Separate Domain */ 13917 *a++ = '\0'; 13918 ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain)); 13919 } 13920 13921 if (sip_debug_test_pvt(p)) 13922 ast_verbose("Looking for %s in %s\n", c, p->context); 13923 13924 if (p->owner) /* Mimic behaviour in res_features.c */ 13925 transfer_context = pbx_builtin_getvar_helper(p->owner, "TRANSFER_CONTEXT"); 13926 13927 /* By default, use the context in the channel sending the REFER */ 13928 if (ast_strlen_zero(transfer_context)) { 13929 transfer_context = S_OR(p->owner->macrocontext, 13930 S_OR(p->context, sip_cfg.default_context)); 13931 } 13932 if (ast_exists_extension(NULL, transfer_context, c, 1, NULL)) { 13933 /* This is a blind transfer */ 13934 ast_debug(1, "SIP Bye-also transfer to Extension %s@%s \n", c, transfer_context); 13935 ast_copy_string(referdata->refer_to, c, sizeof(referdata->refer_to)); 13936 ast_copy_string(referdata->referred_by, "", sizeof(referdata->referred_by)); 13937 ast_copy_string(referdata->refer_contact, "", sizeof(referdata->refer_contact)); 13938 referdata->refer_call = dialog_unref(referdata->refer_call, "unreffing referdata->refer_call"); 13939 /* Set new context */ 13940 ast_string_field_set(p, context, transfer_context); 13941 return 0; 13942 } else if (ast_canmatch_extension(NULL, p->context, c, 1, NULL)) { 13943 return 1; 13944 } 13945 13946 return -1; 13947 }
| static char* get_body | ( | struct sip_request * | req, | |
| char * | name, | |||
| char | delimiter | |||
| ) | [static] |
Get a specific line from the message body.
Definition at line 6959 of file chan_sip.c.
References get_body_by_line(), sip_request::lines, and REQ_OFFSET_TO_STR.
Referenced by handle_request_info(), and handle_request_notify().
06960 { 06961 int x; 06962 int len = strlen(name); 06963 char *r; 06964 06965 for (x = 0; x < req->lines; x++) { 06966 r = get_body_by_line(REQ_OFFSET_TO_STR(req, line[x]), name, len, delimiter); 06967 if (r[0] != '\0') 06968 return r; 06969 } 06970 06971 return ""; 06972 }
| static char* get_body_by_line | ( | const char * | line, | |
| const char * | name, | |||
| int | nameLen, | |||
| char | delimiter | |||
| ) | [static] |
Reads one line of SIP message body.
Definition at line 6904 of file chan_sip.c.
References ast_skip_blanks().
Referenced by get_body(), and get_sdp_iterate().
06905 { 06906 if (!strncasecmp(line, name, nameLen) && line[nameLen] == delimiter) 06907 return ast_skip_blanks(line + nameLen + 1); 06908 06909 return ""; 06910 }
| static int get_cached_mwi | ( | struct sip_peer * | peer, | |
| int * | new, | |||
| int * | old | |||
| ) | [static] |
Get cached MWI info.
| 0 | At least one message is waiting | |
| 1 | no messages waiting |
Definition at line 22507 of file chan_sip.c.
References ast_event_destroy(), ast_event_get_cached(), ast_event_get_ie_uint(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, AST_LIST_TRAVERSE, sip_mailbox::context, sip_mailbox::mailbox, mailbox, sip_peer::mailboxes, and S_OR.
Referenced by sip_send_mwi_to_peer().
22508 { 22509 struct sip_mailbox *mailbox; 22510 22511 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 22512 struct ast_event *event; 22513 event = ast_event_get_cached(AST_EVENT_MWI, 22514 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox, 22515 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"), 22516 AST_EVENT_IE_END); 22517 if (!event) 22518 continue; 22519 *new += ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); 22520 *old += ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS); 22521 ast_event_destroy(event); 22522 } 22523 22524 return (*new || *old) ? 0 : 1; 22525 }
| static char * get_calleridname | ( | const char * | input, | |
| char * | output, | |||
| size_t | outputsize | |||
| ) | [static] |
Get caller id name from SIP headers.
Definition at line 14052 of file chan_sip.c.
References ast_copy_string(), and ast_skip_blanks().
Referenced by check_user_full().
14053 { 14054 const char *end = strchr(input, '<'); /* first_bracket */ 14055 const char *tmp = strchr(input, '"'); /* first quote */ 14056 int bytes = 0; 14057 int maxbytes = outputsize - 1; 14058 14059 if (!end || end == input) /* we require a part in brackets */ 14060 return NULL; 14061 14062 end--; /* move just before "<" */ 14063 14064 if (tmp && tmp <= end) { 14065 /* The quote (tmp) precedes the bracket (end+1). 14066 * Find the matching quote and return the content. 14067 */ 14068 end = strchr(tmp+1, '"'); 14069 if (!end) 14070 return NULL; 14071 bytes = (int) (end - tmp); 14072 /* protect the output buffer */ 14073 if (bytes > maxbytes) 14074 bytes = maxbytes; 14075 ast_copy_string(output, tmp + 1, bytes); 14076 } else { 14077 /* No quoted string, or it is inside brackets. */ 14078 /* clear the empty characters in the begining*/ 14079 input = ast_skip_blanks(input); 14080 /* clear the empty characters in the end */ 14081 while(*end && *end < 33 && end > input) 14082 end--; 14083 if (end >= input) { 14084 bytes = (int) (end - input) + 2; 14085 /* protect the output buffer */ 14086 if (bytes > maxbytes) 14087 bytes = maxbytes; 14088 ast_copy_string(output, input, bytes); 14089 } else 14090 return NULL; 14091 } 14092 return output; 14093 }
| static int get_destination | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Find out who the call is for. We use the request uri as a destination. This code assumes authentication has been done, so that the device (peer/user) context is already set.
Definition at line 13474 of file chan_sip.c.
References sip_settings::allow_external_domains, ast_canmatch_extension(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_get_hint(), AST_LIST_EMPTY, ast_log(), AST_MAX_EXTENSION, ast_pickup_ext(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_verbose, check_sip_domain(), sip_pvt::cid_num, sip_pvt::context, context, sip_pvt::domain, exten, sip_pvt::flags, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, sip_request::method, sip_settings::pedanticsipchecking, REQ_OFFSET_TO_STR, sip_request::rlPart2, S_OR, sip_cfg, sip_debug_test_pvt(), SIP_INVITE, sip_methods, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_HAVEPEERCONTEXT, SIP_REFER, SIP_SUBSCRIBE, strsep(), sip_pvt::subscribecontext, and cfsip_methods::text.
Referenced by handle_request_invite(), handle_request_options(), and handle_request_subscribe().
13475 { 13476 char tmp[256] = "", *uri, *a; 13477 char tmpf[256] = "", *from = NULL; 13478 struct sip_request *req; 13479 char *colon; 13480 char *decoded_uri; 13481 13482 req = oreq; 13483 if (!req) 13484 req = &p->initreq; 13485 13486 /* Find the request URI */ 13487 if (req->rlPart2) 13488 ast_copy_string(tmp, REQ_OFFSET_TO_STR(req, rlPart2), sizeof(tmp)); 13489 13490 if (sip_cfg.pedanticsipchecking) 13491 ast_uri_decode(tmp); 13492 13493 uri = get_in_brackets(tmp); 13494 13495 if (!strncasecmp(uri, "sip:", 4)) { 13496 uri += 4; 13497 } else if (!strncasecmp(uri, "sips:", 5)) { 13498 uri += 5; 13499 } else { 13500 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", uri); 13501 return -1; 13502 } 13503 13504 /* Now find the From: caller ID and name */ 13505 /* XXX Why is this done in get_destination? Isn't it already done? 13506 Needs to be checked 13507 */ 13508 ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf)); 13509 if (!ast_strlen_zero(tmpf)) { 13510 if (sip_cfg.pedanticsipchecking) 13511 ast_uri_decode(tmpf); 13512 from = get_in_brackets(tmpf); 13513 } 13514 13515 if (!ast_strlen_zero(from)) { 13516 if (!strncasecmp(from, "sip:", 4)) { 13517 from += 4; 13518 } else if (!strncasecmp(from, "sips:", 5)) { 13519 from += 5; 13520 } else { 13521 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", from); 13522 return -1; 13523 } 13524 if ((a = strchr(from, '@'))) 13525 *a++ = '\0'; 13526 else 13527 a = from; /* just a domain */ 13528 from = strsep(&from, ";"); /* Remove userinfo options */ 13529 a = strsep(&a, ";"); /* Remove URI options */ 13530 ast_string_field_set(p, fromdomain, a); 13531 } 13532 13533 /* Skip any options and find the domain */ 13534 13535 /* Get the target domain */ 13536 if ((a = strchr(uri, '@'))) { 13537 *a++ = '\0'; 13538 } else { /* No username part */ 13539 a = uri; 13540 uri = "s"; /* Set extension to "s" */ 13541 } 13542 colon = strchr(a, ':'); /* Remove :port */ 13543 if (colon) 13544 *colon = '\0'; 13545 13546 uri = strsep(&uri, ";"); /* Remove userinfo options */ 13547 a = strsep(&a, ";"); /* Remove URI options */ 13548 13549 ast_string_field_set(p, domain, a); 13550 13551 if (!AST_LIST_EMPTY(&domain_list)) { 13552 char domain_context[AST_MAX_EXTENSION]; 13553 13554 domain_context[0] = '\0'; 13555 if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) { 13556 if (!sip_cfg.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) { 13557 ast_debug(1, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain); 13558 return -2; 13559 } 13560 } 13561 /* If we don't have a peer (i.e. we're a guest call), 13562 * overwrite the original context */ 13563 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_HAVEPEERCONTEXT) && !ast_strlen_zero(domain_context)) 13564 ast_string_field_set(p, context, domain_context); 13565 } 13566 13567 /* If the request coming in is a subscription and subscribecontext has been specified use it */ 13568 if (req->method == SIP_SUBSCRIBE && !ast_strlen_zero(p->subscribecontext)) 13569 ast_string_field_set(p, context, p->subscribecontext); 13570 13571 if (sip_debug_test_pvt(p)) 13572 ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain); 13573 13574 /* Since extensions.conf can have unescaped characters, try matching a 13575 * decoded uri in addition to the non-decoded uri. */ 13576 decoded_uri = ast_strdupa(uri); 13577 ast_uri_decode(decoded_uri); 13578 13579 /* If this is a subscription we actually just need to see if a hint exists for the extension */ 13580 if (req->method == SIP_SUBSCRIBE) { 13581 char hint[AST_MAX_EXTENSION]; 13582 int which = 0; 13583 if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, uri) || 13584 (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, decoded_uri) && (which = 1))) { 13585 if (!oreq) { 13586 ast_string_field_set(p, exten, which ? decoded_uri : uri); 13587 } 13588 return 0; 13589 } else { 13590 return -1; 13591 } 13592 } else { 13593 int which = 0; 13594 /* Check the dialplan for the username part of the request URI, 13595 the domain will be stored in the SIPDOMAIN variable 13596 Return 0 if we have a matching extension */ 13597 if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) || 13598 (ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) && (which = 1)) || 13599 !strcmp(decoded_uri, ast_pickup_ext())) { 13600 if (!oreq) { 13601 ast_string_field_set(p, exten, which ? decoded_uri : uri); 13602 } 13603 return 0; 13604 } 13605 } 13606 13607 /* Return 1 for pickup extension or overlap dialling support (if we support it) */ 13608 if((ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) && 13609 ast_canmatch_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from))) || 13610 !strncmp(decoded_uri, ast_pickup_ext(), strlen(decoded_uri))) { 13611 return 1; 13612 } 13613 13614 return -1; 13615 }
| static const char * get_header | ( | const struct sip_request * | req, | |
| const char * | name | |||
| ) | [static] |
Get header from SIP request.
Definition at line 7052 of file chan_sip.c.
References __get_header().
Referenced by __transmit_response(), _sip_tcp_helper_thread(), build_route(), check_auth(), check_user_full(), check_via(), check_via_response(), copy_header(), extract_uri(), find_call(), find_sdp(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), gettag(), handle_incoming(), handle_request_bye(), handle_request_do(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), proc_422_rsp(), receive_message(), register_verify(), reply_digest(), reqprep(), respprep(), send_request(), send_response(), sip_sipredirect(), transmit_fake_auth_response(), transmit_refer(), transmit_response_with_auth(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_state_notify().
07053 { 07054 int start = 0; 07055 return __get_header(req, name, &start); 07056 }
| static char * get_in_brackets | ( | char * | tmp | ) | [static] |
Pick out text in brackets from character string.
| tmp | input string that will be modified Examples: "foo" <bar> valid input, returns bar foo returns the whole string < "foo ... > returns the string between brackets < "foo... bogus (missing closing bracket), returns the whole string XXX maybe should still skip the opening bracket |
Definition at line 4398 of file chan_sip.c.
References ast_log(), find_closing_quote(), LOG_WARNING, and parse().
Referenced by check_user_full(), extract_uri(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), register_verify(), reqprep(), transmit_refer(), and transmit_state_notify().
04399 { 04400 const char *parse = tmp; 04401 char *first_bracket; 04402 04403 /* 04404 * Skip any quoted text until we find the part in brackets. 04405 * On any error give up and return the full string. 04406 */ 04407 while ( (first_bracket = strchr(parse, '<')) ) { 04408 char *first_quote = strchr(parse, '"'); 04409 04410 if (!first_quote || first_quote > first_bracket) 04411 break; /* no need to look at quoted part */ 04412 /* the bracket is within quotes, so ignore it */ 04413 parse = find_closing_quote(first_quote + 1, NULL); 04414 if (!*parse) { /* not found, return full string ? */ 04415 /* XXX or be robust and return in-bracket part ? */ 04416 ast_log(LOG_WARNING, "No closing quote found in '%s'\n", tmp); 04417 break; 04418 } 04419 parse++; 04420 } 04421 if (first_bracket) { 04422 char *second_bracket = strchr(first_bracket + 1, '>'); 04423 if (second_bracket) { 04424 *second_bracket = '\0'; 04425 tmp = first_bracket + 1; 04426 } else { 04427 ast_log(LOG_WARNING, "No closing bracket found in '%s'\n", tmp); 04428 } 04429 } 04430 04431 return tmp; 04432 }
| static struct ast_variable * get_insecure_variable_from_config | ( | struct ast_config * | config | ) | [static, read] |
Definition at line 4770 of file chan_sip.c.
References ast_category_browse(), ast_category_root(), ast_test_flag, ast_variable_retrieve(), set_insecure_flags(), SIP_INSECURE_PORT, and var.
Referenced by realtime_peer().
04771 { 04772 struct ast_variable *var = NULL; 04773 struct ast_flags flags = {0}; 04774 char *cat = NULL; 04775 const char *insecure; 04776 while ((cat = ast_category_browse(cfg, cat))) { 04777 insecure = ast_variable_retrieve(cfg, cat, "insecure"); 04778 set_insecure_flags(&flags, insecure, -1); 04779 if (ast_test_flag(&flags, SIP_INSECURE_PORT)) { 04780 var = ast_category_root(cfg, cat); 04781 break; 04782 } 04783 } 04784 return var; 04785 }
| static int get_ip_and_port_from_sdp | ( | struct sip_request * | req, | |
| const enum media_type | media, | |||
| struct sockaddr_in * | sin | |||
| ) | [static] |
Definition at line 8122 of file chan_sip.c.
References ast_gethostbyname(), ast_log(), ast_strlen_zero(), get_sdp_iterate(), hp, LOG_WARNING, SDP_AUDIO, sip_request::sdp_start, and SDP_VIDEO.
Referenced by handle_request_invite().
08123 { 08124 const char *m; 08125 const char *c; 08126 int miterator = req->sdp_start; 08127 int citerator = req->sdp_start; 08128 int x = 0; 08129 int numberofports; 08130 int len; 08131 char host[258] = ""; /*Initialize to empty so we will know if we have any input */ 08132 struct ast_hostent audiohp; 08133 struct hostent *hp; 08134 08135 c = get_sdp_iterate(&citerator, req, "c"); 08136 if (sscanf(c, "IN IP4 %256s", host) != 1) { 08137 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 08138 /* Continue since there may be a valid host in a c= line specific to the audio stream */ 08139 } 08140 /* We only want the m and c lines for audio */ 08141 for (m = get_sdp_iterate(&miterator, req, "m"); !ast_strlen_zero(m); m = get_sdp_iterate(&miterator, req, "m")) { 08142 if ((media == SDP_AUDIO && ((sscanf(m, "audio %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08143 (sscanf(m, "audio %30u RTP/AVP %n", &x, &len) == 1 && len > 0))) || 08144 (media == SDP_VIDEO && ((sscanf(m, "video %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08145 (sscanf(m, "video %30u RTP/AVP %n", &x, &len) == 1 && len > 0)))) { 08146 /* See if there's a c= line for this media stream. 08147 * XXX There is no guarantee that we'll be grabbing the c= line for this 08148 * particular media stream here. However, this is the same logic used in process_sdp. 08149 */ 08150 c = get_sdp_iterate(&citerator, req, "c"); 08151 if (!ast_strlen_zero(c)) { 08152 sscanf(c, "IN IP4 %256s", host); 08153 } 08154 break; 08155 } 08156 } 08157 08158 if (ast_strlen_zero(host) || x == 0) { 08159 ast_log(LOG_WARNING, "Failed to read an alternate host or port in SDP. Expect %s problems\n", media == SDP_AUDIO ? "audio" : "video"); 08160 return -1; 08161 } 08162 08163 hp = ast_gethostbyname(host, &audiohp); 08164 if (!hp) { 08165 ast_log(LOG_WARNING, "Could not look up IP address of alternate hostname. Expect %s problems\n", media == SDP_AUDIO? "audio" : "video"); 08166 return -1; 08167 } 08168 08169 memcpy(&sin->sin_addr, hp->h_addr, sizeof(sin->sin_addr)); 08170 sin->sin_port = htons(x); 08171 return 0; 08172 }
| static int get_msg_text | ( | char * | buf, | |
| int | len, | |||
| struct sip_request * | req, | |||
| int | addnewline | |||
| ) | [static] |
Get text out of a SIP MESSAGE packet.
Definition at line 14429 of file chan_sip.c.
References sip_request::lines, and REQ_OFFSET_TO_STR.
Referenced by handle_request_info(), handle_request_notify(), and receive_message().
14430 { 14431 int x; 14432 int y; 14433 14434 buf[0] = '\0'; 14435 /*XXX isn't strlen(buf) going to always be 0? */ 14436 y = len - strlen(buf) - 5; 14437 if (y < 0) 14438 y = 0; 14439 for (x = 0; x < req->lines; x++) { 14440 char *line = REQ_OFFSET_TO_STR(req, line[x]); 14441 strncat(buf, line, y); /* safe */ 14442 y -= strlen(line) + 1; 14443 if (y < 0) 14444 y = 0; 14445 if (y != 0 && addnewline) 14446 strcat(buf, "\n"); /* safe */ 14447 } 14448 return 0; 14449 }
| static const char * get_name_from_variable | ( | struct ast_variable * | var, | |
| const char * | newpeername | |||
| ) | [static] |
Definition at line 4787 of file chan_sip.c.
References ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by realtime_peer().
04788 { 04789 struct ast_variable *tmp; 04790 for (tmp = var; tmp; tmp = tmp->next) { 04791 if (!newpeername && !strcasecmp(tmp->name, "name")) 04792 newpeername = tmp->value; 04793 } 04794 return newpeername; 04795 }
| static void get_our_media_address | ( | struct sip_pvt * | p, | |
| int | needvideo, | |||
| struct sockaddr_in * | sin, | |||
| struct sockaddr_in * | vsin, | |||
| struct sockaddr_in * | tsin, | |||
| struct sockaddr_in * | dest, | |||
| struct sockaddr_in * | vdest | |||
| ) | [static] |
Set all IP media addresses for this call.
Definition at line 10154 of file chan_sip.c.
References ast_rtp_get_us(), sip_pvt::ourip, sip_pvt::redirip, sip_pvt::rtp, sip_pvt::trtp, sip_pvt::vredirip, and sip_pvt::vrtp.
Referenced by add_sdp().
10157 { 10158 /* First, get our address */ 10159 ast_rtp_get_us(p->rtp, sin); 10160 if (p->vrtp) 10161 ast_rtp_get_us(p->vrtp, vsin); 10162 if (p->trtp) 10163 ast_rtp_get_us(p->trtp, tsin); 10164 10165 /* Now, try to figure out where we want them to send data */ 10166 /* Is this a re-invite to move the media out, then use the original offer from caller */ 10167 if (p->redirip.sin_addr.s_addr) { /* If we have a redirection IP, use it */ 10168 dest->sin_port = p->redirip.sin_port; 10169 dest->sin_addr = p->redirip.sin_addr; 10170 } else { 10171 dest->sin_addr = p->ourip.sin_addr; 10172 dest->sin_port = sin->sin_port; 10173 } 10174 if (needvideo) { 10175 /* Determine video destination */ 10176 if (p->vredirip.sin_addr.s_addr) { 10177 vdest->sin_addr = p->vredirip.sin_addr; 10178 vdest->sin_port = p->vredirip.sin_port; 10179 } else { 10180 vdest->sin_addr = p->ourip.sin_addr; 10181 vdest->sin_port = vsin->sin_port; 10182 } 10183 } 10184 10185 }
| static int get_rdnis | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Get referring dnis.
Definition at line 13400 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_string_field_set, ast_strip_quoted(), ast_strlen_zero(), ast_verbose, exten, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::redircause, sip_debug_test_pvt(), sip_set_redirstr(), strcasestr(), and strsep().
Referenced by handle_request_invite().
13401 { 13402 char tmp[256], *exten, *rexten, *rdomain; 13403 char *params, *reason = NULL; 13404 struct sip_request *req; 13405 13406 req = oreq ? oreq : &p->initreq; 13407 13408 ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp)); 13409 if (ast_strlen_zero(tmp)) 13410 return 0; 13411 13412 /*! \todo This function does not take user-parameters into consideration. 13413 First look for @, then start looking for ; to find uri-parameters. 13414 */ 13415 params = strchr(tmp, ';'); 13416 13417 exten = get_in_brackets(tmp); 13418 if (!strncasecmp(exten, "sip:", 4)) { 13419 exten += 4; 13420 } else if (!strncasecmp(exten, "sips:", 5)) { 13421 exten += 5; 13422 } else { 13423 ast_log(LOG_WARNING, "Huh? Not an RDNIS SIP header (%s)?\n", exten); 13424 return -1; 13425 } 13426 13427 /* Get diversion-reason param if present */ 13428 if (params) { 13429 *params = '\0'; /* Cut off parameters */ 13430 params++; 13431 while (*params == ';' || *params == ' ') 13432 params++; 13433 /* Check if we have a reason parameter */ 13434 if ((reason = strcasestr(params, "reason="))) { 13435 reason+=7; 13436 /* Remove enclosing double-quotes */ 13437 if (*reason == '"') 13438 ast_strip_quoted(reason, "\"", "\""); 13439 if (!ast_strlen_zero(reason)) { 13440 sip_set_redirstr(p, reason); 13441 if (p->owner) { 13442 pbx_builtin_setvar_helper(p->owner, "__PRIREDIRECTREASON", p->redircause); 13443 pbx_builtin_setvar_helper(p->owner, "__SIPREDIRECTREASON", reason); 13444 } 13445 } 13446 } 13447 } 13448 13449 rdomain = exten; 13450 rexten = strsep(&rdomain, "@"); /* trim anything after @ */ 13451 if (p->owner) 13452 pbx_builtin_setvar_helper(p->owner, "__SIPRDNISDOMAIN", rdomain); 13453 13454 if (sip_debug_test_pvt(p)) 13455 ast_verbose("RDNIS for this call is is %s (reason %s)\n", exten, reason ? reason : ""); 13456 13457 ast_string_field_set(p, rdnis, rexten); 13458 13459 return 0; 13460 }
| static int get_refer_info | ( | struct sip_pvt * | transferer, | |
| struct sip_request * | outgoing_req | |||
| ) | [static] |
Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure.
Definition at line 13708 of file chan_sip.c.
References ast_bridged_channel(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_uri_decode(), ast_verbose, sip_refer::attendedtransfer, sip_pvt::context, sip_settings::default_context, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, ast_channel::macrocontext, sip_pvt::owner, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), sip_settings::pedanticsipchecking, sip_pvt::refer, sip_refer::refer_to, sip_refer::refer_to_context, sip_refer::refer_to_domain, sip_refer::refer_to_urioption, sip_refer::referred_by, sip_refer::referred_by_name, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, S_OR, sip_cfg, sip_debug_test_pvt(), and strcasestr().
Referenced by handle_request_refer().
13709 { 13710 13711 const char *p_referred_by = NULL; 13712 char *h_refer_to = NULL; 13713 char *h_referred_by = NULL; 13714 char *refer_to; 13715 const char *p_refer_to; 13716 char *referred_by_uri = NULL; 13717 char *ptr; 13718 struct sip_request *req = NULL; 13719 const char *transfer_context = NULL; 13720 struct sip_refer *referdata; 13721 13722 13723 req = outgoing_req; 13724 referdata = transferer->refer; 13725 13726 if (!req) 13727 req = &transferer->initreq; 13728 13729 p_refer_to = get_header(req, "Refer-To"); 13730 if (ast_strlen_zero(p_refer_to)) { 13731 ast_log(LOG_WARNING, "Refer-To Header missing. Skipping transfer.\n"); 13732 return -2; /* Syntax error */ 13733 } 13734 h_refer_to = ast_strdupa(p_refer_to); 13735 refer_to = get_in_brackets(h_refer_to); 13736 if (sip_cfg.pedanticsipchecking) 13737 ast_uri_decode(refer_to); 13738 13739 if (!strncasecmp(refer_to, "sip:", 4)) { 13740 refer_to += 4; /* Skip sip: */ 13741 } else if (!strncasecmp(refer_to, "sips:", 5)) { 13742 refer_to += 5; 13743 } else { 13744 ast_log(LOG_WARNING, "Can't transfer to non-sip: URI. (Refer-to: %s)?\n", refer_to); 13745 return -3; 13746 } 13747 13748 /* Get referred by header if it exists */ 13749 p_referred_by = get_header(req, "Referred-By"); 13750 13751 /* Give useful transfer information to the dialplan */ 13752 if (transferer->owner) { 13753 struct ast_channel *peer = ast_bridged_channel(transferer->owner); 13754 if (peer) { 13755 pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT", transferer->context); 13756 pbx_builtin_setvar_helper(peer, "SIPREFERREDBYHDR", p_referred_by); 13757 } 13758 } 13759 13760 if (!ast_strlen_zero(p_referred_by)) { 13761 char *lessthan; 13762 h_referred_by = ast_strdupa(p_referred_by); 13763 if (sip_cfg.pedanticsipchecking) 13764 ast_uri_decode(h_referred_by); 13765 13766 /* Store referrer's caller ID name */ 13767 ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name)); 13768 if ((lessthan = strchr(referdata->referred_by_name, '<'))) { 13769 *(lessthan - 1) = '\0'; /* Space */ 13770 } 13771 13772 referred_by_uri = get_in_brackets(h_referred_by); 13773 if (!strncasecmp(referred_by_uri, "sip:", 4)) { 13774 referred_by_uri += 4; /* Skip sip: */ 13775 } else if (!strncasecmp(referred_by_uri, "sips:", 5)) { 13776 referred_by_uri += 5; /* Skip sips: */ 13777 } else { 13778 ast_log(LOG_WARNING, "Huh? Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri); 13779 referred_by_uri = NULL; 13780 } 13781 } 13782 13783 /* Check for arguments in the refer_to header */ 13784 if ((ptr = strcasestr(refer_to, "replaces="))) { 13785 char *to = NULL, *from = NULL; 13786 13787 /* This is an attended transfer */ 13788 referdata->attendedtransfer = 1; 13789 ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid)); 13790 ast_uri_decode(referdata->replaces_callid); 13791 if ((ptr = strchr(referdata->replaces_callid, ';'))) /* Find options */ { 13792 *ptr++ = '\0'; 13793 } 13794 13795 if (ptr) { 13796 /* Find the different tags before we destroy the string */ 13797 to = strcasestr(ptr, "to-tag="); 13798 from = strcasestr(ptr, "from-tag="); 13799 } 13800 13801 /* Grab the to header */ 13802 if (to) { 13803 ptr = to + 7; 13804 if ((to = strchr(ptr, '&'))) 13805 *to = '\0'; 13806 if ((to = strchr(ptr, ';'))) 13807 *to = '\0'; 13808 ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag)); 13809 } 13810 13811 if (from) { 13812 ptr = from + 9; 13813 if ((to = strchr(ptr, '&'))) 13814 *to = '\0'; 13815 if ((to = strchr(ptr, ';'))) 13816 *to = '\0'; 13817 ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag)); 13818 } 13819 13820 if (!sip_cfg.pedanticsipchecking) 13821 ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid ); 13822 else 13823 ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s F-tag: %s T-tag: %s\n", referdata->replaces_callid, referdata->replaces_callid_fromtag ? referdata->replaces_callid_fromtag : "<none>", referdata->replaces_callid_totag ? referdata->replaces_callid_totag : "<none>" ); 13824 } 13825 13826 if ((ptr = strchr(refer_to, '@'))) { /* Separate domain */ 13827 char *urioption = NULL, *domain; 13828 *ptr++ = '\0'; 13829 13830 if ((urioption = strchr(ptr, ';'))) /* Separate urioptions */ 13831 *urioption++ = '\0'; 13832 13833 domain = ptr; 13834 if ((ptr = strchr(domain, ':'))) /* Remove :port */ 13835 *ptr = '\0'; 13836 13837 /* Save the domain for the dial plan */ 13838 ast_copy_string(referdata->refer_to_domain, domain, sizeof(referdata->refer_to_domain)); 13839 if (urioption) 13840 ast_copy_string(referdata->refer_to_urioption, urioption, sizeof(referdata->refer_to_urioption)); 13841 } 13842 13843 if ((ptr = strchr(refer_to, ';'))) /* Remove options */ 13844 *ptr = '\0'; 13845 ast_copy_string(referdata->refer_to, refer_to, sizeof(referdata->refer_to)); 13846 13847 if (referred_by_uri) { 13848 if ((ptr = strchr(referred_by_uri, ';'))) /* Remove options */ 13849 *ptr = '\0'; 13850 ast_copy_string(referdata->referred_by, referred_by_uri, sizeof(referdata->referred_by)); 13851 } else { 13852 referdata->referred_by[0] = '\0'; 13853 } 13854 13855 /* Determine transfer context */ 13856 if (transferer->owner) /* Mimic behaviour in res_features.c */ 13857 transfer_context = pbx_builtin_getvar_helper(transferer->owner, "TRANSFER_CONTEXT"); 13858 13859 /* By default, use the context in the channel sending the REFER */ 13860 if (ast_strlen_zero(transfer_context)) { 13861 transfer_context = S_OR(transferer->owner->macrocontext, 13862 S_OR(transferer->context, sip_cfg.default_context)); 13863 } 13864 13865 ast_copy_string(referdata->refer_to_context, transfer_context, sizeof(referdata->refer_to_context)); 13866 13867 /* Either an existing extension or the parking extension */ 13868 if (referdata->attendedtransfer || ast_exists_extension(NULL, transfer_context, refer_to, 1, NULL) ) { 13869 if (sip_debug_test_pvt(transferer)) { 13870 ast_verbose("SIP transfer to extension %s@%s by %s\n", refer_to, transfer_context, referred_by_uri); 13871 } 13872 /* We are ready to transfer to the extension */ 13873 return 0; 13874 } 13875 if (sip_debug_test_pvt(transferer)) 13876 ast_verbose("Failed SIP Transfer to non-existing extension %s in context %s\n n", refer_to, transfer_context); 13877 13878 /* Failure, we can't find this extension */ 13879 return -1; 13880 }
| static int get_rpid_num | ( | const char * | input, | |
| char * | output, | |||
| int | maxlen | |||
| ) | [static] |
Get caller id number from Remote-Party-ID header field Returns true if number should be restricted (privacy setting found) output is set to NULL if no number found.
Definition at line 14099 of file chan_sip.c.
References ast_copy_string(), and AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED.
Referenced by check_user_full().
14100 { 14101 char *start; 14102 char *end; 14103 14104 start = strchr(input, ':'); 14105 if (!start) { 14106 output[0] = '\0'; 14107 return 0; 14108 } 14109 start++; 14110 14111 /* we found "number" */ 14112 ast_copy_string(output, start, maxlen); 14113 output[maxlen-1] = '\0'; 14114 14115 end = strchr(output, '@'); 14116 if (end) 14117 *end = '\0'; 14118 else 14119 output[0] = '\0'; 14120 if (strstr(input, "privacy=full") || strstr(input, "privacy=uri")) 14121 return AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; 14122 14123 return 0; 14124 }
| static const char * get_sdp_iterate | ( | int * | start, | |
| struct sip_request * | req, | |||
| const char * | name | |||
| ) | [static] |
Lookup 'name' in the SDP starting at the 'start' line. Returns the matching line, and 'start' is updated with the next line number.
Definition at line 6916 of file chan_sip.c.
References get_body_by_line(), REQ_OFFSET_TO_STR, sip_request::sdp_count, and sip_request::sdp_start.
Referenced by get_ip_and_port_from_sdp(), and process_sdp().
06917 { 06918 int len = strlen(name); 06919 06920 while (*start < (req->sdp_start + req->sdp_count)) { 06921 const char *r = get_body_by_line(REQ_OFFSET_TO_STR(req, line[(*start)++]), name, len, '='); 06922 if (r[0] != '\0') 06923 return r; 06924 } 06925 06926 /* if the line was not found, ensure that *start points past the SDP */ 06927 (*start)++; 06928 06929 return ""; 06930 }
| static char get_sdp_line | ( | int * | start, | |
| int | stop, | |||
| struct sip_request * | req, | |||
| const char ** | value | |||
| ) | [static] |
Fetches the next valid SDP line between the 'start' line (inclusive) and the 'stop' line (exclusive). Returns the type ('a', 'c', ...) and matching line in reference 'start' is updated with the next line number.
Definition at line 6937 of file chan_sip.c.
References ast_skip_blanks(), REQ_OFFSET_TO_STR, sip_request::sdp_count, and sip_request::sdp_start.
Referenced by process_sdp().
06938 { 06939 char type = '\0'; 06940 const char *line = NULL; 06941 06942 if (stop > (req->sdp_start + req->sdp_count)) { 06943 stop = req->sdp_start + req->sdp_count; 06944 } 06945 06946 while (*start < stop) { 06947 line = REQ_OFFSET_TO_STR(req, line[(*start)++]); 06948 if (line[1] == '=') { 06949 type = line[0]; 06950 *value = ast_skip_blanks(line + 2); 06951 break; 06952 } 06953 } 06954 06955 return type; 06956 }
| static struct sip_pvt * get_sip_pvt_byid_locked | ( | const char * | callid, | |
| const char * | totag, | |||
| const char * | fromtag | |||
| ) | [static, read] |
Lock dialog lock and find matching pvt lock.
Definition at line 13620 of file chan_sip.c.
References ao2_t_find, ast_channel_trylock, ast_debug, ast_strlen_zero(), sip_pvt::callid, OBJ_POINTER, sip_pvt::outgoing_call, sip_pvt::owner, sip_settings::pedanticsipchecking, sip_cfg, sip_pvt_lock, sip_pvt_unlock, sip_pvt::tag, sip_pvt::theirtag, and TRUE.
Referenced by handle_request_invite(), and local_attended_transfer().
13621 { 13622 struct sip_pvt *sip_pvt_ptr; 13623 struct sip_pvt tmp_dialog = { 13624 .callid = callid, 13625 }; 13626 13627 if (totag) 13628 ast_debug(4, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>"); 13629 13630 /* Search dialogs and find the match */ 13631 13632 sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table"); 13633 if (sip_pvt_ptr) { 13634 /* Go ahead and lock it (and its owner) before returning */ 13635 sip_pvt_lock(sip_pvt_ptr); 13636 if (sip_cfg.pedanticsipchecking) { 13637 unsigned char frommismatch = 0, tomismatch = 0; 13638 13639 if (ast_strlen_zero(fromtag)) { 13640 sip_pvt_unlock(sip_pvt_ptr); 13641 ast_debug(4, "Matched %s call for callid=%s - no from tag specified, pedantic check fails\n", 13642 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid); 13643 return NULL; 13644 } 13645 13646 if (ast_strlen_zero(totag)) { 13647 sip_pvt_unlock(sip_pvt_ptr); 13648 ast_debug(4, "Matched %s call for callid=%s - no to tag specified, pedantic check fails\n", 13649 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid); 13650 return NULL; 13651 } 13652 /* RFC 3891 13653 * > 3. User Agent Server Behavior: Receiving a Replaces Header 13654 * > The Replaces header contains information used to match an existing 13655 * > SIP dialog (call-id, to-tag, and from-tag). Upon receiving an INVITE 13656 * > with a Replaces header, the User Agent (UA) attempts to match this 13657 * > information with a confirmed or early dialog. The User Agent Server 13658 * > (UAS) matches the to-tag and from-tag parameters as if they were tags 13659 * > present in an incoming request. In other words, the to-tag parameter 13660 * > is compared to the local tag, and the from-tag parameter is compared 13661 * > to the remote tag. 13662 * 13663 * Thus, the totag is always compared to the local tag, regardless if 13664 * this our call is an incoming or outgoing call. 13665 */ 13666 frommismatch = !!strcmp(fromtag, sip_pvt_ptr->theirtag); 13667 tomismatch = !!strcmp(totag, sip_pvt_ptr->tag); 13668 13669 if (frommismatch || tomismatch) { 13670 sip_pvt_unlock(sip_pvt_ptr); 13671 if (frommismatch) { 13672 ast_debug(4, "Matched %s call for callid=%s - pedantic from tag check fails; their tag is %s our tag is %s\n", 13673 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid, 13674 fromtag, sip_pvt_ptr->theirtag); 13675 } 13676 if (tomismatch) { 13677 ast_debug(4, "Matched %s call for callid=%s - pedantic to tag check fails; their tag is %s our tag is %s\n", 13678 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid, 13679 totag, sip_pvt_ptr->tag); 13680 } 13681 return NULL; 13682 } 13683 } 13684 13685 if (totag) 13686 ast_debug(4, "Matched %s call - their tag is %s Our tag is %s\n", 13687 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", 13688 sip_pvt_ptr->theirtag, sip_pvt_ptr->tag); 13689 13690 /* deadlock avoidance... */ 13691 while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) { 13692 sip_pvt_unlock(sip_pvt_ptr); 13693 usleep(1); 13694 sip_pvt_lock(sip_pvt_ptr); 13695 } 13696 } 13697 13698 return sip_pvt_ptr; 13699 }
| static const char* get_srv_protocol | ( | enum sip_transport | t | ) | [inline, static] |
Return protocol string for srv dns query.
Definition at line 3553 of file chan_sip.c.
References SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and SIP_TRANSPORT_UDP.
Referenced by __sip_subscribe_mwi_do(), build_peer(), create_addr(), and transmit_register().
03554 { 03555 switch (t) { 03556 case SIP_TRANSPORT_UDP: 03557 return "udp"; 03558 case SIP_TRANSPORT_TLS: 03559 case SIP_TRANSPORT_TCP: 03560 return "tcp"; 03561 } 03562 03563 return "udp"; 03564 }
| static const char* get_srv_service | ( | enum sip_transport | t | ) | [inline, static] |
Return service string for srv dns query.
Definition at line 3567 of file chan_sip.c.
References SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and SIP_TRANSPORT_UDP.
Referenced by __sip_subscribe_mwi_do(), build_peer(), create_addr(), and transmit_register().
03568 { 03569 switch (t) { 03570 case SIP_TRANSPORT_TCP: 03571 case SIP_TRANSPORT_UDP: 03572 return "sip"; 03573 case SIP_TRANSPORT_TLS: 03574 return "sips"; 03575 } 03576 return "sip"; 03577 }
| static const char* get_transport | ( | enum sip_transport | t | ) | [inline, static] |
Return transport as string.
Definition at line 3538 of file chan_sip.c.
References SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and SIP_TRANSPORT_UDP.
Referenced by _sip_show_peer(), ast_sip_ouraddrfor(), build_contact(), get_transport_pvt(), handle_request_do(), parse_moved_contact(), sip_show_settings(), sip_show_tcp(), and transmit_notify_with_mwi().
03539 { 03540 switch (t) { 03541 case SIP_TRANSPORT_UDP: 03542 return "UDP"; 03543 case SIP_TRANSPORT_TCP: 03544 return "TCP"; 03545 case SIP_TRANSPORT_TLS: 03546 return "TLS"; 03547 } 03548 03549 return "UNKNOWN"; 03550 }
| static const char* get_transport_list | ( | unsigned int | transports | ) | [inline, static] |
Return configuration of transports for a device.
Definition at line 3517 of file chan_sip.c.
References SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and SIP_TRANSPORT_UDP.
Referenced by _sip_show_peer(), and sip_show_settings().
03517 { 03518 switch (transports) { 03519 case SIP_TRANSPORT_UDP: 03520 return "UDP"; 03521 case SIP_TRANSPORT_TCP: 03522 return "TCP"; 03523 case SIP_TRANSPORT_TLS: 03524 return "TLS"; 03525 case SIP_TRANSPORT_UDP | SIP_TRANSPORT_TCP: 03526 return "TCP,UDP"; 03527 case SIP_TRANSPORT_UDP | SIP_TRANSPORT_TLS: 03528 return "TLS,UDP"; 03529 case SIP_TRANSPORT_TCP | SIP_TRANSPORT_TLS: 03530 return "TLS,TCP"; 03531 default: 03532 return transports ? 03533 "TLS,TCP,UDP" : "UNKNOWN"; 03534 } 03535 }
| static const char* get_transport_pvt | ( | struct sip_pvt * | p | ) | [inline, static] |
Return transport of dialog.
Definition at line 3585 of file chan_sip.c.
References get_transport(), sip_pvt::outboundproxy, set_socket_transport(), sip_pvt::socket, sip_proxy::transport, and sip_socket::type.
Referenced by __sip_xmit(), and build_via().
03586 { 03587 if (p->outboundproxy && p->outboundproxy->transport) { 03588 set_socket_transport(&p->socket, p->outboundproxy->transport); 03589 } 03590 03591 return get_transport(p->socket.type); 03592 }
| static int get_transport_str2enum | ( | const char * | transport | ) | [static] |
Return int representing a bit field of transport types found in const char *transport.
Definition at line 3495 of file chan_sip.c.
References ast_strlen_zero(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and SIP_TRANSPORT_UDP.
Referenced by __set_address_from_contact(), and parse_register_contact().
03496 { 03497 int res = 0; 03498 03499 if (ast_strlen_zero(transport)) { 03500 return res; 03501 } 03502 03503 if (!strcasecmp(transport, "udp")) { 03504 res |= SIP_TRANSPORT_UDP; 03505 } 03506 if (!strcasecmp(transport, "tcp")) { 03507 res |= SIP_TRANSPORT_TCP; 03508 } 03509 if (!strcasecmp(transport, "tls")) { 03510 res |= SIP_TRANSPORT_TLS; 03511 } 03512 03513 return res; 03514 }
| static const char * gettag | ( | const struct sip_request * | req, | |
| const char * | header, | |||
| char * | tagbuf, | |||
| int | tagbufsize | |||
| ) | [static] |
Get tag from packet.
Definition at line 19192 of file chan_sip.c.
References ast_copy_string(), get_header(), strcasestr(), and strsep().
Referenced by find_call(), handle_incoming(), handle_request_subscribe(), and handle_response().
19193 { 19194 const char *thetag; 19195 19196 if (!tagbuf) 19197 return NULL; 19198 tagbuf[0] = '\0'; /* reset the buffer */ 19199 thetag = get_header(req, header); 19200 thetag = strcasestr(thetag, ";tag="); 19201 if (thetag) { 19202 thetag += 5; 19203 ast_copy_string(tagbuf, thetag, tagbufsize); 19204 return strsep(&tagbuf, ";"); 19205 } 19206 return NULL; 19207 }
| static int handle_common_options | ( | struct ast_flags * | flags, | |
| struct ast_flags * | mask, | |||
| struct ast_variable * | v | |||
| ) | [static] |
Handle flag-type options common to configuration of devices - peers.
| flags | array of two struct ast_flags | |
| mask | array of two struct ast_flags | |
| v | linked list of config variables to process |
Definition at line 23556 of file chan_sip.c.
References ast_clear_flag, ast_copy_string(), ast_false(), ast_log(), ast_set2_flag, ast_set_flag, ast_strdupa, ast_true(), buf, ast_variable::lineno, LOG_WARNING, ast_variable::name, set_insecure_flags(), SIP_DIRECT_MEDIA, SIP_DIRECT_MEDIA_NAT, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, SIP_DTMF_SHORTINFO, SIP_G726_NONSTANDARD, SIP_INSECURE, SIP_NAT, SIP_NAT_ALWAYS, SIP_NAT_NEVER, SIP_NAT_RFC3581, SIP_NAT_ROUTE, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_BUGGY_MWI, SIP_PAGE2_FAX_DETECT, SIP_PAGE2_FAX_DETECT_BOTH, SIP_PAGE2_FAX_DETECT_CNG, SIP_PAGE2_FAX_DETECT_T38, SIP_PAGE2_IGNORESDPVERSION, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, SIP_PROG_INBAND, SIP_PROG_INBAND_NO, SIP_PROG_INBAND_YES, SIP_PROMISCREDIR, SIP_REINVITE, SIP_REINVITE_UPDATE, SIP_SENDRPID, SIP_TRUSTRPID, SIP_USECLIENTCODE, strsep(), ast_variable::value, and word.
Referenced by build_peer(), and reload_config().
23557 { 23558 int res = 1; 23559 23560 if (!strcasecmp(v->name, "trustrpid")) { 23561 ast_set_flag(&mask[0], SIP_TRUSTRPID); 23562 ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID); 23563 } else if (!strcasecmp(v->name, "sendrpid")) { 23564 ast_set_flag(&mask[0], SIP_SENDRPID); 23565 ast_set2_flag(&flags[0], ast_true(v->value), SIP_SENDRPID); 23566 } else if (!strcasecmp(v->name, "g726nonstandard")) { 23567 ast_set_flag(&mask[0], SIP_G726_NONSTANDARD); 23568 ast_set2_flag(&flags[0], ast_true(v->value), SIP_G726_NONSTANDARD); 23569 } else if (!strcasecmp(v->name, "useclientcode")) { 23570 ast_set_flag(&mask[0], SIP_USECLIENTCODE); 23571 ast_set2_flag(&flags[0], ast_true(v->value), SIP_USECLIENTCODE); 23572 } else if (!strcasecmp(v->name, "dtmfmode")) { 23573 ast_set_flag(&mask[0], SIP_DTMF); 23574 ast_clear_flag(&flags[0], SIP_DTMF); 23575 if (!strcasecmp(v->value, "inband")) 23576 ast_set_flag(&flags[0], SIP_DTMF_INBAND); 23577 else if (!strcasecmp(v->value, "rfc2833")) 23578 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 23579 else if (!strcasecmp(v->value, "info")) 23580 ast_set_flag(&flags[0], SIP_DTMF_INFO); 23581 else if (!strcasecmp(v->value, "shortinfo")) 23582 ast_set_flag(&flags[0], SIP_DTMF_SHORTINFO); 23583 else if (!strcasecmp(v->value, "auto")) 23584 ast_set_flag(&flags[0], SIP_DTMF_AUTO); 23585 else { 23586 ast_log(LOG_WARNING, "Unknown dtmf mode '%s' on line %d, using rfc2833\n", v->value, v->lineno); 23587 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 23588 } 23589 } else if (!strcasecmp(v->name, "nat")) { 23590 ast_set_flag(&mask[0], SIP_NAT); 23591 ast_clear_flag(&flags[0], SIP_NAT); 23592 if (!strcasecmp(v->value, "never")) 23593 ast_set_flag(&flags[0], SIP_NAT_NEVER); 23594 else if (!strcasecmp(v->value, "route")) 23595 ast_set_flag(&flags[0], SIP_NAT_ROUTE); 23596 else if (ast_true(v->value)) 23597 ast_set_flag(&flags[0], SIP_NAT_ALWAYS); 23598 else 23599 ast_set_flag(&flags[0], SIP_NAT_RFC3581); 23600 } else if (!strcasecmp(v->name, "directmedia") || !strcasecmp(v->name, "canreinvite")) { 23601 ast_set_flag(&mask[0], SIP_REINVITE); 23602 ast_clear_flag(&flags[0], SIP_REINVITE); 23603 if (ast_true(v->value)) { 23604 ast_set_flag(&flags[0], SIP_DIRECT_MEDIA | SIP_DIRECT_MEDIA_NAT); 23605 } else if (!ast_false(v->value)) { 23606 char buf[64]; 23607 char *word, *next = buf; 23608 23609 ast_copy_string(buf, v->value, sizeof(buf)); 23610 while ((word = strsep(&next, ","))) { 23611 if (!strcasecmp(word, "update")) { 23612 ast_set_flag(&flags[0], SIP_REINVITE_UPDATE | SIP_DIRECT_MEDIA); 23613 } else if (!strcasecmp(word, "nonat")) { 23614 ast_set_flag(&flags[0], SIP_DIRECT_MEDIA); 23615 ast_clear_flag(&flags[0], SIP_DIRECT_MEDIA_NAT); 23616 } else { 23617 ast_log(LOG_WARNING, "Unknown directmedia mode '%s' on line %d\n", v->value, v->lineno); 23618 } 23619 } 23620 } 23621 } else if (!strcasecmp(v->name, "insecure")) { 23622 ast_set_flag(&mask[0], SIP_INSECURE); 23623 ast_clear_flag(&flags[0], SIP_INSECURE); 23624 set_insecure_flags(&flags[0], v->value, v->lineno); 23625 } else if (!strcasecmp(v->name, "progressinband")) { 23626 ast_set_flag(&mask[0], SIP_PROG_INBAND); 23627 ast_clear_flag(&flags[0], SIP_PROG_INBAND); 23628 if (ast_true(v->value)) 23629 ast_set_flag(&flags[0], SIP_PROG_INBAND_YES); 23630 else if (strcasecmp(v->value, "never")) 23631 ast_set_flag(&flags[0], SIP_PROG_INBAND_NO); 23632 } else if (!strcasecmp(v->name, "promiscredir")) { 23633 ast_set_flag(&mask[0], SIP_PROMISCREDIR); 23634 ast_set2_flag(&flags[0], ast_true(v->value), SIP_PROMISCREDIR); 23635 } else if (!strcasecmp(v->name, "videosupport")) { 23636 if (!strcasecmp(v->value, "always")) { 23637 ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 23638 ast_set_flag(&flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 23639 } else { 23640 ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT); 23641 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_VIDEOSUPPORT); 23642 } 23643 } else if (!strcasecmp(v->name, "textsupport")) { 23644 ast_set_flag(&mask[1], SIP_PAGE2_TEXTSUPPORT); 23645 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_TEXTSUPPORT); 23646 res = 1; 23647 } else if (!strcasecmp(v->name, "allowoverlap")) { 23648 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWOVERLAP); 23649 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_ALLOWOVERLAP); 23650 } else if (!strcasecmp(v->name, "allowsubscribe")) { 23651 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWSUBSCRIBE); 23652 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_ALLOWSUBSCRIBE); 23653 } else if (!strcasecmp(v->name, "ignoresdpversion")) { 23654 ast_set_flag(&mask[1], SIP_PAGE2_IGNORESDPVERSION); 23655 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_IGNORESDPVERSION); 23656 } else if (!strcasecmp(v->name, "faxdetect")) { 23657 ast_set_flag(&mask[1], SIP_PAGE2_FAX_DETECT); 23658 if (ast_true(v->value)) { 23659 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_BOTH); 23660 } else if (ast_false(v->value)) { 23661 ast_clear_flag(&flags[1], SIP_PAGE2_FAX_DETECT_BOTH); 23662 } else { 23663 char *buf = ast_strdupa(v->value); 23664 char *word, *next = buf; 23665 23666 while ((word = strsep(&next, ","))) { 23667 if (!strcasecmp(word, "cng")) { 23668 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_CNG); 23669 } else if (!strcasecmp(word, "t38")) { 23670 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_T38); 23671 } else { 23672 ast_log(LOG_WARNING, "Unknown faxdetect mode '%s' on line %d.\n", word, v->lineno); 23673 } 23674 } 23675 } 23676 } else if (!strcasecmp(v->name, "rfc2833compensate")) { 23677 ast_set_flag(&mask[1], SIP_PAGE2_RFC2833_COMPENSATE); 23678 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RFC2833_COMPENSATE); 23679 } else if (!strcasecmp(v->name, "buggymwi")) { 23680 ast_set_flag(&mask[1], SIP_PAGE2_BUGGY_MWI); 23681 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_BUGGY_MWI); 23682 } else 23683 res = 0; 23684 23685 return res; 23686 }
| static int handle_incoming | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int * | recount, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming SIP requests (methods).
called with p and p->owner locked
Definition at line 21808 of file chan_sip.c.
References __sip_ack(), sip_pvt::alreadygone, ast_debug, ast_inet_ntoa(), ast_log(), ast_skip_blanks(), ast_string_field_set, ast_strlen_zero(), ast_verbose, check_pendings(), sip_request::debug, DEFAULT_TRANS_TIMEOUT, extract_uri(), find_sdp(), get_header(), gettag(), sip_pvt::glareinvite, handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_options(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), sip_request::has_to_tag, sip_request::header, sip_request::headers, sip_pvt::icseq, cfsip_methods::id, sip_request::ignore, sip_pvt::initreq, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::lastinvite, sip_pvt::lastmsg, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, sip_request::method, sip_pvt::method, sip_pvt::ocseq, option_debug, sip_settings::pedanticsipchecking, sip_pvt::pendinginvite, process_sdp(), pvt_set_needdestroy(), sip_pvt::randdata, REQ_OFFSET_TO_STR, sip_request::rlPart1, sip_request::rlPart2, sip_pvt::sa, SDP_T38_NONE, SIP_ACK, SIP_BYE, SIP_CANCEL, sip_cfg, sip_debug_test_pvt(), SIP_INFO, SIP_INVITE, SIP_MESSAGE, sip_methods, SIP_NOTIFY, SIP_OPTIONS, SIP_REFER, SIP_REGISTER, SIP_RESPONSE, sip_scheddestroy(), SIP_SUBSCRIBE, cfsip_methods::text, sip_pvt::theirtag, transmit_response(), transmit_response_reliable(), transmit_response_with_allow(), and sip_peer::useragent.
Referenced by handle_request_do(), and process_request_queue().
21809 { 21810 /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things 21811 relatively static */ 21812 const char *cmd; 21813 const char *cseq; 21814 const char *useragent; 21815 int seqno; 21816 int len; 21817 int respid; 21818 int res = 0; 21819 int debug = sip_debug_test_pvt(p); 21820 char *e; 21821 int error = 0; 21822 int oldmethod = p->method; 21823 int acked = 0; 21824 21825 /* Get Method and Cseq */ 21826 cseq = get_header(req, "Cseq"); 21827 cmd = REQ_OFFSET_TO_STR(req, header[0]); 21828 21829 /* Must have Cseq */ 21830 if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq)) { 21831 ast_log(LOG_ERROR, "Missing Cseq. Dropping this SIP message, it's incomplete.\n"); 21832 error = 1; 21833 } 21834 if (!error && sscanf(cseq, "%30d%n", &seqno, &len) != 1) { 21835 ast_log(LOG_ERROR, "No seqno in '%s'. Dropping incomplete message.\n", cmd); 21836 error = 1; 21837 } 21838 if (error) { 21839 if (!p->initreq.headers) { /* New call */ 21840 pvt_set_needdestroy(p, "no headers"); 21841 } 21842 return -1; 21843 } 21844 /* Get the command XXX */ 21845 21846 cmd = REQ_OFFSET_TO_STR(req, rlPart1); 21847 e = ast_skip_blanks(REQ_OFFSET_TO_STR(req, rlPart2)); 21848 21849 /* Save useragent of the client */ 21850 useragent = get_header(req, "User-Agent"); 21851 if (!ast_strlen_zero(useragent)) 21852 ast_string_field_set(p, useragent, useragent); 21853 21854 /* Find out SIP method for incoming request */ 21855 if (req->method == SIP_RESPONSE) { /* Response to our request */ 21856 /* ignore means "don't do anything with it" but still have to 21857 * respond appropriately. 21858 * But in this case this is a response already, so we really 21859 * have nothing to do with this message, and even setting the 21860 * ignore flag is pointless. 21861 */ 21862 if (ast_strlen_zero(e)) { 21863 return 0; 21864 } 21865 if (sscanf(e, "%30d %n", &respid, &len) != 1) { 21866 ast_log(LOG_WARNING, "Invalid response: '%s'\n", e); 21867 return 0; 21868 } 21869 if (respid <= 0) { 21870 ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid); 21871 return 0; 21872 } 21873 if (p->ocseq && (p->ocseq < seqno)) { 21874 if (option_debug) 21875 ast_log(LOG_DEBUG, "Ignoring out of order response %d (expecting %d)\n", seqno, p->ocseq); 21876 return -1; 21877 } else { 21878 if ((respid == 200) || ((respid >= 300) && (respid <= 399))) { 21879 extract_uri(p, req); 21880 } 21881 handle_response(p, respid, e + len, req, seqno); 21882 } 21883 return 0; 21884 } 21885 21886 /* New SIP request coming in 21887 (could be new request in existing SIP dialog as well...) 21888 */ 21889 21890 p->method = req->method; /* Find out which SIP method they are using */ 21891 ast_debug(4, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); 21892 21893 if (p->icseq && (p->icseq > seqno) ) { 21894 if (p->pendinginvite && seqno == p->pendinginvite && (req->method == SIP_ACK || req->method == SIP_CANCEL)) { 21895 ast_debug(2, "Got CANCEL or ACK on INVITE with transactions in between.\n"); 21896 } else { 21897 ast_debug(1, "Ignoring too old SIP packet packet %d (expecting >= %d)\n", seqno, p->icseq); 21898 if (req->method != SIP_ACK) 21899 transmit_response(p, "500 Server error", req); /* We must respond according to RFC 3261 sec 12.2 */ 21900 return -1; 21901 } 21902 } else if (p->icseq && 21903 p->icseq == seqno && 21904 req->method != SIP_ACK && 21905 (p->method != SIP_CANCEL || p->alreadygone)) { 21906 /* ignore means "don't do anything with it" but still have to 21907 respond appropriately. We do this if we receive a repeat of 21908 the last sequence number */ 21909 req->ignore = 1; 21910 ast_debug(3, "Ignoring SIP message because of retransmit (%s Seqno %d, ours %d)\n", sip_methods[p->method].text, p->icseq, seqno); 21911 } 21912 21913 if (seqno >= p->icseq) 21914 /* Next should follow monotonically (but not necessarily 21915 incrementally -- thanks again to the genius authors of SIP -- 21916 increasing */ 21917 p->icseq = seqno; 21918 21919 /* Find their tag if we haven't got it */ 21920 if (ast_strlen_zero(p->theirtag)) { 21921 char tag[128]; 21922 21923 gettag(req, "From", tag, sizeof(tag)); 21924 ast_string_field_set(p, theirtag, tag); 21925 } 21926 snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd); 21927 21928 if (sip_cfg.pedanticsipchecking) { 21929 /* If this is a request packet without a from tag, it's not 21930 correct according to RFC 3261 */ 21931 /* Check if this a new request in a new dialog with a totag already attached to it, 21932 RFC 3261 - section 12.2 - and we don't want to mess with recovery */ 21933 if (!p->initreq.headers && req->has_to_tag) { 21934 /* If this is a first request and it got a to-tag, it is not for us */ 21935 if (!req->ignore && req->method == SIP_INVITE) { 21936 transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req); 21937 /* Will cease to exist after ACK */ 21938 } else if (req->method != SIP_ACK) { 21939 transmit_response(p, "481 Call/Transaction Does Not Exist", req); 21940 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21941 } else { 21942 ast_debug(1, "Got ACK for unknown dialog... strange.\n"); 21943 } 21944 return res; 21945 } 21946 } 21947 21948 if (!e && (p->method == SIP_INVITE || p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER || p->method == SIP_NOTIFY)) { 21949 transmit_response(p, "400 Bad request", req); 21950 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21951 return -1; 21952 } 21953 21954 /* Handle various incoming SIP methods in requests */ 21955 switch (p->method) { 21956 case SIP_OPTIONS: 21957 res = handle_request_options(p, req); 21958 break; 21959 case SIP_INVITE: 21960 res = handle_request_invite(p, req, debug, seqno, sin, recount, e, nounlock); 21961 break; 21962 case SIP_REFER: 21963 res = handle_request_refer(p, req, debug, seqno, nounlock); 21964 break; 21965 case SIP_CANCEL: 21966 res = handle_request_cancel(p, req); 21967 break; 21968 case SIP_BYE: 21969 res = handle_request_bye(p, req); 21970 break; 21971 case SIP_MESSAGE: 21972 res = handle_request_message(p, req); 21973 break; 21974 case SIP_SUBSCRIBE: 21975 res = handle_request_subscribe(p, req, sin, seqno, e); 21976 break; 21977 case SIP_REGISTER: 21978 res = handle_request_register(p, req, sin, e); 21979 break; 21980 case SIP_INFO: 21981 if (req->debug) 21982 ast_verbose("Receiving INFO!\n"); 21983 if (!req->ignore) 21984 handle_request_info(p, req); 21985 else /* if ignoring, transmit response */ 21986 transmit_response(p, "200 OK", req); 21987 break; 21988 case SIP_NOTIFY: 21989 res = handle_request_notify(p, req, sin, seqno, e); 21990 break; 21991 case SIP_ACK: 21992 /* Make sure we don't ignore this */ 21993 if (seqno == p->pendinginvite) { 21994 p->invitestate = INV_TERMINATED; 21995 p->pendinginvite = 0; 21996 acked = __sip_ack(p, seqno, 1 /* response */, 0); 21997 if (find_sdp(req)) { 21998 if (process_sdp(p, req, SDP_T38_NONE)) 21999 return -1; 22000 } 22001 check_pendings(p); 22002 } else if (p->glareinvite == seqno) { 22003 /* handle ack for the 491 pending sent for glareinvite */ 22004 p->glareinvite = 0; 22005 acked = __sip_ack(p, seqno, 1, 0); 22006 } 22007 if (!acked) { 22008 /* Got an ACK that did not match anything. Ignore 22009 * silently and restore previous method */ 22010 p->method = oldmethod; 22011 } 22012 if (!p->lastinvite && ast_strlen_zero(p->randdata)) { 22013 pvt_set_needdestroy(p, "unmatched ACK"); 22014 } 22015 break; 22016 default: 22017 transmit_response_with_allow(p, "501 Method Not Implemented", req, 0); 22018 ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n", 22019 cmd, ast_inet_ntoa(p->sa.sin_addr)); 22020 /* If this is some new method, and we don't have a call, destroy it now */ 22021 if (!p->initreq.headers) { 22022 pvt_set_needdestroy(p, "unimplemented method"); 22023 } 22024 break; 22025 } 22026 return res; 22027 }
| static int handle_invite_replaces | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | seqno, | |||
| struct sockaddr_in * | sin, | |||
| int * | nounlock | |||
| ) | [static] |
Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer. Used only once. XXX 'ignore' is unused.
Definition at line 19414 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_masquerade(), ast_channel_unlock, ast_debug, ast_do_masquerade(), ast_hangup(), ast_log(), ast_quiet_chan(), ast_set_flag, ast_setstate(), ast_state2str(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, DEFAULT_TRANS_TIMEOUT, dialog_unref(), FALSE, sip_pvt::flags, ast_channel::hangupcause, sip_request::ignore, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::name, sip_pvt::owner, sip_pvt::refer, sip_refer::refer_call, SIP_DEFER_BYE_ON_TRANSFER, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), ast_channel::tech_pvt, transmit_response(), transmit_response_reliable(), transmit_response_with_sdp(), and XMIT_RELIABLE.
Referenced by handle_request_invite().
19415 { 19416 int earlyreplace = 0; 19417 int oneleggedreplace = 0; /* Call with no bridge, propably IVR or voice message */ 19418 struct ast_channel *c = p->owner; /* Our incoming call */ 19419 struct ast_channel *replacecall = p->refer->refer_call->owner; /* The channel we're about to take over */ 19420 struct ast_channel *targetcall; /* The bridge to the take-over target */ 19421 19422 struct ast_channel *test; 19423 19424 /* Check if we're in ring state */ 19425 if (replacecall->_state == AST_STATE_RING) 19426 earlyreplace = 1; 19427 19428 /* Check if we have a bridge */ 19429 if (!(targetcall = ast_bridged_channel(replacecall))) { 19430 /* We have no bridge */ 19431 if (!earlyreplace) { 19432 ast_debug(2, " Attended transfer attempted to replace call with no bridge (maybe ringing). Channel %s!\n", replacecall->name); 19433 oneleggedreplace = 1; 19434 } 19435 } 19436 if (targetcall && targetcall->_state == AST_STATE_RINGING) 19437 ast_debug(4, "SIP transfer: Target channel is in ringing state\n"); 19438 19439 if (targetcall) 19440 ast_debug(4, "SIP transfer: Invite Replace incoming channel should bridge to channel %s while hanging up channel %s\n", targetcall->name, replacecall->name); 19441 else 19442 ast_debug(4, "SIP transfer: Invite Replace incoming channel should replace and hang up channel %s (one call leg)\n", replacecall->name); 19443 19444 if (req->ignore) { 19445 ast_log(LOG_NOTICE, "Ignoring this INVITE with replaces in a stupid way.\n"); 19446 /* We should answer something here. If we are here, the 19447 call we are replacing exists, so an accepted 19448 can't harm */ 19449 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE, FALSE); 19450 /* Do something more clever here */ 19451 if (c) { 19452 *nounlock = 1; 19453 ast_channel_unlock(c); 19454 } 19455 ast_channel_unlock(replacecall); 19456 sip_pvt_unlock(p->refer->refer_call); 19457 return 1; 19458 } 19459 if (!c) { 19460 /* What to do if no channel ??? */ 19461 ast_log(LOG_ERROR, "Unable to create new channel. Invite/replace failed.\n"); 19462 transmit_response_reliable(p, "503 Service Unavailable", req); 19463 append_history(p, "Xfer", "INVITE/Replace Failed. No new channel."); 19464 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19465 ast_channel_unlock(replacecall); 19466 sip_pvt_unlock(p->refer->refer_call); 19467 return 1; 19468 } 19469 append_history(p, "Xfer", "INVITE/Replace received"); 19470 /* We have three channels to play with 19471 channel c: New incoming call 19472 targetcall: Call from PBX to target 19473 p->refer->refer_call: SIP pvt dialog from transferer to pbx. 19474 replacecall: The owner of the previous 19475 We need to masq C into refer_call to connect to 19476 targetcall; 19477 If we are talking to internal audio stream, target call is null. 19478 */ 19479 19480 /* Fake call progress */ 19481 transmit_response(p, "100 Trying", req); 19482 ast_setstate(c, AST_STATE_RING); 19483 19484 /* Masquerade the new call into the referred call to connect to target call 19485 Targetcall is not touched by the masq */ 19486 19487 /* Answer the incoming call and set channel to UP state */ 19488 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE, FALSE); 19489 19490 ast_setstate(c, AST_STATE_UP); 19491 19492 /* Stop music on hold and other generators */ 19493 ast_quiet_chan(replacecall); 19494 ast_quiet_chan(targetcall); 19495 ast_debug(4, "Invite/Replaces: preparing to masquerade %s into %s\n", c->name, replacecall->name); 19496 19497 /* Make sure that the masq does not free our PVT for the old call */ 19498 if (! earlyreplace && ! oneleggedreplace ) 19499 ast_set_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 19500 19501 /* Prepare the masquerade - if this does not happen, we will be gone */ 19502 if(ast_channel_masquerade(replacecall, c)) 19503 ast_log(LOG_ERROR, "Failed to masquerade C into Replacecall\n"); 19504 else 19505 ast_debug(4, "Invite/Replaces: Going to masquerade %s into %s\n", c->name, replacecall->name); 19506 19507 /* C should now be in place of replacecall */ 19508 if (ast_do_masquerade(replacecall)) { 19509 ast_log(LOG_WARNING, "Failed to perform masquerade with INVITE replaces\n"); 19510 } 19511 19512 if (earlyreplace || oneleggedreplace ) { 19513 c->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 19514 } 19515 19516 ast_setstate(c, AST_STATE_DOWN); 19517 ast_debug(4, "After transfer:----------------------------\n"); 19518 ast_debug(4, " -- C: %s State %s\n", c->name, ast_state2str(c->_state)); 19519 if (replacecall) 19520 ast_debug(4, " -- replacecall: %s State %s\n", replacecall->name, ast_state2str(replacecall->_state)); 19521 if (p->owner) { 19522 ast_debug(4, " -- P->owner: %s State %s\n", p->owner->name, ast_state2str(p->owner->_state)); 19523 test = ast_bridged_channel(p->owner); 19524 if (test) 19525 ast_debug(4, " -- Call bridged to P->owner: %s State %s\n", test->name, ast_state2str(test->_state)); 19526 else 19527 ast_debug(4, " -- No call bridged to C->owner \n"); 19528 } else 19529 ast_debug(4, " -- No channel yet \n"); 19530 ast_debug(4, "End After transfer:----------------------------\n"); 19531 19532 /* unlock sip pvt and owner so hangup can do its thing */ 19533 ast_channel_unlock(replacecall); 19534 ast_channel_unlock(c); 19535 sip_pvt_unlock(p->refer->refer_call); 19536 sip_pvt_unlock(p); 19537 *nounlock = 1; 19538 19539 /* The call should be down with no ast_channel, so hang it up */ 19540 c->tech_pvt = dialog_unref(c->tech_pvt, "unref dialog c->tech_pvt"); 19541 ast_hangup(c); 19542 sip_pvt_lock(p); /* lock PVT structure again after hangup */ 19543 19544 return 0; 19545 }
| static int handle_request_bye | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming BYE request.
Definition at line 21263 of file chan_sip.c.
References __sip_pretend_ack(), append_history, ast_async_goto(), ast_bridged_channel(), AST_CAUSE_PROTOCOL_ERROR, ast_channel_trylock, ast_channel_unlock, ast_clear_flag, AST_CONTROL_UNHOLD, ast_debug, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_rtp_get_quality(), ast_rtp_set_vars(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_channel::bridge, sip_pvt::callid, check_via(), context, sip_pvt::context, copy_request(), sip_settings::default_context, DEFAULT_TRANS_TIMEOUT, sip_pvt::do_history, sip_pvt::flags, get_also_info(), get_header(), sip_request::ignore, sip_pvt::initreq, INV_TERMINATED, sip_pvt::invitestate, IS_SIP_TECH, LOG_NOTICE, LOG_WARNING, sip_request::method, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::pendinginvite, sip_pvt::recv, sip_pvt::refer, sip_refer::refer_to, sip_pvt::rtp, RTPQOS_JITTER, RTPQOS_LOSS, RTPQOS_RTT, RTPQOS_SUMMARY, sip_alreadygone(), sip_cfg, sip_methods, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), stop_media_flows(), stop_session_timer(), ast_channel::tech, ast_channel::tech_pvt, cfsip_methods::text, transmit_response(), transmit_response_reliable(), sip_pvt::trtp, and sip_pvt::vrtp.
Referenced by handle_incoming().
21264 { 21265 struct ast_channel *c=NULL; 21266 int res; 21267 struct ast_channel *bridged_to; 21268 21269 /* If we have an INCOMING invite that we haven't answered, terminate that transaction */ 21270 if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !req->ignore) { 21271 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 21272 } 21273 21274 __sip_pretend_ack(p); 21275 21276 p->invitestate = INV_TERMINATED; 21277 21278 copy_request(&p->initreq, req); 21279 if (sipdebug) 21280 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 21281 check_via(p, req); 21282 sip_alreadygone(p); 21283 21284 /* Get RTCP quality before end of call */ 21285 if (p->do_history || p->owner) { 21286 struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL; 21287 char *videoqos, *textqos; 21288 21289 /* We need to get the lock on bridge because ast_rtp_set_vars will attempt 21290 * to lock the bridge. This may get hairy... 21291 */ 21292 while (bridge && ast_channel_trylock(bridge)) { 21293 ast_channel_unlock(p->owner); 21294 do { 21295 /* Can't use DEADLOCK_AVOIDANCE since p is an ao2 object */ 21296 sip_pvt_unlock(p); 21297 usleep(1); 21298 sip_pvt_lock(p); 21299 } while (p->owner && ast_channel_trylock(p->owner)); 21300 bridge = p->owner ? ast_bridged_channel(p->owner) : NULL; 21301 } 21302 21303 if (p->rtp) { 21304 if (p->do_history) { 21305 char *audioqos, 21306 *audioqos_jitter, 21307 *audioqos_loss, 21308 *audioqos_rtt; 21309 21310 audioqos = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_SUMMARY); 21311 audioqos_jitter = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_JITTER); 21312 audioqos_loss = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_LOSS); 21313 audioqos_rtt = ast_rtp_get_quality(p->rtp, NULL, RTPQOS_RTT); 21314 21315 append_history(p, "RTCPaudio", "Quality:%s", audioqos); 21316 append_history(p, "RTCPaudioJitter", "Quality:%s", audioqos_jitter); 21317 append_history(p, "RTCPaudioLoss", "Quality:%s", audioqos_loss); 21318 append_history(p, "RTCPaudioRTT", "Quality:%s", audioqos_rtt); 21319 } 21320 21321 if (p->owner) { 21322 ast_rtp_set_vars(p->owner, p->rtp); 21323 } 21324 } 21325 21326 if (bridge) { 21327 struct sip_pvt *q = bridge->tech_pvt; 21328 21329 if (IS_SIP_TECH(bridge->tech) && q && q->rtp) 21330 ast_rtp_set_vars(bridge, q->rtp); 21331 ast_channel_unlock(bridge); 21332 } 21333 21334 if (p->vrtp) { 21335 videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY); 21336 if (p->do_history) 21337 append_history(p, "RTCPvideo", "Quality:%s", videoqos); 21338 if (p->owner) 21339 pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", videoqos); 21340 } 21341 21342 if (p->trtp) { 21343 textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY); 21344 if (p->do_history) 21345 append_history(p, "RTCPtext", "Quality:%s", textqos); 21346 if (p->owner) 21347 pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", textqos); 21348 } 21349 } 21350 21351 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 21352 stop_session_timer(p); /* Stop Session-Timer */ 21353 21354 if (!ast_strlen_zero(get_header(req, "Also"))) { 21355 ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n", 21356 ast_inet_ntoa(p->recv.sin_addr)); 21357 if (ast_strlen_zero(p->context)) 21358 ast_string_field_set(p, context, sip_cfg.default_context); 21359 res = get_also_info(p, req); 21360 if (!res) { 21361 c = p->owner; 21362 if (c) { 21363 bridged_to = ast_bridged_channel(c); 21364 if (bridged_to) { 21365 /* Don't actually hangup here... */ 21366 ast_queue_control(c, AST_CONTROL_UNHOLD); 21367 ast_async_goto(bridged_to, p->context, p->refer->refer_to, 1); 21368 } else 21369 ast_queue_hangup(p->owner); 21370 } 21371 } else { 21372 ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_inet_ntoa(p->recv.sin_addr)); 21373 if (p->owner) 21374 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR); 21375 } 21376 } else if (p->owner) { 21377 ast_queue_hangup(p->owner); 21378 ast_debug(3, "Received bye, issuing owner hangup\n"); 21379 } else { 21380 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21381 ast_debug(3, "Received bye, no owner, selfdestruct soon.\n"); 21382 } 21383 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21384 transmit_response(p, "200 OK", req); 21385 21386 return 1; 21387 }
| static int handle_request_cancel | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming CANCEL request.
Definition at line 21087 of file chan_sip.c.
References __sip_pretend_ack(), ast_channel::_state, ast_debug, ast_free, ast_queue_hangup(), AST_SCHED_DEL, AST_STATE_UP, ast_test_flag, check_via(), DEC_CALL_LIMIT, DEFAULT_TRANS_TIMEOUT, sip_pvt::flags, sip_pvt::initreq, INV_CANCELLED, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::lastinvite, sip_request::len, sip_pkt::next, sip_pvt::owner, sip_pvt::packets, sip_pkt::response_code, sip_pkt::retransid, sip_pkt::seqno, sip_alreadygone(), SIP_INC_COUNT, SIP_PAGE2_CALL_ONHOLD, sip_scheddestroy(), stop_media_flows(), transmit_response(), transmit_response_reliable(), UNLINK, and update_call_counter().
Referenced by handle_incoming().
21088 { 21089 21090 check_via(p, req); 21091 sip_alreadygone(p); 21092 21093 /* At this point, we could have cancelled the invite at the same time 21094 as the other side sends a CANCEL. Our final reply with error code 21095 might not have been received by the other side before the CANCEL 21096 was sent, so let's just give up retransmissions and waiting for 21097 ACK on our error code. The call is hanging up any way. */ 21098 if (p->invitestate == INV_TERMINATED) 21099 __sip_pretend_ack(p); 21100 else 21101 p->invitestate = INV_CANCELLED; 21102 21103 if (p->owner && p->owner->_state == AST_STATE_UP) { 21104 /* This call is up, cancel is ignored, we need a bye */ 21105 transmit_response(p, "200 OK", req); 21106 ast_debug(1, "Got CANCEL on an answered call. Ignoring... \n"); 21107 return 0; 21108 } 21109 21110 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) 21111 update_call_counter(p, DEC_CALL_LIMIT); 21112 21113 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 21114 if (p->owner) 21115 ast_queue_hangup(p->owner); 21116 else 21117 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21118 if (p->initreq.len > 0) { 21119 struct sip_pkt *pkt, *prev_pkt; 21120 /* If the CANCEL we are receiving is a retransmission, and we already have scheduled 21121 * a reliable 487, then we don't want to schedule another one on top of the previous 21122 * one. 21123 * 21124 * As odd as this may sound, we can't rely on the previously-transmitted "reliable" 21125 * response in this situation. What if we've sent all of our reliable responses 21126 * already and now all of a sudden, we get this second CANCEL? 21127 * 21128 * The only way to do this correctly is to cancel our previously-scheduled reliably- 21129 * transmitted response and send a new one in its place. 21130 */ 21131 for (pkt = p->packets, prev_pkt = NULL; pkt; prev_pkt = pkt, pkt = pkt->next) { 21132 if (pkt->seqno == p->lastinvite && pkt->response_code == 487) { 21133 AST_SCHED_DEL(sched, pkt->retransid); 21134 UNLINK(pkt, p->packets, prev_pkt); 21135 ast_free(pkt); 21136 break; 21137 } 21138 } 21139 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 21140 transmit_response(p, "200 OK", req); 21141 return 1; 21142 } else { 21143 transmit_response(p, "481 Call Leg Does Not Exist", req); 21144 return 0; 21145 } 21146 }
| static int handle_request_do | ( | struct sip_request * | req, | |
| struct sockaddr_in * | sin | |||
| ) | [static] |
Handle incoming SIP message - request or response.
This is used for all transports (udp, tcp and tcp/tls)
Definition at line 22170 of file chan_sip.c.
References ao2_t_ref, append_history, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_inet_ntoa(), AST_LIST_EMPTY, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), AST_SCHED_DEL_UNREF, ast_str_reset(), ast_update_use_count(), ast_verbose, sip_pvt::callid, copy_socket_data(), sip_request::data, sip_request::debug, dialog_unref(), sip_pvt::do_history, find_call(), find_sip_method(), get_header(), get_transport(), handle_incoming(), sip_request::headers, sip_request::len, sip_request::lines, LOG_ERROR, lws2sws(), sip_request::method, ast_channel::name, netlock, sip_pvt::owner, parse_request(), sip_settings::pedanticsipchecking, process_request_queue(), queue_request(), sip_pvt::recv, REQ_OFFSET_TO_STR, sip_pvt::request_queue, sip_pvt::request_queue_sched_id, sip_request::rlPart1, sip_request::rlPart2, S_OR, SIP_ACK, sip_cfg, sip_debug_test_addr(), sip_pvt_unlock, sip_pvt::socket, sip_request::socket, transmit_response(), and sip_socket::type.
Referenced by _sip_tcp_helper_thread(), and sipsock_read().
22171 { 22172 struct sip_pvt *p; 22173 int recount = 0; 22174 int nounlock = 0; 22175 int lockretry; 22176 22177 if (sip_debug_test_addr(sin)) /* Set the debug flag early on packet level */ 22178 req->debug = 1; 22179 if (sip_cfg.pedanticsipchecking) 22180 req->len = lws2sws(req->data->str, req->len); /* Fix multiline headers */ 22181 if (req->debug) { 22182 ast_verbose("\n<--- SIP read from %s:%s:%d --->\n%s\n<------------->\n", 22183 get_transport(req->socket.type), ast_inet_ntoa(sin->sin_addr), 22184 ntohs(sin->sin_port), req->data->str); 22185 } 22186 22187 if (parse_request(req) == -1) { /* Bad packet, can't parse */ 22188 ast_str_reset(req->data); /* nulling this out is NOT a good idea here. */ 22189 return 1; 22190 } 22191 req->method = find_sip_method(REQ_OFFSET_TO_STR(req, rlPart1)); 22192 22193 if (req->debug) 22194 ast_verbose("--- (%d headers %d lines)%s ---\n", req->headers, req->lines, (req->headers + req->lines == 0) ? " Nat keepalive" : ""); 22195 22196 if (req->headers < 2) { /* Must have at least two headers */ 22197 ast_str_reset(req->data); /* nulling this out is NOT a good idea here. */ 22198 return 1; 22199 } 22200 22201 /* Process request, with netlock held, and with usual deadlock avoidance */ 22202 for (lockretry = 10; lockretry > 0; lockretry--) { 22203 ast_mutex_lock(&netlock); 22204 22205 /* Find the active SIP dialog or create a new one */ 22206 p = find_call(req, sin, req->method); /* returns p locked */ 22207 if (p == NULL) { 22208 ast_debug(1, "Invalid SIP message - rejected , no callid, len %d\n", req->len); 22209 ast_mutex_unlock(&netlock); 22210 return 1; 22211 } 22212 22213 copy_socket_data(&p->socket, &req->socket); 22214 22215 /* Go ahead and lock the owner if it has one -- we may need it */ 22216 /* becaues this is deadlock-prone, we need to try and unlock if failed */ 22217 if (!p->owner || !ast_channel_trylock(p->owner)) 22218 break; /* locking succeeded */ 22219 22220 if (lockretry != 1) { 22221 sip_pvt_unlock(p); 22222 ao2_t_ref(p, -1, "release p (from find_call) inside lockretry loop"); /* we'll look for it again, but p is dead now */ 22223 ast_mutex_unlock(&netlock); 22224 /* Sleep for a very short amount of time */ 22225 usleep(1); 22226 } 22227 } 22228 p->recv = *sin; 22229 22230 if (p->do_history) /* This is a request or response, note what it was for */ 22231 append_history(p, "Rx", "%s / %s / %s", req->data->str, get_header(req, "CSeq"), REQ_OFFSET_TO_STR(req, rlPart2)); 22232 22233 if (!lockretry) { 22234 if (!queue_request(p, req)) { 22235 /* the request has been queued for later handling */ 22236 sip_pvt_unlock(p); 22237 ao2_t_ref(p, -1, "release p (from find_call) after queueing request"); 22238 ast_mutex_unlock(&netlock); 22239 return 1; 22240 } 22241 22242 if (p->owner) 22243 ast_log(LOG_ERROR, "Channel lock for %s could not be obtained, and request was unable to be queued.\n", S_OR(p->owner->name, "- no channel name ??? - ")); 22244 ast_log(LOG_ERROR, "SIP transaction failed: %s \n", p->callid); 22245 if (req->method != SIP_ACK) 22246 transmit_response(p, "503 Server error", req); /* We must respond according to RFC 3261 sec 12.2 */ 22247 /* XXX We could add retry-after to make sure they come back */ 22248 append_history(p, "LockFail", "Owner lock failed, transaction failed."); 22249 sip_pvt_unlock(p); 22250 ao2_t_ref(p, -1, "release p (from find_call) at end of lockretry"); /* p is gone after the return */ 22251 ast_mutex_unlock(&netlock); 22252 return 1; 22253 } 22254 22255 /* if there are queued requests on this sip_pvt, process them first, so that everything is 22256 handled in order 22257 */ 22258 if (!AST_LIST_EMPTY(&p->request_queue)) { 22259 AST_SCHED_DEL_UNREF(sched, p->request_queue_sched_id, dialog_unref(p, "when you delete the request_queue_sched_id sched, you should dec the refcount for the stored dialog ptr")); 22260 process_request_queue(p, &recount, &nounlock); 22261 } 22262 22263 if (handle_incoming(p, req, sin, &recount, &nounlock) == -1) { 22264 /* Request failed */ 22265 ast_debug(1, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>"); 22266 } 22267 22268 if (recount) 22269 ast_update_use_count(); 22270 22271 if (p->owner && !nounlock) 22272 ast_channel_unlock(p->owner); 22273 sip_pvt_unlock(p); 22274 ao2_t_ref(p, -1, "throw away dialog ptr from find_call at end of routine"); /* p is gone after the return */ 22275 ast_mutex_unlock(&netlock); 22276 return 1; 22277 }
| static void handle_request_info | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP INFO Message.
Definition at line 16825 of file chan_sip.c.
References ast_bridged_channel(), ast_cdr_setuserfield(), AST_CONTROL_FLASH, AST_CONTROL_VIDUPDATE, ast_copy_string(), ast_debug, ast_find_call_feature(), AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_log(), ast_queue_control(), ast_queue_frame(), ast_rdlock_call_features(), ast_strlen_zero(), ast_test_flag, ast_unlock_call_features(), ast_verbose, buf, sip_pvt::callid, ast_channel::cdr, DEFAULT_TRANS_TIMEOUT, sip_history::event, ast_call_feature::exten, sip_pvt::flags, get_body(), get_header(), get_msg_text(), ast_frame::len, LOG_WARNING, sip_pvt::owner, sip_scheddestroy(), SIP_USECLIENTCODE, ast_frame::subclass, transmit_response(), and TRUE.
Referenced by handle_incoming().
16826 { 16827 char buf[1024]; 16828 unsigned int event; 16829 const char *c = get_header(req, "Content-Type"); 16830 16831 /* Need to check the media/type */ 16832 if (!strcasecmp(c, "application/dtmf-relay") || 16833 !strcasecmp(c, "application/vnd.nortelnetworks.digits")) { 16834 unsigned int duration = 0; 16835 16836 if (!p->owner) { /* not a PBX call */ 16837 transmit_response(p, "481 Call leg/transaction does not exist", req); 16838 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16839 return; 16840 } 16841 16842 /* Try getting the "signal=" part */ 16843 if (ast_strlen_zero(c = get_body(req, "Signal", '=')) && ast_strlen_zero(c = get_body(req, "d", '='))) { 16844 ast_log(LOG_WARNING, "Unable to retrieve DTMF signal from INFO message from %s\n", p->callid); 16845 transmit_response(p, "200 OK", req); /* Should return error */ 16846 return; 16847 } else { 16848 ast_copy_string(buf, c, sizeof(buf)); 16849 } 16850 16851 if (!ast_strlen_zero((c = get_body(req, "Duration", '=')))) 16852 duration = atoi(c); 16853 if (!duration) 16854 duration = 100; /* 100 ms */ 16855 16856 16857 if (ast_strlen_zero(buf)) { 16858 transmit_response(p, "200 OK", req); 16859 return; 16860 } 16861 16862 if (buf[0] == '*') 16863 event = 10; 16864 else if (buf[0] == '#') 16865 event = 11; 16866 else if ((buf[0] >= 'A') && (buf[0] <= 'D')) 16867 event = 12 + buf[0] - 'A'; 16868 else if (buf[0] == '!') 16869 event = 16; 16870 else 16871 event = atoi(buf); 16872 if (event == 16) { 16873 /* send a FLASH event */ 16874 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, }; 16875 ast_queue_frame(p->owner, &f); 16876 if (sipdebug) 16877 ast_verbose("* DTMF-relay event received: FLASH\n"); 16878 } else { 16879 /* send a DTMF event */ 16880 struct ast_frame f = { AST_FRAME_DTMF, }; 16881 if (event < 10) { 16882 f.subclass = '0' + event; 16883 } else if (event < 11) { 16884 f.subclass = '*'; 16885 } else if (event < 12) { 16886 f.subclass = '#'; 16887 } else if (event < 16) { 16888 f.subclass = 'A' + (event - 12); 16889 } 16890 f.len = duration; 16891 ast_queue_frame(p->owner, &f); 16892 if (sipdebug) 16893 ast_verbose("* DTMF-relay event received: %c\n", f.subclass); 16894 } 16895 transmit_response(p, "200 OK", req); 16896 return; 16897 } else if (!strcasecmp(c, "application/dtmf")) { 16898 /*! \todo Note: Doesn't read the duration of the DTMF. Should be fixed. */ 16899 unsigned int duration = 0; 16900 16901 if (!p->owner) { /* not a PBX call */ 16902 transmit_response(p, "481 Call leg/transaction does not exist", req); 16903 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16904 return; 16905 } 16906 16907 get_msg_text(buf, sizeof(buf), req, TRUE); 16908 duration = 100; /* 100 ms */ 16909 16910 if (ast_strlen_zero(buf)) { 16911 transmit_response(p, "200 OK", req); 16912 return; 16913 } 16914 event = atoi(buf); 16915 if (event == 16) { 16916 /* send a FLASH event */ 16917 struct ast_frame f = { AST_FRAME_CONTROL, AST_CONTROL_FLASH, }; 16918 ast_queue_frame(p->owner, &f); 16919 if (sipdebug) 16920 ast_verbose("* DTMF-relay event received: FLASH\n"); 16921 } else { 16922 /* send a DTMF event */ 16923 struct ast_frame f = { AST_FRAME_DTMF, }; 16924 if (event < 10) { 16925 f.subclass = '0' + event; 16926 } else if (event < 11) { 16927 f.subclass = '*'; 16928 } else if (event < 12) { 16929 f.subclass = '#'; 16930 } else if (event < 16) { 16931 f.subclass = 'A' + (event - 12); 16932 } 16933 f.len = duration; 16934 ast_queue_frame(p->owner, &f); 16935 if (sipdebug) 16936 ast_verbose("* DTMF-relay event received: %c\n", f.subclass); 16937 } 16938 transmit_response(p, "200 OK", req); 16939 return; 16940 16941 } else if (!strcasecmp(c, "application/media_control+xml")) { 16942 /* Eh, we'll just assume it's a fast picture update for now */ 16943 if (p->owner) 16944 ast_queue_control(p->owner, AST_CONTROL_VIDUPDATE); 16945 transmit_response(p, "200 OK", req); 16946 return; 16947 } else if (!ast_strlen_zero(c = get_header(req, "X-ClientCode"))) { 16948 /* Client code (from SNOM phone) */ 16949 if (ast_test_flag(&p->flags[0], SIP_USECLIENTCODE)) { 16950 if (p->owner && p->owner->cdr) 16951 ast_cdr_setuserfield(p->owner, c); 16952 if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr) 16953 ast_cdr_setuserfield(ast_bridged_channel(p->owner), c); 16954 transmit_response(p, "200 OK", req); 16955 } else { 16956 transmit_response(p, "403 Forbidden", req); 16957 } 16958 return; 16959 } else if (!ast_strlen_zero(c = get_header(req, "Record"))) { 16960 /* INFO messages generated by some phones to start/stop recording 16961 on phone calls. 16962 OEJ: I think this should be something that is enabled/disabled 16963 per device. I don't want incoming callers to record calls in my 16964 pbx. 16965 */ 16966 /* first, get the feature string, if it exists */ 16967 struct ast_call_feature *feat; 16968 int j; 16969 struct ast_frame f = { AST_FRAME_DTMF, }; 16970 16971 ast_rdlock_call_features(); 16972 feat = ast_find_call_feature("automon"); 16973 if (!feat || ast_strlen_zero(feat->exten)) { 16974 ast_log(LOG_WARNING, "Recording requested, but no One Touch Monitor registered. (See features.conf)\n"); 16975 /* 403 means that we don't support this feature, so don't request it again */ 16976 transmit_response(p, "403 Forbidden", req); 16977 ast_unlock_call_features(); 16978 return; 16979 } 16980 /* Send the feature code to the PBX as DTMF, just like the handset had sent it */ 16981 f.len = 100; 16982 for (j=0; j < strlen(feat->exten); j++) { 16983 f.subclass = feat->exten[j]; 16984 ast_queue_frame(p->owner, &f); 16985 if (sipdebug) 16986 ast_verbose("* DTMF-relay event faked: %c\n", f.subclass); 16987 } 16988 ast_unlock_call_features(); 16989 16990 ast_debug(1, "Got a Request to Record the channel, state %s\n", c); 16991 transmit_response(p, "200 OK", req); 16992 return; 16993 } else if (ast_strlen_zero(c = get_header(req, "Content-Length")) || !strcasecmp(c, "0")) { 16994 /* This is probably just a packet making sure the signalling is still up, just send back a 200 OK */ 16995 transmit_response(p, "200 OK", req); 16996 return; 16997 } 16998 16999 /* Other type of INFO message, not really understood by Asterisk */ 17000 /* if (get_msg_text(buf, sizeof(buf), req)) { */ 17001 17002 ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf); 17003 transmit_response(p, "415 Unsupported media type", req); 17004 return; 17005 }
| static int handle_request_invite | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | seqno, | |||
| struct sockaddr_in * | sin, | |||
| int * | recount, | |||
| char * | e, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming INVITE request.
This is a spiral. What we need to do is to just change the outgoing INVITE so that it now routes to the new Request URI. Since we created the INVITE ourselves that should be all we need to do.
Definition at line 19866 of file chan_sip.c.
References __sip_ack(), ast_channel::_state, append_history, AST_CAUSE_CALL_REJECTED, AST_CAUSE_NORMAL_CLEARING, ast_channel_lock, ast_channel_unlock, ast_clear_flag, AST_CONTROL_BUSY, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_hangup(), ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_null_frame, AST_PBX_CALL_LIMIT, AST_PBX_FAILED, ast_pbx_start(), AST_PBX_SUCCESS, ast_pickup_call(), ast_pickup_ext(), ast_queue_control(), ast_queue_frame(), ast_rtp_set_alt_peer(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_sched_add(), ast_set_flag, ast_setstate(), ast_skip_blanks(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_new_with_bindaddr(), ast_uri_decode(), ast_verbose, AUTH_CHALLENGE_SENT, AUTH_FAKE_AUTH, sip_pvt::autokillid, bindaddr, build_contact(), build_route(), sip_pvt::callid, sip_pvt::capability, change_hold_state(), check_user(), check_via(), sip_pvt::context, context, copy_request(), DEC_CALL_LIMIT, sip_settings::default_context, DEFAULT_TRANS_TIMEOUT, dialog_ref(), dialog_unref(), sip_pvt::do_history, do_magic_pickup(), ast_channel::exten, sip_pvt::exten, exten, extract_uri(), FALSE, find_sdp(), sip_pvt::flags, get_destination(), get_header(), get_ip_and_port_from_sdp(), get_rdnis(), get_sip_pvt_byid_locked(), sip_pvt::glareinvite, handle_invite_replaces(), ast_channel::hangupcause, sip_request::headers, sip_request::ignore, INC_CALL_LIMIT, sip_pvt::initreq, INV_COMPLETED, INV_CONFIRMED, INV_PROCEEDING, INV_TERMINATED, sip_pvt::invitestate, sip_pvt::jointcapability, sip_pvt::lastinvite, LOG_ERROR, LOG_NOTICE, LOG_WARNING, make_our_tag(), sip_request::method, msg, ast_channel::name, sip_pvt::owner, parse_minse(), parse_ok_contact(), parse_session_expires(), parse_sip_options(), sip_settings::pedanticsipchecking, sip_pvt::peername, sip_pvt::pendinginvite, process_sdp(), sip_pvt::refer, sip_refer::refer_call, REQ_OFFSET_TO_STR, sip_pvt::reqsipoptions, restart_session_timer(), sip_request::rlPart2, sip_pvt::rtp, S_OR, SDP_AUDIO, SDP_T38_INITIATE, SDP_VIDEO, sip_pvt::session_modify, SESSION_TIMER_MODE_ACCEPT, SESSION_TIMER_MODE_ORIGINATE, SESSION_TIMER_MODE_REFUSE, SESSION_TIMER_REFRESHER_AUTO, SESSION_TIMER_REFRESHER_UAS, set_t38_capabilities(), sip_alreadygone(), sip_cancel_destroy(), sip_cfg, SIP_DTMF, SIP_DTMF_RFC2833, SIP_INVITE, sip_methods, sip_new(), SIP_OPT_REPLACES, SIP_OPT_TIMER, SIP_OUTGOING, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT, sip_pvt_lock, sip_pvt_unlock, sip_refer_allocate(), sip_scheddestroy(), sip_st_alloc(), sip_t38_abort(), sip_uri_cmp(), sip_pvt::sipoptions, sip_st_dlg::st_active, sip_st_dlg::st_active_peer_ua, sip_st_dlg::st_expirys, st_get_mode(), st_get_refresher(), st_get_se(), sip_st_dlg::st_interval, sip_st_dlg::st_ref, start_session_timer(), t38properties::state, sip_pvt::stimer, strcasestr(), strsep(), sip_pvt::t38, T38_DISABLED, T38_ENABLED, sip_pvt::t38_maxdatagram, T38_PEER_REINVITE, sip_pvt::t38id, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, transmit_fake_auth_response(), transmit_provisional_response(), transmit_response(), transmit_response_reliable(), transmit_response_with_minse(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), transmit_response_with_unsupported(), TRUE, sip_pvt::udptl, update_call_counter(), sip_pvt::username, sip_pvt::vrtp, XMIT_CRITICAL, XMIT_RELIABLE, and XMIT_UNRELIABLE.
Referenced by handle_incoming().
19867 { 19868 int res = 1; 19869 int gotdest; 19870 const char *p_replaces; 19871 char *replace_id = NULL; 19872 int refer_locked = 0; 19873 const char *required; 19874 unsigned int required_profile = 0; 19875 struct ast_channel *c = NULL; /* New channel */ 19876 int reinvite = 0; 19877 int rtn; 19878 19879 const char *p_uac_se_hdr; /* UAC's Session-Expires header string */ 19880 const char *p_uac_min_se; /* UAC's requested Min-SE interval (char string) */ 19881 int uac_max_se = -1; /* UAC's Session-Expires in integer format */ 19882 int uac_min_se = -1; /* UAC's Min-SE in integer format */ 19883 int st_active = FALSE; /* Session-Timer on/off boolean */ 19884 int st_interval = 0; /* Session-Timer negotiated refresh interval */ 19885 enum st_refresher st_ref; /* Session-Timer session refresher */ 19886 int dlg_min_se = -1; 19887 struct { 19888 char exten[AST_MAX_EXTENSION]; 19889 char context[AST_MAX_CONTEXT]; 19890 } pickup = { 19891 .exten = "", 19892 }; 19893 st_ref = SESSION_TIMER_REFRESHER_AUTO; 19894 19895 /* Find out what they support */ 19896 if (!p->sipoptions) { 19897 const char *supported = get_header(req, "Supported"); 19898 if (!ast_strlen_zero(supported)) 19899 parse_sip_options(p, supported); 19900 } 19901 19902 /* Find out what they require */ 19903 required = get_header(req, "Require"); 19904 if (!ast_strlen_zero(required)) { 19905 required_profile = parse_sip_options(NULL, required); 19906 if (required_profile && !(required_profile & (SIP_OPT_REPLACES | SIP_OPT_TIMER))) { 19907 /* At this point we only support REPLACES and Session-Timer */ 19908 transmit_response_with_unsupported(p, "420 Bad extension (unsupported)", req, required); 19909 ast_log(LOG_WARNING, "Received SIP INVITE with unsupported required extension: %s\n", required); 19910 p->invitestate = INV_COMPLETED; 19911 if (!p->lastinvite) 19912 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19913 res = -1; 19914 goto request_invite_cleanup; 19915 } 19916 } 19917 19918 /* The option tags may be present in Supported: or Require: headers. 19919 Include the Require: option tags for further processing as well */ 19920 p->sipoptions |= required_profile; 19921 p->reqsipoptions = required_profile; 19922 19923 /* Check if this is a loop */ 19924 if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && p->owner && (p->invitestate != INV_TERMINATED && p->invitestate != INV_CONFIRMED)) { 19925 /* This is a call to ourself. Send ourselves an error code and stop 19926 processing immediately, as SIP really has no good mechanism for 19927 being able to call yourself */ 19928 /* If pedantic is on, we need to check the tags. If they're different, this is 19929 in fact a forked call through a SIP proxy somewhere. */ 19930 int different; 19931 char *initial_rlPart2 = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); 19932 char *this_rlPart2 = REQ_OFFSET_TO_STR(req, rlPart2); 19933 if (sip_cfg.pedanticsipchecking) 19934 different = sip_uri_cmp(initial_rlPart2, this_rlPart2); 19935 else 19936 different = strcmp(initial_rlPart2, this_rlPart2); 19937 if (!different) { 19938 transmit_response(p, "482 Loop Detected", req); 19939 p->invitestate = INV_COMPLETED; 19940 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19941 res = 0; 19942 goto request_invite_cleanup; 19943 } else { 19944 /*! This is a spiral. What we need to do is to just change the outgoing INVITE 19945 * so that it now routes to the new Request URI. Since we created the INVITE ourselves 19946 * that should be all we need to do. 19947 * 19948 * \todo XXX This needs to be reviewed. YOu don't change the request URI really, you route the packet 19949 * correctly instead... 19950 */ 19951 char *uri = ast_strdupa(this_rlPart2); 19952 char *at = strchr(uri, '@'); 19953 char *peerorhost; 19954 ast_debug(2, "Potential spiral detected. Original RURI was %s, new RURI is %s\n", initial_rlPart2, this_rlPart2); 19955 transmit_response(p, "100 Trying", req); 19956 if (at) { 19957 *at = '\0'; 19958 } 19959 /* Parse out "sip:" */ 19960 if ((peerorhost = strchr(uri, ':'))) { 19961 *peerorhost++ = '\0'; 19962 } 19963 ast_string_field_set(p, theirtag, NULL); 19964 /* Treat this as if there were a call forward instead... 19965 */ 19966 ast_string_field_set(p->owner, call_forward, peerorhost); 19967 ast_queue_control(p->owner, AST_CONTROL_BUSY); 19968 res = 0; 19969 goto request_invite_cleanup; 19970 } 19971 } 19972 19973 if (!req->ignore && p->pendinginvite) { 19974 if (!ast_test_flag(&p->flags[0], SIP_OUTGOING) && (p->invitestate == INV_COMPLETED || p->invitestate == INV_TERMINATED)) { 19975 /* What do these circumstances mean? We have received an INVITE for an "incoming" dialog for which we 19976 * have sent a final response. We have not yet received an ACK, though (which is why p->pendinginvite is non-zero). 19977 * We also know that the INVITE is not a retransmission, because otherwise the "ignore" flag would be set. 19978 * This means that either we are receiving a reinvite for a terminated dialog, or we are receiving an INVITE with 19979 * credentials based on one we challenged earlier. 19980 * 19981 * The action to take in either case is to treat the INVITE as though it contains an implicit ACK for the previous 19982 * transaction. Calling __sip_ack will take care of this by clearing the p->pendinginvite and removing the response 19983 * from the previous transaction from the list of outstanding packets. 19984 */ 19985 __sip_ack(p, p->pendinginvite, 1, 0); 19986 } else { 19987 /* We already have a pending invite. Sorry. You are on hold. */ 19988 p->glareinvite = seqno; /* must hold on to this seqno to process ack and retransmit correctly */ 19989 if (p->rtp && find_sdp(req)) { 19990 struct sockaddr_in sin; 19991 if (get_ip_and_port_from_sdp(req, SDP_AUDIO, &sin)) { 19992 ast_log(LOG_WARNING, "Failed to set an alternate media source on glared reinvite. Audio may not work properly on this call.\n"); 19993 } else { 19994 ast_rtp_set_alt_peer(p->rtp, &sin); 19995 } 19996 if (p->vrtp) { 19997 if (get_ip_and_port_from_sdp(req, SDP_VIDEO, &sin)) { 19998 ast_log(LOG_WARNING, "Failed to set an alternate media source on glared reinvite. Video may not work properly on this call.\n"); 19999 } else { 20000 ast_rtp_set_alt_peer(p->vrtp, &sin); 20001 } 20002 } 20003 } 20004 transmit_response_reliable(p, "491 Request Pending", req); 20005 ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid); 20006 /* Don't destroy dialog here */ 20007 res = 0; 20008 goto request_invite_cleanup; 20009 } 20010 } 20011 20012 p_replaces = get_header(req, "Replaces"); 20013 if (!ast_strlen_zero(p_replaces)) { 20014 /* We have a replaces header */ 20015 char *ptr; 20016 char *fromtag = NULL; 20017 char *totag = NULL; 20018 char *start, *to; 20019 int error = 0; 20020 20021 if (p->owner) { 20022 ast_debug(3, "INVITE w Replaces on existing call? Refusing action. [%s]\n", p->callid); 20023 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 20024 /* Do not destroy existing call */ 20025 res = -1; 20026 goto request_invite_cleanup; 20027 } 20028 20029 if (sipdebug) 20030 ast_debug(3, "INVITE part of call transfer. Replaces [%s]\n", p_replaces); 20031 /* Create a buffer we can manipulate */ 20032 replace_id = ast_strdupa(p_replaces); 20033 ast_uri_decode(replace_id); 20034 20035 if (!p->refer && !sip_refer_allocate(p)) { 20036 transmit_response_reliable(p, "500 Server Internal Error", req); 20037 append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory."); 20038 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20039 p->invitestate = INV_COMPLETED; 20040 res = -1; 20041 goto request_invite_cleanup; 20042 } 20043 20044 /* Todo: (When we find phones that support this) 20045 if the replaces header contains ";early-only" 20046 we can only replace the call in early 20047 stage, not after it's up. 20048 20049 If it's not in early mode, 486 Busy. 20050 */ 20051 20052 /* Skip leading whitespace */ 20053 replace_id = ast_skip_blanks(replace_id); 20054 20055 start = replace_id; 20056 while ( (ptr = strsep(&start, ";")) ) { 20057 ptr = ast_skip_blanks(ptr); /* XXX maybe unnecessary ? */ 20058 if ( (to = strcasestr(ptr, "to-tag=") ) ) 20059 totag = to + 7; /* skip the keyword */ 20060 else if ( (to = strcasestr(ptr, "from-tag=") ) ) { 20061 fromtag = to + 9; /* skip the keyword */ 20062 fromtag = strsep(&fromtag, "&"); /* trim what ? */ 20063 } 20064 } 20065 20066 if (sipdebug) 20067 ast_debug(4, "Invite/replaces: Will use Replace-Call-ID : %s Fromtag: %s Totag: %s\n", 20068 replace_id, 20069 fromtag ? fromtag : "<no from tag>", 20070 totag ? totag : "<no to tag>"); 20071 20072 /* Try to find call that we are replacing. 20073 If we have a Replaces header, we need to cancel that call if we succeed with this call. 20074 First we cheat a little and look for a magic call-id from phones that support 20075 dialog-info+xml so we can do technology independent pickup... */ 20076 if (strncmp(replace_id, "pickup-", 7) == 0) { 20077 struct sip_pvt *subscription = NULL; 20078 replace_id += 7; /* Worst case we are looking at \0 */ 20079 20080 if ((subscription = get_sip_pvt_byid_locked(replace_id, totag, fromtag)) == NULL) { 20081 ast_log(LOG_NOTICE, "Unable to find subscription with call-id: %s\n", replace_id); 20082 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replaces)", req); 20083 error = 1; 20084 } else { 20085 ast_log(LOG_NOTICE, "Trying to pick up %s@%s\n", subscription->exten, subscription->context); 20086 ast_copy_string(pickup.exten, subscription->exten, sizeof(pickup.exten)); 20087 ast_copy_string(pickup.context, subscription->context, sizeof(pickup.context)); 20088 sip_pvt_unlock(subscription); 20089 if (subscription->owner) { 20090 ast_channel_unlock(subscription->owner); 20091 } 20092 } 20093 } 20094 20095 /* This locks both refer_call pvt and refer_call pvt's owner!!!*/ 20096 if (!error && ast_strlen_zero(pickup.exten) && (p->refer->refer_call = get_sip_pvt_byid_locked(replace_id, totag, fromtag)) == NULL) { 20097 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existent call id (%s)!\n", replace_id); 20098 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replaces)", req); 20099 error = 1; 20100 } else { 20101 refer_locked = 1; 20102 } 20103 20104 /* The matched call is the call from the transferer to Asterisk . 20105 We want to bridge the bridged part of the call to the 20106 incoming invite, thus taking over the refered call */ 20107 20108 if (p->refer->refer_call == p) { 20109 ast_log(LOG_NOTICE, "INVITE with replaces into it's own call id (%s == %s)!\n", replace_id, p->callid); 20110 p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); 20111 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 20112 error = 1; 20113 } 20114 20115 if (!error && ast_strlen_zero(pickup.exten) && !p->refer->refer_call->owner) { 20116 /* Oops, someting wrong anyway, no owner, no call */ 20117 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existing call id (%s)!\n", replace_id); 20118 /* Check for better return code */ 20119 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replace)", req); 20120 error = 1; 20121 } 20122 20123 if (!error && ast_strlen_zero(pickup.exten) && p->refer->refer_call->owner->_state != AST_STATE_RINGING && p->refer->refer_call->owner->_state != AST_STATE_RING && p->refer->refer_call->owner->_state != AST_STATE_UP) { 20124 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-ringing or active call id (%s)!\n", replace_id); 20125 transmit_response_reliable(p, "603 Declined (Replaces)", req); 20126 error = 1; 20127 } 20128 20129 if (error) { /* Give up this dialog */ 20130 append_history(p, "Xfer", "INVITE/Replace Failed."); 20131 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20132 sip_pvt_unlock(p); 20133 if (p->refer->refer_call) { 20134 sip_pvt_unlock(p->refer->refer_call); 20135 if (p->refer->refer_call->owner) { 20136 ast_channel_unlock(p->refer->refer_call->owner); 20137 } 20138 } 20139 refer_locked = 0; 20140 p->invitestate = INV_COMPLETED; 20141 res = -1; 20142 goto request_invite_cleanup; 20143 } 20144 } 20145 20146 /* Check if this is an INVITE that sets up a new dialog or 20147 a re-invite in an existing dialog */ 20148 20149 if (!req->ignore) { 20150 int newcall = (p->initreq.headers ? TRUE : FALSE); 20151 20152 if (sip_cancel_destroy(p)) 20153 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20154 /* This also counts as a pending invite */ 20155 p->pendinginvite = seqno; 20156 check_via(p, req); 20157 20158 copy_request(&p->initreq, req); /* Save this INVITE as the transaction basis */ 20159 if (sipdebug) 20160 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 20161 if (!p->owner) { /* Not a re-invite */ 20162 if (debug) 20163 ast_verbose("Using INVITE request as basis request - %s\n", p->callid); 20164 if (newcall) 20165 append_history(p, "Invite", "New call: %s", p->callid); 20166 parse_ok_contact(p, req); 20167 } else { /* Re-invite on existing call */ 20168 ast_clear_flag(&p->flags[0], SIP_OUTGOING); /* This is now an inbound dialog */ 20169 /* Handle SDP here if we already have an owner */ 20170 if (find_sdp(req)) { 20171 if (process_sdp(p, req, SDP_T38_INITIATE)) { 20172 transmit_response_reliable(p, "488 Not acceptable here", req); 20173 if (!p->lastinvite) 20174 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20175 res = -1; 20176 goto request_invite_cleanup; 20177 } 20178 ast_queue_control(p->owner, AST_CONTROL_SRCUPDATE); 20179 } else { 20180 p->jointcapability = p->capability; 20181 ast_debug(1, "Hm.... No sdp for the moment\n"); 20182 /* Some devices signal they want to be put off hold by sending a re-invite 20183 *without* an SDP, which is supposed to mean "Go back to your state" 20184 and since they put os on remote hold, we go back to off hold */ 20185 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 20186 ast_queue_control(p->owner, AST_CONTROL_UNHOLD); 20187 /* Activate a re-invite */ 20188 ast_queue_frame(p->owner, &ast_null_frame); 20189 change_hold_state(p, req, FALSE, 0); 20190 } 20191 } 20192 if (p->do_history) /* This is a response, note what it was for */ 20193 append_history(p, "ReInv", "Re-invite received"); 20194 } 20195 } else if (debug) 20196 ast_verbose("Ignoring this INVITE request\n"); 20197 20198 if (!p->lastinvite && !req->ignore && !p->owner) { 20199 /* This is a new invite */ 20200 /* Handle authentication if this is our first invite */ 20201 res = check_user(p, req, SIP_INVITE, e, XMIT_RELIABLE, sin); 20202 if (res == AUTH_CHALLENGE_SENT) { 20203 p->invitestate = INV_COMPLETED; /* Needs to restart in another INVITE transaction */ 20204 res = 0; 20205 goto request_invite_cleanup; 20206 } 20207 if (res < 0) { /* Something failed in authentication */ 20208 if (res == AUTH_FAKE_AUTH) { 20209 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 20210 transmit_fake_auth_response(p, SIP_INVITE, req, XMIT_RELIABLE); 20211 } else { 20212 ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From")); 20213 transmit_response_reliable(p, "403 Forbidden", req); 20214 } 20215 p->invitestate = INV_COMPLETED; 20216 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20217 ast_string_field_set(p, theirtag, NULL); 20218 res = 0; 20219 goto request_invite_cleanup; 20220 } 20221 20222 /* If T38 is needed but not present, then make it magically appear */ 20223 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && !p->udptl) { 20224 if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) { 20225 p->t38_maxdatagram = global_t38_maxdatagram; 20226 set_t38_capabilities(p); 20227 } else { 20228 /* udptl creation failed, T38 can not be supported on this dialog */ 20229 ast_debug(1, "UDPTL creation failed on dialog.\n"); 20230 ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT); 20231 } 20232 } 20233 20234 /* We have a succesful authentication, process the SDP portion if there is one */ 20235 if (find_sdp(req)) { 20236 if (process_sdp(p, req, SDP_T38_INITIATE)) { 20237 /* Unacceptable codecs */ 20238 transmit_response_reliable(p, "488 Not acceptable here", req); 20239 p->invitestate = INV_COMPLETED; 20240 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20241 ast_debug(1, "No compatible codecs for this SIP call.\n"); 20242 res = -1; 20243 goto request_invite_cleanup; 20244 } 20245 } else { /* No SDP in invite, call control session */ 20246 p->jointcapability = p->capability; 20247 ast_debug(2, "No SDP in Invite, third party call control\n"); 20248 } 20249 20250 /* Queue NULL frame to prod ast_rtp_bridge if appropriate */ 20251 /* This seems redundant ... see !p-owner above */ 20252 if (p->owner) 20253 ast_queue_frame(p->owner, &ast_null_frame); 20254 20255 20256 /* Initialize the context if it hasn't been already */ 20257 if (ast_strlen_zero(p->context)) 20258 ast_string_field_set(p, context, sip_cfg.default_context); 20259 20260 20261 /* Check number of concurrent calls -vs- incoming limit HERE */ 20262 ast_debug(1, "Checking SIP call limits for device %s\n", p->username); 20263 if ((res = update_call_counter(p, INC_CALL_LIMIT))) { 20264 if (res < 0) { 20265 ast_log(LOG_NOTICE, "Failed to place call for device %s, too many calls\n", p->username); 20266 transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req); 20267 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20268 p->invitestate = INV_COMPLETED; 20269 } 20270 res = 0; 20271 goto request_invite_cleanup; 20272 } 20273 gotdest = get_destination(p, NULL); /* Get destination right away */ 20274 get_rdnis(p, NULL); /* Get redirect information */ 20275 extract_uri(p, req); /* Get the Contact URI */ 20276 build_contact(p); /* Build our contact header */ 20277 20278 if (p->rtp) { 20279 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 20280 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 20281 } 20282 20283 if (!replace_id && gotdest) { /* No matching extension found */ 20284 if (gotdest == 1 && ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP)) 20285 transmit_response_reliable(p, "484 Address Incomplete", req); 20286 else { 20287 char *decoded_exten = ast_strdupa(p->exten); 20288 20289 transmit_response_reliable(p, "404 Not Found", req); 20290 ast_uri_decode(decoded_exten); 20291 ast_log(LOG_NOTICE, "Call from '%s' to extension" 20292 " '%s' rejected because extension not found in context '%s'.\n", 20293 S_OR(p->username, p->peername), decoded_exten, p->context); 20294 } 20295 p->invitestate = INV_COMPLETED; 20296 update_call_counter(p, DEC_CALL_LIMIT); 20297 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20298 res = 0; 20299 goto request_invite_cleanup; 20300 } else { 20301 20302 /* If no extension was specified, use the s one */ 20303 /* Basically for calling to IP/Host name only */ 20304 if (ast_strlen_zero(p->exten)) 20305 ast_string_field_set(p, exten, "s"); 20306 /* Initialize our tag */ 20307 20308 make_our_tag(p->tag, sizeof(p->tag)); 20309 /* First invitation - create the channel. Allocation 20310 * failures are handled below. */ 20311 c = sip_new(p, AST_STATE_DOWN, S_OR(p->peername, NULL)); 20312 *recount = 1; 20313 20314 /* Save Record-Route for any later requests we make on this dialogue */ 20315 build_route(p, req, 0); 20316 20317 if (c) { 20318 /* Pre-lock the call */ 20319 ast_channel_lock(c); 20320 } 20321 } 20322 } else { 20323 if (sipdebug) { 20324 if (!req->ignore) 20325 ast_debug(2, "Got a SIP re-invite for call %s\n", p->callid); 20326 else 20327 ast_debug(2, "Got a SIP re-transmit of INVITE for call %s\n", p->callid); 20328 } 20329 if (!req->ignore) 20330 reinvite = 1; 20331 c = p->owner; 20332 } 20333 20334 /* Session-Timers */ 20335 if ((p->sipoptions & SIP_OPT_TIMER) && !ast_strlen_zero(get_header(req, "Session-Expires"))) { 20336 /* The UAC has requested session-timers for this session. Negotiate 20337 the session refresh interval and who will be the refresher */ 20338 ast_debug(2, "Incoming INVITE with 'timer' option supported and \"Session-Expires\" header.\n"); 20339 20340 /* Allocate Session-Timers struct w/in the dialog */ 20341 if (!p->stimer) 20342 sip_st_alloc(p); 20343 20344 /* Parse the Session-Expires header */ 20345 p_uac_se_hdr = get_header(req, "Session-Expires"); 20346 rtn = parse_session_expires(p_uac_se_hdr, &uac_max_se, &st_ref); 20347 if (rtn != 0) { 20348 transmit_response_reliable(p, "400 Session-Expires Invalid Syntax", req); 20349 p->invitestate = INV_COMPLETED; 20350 if (!p->lastinvite) { 20351 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20352 } 20353 res = -1; 20354 goto request_invite_cleanup; 20355 } 20356 20357 /* Parse the Min-SE header */ 20358 p_uac_min_se = get_header(req, "Min-SE"); 20359 if (!ast_strlen_zero(p_uac_min_se)) { 20360 rtn = parse_minse(p_uac_min_se, &uac_min_se); 20361 if (rtn != 0) { 20362 transmit_response_reliable(p, "400 Min-SE Invalid Syntax", req); 20363 p->invitestate = INV_COMPLETED; 20364 if (!p->lastinvite) { 20365 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20366 } 20367 res = -1; 20368 goto request_invite_cleanup; 20369 } 20370 } 20371 20372 dlg_min_se = st_get_se(p, FALSE); 20373 switch (st_get_mode(p)) { 20374 case SESSION_TIMER_MODE_ACCEPT: 20375 case SESSION_TIMER_MODE_ORIGINATE: 20376 if (uac_max_se > 0 && uac_max_se < dlg_min_se) { 20377 transmit_response_with_minse(p, "422 Session Interval Too Small", req, dlg_min_se); 20378 p->invitestate = INV_COMPLETED; 20379 if (!p->lastinvite) { 20380 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20381 } 20382 res = -1; 20383 goto request_invite_cleanup; 20384 } 20385 20386 p->stimer->st_active_peer_ua = TRUE; 20387 st_active = TRUE; 20388 if (st_ref == SESSION_TIMER_REFRESHER_AUTO) { 20389 st_ref = st_get_refresher(p); 20390 } 20391 20392 if (uac_max_se > 0) { 20393 int dlg_max_se = st_get_se(p, TRUE); 20394 if (dlg_max_se >= uac_min_se) { 20395 st_interval = (uac_max_se < dlg_max_se) ? uac_max_se : dlg_max_se; 20396 } else { 20397 st_interval = uac_max_se; 20398 } 20399 } else { 20400 /* Set to default max value */ 20401 st_interval = global_max_se; 20402 } 20403 break; 20404 20405 case SESSION_TIMER_MODE_REFUSE: 20406 if (p->reqsipoptions & SIP_OPT_TIMER) { 20407 transmit_response_with_unsupported(p, "420 Option Disabled", req, required); 20408 ast_log(LOG_WARNING, "Received SIP INVITE with supported but disabled option: %s\n", required); 20409 p->invitestate = INV_COMPLETED; 20410 if (!p->lastinvite) { 20411 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20412 } 20413 res = -1; 20414 goto request_invite_cleanup; 20415 } 20416 break; 20417 20418 default: 20419 ast_log(LOG_ERROR, "Internal Error %d at %s:%d\n", st_get_mode(p), __FILE__, __LINE__); 20420 break; 20421 } 20422 } else { 20423 /* The UAC did not request session-timers. Asterisk (UAS), will now decide 20424 (based on session-timer-mode in sip.conf) whether to run session-timers for 20425 this session or not. */ 20426 switch (st_get_mode(p)) { 20427 case SESSION_TIMER_MODE_ORIGINATE: 20428 st_active = TRUE; 20429 st_interval = st_get_se(p, TRUE); 20430 st_ref = SESSION_TIMER_REFRESHER_UAS; 20431 p->stimer->st_active_peer_ua = FALSE; 20432 break; 20433 20434 default: 20435 break; 20436 } 20437 } 20438 20439 if (reinvite == 0) { 20440 /* Session-Timers: Start session refresh timer based on negotiation/config */ 20441 if (st_active == TRUE) { 20442 p->stimer->st_active = TRUE; 20443 p->stimer->st_interval = st_interval; 20444 p->stimer->st_ref = st_ref; 20445 start_session_timer(p); 20446 } 20447 } else { 20448 if (p->stimer->st_active == TRUE) { 20449 /* Session-Timers: A re-invite request sent within a dialog will serve as 20450 a refresh request, no matter whether the re-invite was sent for refreshing 20451 the session or modifying it.*/ 20452 ast_debug (2, "Restarting session-timers on a refresh - %s\n", p->callid); 20453 20454 /* The UAC may be adjusting the session-timers mid-session */ 20455 if (st_interval > 0) { 20456 p->stimer->st_interval = st_interval; 20457 p->stimer->st_ref = st_ref; 20458 } 20459 20460 restart_session_timer(p); 20461 if (p->stimer->st_expirys > 0) { 20462 p->stimer->st_expirys--; 20463 } 20464 } 20465 } 20466 20467 if (!req->ignore && p) 20468 p->lastinvite = seqno; 20469 20470 if (c && replace_id) { /* Attended transfer or call pickup - we're the target */ 20471 if (!ast_strlen_zero(pickup.exten)) { 20472 append_history(p, "Xfer", "INVITE/Replace received"); 20473 20474 /* Let the caller know we're giving it a shot */ 20475 transmit_response(p, "100 Trying", req); 20476 p->invitestate = INV_PROCEEDING; 20477 ast_setstate(c, AST_STATE_RING); 20478 20479 /* Do the pickup itself */ 20480 ast_channel_unlock(c); 20481 *nounlock = 1; 20482 do_magic_pickup(c, pickup.exten, pickup.context); 20483 20484 /* Now we're either masqueraded or we failed to pickup, in either case we... */ 20485 sip_pvt_unlock(p); 20486 ast_hangup(c); 20487 sip_pvt_lock(p); 20488 20489 res = 0; 20490 goto request_invite_cleanup; 20491 } else { 20492 /* Go and take over the target call */ 20493 if (sipdebug) 20494 ast_debug(4, "Sending this call to the invite/replcaes handler %s\n", p->callid); 20495 res = handle_invite_replaces(p, req, debug, seqno, sin, nounlock); 20496 refer_locked = 0; 20497 goto request_invite_cleanup; 20498 } 20499 } 20500 20501 20502 if (c) { /* We have a call -either a new call or an old one (RE-INVITE) */ 20503 enum ast_channel_state c_state = c->_state; 20504 20505 if (c_state != AST_STATE_UP && reinvite && 20506 (p->invitestate == INV_TERMINATED || p->invitestate == INV_CONFIRMED)) { 20507 /* If these conditions are true, and the channel is still in the 'ringing' 20508 * state, then this likely means that we have a situation where the initial 20509 * INVITE transaction has completed *but* the channel's state has not yet been 20510 * changed to UP. The reason this could happen is if the reinvite is received 20511 * on the SIP socket prior to an application calling ast_read on this channel 20512 * to read the answer frame we earlier queued on it. In this case, the reinvite 20513 * is completely legitimate so we need to handle this the same as if the channel 20514 * were already UP. Thus we are purposely falling through to the AST_STATE_UP case. 20515 */ 20516 c_state = AST_STATE_UP; 20517 } 20518 20519 switch(c_state) { 20520 case AST_STATE_DOWN: 20521 ast_debug(2, "%s: New call is still down.... Trying... \n", c->name); 20522 transmit_provisional_response(p, "100 Trying", req, 0); 20523 p->invitestate = INV_PROCEEDING; 20524 ast_setstate(c, AST_STATE_RING); 20525 if (strcmp(p->exten, ast_pickup_ext())) { /* Call to extension -start pbx on this call */ 20526 enum ast_pbx_result result; 20527 20528 result = ast_pbx_start(c); 20529 20530 switch(result) { 20531 case AST_PBX_FAILED: 20532 ast_log(LOG_WARNING, "Failed to start PBX :(\n"); 20533 p->invitestate = INV_COMPLETED; 20534 transmit_response_reliable(p, "503 Unavailable", req); 20535 break; 20536 case AST_PBX_CALL_LIMIT: 20537 ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n"); 20538 p->invitestate = INV_COMPLETED; 20539 transmit_response_reliable(p, "480 Temporarily Unavailable", req); 20540 break; 20541 case AST_PBX_SUCCESS: 20542 /* nothing to do */ 20543 break; 20544 } 20545 20546 if (result) { 20547 20548 /* Unlock locks so ast_hangup can do its magic */ 20549 ast_channel_unlock(c); 20550 sip_pvt_unlock(p); 20551 ast_hangup(c); 20552 sip_pvt_lock(p); 20553 c = NULL; 20554 } 20555 } else { /* Pickup call in call group */ 20556 ast_channel_unlock(c); 20557 *nounlock = 1; 20558 if (ast_pickup_call(c)) { 20559 ast_log(LOG_NOTICE, "Nothing to pick up for %s\n", p->callid); 20560 transmit_response_reliable(p, "503 Unavailable", req); 20561 sip_alreadygone(p); 20562 /* Unlock locks so ast_hangup can do its magic */ 20563 sip_pvt_unlock(p); 20564 c->hangupcause = AST_CAUSE_CALL_REJECTED; 20565 } else { 20566 sip_pvt_unlock(p); 20567 ast_setstate(c, AST_STATE_DOWN); 20568 c->hangupcause = AST_CAUSE_NORMAL_CLEARING; 20569 } 20570 p->invitestate = INV_COMPLETED; 20571 ast_hangup(c); 20572 sip_pvt_lock(p); 20573 c = NULL; 20574 } 20575 break; 20576 case AST_STATE_RING: 20577 transmit_provisional_response(p, "100 Trying", req, 0); 20578 p->invitestate = INV_PROCEEDING; 20579 break; 20580 case AST_STATE_RINGING: 20581 transmit_provisional_response(p, "180 Ringing", req, 0); 20582 p->invitestate = INV_PROCEEDING; 20583 break; 20584 case AST_STATE_UP: 20585 ast_debug(2, "%s: This call is UP.... \n", c->name); 20586 20587 transmit_response(p, "100 Trying", req); 20588 20589 if (p->t38.state == T38_PEER_REINVITE) { 20590 p->t38id = ast_sched_add(sched, 5000, sip_t38_abort, dialog_ref(p, "passing dialog ptr into sched structure based on t38id for sip_t38_abort.")); 20591 } else if (p->t38.state == T38_ENABLED) { 20592 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 20593 transmit_response_with_t38_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL))); 20594 } else if (p->t38.state == T38_DISABLED) { 20595 /* If this is not a re-invite or something to ignore - it's critical */ 20596 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 20597 transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL)), p->session_modify == TRUE ? FALSE:TRUE); 20598 } 20599 20600 p->invitestate = INV_TERMINATED; 20601 break; 20602 default: 20603 ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state); 20604 transmit_response(p, "100 Trying", req); 20605 break; 20606 } 20607 } else { 20608 if (p && (p->autokillid == -1)) { 20609 const char *msg; 20610 20611 if (!p->jointcapability) 20612 msg = "488 Not Acceptable Here (codec error)"; 20613 else { 20614 ast_log(LOG_NOTICE, "Unable to create/find SIP channel for this INVITE\n"); 20615 msg = "503 Unavailable"; 20616 } 20617 transmit_response_reliable(p, msg, req); 20618 p->invitestate = INV_COMPLETED; 20619 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20620 } 20621 } 20622 20623 request_invite_cleanup: 20624 20625 if (refer_locked && p->refer && p->refer->refer_call) { 20626 sip_pvt_unlock(p->refer->refer_call); 20627 if (p->refer->refer_call->owner) { 20628 ast_channel_unlock(p->refer->refer_call->owner); 20629 } 20630 } 20631 20632 return res; 20633 }
| static int handle_request_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming MESSAGE request.
Definition at line 21390 of file chan_sip.c.
References ast_verbose, sip_request::debug, sip_request::ignore, receive_message(), and transmit_response().
Referenced by handle_incoming().
21391 { 21392 if (!req->ignore) { 21393 if (req->debug) 21394 ast_verbose("Receiving message!\n"); 21395 receive_message(p, req); 21396 } else 21397 transmit_response(p, "202 Accepted", req); 21398 return 1; 21399 }
| static int handle_request_notify | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int | seqno, | |||
| char * | e | |||
| ) | [static] |
Handle incoming notifications.
Definition at line 19210 of file chan_sip.c.
References ast_debug, AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI, ast_event_new(), ast_event_queue_and_cache(), ast_log(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), buf, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, FALSE, get_body(), get_header(), get_msg_text(), sip_pvt::lastinvite, LOG_NOTICE, LOG_WARNING, sip_subscription_mwi::mailbox, sip_pvt::mwi, sip_scheddestroy(), strsep(), transmit_response(), and TRUE.
Referenced by handle_incoming().
19211 { 19212 /* This is mostly a skeleton for future improvements */ 19213 /* Mostly created to return proper answers on notifications on outbound REFER's */ 19214 int res = 0; 19215 const char *event = get_header(req, "Event"); 19216 char *eventid = NULL; 19217 char *sep; 19218 19219 if( (sep = strchr(event, ';')) ) { /* XXX bug here - overwriting string ? */ 19220 *sep++ = '\0'; 19221 eventid = sep; 19222 } 19223 19224 if (sipdebug) 19225 ast_debug(2, "Got NOTIFY Event: %s\n", event); 19226 19227 if (!strcmp(event, "refer")) { 19228 /* Save nesting depth for now, since there might be other events we will 19229 support in the future */ 19230 19231 /* Handle REFER notifications */ 19232 19233 char buf[1024]; 19234 char *cmd, *code; 19235 int respcode; 19236 int success = TRUE; 19237 19238 /* EventID for each transfer... EventID is basically the REFER cseq 19239 19240 We are getting notifications on a call that we transfered 19241 We should hangup when we are getting a 200 OK in a sipfrag 19242 Check if we have an owner of this event */ 19243 19244 /* Check the content type */ 19245 if (strncasecmp(get_header(req, "Content-Type"), "message/sipfrag", strlen("message/sipfrag"))) { 19246 /* We need a sipfrag */ 19247 transmit_response(p, "400 Bad request", req); 19248 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19249 return -1; 19250 } 19251 19252 /* Get the text of the attachment */ 19253 if (get_msg_text(buf, sizeof(buf), req, TRUE)) { 19254 ast_log(LOG_WARNING, "Unable to retrieve attachment from NOTIFY %s\n", p->callid); 19255 transmit_response(p, "400 Bad request", req); 19256 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19257 return -1; 19258 } 19259 19260 /* 19261 From the RFC... 19262 A minimal, but complete, implementation can respond with a single 19263 NOTIFY containing either the body: 19264 SIP/2.0 100 Trying 19265 19266 if the subscription is pending, the body: 19267 SIP/2.0 200 OK 19268 if the reference was successful, the body: 19269 SIP/2.0 503 Service Unavailable 19270 if the reference failed, or the body: 19271 SIP/2.0 603 Declined 19272 19273 if the REFER request was accepted before approval to follow the 19274 reference could be obtained and that approval was subsequently denied 19275 (see Section 2.4.7). 19276 19277 If there are several REFERs in the same dialog, we need to 19278 match the ID of the event header... 19279 */ 19280 ast_debug(3, "* SIP Transfer NOTIFY Attachment: \n---%s\n---\n", buf); 19281 cmd = ast_skip_blanks(buf); 19282 code = cmd; 19283 /* We are at SIP/2.0 */ 19284 while(*code && (*code > 32)) { /* Search white space */ 19285 code++; 19286 } 19287 *code++ = '\0'; 19288 code = ast_skip_blanks(code); 19289 sep = code; 19290 sep++; 19291 while(*sep && (*sep > 32)) { /* Search white space */ 19292 sep++; 19293 } 19294 *sep++ = '\0'; /* Response string */ 19295 respcode = atoi(code); 19296 switch (respcode) { 19297 case 100: /* Trying: */ 19298 case 101: /* dialog establishment */ 19299 /* Don't do anything yet */ 19300 break; 19301 case 183: /* Ringing: */ 19302 /* Don't do anything yet */ 19303 break; 19304 case 200: /* OK: The new call is up, hangup this call */ 19305 /* Hangup the call that we are replacing */ 19306 break; 19307 case 301: /* Moved permenantly */ 19308 case 302: /* Moved temporarily */ 19309 /* Do we get the header in the packet in this case? */ 19310 success = FALSE; 19311 break; 19312 case 503: /* Service Unavailable: The new call failed */ 19313 /* Cancel transfer, continue the call */ 19314 success = FALSE; 19315 break; 19316 case 603: /* Declined: Not accepted */ 19317 /* Cancel transfer, continue the current call */ 19318 success = FALSE; 19319 break; 19320 } 19321 if (!success) { 19322 ast_log(LOG_NOTICE, "Transfer failed. Sorry. Nothing further to do with this call\n"); 19323 } 19324 19325 /* Confirm that we received this packet */ 19326 transmit_response(p, "200 OK", req); 19327 } else if (p->mwi && !strcmp(event, "message-summary")) { 19328 char *c = ast_strdupa(get_body(req, "Voice-Message", ':')); 19329 19330 if (!ast_strlen_zero(c)) { 19331 char *old = strsep(&c, " "); 19332 char *new = strsep(&old, "/"); 19333 struct ast_event *event; 19334 19335 if ((event = ast_event_new(AST_EVENT_MWI, 19336 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, p->mwi->mailbox, 19337 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, "SIP_Remote", 19338 AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(new), 19339 AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(old), 19340 AST_EVENT_IE_END))) { 19341 ast_event_queue_and_cache(event); 19342 } 19343 } 19344 19345 transmit_response(p, "200 OK", req); 19346 } else if (!strcmp(event, "keep-alive")) { 19347 /* Used by Sipura/Linksys for NAT pinhole, 19348 * just confirm that we recieved the packet. */ 19349 transmit_response(p, "200 OK", req); 19350 } else { 19351 /* We don't understand this event. */ 19352 transmit_response(p, "489 Bad event", req); 19353 res = -1; 19354 } 19355 19356 if (!p->lastinvite) 19357 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19358 19359 return res; 19360 }
| static int handle_request_options | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming OPTIONS request An OPTIONS request should be answered like an INVITE from the same UA, including SDP.
XXX get_destination assumes we're already authenticated. This means that a request from a known device (peer) will end up in the wrong context if this is out-of-dialog. However, we want to handle OPTIONS as light as possible, so we might want to have a configuration option whether we care or not. Some devices use this for testing capabilities, which means that we need to match device to answer with proper capabilities (including SDP).
Definition at line 19365 of file chan_sip.c.
References ast_shutting_down(), ast_string_field_set, ast_strlen_zero(), build_contact(), context, sip_pvt::context, sip_settings::default_context, DEFAULT_TRANS_TIMEOUT, get_destination(), sip_pvt::lastinvite, sip_cfg, sip_scheddestroy(), and transmit_response_with_allow().
Referenced by handle_incoming().
19366 { 19367 int res; 19368 19369 /*! XXX get_destination assumes we're already authenticated. This means that a request from 19370 a known device (peer) will end up in the wrong context if this is out-of-dialog. 19371 However, we want to handle OPTIONS as light as possible, so we might want to have 19372 a configuration option whether we care or not. Some devices use this for testing 19373 capabilities, which means that we need to match device to answer with proper 19374 capabilities (including SDP). 19375 \todo Fix handle_request_options device handling with optional authentication 19376 (this needs to be fixed in 1.4 as well) 19377 */ 19378 19379 if (p->lastinvite) { 19380 /* if this is a request in an active dialog, just confirm that the dialog exists. */ 19381 transmit_response_with_allow(p, "200 OK", req, 0); 19382 return 0; 19383 } 19384 19385 res = get_destination(p, req); 19386 build_contact(p); 19387 19388 if (ast_strlen_zero(p->context)) 19389 ast_string_field_set(p, context, sip_cfg.default_context); 19390 19391 if (ast_shutting_down()) 19392 transmit_response_with_allow(p, "503 Unavailable", req, 0); 19393 else if (res < 0) 19394 transmit_response_with_allow(p, "404 Not Found", req, 0); 19395 else 19396 transmit_response_with_allow(p, "200 OK", req, 0); 19397 19398 /* Destroy if this OPTIONS was the opening request, but not if 19399 it's in the middle of a normal call flow. */ 19400 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19401 19402 return res; 19403 }
| static int handle_request_refer | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| int | seqno, | |||
| int * | nounlock | |||
| ) | [static] |
Definition at line 20804 of file chan_sip.c.
References sip_settings::allow_external_domains, sip_pvt::allowtransfer, append_history, ast_async_goto(), ast_bridged_channel(), AST_CAUSE_NORMAL_CLEARING, ast_channel_unlock, ast_clear_flag, AST_CONTROL_UNHOLD, ast_debug, AST_LIST_EMPTY, ast_parking_ext(), ast_queue_control(), ast_set_flag, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose, sip_refer::attendedtransfer, sip_pvt::callid, sip_dual::chan1, sip_dual::chan2, check_sip_domain(), context, sip_pvt::context, copy_request(), sip_request::data, sip_request::debug, sip_settings::default_context, EVENT_FLAG_CALL, FALSE, sip_pvt::flags, get_refer_info(), ast_channel::hangupcause, sip_request::ignore, local_attended_transfer(), sip_refer::localtransfer, manager_event, ast_channel::name, sip_pvt::owner, pbx_builtin_setvar_helper(), pvt_set_needdestroy(), sip_pvt::refer, REFER_200OK, REFER_FAILED, REFER_SENT, sip_refer::refer_to, sip_refer::refer_to_context, sip_refer::refer_to_domain, sip_refer::referred_by, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, sip_dual::req, sip_alreadygone(), sip_cfg, SIP_DEFER_BYE_ON_TRANSFER, SIP_GOTREFER, SIP_OUTGOING, sip_park(), sip_refer_allocate(), SIPBUFSIZE, sip_refer::status, TRANSFER_CLOSED, transmit_notify_with_sipfrag(), transmit_response(), TRUE, and ast_channel::uniqueid.
Referenced by handle_incoming().
20805 { 20806 struct sip_dual current; /* Chan1: Call between asterisk and transferer */ 20807 /* Chan2: Call between asterisk and transferee */ 20808 20809 int res = 0; 20810 current.req.data = NULL; 20811 20812 if (req->debug) 20813 ast_verbose("Call %s got a SIP call transfer from %s: (REFER)!\n", p->callid, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "callee" : "caller"); 20814 20815 if (!p->owner) { 20816 /* This is a REFER outside of an existing SIP dialog */ 20817 /* We can't handle that, so decline it */ 20818 ast_debug(3, "Call %s: Declined REFER, outside of dialog...\n", p->callid); 20819 transmit_response(p, "603 Declined (No dialog)", req); 20820 if (!req->ignore) { 20821 append_history(p, "Xfer", "Refer failed. Outside of dialog."); 20822 sip_alreadygone(p); 20823 pvt_set_needdestroy(p, "outside of dialog"); 20824 } 20825 return 0; 20826 } 20827 20828 20829 /* Check if transfer is allowed from this device */ 20830 if (p->allowtransfer == TRANSFER_CLOSED ) { 20831 /* Transfer not allowed, decline */ 20832 transmit_response(p, "603 Declined (policy)", req); 20833 append_history(p, "Xfer", "Refer failed. Allowtransfer == closed."); 20834 /* Do not destroy SIP session */ 20835 return 0; 20836 } 20837 20838 if (!req->ignore && ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 20839 /* Already have a pending REFER */ 20840 transmit_response(p, "491 Request pending", req); 20841 append_history(p, "Xfer", "Refer failed. Request pending."); 20842 return 0; 20843 } 20844 20845 /* Allocate memory for call transfer data */ 20846 if (!p->refer && !sip_refer_allocate(p)) { 20847 transmit_response(p, "500 Internal Server Error", req); 20848 append_history(p, "Xfer", "Refer failed. Memory allocation error."); 20849 return -3; 20850 } 20851 20852 res = get_refer_info(p, req); /* Extract headers */ 20853 20854 p->refer->status = REFER_SENT; 20855 20856 if (res != 0) { 20857 switch (res) { 20858 case -2: /* Syntax error */ 20859 transmit_response(p, "400 Bad Request (Refer-to missing)", req); 20860 append_history(p, "Xfer", "Refer failed. Refer-to missing."); 20861 if (req->debug) 20862 ast_debug(1, "SIP transfer to black hole can't be handled (no refer-to: )\n"); 20863 break; 20864 case -3: 20865 transmit_response(p, "603 Declined (Non sip: uri)", req); 20866 append_history(p, "Xfer", "Refer failed. Non SIP uri"); 20867 if (req->debug) 20868 ast_debug(1, "SIP transfer to non-SIP uri denied\n"); 20869 break; 20870 default: 20871 /* Refer-to extension not found, fake a failed transfer */ 20872 transmit_response(p, "202 Accepted", req); 20873 append_history(p, "Xfer", "Refer failed. Bad extension."); 20874 transmit_notify_with_sipfrag(p, seqno, "404 Not found", TRUE); 20875 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 20876 if (req->debug) 20877 ast_debug(1, "SIP transfer to bad extension: %s\n", p->refer->refer_to); 20878 break; 20879 } 20880 return 0; 20881 } 20882 if (ast_strlen_zero(p->context)) 20883 ast_string_field_set(p, context, sip_cfg.default_context); 20884 20885 /* If we do not support SIP domains, all transfers are local */ 20886 if (sip_cfg.allow_external_domains && check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 20887 p->refer->localtransfer = 1; 20888 if (sipdebug) 20889 ast_debug(3, "This SIP transfer is local : %s\n", p->refer->refer_to_domain); 20890 } else if (AST_LIST_EMPTY(&domain_list) || check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 20891 /* This PBX doesn't bother with SIP domains or domain is local, so this transfer is local */ 20892 p->refer->localtransfer = 1; 20893 } else if (sipdebug) 20894 ast_debug(3, "This SIP transfer is to a remote SIP extension (remote domain %s)\n", p->refer->refer_to_domain); 20895 20896 /* Is this a repeat of a current request? Ignore it */ 20897 /* Don't know what else to do right now. */ 20898 if (req->ignore) 20899 return res; 20900 20901 /* If this is a blind transfer, we have the following 20902 channels to work with: 20903 - chan1, chan2: The current call between transferer and transferee (2 channels) 20904 - target_channel: A new call from the transferee to the target (1 channel) 20905 We need to stay tuned to what happens in order to be able 20906 to bring back the call to the transferer */ 20907 20908 /* If this is a attended transfer, we should have all call legs within reach: 20909 - chan1, chan2: The call between the transferer and transferee (2 channels) 20910 - target_channel, targetcall_pvt: The call between the transferer and the target (2 channels) 20911 We want to bridge chan2 with targetcall_pvt! 20912 20913 The replaces call id in the refer message points 20914 to the call leg between Asterisk and the transferer. 20915 So we need to connect the target and the transferee channel 20916 and hangup the two other channels silently 20917 20918 If the target is non-local, the call ID could be on a remote 20919 machine and we need to send an INVITE with replaces to the 20920 target. We basically handle this as a blind transfer 20921 and let the sip_call function catch that we need replaces 20922 header in the INVITE. 20923 */ 20924 20925 20926 /* Get the transferer's channel */ 20927 current.chan1 = p->owner; 20928 20929 /* Find the other part of the bridge (2) - transferee */ 20930 current.chan2 = ast_bridged_channel(current.chan1); 20931 20932 if (sipdebug) 20933 ast_debug(3, "SIP %s transfer: Transferer channel %s, transferee channel %s\n", p->refer->attendedtransfer ? "attended" : "blind", current.chan1->name, current.chan2 ? current.chan2->name : "<none>"); 20934 20935 if (!current.chan2 && !p->refer->attendedtransfer) { 20936 /* No bridged channel, propably IVR or echo or similar... */ 20937 /* Guess we should masquerade or something here */ 20938 /* Until we figure it out, refuse transfer of such calls */ 20939 if (sipdebug) 20940 ast_debug(3, "Refused SIP transfer on non-bridged channel.\n"); 20941 p->refer->status = REFER_FAILED; 20942 append_history(p, "Xfer", "Refer failed. Non-bridged channel."); 20943 transmit_response(p, "603 Declined", req); 20944 return -1; 20945 } 20946 20947 if (current.chan2) { 20948 if (sipdebug) 20949 ast_debug(4, "Got SIP transfer, applying to bridged peer '%s'\n", current.chan2->name); 20950 20951 ast_queue_control(current.chan1, AST_CONTROL_UNHOLD); 20952 } 20953 20954 ast_set_flag(&p->flags[0], SIP_GOTREFER); 20955 20956 /* Attended transfer: Find all call legs and bridge transferee with target*/ 20957 if (p->refer->attendedtransfer) { 20958 if ((res = local_attended_transfer(p, ¤t, req, seqno))) 20959 return res; /* We're done with the transfer */ 20960 /* Fall through for remote transfers that we did not find locally */ 20961 if (sipdebug) 20962 ast_debug(4, "SIP attended transfer: Still not our call - generating INVITE with replaces\n"); 20963 /* Fallthrough if we can't find the call leg internally */ 20964 } 20965 20966 20967 /* Parking a call */ 20968 if (p->refer->localtransfer && !strcmp(p->refer->refer_to, ast_parking_ext())) { 20969 /* Must release c's lock now, because it will not longer be accessible after the transfer! */ 20970 *nounlock = 1; 20971 ast_channel_unlock(current.chan1); 20972 copy_request(¤t.req, req); 20973 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 20974 p->refer->status = REFER_200OK; 20975 append_history(p, "Xfer", "REFER to call parking."); 20976 manager_event(EVENT_FLAG_CALL, "Transfer", "TransferMethod: SIP\r\nTransferType: Blind\r\nChannel: %s\r\nUniqueid: %s\r\nSIP-Callid: %s\r\nTargetChannel: %s\r\nTargetUniqueid: %s\r\nTransferExten: %s\r\nTransfer2Parking: Yes\r\n", 20977 current.chan1->name, 20978 current.chan1->uniqueid, 20979 p->callid, 20980 current.chan2->name, 20981 current.chan2->uniqueid, 20982 p->refer->refer_to); 20983 if (sipdebug) 20984 ast_debug(4, "SIP transfer to parking: trying to park %s. Parked by %s\n", current.chan2->name, current.chan1->name); 20985 sip_park(current.chan2, current.chan1, req, seqno); 20986 return res; 20987 } 20988 20989 /* Blind transfers and remote attended xfers */ 20990 transmit_response(p, "202 Accepted", req); 20991 20992 if (current.chan1 && current.chan2) { 20993 ast_debug(3, "chan1->name: %s\n", current.chan1->name); 20994 pbx_builtin_setvar_helper(current.chan1, "BLINDTRANSFER", current.chan2->name); 20995 } 20996 if (current.chan2) { 20997 pbx_builtin_setvar_helper(current.chan2, "BLINDTRANSFER", current.chan1->name); 20998 pbx_builtin_setvar_helper(current.chan2, "SIPDOMAIN", p->refer->refer_to_domain); 20999 pbx_builtin_setvar_helper(current.chan2, "SIPTRANSFER", "yes"); 21000 /* One for the new channel */ 21001 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER", "yes"); 21002 /* Attended transfer to remote host, prepare headers for the INVITE */ 21003 if (p->refer->referred_by) 21004 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REFERER", p->refer->referred_by); 21005 } 21006 /* Generate a Replaces string to be used in the INVITE during attended transfer */ 21007 if (!ast_strlen_zero(p->refer->replaces_callid)) { 21008 char tempheader[SIPBUFSIZE]; 21009 snprintf(tempheader, sizeof(tempheader), "%s%s%s%s%s", p->refer->replaces_callid, 21010 p->refer->replaces_callid_totag ? ";to-tag=" : "", 21011 p->refer->replaces_callid_totag, 21012 p->refer->replaces_callid_fromtag ? ";from-tag=" : "", 21013 p->refer->replaces_callid_fromtag); 21014 if (current.chan2) 21015 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REPLACES", tempheader); 21016 } 21017 /* Must release lock now, because it will not longer 21018 be accessible after the transfer! */ 21019 *nounlock = 1; 21020 ast_channel_unlock(current.chan1); 21021 21022 /* Connect the call */ 21023 21024 /* FAKE ringing if not attended transfer */ 21025 if (!p->refer->attendedtransfer) 21026 transmit_notify_with_sipfrag(p, seqno, "183 Ringing", FALSE); 21027 21028 /* For blind transfer, this will lead to a new call */ 21029 /* For attended transfer to remote host, this will lead to 21030 a new SIP call with a replaces header, if the dial plan allows it 21031 */ 21032 if (!current.chan2) { 21033 /* We have no bridge, so we're talking with Asterisk somehow */ 21034 /* We need to masquerade this call */ 21035 /* What to do to fix this situation: 21036 * Set up the new call in a new channel 21037 * Let the new channel masq into this channel 21038 Please add that code here :-) 21039 */ 21040 p->refer->status = REFER_FAILED; 21041 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable (can't handle one-legged xfers)", TRUE); 21042 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 21043 append_history(p, "Xfer", "Refer failed (only bridged calls)."); 21044 return -1; 21045 } 21046 ast_set_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 21047 21048 21049 /* For blind transfers, move the call to the new extensions. For attended transfers on multiple 21050 servers - generate an INVITE with Replaces. Either way, let the dial plan decided */ 21051 res = ast_async_goto(current.chan2, p->refer->refer_to_context, p->refer->refer_to, 1); 21052 21053 if (!res) { 21054 manager_event(EVENT_FLAG_CALL, "Transfer", "TransferMethod: SIP\r\nTransferType: Blind\r\nChannel: %s\r\nUniqueid: %s\r\nSIP-Callid: %s\r\nTargetChannel: %s\r\nTargetUniqueid: %s\r\nTransferExten: %s\r\nTransferContext: %s\r\n", 21055 current.chan1->name, 21056 current.chan1->uniqueid, 21057 p->callid, 21058 current.chan2->name, 21059 current.chan2->uniqueid, 21060 p->refer->refer_to, p->refer->refer_to_context); 21061 /* Success - we have a new channel */ 21062 ast_debug(3, "%s transfer succeeded. Telling transferer.\n", p->refer->attendedtransfer? "Attended" : "Blind"); 21063 transmit_notify_with_sipfrag(p, seqno, "200 Ok", TRUE); 21064 if (p->refer->localtransfer) 21065 p->refer->status = REFER_200OK; 21066 if (p->owner) 21067 p->owner->hangupcause = AST_CAUSE_NORMAL_CLEARING; 21068 append_history(p, "Xfer", "Refer succeeded."); 21069 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 21070 /* Do not hangup call, the other side do that when we say 200 OK */ 21071 /* We could possibly implement a timer here, auto congestion */ 21072 res = 0; 21073 } else { 21074 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Don't delay hangup */ 21075 ast_debug(3, "%s transfer failed. Resuming original call.\n", p->refer->attendedtransfer? "Attended" : "Blind"); 21076 append_history(p, "Xfer", "Refer failed."); 21077 /* Failure of some kind */ 21078 p->refer->status = REFER_FAILED; 21079 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable", TRUE); 21080 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 21081 res = -1; 21082 } 21083 return res; 21084 }
| static int handle_request_register | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| char * | e | |||
| ) | [static] |
Handle incoming REGISTER request.
Definition at line 21748 of file chan_sip.c.
References append_history, ast_debug, ast_inet_ntoa(), ast_log(), AUTH_ACL_FAILED, AUTH_BAD_TRANSPORT, AUTH_NOT_FOUND, AUTH_PEER_NOT_DYNAMIC, AUTH_SECRET_FAILED, AUTH_UNKNOWN_DOMAIN, AUTH_USERNAME_MISMATCH, sip_pvt::callid, check_via(), copy_request(), DEFAULT_TRANS_TIMEOUT, get_header(), sip_pvt::initreq, LOG_NOTICE, sip_request::method, register_verify(), sip_methods, sip_scheddestroy(), and cfsip_methods::text.
Referenced by handle_incoming().
21749 { 21750 enum check_auth_result res; 21751 21752 /* Use this as the basis */ 21753 copy_request(&p->initreq, req); 21754 if (sipdebug) 21755 ast_debug(4, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 21756 check_via(p, req); 21757 if ((res = register_verify(p, sin, req, e)) < 0) { 21758 const char *reason; 21759 21760 switch (res) { 21761 case AUTH_SECRET_FAILED: 21762 reason = "Wrong password"; 21763 break; 21764 case AUTH_USERNAME_MISMATCH: 21765 reason = "Username/auth name mismatch"; 21766 break; 21767 case AUTH_NOT_FOUND: 21768 reason = "No matching peer found"; 21769 break; 21770 case AUTH_UNKNOWN_DOMAIN: 21771 reason = "Not a local domain"; 21772 break; 21773 case AUTH_PEER_NOT_DYNAMIC: 21774 reason = "Peer is not supposed to register"; 21775 break; 21776 case AUTH_ACL_FAILED: 21777 reason = "Device does not match ACL"; 21778 break; 21779 case AUTH_BAD_TRANSPORT: 21780 reason = "Device not configured to use this transport type"; 21781 break; 21782 default: 21783 reason = "Unknown failure"; 21784 break; 21785 } 21786 ast_log(LOG_NOTICE, "Registration from '%s' failed for '%s' - %s\n", 21787 get_header(req, "To"), ast_inet_ntoa(sin->sin_addr), 21788 reason); 21789 append_history(p, "RegRequest", "Failed : Account %s : %s", get_header(req, "To"), reason); 21790 } else 21791 append_history(p, "RegRequest", "Succeeded : Account %s", get_header(req, "To")); 21792 21793 if (res < 1) { 21794 /* Destroy the session, but keep us around for just a bit in case they don't 21795 get our 200 OK */ 21796 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21797 } 21798 return res; 21799 }
| static int handle_request_subscribe | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct sockaddr_in * | sin, | |||
| int | seqno, | |||
| char * | e | |||
| ) | [static] |
Handle incoming SUBSCRIBE request.
Definition at line 21414 of file chan_sip.c.
References __get_header(), add_peer_mwi_subs(), sip_settings::allowsubscribe, ao2_lock(), ao2_unlock(), append_history, ast_debug, AST_EXTENSION_REMOVED, ast_extension_state(), ast_extension_state2str(), ast_extension_state_add(), ast_extension_state_del(), ast_inet_ntoa(), AST_LIST_EMPTY, ast_log(), ast_set_flag, ast_strdupa, ast_string_field_build, ast_strlen_zero(), ast_test_flag, ast_verbose, AUTH_CHALLENGE_SENT, AUTH_FAKE_AUTH, sip_pvt::autokillid, build_contact(), build_route(), sip_pvt::callid, cb_extensionstate(), check_user_full(), check_via(), sip_pvt::context, copy_request(), CPIM_PIDF_XML, sip_request::debug, DIALOG_INFO_XML, dialog_ref(), dialog_unlink_all(), dialog_unref(), sip_pvt::dialogver, sip_pvt::expiry, sip_pvt::exten, FALSE, sip_peer::flags, sip_pvt::flags, get_destination(), get_header(), gettag(), sip_request::headers, sip_request::ignore, sip_pvt::initreq, sip_pvt::lastinvite, sip_pvt::laststate, LOG_DEBUG, LOG_NOTICE, LOG_WARNING, sip_peer::mailboxes, make_our_tag(), sip_request::method, MWI_NOTIFICATION, sip_peer::mwipvt, sip_peer::name, sip_pvt::needdestroy, NONE, option_debug, parse_ok_contact(), PIDF_XML, pvt_set_needdestroy(), ref_peer(), sip_pvt::relatedpeer, sip_pvt::sa, sip_cancel_destroy(), sip_cfg, sip_methods, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PAGE2_SUBSCRIBEMWIONLY, sip_scheddestroy(), sip_send_mwi_to_peer(), SIP_SUBSCRIBE, sip_pvt::stateid, sip_pvt::subscribecontext, sip_pvt::subscribed, sip_pvt::subscribeuri, sip_pvt::tag, cfsip_methods::text, transmit_fake_auth_response(), transmit_response(), transmit_response_reliable(), transmit_state_notify(), TRUE, unref_peer(), sip_pvt::useragent, sip_pvt::username, XMIT_UNRELIABLE, and XPIDF_XML.
Referenced by handle_incoming().
21415 { 21416 int gotdest = 0; 21417 int res = 0; 21418 int firststate = AST_EXTENSION_REMOVED; 21419 struct sip_peer *authpeer = NULL; 21420 const char *eventheader = get_header(req, "Event"); /* Get Event package name */ 21421 int resubscribe = (p->subscribed != NONE); 21422 char *temp, *event; 21423 21424 if (p->initreq.headers) { 21425 /* We already have a dialog */ 21426 if (p->initreq.method != SIP_SUBSCRIBE) { 21427 /* This is a SUBSCRIBE within another SIP dialog, which we do not support */ 21428 /* For transfers, this could happen, but since we haven't seen it happening, let us just refuse this */ 21429 transmit_response(p, "403 Forbidden (within dialog)", req); 21430 /* Do not destroy session, since we will break the call if we do */ 21431 ast_debug(1, "Got a subscription within the context of another call, can't handle that - %s (Method %s)\n", p->callid, sip_methods[p->initreq.method].text); 21432 return 0; 21433 } else if (req->debug) { 21434 if (resubscribe) 21435 ast_debug(1, "Got a re-subscribe on existing subscription %s\n", p->callid); 21436 else 21437 ast_debug(1, "Got a new subscription %s (possibly with auth)\n", p->callid); 21438 } 21439 } 21440 21441 /* Check if we have a global disallow setting on subscriptions. 21442 if so, we don't have to check peer settings after auth, which saves a lot of processing 21443 */ 21444 if (!sip_cfg.allowsubscribe) { 21445 transmit_response(p, "403 Forbidden (policy)", req); 21446 pvt_set_needdestroy(p, "forbidden"); 21447 return 0; 21448 } 21449 21450 if (!req->ignore && !resubscribe) { /* Set up dialog, new subscription */ 21451 const char *to = get_header(req, "To"); 21452 char totag[128]; 21453 21454 /* Check to see if a tag was provided, if so this is actually a resubscription of a dialog we no longer know about */ 21455 if (!ast_strlen_zero(to) && gettag(req, "To", totag, sizeof(totag))) { 21456 if (req->debug) 21457 ast_verbose("Received resubscription for a dialog we no longer know about. Telling remote side to subscribe again.\n"); 21458 transmit_response(p, "481 Subscription does not exist", req); 21459 pvt_set_needdestroy(p, "subscription does not exist"); 21460 return 0; 21461 } 21462 21463 /* Use this as the basis */ 21464 if (req->debug) 21465 ast_verbose("Creating new subscription\n"); 21466 21467 copy_request(&p->initreq, req); 21468 if (sipdebug) 21469 ast_debug(4, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 21470 check_via(p, req); 21471 build_route(p, req, 0); 21472 } else if (req->debug && req->ignore) 21473 ast_verbose("Ignoring this SUBSCRIBE request\n"); 21474 21475 /* Find parameters to Event: header value and remove them for now */ 21476 if (ast_strlen_zero(eventheader)) { 21477 transmit_response(p, "489 Bad Event", req); 21478 ast_debug(2, "Received SIP subscribe for unknown event package: <none>\n"); 21479 pvt_set_needdestroy(p, "unknown event package in subscribe"); 21480 return 0; 21481 } 21482 21483 if ( (strchr(eventheader, ';'))) { 21484 event = ast_strdupa(eventheader); /* Since eventheader is a const, we can't change it */ 21485 temp = strchr(event, ';'); 21486 *temp = '\0'; /* Remove any options for now */ 21487 /* We might need to use them later :-) */ 21488 } else 21489 event = (char *) eventheader; /* XXX is this legal ? */ 21490 21491 /* Handle authentication */ 21492 res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, sin, &authpeer); 21493 /* if an authentication response was sent, we are done here */ 21494 if (res == AUTH_CHALLENGE_SENT) /* authpeer = NULL here */ 21495 return 0; 21496 if (res < 0) { 21497 if (res == AUTH_FAKE_AUTH) { 21498 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 21499 transmit_fake_auth_response(p, SIP_SUBSCRIBE, req, XMIT_UNRELIABLE); 21500 } else { 21501 ast_log(LOG_NOTICE, "Failed to authenticate device %s for SUBSCRIBE\n", get_header(req, "From")); 21502 transmit_response_reliable(p, "403 Forbidden", req); 21503 } 21504 pvt_set_needdestroy(p, "authentication failed"); 21505 return 0; 21506 } 21507 21508 /* At this point, authpeer cannot be NULL. Remember we hold a reference, 21509 * so we must release it when done. 21510 * XXX must remove all the checks for authpeer == NULL. 21511 */ 21512 21513 /* Check if this device is allowed to subscribe at all */ 21514 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { 21515 transmit_response(p, "403 Forbidden (policy)", req); 21516 pvt_set_needdestroy(p, "subscription not allowed"); 21517 if (authpeer) 21518 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 1)"); 21519 return 0; 21520 } 21521 21522 if (strcmp(event, "message-summary")) { 21523 /* Get destination right away */ 21524 gotdest = get_destination(p, NULL); 21525 } 21526 21527 /* Get full contact header - this needs to be used as a request URI in NOTIFY's */ 21528 parse_ok_contact(p, req); 21529 21530 build_contact(p); 21531 if (gotdest) { 21532 transmit_response(p, "404 Not Found", req); 21533 pvt_set_needdestroy(p, "subscription target not found"); 21534 if (authpeer) 21535 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 2)"); 21536 return 0; 21537 } 21538 21539 /* Initialize tag for new subscriptions */ 21540 if (ast_strlen_zero(p->tag)) 21541 make_our_tag(p->tag, sizeof(p->tag)); 21542 21543 if (!strcmp(event, "presence") || !strcmp(event, "dialog")) { /* Presence, RFC 3842 */ 21544 unsigned int pidf_xml; 21545 const char *accept; 21546 int start = 0; 21547 enum subscriptiontype subscribed = NONE; 21548 const char *unknown_acceptheader = NULL; 21549 21550 if (authpeer) /* We do not need the authpeer any more */ 21551 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 2)"); 21552 21553 /* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */ 21554 21555 accept = __get_header(req, "Accept", &start); 21556 while ((subscribed == NONE) && !ast_strlen_zero(accept)) { 21557 pidf_xml = strstr(accept, "application/pidf+xml") ? 1 : 0; 21558 21559 /* Older versions of Polycom firmware will claim pidf+xml, but really 21560 * they only support xpidf+xml. */ 21561 if (pidf_xml && strstr(p->useragent, "Polycom")) { 21562 subscribed = XPIDF_XML; 21563 } else if (pidf_xml) { 21564 subscribed = PIDF_XML; /* RFC 3863 format */ 21565 } else if (strstr(accept, "application/dialog-info+xml")) { 21566 subscribed = DIALOG_INFO_XML; 21567 /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */ 21568 } else if (strstr(accept, "application/cpim-pidf+xml")) { 21569 subscribed = CPIM_PIDF_XML; /* RFC 3863 format */ 21570 } else if (strstr(accept, "application/xpidf+xml")) { 21571 subscribed = XPIDF_XML; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */ 21572 } else { 21573 unknown_acceptheader = accept; 21574 } 21575 /* check to see if there is another Accept header present */ 21576 accept = __get_header(req, "Accept", &start); 21577 } 21578 21579 if (!start) { 21580 if (p->subscribed == NONE) { /* if the subscribed field is not already set, and there is no accept header... */ 21581 transmit_response(p, "489 Bad Event", req); 21582 ast_log(LOG_WARNING,"SUBSCRIBE failure: no Accept header: pvt: " 21583 "stateid: %d, laststate: %d, dialogver: %d, subscribecont: " 21584 "'%s', subscribeuri: '%s'\n", 21585 p->stateid, 21586 p->laststate, 21587 p->dialogver, 21588 p->subscribecontext, 21589 p->subscribeuri); 21590 pvt_set_needdestroy(p, "no Accept header"); 21591 return 0; 21592 } 21593 /* if p->subscribed is non-zero, then accept is not obligatory; according to rfc 3265 section 3.1.3, at least. 21594 so, we'll just let it ride, keeping the value from a previous subscription, and not abort the subscription */ 21595 } else if (subscribed == NONE) { 21596 /* Can't find a format for events that we know about */ 21597 char mybuf[200]; 21598 if (!ast_strlen_zero(unknown_acceptheader)) { 21599 snprintf(mybuf, sizeof(mybuf), "489 Bad Event (format %s)", unknown_acceptheader); 21600 } else { 21601 snprintf(mybuf, sizeof(mybuf), "489 Bad Event"); 21602 } 21603 transmit_response(p, mybuf, req); 21604 ast_log(LOG_WARNING,"SUBSCRIBE failure: unrecognized format:" 21605 "'%s' pvt: subscribed: %d, stateid: %d, laststate: %d," 21606 "dialogver: %d, subscribecont: '%s', subscribeuri: '%s'\n", 21607 unknown_acceptheader, 21608 (int)p->subscribed, 21609 p->stateid, 21610 p->laststate, 21611 p->dialogver, 21612 p->subscribecontext, 21613 p->subscribeuri); 21614 pvt_set_needdestroy(p, "unrecognized format"); 21615 return 0; 21616 } else { 21617 p->subscribed = subscribed; 21618 } 21619 } else if (!strcmp(event, "message-summary")) { 21620 int start = 0; 21621 int found_supported = 0; 21622 const char *acceptheader; 21623 21624 acceptheader = __get_header(req, "Accept", &start); 21625 while (!found_supported && !ast_strlen_zero(acceptheader)) { 21626 found_supported = strcmp(acceptheader, "application/simple-message-summary") ? 0 : 1; 21627 if (!found_supported && (option_debug > 2)) { 21628 ast_log(LOG_DEBUG, "Received SIP mailbox subscription for unknown format: %s\n", acceptheader); 21629 } 21630 acceptheader = __get_header(req, "Accept", &start); 21631 } 21632 if (start && !found_supported) { 21633 /* Format requested that we do not support */ 21634 transmit_response(p, "406 Not Acceptable", req); 21635 ast_debug(2, "Received SIP mailbox subscription for unknown format: %s\n", acceptheader); 21636 pvt_set_needdestroy(p, "unknown format"); 21637 if (authpeer) 21638 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 3)"); 21639 return 0; 21640 } 21641 21642 /* Looks like they actually want a mailbox status 21643 This version of Asterisk supports mailbox subscriptions 21644 The subscribed URI needs to exist in the dial plan 21645 In most devices, this is configurable to the voicemailmain extension you use 21646 */ 21647 if (!authpeer || AST_LIST_EMPTY(&authpeer->mailboxes)) { 21648 transmit_response(p, "404 Not found (no mailbox)", req); 21649 pvt_set_needdestroy(p, "received 404 response"); 21650 ast_log(LOG_NOTICE, "Received SIP subscribe for peer without mailbox: %s\n", authpeer->name); 21651 if (authpeer) 21652 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 4)"); 21653 return 0; 21654 } 21655 21656 p->subscribed = MWI_NOTIFICATION; 21657 if (ast_test_flag(&authpeer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY)) { 21658 add_peer_mwi_subs(authpeer); 21659 } 21660 if (authpeer->mwipvt && authpeer->mwipvt != p) { /* Destroy old PVT if this is a new one */ 21661 /* We only allow one subscription per peer */ 21662 dialog_unlink_all(authpeer->mwipvt, TRUE, TRUE); 21663 authpeer->mwipvt = dialog_unref(authpeer->mwipvt, "unref dialog authpeer->mwipvt"); 21664 /* sip_destroy(authpeer->mwipvt); */ 21665 } 21666 if (authpeer->mwipvt) 21667 dialog_unref(authpeer->mwipvt, "Unref previously stored mwipvt dialog pointer"); 21668 authpeer->mwipvt = dialog_ref(p, "setting peers' mwipvt to p"); /* Link from peer to pvt UH- should this be dialog_ref()? */ 21669 if (p->relatedpeer) 21670 unref_peer(p->relatedpeer, "Unref previously stored relatedpeer ptr"); 21671 p->relatedpeer = ref_peer(authpeer, "setting dialog's relatedpeer pointer"); /* already refcounted...Link from pvt to peer UH- should this be dialog_ref()? */ 21672 /* Do not release authpeer here */ 21673 } else { /* At this point, Asterisk does not understand the specified event */ 21674 transmit_response(p, "489 Bad Event", req); 21675 ast_debug(2, "Received SIP subscribe for unknown event package: %s\n", event); 21676 pvt_set_needdestroy(p, "unknown event package"); 21677 if (authpeer) 21678 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 5)"); 21679 return 0; 21680 } 21681 21682 /* Add subscription for extension state from the PBX core */ 21683 if (p->subscribed != MWI_NOTIFICATION && !resubscribe) { 21684 if (p->stateid > -1) { 21685 ast_extension_state_del(p->stateid, cb_extensionstate); 21686 /* we need to dec the refcount, now that the extensionstate is removed */ 21687 dialog_unref(p, "the extensionstate containing this dialog ptr was deleted"); 21688 } 21689 p->stateid = ast_extension_state_add(p->context, p->exten, cb_extensionstate, dialog_ref(p,"copying dialog ptr into extension state struct")); 21690 } 21691 21692 if (!req->ignore && p) 21693 p->lastinvite = seqno; 21694 if (p && !p->needdestroy) { 21695 p->expiry = atoi(get_header(req, "Expires")); 21696 21697 /* check if the requested expiry-time is within the approved limits from sip.conf */ 21698 if (p->expiry > max_expiry) 21699 p->expiry = max_expiry; 21700 if (p->expiry < min_expiry && p->expiry > 0) 21701 p->expiry = min_expiry; 21702 21703 if (sipdebug) { 21704 if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer) 21705 ast_debug(2, "Adding subscription for mailbox notification - peer %s\n", p->relatedpeer->name); 21706 else 21707 ast_debug(2, "Adding subscription for extension %s context %s for peer %s\n", p->exten, p->context, p->username); 21708 } 21709 if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */ 21710 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 21711 if (p->expiry > 0) 21712 sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */ 21713 21714 if (p->subscribed == MWI_NOTIFICATION) { 21715 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21716 transmit_response(p, "200 OK", req); 21717 if (p->relatedpeer) { /* Send first notification */ 21718 ao2_lock(p->relatedpeer); /* was WRLOCK */ 21719 sip_send_mwi_to_peer(p->relatedpeer, NULL, 0); 21720 ao2_unlock(p->relatedpeer); 21721 } 21722 } else { 21723 21724 if ((firststate = ast_extension_state(NULL, p->context, p->exten)) < 0) { 21725 21726 ast_log(LOG_NOTICE, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension.\n", p->exten, p->context, ast_inet_ntoa(p->sa.sin_addr)); 21727 transmit_response(p, "404 Not found", req); 21728 pvt_set_needdestroy(p, "no extension for SUBSCRIBE"); 21729 return 0; 21730 } 21731 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21732 transmit_response(p, "200 OK", req); 21733 transmit_state_notify(p, firststate, 1, FALSE); /* Send first notification */ 21734 append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate)); 21735 /* hide the 'complete' exten/context in the refer_to field for later display */ 21736 ast_string_field_build(p, subscribeuri, "%s@%s", p->exten, p->context); 21737 /* Deleted the slow iteration of all sip dialogs to find old subscribes from this peer for exten@context */ 21738 21739 } 21740 if (!p->expiry) { 21741 pvt_set_needdestroy(p, "forcing expiration"); 21742 } 21743 } 21744 return 1; 21745 }
| static void handle_response | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Handle SIP response in dialogue.
Definition at line 18496 of file chan_sip.c.
References __sip_ack(), __sip_semi_ack(), append_history, AST_CAUSE_PROTOCOL_ERROR, ast_clear_flag, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, ast_debug, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_queue_hangup_with_cause(), ast_set_flag, ast_skip_blanks(), ast_skip_nonblanks(), ast_strdupa, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, ast_verbose, sip_invite_param::auth_type, sip_pvt::authname, sip_pvt::authtries, ast_channel::call_forward, sip_pvt::callid, cb_extensionstate(), sip_pvt::context, sip_request::debug, do_proxy_auth(), sip_pvt::exten, FALSE, find_sdp(), find_sip_method(), sip_pvt::flags, get_header(), gettag(), handle_response_invite(), handle_response_notify(), handle_response_peerpoke(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), hangup_sip2cause(), ast_channel::hangupcause, sip_request::ignore, sip_pvt::initreq, sip_pvt::laststate, LOG_NOTICE, LOG_WARNING, MAX_AUTHTRIES, sip_pvt::method, msg, ast_channel::name, sip_pvt::options, sip_pvt::owner, parse_moved_contact(), sip_pvt::pendinginvite, process_sdp(), pvt_set_needdestroy(), sip_pvt::recv, sip_pvt::refer, sip_pvt::registry, sip_pvt::relatedpeer, sip_pvt::sa, SDP_T38_NONE, SIP_ACK, sip_alreadygone(), SIP_BYE, SIP_CANCEL, sip_cancel_destroy(), SIP_INFO, SIP_INVITE, SIP_MESSAGE, sip_methods, SIP_NOTIFY, SIP_OPTIONS, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PAGE2_FORWARD_LOOP_DETECTED, SIP_PAGE2_STATECHANGEQUEUE, SIP_REFER, SIP_REGISTER, SIP_SUBSCRIBE, SIP_TRANSPORT_UDP, sip_pvt::socket, stop_media_flows(), sip_pvt::subscribed, text, sip_pvt::theirtag, transmit_request(), sip_socket::type, sip_pvt::username, and XMIT_UNRELIABLE.
Referenced by handle_incoming().
18497 { 18498 struct ast_channel *owner; 18499 int sipmethod; 18500 int res = 1; 18501 const char *c = get_header(req, "Cseq"); 18502 /* GCC 4.2 complains if I try to cast c as a char * when passing it to ast_skip_nonblanks, so make a copy of it */ 18503 char *c_copy = ast_strdupa(c); 18504 /* Skip the Cseq and its subsequent spaces */ 18505 const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy)); 18506 18507 if (!msg) 18508 msg = ""; 18509 18510 sipmethod = find_sip_method(msg); 18511 18512 owner = p->owner; 18513 if (owner) 18514 owner->hangupcause = hangup_sip2cause(resp); 18515 18516 if (p->socket.type == SIP_TRANSPORT_UDP) { 18517 int ack_res; 18518 18519 /* Acknowledge whatever it is destined for */ 18520 if ((resp >= 100) && (resp <= 199)) { 18521 ack_res = __sip_semi_ack(p, seqno, 0, sipmethod); 18522 } else { 18523 ack_res = __sip_ack(p, seqno, 0, sipmethod); 18524 } 18525 18526 if (ack_res == FALSE) { 18527 append_history(p, "Ignore", "Ignoring this retransmit\n"); 18528 return; 18529 } 18530 } 18531 18532 /* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */ 18533 if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) 18534 p->pendinginvite = 0; 18535 18536 /* Get their tag if we haven't already */ 18537 if (ast_strlen_zero(p->theirtag) || (resp >= 200)) { 18538 char tag[128]; 18539 18540 gettag(req, "To", tag, sizeof(tag)); 18541 ast_string_field_set(p, theirtag, tag); 18542 } 18543 /* This needs to be configurable on a channel/peer level, 18544 not mandatory for all communication. Sadly enough, NAT implementations 18545 are not so stable so we can always rely on these headers. 18546 Temporarily disabled, while waiting for fix. 18547 Fix assigned to Rizzo :-) 18548 */ 18549 /* check_via_response(p, req); */ 18550 18551 /* RFC 3261 Section 15 specifies that if we receive a 408 or 481 18552 * in response to a BYE, then we should end the current dialog 18553 * and session. It is known that at least one phone manufacturer 18554 * potentially will send a 404 in response to a BYE, so we'll be 18555 * liberal in what we accept and end the dialog and session if we 18556 * receive any of those responses to a BYE. 18557 */ 18558 if ((resp == 404 || resp == 408 || resp == 481) && sipmethod == SIP_BYE) { 18559 pvt_set_needdestroy(p, "received 4XX response to a BYE"); 18560 return; 18561 } 18562 18563 if (p->relatedpeer && p->method == SIP_OPTIONS) { 18564 /* We don't really care what the response is, just that it replied back. 18565 Well, as long as it's not a 100 response... since we might 18566 need to hang around for something more "definitive" */ 18567 if (resp != 100) 18568 handle_response_peerpoke(p, resp, req); 18569 } else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 18570 switch(resp) { 18571 case 100: /* 100 Trying */ 18572 case 101: /* 101 Dialog establishment */ 18573 case 183: /* 183 Session Progress */ 18574 case 180: /* 180 Ringing */ 18575 case 182: /* 182 Queued */ 18576 if (sipmethod == SIP_INVITE) 18577 handle_response_invite(p, resp, rest, req, seqno); 18578 break; 18579 case 200: /* 200 OK */ 18580 p->authtries = 0; /* Reset authentication counter */ 18581 if (sipmethod == SIP_MESSAGE || sipmethod == SIP_INFO) { 18582 /* We successfully transmitted a message 18583 or a video update request in INFO */ 18584 /* Nothing happens here - the message is inside a dialog */ 18585 } else if (sipmethod == SIP_INVITE) { 18586 handle_response_invite(p, resp, rest, req, seqno); 18587 } else if (sipmethod == SIP_NOTIFY) { 18588 handle_response_notify(p, resp, rest, req, seqno); 18589 } else if (sipmethod == SIP_REGISTER) { 18590 res = handle_response_register(p, resp, rest, req, seqno); 18591 } else if (sipmethod == SIP_SUBSCRIBE) { 18592 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 18593 handle_response_subscribe(p, resp, rest, req, seqno); 18594 } else if (sipmethod == SIP_BYE) { /* Ok, we're ready to go */ 18595 pvt_set_needdestroy(p, "received 200 response"); 18596 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 18597 } 18598 break; 18599 case 202: /* Transfer accepted */ 18600 if (sipmethod == SIP_REFER) 18601 handle_response_refer(p, resp, rest, req, seqno); 18602 break; 18603 case 401: /* Not www-authorized on SIP method */ 18604 case 407: /* Proxy auth required */ 18605 if (sipmethod == SIP_INVITE) 18606 handle_response_invite(p, resp, rest, req, seqno); 18607 else if (sipmethod == SIP_NOTIFY) 18608 handle_response_notify(p, resp, rest, req, seqno); 18609 else if (sipmethod == SIP_REFER) 18610 handle_response_refer(p, resp, rest, req, seqno); 18611 else if (sipmethod == SIP_SUBSCRIBE) 18612 handle_response_subscribe(p, resp, rest, req, seqno); 18613 else if (p->registry && sipmethod == SIP_REGISTER) 18614 res = handle_response_register(p, resp, rest, req, seqno); 18615 else if (sipmethod == SIP_BYE) { 18616 if (p->options) 18617 p->options->auth_type = resp; 18618 if (ast_strlen_zero(p->authname)) { 18619 ast_log(LOG_WARNING, "Asked to authenticate %s, to %s:%d but we have no matching peer!\n", 18620 msg, ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 18621 pvt_set_needdestroy(p, "unable to authenticate BYE"); 18622 } else if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, sipmethod, 0)) { 18623 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 18624 pvt_set_needdestroy(p, "failed to authenticate BYE"); 18625 } 18626 } else { 18627 ast_log(LOG_WARNING, "Got authentication request (%d) on %s to '%s'\n", resp, sip_methods[sipmethod].text, get_header(req, "To")); 18628 pvt_set_needdestroy(p, "received 407 response"); 18629 } 18630 break; 18631 case 403: /* Forbidden - we failed authentication */ 18632 if (sipmethod == SIP_INVITE) 18633 handle_response_invite(p, resp, rest, req, seqno); 18634 else if (sipmethod == SIP_SUBSCRIBE) 18635 handle_response_subscribe(p, resp, rest, req, seqno); 18636 else if (p->registry && sipmethod == SIP_REGISTER) 18637 res = handle_response_register(p, resp, rest, req, seqno); 18638 else { 18639 ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg); 18640 pvt_set_needdestroy(p, "received 403 response"); 18641 } 18642 break; 18643 case 404: /* Not found */ 18644 if (p->registry && sipmethod == SIP_REGISTER) 18645 res = handle_response_register(p, resp, rest, req, seqno); 18646 else if (sipmethod == SIP_INVITE) 18647 handle_response_invite(p, resp, rest, req, seqno); 18648 else if (sipmethod == SIP_SUBSCRIBE) 18649 handle_response_subscribe(p, resp, rest, req, seqno); 18650 else if (owner) 18651 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18652 break; 18653 case 423: /* Interval too brief */ 18654 if (sipmethod == SIP_REGISTER) 18655 res = handle_response_register(p, resp, rest, req, seqno); 18656 break; 18657 case 408: /* Request timeout - terminate dialog */ 18658 if (sipmethod == SIP_INVITE) 18659 handle_response_invite(p, resp, rest, req, seqno); 18660 else if (sipmethod == SIP_REGISTER) 18661 res = handle_response_register(p, resp, rest, req, seqno); 18662 else if (sipmethod == SIP_BYE) { 18663 pvt_set_needdestroy(p, "received 408 response"); 18664 ast_debug(4, "Got timeout on bye. Thanks for the answer. Now, kill this call\n"); 18665 } else { 18666 if (owner) 18667 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18668 pvt_set_needdestroy(p, "received 408 response"); 18669 } 18670 break; 18671 18672 case 422: /* Session-Timers: Session Interval Too Small */ 18673 if (sipmethod == SIP_INVITE) { 18674 handle_response_invite(p, resp, rest, req, seqno); 18675 } 18676 break; 18677 18678 case 481: /* Call leg does not exist */ 18679 if (sipmethod == SIP_INVITE) { 18680 handle_response_invite(p, resp, rest, req, seqno); 18681 } else if (sipmethod == SIP_REFER) { 18682 handle_response_refer(p, resp, rest, req, seqno); 18683 } else if (sipmethod == SIP_SUBSCRIBE) { 18684 handle_response_subscribe(p, resp, rest, req, seqno); 18685 } else if (sipmethod == SIP_NOTIFY) { 18686 pvt_set_needdestroy(p, "received 481 response"); 18687 } else if (sipmethod == SIP_BYE) { 18688 /* The other side has no transaction to bye, 18689 just assume it's all right then */ 18690 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 18691 } else if (sipmethod == SIP_CANCEL) { 18692 /* The other side has no transaction to cancel, 18693 just assume it's all right then */ 18694 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 18695 } else { 18696 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 18697 /* Guessing that this is not an important request */ 18698 } 18699 break; 18700 case 487: 18701 if (sipmethod == SIP_INVITE) 18702 handle_response_invite(p, resp, rest, req, seqno); 18703 break; 18704 case 415: /* Unsupported media type */ 18705 case 488: /* Not acceptable here - codec error */ 18706 case 606: /* Not Acceptable */ 18707 if (sipmethod == SIP_INVITE) 18708 handle_response_invite(p, resp, rest, req, seqno); 18709 break; 18710 case 491: /* Pending */ 18711 if (sipmethod == SIP_INVITE) 18712 handle_response_invite(p, resp, rest, req, seqno); 18713 else { 18714 ast_debug(1, "Got 491 on %s, unsupported. Call ID %s\n", sip_methods[sipmethod].text, p->callid); 18715 pvt_set_needdestroy(p, "received 491 response"); 18716 } 18717 break; 18718 case 501: /* Not Implemented */ 18719 if (sipmethod == SIP_INVITE) 18720 handle_response_invite(p, resp, rest, req, seqno); 18721 else if (sipmethod == SIP_REFER) 18722 handle_response_refer(p, resp, rest, req, seqno); 18723 else 18724 ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_inet_ntoa(p->sa.sin_addr), msg); 18725 break; 18726 case 603: /* Declined transfer */ 18727 if (sipmethod == SIP_REFER) { 18728 handle_response_refer(p, resp, rest, req, seqno); 18729 break; 18730 } 18731 /* Fallthrough */ 18732 default: 18733 if ((resp >= 300) && (resp < 700)) { 18734 /* Fatal response */ 18735 if ((resp != 487)) 18736 ast_verb(3, "Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(p->sa.sin_addr)); 18737 18738 if (sipmethod == SIP_INVITE) 18739 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 18740 18741 /* XXX Locking issues?? XXX */ 18742 switch(resp) { 18743 case 300: /* Multiple Choices */ 18744 case 301: /* Moved permanently */ 18745 case 302: /* Moved temporarily */ 18746 case 305: /* Use Proxy */ 18747 parse_moved_contact(p, req); 18748 /* Fall through */ 18749 case 486: /* Busy here */ 18750 case 600: /* Busy everywhere */ 18751 case 603: /* Decline */ 18752 if (p->owner) 18753 ast_queue_control(p->owner, AST_CONTROL_BUSY); 18754 break; 18755 case 482: /* Loop Detected */ 18756 /* 18757 \note Asterisk has historically tried to do a call forward when it 18758 gets a 482, but that behavior isn't necessarily the best course of 18759 action. Go ahead and do it anyway by default, but allow the option 18760 to immediately pass to the next line in the dialplan. */ 18761 if (p->owner && ast_test_flag(&p->flags[1], SIP_PAGE2_FORWARD_LOOP_DETECTED)) { 18762 ast_debug(1, "Hairpin detected, setting up call forward for what it's worth\n"); 18763 ast_string_field_build(p->owner, call_forward, 18764 "Local/%s@%s", p->username, p->context); 18765 } 18766 /* Fall through */ 18767 case 480: /* Temporarily Unavailable */ 18768 case 404: /* Not Found */ 18769 case 410: /* Gone */ 18770 case 400: /* Bad Request */ 18771 case 500: /* Server error */ 18772 if (sipmethod == SIP_REFER) { 18773 handle_response_refer(p, resp, rest, req, seqno); 18774 break; 18775 } else if (sipmethod == SIP_SUBSCRIBE) { 18776 handle_response_subscribe(p, resp, rest, req, seqno); 18777 break; 18778 } 18779 /* Fall through */ 18780 case 502: /* Bad gateway */ 18781 case 503: /* Service Unavailable */ 18782 case 504: /* Server Timeout */ 18783 if (owner) 18784 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18785 break; 18786 default: 18787 /* Send hangup */ 18788 if (owner && sipmethod != SIP_MESSAGE && sipmethod != SIP_INFO && sipmethod != SIP_BYE) 18789 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR); 18790 break; 18791 } 18792 /* ACK on invite */ 18793 if (sipmethod == SIP_INVITE) 18794 transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18795 if (sipmethod != SIP_MESSAGE && sipmethod != SIP_INFO) 18796 sip_alreadygone(p); 18797 if (!p->owner) { 18798 pvt_set_needdestroy(p, "transaction completed"); 18799 } 18800 } else if ((resp >= 100) && (resp < 200)) { 18801 if (sipmethod == SIP_INVITE) { 18802 if (!req->ignore && sip_cancel_destroy(p)) 18803 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 18804 if (find_sdp(req)) 18805 process_sdp(p, req, SDP_T38_NONE); 18806 if (p->owner) { 18807 /* Queue a progress frame */ 18808 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 18809 } 18810 } 18811 } else 18812 ast_log(LOG_NOTICE, "Don't know how to handle a %d %s response from %s\n", resp, rest, p->owner ? p->owner->name : ast_inet_ntoa(p->sa.sin_addr)); 18813 } 18814 } else { 18815 /* Responses to OUTGOING SIP requests on INCOMING calls 18816 get handled here. As well as out-of-call message responses */ 18817 if (req->debug) 18818 ast_verbose("SIP Response message for INCOMING dialog %s arrived\n", msg); 18819 18820 if (sipmethod == SIP_INVITE && resp == 200) { 18821 /* Tags in early session is replaced by the tag in 200 OK, which is 18822 the final reply to our INVITE */ 18823 char tag[128]; 18824 18825 gettag(req, "To", tag, sizeof(tag)); 18826 ast_string_field_set(p, theirtag, tag); 18827 } 18828 18829 switch(resp) { 18830 case 200: 18831 if (sipmethod == SIP_INVITE) { 18832 handle_response_invite(p, resp, rest, req, seqno); 18833 } else if (sipmethod == SIP_CANCEL) { 18834 ast_debug(1, "Got 200 OK on CANCEL\n"); 18835 18836 /* Wait for 487, then destroy */ 18837 } else if (sipmethod == SIP_NOTIFY) { 18838 /* They got the notify, this is the end */ 18839 if (p->owner) { 18840 if (p->refer) { 18841 ast_debug(1, "Got 200 OK on NOTIFY for transfer\n"); 18842 } else 18843 ast_log(LOG_WARNING, "Notify answer on an owned channel?\n"); 18844 /* ast_queue_hangup(p->owner); Disabled */ 18845 } else { 18846 if (!p->subscribed && !p->refer) { 18847 pvt_set_needdestroy(p, "transaction completed"); 18848 } 18849 if (ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE)) { 18850 /* Ready to send the next state we have on queue */ 18851 ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 18852 cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p); 18853 } 18854 } 18855 } else if (sipmethod == SIP_BYE) { 18856 pvt_set_needdestroy(p, "transaction completed"); 18857 } else if (sipmethod == SIP_MESSAGE || sipmethod == SIP_INFO) { 18858 /* We successfully transmitted a message or 18859 a video update request in INFO */ 18860 ; 18861 } 18862 break; 18863 case 202: /* Transfer accepted */ 18864 if (sipmethod == SIP_REFER) 18865 handle_response_refer(p, resp, rest, req, seqno); 18866 break; 18867 case 401: /* www-auth */ 18868 case 407: 18869 if (sipmethod == SIP_REFER) 18870 handle_response_refer(p, resp, rest, req, seqno); 18871 else if (sipmethod == SIP_INVITE) 18872 handle_response_invite(p, resp, rest, req, seqno); 18873 else if (sipmethod == SIP_BYE) { 18874 if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, sipmethod, 0)) { 18875 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 18876 pvt_set_needdestroy(p, "failed to authenticate BYE"); 18877 } 18878 } 18879 break; 18880 case 481: /* Call leg does not exist */ 18881 if (sipmethod == SIP_INVITE) { 18882 /* Re-invite failed */ 18883 handle_response_invite(p, resp, rest, req, seqno); 18884 } else if (sipmethod == SIP_BYE) { 18885 pvt_set_needdestroy(p, "received 481 response"); 18886 } else if (sipmethod == SIP_NOTIFY) { 18887 pvt_set_needdestroy(p, "received 481 response"); 18888 } else if (sipdebug) { 18889 ast_debug(1, "Remote host can't match request %s to call '%s'. Giving up\n", sip_methods[sipmethod].text, p->callid); 18890 } 18891 break; 18892 case 501: /* Not Implemented */ 18893 if (sipmethod == SIP_INVITE) 18894 handle_response_invite(p, resp, rest, req, seqno); 18895 else if (sipmethod == SIP_REFER) 18896 handle_response_refer(p, resp, rest, req, seqno); 18897 break; 18898 case 603: /* Declined transfer */ 18899 if (sipmethod == SIP_REFER) { 18900 handle_response_refer(p, resp, rest, req, seqno); 18901 break; 18902 } 18903 /* Fallthrough */ 18904 default: /* Errors without handlers */ 18905 if ((resp >= 100) && (resp < 200)) { 18906 if (sipmethod == SIP_INVITE) { /* re-invite */ 18907 if (!req->ignore && sip_cancel_destroy(p)) 18908 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 18909 } 18910 } 18911 if ((resp >= 300) && (resp < 700)) { 18912 if ((resp != 487)) 18913 ast_verb(3, "Incoming call: Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_inet_ntoa(p->sa.sin_addr)); 18914 switch(resp) { 18915 case 415: /* Unsupported media type */ 18916 case 488: /* Not acceptable here - codec error */ 18917 case 603: /* Decline */ 18918 case 500: /* Server error */ 18919 case 502: /* Bad gateway */ 18920 case 503: /* Service Unavailable */ 18921 case 504: /* Server timeout */ 18922 18923 /* re-invite failed */ 18924 if (sipmethod == SIP_INVITE && sip_cancel_destroy(p)) 18925 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 18926 break; 18927 } 18928 } 18929 break; 18930 } 18931 } 18932 }
| static void handle_response_invite | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Handle SIP response to INVITE dialogue.
Definition at line 17800 of file chan_sip.c.
References ast_channel::_state, sip_pvt::alreadygone, append_history, AST_CAUSE_NORMAL_CLEARING, AST_CONTROL_ANSWER, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, ast_debug, ast_log(), ast_null_frame, ast_queue_control(), ast_queue_frame(), ast_queue_hangup_with_cause(), ast_random(), ast_rtp_set_rtptimers_onhold(), ast_sched_add(), AST_SCHED_DEL_UNREF, ast_set_flag, ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_string_field_set, ast_strlen_zero(), ast_test_flag, sip_invite_param::auth_type, sip_pvt::authtries, build_route(), sip_settings::callevents, sip_pvt::callid, change_t38_state(), check_pendings(), DEC_CALL_LIMIT, DEC_CALL_RINGING, DEFAULT_TRANS_TIMEOUT, dialog_ref(), dialog_unref(), do_proxy_auth(), EVENT_FLAG_SYSTEM, FALSE, find_sdp(), sip_pvt::flags, sip_pvt::fullcontact, get_header(), sip_request::ignore, sip_pvt::initid, sip_pvt::initreq, INV_CALLING, INV_CANCELLED, INV_COMPLETED, INV_EARLY_MEDIA, INV_PROCEEDING, INV_TERMINATED, sip_pvt::invitestate, LOG_NOTICE, LOG_WARNING, manager_event, MAX_AUTHTRIES, ast_channel::name, sip_pvt::options, sip_pvt::outgoing_call, sip_pvt::owner, parse_ok_contact(), parse_session_expires(), sip_pvt::peername, sip_pvt::pendinginvite, proc_422_rsp(), process_sdp(), pvt_set_needdestroy(), sip_pvt::route, sip_pvt::rtp, SDP_T38_ACCEPT, SDP_T38_NONE, SESSION_TIMER_MODE_ORIGINATE, SESSION_TIMER_MODE_REFUSE, SESSION_TIMER_REFRESHER_AUTO, SESSION_TIMER_REFRESHER_UAC, SESSION_TIMER_REFRESHER_UAS, set_address_from_contact(), SIP_ACK, sip_alreadygone(), sip_cancel_destroy(), sip_cfg, SIP_INVITE, SIP_OUTGOING, SIP_PAGE2_DIALOG_ESTABLISHED, SIP_PENDINGBYE, sip_reinvite_retry(), sip_scheddestroy(), sip_st_dlg::st_active, sip_st_dlg::st_active_peer_ua, st_get_mode(), sip_st_dlg::st_interval, sip_st_dlg::st_ref, start_session_timer(), t38properties::state, sip_pvt::stimer, sip_pvt::t38, T38_DISABLED, T38_LOCAL_REINVITE, transmit_reinvite_with_sdp(), transmit_request(), TRUE, sip_pvt::udptl, ast_channel::uniqueid, update_call_counter(), sip_pvt::waitid, XMIT_ERROR, and XMIT_UNRELIABLE.
Referenced by handle_response().
17801 { 17802 int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); 17803 int res = 0; 17804 int xmitres = 0; 17805 int reinvite = (p->owner && p->owner->_state == AST_STATE_UP); 17806 char *p_hdrval; 17807 int rtn; 17808 17809 if (reinvite) 17810 ast_debug(4, "SIP response %d to RE-invite on %s call %s\n", resp, outgoing ? "outgoing" : "incoming", p->callid); 17811 else 17812 ast_debug(4, "SIP response %d to standard invite\n", resp); 17813 17814 if (p->alreadygone) { /* This call is already gone */ 17815 ast_debug(1, "Got response on call that is already terminated: %s (ignoring)\n", p->callid); 17816 return; 17817 } 17818 17819 /* Acknowledge sequence number - This only happens on INVITE from SIP-call */ 17820 /* Don't auto congest anymore since we've gotten something useful back */ 17821 AST_SCHED_DEL_UNREF(sched, p->initid, dialog_unref(p, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr")); 17822 17823 /* RFC3261 says we must treat every 1xx response (but not 100) 17824 that we don't recognize as if it was 183. 17825 */ 17826 if (resp > 100 && resp < 200 && resp!=101 && resp != 180 && resp != 182 && resp != 183) 17827 resp = 183; 17828 17829 /* Any response between 100 and 199 is PROCEEDING */ 17830 if (resp >= 100 && resp < 200 && p->invitestate == INV_CALLING) 17831 p->invitestate = INV_PROCEEDING; 17832 17833 /* Final response, not 200 ? */ 17834 if (resp >= 300 && (p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA )) 17835 p->invitestate = INV_COMPLETED; 17836 17837 /* Final response, clear out pending invite */ 17838 if ((resp == 200 || resp >= 300) && p->pendinginvite && seqno == p->pendinginvite) 17839 p->pendinginvite = 0; 17840 17841 switch (resp) { 17842 case 100: /* Trying */ 17843 case 101: /* Dialog establishment */ 17844 if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p)) 17845 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 17846 check_pendings(p); 17847 break; 17848 17849 case 180: /* 180 Ringing */ 17850 case 182: /* 182 Queued */ 17851 if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p)) 17852 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 17853 if (!req->ignore && p->owner) { 17854 ast_queue_control(p->owner, AST_CONTROL_RINGING); 17855 if (p->owner->_state != AST_STATE_UP) { 17856 ast_setstate(p->owner, AST_STATE_RINGING); 17857 } 17858 } 17859 if (find_sdp(req)) { 17860 if (p->invitestate != INV_CANCELLED) 17861 p->invitestate = INV_EARLY_MEDIA; 17862 res = process_sdp(p, req, SDP_T38_NONE); 17863 if (!req->ignore && p->owner) { 17864 /* Queue a progress frame only if we have SDP in 180 or 182 */ 17865 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 17866 } 17867 } 17868 check_pendings(p); 17869 break; 17870 17871 case 183: /* Session progress */ 17872 if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 17873 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 17874 if (find_sdp(req)) { 17875 if (p->invitestate != INV_CANCELLED) 17876 p->invitestate = INV_EARLY_MEDIA; 17877 res = process_sdp(p, req, SDP_T38_NONE); 17878 if (!req->ignore && p->owner) { 17879 /* Queue a progress frame */ 17880 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 17881 } 17882 } else { 17883 /* Alcatel PBXs are known to send 183s with no SDP after sending 17884 * a 100 Trying response. We're just going to treat this sort of thing 17885 * the same as we would treat a 180 Ringing 17886 */ 17887 if (!req->ignore && p->owner) { 17888 ast_queue_control(p->owner, AST_CONTROL_RINGING); 17889 } 17890 } 17891 check_pendings(p); 17892 break; 17893 17894 case 200: /* 200 OK on invite - someone's answering our call */ 17895 if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 17896 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 17897 p->authtries = 0; 17898 if (find_sdp(req)) { 17899 if ((res = process_sdp(p, req, SDP_T38_ACCEPT)) && !req->ignore) 17900 if (!reinvite) 17901 /* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */ 17902 /* For re-invites, we try to recover */ 17903 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 17904 } 17905 17906 /* Parse contact header for continued conversation */ 17907 /* When we get 200 OK, we know which device (and IP) to contact for this call */ 17908 /* This is important when we have a SIP proxy between us and the phone */ 17909 if (outgoing) { 17910 update_call_counter(p, DEC_CALL_RINGING); 17911 parse_ok_contact(p, req); 17912 /* Save Record-Route for any later requests we make on this dialogue */ 17913 if (!reinvite) 17914 build_route(p, req, 1); 17915 17916 if(set_address_from_contact(p)) { 17917 /* Bad contact - we don't know how to reach this device */ 17918 /* We need to ACK, but then send a bye */ 17919 if (!p->route && !req->ignore) 17920 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 17921 } 17922 17923 } 17924 17925 if (!req->ignore && p->owner) { 17926 if (!reinvite) { 17927 ast_queue_control(p->owner, AST_CONTROL_ANSWER); 17928 if (sip_cfg.callevents) 17929 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 17930 "Channel: %s\r\nChanneltype: %s\r\nUniqueid: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\nPeername: %s\r\n", 17931 p->owner->name, "SIP", p->owner->uniqueid, p->callid, p->fullcontact, p->peername); 17932 } else { /* RE-invite */ 17933 ast_queue_frame(p->owner, &ast_null_frame); 17934 } 17935 } else { 17936 /* It's possible we're getting an 200 OK after we've tried to disconnect 17937 by sending CANCEL */ 17938 /* First send ACK, then send bye */ 17939 if (!req->ignore) 17940 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 17941 } 17942 17943 /* Check for Session-Timers related headers */ 17944 if (st_get_mode(p) != SESSION_TIMER_MODE_REFUSE && p->outgoing_call == TRUE && !reinvite) { 17945 p_hdrval = (char*)get_header(req, "Session-Expires"); 17946 if (!ast_strlen_zero(p_hdrval)) { 17947 /* UAS supports Session-Timers */ 17948 enum st_refresher tmp_st_ref = SESSION_TIMER_REFRESHER_AUTO; 17949 int tmp_st_interval = 0; 17950 rtn = parse_session_expires(p_hdrval, &tmp_st_interval, &tmp_st_ref); 17951 if (rtn != 0) { 17952 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 17953 } 17954 if (tmp_st_ref == SESSION_TIMER_REFRESHER_UAC || 17955 tmp_st_ref == SESSION_TIMER_REFRESHER_UAS) { 17956 p->stimer->st_ref = tmp_st_ref; 17957 } 17958 if (tmp_st_interval) { 17959 p->stimer->st_interval = tmp_st_interval; 17960 } 17961 p->stimer->st_active = TRUE; 17962 p->stimer->st_active_peer_ua = TRUE; 17963 start_session_timer(p); 17964 } else { 17965 /* UAS doesn't support Session-Timers */ 17966 if (st_get_mode(p) == SESSION_TIMER_MODE_ORIGINATE) { 17967 p->stimer->st_ref = SESSION_TIMER_REFRESHER_UAC; 17968 p->stimer->st_active_peer_ua = FALSE; 17969 start_session_timer(p); 17970 } 17971 } 17972 } 17973 17974 17975 /* If I understand this right, the branch is different for a non-200 ACK only */ 17976 p->invitestate = INV_TERMINATED; 17977 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 17978 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, TRUE); 17979 check_pendings(p); 17980 break; 17981 17982 case 407: /* Proxy authentication */ 17983 case 401: /* Www auth */ 17984 /* First we ACK */ 17985 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 17986 if (p->options) 17987 p->options->auth_type = resp; 17988 17989 /* Then we AUTH */ 17990 ast_string_field_set(p, theirtag, NULL); /* forget their old tag, so we don't match tags when getting response */ 17991 if (!req->ignore) { 17992 if (p->authtries < MAX_AUTHTRIES) 17993 p->invitestate = INV_CALLING; 17994 if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, SIP_INVITE, 1)) { 17995 ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); 17996 pvt_set_needdestroy(p, "failed to authenticate on INVITE"); 17997 sip_alreadygone(p); 17998 if (p->owner) 17999 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18000 } 18001 } 18002 break; 18003 18004 case 403: /* Forbidden */ 18005 /* First we ACK */ 18006 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18007 ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From")); 18008 if (!req->ignore && p->owner) 18009 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18010 pvt_set_needdestroy(p, "received 403 response"); 18011 sip_alreadygone(p); 18012 break; 18013 18014 case 404: /* Not found */ 18015 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18016 if (p->owner && !req->ignore) 18017 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18018 sip_alreadygone(p); 18019 break; 18020 18021 case 408: /* Request timeout */ 18022 case 481: /* Call leg does not exist */ 18023 /* Could be REFER caused INVITE with replaces */ 18024 ast_log(LOG_WARNING, "Re-invite to non-existing call leg on other UA. SIP dialog '%s'. Giving up.\n", p->callid); 18025 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18026 if (p->owner) 18027 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18028 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 18029 break; 18030 18031 case 422: /* Session-Timers: Session interval too small */ 18032 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18033 ast_string_field_set(p, theirtag, NULL); 18034 proc_422_rsp(p, req); 18035 break; 18036 18037 case 428: /* Use identity header - rfc 4474 - not supported by Asterisk yet */ 18038 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18039 append_history(p, "Identity", "SIP identity is required. Not supported by Asterisk."); 18040 ast_log(LOG_WARNING, "SIP identity required by proxy. SIP dialog '%s'. Giving up.\n", p->callid); 18041 if (p->owner) 18042 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18043 break; 18044 18045 18046 18047 case 487: /* Cancelled transaction */ 18048 /* We have sent CANCEL on an outbound INVITE 18049 This transaction is already scheduled to be killed by sip_hangup(). 18050 */ 18051 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18052 if (p->owner && !req->ignore) { 18053 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_NORMAL_CLEARING); 18054 append_history(p, "Hangup", "Got 487 on CANCEL request from us. Queued AST hangup request"); 18055 } else if (!req->ignore) { 18056 update_call_counter(p, DEC_CALL_LIMIT); 18057 append_history(p, "Hangup", "Got 487 on CANCEL request from us on call without owner. Killing this dialog."); 18058 pvt_set_needdestroy(p, "received 487 response"); 18059 sip_alreadygone(p); 18060 } 18061 break; 18062 case 415: /* Unsupported media type */ 18063 case 488: /* Not acceptable here */ 18064 case 606: /* Not Acceptable */ 18065 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18066 if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) { 18067 change_t38_state(p, T38_DISABLED); 18068 /* Try to reset RTP timers */ 18069 ast_rtp_set_rtptimers_onhold(p->rtp); 18070 18071 /* Trigger a reinvite back to audio */ 18072 transmit_reinvite_with_sdp(p, FALSE, FALSE); 18073 } else { 18074 /* We can't set up this call, so give up */ 18075 if (p->owner && !req->ignore) 18076 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18077 pvt_set_needdestroy(p, "received 488 response"); 18078 /* If there's no dialog to end, then mark p as already gone */ 18079 if (!reinvite) 18080 sip_alreadygone(p); 18081 } 18082 break; 18083 case 491: /* Pending */ 18084 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18085 if (p->owner && !req->ignore) { 18086 if (p->owner->_state != AST_STATE_UP) { 18087 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18088 pvt_set_needdestroy(p, "received 491 response"); 18089 } else { 18090 /* This is a re-invite that failed. */ 18091 /* Reset the flag after a while 18092 */ 18093 int wait; 18094 /* RFC 3261, if owner of call, wait between 2.1 to 4 seconds, 18095 * if not owner of call, wait 0 to 2 seconds */ 18096 if (p->outgoing_call) { 18097 wait = 2100 + ast_random() % 2000; 18098 } else { 18099 wait = ast_random() % 2000; 18100 } 18101 p->waitid = ast_sched_add(sched, wait, sip_reinvite_retry, dialog_ref(p, "passing dialog ptr into sched structure based on waitid for sip_reinvite_retry.")); 18102 ast_log(LOG_WARNING, "just did sched_add waitid(%d) for sip_reinvite_retry for dialog %s in handle_response_invite\n", p->waitid, p->callid); 18103 ast_debug(2, "Reinvite race. Waiting %d secs before retry\n", wait); 18104 } 18105 } 18106 break; 18107 18108 case 501: /* Not implemented */ 18109 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 18110 if (p->owner) 18111 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18112 break; 18113 } 18114 if (xmitres == XMIT_ERROR) 18115 ast_log(LOG_WARNING, "Could not transmit message in dialog %s\n", p->callid); 18116 }
| static void handle_response_notify | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Definition at line 18121 of file chan_sip.c.
References AST_CAUSE_NORMAL_UNSPECIFIED, ast_clear_flag, ast_debug, ast_inet_ntoa(), ast_log(), ast_queue_hangup_with_cause(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, sip_pvt::authname, sip_pvt::authtries, cb_extensionstate(), sip_pvt::context, do_proxy_auth(), sip_pvt::exten, sip_pvt::flags, get_header(), sip_pvt::initreq, sip_pvt::laststate, LOG_NOTICE, LOG_WARNING, ast_channel::name, NONE, sip_pvt::notify_headers, sip_pvt::owner, pvt_set_needdestroy(), sip_pvt::recv, sip_pvt::refer, SIP_NOTIFY, SIP_PAGE2_STATECHANGEQUEUE, and sip_pvt::subscribed.
Referenced by handle_response().
18122 { 18123 switch (resp) { 18124 case 200: /* Notify accepted */ 18125 /* They got the notify, this is the end */ 18126 if (p->owner) { 18127 if (!p->refer) { 18128 ast_log(LOG_WARNING, "Notify answer on an owned channel? - %s\n", p->owner->name); 18129 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_NORMAL_UNSPECIFIED); 18130 } else { 18131 ast_debug(4, "Got OK on REFER Notify message\n"); 18132 } 18133 } else { 18134 if (p->subscribed == NONE) { 18135 ast_debug(4, "Got 200 accepted on NOTIFY\n"); 18136 pvt_set_needdestroy(p, "received 200 response"); 18137 } 18138 if (ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE)) { 18139 /* Ready to send the next state we have on queue */ 18140 ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 18141 cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p); 18142 } 18143 } 18144 break; 18145 case 401: /* Not www-authorized on SIP method */ 18146 case 407: /* Proxy auth */ 18147 if (!p->notify_headers) { 18148 break; /* Only device notify can use NOTIFY auth */ 18149 } 18150 ast_string_field_set(p, theirtag, NULL); 18151 if (ast_strlen_zero(p->authname)) { 18152 ast_log(LOG_WARNING, "Asked to authenticate NOTIFY to %s:%d but we have no matching peer or realm auth!\n", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 18153 pvt_set_needdestroy(p, "unable to authenticate NOTIFY"); 18154 } 18155 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_NOTIFY, 0)) { 18156 ast_log(LOG_NOTICE, "Failed to authenticate on NOTIFY to '%s'\n", get_header(&p->initreq, "From")); 18157 pvt_set_needdestroy(p, "failed to authenticate NOTIFY"); 18158 } 18159 break; 18160 } 18161 }
| static void handle_response_peerpoke | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| struct sip_request * | req | |||
| ) | [static] |
Handle qualification responses (OPTIONS).
Definition at line 18426 of file chan_sip.c.
References ast_check_realtime(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), AST_SCHED_REPLACE_UNREF, ast_tvdiff_ms(), ast_tvnow(), ast_update_realtime(), sip_peer::call, DEFAULT_FREQ_NOTOK, dialog_unref(), EVENT_FLAG_SYSTEM, sip_peer::lastms, LOG_NOTICE, manager_event, sip_peer::maxms, sip_peer::name, sip_settings::peer_rtupdate, sip_peer::pokeexpire, sip_peer::ps, pvt_set_needdestroy(), sip_peer::qualifyfreq, ref_peer(), sip_settings::regextenonqualify, register_peer_exten(), sip_pvt::relatedpeer, s, SENTINEL, sip_cfg, sip_poke_peer_s(), TRUE, and unref_peer().
Referenced by handle_response().
18427 { 18428 struct sip_peer *peer = /* ref_peer( */ p->relatedpeer /* , "bump refcount on p, as it is being used in this function(handle_response_peerpoke)")*/ ; /* hope this is already refcounted! */ 18429 int statechanged, is_reachable, was_reachable; 18430 int pingtime = ast_tvdiff_ms(ast_tvnow(), peer->ps); 18431 18432 /* 18433 * Compute the response time to a ping (goes in peer->lastms.) 18434 * -1 means did not respond, 0 means unknown, 18435 * 1..maxms is a valid response, >maxms means late response. 18436 */ 18437 if (pingtime < 1) /* zero = unknown, so round up to 1 */ 18438 pingtime = 1; 18439 18440 /* Now determine new state and whether it has changed. 18441 * Use some helper variables to simplify the writing 18442 * of the expressions. 18443 */ 18444 was_reachable = peer->lastms > 0 && peer->lastms <= peer->maxms; 18445 is_reachable = pingtime <= peer->maxms; 18446 statechanged = peer->lastms == 0 /* yes, unknown before */ 18447 || was_reachable != is_reachable; 18448 18449 peer->lastms = pingtime; 18450 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 18451 if (statechanged) { 18452 const char *s = is_reachable ? "Reachable" : "Lagged"; 18453 char str_lastms[20]; 18454 snprintf(str_lastms, sizeof(str_lastms), "%d", pingtime); 18455 18456 ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n", 18457 peer->name, s, pingtime, peer->maxms); 18458 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 18459 if (sip_cfg.peer_rtupdate) { 18460 ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", str_lastms, SENTINEL); 18461 } 18462 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 18463 "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n", 18464 peer->name, s, pingtime); 18465 if (is_reachable && sip_cfg.regextenonqualify) 18466 register_peer_exten(peer, TRUE); 18467 } 18468 18469 pvt_set_needdestroy(p, "got OPTIONS response"); 18470 18471 /* Try again eventually */ 18472 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, 18473 is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK, 18474 sip_poke_peer_s, peer, 18475 unref_peer(_data, "removing poke peer ref"), 18476 unref_peer(peer, "removing poke peer ref"), 18477 ref_peer(peer, "adding poke peer ref")); 18478 }
| static void handle_response_refer | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Definition at line 18225 of file chan_sip.c.
References AST_CONTROL_CONGESTION, ast_debug, ast_inet_ntoa(), ast_log(), ast_queue_control(), ast_strlen_zero(), sip_pvt::authname, sip_pvt::authtries, sip_pvt::callid, do_proxy_auth(), get_header(), sip_pvt::initreq, LOG_NOTICE, LOG_WARNING, sip_pvt::owner, pvt_set_needdestroy(), sip_pvt::recv, sip_pvt::refer, REFER_ACCEPTED, REFER_FAILED, REFER_NOAUTH, sip_refer::refer_to, SIP_REFER, and sip_refer::status.
Referenced by handle_response().
18226 { 18227 /* If no refer structure exists, then do nothing */ 18228 if (!p->refer) 18229 return; 18230 18231 switch (resp) { 18232 case 202: /* Transfer accepted */ 18233 /* We need to do something here */ 18234 /* The transferee is now sending INVITE to target */ 18235 p->refer->status = REFER_ACCEPTED; 18236 /* Now wait for next message */ 18237 ast_debug(3, "Got 202 accepted on transfer\n"); 18238 /* We should hang along, waiting for NOTIFY's here */ 18239 break; 18240 18241 case 401: /* Not www-authorized on SIP method */ 18242 case 407: /* Proxy auth */ 18243 if (ast_strlen_zero(p->authname)) { 18244 ast_log(LOG_WARNING, "Asked to authenticate REFER to %s:%d but we have no matching peer or realm auth!\n", 18245 ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port)); 18246 pvt_set_needdestroy(p, "unable to authenticate REFER"); 18247 } 18248 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_REFER, 0)) { 18249 ast_log(LOG_NOTICE, "Failed to authenticate on REFER to '%s'\n", get_header(&p->initreq, "From")); 18250 p->refer->status = REFER_NOAUTH; 18251 pvt_set_needdestroy(p, "failed to authenticat REFER"); 18252 } 18253 break; 18254 case 481: /* Call leg does not exist */ 18255 18256 /* A transfer with Replaces did not work */ 18257 /* OEJ: We should Set flag, cancel the REFER, go back 18258 to original call - but right now we can't */ 18259 ast_log(LOG_WARNING, "Remote host can't match REFER request to call '%s'. Giving up.\n", p->callid); 18260 if (p->owner) 18261 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 18262 pvt_set_needdestroy(p, "received 481 response"); 18263 break; 18264 18265 case 500: /* Server error */ 18266 case 501: /* Method not implemented */ 18267 /* Return to the current call onhold */ 18268 /* Status flag needed to be reset */ 18269 ast_log(LOG_NOTICE, "SIP transfer to %s failed, call miserably fails. \n", p->refer->refer_to); 18270 pvt_set_needdestroy(p, "received 500/501 response"); 18271 p->refer->status = REFER_FAILED; 18272 break; 18273 case 603: /* Transfer declined */ 18274 ast_log(LOG_NOTICE, "SIP transfer to %s declined, call miserably fails. \n", p->refer->refer_to); 18275 p->refer->status = REFER_FAILED; 18276 pvt_set_needdestroy(p, "received 603 response"); 18277 break; 18278 } 18279 }
| static int handle_response_register | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Handle responses on REGISTER to services.
Definition at line 18282 of file chan_sip.c.
References __get_header(), ast_debug, ast_log(), AST_SCHED_DEL_UNREF, AST_SCHED_REPLACE_UNREF, ast_strlen_zero(), ast_tvnow(), sip_pvt::authtries, sip_registry::call, sip_pvt::callid, sip_registry::configured_expiry, DEFAULT_TRANS_TIMEOUT, dialog_unref(), do_register_auth(), EVENT_FLAG_SYSTEM, sip_registry::expire, sip_registry::expiry, EXPIRY_GUARD_LIMIT, EXPIRY_GUARD_MIN, EXPIRY_GUARD_PCT, EXPIRY_GUARD_SECS, get_header(), sip_registry::hostname, sip_pvt::initreq, LOG_NOTICE, LOG_WARNING, manager_event, MAX, MAX_AUTHTRIES, sip_pvt::our_contact, sip_pvt::peername, pvt_set_needdestroy(), sip_registry::refresh, REG_STATE_NOAUTH, REG_STATE_REGISTERED, REG_STATE_REJECTED, REG_STATE_UNREGISTERED, sip_registry::regattempts, sip_pvt::registry, registry_addref(), registry_unref(), sip_registry::regstate, regstate2str(), sip_registry::regtime, S_OR, SIP_REGISTER, sip_reregister(), sip_scheddestroy(), strcasestr(), sip_registry::timeout, transmit_register(), sip_pvt::username, and sip_registry::username.
Referenced by handle_response().
18283 { 18284 int expires, expires_ms; 18285 struct sip_registry *r; 18286 r=p->registry; 18287 18288 switch (resp) { 18289 case 401: /* Unauthorized */ 18290 if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) { 18291 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s@%s' (Tries %d)\n", p->registry->username, p->registry->hostname, p->authtries); 18292 pvt_set_needdestroy(p, "failed to authenticate REGISTER"); 18293 } 18294 break; 18295 case 403: /* Forbidden */ 18296 ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname); 18297 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 403")); 18298 r->regstate = REG_STATE_NOAUTH; 18299 pvt_set_needdestroy(p, "received 403 response"); 18300 break; 18301 case 404: /* Not found */ 18302 ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username, p->registry->hostname); 18303 pvt_set_needdestroy(p, "received 404 response"); 18304 if (r->call) 18305 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 404"); 18306 r->regstate = REG_STATE_REJECTED; 18307 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 404")); 18308 break; 18309 case 407: /* Proxy auth */ 18310 if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) { 18311 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries); 18312 pvt_set_needdestroy(p, "failed to authenticate REGISTER"); 18313 } 18314 break; 18315 case 408: /* Request timeout */ 18316 /* Got a timeout response, so reset the counter of failed responses */ 18317 if (r) { 18318 r->regattempts = 0; 18319 } else { 18320 ast_log(LOG_WARNING, "Got a 408 response to our REGISTER on call %s after we had destroyed the registry object\n", p->callid); 18321 } 18322 break; 18323 case 423: /* Interval too brief */ 18324 r->expiry = atoi(get_header(req, "Min-Expires")); 18325 ast_log(LOG_WARNING, "Got 423 Interval too brief for service %s@%s, minimum is %d seconds\n", p->registry->username, p->registry->hostname, r->expiry); 18326 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 423")); 18327 if (r->call) { 18328 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 423"); 18329 pvt_set_needdestroy(p, "received 423 response"); 18330 } 18331 if (r->expiry > max_expiry) { 18332 ast_log(LOG_WARNING, "Required expiration time from %s@%s is too high, giving up\n", p->registry->username, p->registry->hostname); 18333 r->expiry = r->configured_expiry; 18334 r->regstate = REG_STATE_REJECTED; 18335 } else { 18336 r->regstate = REG_STATE_UNREGISTERED; 18337 transmit_register(r, SIP_REGISTER, NULL, NULL); 18338 } 18339 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate)); 18340 break; 18341 case 479: /* SER: Not able to process the URI - address is wrong in register*/ 18342 ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username, p->registry->hostname); 18343 pvt_set_needdestroy(p, "received 479 response"); 18344 if (r->call) 18345 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 479"); 18346 r->regstate = REG_STATE_REJECTED; 18347 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 479")); 18348 break; 18349 case 200: /* 200 OK */ 18350 if (!r) { 18351 ast_log(LOG_WARNING, "Got 200 OK on REGISTER, but there isn't a registry entry for '%s' (we probably already got the OK)\n", S_OR(p->peername, p->username)); 18352 pvt_set_needdestroy(p, "received erroneous 200 response"); 18353 return 0; 18354 } 18355 18356 r->regstate = REG_STATE_REGISTERED; 18357 r->regtime = ast_tvnow(); /* Reset time of last succesful registration */ 18358 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate)); 18359 r->regattempts = 0; 18360 ast_debug(1, "Registration successful\n"); 18361 if (r->timeout > -1) { 18362 ast_debug(1, "Cancelling timeout %d\n", r->timeout); 18363 } 18364 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 200")); 18365 if (r->call) 18366 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 200"); 18367 p->registry = registry_unref(p->registry, "unref registry entry p->registry"); 18368 /* Let this one hang around until we have all the responses */ 18369 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 18370 /* p->needdestroy = 1; */ 18371 18372 /* set us up for re-registering 18373 * figure out how long we got registered for 18374 * according to section 6.13 of RFC, contact headers override 18375 * expires headers, so check those first */ 18376 expires = 0; 18377 18378 /* XXX todo: try to save the extra call */ 18379 if (!ast_strlen_zero(get_header(req, "Contact"))) { 18380 const char *contact = NULL; 18381 const char *tmptmp = NULL; 18382 int start = 0; 18383 for(;;) { 18384 contact = __get_header(req, "Contact", &start); 18385 /* this loop ensures we get a contact header about our register request */ 18386 if(!ast_strlen_zero(contact)) { 18387 if( (tmptmp=strstr(contact, p->our_contact))) { 18388 contact=tmptmp; 18389 break; 18390 } 18391 } else 18392 break; 18393 } 18394 tmptmp = strcasestr(contact, "expires="); 18395 if (tmptmp) { 18396 if (sscanf(tmptmp + 8, "%30d;", &expires) != 1) 18397 expires = 0; 18398 } 18399 18400 } 18401 if (!expires) 18402 expires=atoi(get_header(req, "expires")); 18403 if (!expires) 18404 expires=default_expiry; 18405 18406 expires_ms = expires * 1000; 18407 if (expires <= EXPIRY_GUARD_LIMIT) 18408 expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT), EXPIRY_GUARD_MIN); 18409 else 18410 expires_ms -= EXPIRY_GUARD_SECS * 1000; 18411 if (sipdebug) 18412 ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000); 18413 18414 r->refresh= (int) expires_ms / 1000; 18415 18416 /* Schedule re-registration before we expire */ 18417 AST_SCHED_REPLACE_UNREF(r->expire, sched, expires_ms, sip_reregister, r, 18418 registry_unref(_data,"unref in REPLACE del fail"), 18419 registry_unref(r,"unref in REPLACE add fail"), 18420 registry_addref(r,"The Addition side of REPLACE")); 18421 } 18422 return 1; 18423 }
| static void handle_response_subscribe | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| char * | rest, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Definition at line 18164 of file chan_sip.c.
References ast_debug, ast_free, ast_log(), ast_sched_add(), ast_string_field_set, ASTOBJ_REF, ASTOBJ_UNREF, sip_pvt::authtries, sip_subscription_mwi::call, do_proxy_auth(), get_header(), sip_pvt::initreq, LOG_NOTICE, LOG_WARNING, sip_pvt::mwi, sip_pvt::options, pvt_set_needdestroy(), sip_subscription_mwi::resub, sip_alreadygone(), SIP_SUBSCRIBE, sip_subscribe_mwi_destroy(), sip_subscribe_mwi_do(), sip_subscription_mwi::subscribed, and transmit_response_with_date().
Referenced by handle_response().
18165 { 18166 if (!p->mwi) { 18167 return; 18168 } 18169 18170 switch (resp) { 18171 case 200: /* Subscription accepted */ 18172 ast_debug(3, "Got 200 OK on subscription for MWI\n"); 18173 if (p->options) { 18174 ast_free(p->options); 18175 p->options = NULL; 18176 } 18177 p->mwi->subscribed = 1; 18178 if ((p->mwi->resub = ast_sched_add(sched, mwi_expiry * 1000, sip_subscribe_mwi_do, ASTOBJ_REF(p->mwi))) < 0) { 18179 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18180 } 18181 break; 18182 case 401: 18183 case 407: 18184 ast_string_field_set(p, theirtag, NULL); 18185 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_SUBSCRIBE, 0)) { 18186 ast_log(LOG_NOTICE, "Failed to authenticate on SUBSCRIBE to '%s'\n", get_header(&p->initreq, "From")); 18187 p->mwi->call = NULL; 18188 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18189 pvt_set_needdestroy(p, "failed to authenticate SUBSCRIBE"); 18190 } 18191 break; 18192 case 403: 18193 transmit_response_with_date(p, "200 OK", req); 18194 ast_log(LOG_WARNING, "Authentication failed while trying to subscribe for MWI.\n"); 18195 p->mwi->call = NULL; 18196 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18197 pvt_set_needdestroy(p, "received 403 response"); 18198 sip_alreadygone(p); 18199 break; 18200 case 404: 18201 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side said that a mailbox may not have been configured.\n"); 18202 p->mwi->call = NULL; 18203 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18204 pvt_set_needdestroy(p, "received 404 response"); 18205 break; 18206 case 481: 18207 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side said that our dialog did not exist.\n"); 18208 p->mwi->call = NULL; 18209 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18210 pvt_set_needdestroy(p, "received 481 response"); 18211 break; 18212 case 500: 18213 case 501: 18214 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side may have suffered a heart attack.\n"); 18215 p->mwi->call = NULL; 18216 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 18217 pvt_set_needdestroy(p, "received 500/501 response"); 18218 break; 18219 } 18220 }
| static int handle_t38_options | ( | struct ast_flags * | flags, | |
| struct ast_flags * | mask, | |||
| struct ast_variable * | v, | |||
| int * | maxdatagram | |||
| ) | [static] |
Handle T.38 configuration options common to users and peers.
Definition at line 23508 of file chan_sip.c.
References ast_clear_flag, ast_log(), ast_set2_flag, ast_set_flag, ast_strdupa, ast_true(), buf, ast_variable::lineno, LOG_WARNING, ast_variable::name, SIP_PAGE2_FORWARD_LOOP_DETECTED, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PAGE2_T38SUPPORT_UDPTL_FEC, SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY, SIP_PAGE2_UDPTL_DESTINATION, strsep(), ast_variable::value, and word.
Referenced by build_peer(), and reload_config().
23510 { 23511 int res = 1; 23512 23513 if (!strcasecmp(v->name, "t38pt_udptl")) { 23514 char *buf = ast_strdupa(v->value); 23515 char *word, *next = buf; 23516 23517 ast_set_flag(&mask[1], SIP_PAGE2_T38SUPPORT); 23518 23519 while ((word = strsep(&next, ","))) { 23520 if (ast_true(word) || !strcasecmp(word, "fec")) { 23521 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 23522 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL_FEC); 23523 } else if (!strcasecmp(word, "redundancy")) { 23524 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 23525 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY); 23526 } else if (!strcasecmp(word, "none")) { 23527 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 23528 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL); 23529 } else if (!strncasecmp(word, "maxdatagram=", 12)) { 23530 if (sscanf(&word[12], "%30u", maxdatagram) != 1) { 23531 ast_log(LOG_WARNING, "Invalid maxdatagram '%s' at line %d of %s\n", v->value, v->lineno, config); 23532 *maxdatagram = global_t38_maxdatagram; 23533 } 23534 } 23535 } 23536 } else if (!strcasecmp(v->name, "t38pt_usertpsource")) { 23537 ast_set_flag(&mask[1], SIP_PAGE2_UDPTL_DESTINATION); 23538 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_UDPTL_DESTINATION); 23539 } else if (!strcasecmp(v->name, "forwardloopdetected")) { 23540 ast_set_flag(&mask[1], SIP_PAGE2_FORWARD_LOOP_DETECTED); 23541 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_FORWARD_LOOP_DETECTED); 23542 } else { 23543 res = 0; 23544 } 23545 23546 return res; 23547 }
| static const char * hangup_cause2sip | ( | int | cause | ) | [static] |
Convert Asterisk hangup causes to SIP codes.
Possible values from causes.h
AST_CAUSE_NOTDEFINED AST_CAUSE_NORMAL AST_CAUSE_BUSY
AST_CAUSE_FAILURE AST_CAUSE_CONGESTION AST_CAUSE_UNALLOCATED
In addition to these, a lot of PRI codes is defined in causes.h
...should we take care of them too ?
Quote RFC 3398
ISUP Cause value SIP response
---------------- ------------
1 unallocated number 404 Not Found
2 no route to network 404 Not found
3 no route to destination 404 Not found
16 normal call clearing --- (*)
17 user busy 486 Busy here
18 no user responding 408 Request Timeout
19 no answer from the user 480 Temporarily unavailable
20 subscriber absent 480 Temporarily unavailable
21 call rejected 403 Forbidden (+)
22 number changed (w/o diagnostic) 410 Gone
22 number changed (w/ diagnostic) 301 Moved Permanently
23 redirection to new destination 410 Gone
26 non-selected user clearing 404 Not Found (=)
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
Definition at line 5980 of file chan_sip.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CHAN_NOT_IMPLEMENTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_ROUTE_TRANSIT_NET, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL_UNSPECIFIED, AST_CAUSE_NOTDEFINED, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNALLOCATED, AST_CAUSE_UNREGISTERED, AST_CAUSE_USER_BUSY, and ast_debug.
Referenced by sip_hangup().
05981 { 05982 switch (cause) { 05983 case AST_CAUSE_UNALLOCATED: /* 1 */ 05984 case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ 05985 case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ 05986 return "404 Not Found"; 05987 case AST_CAUSE_CONGESTION: /* 34 */ 05988 case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ 05989 return "503 Service Unavailable"; 05990 case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ 05991 return "408 Request Timeout"; 05992 case AST_CAUSE_NO_ANSWER: /* 19 */ 05993 case AST_CAUSE_UNREGISTERED: /* 20 */ 05994 return "480 Temporarily unavailable"; 05995 case AST_CAUSE_CALL_REJECTED: /* 21 */ 05996 return "403 Forbidden"; 05997 case AST_CAUSE_NUMBER_CHANGED: /* 22 */ 05998 return "410 Gone"; 05999 case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ 06000 return "480 Temporarily unavailable"; 06001 case AST_CAUSE_INVALID_NUMBER_FORMAT: 06002 return "484 Address incomplete"; 06003 case AST_CAUSE_USER_BUSY: 06004 return "486 Busy here"; 06005 case AST_CAUSE_FAILURE: 06006 return "500 Server internal failure"; 06007 case AST_CAUSE_FACILITY_REJECTED: /* 29 */ 06008 return "501 Not Implemented"; 06009 case AST_CAUSE_CHAN_NOT_IMPLEMENTED: 06010 return "503 Service Unavailable"; 06011 /* Used in chan_iax2 */ 06012 case AST_CAUSE_DESTINATION_OUT_OF_ORDER: 06013 return "502 Bad Gateway"; 06014 case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ 06015 return "488 Not Acceptable Here"; 06016 06017 case AST_CAUSE_NOTDEFINED: 06018 default: 06019 ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause); 06020 return NULL; 06021 } 06022 06023 /* Never reached */ 06024 return 0; 06025 }
| static int hangup_sip2cause | ( | int | cause | ) | [static] |
Convert SIP hangup causes to Asterisk hangup causes.
Definition at line 5868 of file chan_sip.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_BUSY, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INTERWORKING, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL, AST_CAUSE_NORMAL_TEMPORARY_FAILURE, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, AST_CAUSE_UNALLOCATED, and AST_CAUSE_USER_BUSY.
Referenced by handle_response().
05869 { 05870 /* Possible values taken from causes.h */ 05871 05872 switch(cause) { 05873 case 401: /* Unauthorized */ 05874 return AST_CAUSE_CALL_REJECTED; 05875 case 403: /* Not found */ 05876 return AST_CAUSE_CALL_REJECTED; 05877 case 404: /* Not found */ 05878 return AST_CAUSE_UNALLOCATED; 05879 case 405: /* Method not allowed */ 05880 return AST_CAUSE_INTERWORKING; 05881 case 407: /* Proxy authentication required */ 05882 return AST_CAUSE_CALL_REJECTED; 05883 case 408: /* No reaction */ 05884 return AST_CAUSE_NO_USER_RESPONSE; 05885 case 409: /* Conflict */ 05886 return AST_CAUSE_NORMAL_TEMPORARY_FAILURE; 05887 case 410: /* Gone */ 05888 return AST_CAUSE_NUMBER_CHANGED; 05889 case 411: /* Length required */ 05890 return AST_CAUSE_INTERWORKING; 05891 case 413: /* Request entity too large */ 05892 return AST_CAUSE_INTERWORKING; 05893 case 414: /* Request URI too large */ 05894 return AST_CAUSE_INTERWORKING; 05895 case 415: /* Unsupported media type */ 05896 return AST_CAUSE_INTERWORKING; 05897 case 420: /* Bad extension */ 05898 return AST_CAUSE_NO_ROUTE_DESTINATION; 05899 case 480: /* No answer */ 05900 return AST_CAUSE_NO_ANSWER; 05901 case 481: /* No answer */ 05902 return AST_CAUSE_INTERWORKING; 05903 case 482: /* Loop detected */ 05904 return AST_CAUSE_INTERWORKING; 05905 case 483: /* Too many hops */ 05906 return AST_CAUSE_NO_ANSWER; 05907 case 484: /* Address incomplete */ 05908 return AST_CAUSE_INVALID_NUMBER_FORMAT; 05909 case 485: /* Ambiguous */ 05910 return AST_CAUSE_UNALLOCATED; 05911 case 486: /* Busy everywhere */ 05912 return AST_CAUSE_BUSY; 05913 case 487: /* Request terminated */ 05914 return AST_CAUSE_INTERWORKING; 05915 case 488: /* No codecs approved */ 05916 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 05917 case 491: /* Request pending */ 05918 return AST_CAUSE_INTERWORKING; 05919 case 493: /* Undecipherable */ 05920 return AST_CAUSE_INTERWORKING; 05921 case 500: /* Server internal failure */ 05922 return AST_CAUSE_FAILURE; 05923 case 501: /* Call rejected */ 05924 return AST_CAUSE_FACILITY_REJECTED; 05925 case 502: 05926 return AST_CAUSE_DESTINATION_OUT_OF_ORDER; 05927 case 503: /* Service unavailable */ 05928 return AST_CAUSE_CONGESTION; 05929 case 504: /* Gateway timeout */ 05930 return AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE; 05931 case 505: /* SIP version not supported */ 05932 return AST_CAUSE_INTERWORKING; 05933 case 600: /* Busy everywhere */ 05934 return AST_CAUSE_USER_BUSY; 05935 case 603: /* Decline */ 05936 return AST_CAUSE_CALL_REJECTED; 05937 case 604: /* Does not exist anywhere */ 05938 return AST_CAUSE_UNALLOCATED; 05939 case 606: /* Not acceptable */ 05940 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 05941 default: 05942 return AST_CAUSE_NORMAL; 05943 } 05944 /* Never reached */ 05945 return 0; 05946 }
| static int init_req | ( | struct sip_request * | req, | |
| int | sipmethod, | |||
| const char * | recip | |||
| ) | [static] |
Initialize SIP request.
Definition at line 9449 of file chan_sip.c.
References ast_free, ast_str_create(), ast_str_set(), ast_str_strlen(), sip_request::content, sip_request::data, sip_request::header, sip_request::headers, sip_request::len, sip_request::method, sip_methods, SIP_MIN_PACKET, and cfsip_methods::text.
Referenced by initreqprep(), reqprep(), and transmit_register().
09450 { 09451 /* Initialize a request */ 09452 memset(req, 0, sizeof(*req)); 09453 if (!(req->data = ast_str_create(SIP_MIN_PACKET))) 09454 goto e_return; 09455 if (!(req->content = ast_str_create(SIP_MIN_PACKET))) 09456 goto e_free_data; 09457 req->method = sipmethod; 09458 req->header[0] = 0; 09459 ast_str_set(&req->data, 0, "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip); 09460 req->len = ast_str_strlen(req->data); 09461 req->headers++; 09462 return 0; 09463 09464 e_free_data: 09465 ast_free(req->data); 09466 req->data = NULL; 09467 e_return: 09468 return -1; 09469 }
| static int init_resp | ( | struct sip_request * | resp, | |
| const char * | msg | |||
| ) | [static] |
Initialize SIP response, based on SIP request.
Definition at line 9426 of file chan_sip.c.
References ast_free, ast_str_create(), ast_str_set(), sip_request::content, sip_request::data, sip_request::header, sip_request::headers, sip_request::len, sip_request::method, SIP_MIN_PACKET, and SIP_RESPONSE.
Referenced by respprep().
09427 { 09428 /* Initialize a response */ 09429 memset(resp, 0, sizeof(*resp)); 09430 resp->method = SIP_RESPONSE; 09431 if (!(resp->data = ast_str_create(SIP_MIN_PACKET))) 09432 goto e_return; 09433 if (!(resp->content = ast_str_create(SIP_MIN_PACKET))) 09434 goto e_free_data; 09435 resp->header[0] = 0; 09436 ast_str_set(&resp->data, 0, "SIP/2.0 %s\r\n", msg); 09437 resp->len = resp->data->used; 09438 resp->headers++; 09439 return 0; 09440 09441 e_free_data: 09442 ast_free(resp->data); 09443 resp->data = NULL; 09444 e_return: 09445 return -1; 09446 }
| static void initialize_initreq | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Initialize the initital request packet in the pvt structure. This packet is used for creating replies and future requests in a dialog.
Definition at line 3285 of file chan_sip.c.
References ast_debug, ast_verbose, sip_pvt::callid, copy_request(), sip_request::debug, sip_request::headers, sip_pvt::initreq, sip_request::lines, sip_request::method, parse_request(), sip_methods, and cfsip_methods::text.
Referenced by transmit_invite(), transmit_notify_custom(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_register(), and transmit_reinvite_with_sdp().
03286 { 03287 if (p->initreq.headers) 03288 ast_debug(1, "Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->callid); 03289 else 03290 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 03291 /* Use this as the basis */ 03292 copy_request(&p->initreq, req); 03293 parse_request(&p->initreq); 03294 if (req->debug) 03295 ast_verbose("Initreq: %d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 03296 }
| static void initreqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod | |||
| ) | [static] |
Initiate new SIP request to peer/user.
Definition at line 10825 of file chan_sip.c.
References add_header(), add_route(), AST_DIGIT_ANYNUM, ast_inet_ntoa(), AST_PRES_ALLOWED, AST_PRES_RESTRICTION, ast_str_alloca, ast_str_append(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_encode(), build_contact(), build_rpid(), CALLERID_UNKNOWN, sip_pvt::callid, sip_pvt::callingpres, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, DEFAULT_MAX_FORWARDS, exten, sip_pvt::flags, sip_pvt::fromdomain, FROMDOMAIN_INVALID, sip_pvt::fromname, sip_pvt::fromuser, sip_pvt::fullcontact, init_req(), sip_pvt::lastmsg, sip_pvt::ocseq, sip_pvt::options, sip_pvt::our_contact, sip_pvt::ourip, ourport, sip_pvt::owner, sip_settings::pedanticsipchecking, sip_pvt::portinuri, sip_pvt::route, sip_pvt::rpid, sip_pvt::rpid_from, s, S_OR, sip_pvt::sa, sip_cfg, SIP_INVITE, sip_methods, SIP_NOTIFY, SIP_SENDRPID, sip_standard_port(), SIP_USEREQPHONE, SIPBUFSIZE, sip_pvt::socket, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, sip_pvt::todnid, sip_pvt::tohost, sip_socket::type, sip_pvt::uri, sip_invite_param::uri_options, sip_pvt::username, sip_pvt::via, and sip_invite_param::vxml_url.
Referenced by transmit_invite(), transmit_notify_custom(), and transmit_notify_with_mwi().
10826 { 10827 struct ast_str *invite = ast_str_alloca(256); 10828 char from[256]; 10829 char to[256]; 10830 char tmp_n[SIPBUFSIZE/2]; /* build a local copy of 'n' if needed */ 10831 char tmp_l[SIPBUFSIZE/2]; /* build a local copy of 'l' if needed */ 10832 const char *l = NULL; /* XXX what is this, exactly ? */ 10833 const char *n = NULL; /* XXX what is this, exactly ? */ 10834 const char *d = NULL; /* domain in from header */ 10835 const char *urioptions = ""; 10836 int ourport; 10837 10838 if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { 10839 const char *s = p->username; /* being a string field, cannot be NULL */ 10840 10841 /* Test p->username against allowed characters in AST_DIGIT_ANY 10842 If it matches the allowed characters list, then sipuser = ";user=phone" 10843 If not, then sipuser = "" 10844 */ 10845 /* + is allowed in first position in a tel: uri */ 10846 if (*s == '+') 10847 s++; 10848 for (; *s; s++) { 10849 if (!strchr(AST_DIGIT_ANYNUM, *s) ) 10850 break; 10851 } 10852 /* If we have only digits, add ;user=phone to the uri */ 10853 if (!*s) 10854 urioptions = ";user=phone"; 10855 } 10856 10857 10858 snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text); 10859 10860 d = S_OR(p->fromdomain, ast_inet_ntoa(p->ourip.sin_addr)); 10861 if (p->owner) { 10862 l = p->owner->cid.cid_num; 10863 n = p->owner->cid.cid_name; 10864 } 10865 /* if we are not sending RPID and user wants his callerid restricted */ 10866 if (!ast_test_flag(&p->flags[0], SIP_SENDRPID) && 10867 ((p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED)) { 10868 l = CALLERID_UNKNOWN; 10869 n = l; 10870 d = FROMDOMAIN_INVALID; 10871 } 10872 if (ast_strlen_zero(l)) 10873 l = default_callerid; 10874 if (ast_strlen_zero(n)) 10875 n = l; 10876 /* Allow user to be overridden */ 10877 if (!ast_strlen_zero(p->fromuser)) 10878 l = p->fromuser; 10879 else /* Save for any further attempts */ 10880 ast_string_field_set(p, fromuser, l); 10881 10882 /* Allow user to be overridden */ 10883 if (!ast_strlen_zero(p->fromname)) 10884 n = p->fromname; 10885 else /* Save for any further attempts */ 10886 ast_string_field_set(p, fromname, n); 10887 10888 if (sip_cfg.pedanticsipchecking) { 10889 ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0); 10890 n = tmp_n; 10891 ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0); 10892 l = tmp_l; 10893 } 10894 10895 ourport = ntohs(p->ourip.sin_port); 10896 if (!sip_standard_port(p->socket.type, ourport) && ast_strlen_zero(p->fromdomain)) 10897 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, d, ourport, p->tag); 10898 else 10899 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, d, p->tag); 10900 10901 /* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */ 10902 if (!ast_strlen_zero(p->fullcontact)) { 10903 /* If we have full contact, trust it */ 10904 ast_str_append(&invite, 0, "%s", p->fullcontact); 10905 } else { 10906 /* Otherwise, use the username while waiting for registration */ 10907 ast_str_append(&invite, 0, "sip:"); 10908 if (!ast_strlen_zero(p->username)) { 10909 n = p->username; 10910 if (sip_cfg.pedanticsipchecking) { 10911 ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0); 10912 n = tmp_n; 10913 } 10914 ast_str_append(&invite, 0, "%s@", n); 10915 } 10916 ast_str_append(&invite, 0, "%s", p->tohost); 10917 if (p->portinuri) 10918 ast_str_append(&invite, 0, ":%d", ntohs(p->sa.sin_port)); 10919 ast_str_append(&invite, 0, "%s", urioptions); 10920 } 10921 10922 /* If custom URI options have been provided, append them */ 10923 if (p->options && !ast_strlen_zero(p->options->uri_options)) 10924 ast_str_append(&invite, 0, ";%s", p->options->uri_options); 10925 10926 /* This is the request URI, which is the next hop of the call 10927 which may or may not be the destination of the call 10928 */ 10929 ast_string_field_set(p, uri, invite->str); 10930 10931 if (!ast_strlen_zero(p->todnid)) { 10932 /*! \todo Need to add back the VXML URL here at some point, possibly use build_string for all this junk */ 10933 if (!strchr(p->todnid, '@')) { 10934 /* We have no domain in the dnid */ 10935 snprintf(to, sizeof(to), "<sip:%s@%s>%s%s", p->todnid, p->tohost, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag); 10936 } else { 10937 snprintf(to, sizeof(to), "<sip:%s>%s%s", p->todnid, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag); 10938 } 10939 } else { 10940 if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) { 10941 /* If this is a NOTIFY, use the From: tag in the subscribe (RFC 3265) */ 10942 snprintf(to, sizeof(to), "<%s%s>;tag=%s", (strncasecmp(p->uri, "sip:", 4) ? "sip:" : ""), p->uri, p->theirtag); 10943 } else if (p->options && p->options->vxml_url) { 10944 /* If there is a VXML URL append it to the SIP URL */ 10945 snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url); 10946 } else 10947 snprintf(to, sizeof(to), "<%s>", p->uri); 10948 } 10949 10950 init_req(req, sipmethod, p->uri); 10951 /* now tmp_n is available so reuse it to build the CSeq */ 10952 snprintf(tmp_n, sizeof(tmp_n), "%d %s", ++p->ocseq, sip_methods[sipmethod].text); 10953 10954 add_header(req, "Via", p->via); 10955 add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 10956 /* This will be a no-op most of the time. However, under certain circumstances, 10957 * NOTIFY messages will use this function for preparing the request and should 10958 * have Route headers present. 10959 */ 10960 add_route(req, p->route); 10961 10962 /* Build Remote Party-ID and From */ 10963 if (ast_test_flag(&p->flags[0], SIP_SENDRPID) && (sipmethod == SIP_INVITE)) { 10964 build_rpid(p); 10965 add_header(req, "From", p->rpid_from); 10966 } else 10967 add_header(req, "From", from); 10968 add_header(req, "To", to); 10969 ast_string_field_set(p, exten, l); 10970 build_contact(p); 10971 add_header(req, "Contact", p->our_contact); 10972 add_header(req, "Call-ID", p->callid); 10973 add_header(req, "CSeq", tmp_n); 10974 if (!ast_strlen_zero(global_useragent)) 10975 add_header(req, "User-Agent", global_useragent); 10976 if (!ast_strlen_zero(p->rpid)) 10977 add_header(req, "Remote-Party-ID", p->rpid); 10978 }
| static const char * insecure2str | ( | int | mode | ) | [static] |
Convert Insecure setting to printable string.
Definition at line 15144 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer().
15145 { 15146 return map_x_s(insecurestr, mode, "<error>"); 15147 }
| static int interpret_t38_parameters | ( | struct sip_pvt * | p, | |
| const struct ast_control_t38_parameters * | parameters | |||
| ) | [static] |
Helper function which updates T.38 capability information and triggers a reinvite.
Definition at line 6498 of file chan_sip.c.
References AST_CONTROL_T38_PARAMETERS, ast_queue_control_data(), AST_SCHED_DEL, AST_SCHED_DEL_UNREF, ast_set_flag, AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_PARMS, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_test_flag, ast_udptl_get_far_max_ifp(), ast_udptl_set_local_max_ifp(), change_t38_state(), dialog_unref(), FALSE, ast_control_t38_parameters::fill_bit_removal, sip_pvt::flags, sip_pvt::initreq, ast_control_t38_parameters::max_ifp, MIN, t38properties::our_parms, sip_pvt::owner, sip_pvt::pendinginvite, ast_control_t38_parameters::rate_management, ast_control_t38_parameters::request_response, SIP_NEEDREINVITE, SIP_PAGE2_T38SUPPORT, SIP_PENDINGBYE, t38properties::state, sip_pvt::t38, T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_PEER_REINVITE, sip_pvt::t38id, t38properties::their_parms, ast_control_t38_parameters::transcoding_jbig, ast_control_t38_parameters::transcoding_mmr, transmit_reinvite_with_sdp(), transmit_response_reliable(), transmit_response_with_t38_sdp(), TRUE, sip_pvt::udptl, ast_control_t38_parameters::version, and XMIT_CRITICAL.
Referenced by sip_indicate().
06499 { 06500 int res = 0; 06501 06502 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) || !p->udptl) { 06503 return -1; 06504 } 06505 switch (parameters->request_response) { 06506 case AST_T38_NEGOTIATED: 06507 case AST_T38_REQUEST_NEGOTIATE: /* Request T38 */ 06508 /* Negotiation can not take place without a valid max_ifp value. */ 06509 if (!parameters->max_ifp) { 06510 change_t38_state(p, T38_DISABLED); 06511 if (p->t38.state == T38_PEER_REINVITE) { 06512 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06513 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 06514 } 06515 break; 06516 } else if (p->t38.state == T38_PEER_REINVITE) { 06517 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06518 p->t38.our_parms = *parameters; 06519 /* modify our parameters to conform to the peer's parameters, 06520 * based on the rules in the ITU T.38 recommendation 06521 */ 06522 if (!p->t38.their_parms.fill_bit_removal) { 06523 p->t38.our_parms.fill_bit_removal = FALSE; 06524 } 06525 if (!p->t38.their_parms.transcoding_mmr) { 06526 p->t38.our_parms.transcoding_mmr = FALSE; 06527 } 06528 if (!p->t38.their_parms.transcoding_jbig) { 06529 p->t38.our_parms.transcoding_jbig = FALSE; 06530 } 06531 p->t38.our_parms.version = MIN(p->t38.our_parms.version, p->t38.their_parms.version); 06532 p->t38.our_parms.rate_management = p->t38.their_parms.rate_management; 06533 ast_udptl_set_local_max_ifp(p->udptl, p->t38.our_parms.max_ifp); 06534 change_t38_state(p, T38_ENABLED); 06535 transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); 06536 } else if (p->t38.state != T38_ENABLED) { 06537 p->t38.our_parms = *parameters; 06538 ast_udptl_set_local_max_ifp(p->udptl, p->t38.our_parms.max_ifp); 06539 change_t38_state(p, T38_LOCAL_REINVITE); 06540 if (!p->pendinginvite) { 06541 transmit_reinvite_with_sdp(p, TRUE, FALSE); 06542 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 06543 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 06544 } 06545 } 06546 break; 06547 case AST_T38_TERMINATED: 06548 case AST_T38_REFUSED: 06549 case AST_T38_REQUEST_TERMINATE: /* Shutdown T38 */ 06550 if (p->t38.state == T38_PEER_REINVITE) { 06551 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06552 change_t38_state(p, T38_DISABLED); 06553 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 06554 } else if (p->t38.state == T38_ENABLED) 06555 transmit_reinvite_with_sdp(p, FALSE, FALSE); 06556 break; 06557 case AST_T38_REQUEST_PARMS: { /* Application wants remote's parameters re-sent */ 06558 struct ast_control_t38_parameters parameters = p->t38.their_parms; 06559 06560 if (p->t38.state == T38_PEER_REINVITE) { 06561 AST_SCHED_DEL(sched, p->t38id); 06562 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 06563 parameters.request_response = AST_T38_REQUEST_NEGOTIATE; 06564 ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters)); 06565 /* we need to return a positive value here, so that applications that 06566 * send this request can determine conclusively whether it was accepted or not... 06567 * older versions of chan_sip would just silently accept it and return zero. 06568 */ 06569 res = AST_T38_REQUEST_PARMS; 06570 } 06571 break; 06572 } 06573 default: 06574 res = -1; 06575 break; 06576 } 06577 06578 return res; 06579 }
| static void list_route | ( | struct sip_route * | route | ) | [static] |
List all routes - mostly for debugging.
Definition at line 12612 of file chan_sip.c.
References ast_verbose, sip_route::hop, and sip_route::next.
Referenced by build_route().
12613 { 12614 if (!route) 12615 ast_verbose("list_route: no route\n"); 12616 else { 12617 for (;route; route = route->next) 12618 ast_verbose("list_route: hop: <%s>\n", route->hop); 12619 } 12620 }
| static int load_module | ( | void | ) | [static] |
PBX load module - initialization.
Definition at line 26028 of file chan_sip.c.
References ao2_t_container_alloc, ARRAY_LEN, ast_channel_register(), ast_check_realtime(), ast_cli_register_multiple(), ast_custom_function_register, ast_log(), ast_manager_register2(), AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_realtime_require_field(), ast_register_application_xml, ast_rtp_proto_register(), ast_udptl_proto_register(), ast_verbose, ASTOBJ_CONTAINER_INIT, CHANNEL_MODULE_LOAD, dialog_cmp_cb(), dialog_hash_cb(), EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, io_context_create(), io_context_destroy(), LOG_ERROR, manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), peer_cmp_cb(), peer_hash_cb(), peer_ipcmp_cb(), peer_iphash_cb(), regl, reload_config(), restart_monitor(), RQ_CHAR, RQ_INTEGER4, RQ_UINTEGER2, sched_context_create(), sched_context_destroy(), ast_channel_tech::send_digit_begin, SENTINEL, sip_addheader(), sip_dtmfmode(), sip_poke_all_peers(), sip_removeheader(), sip_send_all_mwi_subscriptions(), sip_send_all_registers(), sip_tech_info, submwil, threadt_cmp_cb(), and threadt_hash_cb().
26029 { 26030 ast_verbose("SIP channel loading...\n"); 26031 /* the fact that ao2_containers can't resize automatically is a major worry! */ 26032 /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */ 26033 peers = ao2_t_container_alloc(HASH_PEER_SIZE, peer_hash_cb, peer_cmp_cb, "allocate peers"); 26034 peers_by_ip = ao2_t_container_alloc(HASH_PEER_SIZE, peer_iphash_cb, peer_ipcmp_cb, "allocate peers_by_ip"); 26035 dialogs = ao2_t_container_alloc(HASH_DIALOG_SIZE, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs"); 26036 threadt = ao2_t_container_alloc(HASH_DIALOG_SIZE, threadt_hash_cb, threadt_cmp_cb, "allocate threadt table"); 26037 26038 ASTOBJ_CONTAINER_INIT(®l); /* Registry object list -- not searched for anything */ 26039 ASTOBJ_CONTAINER_INIT(&submwil); /* MWI subscription object list */ 26040 26041 if (!(sched = sched_context_create())) { 26042 ast_log(LOG_ERROR, "Unable to create scheduler context\n"); 26043 return AST_MODULE_LOAD_FAILURE; 26044 } 26045 26046 if (!(io = io_context_create())) { 26047 ast_log(LOG_ERROR, "Unable to create I/O context\n"); 26048 sched_context_destroy(sched); 26049 return AST_MODULE_LOAD_FAILURE; 26050 } 26051 26052 sip_reloadreason = CHANNEL_MODULE_LOAD; 26053 26054 if(reload_config(sip_reloadreason)) /* Load the configuration from sip.conf */ 26055 return AST_MODULE_LOAD_DECLINE; 26056 26057 /* Prepare the version that does not require DTMF BEGIN frames. 26058 * We need to use tricks such as memcpy and casts because the variable 26059 * has const fields. 26060 */ 26061 memcpy(&sip_tech_info, &sip_tech, sizeof(sip_tech)); 26062 memset((void *) &sip_tech_info.send_digit_begin, 0, sizeof(sip_tech_info.send_digit_begin)); 26063 26064 /* Make sure we can register our sip channel type */ 26065 if (ast_channel_register(&sip_tech)) { 26066 ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n"); 26067 io_context_destroy(io); 26068 sched_context_destroy(sched); 26069 return AST_MODULE_LOAD_FAILURE; 26070 } 26071 26072 /* Register all CLI functions for SIP */ 26073 ast_cli_register_multiple(cli_sip, ARRAY_LEN(cli_sip)); 26074 26075 /* Tell the RTP subdriver that we're here */ 26076 ast_rtp_proto_register(&sip_rtp); 26077 26078 /* Tell the UDPTL subdriver that we're here */ 26079 ast_udptl_proto_register(&sip_udptl); 26080 26081 /* Register dialplan applications */ 26082 ast_register_application_xml(app_dtmfmode, sip_dtmfmode); 26083 ast_register_application_xml(app_sipaddheader, sip_addheader); 26084 ast_register_application_xml(app_sipremoveheader, sip_removeheader); 26085 26086 /* Register dialplan functions */ 26087 ast_custom_function_register(&sip_header_function); 26088 ast_custom_function_register(&sippeer_function); 26089 ast_custom_function_register(&sipchaninfo_function); 26090 ast_custom_function_register(&checksipdomain_function); 26091 26092 /* Register manager commands */ 26093 ast_manager_register2("SIPpeers", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_show_peers, 26094 "List SIP peers (text format)", mandescr_show_peers); 26095 ast_manager_register2("SIPshowpeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_show_peer, 26096 "Show SIP peer (text format)", mandescr_show_peer); 26097 ast_manager_register2("SIPqualifypeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_qualify_peer, 26098 "Show SIP peer (text format)", mandescr_show_peer); /*! \todo Fix this XXX This must be all wrong XXXX */ 26099 ast_manager_register2("SIPshowregistry", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_show_registry, 26100 "Show SIP registrations (text format)", mandescr_show_registry); 26101 ast_manager_register2("SIPnotify", EVENT_FLAG_SYSTEM, manager_sipnotify, 26102 "Send a SIP notify", mandescr_sipnotify); 26103 sip_poke_all_peers(); 26104 sip_send_all_registers(); 26105 sip_send_all_mwi_subscriptions(); 26106 26107 /* And start the monitor for the first time */ 26108 restart_monitor(); 26109 26110 ast_realtime_require_field(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", 26111 "name", RQ_CHAR, 10, 26112 "ipaddr", RQ_CHAR, 15, 26113 "port", RQ_UINTEGER2, 5, 26114 "regseconds", RQ_INTEGER4, 11, 26115 "defaultuser", RQ_CHAR, 10, 26116 "fullcontact", RQ_CHAR, 35, 26117 "regserver", RQ_CHAR, 20, 26118 "useragent", RQ_CHAR, 20, 26119 "lastms", RQ_INTEGER4, 11, 26120 SENTINEL); 26121 26122 return AST_MODULE_LOAD_SUCCESS; 26123 }
| static int local_attended_transfer | ( | struct sip_pvt * | transferer, | |
| struct sip_dual * | current, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Find all call legs and bridge transferee with target called from handle_request_refer.
Definition at line 20637 of file chan_sip.c.
References ast_channel::_state, ao2_t_ref, append_history, ast_bridged_channel(), ast_channel_unlock, ast_clear_flag, ast_debug, ast_set_flag, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), attempt_transfer(), sip_pvt::callid, sip_dual::chan1, sip_dual::chan2, EVENT_FLAG_CALL, sip_pvt::flags, get_sip_pvt_byid_locked(), ast_channel::language, sip_refer::localtransfer, manager_event, ast_channel::name, sip_pvt::owner, pbx_builtin_getvar_helper(), sip_pvt::refer, REFER_200OK, REFER_FAILED, sip_refer::replaces_callid, sip_refer::replaces_callid_fromtag, sip_refer::replaces_callid_totag, SIP_DEFER_BYE_ON_TRANSFER, SIP_GOTREFER, sip_pvt_unlock, sip_refer::status, transmit_notify_with_sipfrag(), transmit_response(), TRUE, ast_channel::uniqueid, and xfersound.
Referenced by handle_request_refer().
20638 { 20639 struct sip_dual target; /* Chan 1: Call from tranferer to Asterisk */ 20640 /* Chan 2: Call from Asterisk to target */ 20641 int res = 0; 20642 struct sip_pvt *targetcall_pvt; 20643 20644 /* Check if the call ID of the replaces header does exist locally */ 20645 if (!(targetcall_pvt = get_sip_pvt_byid_locked(transferer->refer->replaces_callid, transferer->refer->replaces_callid_totag, 20646 transferer->refer->replaces_callid_fromtag))) { 20647 if (transferer->refer->localtransfer) { 20648 /* We did not find the refered call. Sorry, can't accept then */ 20649 transmit_response(transferer, "202 Accepted", req); 20650 /* Let's fake a response from someone else in order 20651 to follow the standard */ 20652 transmit_notify_with_sipfrag(transferer, seqno, "481 Call leg/transaction does not exist", TRUE); 20653 append_history(transferer, "Xfer", "Refer failed"); 20654 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 20655 transferer->refer->status = REFER_FAILED; 20656 return -1; 20657 } 20658 /* Fall through for remote transfers that we did not find locally */ 20659 ast_debug(3, "SIP attended transfer: Not our call - generating INVITE with replaces\n"); 20660 return 0; 20661 } 20662 20663 /* Ok, we can accept this transfer */ 20664 transmit_response(transferer, "202 Accepted", req); 20665 append_history(transferer, "Xfer", "Refer accepted"); 20666 if (!targetcall_pvt->owner) { /* No active channel */ 20667 ast_debug(4, "SIP attended transfer: Error: No owner of target call\n"); 20668 /* Cancel transfer */ 20669 transmit_notify_with_sipfrag(transferer, seqno, "503 Service Unavailable", TRUE); 20670 append_history(transferer, "Xfer", "Refer failed"); 20671 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 20672 transferer->refer->status = REFER_FAILED; 20673 sip_pvt_unlock(targetcall_pvt); 20674 if (targetcall_pvt) 20675 ao2_t_ref(targetcall_pvt, -1, "Drop targetcall_pvt pointer"); 20676 return -1; 20677 } 20678 20679 /* We have a channel, find the bridge */ 20680 target.chan1 = targetcall_pvt->owner; /* Transferer to Asterisk */ 20681 target.chan2 = ast_bridged_channel(targetcall_pvt->owner); /* Asterisk to target */ 20682 20683 if (!target.chan2 || !(target.chan2->_state == AST_STATE_UP || target.chan2->_state == AST_STATE_RINGING) ) { 20684 /* Wrong state of new channel */ 20685 if (target.chan2) 20686 ast_debug(4, "SIP attended transfer: Error: Wrong state of target call: %s\n", ast_state2str(target.chan2->_state)); 20687 else if (target.chan1->_state != AST_STATE_RING) 20688 ast_debug(4, "SIP attended transfer: Error: No target channel\n"); 20689 else 20690 ast_debug(4, "SIP attended transfer: Attempting transfer in ringing state\n"); 20691 } 20692 20693 /* Transfer */ 20694 if (sipdebug) { 20695 if (current->chan2) /* We have two bridges */ 20696 ast_debug(4, "SIP attended transfer: trying to bridge %s and %s\n", target.chan1->name, current->chan2->name); 20697 else /* One bridge, propably transfer of IVR/voicemail etc */ 20698 ast_debug(4, "SIP attended transfer: trying to make %s take over (masq) %s\n", target.chan1->name, current->chan1->name); 20699 } 20700 20701 ast_set_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 20702 20703 /* Perform the transfer */ 20704 manager_event(EVENT_FLAG_CALL, "Transfer", "TransferMethod: SIP\r\nTransferType: Attended\r\nChannel: %s\r\nUniqueid: %s\r\nSIP-Callid: %s\r\nTargetChannel: %s\r\nTargetUniqueid: %s\r\n", 20705 transferer->owner->name, 20706 transferer->owner->uniqueid, 20707 transferer->callid, 20708 target.chan1->name, 20709 target.chan1->uniqueid); 20710 res = attempt_transfer(current, &target); 20711 sip_pvt_unlock(targetcall_pvt); 20712 if (res) { 20713 /* Failed transfer */ 20714 transmit_notify_with_sipfrag(transferer, seqno, "486 Busy Here", TRUE); 20715 append_history(transferer, "Xfer", "Refer failed"); 20716 if (targetcall_pvt->owner) 20717 ast_channel_unlock(targetcall_pvt->owner); 20718 ast_clear_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); 20719 } else { 20720 /* Transfer succeeded! */ 20721 const char *xfersound = pbx_builtin_getvar_helper(target.chan1, "ATTENDED_TRANSFER_COMPLETE_SOUND"); 20722 20723 /* Tell transferer that we're done. */ 20724 transmit_notify_with_sipfrag(transferer, seqno, "200 OK", TRUE); 20725 append_history(transferer, "Xfer", "Refer succeeded"); 20726 transferer->refer->status = REFER_200OK; 20727 if (target.chan2 && !ast_strlen_zero(xfersound) && ast_streamfile(target.chan2, xfersound, target.chan2->language) >= 0) { 20728 ast_waitstream(target.chan2, ""); 20729 } 20730 if (targetcall_pvt->owner) { 20731 ast_debug(1, "SIP attended transfer: Unlocking channel %s\n", targetcall_pvt->owner->name); 20732 ast_channel_unlock(targetcall_pvt->owner); 20733 } 20734 } 20735 if (targetcall_pvt) 20736 ao2_t_ref(targetcall_pvt, -1, "drop targetcall_pvt"); 20737 return 1; 20738 }
| static int lws2sws | ( | char * | msgbuf, | |
| int | len | |||
| ) | [static] |
Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled.
Definition at line 7848 of file chan_sip.c.
Referenced by handle_request_do().
07849 { 07850 int h = 0, t = 0; 07851 int lws = 0; 07852 07853 for (; h < len;) { 07854 /* Eliminate all CRs */ 07855 if (msgbuf[h] == '\r') { 07856 h++; 07857 continue; 07858 } 07859 /* Check for end-of-line */ 07860 if (msgbuf[h] == '\n') { 07861 /* Check for end-of-message */ 07862 if (h + 1 == len) 07863 break; 07864 /* Check for a continuation line */ 07865 if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') { 07866 /* Merge continuation line */ 07867 h++; 07868 continue; 07869 } 07870 /* Propagate LF and start new line */ 07871 msgbuf[t++] = msgbuf[h++]; 07872 lws = 0; 07873 continue; 07874 } 07875 if (msgbuf[h] == ' ' || msgbuf[h] == '\t') { 07876 if (lws) { 07877 h++; 07878 continue; 07879 } 07880 msgbuf[t++] = msgbuf[h++]; 07881 lws = 1; 07882 continue; 07883 } 07884 msgbuf[t++] = msgbuf[h++]; 07885 if (lws) 07886 lws = 0; 07887 } 07888 msgbuf[t] = '\0'; 07889 return t; 07890 }
| static void make_our_tag | ( | char * | tagbuf, | |
| size_t | len | |||
| ) | [static] |
Make our SIP dialog tag.
Definition at line 7226 of file chan_sip.c.
References ast_random().
Referenced by handle_request_invite(), handle_request_subscribe(), sip_alloc(), transmit_register(), and transmit_response_using_temp().
07227 { 07228 snprintf(tagbuf, len, "as%08lx", ast_random()); 07229 }
| static int manager_show_registry | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP registrations in the manager API.
Definition at line 14786 of file chan_sip.c.
References ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_listack(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, regl, regstate2str(), STANDARD_SIP_PORT, and total.
Referenced by load_module().
14787 { 14788 const char *id = astman_get_header(m, "ActionID"); 14789 char idtext[256] = ""; 14790 int total = 0; 14791 14792 if (!ast_strlen_zero(id)) 14793 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 14794 14795 astman_send_listack(s, m, "Registrations will follow", "start"); 14796 14797 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 14798 ASTOBJ_RDLOCK(iterator); 14799 astman_append(s, 14800 "Event: RegistryEntry\r\n" 14801 "%s" 14802 "Host: %s\r\n" 14803 "Port: %d\r\n" 14804 "Username: %s\r\n" 14805 "Refresh: %d\r\n" 14806 "State: %s\r\n" 14807 "RegistrationTime: %ld\r\n" 14808 "\r\n", idtext, iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT, 14809 iterator->username, iterator->refresh, regstate2str(iterator->regstate), (long) iterator->regtime.tv_sec); 14810 ASTOBJ_UNLOCK(iterator); 14811 total++; 14812 } while(0)); 14813 14814 astman_append(s, 14815 "Event: RegistrationsComplete\r\n" 14816 "EventList: Complete\r\n" 14817 "ListItems: %d\r\n" 14818 "%s" 14819 "\r\n", total, idtext); 14820 14821 return 0; 14822 }
| static int manager_sip_qualify_peer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Qualify SIP peers in the manager API.
Definition at line 15495 of file chan_sip.c.
References _sip_qualify_peer(), ast_strlen_zero(), astman_append(), astman_get_header(), and astman_send_error().
Referenced by load_module().
15496 { 15497 const char *a[4]; 15498 const char *peer; 15499 15500 peer = astman_get_header(m, "Peer"); 15501 if (ast_strlen_zero(peer)) { 15502 astman_send_error(s, m, "Peer: <name> missing."); 15503 return 0; 15504 } 15505 a[0] = "sip"; 15506 a[1] = "qualify"; 15507 a[2] = "peer"; 15508 a[3] = peer; 15509 15510 _sip_qualify_peer(1, -1, s, m, 4, a); 15511 astman_append(s, "\r\n\r\n" ); 15512 return 0; 15513 }
| static int manager_sip_show_peer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 15436 of file chan_sip.c.
References _sip_show_peer(), ast_strlen_zero(), astman_append(), astman_get_header(), and astman_send_error().
Referenced by load_module().
15437 { 15438 const char *a[4]; 15439 const char *peer; 15440 15441 peer = astman_get_header(m, "Peer"); 15442 if (ast_strlen_zero(peer)) { 15443 astman_send_error(s, m, "Peer: <name> missing."); 15444 return 0; 15445 } 15446 a[0] = "sip"; 15447 a[1] = "show"; 15448 a[2] = "peer"; 15449 a[3] = peer; 15450 15451 _sip_show_peer(1, -1, s, m, 4, a); 15452 astman_append(s, "\r\n\r\n" ); 15453 return 0; 15454 }
| static int manager_sip_show_peers | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 14833 of file chan_sip.c.
References _sip_show_peers(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_listack(), and total.
Referenced by load_module().
14834 { 14835 const char *id = astman_get_header(m, "ActionID"); 14836 const char *a[] = {"sip", "show", "peers"}; 14837 char idtext[256] = ""; 14838 int total = 0; 14839 14840 if (!ast_strlen_zero(id)) 14841 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 14842 14843 astman_send_listack(s, m, "Peer status list will follow", "start"); 14844 /* List the peers in separate manager events */ 14845 _sip_show_peers(-1, &total, s, m, 3, a); 14846 /* Send final confirmation */ 14847 astman_append(s, 14848 "Event: PeerlistComplete\r\n" 14849 "EventList: Complete\r\n" 14850 "ListItems: %d\r\n" 14851 "%s" 14852 "\r\n", total, idtext); 14853 return 0; 14854 }
| static int manager_sipnotify | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 11542 of file chan_sip.c.
References ao2_t_link, ao2_t_unlink, ast_set_flag, ast_sip_ouraddrfor(), ast_strlen_zero(), ast_variables_destroy(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), build_callid_pvt(), build_via(), create_addr(), dialog_ref(), dialog_unlink_all(), dialog_unref(), sip_pvt::flags, sip_pvt::ourip, sip_pvt::sa, sip_alloc(), SIP_NOTIFY, SIP_OUTGOING, sip_scheddestroy(), SIP_TRANS_TIMEOUT, transmit_notify_custom(), and TRUE.
Referenced by load_module().
11543 { 11544 const char *channame = astman_get_header(m, "Channel"); 11545 struct ast_variable *vars = astman_get_variables(m); 11546 struct sip_pvt *p; 11547 11548 if (ast_strlen_zero(channame)) { 11549 astman_send_error(s, m, "SIPNotify requires a channel name"); 11550 return 0; 11551 } 11552 11553 if (!strncasecmp(channame, "sip/", 4)) { 11554 channame += 4; 11555 } 11556 11557 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) { 11558 astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)"); 11559 return 0; 11560 } 11561 11562 if (create_addr(p, channame, NULL, 0)) { 11563 /* Maybe they're not registered, etc. */ 11564 dialog_unlink_all(p, TRUE, TRUE); 11565 dialog_unref(p, "unref dialog inside for loop" ); 11566 /* sip_destroy(p); */ 11567 astman_send_error(s, m, "Could not create address"); 11568 return 0; 11569 } 11570 11571 /* Notify is outgoing call */ 11572 ast_set_flag(&p->flags[0], SIP_OUTGOING); 11573 11574 /* Recalculate our side, and recalculate Call ID */ 11575 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 11576 build_via(p); 11577 ao2_t_unlink(dialogs, p, "About to change the callid -- remove the old name"); 11578 build_callid_pvt(p); 11579 ao2_t_link(dialogs, p, "Linking in new name"); 11580 dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement."); 11581 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); 11582 11583 if (!transmit_notify_custom(p, vars)) { 11584 astman_send_ack(s, m, "Notify Sent"); 11585 } else { 11586 astman_send_error(s, m, "Unable to send notify"); 11587 } 11588 ast_variables_destroy(vars); 11589 return 0; 11590 }
| static int map_s_x | ( | const struct _map_x_s * | table, | |
| const char * | s, | |||
| int | errorvalue | |||
| ) | [static] |
map from a string to an integer value, case insensitive. If no match is found, return errorvalue.
Definition at line 2735 of file chan_sip.c.
References _map_x_s::s, and _map_x_s::x.
Referenced by str2dtmfmode(), str2stmode(), and str2strefresher().
02736 { 02737 const struct _map_x_s *cur; 02738 02739 for (cur = table; cur->s; cur++) 02740 if (!strcasecmp(cur->s, s)) 02741 return cur->x; 02742 return errorvalue; 02743 }
| static const char* map_x_s | ( | const struct _map_x_s * | table, | |
| int | x, | |||
| const char * | errorstring | |||
| ) | [static] |
map from an integer value to a string. If no match is found, return errorstring
Definition at line 2722 of file chan_sip.c.
References _map_x_s::s, and _map_x_s::x.
Referenced by dtmfmode2str(), faxec2str(), insecure2str(), nat2str(), referstatus2str(), regstate2str(), stmode2str(), and strefresher2str().
02723 { 02724 const struct _map_x_s *cur; 02725 02726 for (cur = table; cur->s; cur++) 02727 if (cur->x == x) 02728 return cur->s; 02729 return errorstring; 02730 }
| static int method_match | ( | enum sipmethod | id, | |
| const char * | name | |||
| ) | [static] |
returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'. Strictly speaking, SIP methods are case SENSITIVE, but we do a case-insensitive comparison to be more tolerant. following Jon Postel's rule: Be gentle in what you accept, strict with what you send
Definition at line 3382 of file chan_sip.c.
References sip_methods, and text.
Referenced by __sip_autodestruct(), __sip_semi_ack(), and find_sip_method().
03383 { 03384 int len = strlen(sip_methods[id].text); 03385 int l_name = name ? strlen(name) : 0; 03386 /* true if the string is long enough, and ends with whitespace, and matches */ 03387 return (l_name >= len && name[len] < 33 && 03388 !strncasecmp(sip_methods[id].text, name, len)); 03389 }
| static void mwi_event_cb | ( | const struct ast_event * | event, | |
| void * | userdata | |||
| ) | [static] |
Receive MWI events that we have subscribed to.
Definition at line 12943 of file chan_sip.c.
References ao2_lock(), ao2_unlock(), and sip_send_mwi_to_peer().
Referenced by add_peer_mwi_subs().
12944 { 12945 struct sip_peer *peer = userdata; 12946 12947 ao2_lock(peer); 12948 sip_send_mwi_to_peer(peer, event, 0); 12949 ao2_unlock(peer); 12950 }
| static const char * nat2str | ( | int | nat | ) | [static] |
Convert NAT setting to text string.
Definition at line 14568 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_users().
| static struct sip_proxy* obproxy_get | ( | struct sip_pvt * | dialog, | |
| struct sip_peer * | peer | |||
| ) | [static, read] |
Get default outbound proxy or global proxy.
Definition at line 3357 of file chan_sip.c.
References append_history, ast_debug, sip_proxy::name, sip_settings::outboundproxy, sip_peer::outboundproxy, and sip_cfg.
Referenced by __sip_subscribe_mwi_do(), create_addr(), and create_addr_from_peer().
03358 { 03359 if (peer && peer->outboundproxy) { 03360 if (sipdebug) 03361 ast_debug(1, "OBPROXY: Applying peer OBproxy to this call\n"); 03362 append_history(dialog, "OBproxy", "Using peer obproxy %s", peer->outboundproxy->name); 03363 return peer->outboundproxy; 03364 } 03365 if (sip_cfg.outboundproxy.name[0]) { 03366 if (sipdebug) 03367 ast_debug(1, "OBPROXY: Applying global OBproxy to this call\n"); 03368 append_history(dialog, "OBproxy", "Using global obproxy %s", sip_cfg.outboundproxy.name); 03369 return &sip_cfg.outboundproxy; 03370 } 03371 if (sipdebug) 03372 ast_debug(1, "OBPROXY: Not applying OBproxy to this call\n"); 03373 return NULL; 03374 }
| static void parse_copy | ( | struct sip_request * | dst, | |
| const struct sip_request * | src | |||
| ) | [static] |
Copy SIP request, parse it.
Definition at line 4200 of file chan_sip.c.
References copy_request(), and parse_request().
Referenced by send_request(), and send_response().
04201 { 04202 copy_request(dst, src); 04203 parse_request(dst); 04204 }
| int parse_minse | ( | const char * | p_hdrval, | |
| int *const | p_interval | |||
| ) | [static] |
Session-Timers: Function for parsing Min-SE header.
Definition at line 22898 of file chan_sip.c.
References ast_debug, ast_log(), ast_skip_blanks(), ast_strlen_zero(), and LOG_WARNING.
Referenced by handle_request_invite(), and proc_422_rsp().
22899 { 22900 if (ast_strlen_zero(p_hdrval)) { 22901 ast_log(LOG_WARNING, "Null Min-SE header\n"); 22902 return -1; 22903 } 22904 22905 *p_interval = 0; 22906 p_hdrval = ast_skip_blanks(p_hdrval); 22907 if (!sscanf(p_hdrval, "%30d", p_interval)) { 22908 ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval); 22909 return -1; 22910 } 22911 22912 ast_debug(2, "Received Min-SE: %d\n", *p_interval); 22913 return 0; 22914 }
| static void parse_moved_contact | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Parse 302 Moved temporalily response.
Definition at line 17645 of file chan_sip.c.
References ao2_ref, ast_copy_string(), ast_debug, ast_string_field_build, ast_string_field_set, ast_test_flag, ast_uri_decode(), sip_pvt::flags, get_header(), get_in_brackets(), get_transport(), sip_pvt::owner, pbx_builtin_setvar_helper(), remove_uri_parameters(), s, set_socket_transport(), SIP_PROMISCREDIR, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, SIPBUFSIZE, sip_pvt::socket, strcasestr(), and sip_socket::tcptls_session.
Referenced by handle_response().
17646 { 17647 char tmp[SIPBUFSIZE]; 17648 char *s, *e, *t, *trans; 17649 char *domain; 17650 enum sip_transport transport = SIP_TRANSPORT_UDP; 17651 17652 ast_copy_string(tmp, get_header(req, "Contact"), sizeof(tmp)); 17653 if ((t = strchr(tmp, ','))) 17654 *t = '\0'; 17655 17656 s = get_in_brackets(tmp); 17657 if ((trans = strcasestr(s, ";transport="))) do { 17658 trans += 11; 17659 17660 if ((e = strchr(trans, ';'))) 17661 *e = '\0'; 17662 17663 if (!strncasecmp(trans, "tcp", 3)) 17664 transport = SIP_TRANSPORT_TCP; 17665 else if (!strncasecmp(trans, "tls", 3)) 17666 transport = SIP_TRANSPORT_TLS; 17667 else { 17668 if (strncasecmp(trans, "udp", 3)) 17669 ast_debug(1, "received contact with an invalid transport, '%s'\n", s); 17670 /* This will assume UDP for all unknown transports */ 17671 transport = SIP_TRANSPORT_UDP; 17672 } 17673 } while(0); 17674 s = remove_uri_parameters(s); 17675 17676 if (p->socket.tcptls_session) { 17677 ao2_ref(p->socket.tcptls_session, -1); 17678 p->socket.tcptls_session = NULL; 17679 } 17680 17681 set_socket_transport(&p->socket, transport); 17682 17683 if (ast_test_flag(&p->flags[0], SIP_PROMISCREDIR)) { 17684 char *host = NULL; 17685 if (!strncasecmp(s, "sip:", 4)) 17686 s += 4; 17687 else if (!strncasecmp(s, "sips:", 5)) 17688 s += 5; 17689 e = strchr(s, '/'); 17690 if (e) 17691 *e = '\0'; 17692 if ((host = strchr(s, '@'))) { 17693 *host++ = '\0'; 17694 ast_debug(2, "Found promiscuous redirection to 'SIP/%s::::%s@%s'\n", s, get_transport(transport), host); 17695 if (p->owner) 17696 ast_string_field_build(p->owner, call_forward, "SIP/%s::::%s@%s", s, get_transport(transport), host); 17697 } else { 17698 ast_debug(2, "Found promiscuous redirection to 'SIP/::::%s@%s'\n", get_transport(transport), s); 17699 if (p->owner) 17700 ast_string_field_build(p->owner, call_forward, "SIP/::::%s@%s", get_transport(transport), s); 17701 } 17702 } else { 17703 e = strchr(tmp, '@'); 17704 if (e) { 17705 *e++ = '\0'; 17706 domain = e; 17707 } else { 17708 /* No username part */ 17709 domain = tmp; 17710 } 17711 e = strchr(tmp, '/'); /* WHEN do we hae a forward slash in the URI? */ 17712 if (e) 17713 *e = '\0'; 17714 17715 if (!strncasecmp(s, "sip:", 4)) 17716 s += 4; 17717 else if (!strncasecmp(s, "sips:", 5)) 17718 s += 5; 17719 e = strchr(s, ';'); /* And username ; parameters? */ 17720 if (e) 17721 *e = '\0'; 17722 ast_uri_decode(s); 17723 ast_debug(2, "Received 302 Redirect to extension '%s' (domain %s)\n", s, domain); 17724 if (p->owner) { 17725 pbx_builtin_setvar_helper(p->owner, "SIPDOMAIN", domain); 17726 ast_string_field_set(p->owner, call_forward, s); 17727 } 17728 } 17729 }
| static int parse_ok_contact | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
Save contact header for 200 OK on INVITE.
Definition at line 12310 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, get_header(), get_in_brackets(), SIPBUFSIZE, and TRUE.
Referenced by handle_request_invite(), handle_request_subscribe(), and handle_response_invite().
12311 { 12312 char contact[SIPBUFSIZE]; 12313 char *c; 12314 12315 /* Look for brackets */ 12316 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 12317 c = get_in_brackets(contact); 12318 12319 /* Save full contact to call pvt for later bye or re-invite */ 12320 ast_string_field_set(pvt, fullcontact, c); 12321 12322 /* Save URI for later ACKs, BYE or RE-invites */ 12323 ast_string_field_set(pvt, okcontacturi, c); 12324 12325 /* We should return false for URI:s we can't handle, 12326 like tel:, mailto:,ldap: etc */ 12327 return TRUE; 12328 }
| static enum parse_register_result parse_register_contact | ( | struct sip_pvt * | pvt, | |
| struct sip_peer * | p, | |||
| struct sip_request * | req | |||
| ) | [static] |
Parse contact header and save registration (peer registration).
Definition at line 12395 of file chan_sip.c.
References sip_peer::addr, ao2_t_link, ao2_t_unlink, ast_apply_ha(), ast_copy_string(), ast_db_put(), ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_sched_add(), AST_SCHED_DEL_UNREF, ast_sched_when(), AST_SENSE_ALLOW, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, ast_verbose, sip_peer::contactha, copy_socket_data(), sip_peer::default_outbound_transport, destroy_association(), EVENT_FLAG_SYSTEM, sip_peer::expire, expire_register(), sip_pvt::expiry, FALSE, sip_peer::flags, sip_peer::fullcontact, get_header(), get_in_brackets(), get_transport_str2enum(), hp, inaddrcmp(), sip_peer::is_realtime, sip_peer::lastms, LOG_NOTICE, LOG_WARNING, manager_event, sip_peer::name, PARSE_REGISTER_DENIED, PARSE_REGISTER_FAILED, PARSE_REGISTER_QUERY, PARSE_REGISTER_UPDATE, parse_uri(), port_str2int(), sip_peer::portinuri, sip_pvt::recv, ref_peer(), register_peer_exten(), sip_peer::rt_fromcontact, s, set_socket_transport(), SIP_NAT_ROUTE, SIP_PAGE2_RTCACHEFRIENDS, sip_poke_peer(), SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, SIPBUFSIZE, sip_pvt::sipoptions, sip_peer::sipoptions, sip_peer::socket, sip_request::socket, sip_pvt::socket, STANDARD_SIP_PORT, STANDARD_TLS_PORT, strcasestr(), strsep(), sip_peer::transports, TRUE, sip_socket::type, unref_peer(), sip_peer::useragent, sip_peer::username, VERBOSE_PREFIX_3, and VERBOSITY_ATLEAST.
Referenced by register_verify().
12396 { 12397 char contact[SIPBUFSIZE]; 12398 char data[SIPBUFSIZE]; 12399 const char *expires = get_header(req, "Expires"); 12400 int expire = atoi(expires); 12401 char *curi, *host, *pt, *transport; 12402 int port; 12403 int transport_type; 12404 const char *useragent; 12405 struct hostent *hp; 12406 struct ast_hostent ahp; 12407 struct sockaddr_in oldsin, testsin; 12408 12409 12410 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 12411 12412 if (ast_strlen_zero(expires)) { /* No expires header, try look in Contact: */ 12413 char *s = strcasestr(contact, ";expires="); 12414 if (s) { 12415 expires = strsep(&s, ";"); /* trim ; and beyond */ 12416 if (sscanf(expires + 9, "%30d", &expire) != 1) 12417 expire = default_expiry; 12418 } else { 12419 /* Nothing has been specified */ 12420 expire = default_expiry; 12421 } 12422 } 12423 12424 copy_socket_data(&pvt->socket, &req->socket); 12425 12426 /* Look for brackets */ 12427 curi = contact; 12428 if (strchr(contact, '<') == NULL) /* No <, check for ; and strip it */ 12429 strsep(&curi, ";"); /* This is Header options, not URI options */ 12430 curi = get_in_brackets(contact); 12431 12432 /* if they did not specify Contact: or Expires:, they are querying 12433 what we currently have stored as their contact address, so return 12434 it 12435 */ 12436 if (ast_strlen_zero(curi) && ast_strlen_zero(expires)) { 12437 /* If we have an active registration, tell them when the registration is going to expire */ 12438 if (peer->expire > -1 && !ast_strlen_zero(peer->fullcontact)) 12439 pvt->expiry = ast_sched_when(sched, peer->expire); 12440 return PARSE_REGISTER_QUERY; 12441 } else if (!strcasecmp(curi, "*") || !expire) { /* Unregister this peer */ 12442 /* This means remove all registrations and return OK */ 12443 memset(&peer->addr, 0, sizeof(peer->addr)); 12444 set_socket_transport(&peer->socket, peer->default_outbound_transport); 12445 12446 AST_SCHED_DEL_UNREF(sched, peer->expire, 12447 unref_peer(peer, "remove register expire ref")); 12448 12449 destroy_association(peer); 12450 12451 register_peer_exten(peer, FALSE); /* Remove extension from regexten= setting in sip.conf */ 12452 ast_string_field_set(peer, fullcontact, ""); 12453 ast_string_field_set(peer, useragent, ""); 12454 peer->sipoptions = 0; 12455 peer->lastms = 0; 12456 peer->portinuri = 0; 12457 pvt->expiry = 0; 12458 12459 ast_verb(3, "Unregistered SIP '%s'\n", peer->name); 12460 12461 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\n", peer->name); 12462 return PARSE_REGISTER_UPDATE; 12463 } 12464 12465 /* Store whatever we got as a contact from the client */ 12466 ast_string_field_set(peer, fullcontact, curi); 12467 12468 /* For the 200 OK, we should use the received contact */ 12469 ast_string_field_build(pvt, our_contact, "<%s>", curi); 12470 12471 /* Make sure it's a SIP URL */ 12472 if (parse_uri(curi, "sip:,sips:", &curi, NULL, &host, &pt, NULL, &transport)) { 12473 ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:) trying to use anyway\n"); 12474 } 12475 12476 /* If we have a port number in the given URI, make sure we do remember to not check for NAPTR/SRV records. 12477 The domain part is actually a host. */ 12478 peer->portinuri = !ast_strlen_zero(pt) ? TRUE : FALSE; 12479 12480 /* handle the transport type specified in Contact header. */ 12481 if ((transport_type = get_transport_str2enum(transport))) { 12482 /* if the port is not specified but the transport is, make sure to set the 12483 * default port to match the specified transport. This may or may not be the 12484 * same transport used by the pvt struct for the Register dialog. */ 12485 12486 port = port_str2int(pt, (transport_type == SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT); 12487 } else { 12488 port = port_str2int(pt, STANDARD_SIP_PORT); 12489 transport_type = pvt->socket.type; 12490 } 12491 12492 /* if the peer's socket type is different than the Registration 12493 * transport type, change it. If it got this far, it is a 12494 * supported type, but check just in case */ 12495 if ((peer->socket.type != transport_type) && (peer->transports & transport_type)) { 12496 set_socket_transport(&peer->socket, transport_type); 12497 } 12498 12499 oldsin = peer->addr; 12500 12501 /* If we were already linked into the peers_by_ip container unlink ourselves so nobody can find us */ 12502 if (peer->addr.sin_addr.s_addr) { 12503 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table"); 12504 } 12505 12506 if (!ast_test_flag(&peer->flags[0], SIP_NAT_ROUTE)) { 12507 /* use the data provided in the Contact header for call routing */ 12508 ast_debug(1, "Store REGISTER's Contact header for call routing.\n"); 12509 /* XXX This could block for a long time XXX */ 12510 /*! \todo Check NAPTR/SRV if we have not got a port in the URI */ 12511 hp = ast_gethostbyname(host, &ahp); 12512 if (!hp) { 12513 ast_log(LOG_WARNING, "Invalid host '%s'\n", host); 12514 ast_string_field_set(peer, fullcontact, ""); 12515 ast_string_field_set(pvt, our_contact, ""); 12516 return PARSE_REGISTER_FAILED; 12517 } 12518 peer->addr.sin_family = AF_INET; 12519 memcpy(&peer->addr.sin_addr, hp->h_addr, sizeof(peer->addr.sin_addr)); 12520 peer->addr.sin_port = htons(port); 12521 } else { 12522 /* Don't trust the contact field. Just use what they came to us 12523 with */ 12524 ast_debug(1, "Store REGISTER's src-IP:port for call routing.\n"); 12525 peer->addr = pvt->recv; 12526 } 12527 12528 /* Check that they're allowed to register at this IP */ 12529 memcpy(&testsin.sin_addr, &peer->addr.sin_addr, sizeof(testsin.sin_addr)); 12530 if (ast_apply_ha(global_contact_ha, &testsin) != AST_SENSE_ALLOW || 12531 ast_apply_ha(peer->contactha, &testsin) != AST_SENSE_ALLOW) { 12532 ast_log(LOG_WARNING, "Host '%s' disallowed by contact ACL (violating IP %s)\n", host, ast_inet_ntoa(testsin.sin_addr)); 12533 ast_string_field_set(peer, fullcontact, ""); 12534 ast_string_field_set(pvt, our_contact, ""); 12535 return PARSE_REGISTER_DENIED; 12536 } 12537 12538 /* if the Contact header information copied into peer->addr matches the 12539 * received address, and the transport types are the same, then copy socket 12540 * data into the peer struct */ 12541 if ((peer->socket.type == pvt->socket.type) && 12542 (peer->addr.sin_addr.s_addr == pvt->recv.sin_addr.s_addr) && 12543 (peer->addr.sin_port == pvt->recv.sin_port)){ 12544 12545 copy_socket_data(&peer->socket, &pvt->socket); 12546 } 12547 12548 /* Now that our address has been updated put ourselves back into the container for lookups */ 12549 ao2_t_link(peers_by_ip, peer, "ao2_link into peers_by_ip table"); 12550 12551 /* Save SIP options profile */ 12552 peer->sipoptions = pvt->sipoptions; 12553 12554 if (!ast_strlen_zero(curi) && ast_strlen_zero(peer->username)) 12555 ast_string_field_set(peer, username, curi); 12556 12557 AST_SCHED_DEL_UNREF(sched, peer->expire, 12558 unref_peer(peer, "remove register expire ref")); 12559 12560 if (expire > max_expiry) 12561 expire = max_expiry; 12562 if (expire < min_expiry) 12563 expire = min_expiry; 12564 if (peer->is_realtime && !ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 12565 peer->expire = -1; 12566 } else { 12567 peer->expire = ast_sched_add(sched, (expire + 10) * 1000, expire_register, 12568 ref_peer(peer, "add registration ref")); 12569 if (peer->expire == -1) { 12570 unref_peer(peer, "remote registration ref"); 12571 } 12572 } 12573 pvt->expiry = expire; 12574 snprintf(data, sizeof(data), "%s:%d:%d:%s:%s", ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port), expire, peer->username, peer->fullcontact); 12575 /* Saving TCP connections is useless, we won't be able to reconnect 12576 XXX WHY???? XXX 12577 \todo Fix this immediately. 12578 */ 12579 if (!peer->rt_fromcontact && (peer->socket.type & SIP_TRANSPORT_UDP)) 12580 ast_db_put("SIP/Registry", peer->name, data); 12581 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\nPort: %d\r\n", peer->name, ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port)); 12582 12583 /* Is this a new IP address for us? */ 12584 if (VERBOSITY_ATLEAST(2) && inaddrcmp(&peer->addr, &oldsin)) { 12585 ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s port %d\n", peer->name, ast_inet_ntoa(peer->addr.sin_addr), ntohs(peer->addr.sin_port)); 12586 } 12587 sip_poke_peer(peer, 0); 12588 register_peer_exten(peer, 1); 12589 12590 /* Save User agent */ 12591 useragent = get_header(req, "User-Agent"); 12592 if (strcasecmp(useragent, peer->useragent)) { 12593 ast_string_field_set(peer, useragent, useragent); 12594 ast_verb(4, "Saved useragent \"%s\" for peer %s\n", peer->useragent, peer->name); 12595 } 12596 return PARSE_REGISTER_UPDATE; 12597 }
| static int parse_request | ( | struct sip_request * | req | ) | [static] |
Parse a SIP message.
Definition at line 7895 of file chan_sip.c.
References ast_debug, ast_log(), ast_str_strlen(), ast_strlen_zero(), sip_request::data, determine_firstline_parts(), sip_request::header, sip_request::headers, sip_request::line, sip_request::lines, LOG_WARNING, SIP_MAX_HEADERS, and SIP_MAX_LINES.
Referenced by _sip_tcp_helper_thread(), handle_request_do(), initialize_initreq(), and parse_copy().
07896 { 07897 char *c = req->data->str; 07898 ptrdiff_t *dst = req->header; 07899 int i = 0, lim = SIP_MAX_HEADERS - 1; 07900 unsigned int skipping_headers = 0; 07901 ptrdiff_t current_header_offset = 0; 07902 char *previous_header = ""; 07903 07904 req->header[0] = 0; 07905 req->headers = -1; /* mark that we are working on the header */ 07906 for (; *c; c++) { 07907 if (*c == '\r') { /* remove \r */ 07908 *c = '\0'; 07909 } else if (*c == '\n') { /* end of this line */ 07910 *c = '\0'; 07911 current_header_offset = (c + 1) - req->data->str; 07912 previous_header = req->data->str + dst[i]; 07913 if (skipping_headers) { 07914 /* check to see if this line is blank; if so, turn off 07915 the skipping flag, so the next line will be processed 07916 as a body line */ 07917 if (ast_strlen_zero(previous_header)) { 07918 skipping_headers = 0; 07919 } 07920 dst[i] = current_header_offset; /* record start of next line */ 07921 continue; 07922 } 07923 if (sipdebug) { 07924 ast_debug(4, "%7s %2d [%3d]: %s\n", 07925 req->headers < 0 ? "Header" : "Body", 07926 i, (int) strlen(previous_header), previous_header); 07927 } 07928 if (ast_strlen_zero(previous_header) && req->headers < 0) { 07929 req->headers = i; /* record number of header lines */ 07930 dst = req->line; /* start working on the body */ 07931 i = 0; 07932 lim = SIP_MAX_LINES - 1; 07933 } else { /* move to next line, check for overflows */ 07934 if (i++ == lim) { 07935 /* if we're processing headers, then skip any remaining 07936 headers and move on to processing the body, otherwise 07937 we're done */ 07938 if (req->headers != -1) { 07939 break; 07940 } else { 07941 req->headers = i; 07942 dst = req->line; 07943 i = 0; 07944 lim = SIP_MAX_LINES - 1; 07945 skipping_headers = 1; 07946 } 07947 } 07948 } 07949 dst[i] = current_header_offset; /* record start of next line */ 07950 } 07951 } 07952 07953 /* Check for last header or body line without CRLF. The RFC for SDP requires CRLF, 07954 but since some devices send without, we'll be generous in what we accept. However, 07955 if we've already reached the maximum number of lines for portion of the message 07956 we were parsing, we can't accept any more, so just ignore it. 07957 */ 07958 previous_header = req->data->str + dst[i]; 07959 if ((i < lim) && !ast_strlen_zero(previous_header)) { 07960 if (sipdebug) { 07961 ast_debug(4, "%7s %2d [%3d]: %s\n", 07962 req->headers < 0 ? "Header" : "Body", 07963 i, (int) strlen(previous_header), previous_header ); 07964 } 07965 i++; 07966 } 07967 07968 /* update count of header or body lines */ 07969 if (req->headers >= 0) { /* we are in the body */ 07970 req->lines = i; 07971 } else { /* no body */ 07972 req->headers = i; 07973 req->lines = 0; 07974 /* req->data->used will be a NULL byte */ 07975 req->line[0] = ast_str_strlen(req->data); 07976 } 07977 07978 if (*c) { 07979 ast_log(LOG_WARNING, "Too many lines, skipping <%s>\n", c); 07980 } 07981 07982 /* Split up the first line parts */ 07983 return determine_firstline_parts(req); 07984 }
| int parse_session_expires | ( | const char * | p_hdrval, | |
| int *const | p_interval, | |||
| enum st_refresher *const | p_ref | |||
| ) | [static] |
Session-Timers: Function for parsing Session-Expires header.
Definition at line 22918 of file chan_sip.c.
References ast_debug, ast_log(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), LOG_WARNING, SESSION_TIMER_REFRESHER_AUTO, SESSION_TIMER_REFRESHER_UAC, SESSION_TIMER_REFRESHER_UAS, and strsep().
Referenced by handle_request_invite(), and handle_response_invite().
22919 { 22920 char *p_token; 22921 int ref_idx; 22922 char *p_se_hdr; 22923 22924 if (ast_strlen_zero(p_hdrval)) { 22925 ast_log(LOG_WARNING, "Null Session-Expires header\n"); 22926 return -1; 22927 } 22928 22929 *p_ref = SESSION_TIMER_REFRESHER_AUTO; 22930 *p_interval = 0; 22931 22932 p_se_hdr = ast_strdupa(p_hdrval); 22933 p_se_hdr = ast_skip_blanks(p_se_hdr); 22934 22935 while ((p_token = strsep(&p_se_hdr, ";"))) { 22936 p_token = ast_skip_blanks(p_token); 22937 if (!sscanf(p_token, "%30d", p_interval)) { 22938 ast_log(LOG_WARNING, "Parsing of Session-Expires failed\n"); 22939 return -1; 22940 } 22941 22942 ast_debug(2, "Session-Expires: %d\n", *p_interval); 22943 22944 if (!p_se_hdr) 22945 continue; 22946 22947 p_se_hdr = ast_skip_blanks(p_se_hdr); 22948 ref_idx = strlen("refresher="); 22949 if (!strncasecmp(p_se_hdr, "refresher=", ref_idx)) { 22950 p_se_hdr += ref_idx; 22951 p_se_hdr = ast_skip_blanks(p_se_hdr); 22952 22953 if (!strncasecmp(p_se_hdr, "uac", strlen("uac"))) { 22954 *p_ref = SESSION_TIMER_REFRESHER_UAC; 22955 ast_debug(2, "Refresher: UAC\n"); 22956 } else if (!strncasecmp(p_se_hdr, "uas", strlen("uas"))) { 22957 *p_ref = SESSION_TIMER_REFRESHER_UAS; 22958 ast_debug(2, "Refresher: UAS\n"); 22959 } else { 22960 ast_log(LOG_WARNING, "Invalid refresher value %s\n", p_se_hdr); 22961 return -1; 22962 } 22963 break; 22964 } 22965 } 22966 return 0; 22967 }
| static unsigned int parse_sip_options | ( | struct sip_pvt * | pvt, | |
| const char * | supported | |||
| ) | [static] |
Parse supported header in incoming packet.
Definition at line 3406 of file chan_sip.c.
References ARRAY_LEN, ast_debug, ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), FALSE, cfsip_options::id, SIP_OPT_UNKNOWN, sip_options, sip_pvt::sipoptions, text, and TRUE.
Referenced by handle_request_invite().
03407 { 03408 char *next, *sep; 03409 char *temp; 03410 unsigned int profile = 0; 03411 int i, found; 03412 03413 if (ast_strlen_zero(supported) ) 03414 return 0; 03415 temp = ast_strdupa(supported); 03416 03417 if (sipdebug) 03418 ast_debug(3, "Begin: parsing SIP \"Supported: %s\"\n", supported); 03419 03420 for (next = temp; next; next = sep) { 03421 found = FALSE; 03422 if ( (sep = strchr(next, ',')) != NULL) 03423 *sep++ = '\0'; 03424 next = ast_skip_blanks(next); 03425 if (sipdebug) 03426 ast_debug(3, "Found SIP option: -%s-\n", next); 03427 for (i = 0; i < ARRAY_LEN(sip_options); i++) { 03428 if (!strcasecmp(next, sip_options[i].text)) { 03429 profile |= sip_options[i].id; 03430 found = TRUE; 03431 if (sipdebug) 03432 ast_debug(3, "Matched SIP option: %s\n", next); 03433 break; 03434 } 03435 } 03436 03437 /* This function is used to parse both Suported: and Require: headers. 03438 Let the caller of this function know that an unknown option tag was 03439 encountered, so that if the UAC requires it then the request can be 03440 rejected with a 420 response. */ 03441 if (!found) 03442 profile |= SIP_OPT_UNKNOWN; 03443 03444 if (!found && sipdebug) { 03445 if (!strncasecmp(next, "x-", 2)) 03446 ast_debug(3, "Found private SIP option, not supported: %s\n", next); 03447 else 03448 ast_debug(3, "Found no match for SIP option: %s (Please file bug report!)\n", next); 03449 } 03450 } 03451 03452 if (pvt) 03453 pvt->sipoptions = profile; 03454 return profile; 03455 }
| static int parse_uri | ( | char * | uri, | |
| const char * | scheme, | |||
| char ** | ret_name, | |||
| char ** | pass, | |||
| char ** | domain, | |||
| char ** | port, | |||
| char ** | options, | |||
| char ** | transport | |||
| ) | [static] |
* parses a URI in its components.
* general form we are expecting is sip[s]:username[:password][;parameter]@host[:port][;...] *
Definition at line 4453 of file chan_sip.c.
References ast_debug, ast_strdupa, ast_strlen_zero(), name, and strsep().
Referenced by __set_address_from_contact(), check_user_full(), and parse_register_contact().
04455 { 04456 char *name = NULL; 04457 int error = 0; 04458 04459 /* init field as required */ 04460 if (pass) 04461 *pass = ""; 04462 if (port) 04463 *port = ""; 04464 if (scheme) { 04465 int l; 04466 char *scheme2 = ast_strdupa(scheme); 04467 char *cur = strsep(&scheme2, ","); 04468 for (; !ast_strlen_zero(cur); cur = strsep(&scheme2, ",")) { 04469 l = strlen(cur); 04470 if (!strncasecmp(uri, cur, l)) { 04471 uri += l; 04472 break; 04473 } 04474 } 04475 if (ast_strlen_zero(cur)) { 04476 ast_debug(1, "No supported scheme found in '%s' using the scheme[s] %s\n", uri, scheme); 04477 error = -1; 04478 } 04479 } 04480 if (transport) { 04481 char *t, *type = ""; 04482 *transport = ""; 04483 if ((t = strstr(uri, "transport="))) { 04484 strsep(&t, "="); 04485 if ((type = strsep(&t, ";"))) { 04486 *transport = type; 04487 } 04488 } 04489 } 04490 04491 if (!domain) { 04492 /* if we don't want to split around domain, keep everything as a name, 04493 * so we need to do nothing here, except remember why. 04494 */ 04495 } else { 04496 /* store the result in a temp. variable to avoid it being 04497 * overwritten if arguments point to the same place. 04498 */ 04499 char *c, *dom = ""; 04500 04501 if ((c = strchr(uri, '@')) == NULL) { 04502 /* domain-only URI, according to the SIP RFC. */ 04503 dom = uri; 04504 name = ""; 04505 } else { 04506 *c++ = '\0'; 04507 dom = c; 04508 name = uri; 04509 } 04510 04511 /* Remove options in domain and name */ 04512 dom = strsep(&dom, ";"); 04513 name = strsep(&name, ";"); 04514 04515 if (port && (c = strchr(dom, ':'))) { /* Remove :port */ 04516 *c++ = '\0'; 04517 *port = c; 04518 } 04519 if (pass && (c = strchr(name, ':'))) { /* user:password */ 04520 *c++ = '\0'; 04521 *pass = c; 04522 } 04523 *domain = dom; 04524 } 04525 if (ret_name) /* same as for domain, store the result only at the end */ 04526 *ret_name = name; 04527 if (options) 04528 *options = uri ? uri : ""; 04529 04530 return error; 04531 }
| static int peer_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 2037 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, and sip_peer::name.
Referenced by load_module().
02038 { 02039 struct sip_peer *peer = obj, *peer2 = arg; 02040 02041 return !strcasecmp(peer->name, peer2->name) ? CMP_MATCH | CMP_STOP : 0; 02042 }
| static int peer_dump_func | ( | void * | userobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 15057 of file chan_sip.c.
References ao2_t_ref, ast_cli(), and sip_peer::name.
Referenced by sip_show_objects().
15058 { 15059 struct sip_peer *peer = userobj; 15060 int refc = ao2_t_ref(userobj, 0, ""); 15061 int *fd = arg; 15062 15063 ast_cli(*fd, "name: %s\ntype: peer\nobjflags: %d\nrefcount: %d\n\n", 15064 peer->name, 0, refc); 15065 return 0; 15066 }
| static int peer_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 2027 of file chan_sip.c.
References ast_str_case_hash(), and sip_peer::name.
Referenced by load_module().
02028 { 02029 const struct sip_peer *peer = obj; 02030 02031 return ast_str_case_hash(peer->name); 02032 }
| static int peer_ipcmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Match Peers by IP and Port number.
This function has two modes.
This callback will be used twice when doing peer matching. There is a first pass for full IP+port matching, and a second pass in case there is a match that meets the insecure=port criteria.
the peer's addr struct provides to fields combined to make a key: the sin_addr.s_addr and sin_port fields.
Definition at line 2075 of file chan_sip.c.
References sip_peer::addr, ast_test_flag, CMP_MATCH, CMP_STOP, sip_peer::flags, SIP_INSECURE_PORT, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, and sip_peer::transports.
Referenced by load_module().
02076 { 02077 struct sip_peer *peer = obj, *peer2 = arg; 02078 02079 if (peer->addr.sin_addr.s_addr != peer2->addr.sin_addr.s_addr) { 02080 /* IP doesn't match */ 02081 return 0; 02082 } 02083 02084 /* We matched the IP, check to see if we need to match by port as well. */ 02085 if ((peer->transports & peer2->transports) & (SIP_TRANSPORT_TLS | SIP_TRANSPORT_TCP)) { 02086 /* peer matching on port is not possible with TCP/TLS */ 02087 return CMP_MATCH | CMP_STOP; 02088 } else if (ast_test_flag(&peer2->flags[0], SIP_INSECURE_PORT)) { 02089 /* We are allowing match without port for peers configured that 02090 * way in this pass through the peers. */ 02091 return ast_test_flag(&peer->flags[0], SIP_INSECURE_PORT) ? 02092 (CMP_MATCH | CMP_STOP) : 0; 02093 } 02094 02095 /* Now only return a match if the port matches, as well. */ 02096 return peer->addr.sin_port == peer2->addr.sin_port ? (CMP_MATCH | CMP_STOP) : 0; 02097 }
| static int peer_iphash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 2047 of file chan_sip.c.
References sip_peer::addr.
Referenced by load_module().
02048 { 02049 const struct sip_peer *peer = obj; 02050 int ret1 = peer->addr.sin_addr.s_addr; 02051 if (ret1 < 0) 02052 ret1 = -ret1; 02053 02054 return ret1; 02055 }
| static int peer_is_marked | ( | void * | peerobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 3102 of file chan_sip.c.
References AST_SCHED_DEL, CMP_MATCH, sip_peer::pokeexpire, and sip_peer::the_mark.
Referenced by unlink_marked_peers_from_tables().
03103 { 03104 struct sip_peer *peer = peerobj; 03105 if (peer->the_mark && peer->pokeexpire != -1) { 03106 AST_SCHED_DEL(sched, peer->pokeexpire); 03107 } 03108 return peer->the_mark ? CMP_MATCH : 0; 03109 }
| static void peer_mailboxes_to_str | ( | struct ast_str ** | mailbox_str, | |
| struct sip_peer * | peer | |||
| ) | [static] |
list peer mailboxes to CLI
Definition at line 15533 of file chan_sip.c.
References AST_LIST_NEXT, AST_LIST_TRAVERSE, ast_str_append(), ast_strlen_zero(), sip_mailbox::context, sip_mailbox::mailbox, mailbox, sip_peer::mailboxes, and S_OR.
Referenced by _sip_show_peer(), function_sippeer(), show_channels_cb(), and sip_send_mwi_to_peer().
15534 { 15535 struct sip_mailbox *mailbox; 15536 15537 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 15538 ast_str_append(mailbox_str, 0, "%s%s%s%s", 15539 mailbox->mailbox, 15540 ast_strlen_zero(mailbox->context) ? "" : "@", 15541 S_OR(mailbox->context, ""), 15542 AST_LIST_NEXT(mailbox, entry) ? "," : ""); 15543 } 15544 }
| static int peer_markall_func | ( | void * | device, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 24545 of file chan_sip.c.
References sip_peer::the_mark.
Referenced by reload_config().
| static int peer_status | ( | struct sip_peer * | peer, | |
| char * | status, | |||
| int | statuslen | |||
| ) | [static] |
Definition at line 14635 of file chan_sip.c.
References ast_copy_string(), sip_peer::lastms, and sip_peer::maxms.
Referenced by _sip_show_peer(), _sip_show_peers(), and function_sippeer().
14636 { 14637 int res = 0; 14638 if (peer->maxms) { 14639 if (peer->lastms < 0) { 14640 ast_copy_string(status, "UNREACHABLE", statuslen); 14641 } else if (peer->lastms > peer->maxms) { 14642 snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms); 14643 res = 1; 14644 } else if (peer->lastms) { 14645 snprintf(status, statuslen, "OK (%d ms)", peer->lastms); 14646 res = 1; 14647 } else { 14648 ast_copy_string(status, "UNKNOWN", statuslen); 14649 } 14650 } else { 14651 ast_copy_string(status, "Unmonitored", statuslen); 14652 /* Checking if port is 0 */ 14653 res = -1; 14654 } 14655 return res; 14656 }
| int peercomparefunc | ( | const void * | a, | |
| const void * | b | |||
| ) |
Definition at line 14876 of file chan_sip.c.
Referenced by _sip_show_peers().
14877 { 14878 struct sip_peer **ap = (struct sip_peer **)a; 14879 struct sip_peer **bp = (struct sip_peer **)b; 14880 return strcmp((*ap)->name, (*bp)->name); 14881 }
| static int port_str2int | ( | const char * | pt, | |
| unsigned int | standard | |||
| ) | [static] |
converts ascii port to int representation. If no pt buffer is provided or the pt has errors when being converted to an int value, the port provided as the standard is used.
Definition at line 3326 of file chan_sip.c.
References ast_strlen_zero().
Referenced by __set_address_from_contact(), build_peer(), check_via(), create_addr(), parse_register_contact(), proxy_allocate(), and sip_register().
03327 { 03328 int port = standard; 03329 if (ast_strlen_zero(pt) || (sscanf(pt, "%30d", &port) != 1) || (port < 1) || (port > 65535)) { 03330 port = standard; 03331 } 03332 03333 return port; 03334 }
| static void print_codec_to_cli | ( | int | fd, | |
| struct ast_codec_pref * | pref | |||
| ) | [static] |
Print codec list from preference to CLI/manager.
Definition at line 15365 of file chan_sip.c.
References ast_cli(), ast_codec_pref_index(), ast_getformatname(), and ast_codec_pref::framing.
Referenced by _sip_show_peer(), sip_show_settings(), and sip_show_user().
15366 { 15367 int x, codec; 15368 15369 for(x = 0; x < 32 ; x++) { 15370 codec = ast_codec_pref_index(pref, x); 15371 if (!codec) 15372 break; 15373 ast_cli(fd, "%s", ast_getformatname(codec)); 15374 ast_cli(fd, ":%d", pref->framing[x]); 15375 if (x < 31 && ast_codec_pref_index(pref, x + 1)) 15376 ast_cli(fd, ","); 15377 } 15378 if (!x) 15379 ast_cli(fd, "none"); 15380 }
| static void print_group | ( | int | fd, | |
| ast_group_t | group, | |||
| int | crlf | |||
| ) | [static] |
Print call group and pickup group.
Definition at line 15107 of file chan_sip.c.
References ast_cli(), ast_print_group(), and buf.
Referenced by _sip_show_peer(), and sip_show_user().
15108 { 15109 char buf[256]; 15110 ast_cli(fd, crlf ? "%s\r\n" : "%s\n", ast_print_group(buf, sizeof(buf), group) ); 15111 }
| static void proc_422_rsp | ( | struct sip_pvt * | p, | |
| struct sip_request * | rsp | |||
| ) | [static] |
Handle 422 response to INVITE with session-timer requested.
Session-Timers: An INVITE originated by Asterisk that asks for session-timers support from the UAS can result into a 422 response. This is how a UAS or an intermediary proxy server tells Asterisk that the session refresh interval offered by Asterisk is too low for them. The proc_422_rsp() function handles a 422 response. It extracts the Min-SE header that comes back in 422 and sends a new INVITE accordingly.
Definition at line 22977 of file chan_sip.c.
References ast_log(), ast_strlen_zero(), get_header(), LOG_WARNING, parse_minse(), SIP_INVITE, sip_st_dlg::st_interval, sip_pvt::stimer, and transmit_invite().
Referenced by handle_response_invite().
22978 { 22979 int rtn; 22980 const char *p_hdrval; 22981 int minse; 22982 22983 p_hdrval = get_header(rsp, "Min-SE"); 22984 if (ast_strlen_zero(p_hdrval)) { 22985 ast_log(LOG_WARNING, "422 response without a Min-SE header %s\n", p_hdrval); 22986 return; 22987 } 22988 rtn = parse_minse(p_hdrval, &minse); 22989 if (rtn != 0) { 22990 ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval); 22991 return; 22992 } 22993 p->stimer->st_interval = minse; 22994 transmit_invite(p, SIP_INVITE, 1, 2); 22995 }
| static int proc_session_timer | ( | const void * | vp | ) | [static] |
Session-Timers: Process session refresh timeout event.
Definition at line 22817 of file chan_sip.c.
References ast_channel::_state, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, sip_pvt::callid, dialog_unref(), FALSE, LOG_ERROR, LOG_WARNING, sip_pvt::outgoing_call, sip_pvt::owner, sip_st_dlg::quit_flag, SESSION_TIMER_REFRESHER_UAC, SESSION_TIMER_REFRESHER_UAS, sip_pvt_lock, sip_pvt_unlock, sip_st_dlg::st_active, sip_st_dlg::st_expirys, sip_st_dlg::st_ref, sip_st_dlg::st_schedid, sip_pvt::stimer, stop_session_timer(), transmit_reinvite_with_sdp(), and TRUE.
Referenced by start_session_timer().
22818 { 22819 struct sip_pvt *p = (struct sip_pvt *) vp; 22820 int sendreinv = FALSE; 22821 int res = 0; 22822 22823 if (!p->stimer) { 22824 ast_log(LOG_WARNING, "Null stimer in proc_session_timer - %s\n", p->callid); 22825 goto return_unref; 22826 } 22827 22828 ast_debug(2, "Session timer expired: %d - %s\n", p->stimer->st_schedid, p->callid); 22829 22830 if (!p->owner) { 22831 goto return_unref; 22832 } 22833 22834 if ((p->stimer->st_active != TRUE) || (p->owner->_state != AST_STATE_UP)) { 22835 goto return_unref; 22836 } 22837 22838 switch (p->stimer->st_ref) { 22839 case SESSION_TIMER_REFRESHER_UAC: 22840 if (p->outgoing_call == TRUE) { 22841 sendreinv = TRUE; 22842 } 22843 break; 22844 case SESSION_TIMER_REFRESHER_UAS: 22845 if (p->outgoing_call != TRUE) { 22846 sendreinv = TRUE; 22847 } 22848 break; 22849 default: 22850 ast_log(LOG_ERROR, "Unknown session refresher %d\n", p->stimer->st_ref); 22851 goto return_unref; 22852 } 22853 22854 if (sendreinv == TRUE) { 22855 res = 1; 22856 transmit_reinvite_with_sdp(p, FALSE, TRUE); 22857 } else { 22858 p->stimer->st_expirys++; 22859 if (p->stimer->st_expirys >= 2) { 22860 if (p->stimer->quit_flag) { 22861 goto return_unref; 22862 } 22863 ast_log(LOG_WARNING, "Session-Timer expired - %s\n", p->callid); 22864 sip_pvt_lock(p); 22865 while (p->owner && ast_channel_trylock(p->owner)) { 22866 sip_pvt_unlock(p); 22867 usleep(1); 22868 if (p->stimer && p->stimer->quit_flag) { 22869 goto return_unref; 22870 } 22871 sip_pvt_lock(p); 22872 } 22873 22874 ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV); 22875 ast_channel_unlock(p->owner); 22876 sip_pvt_unlock(p); 22877 } 22878 } 22879 22880 return_unref: 22881 if (!res) { 22882 /* An error occurred. Stop session timer processing */ 22883 if (p->stimer) { 22884 p->stimer->st_schedid = -1; 22885 stop_session_timer(p); 22886 } 22887 22888 /* If we are not asking to be rescheduled, then we need to release our 22889 * reference to the dialog. */ 22890 dialog_unref(p, "removing session timer ref"); 22891 } 22892 22893 return res; 22894 }
| static void process_request_queue | ( | struct sip_pvt * | p, | |
| int * | recount, | |||
| int * | nounlock | |||
| ) | [static] |
Definition at line 22029 of file chan_sip.c.
References ast_free, AST_LIST_REMOVE_HEAD, ast_log(), sip_pvt::callid, handle_incoming(), LOG_DEBUG, option_debug, sip_pvt::recv, and sip_pvt::request_queue.
Referenced by handle_request_do(), and scheduler_process_request_queue().
22030 { 22031 struct sip_request *req; 22032 22033 while ((req = AST_LIST_REMOVE_HEAD(&p->request_queue, next))) { 22034 if (handle_incoming(p, req, &p->recv, recount, nounlock) == -1) { 22035 /* Request failed */ 22036 if (option_debug) { 22037 ast_log(LOG_DEBUG, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>"); 22038 } 22039 } 22040 ast_free(req); 22041 } 22042 }
| static int process_sdp | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | t38action | |||
| ) | [static] |
Process SIP SDP offer, select formats and activate RTP channels If offer is rejected, we will not change any properties of the call Return 0 on success, a negative value on errors. Must be called after find_sdp().
< RTP Audio host IP
< RTP video host IP
< RTP text host IP
< UDPTL host ip
< RTP Audio port number
< RTP Video port number
< RTP Text port number
< UDPTL Image port number
< media socket address
< video socket address
< image socket address
< text socket address
Definition at line 8179 of file chan_sip.c.
References ast_async_goto(), ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_codec_choose(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_exists_extension(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_T140RED, ast_getformatname_multiple(), ast_inet_ntoa(), ast_log(), ast_null_frame, ast_queue_control(), ast_queue_control_data(), ast_queue_frame(), ast_rtp_alloc_size(), AST_RTP_DTMF, ast_rtp_get_current_formats(), ast_rtp_get_peer(), ast_rtp_lookup_mime_multiple(), ast_rtp_new_init(), ast_rtp_pt_clear(), ast_rtp_pt_copy(), ast_rtp_set_m_type(), ast_rtp_set_peer(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_rtp_stop(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), ast_skip_blanks(), ast_strlen_zero(), ast_test_flag, ast_threadstorage_get(), ast_udptl_get_far_max_datagram(), ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), ast_udptl_set_peer(), ast_udptl_stop(), ast_verbose, buf, sip_pvt::callid, sip_pvt::capability, change_hold_state(), change_t38_state(), ast_channel::cid, ast_callerid::cid_num, ast_channel::context, sip_request::debug, ast_channel::exten, FALSE, sip_pvt::flags, get_sdp_iterate(), get_sdp_line(), ast_hostent::hp, hp, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, sip_pvt::lastinvite, sip_pvt::lastrtprx, sip_pvt::lastrtptx, LOG_DEBUG, LOG_ERROR, LOG_NOTICE, LOG_WARNING, ast_channel::macrocontext, sip_pvt::mohsuggest, ast_channel::name, ast_channel::nativeformats, sip_pvt::noncodeccapability, sip_pvt::notext, sip_pvt::novideo, offered_media::offered, sip_pvt::offered_media, option_debug, sip_pvt::owner, pbx_builtin_setvar_helper(), sip_pvt::peercapability, sip_pvt::prefs, process_sdp_a_audio(), process_sdp_a_image(), process_sdp_a_sendonly(), process_sdp_a_text(), process_sdp_a_video(), process_sdp_c(), process_sdp_o(), ast_channel::readformat, sip_pvt::red, sip_pvt::rtp, rtp_red_init(), S_OR, SDP_AUDIO, SDP_IMAGE, sip_request::sdp_start, SDP_T38_ACCEPT, SDP_T38_INITIATE, SDP_TEXT, SDP_VIDEO, sip_pvt::session_modify, sip_debug_test_pvt(), SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, SIP_NAT, SIP_PAGE2_CALL_ONHOLD, SIP_PAGE2_FAX_DETECT_T38, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_UDPTL_DESTINATION, SIPBUFSIZE, t38properties::state, sip_pvt::t38, T38_DISABLED, T38_ENABLED, T38_LOCAL_REINVITE, T38_PEER_REINVITE, offered_media::text, text, t38properties::their_parms, sip_pvt::trtp, TRUE, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_NONE, VERBOSE_PREFIX_2, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by handle_incoming(), handle_request_invite(), handle_response(), and handle_response_invite().
08180 { 08181 /* Iterators for SDP parsing */ 08182 int start = req->sdp_start; 08183 int next = start; 08184 int iterator = start; 08185 08186 /* Temporary vars for SDP parsing */ 08187 char type = '\0'; 08188 const char *value = NULL; 08189 const char *m = NULL; /* SDP media offer */ 08190 const char *nextm = NULL; 08191 int len = -1; 08192 08193 /* Host information */ 08194 struct ast_hostent sessionhp; 08195 struct ast_hostent audiohp; 08196 struct ast_hostent videohp; 08197 struct ast_hostent texthp; 08198 struct ast_hostent imagehp; 08199 struct hostent *hp = NULL; /*!< RTP Audio host IP */ 08200 struct hostent *vhp = NULL; /*!< RTP video host IP */ 08201 struct hostent *thp = NULL; /*!< RTP text host IP */ 08202 struct hostent *ihp = NULL; /*!< UDPTL host ip */ 08203 int portno = -1; /*!< RTP Audio port number */ 08204 int vportno = -1; /*!< RTP Video port number */ 08205 int tportno = -1; /*!< RTP Text port number */ 08206 int udptlportno = -1; /*!< UDPTL Image port number */ 08207 struct sockaddr_in sin = { 0, }; /*!< media socket address */ 08208 struct sockaddr_in vsin = { 0, }; /*!< video socket address */ 08209 struct sockaddr_in isin = { 0, }; /*!< image socket address */ 08210 struct sockaddr_in tsin = { 0, }; /*!< text socket address */ 08211 08212 /* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */ 08213 int peercapability = 0, peernoncodeccapability = 0; 08214 int vpeercapability = 0, vpeernoncodeccapability = 0; 08215 int tpeercapability = 0, tpeernoncodeccapability = 0; 08216 08217 struct ast_rtp *newaudiortp, *newvideortp, *newtextrtp; 08218 int newjointcapability; /* Negotiated capability */ 08219 int newpeercapability; 08220 int newnoncodeccapability; 08221 08222 const char *codecs; 08223 int codec; 08224 08225 /* Others */ 08226 int sendonly = -1; 08227 int vsendonly = -1; 08228 int numberofports; 08229 int numberofmediastreams = 0; 08230 int last_rtpmap_codec = 0; 08231 int red_data_pt[10]; /* For T.140 red */ 08232 int red_num_gen = 0; /* For T.140 red */ 08233 char red_fmtp[100] = "empty"; /* For T.140 red */ 08234 int debug = sip_debug_test_pvt(p); 08235 08236 /* START UNKNOWN */ 08237 char buf[SIPBUFSIZE]; 08238 /* END UNKNOWN */ 08239 08240 /* Initial check */ 08241 if (!p->rtp) { 08242 ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n"); 08243 return -1; 08244 } 08245 08246 /* Initialize the temporary RTP structures we use to evaluate the offer from the peer */ 08247 #ifdef LOW_MEMORY 08248 newaudiortp = ast_threadstorage_get(&ts_audio_rtp, ast_rtp_alloc_size()); 08249 #else 08250 newaudiortp = alloca(ast_rtp_alloc_size()); 08251 #endif 08252 memset(newaudiortp, 0, ast_rtp_alloc_size()); 08253 ast_rtp_new_init(newaudiortp); 08254 ast_rtp_pt_clear(newaudiortp); 08255 08256 #ifdef LOW_MEMORY 08257 newvideortp = ast_threadstorage_get(&ts_video_rtp, ast_rtp_alloc_size()); 08258 #else 08259 newvideortp = alloca(ast_rtp_alloc_size()); 08260 #endif 08261 memset(newvideortp, 0, ast_rtp_alloc_size()); 08262 ast_rtp_new_init(newvideortp); 08263 ast_rtp_pt_clear(newvideortp); 08264 08265 #ifdef LOW_MEMORY 08266 newtextrtp = ast_threadstorage_get(&ts_text_rtp, ast_rtp_alloc_size()); 08267 #else 08268 newtextrtp = alloca(ast_rtp_alloc_size()); 08269 #endif 08270 memset(newtextrtp, 0, ast_rtp_alloc_size()); 08271 ast_rtp_new_init(newtextrtp); 08272 ast_rtp_pt_clear(newtextrtp); 08273 08274 /* Update our last rtprx when we receive an SDP, too */ 08275 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 08276 08277 memset(p->offered_media, 0, sizeof(p->offered_media)); 08278 08279 08280 /* default: novideo and notext set */ 08281 p->novideo = TRUE; 08282 p->notext = TRUE; 08283 08284 if (p->vrtp) 08285 ast_rtp_pt_clear(newvideortp); /* Must be cleared in case no m=video line exists */ 08286 08287 if (p->trtp) 08288 ast_rtp_pt_clear(newtextrtp); /* Must be cleared in case no m=text line exists */ 08289 08290 /* Scan for the first media stream (m=) line to limit scanning of globals */ 08291 nextm = get_sdp_iterate(&next, req, "m"); 08292 if (ast_strlen_zero(nextm)) { 08293 ast_log(LOG_WARNING, "Insufficient information for SDP (m= not found)\n"); 08294 return -1; 08295 } 08296 08297 /* Scan session level SDP parameters (lines before first media stream) */ 08298 while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') { 08299 int processed = FALSE; 08300 switch (type) { 08301 case 'o': 08302 /* If we end up receiving SDP that doesn't actually modify the session we don't want to treat this as a fatal 08303 * error. We just want to ignore the SDP and let the rest of the packet be handled as normal. 08304 */ 08305 if (!process_sdp_o(value, p)) 08306 return (p->session_modify == FALSE) ? 0 : -1; 08307 break; 08308 case 'c': 08309 if (process_sdp_c(value, &sessionhp)) { 08310 processed = TRUE; 08311 hp = &sessionhp.hp; 08312 vhp = hp; 08313 thp = hp; 08314 ihp = hp; 08315 } 08316 break; 08317 case 'a': 08318 if (process_sdp_a_sendonly(value, &sendonly)) { 08319 processed = TRUE; 08320 vsendonly = sendonly; 08321 } 08322 else if (process_sdp_a_audio(value, p, newaudiortp, &last_rtpmap_codec)) 08323 processed = TRUE; 08324 else if (process_sdp_a_video(value, p, newvideortp, &last_rtpmap_codec)) 08325 processed = TRUE; 08326 else if (process_sdp_a_text(value, p, newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) 08327 processed = TRUE; 08328 else if (process_sdp_a_image(value, p)) 08329 processed = TRUE; 08330 break; 08331 } 08332 08333 if (option_debug > 2) 08334 ast_log(LOG_DEBUG, "Processing session-level SDP %c=%s... %s\n", type, value, (processed == TRUE)? "OK." : "UNSUPPORTED."); 08335 } 08336 08337 08338 08339 /* Scan media stream (m=) specific parameters loop */ 08340 while (!ast_strlen_zero(nextm)) { 08341 int audio = FALSE; 08342 int video = FALSE; 08343 int image = FALSE; 08344 int text = FALSE; 08345 int x; 08346 08347 numberofports = 1; 08348 len = -1; 08349 start = next; 08350 m = nextm; 08351 iterator = next; 08352 nextm = get_sdp_iterate(&next, req, "m"); 08353 08354 /* Search for audio media definition */ 08355 if ((sscanf(m, "audio %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08356 (sscanf(m, "audio %30u RTP/AVP %n", &x, &len) == 1 && len > 0)) { 08357 audio = TRUE; 08358 p->offered_media[SDP_AUDIO].offered = TRUE; 08359 numberofmediastreams++; 08360 portno = x; 08361 08362 /* Scan through the RTP payload types specified in a "m=" line: */ 08363 codecs = m + len; 08364 ast_copy_string(p->offered_media[SDP_AUDIO].text, codecs, sizeof(p->offered_media[SDP_AUDIO].text)); 08365 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 08366 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 08367 ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); 08368 return -1; 08369 } 08370 if (debug) 08371 ast_verbose("Found RTP audio format %d\n", codec); 08372 08373 ast_rtp_set_m_type(newaudiortp, codec); 08374 } 08375 /* Search for video media definition */ 08376 } else if ((sscanf(m, "video %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08377 (sscanf(m, "video %30u RTP/AVP %n", &x, &len) == 1 && len >= 0)) { 08378 video = TRUE; 08379 p->novideo = FALSE; 08380 p->offered_media[SDP_VIDEO].offered = TRUE; 08381 numberofmediastreams++; 08382 vportno = x; 08383 08384 /* Scan through the RTP payload types specified in a "m=" line: */ 08385 codecs = m + len; 08386 ast_copy_string(p->offered_media[SDP_VIDEO].text, codecs, sizeof(p->offered_media[SDP_VIDEO].text)); 08387 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 08388 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 08389 ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); 08390 return -1; 08391 } 08392 if (debug) 08393 ast_verbose("Found RTP video format %d\n", codec); 08394 ast_rtp_set_m_type(newvideortp, codec); 08395 } 08396 /* Search for text media definition */ 08397 } else if ((sscanf(m, "text %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08398 (sscanf(m, "text %30u RTP/AVP %n", &x, &len) == 1 && len > 0)) { 08399 text = TRUE; 08400 p->notext = FALSE; 08401 p->offered_media[SDP_TEXT].offered = TRUE; 08402 numberofmediastreams++; 08403 tportno = x; 08404 08405 /* Scan through the RTP payload types specified in a "m=" line: */ 08406 codecs = m + len; 08407 ast_copy_string(p->offered_media[SDP_TEXT].text, codecs, sizeof(p->offered_media[SDP_TEXT].text)); 08408 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 08409 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 08410 ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs); 08411 return -1; 08412 } 08413 if (debug) 08414 ast_verbose("Found RTP text format %d\n", codec); 08415 ast_rtp_set_m_type(newtextrtp, codec); 08416 } 08417 /* Search for image media definition */ 08418 } else if (p->udptl && ((sscanf(m, "image %30u udptl t38%n", &x, &len) == 1 && len > 0) || 08419 (sscanf(m, "image %30u UDPTL t38%n", &x, &len) == 1 && len > 0) )) { 08420 image = TRUE; 08421 if (debug) 08422 ast_verbose("Got T.38 offer in SDP in dialog %s\n", p->callid); 08423 p->offered_media[SDP_IMAGE].offered = TRUE; 08424 udptlportno = x; 08425 numberofmediastreams++; 08426 08427 if (p->t38.state != T38_ENABLED) { 08428 memset(&p->t38.their_parms, 0, sizeof(p->t38.their_parms)); 08429 08430 /* default EC to none, the remote end should 08431 * respond with the EC they want to use */ 08432 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 08433 } 08434 } else { 08435 ast_log(LOG_WARNING, "Unsupported SDP media type in offer: %s\n", m); 08436 continue; 08437 } 08438 08439 /* Check for number of ports */ 08440 if (numberofports > 1) 08441 ast_log(LOG_WARNING, "SDP offered %d ports for media, not supported by Asterisk. Will try anyway...\n", numberofports); 08442 08443 08444 08445 /* Media stream specific parameters */ 08446 while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') { 08447 int processed = FALSE; 08448 08449 switch (type) { 08450 case 'c': 08451 if (audio) { 08452 if (process_sdp_c(value, &audiohp)) { 08453 processed = TRUE; 08454 hp = &audiohp.hp; 08455 } 08456 } else if (video) { 08457 if (process_sdp_c(value, &videohp)) { 08458 processed = TRUE; 08459 vhp = &videohp.hp; 08460 } 08461 } else if (text) { 08462 if (process_sdp_c(value, &texthp)) { 08463 processed = TRUE; 08464 thp = &texthp.hp; 08465 } 08466 } else if (image) { 08467 if (process_sdp_c(value, &imagehp)) { 08468 processed = TRUE; 08469 ihp = &imagehp.hp; 08470 } 08471 } 08472 break; 08473 case 'a': 08474 /* Audio specific scanning */ 08475 if (audio) { 08476 if (process_sdp_a_sendonly(value, &sendonly)) 08477 processed = TRUE; 08478 else if (process_sdp_a_audio(value, p, newaudiortp, &last_rtpmap_codec)) 08479 processed = TRUE; 08480 } 08481 /* Video specific scanning */ 08482 else if (video) { 08483 if (process_sdp_a_sendonly(value, &vsendonly)) 08484 processed = TRUE; 08485 else if (process_sdp_a_video(value, p, newvideortp, &last_rtpmap_codec)) 08486 processed = TRUE; 08487 } 08488 /* Text (T.140) specific scanning */ 08489 else if (text) { 08490 if (process_sdp_a_text(value, p, newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) 08491 processed = TRUE; 08492 } 08493 /* Image (T.38 FAX) specific scanning */ 08494 else if (image) { 08495 if (process_sdp_a_image(value, p)) 08496 processed = TRUE; 08497 } 08498 break; 08499 } 08500 08501 if (option_debug > 2) 08502 ast_log(LOG_DEBUG, "Processing media-level (%s) SDP %c=%s... %s\n", 08503 (audio == TRUE)? "audio" : (video == TRUE)? "video" : "image", 08504 type, value, 08505 (processed == TRUE)? "OK." : "UNSUPPORTED."); 08506 } 08507 } 08508 08509 08510 /* Sanity checks */ 08511 if (!hp && !vhp && !thp && !ihp) { 08512 ast_log(LOG_WARNING, "Insufficient information in SDP (c=)...\n"); 08513 return -1; 08514 } 08515 08516 if (portno == -1 && vportno == -1 && udptlportno == -1 && tportno == -1) 08517 /* No acceptable offer found in SDP - we have no ports */ 08518 /* Do not change RTP or VRTP if this is a re-invite */ 08519 return -2; 08520 08521 if (numberofmediastreams > 3) 08522 /* We have too many fax, audio and/or video and/or text media streams, fail this offer */ 08523 return -3; 08524 08525 if (udptlportno == -1) { 08526 change_t38_state(p, T38_DISABLED); 08527 } 08528 08529 08530 /* Now gather all of the codecs that we are asked for: */ 08531 ast_rtp_get_current_formats(newaudiortp, &peercapability, &peernoncodeccapability); 08532 ast_rtp_get_current_formats(newvideortp, &vpeercapability, &vpeernoncodeccapability); 08533 ast_rtp_get_current_formats(newtextrtp, &tpeercapability, &tpeernoncodeccapability); 08534 08535 newjointcapability = p->capability & (peercapability | vpeercapability | tpeercapability); 08536 newpeercapability = (peercapability | vpeercapability | tpeercapability); 08537 newnoncodeccapability = p->noncodeccapability & peernoncodeccapability; 08538 08539 if (debug) { 08540 /* shame on whoever coded this.... */ 08541 char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE], s5[SIPBUFSIZE]; 08542 08543 ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s/text=%s, combined - %s\n", 08544 ast_getformatname_multiple(s1, SIPBUFSIZE, p->capability), 08545 ast_getformatname_multiple(s2, SIPBUFSIZE, peercapability), 08546 ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability), 08547 ast_getformatname_multiple(s4, SIPBUFSIZE, tpeercapability), 08548 ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability)); 08549 08550 ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n", 08551 ast_rtp_lookup_mime_multiple(s1, SIPBUFSIZE, p->noncodeccapability, 0, 0), 08552 ast_rtp_lookup_mime_multiple(s2, SIPBUFSIZE, peernoncodeccapability, 0, 0), 08553 ast_rtp_lookup_mime_multiple(s3, SIPBUFSIZE, newnoncodeccapability, 0, 0)); 08554 } 08555 if (!newjointcapability && (portno != -1)) { 08556 ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n"); 08557 /* Do NOT Change current setting */ 08558 return -1; 08559 } 08560 08561 /* Setup audio address and port */ 08562 if (p->rtp) { 08563 if (portno > 0) { 08564 sin.sin_family = AF_INET; 08565 sin.sin_port = htons(portno); 08566 memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr)); 08567 ast_rtp_set_peer(p->rtp, &sin); 08568 if (debug) 08569 ast_verbose("Peer audio RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port)); 08570 /* We are now ready to change the sip session and p->rtp and p->vrtp with the offered codecs, since 08571 they are acceptable */ 08572 p->jointcapability = newjointcapability; /* Our joint codec profile for this call */ 08573 p->peercapability = newpeercapability; /* The other sides capability in latest offer */ 08574 p->jointnoncodeccapability = newnoncodeccapability; /* DTMF capabilities */ 08575 08576 ast_rtp_pt_copy(p->rtp, newaudiortp); 08577 08578 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) { 08579 ast_clear_flag(&p->flags[0], SIP_DTMF); 08580 if (newnoncodeccapability & AST_RTP_DTMF) { 08581 /* XXX Would it be reasonable to drop the DSP at this point? XXX */ 08582 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 08583 /* Since RFC2833 is now negotiated we need to change some properties of the RTP stream */ 08584 ast_rtp_setdtmf(p->rtp, 1); 08585 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 08586 } else { 08587 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 08588 } 08589 } 08590 } else if (udptlportno > 0) { 08591 if (debug) 08592 ast_verbose("Got T.38 Re-invite without audio. Keeping RTP active during T.38 session.\n"); 08593 } else { 08594 ast_rtp_stop(p->rtp); 08595 if (debug) 08596 ast_verbose("Peer doesn't provide audio\n"); 08597 } 08598 } 08599 08600 /* Setup video address and port */ 08601 if (p->vrtp) { 08602 if (vportno > 0) { 08603 vsin.sin_family = AF_INET; 08604 vsin.sin_port = htons(vportno); 08605 memcpy(&vsin.sin_addr, vhp->h_addr, sizeof(vsin.sin_addr)); 08606 ast_rtp_set_peer(p->vrtp, &vsin); 08607 if (debug) 08608 ast_verbose("Peer video RTP is at port %s:%d\n", ast_inet_ntoa(vsin.sin_addr), ntohs(vsin.sin_port)); 08609 ast_rtp_pt_copy(p->vrtp, newvideortp); 08610 } else { 08611 ast_rtp_stop(p->vrtp); 08612 if (debug) 08613 ast_verbose("Peer doesn't provide video\n"); 08614 } 08615 } 08616 08617 /* Setup text address and port */ 08618 if (p->trtp) { 08619 if (tportno > 0) { 08620 tsin.sin_family = AF_INET; 08621 tsin.sin_port = htons(tportno); 08622 memcpy(&tsin.sin_addr, thp->h_addr, sizeof(tsin.sin_addr)); 08623 ast_rtp_set_peer(p->trtp, &tsin); 08624 if (debug) 08625 ast_verbose("Peer T.140 RTP is at port %s:%d\n", ast_inet_ntoa(tsin.sin_addr), ntohs(tsin.sin_port)); 08626 if ((p->jointcapability & AST_FORMAT_T140RED)) { 08627 p->red = 1; 08628 rtp_red_init(p->trtp, 300, red_data_pt, 2); 08629 } else { 08630 p->red = 0; 08631 } 08632 ast_rtp_pt_copy(p->trtp, newtextrtp); 08633 } else { 08634 ast_rtp_stop(p->trtp); 08635 if (debug) 08636 ast_verbose("Peer doesn't provide T.140\n"); 08637 } 08638 } 08639 /* Setup image address and port */ 08640 if (p->udptl) { 08641 if (udptlportno > 0) { 08642 isin.sin_family = AF_INET; 08643 isin.sin_port = htons(udptlportno); 08644 if (ast_test_flag(&p->flags[0], SIP_NAT) && ast_test_flag(&p->flags[1], SIP_PAGE2_UDPTL_DESTINATION)) { 08645 struct sockaddr_in remote_address = { 0, }; 08646 ast_rtp_get_peer(p->rtp, &remote_address); 08647 if (remote_address.sin_addr.s_addr) { 08648 memcpy(&isin, &remote_address, sizeof(isin)); 08649 if (debug) { 08650 ast_log(LOG_DEBUG, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_inet_ntoa(isin.sin_addr)); 08651 } 08652 } 08653 } else { 08654 memcpy(&isin.sin_addr, ihp->h_addr, sizeof(isin.sin_addr)); 08655 } 08656 ast_udptl_set_peer(p->udptl, &isin); 08657 if (debug) 08658 ast_debug(1,"Peer T.38 UDPTL is at port %s:%d\n", ast_inet_ntoa(isin.sin_addr), ntohs(isin.sin_port)); 08659 08660 /* verify the far max ifp can be calculated. this requires far max datagram to be set. */ 08661 if (!ast_udptl_get_far_max_datagram(p->udptl)) { 08662 /* setting to zero will force a default if none was provided by the SDP */ 08663 ast_udptl_set_far_max_datagram(p->udptl, 0); 08664 } 08665 08666 /* Remote party offers T38, we need to update state */ 08667 if ((t38action == SDP_T38_ACCEPT) && 08668 (p->t38.state == T38_LOCAL_REINVITE)) { 08669 change_t38_state(p, T38_ENABLED); 08670 } else if ((t38action == SDP_T38_INITIATE) && 08671 p->owner && p->lastinvite) { 08672 change_t38_state(p, T38_PEER_REINVITE); /* T38 Offered in re-invite from remote party */ 08673 /* If fax detection is enabled then send us off to the fax extension */ 08674 if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38)) { 08675 ast_channel_lock(p->owner); 08676 if (strcmp(p->owner->exten, "fax")) { 08677 const char *target_context = S_OR(p->owner->macrocontext, p->owner->context); 08678 ast_channel_unlock(p->owner); 08679 if (ast_exists_extension(p->owner, target_context, "fax", 1, p->owner->cid.cid_num)) { 08680 ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to peer T.38 re-INVITE\n", p->owner->name); 08681 pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten); 08682 if (ast_async_goto(p->owner, target_context, "fax", 1)) { 08683 ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context); 08684 } 08685 } else { 08686 ast_log(LOG_NOTICE, "T.38 re-INVITE detected but no fax extension\n"); 08687 } 08688 } else { 08689 ast_channel_unlock(p->owner); 08690 } 08691 } 08692 } 08693 } else { 08694 ast_udptl_stop(p->udptl); 08695 if (debug) 08696 ast_debug(1, "Peer doesn't provide T.38 UDPTL\n"); 08697 } 08698 } 08699 08700 if ((portno == -1) && (p->t38.state != T38_DISABLED)) { 08701 ast_debug(3, "Have T.38 but no audio, accepting offer anyway\n"); 08702 return 0; 08703 } 08704 08705 /* Ok, we're going with this offer */ 08706 ast_debug(2, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcapability)); 08707 08708 if (!p->owner) /* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */ 08709 return 0; 08710 08711 ast_debug(4, "We have an owner, now see if we need to change this call\n"); 08712 08713 if (!(p->owner->nativeformats & p->jointcapability) && (p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 08714 if (debug) { 08715 char s1[SIPBUFSIZE], s2[SIPBUFSIZE]; 08716 ast_debug(1, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n", 08717 ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcapability), 08718 ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats)); 08719 } 08720 p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability) | (p->capability & tpeercapability); 08721 ast_set_read_format(p->owner, p->owner->readformat); 08722 ast_set_write_format(p->owner, p->owner->writeformat); 08723 } 08724 08725 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) 08726 && (sin.sin_addr.s_addr || vsin.sin_addr.s_addr || 08727 isin.sin_addr.s_addr || tsin.sin_addr.s_addr) 08728 && (!sendonly || sendonly == -1)) { 08729 ast_queue_control(p->owner, AST_CONTROL_UNHOLD); 08730 /* Activate a re-invite */ 08731 ast_queue_frame(p->owner, &ast_null_frame); 08732 change_hold_state(p, req, FALSE, sendonly); 08733 } else if (!(sin.sin_addr.s_addr || vsin.sin_addr.s_addr || 08734 isin.sin_addr.s_addr || tsin.sin_addr.s_addr) 08735 || (sendonly && sendonly != -1)) { 08736 ast_queue_control_data(p->owner, AST_CONTROL_HOLD, 08737 S_OR(p->mohsuggest, NULL), 08738 !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0); 08739 if (sendonly) 08740 ast_rtp_stop(p->rtp); 08741 /* RTCP needs to go ahead, even if we're on hold!!! */ 08742 /* Activate a re-invite */ 08743 ast_queue_frame(p->owner, &ast_null_frame); 08744 change_hold_state(p, req, TRUE, sendonly); 08745 } 08746 08747 return 0; 08748 }
| static int process_sdp_a_audio | ( | const char * | a, | |
| struct sip_pvt * | p, | |||
| struct ast_rtp * | newaudiortp, | |||
| int * | last_rtpmap_codec | |||
| ) | [static] |
Definition at line 8868 of file chan_sip.c.
References ast_codec_pref_setsize(), ast_debug, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, ast_log(), ast_rtp_codec_getformat(), ast_rtp_codec_getpref(), ast_rtp_codec_setpref(), ast_rtp_lookup_pt(), AST_RTP_OPT_G726_NONSTANDARD, ast_rtp_set_rtpmap_type_rate(), ast_rtp_unset_m_type(), ast_test_flag, ast_verbose, sip_pvt::autoframing, sip_request::debug, FALSE, sip_pvt::flags, format, LOG_DEBUG, LOG_WARNING, MAX_RTP_PT, option_debug, sip_pvt::rtp, SDP_MAX_RTPMAP_CODECS, sip_debug_test_pvt(), SIP_G726_NONSTANDARD, and TRUE.
Referenced by process_sdp().
08869 { 08870 int found = FALSE; 08871 int codec; 08872 char mimeSubtype[128]; 08873 char fmtp_string[64]; 08874 unsigned int sample_rate; 08875 int debug = sip_debug_test_pvt(p); 08876 08877 if (!strncasecmp(a, "ptime", 5)) { 08878 char *tmp = strrchr(a, ':'); 08879 long int framing = 0; 08880 if (tmp) { 08881 tmp++; 08882 framing = strtol(tmp, NULL, 10); 08883 if (framing == LONG_MIN || framing == LONG_MAX) { 08884 framing = 0; 08885 ast_debug(1, "Can't read framing from SDP: %s\n", a); 08886 } 08887 } 08888 if (framing && p->autoframing) { 08889 struct ast_codec_pref *pref = ast_rtp_codec_getpref(p->rtp); 08890 int codec_n; 08891 int format = 0; 08892 for (codec_n = 0; codec_n < MAX_RTP_PT; codec_n++) { 08893 format = ast_rtp_codec_getformat(codec_n); 08894 if (!format) /* non-codec or not found */ 08895 continue; 08896 if (option_debug) 08897 ast_log(LOG_DEBUG, "Setting framing for %d to %ld\n", format, framing); 08898 ast_codec_pref_setsize(pref, format, framing); 08899 } 08900 ast_rtp_codec_setpref(p->rtp, pref); 08901 } 08902 found = TRUE; 08903 } else if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 08904 /* We have a rtpmap to handle */ 08905 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 08906 if (ast_rtp_set_rtpmap_type_rate(newaudiortp, codec, "audio", mimeSubtype, 08907 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0, sample_rate) != -1) { 08908 if (debug) 08909 ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec); 08910 //found_rtpmap_codecs[last_rtpmap_codec] = codec; 08911 (*last_rtpmap_codec)++; 08912 found = TRUE; 08913 } else { 08914 ast_rtp_unset_m_type(newaudiortp, codec); 08915 if (debug) 08916 ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec); 08917 } 08918 } else { 08919 if (debug) 08920 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 08921 } 08922 } else if (sscanf(a, "fmtp: %30u %63s", &codec, fmtp_string) == 2) { 08923 struct rtpPayloadType payload; 08924 08925 payload = ast_rtp_lookup_pt(newaudiortp, codec); 08926 if (payload.code && payload.isAstFormat) { 08927 unsigned int bit_rate; 08928 08929 switch (payload.code) { 08930 case AST_FORMAT_SIREN7: 08931 if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) { 08932 if (bit_rate != 32000) { 08933 ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate); 08934 ast_rtp_unset_m_type(newaudiortp, codec); 08935 } else { 08936 found = TRUE; 08937 } 08938 } 08939 break; 08940 case AST_FORMAT_SIREN14: 08941 if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) { 08942 if (bit_rate != 48000) { 08943 ast_log(LOG_WARNING, "Got Siren14 offer at %d bps, but only 48000 bps supported; ignoring.\n", bit_rate); 08944 ast_rtp_unset_m_type(newaudiortp, codec); 08945 } else { 08946 found = TRUE; 08947 } 08948 } 08949 break; 08950 } 08951 } 08952 } 08953 08954 return found; 08955 }
| static int process_sdp_a_image | ( | const char * | a, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Definition at line 9040 of file chan_sip.c.
References ast_debug, AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, AST_T38_RATE_9600, AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), FALSE, ast_control_t38_parameters::fill_bit_removal, ast_control_t38_parameters::rate, ast_control_t38_parameters::rate_management, s, sip_pvt::t38, sip_pvt::t38_maxdatagram, t38properties::their_parms, ast_control_t38_parameters::transcoding_jbig, ast_control_t38_parameters::transcoding_mmr, TRUE, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, and ast_control_t38_parameters::version.
Referenced by process_sdp().
09041 { 09042 int found = FALSE; 09043 char s[256]; 09044 unsigned int x; 09045 09046 if ((sscanf(a, "T38FaxMaxBuffer:%30u", &x) == 1)) { 09047 ast_debug(3, "MaxBufferSize:%d\n", x); 09048 found = TRUE; 09049 } else if ((sscanf(a, "T38MaxBitRate:%30u", &x) == 1) || (sscanf(a, "T38FaxMaxRate:%30u", &x) == 1)) { 09050 ast_debug(3, "T38MaxBitRate: %d\n", x); 09051 switch (x) { 09052 case 14400: 09053 p->t38.their_parms.rate = AST_T38_RATE_14400; 09054 break; 09055 case 12000: 09056 p->t38.their_parms.rate = AST_T38_RATE_12000; 09057 break; 09058 case 9600: 09059 p->t38.their_parms.rate = AST_T38_RATE_9600; 09060 break; 09061 case 7200: 09062 p->t38.their_parms.rate = AST_T38_RATE_7200; 09063 break; 09064 case 4800: 09065 p->t38.their_parms.rate = AST_T38_RATE_4800; 09066 break; 09067 case 2400: 09068 p->t38.their_parms.rate = AST_T38_RATE_2400; 09069 break; 09070 } 09071 found = TRUE; 09072 } else if ((sscanf(a, "T38FaxVersion:%30u", &x) == 1)) { 09073 ast_debug(3, "FaxVersion: %u\n", x); 09074 p->t38.their_parms.version = x; 09075 found = TRUE; 09076 } else if ((sscanf(a, "T38FaxMaxDatagram:%30u", &x) == 1) || (sscanf(a, "T38MaxDatagram:%30u", &x) == 1)) { 09077 /* override the supplied value if the configuration requests it */ 09078 if (((signed int) p->t38_maxdatagram >= 0) && ((unsigned int) p->t38_maxdatagram > x)) { 09079 ast_debug(1, "Overriding T38FaxMaxDatagram '%d' with '%d'\n", x, p->t38_maxdatagram); 09080 x = p->t38_maxdatagram; 09081 } 09082 ast_debug(3, "FaxMaxDatagram: %u\n", x); 09083 ast_udptl_set_far_max_datagram(p->udptl, x); 09084 found = TRUE; 09085 } else if ((strncmp(a, "T38FaxFillBitRemoval", 20) == 0)) { 09086 if (sscanf(a, "T38FaxFillBitRemoval:%30u", &x) == 1) { 09087 ast_debug(3, "FillBitRemoval: %d\n", x); 09088 if (x == 1) { 09089 p->t38.their_parms.fill_bit_removal = TRUE; 09090 } 09091 } else { 09092 ast_debug(3, "FillBitRemoval\n"); 09093 p->t38.their_parms.fill_bit_removal = TRUE; 09094 } 09095 found = TRUE; 09096 } else if ((strncmp(a, "T38FaxTranscodingMMR", 20) == 0)) { 09097 if (sscanf(a, "T38FaxTranscodingMMR:%30u", &x) == 1) { 09098 ast_debug(3, "Transcoding MMR: %d\n", x); 09099 if (x == 1) { 09100 p->t38.their_parms.transcoding_mmr = TRUE; 09101 } 09102 } else { 09103 ast_debug(3, "Transcoding MMR\n"); 09104 p->t38.their_parms.transcoding_mmr = TRUE; 09105 } 09106 found = TRUE; 09107 } else if ((strncmp(a, "T38FaxTranscodingJBIG", 21) == 0)) { 09108 if (sscanf(a, "T38FaxTranscodingJBIG:%30u", &x) == 1) { 09109 ast_debug(3, "Transcoding JBIG: %d\n", x); 09110 if (x == 1) { 09111 p->t38.their_parms.transcoding_jbig = TRUE; 09112 } 09113 } else { 09114 ast_debug(3, "Transcoding JBIG\n"); 09115 p->t38.their_parms.transcoding_jbig = TRUE; 09116 } 09117 found = TRUE; 09118 } else if ((sscanf(a, "T38FaxRateManagement:%255s", s) == 1)) { 09119 ast_debug(3, "RateManagement: %s\n", s); 09120 if (!strcasecmp(s, "localTCF")) 09121 p->t38.their_parms.rate_management = AST_T38_RATE_MANAGEMENT_LOCAL_TCF; 09122 else if (!strcasecmp(s, "transferredTCF")) 09123 p->t38.their_parms.rate_management = AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF; 09124 found = TRUE; 09125 } else if ((sscanf(a, "T38FaxUdpEC:%255s", s) == 1)) { 09126 ast_debug(3, "UDP EC: %s\n", s); 09127 if (!strcasecmp(s, "t38UDPRedundancy")) { 09128 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_REDUNDANCY); 09129 } else if (!strcasecmp(s, "t38UDPFEC")) { 09130 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_FEC); 09131 } else { 09132 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 09133 } 09134 found = TRUE; 09135 } 09136 09137 return found; 09138 }
| static int process_sdp_a_sendonly | ( | const char * | a, | |
| int * | sendonly | |||
| ) | [static] |
Definition at line 8848 of file chan_sip.c.
Referenced by process_sdp().
08849 { 08850 int found = FALSE; 08851 08852 if (!strcasecmp(a, "sendonly")) { 08853 if (*sendonly == -1) 08854 *sendonly = 1; 08855 found = TRUE; 08856 } else if (!strcasecmp(a, "inactive")) { 08857 if (*sendonly == -1) 08858 *sendonly = 2; 08859 found = TRUE; 08860 } else if (!strcasecmp(a, "sendrecv")) { 08861 if (*sendonly == -1) 08862 *sendonly = 0; 08863 found = TRUE; 08864 } 08865 return found; 08866 }
| static int process_sdp_a_text | ( | const char * | a, | |
| struct sip_pvt * | p, | |||
| struct ast_rtp * | newtextrtp, | |||
| char * | red_fmtp, | |||
| int * | red_num_gen, | |||
| int * | red_data_pt, | |||
| int * | last_rtpmap_codec | |||
| ) | [static] |
Definition at line 8991 of file chan_sip.c.
References ast_rtp_set_rtpmap_type(), ast_verbose, sip_request::debug, FALSE, RED_MAX_GENERATION, SDP_MAX_RTPMAP_CODECS, sip_debug_test_pvt(), sip_pvt::trtp, and TRUE.
Referenced by process_sdp().
08992 { 08993 int found = FALSE; 08994 int codec; 08995 char mimeSubtype[128]; 08996 unsigned int sample_rate; 08997 char *red_cp; 08998 int debug = sip_debug_test_pvt(p); 08999 09000 if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 09001 /* We have a rtpmap to handle */ 09002 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 09003 if (!strncasecmp(mimeSubtype, "T140", 4)) { /* Text */ 09004 if (p->trtp) { 09005 /* ast_verbose("Adding t140 mimeSubtype to textrtp struct\n"); */ 09006 ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0); 09007 found = TRUE; 09008 } 09009 } else if (!strncasecmp(mimeSubtype, "RED", 3)) { /* Text with Redudancy */ 09010 if (p->trtp) { 09011 ast_rtp_set_rtpmap_type(newtextrtp, codec, "text", mimeSubtype, 0); 09012 sprintf(red_fmtp, "fmtp:%d ", codec); 09013 if (debug) 09014 ast_verbose("RED submimetype has payload type: %d\n", codec); 09015 found = TRUE; 09016 } 09017 } 09018 } else { 09019 if (debug) 09020 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 09021 } 09022 } else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) { 09023 /* count numbers of generations in fmtp */ 09024 red_cp = &red_fmtp[strlen(red_fmtp)]; 09025 strncpy(red_fmtp, a, 100); 09026 09027 sscanf(red_cp, "%30u", &red_data_pt[*red_num_gen]); 09028 red_cp = strtok(red_cp, "/"); 09029 while (red_cp && (*red_num_gen)++ < RED_MAX_GENERATION) { 09030 sscanf(red_cp, "%30u", &red_data_pt[*red_num_gen]); 09031 red_cp = strtok(NULL, "/"); 09032 } 09033 red_cp = red_fmtp; 09034 found = TRUE; 09035 } 09036 09037 return found; 09038 }
| static int process_sdp_a_video | ( | const char * | a, | |
| struct sip_pvt * | p, | |||
| struct ast_rtp * | newvideortp, | |||
| int * | last_rtpmap_codec | |||
| ) | [static] |
Definition at line 8957 of file chan_sip.c.
References ast_rtp_set_rtpmap_type_rate(), ast_rtp_unset_m_type(), ast_verbose, sip_request::debug, FALSE, SDP_MAX_RTPMAP_CODECS, sip_debug_test_pvt(), and TRUE.
Referenced by process_sdp().
08958 { 08959 int found = FALSE; 08960 int codec; 08961 char mimeSubtype[128]; 08962 unsigned int sample_rate; 08963 int debug = sip_debug_test_pvt(p); 08964 08965 if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 08966 /* We have a rtpmap to handle */ 08967 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 08968 /* Note: should really look at the '#chans' params too */ 08969 if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)) { 08970 if (ast_rtp_set_rtpmap_type_rate(newvideortp, codec, "video", mimeSubtype, 0, sample_rate) != -1) { 08971 if (debug) 08972 ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec); 08973 //found_rtpmap_codecs[last_rtpmap_codec] = codec; 08974 (*last_rtpmap_codec)++; 08975 found = TRUE; 08976 } else { 08977 ast_rtp_unset_m_type(newvideortp, codec); 08978 if (debug) 08979 ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec); 08980 } 08981 } 08982 } else { 08983 if (debug) 08984 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 08985 } 08986 } 08987 08988 return found; 08989 }
| static int process_sdp_c | ( | const char * | c, | |
| struct ast_hostent * | hp | |||
| ) | [static] |
Definition at line 8829 of file chan_sip.c.
References ast_gethostbyname(), ast_log(), FALSE, hp, LOG_WARNING, and TRUE.
Referenced by process_sdp().
08830 { 08831 char host[258]; 08832 struct hostent *hp; 08833 08834 /* Check for Media-description-level-address */ 08835 if (sscanf(c, "IN IP4 %255s", host) != 1) { 08836 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 08837 return FALSE; 08838 } else { 08839 if (!(hp = ast_gethostbyname(host, ast_hp))) { 08840 ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in c= line, '%s'\n", c); 08841 return FALSE; 08842 } 08843 return TRUE; 08844 } 08845 return FALSE; 08846 }
| static int process_sdp_o | ( | const char * | o, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Definition at line 8750 of file chan_sip.c.
References ast_debug, ast_log(), ast_strdupa, ast_strlen_zero(), ast_test_flag, sip_pvt::callid, FALSE, sip_pvt::flags, LOG_WARNING, sip_pvt::session_modify, sip_pvt::sessionversion_remote, SIP_PAGE2_IGNORESDPVERSION, t38properties::state, strsep(), sip_pvt::t38, T38_LOCAL_REINVITE, and TRUE.
Referenced by process_sdp().
08751 { 08752 char *o_copy; 08753 char *token; 08754 int64_t rua_version; 08755 08756 /* Store the SDP version number of remote UA. This will allow us to 08757 distinguish between session modifications and session refreshes. If 08758 the remote UA does not send an incremented SDP version number in a 08759 subsequent RE-INVITE then that means its not changing media session. 08760 The RE-INVITE may have been sent to update connected party, remote 08761 target or to refresh the session (Session-Timers). Asterisk must not 08762 change media session and increment its own version number in answer 08763 SDP in this case. */ 08764 08765 p->session_modify = TRUE; 08766 08767 if (ast_strlen_zero(o)) { 08768 ast_log(LOG_WARNING, "SDP syntax error. SDP without an o= line\n"); 08769 return FALSE; 08770 } 08771 08772 o_copy = ast_strdupa(o); 08773 token = strsep(&o_copy, " "); /* Skip username */ 08774 if (!o_copy) { 08775 ast_log(LOG_WARNING, "SDP syntax error in o= line username\n"); 08776 return FALSE; 08777 } 08778 token = strsep(&o_copy, " "); /* Skip session-id */ 08779 if (!o_copy) { 08780 ast_log(LOG_WARNING, "SDP syntax error in o= line session-id\n"); 08781 return FALSE; 08782 } 08783 token = strsep(&o_copy, " "); /* Version */ 08784 if (!o_copy) { 08785 ast_log(LOG_WARNING, "SDP syntax error in o= line\n"); 08786 return FALSE; 08787 } 08788 if (!sscanf(token, "%30" SCNd64, &rua_version)) { 08789 ast_log(LOG_WARNING, "SDP syntax error in o= line version\n"); 08790 return FALSE; 08791 } 08792 08793 /* we need to check the SDP version number the other end sent us; 08794 * our rules for deciding what to accept are a bit complex. 08795 * 08796 * 1) if 'ignoresdpversion' has been set for this dialog, then 08797 * we will just accept whatever they sent and assume it is 08798 * a modification of the session, even if it is not 08799 * 2) otherwise, if this is the first SDP we've seen from them 08800 * we accept it 08801 * 3) otherwise, if the new SDP version number is higher than the 08802 * old one, we accept it 08803 * 4) otherwise, if this SDP is in response to us requesting a switch 08804 * to T.38, we accept the SDP, but also generate a warning message 08805 * that this peer should have the 'ignoresdpversion' option set, 08806 * because it is not following the SDP offer/answer RFC; if we did 08807 * not request a switch to T.38, then we stop parsing the SDP, as it 08808 * has not changed from the previous version 08809 */ 08810 08811 if (ast_test_flag(&p->flags[1], SIP_PAGE2_IGNORESDPVERSION) || 08812 (p->sessionversion_remote < 0) || 08813 (p->sessionversion_remote < rua_version)) { 08814 p->sessionversion_remote = rua_version; 08815 } else { 08816 if (p->t38.state == T38_LOCAL_REINVITE) { 08817 p->sessionversion_remote = rua_version; 08818 ast_log(LOG_WARNING, "Call %s responded to our T.38 reinvite without changing SDP version; 'ignoresdpversion' should be set for this peer.\n", p->callid); 08819 } else { 08820 p->session_modify = FALSE; 08821 ast_debug(2, "Call %s responded to our reinvite without changing SDP version; ignoring SDP.\n", p->callid); 08822 return FALSE; 08823 } 08824 } 08825 08826 return TRUE; 08827 }
| static struct sip_proxy* proxy_allocate | ( | char * | name, | |
| char * | port, | |||
| int | force | |||
| ) | [static, read] |
Allocate and initialize sip proxy.
Definition at line 3337 of file chan_sip.c.
References ao2_alloc, ast_copy_string(), ast_strlen_zero(), sip_proxy::force, sip_proxy::ip, sip_proxy::name, port_str2int(), proxy_update(), and STANDARD_SIP_PORT.
Referenced by build_peer().
03338 { 03339 struct sip_proxy *proxy; 03340 03341 if (ast_strlen_zero(name)) { 03342 return NULL; 03343 } 03344 03345 proxy = ao2_alloc(sizeof(*proxy), NULL); 03346 if (!proxy) 03347 return NULL; 03348 proxy->force = force; 03349 ast_copy_string(proxy->name, name, sizeof(proxy->name)); 03350 proxy->ip.sin_port = htons(port_str2int(port, STANDARD_SIP_PORT)); 03351 proxy->ip.sin_family = AF_INET; 03352 proxy_update(proxy); 03353 return proxy; 03354 }
| static int proxy_update | ( | struct sip_proxy * | proxy | ) | [static] |
Resolve DNS srv name or host name in a sip_proxy structure
Definition at line 3306 of file chan_sip.c.
References ast_get_ip_or_srv(), ast_log(), FALSE, inet_aton(), sip_proxy::ip, sip_proxy::last_dnsupdate, LOG_WARNING, sip_proxy::name, sip_cfg, sip_settings::srvlookup, and TRUE.
Referenced by proxy_allocate(), and reload_config().
03307 { 03308 /* if it's actually an IP address and not a name, 03309 there's no need for a managed lookup */ 03310 if (!inet_aton(proxy->name, &proxy->ip.sin_addr)) { 03311 /* Ok, not an IP address, then let's check if it's a domain or host */ 03312 /* XXX Todo - if we have proxy port, don't do SRV */ 03313 if (ast_get_ip_or_srv(&proxy->ip, proxy->name, sip_cfg.srvlookup ? "_sip._udp" : NULL) < 0) { 03314 ast_log(LOG_WARNING, "Unable to locate host '%s'\n", proxy->name); 03315 return FALSE; 03316 } 03317 } 03318 proxy->last_dnsupdate = time(NULL); 03319 return TRUE; 03320 }
| static void pvt_set_needdestroy | ( | struct sip_pvt * | pvt, | |
| const char * | reason | |||
| ) | [inline, static] |
Definition at line 3276 of file chan_sip.c.
References append_history, and sip_pvt::needdestroy.
Referenced by __sip_autodestruct(), handle_incoming(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_peerpoke(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), retrans_pkt(), sip_hangup(), and sip_reg_timeout().
03277 { 03278 append_history(pvt, "NeedDestroy", "Setting needdestroy because %s", reason); 03279 pvt->needdestroy = 1; 03280 }
| static int queue_request | ( | struct sip_pvt * | p, | |
| const struct sip_request * | req | |||
| ) | [static] |
Definition at line 22099 of file chan_sip.c.
References ast_calloc, AST_LIST_INSERT_TAIL, ast_sched_add(), copy_request(), dialog_ref(), dialog_unref(), sip_pvt::request_queue, sip_pvt::request_queue_sched_id, and scheduler_process_request_queue().
Referenced by handle_request_do().
22100 { 22101 struct sip_request *newreq; 22102 22103 if (!(newreq = ast_calloc(1, sizeof(*newreq)))) { 22104 return -1; 22105 } 22106 22107 copy_request(newreq, req); 22108 AST_LIST_INSERT_TAIL(&p->request_queue, newreq, next); 22109 if (p->request_queue_sched_id == -1) { 22110 if ((p->request_queue_sched_id = ast_sched_add(sched, 10, scheduler_process_request_queue, dialog_ref(p, "Increment refcount to pass dialog pointer to sched callback"))) == -1) { 22111 dialog_unref(p, "Decrement refcount due to sched_add failure"); 22112 } 22113 } 22114 22115 return 0; 22116 }
| static struct sip_peer * realtime_peer | ( | const char * | peername, | |
| struct sockaddr_in * | sin, | |||
| int | devstate_only | |||
| ) | [static, read] |
realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf Checks the "sipregs" realtime family from extconfig.conf if it's configured. This returns a pointer to a peer and because we use build_peer, we can rest assured that the refcount is bumped.
Definition at line 4803 of file chan_sip.c.
References sip_peer::addr, ao2_t_link, ast_check_realtime(), ast_config_destroy(), ast_copy_flags, ast_copy_string(), ast_debug, ast_gethostbyname(), ast_inet_ntoa(), ast_load_realtime(), ast_load_realtime_multientry(), ast_log(), AST_SCHED_REPLACE_UNREF, ast_test_flag, ast_variables_destroy(), build_peer(), sip_peer::expire, expire_register(), sip_peer::flags, get_insecure_variable_from_config(), get_name_from_variable(), hp, ipaddr, sip_peer::is_realtime, LOG_WARNING, sip_peer::name, ast_variable::name, ast_variable::next, ref_peer(), sip_settings::rtautoclear, SENTINEL, sip_cfg, SIP_PAGE2_RTAUTOCLEAR, SIP_PAGE2_RTCACHEFRIENDS, TRUE, unref_peer(), ast_variable::value, and var.
Referenced by find_peer().
04804 { 04805 struct sip_peer *peer; 04806 struct ast_variable *var = NULL; 04807 struct ast_variable *varregs = NULL; 04808 struct ast_variable *tmp; 04809 struct ast_config *peerlist = NULL; 04810 char ipaddr[INET_ADDRSTRLEN]; 04811 char portstring[6]; /*up to 5 digits plus null terminator*/ 04812 char *cat = NULL; 04813 unsigned short portnum; 04814 int realtimeregs = ast_check_realtime("sipregs"); 04815 04816 /* First check on peer name */ 04817 if (newpeername) { 04818 if (realtimeregs) 04819 varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL); 04820 04821 var = ast_load_realtime("sippeers", "name", newpeername, "host", "dynamic", SENTINEL); 04822 if (!var && sin) 04823 var = ast_load_realtime("sippeers", "name", newpeername, "host", ast_inet_ntoa(sin->sin_addr), SENTINEL); 04824 if (!var) { 04825 var = ast_load_realtime("sippeers", "name", newpeername, SENTINEL); 04826 /*!\note 04827 * If this one loaded something, then we need to ensure that the host 04828 * field matched. The only reason why we can't have this as a criteria 04829 * is because we only have the IP address and the host field might be 04830 * set as a name (and the reverse PTR might not match). 04831 */ 04832 if (var && sin) { 04833 for (tmp = var; tmp; tmp = tmp->next) { 04834 if (!strcasecmp(tmp->name, "host")) { 04835 struct hostent *hp; 04836 struct ast_hostent ahp; 04837 if (!(hp = ast_gethostbyname(tmp->value, &ahp)) || (memcmp(hp->h_addr, &sin->sin_addr, sizeof(hp->h_addr)))) { 04838 /* No match */ 04839 ast_variables_destroy(var); 04840 var = NULL; 04841 } 04842 break; 04843 } 04844 } 04845 } 04846 } 04847 } 04848 04849 if (!var && sin) { /* Then check on IP address for dynamic peers */ 04850 ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr)); 04851 portnum = ntohs(sin->sin_port); 04852 sprintf(portstring, "%u", portnum); 04853 var = ast_load_realtime("sippeers", "host", ipaddr, "port", portstring, SENTINEL); /* First check for fixed IP hosts */ 04854 if (var) { 04855 if (realtimeregs) { 04856 newpeername = get_name_from_variable(var, newpeername); 04857 varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL); 04858 } 04859 } else { 04860 if (realtimeregs) 04861 varregs = ast_load_realtime("sipregs", "ipaddr", ipaddr, "port", portstring, SENTINEL); /* Then check for registered hosts */ 04862 else 04863 var = ast_load_realtime("sippeers", "ipaddr", ipaddr, "port", portstring, SENTINEL); /* Then check for registered hosts */ 04864 if (varregs) { 04865 newpeername = get_name_from_variable(varregs, newpeername); 04866 var = ast_load_realtime("sippeers", "name", newpeername, SENTINEL); 04867 } 04868 } 04869 if (!var) { /*We couldn't match on ipaddress and port, so we need to check if port is insecure*/ 04870 peerlist = ast_load_realtime_multientry("sippeers", "host", ipaddr, SENTINEL); 04871 if (peerlist) { 04872 var = get_insecure_variable_from_config(peerlist); 04873 if(var) { 04874 if (realtimeregs) { 04875 newpeername = get_name_from_variable(var, newpeername); 04876 varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL); 04877 } 04878 } else { /*var wasn't found in the list of "hosts", so try "ipaddr"*/ 04879 peerlist = NULL; 04880 cat = NULL; 04881 peerlist = ast_load_realtime_multientry("sippeers", "ipaddr", ipaddr, SENTINEL); 04882 if(peerlist) { 04883 var = get_insecure_variable_from_config(peerlist); 04884 if(var) { 04885 if (realtimeregs) { 04886 newpeername = get_name_from_variable(var, newpeername); 04887 varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL); 04888 } 04889 } 04890 } 04891 } 04892 } else { 04893 if (realtimeregs) { 04894 peerlist = ast_load_realtime_multientry("sipregs", "ipaddr", ipaddr, SENTINEL); 04895 if (peerlist) { 04896 varregs = get_insecure_variable_from_config(peerlist); 04897 if (varregs) { 04898 newpeername = get_name_from_variable(varregs, newpeername); 04899 var = ast_load_realtime("sippeers", "name", newpeername, SENTINEL); 04900 } 04901 } 04902 } else { 04903 peerlist = ast_load_realtime_multientry("sippeers", "ipaddr", ipaddr, SENTINEL); 04904 if (peerlist) { 04905 var = get_insecure_variable_from_config(peerlist); 04906 if (var) { 04907 newpeername = get_name_from_variable(var, newpeername); 04908 varregs = ast_load_realtime("sipregs", "name", newpeername, SENTINEL); 04909 } 04910 } 04911 } 04912 } 04913 } 04914 } 04915 04916 if (!var) { 04917 if (peerlist) 04918 ast_config_destroy(peerlist); 04919 return NULL; 04920 } 04921 04922 for (tmp = var; tmp; tmp = tmp->next) { 04923 if (!newpeername && !strcasecmp(tmp->name, "name")) { 04924 newpeername = tmp->value; 04925 } 04926 } 04927 04928 if (!newpeername) { /* Did not find peer in realtime */ 04929 ast_log(LOG_WARNING, "Cannot Determine peer name ip=%s\n", ipaddr); 04930 if(peerlist) 04931 ast_config_destroy(peerlist); 04932 else 04933 ast_variables_destroy(var); 04934 return NULL; 04935 } 04936 04937 04938 /* Peer found in realtime, now build it in memory */ 04939 peer = build_peer(newpeername, var, varregs, TRUE, devstate_only); 04940 if (!peer) { 04941 if(peerlist) 04942 ast_config_destroy(peerlist); 04943 else { 04944 ast_variables_destroy(var); 04945 ast_variables_destroy(varregs); 04946 } 04947 return NULL; 04948 } 04949 04950 ast_debug(3, "-REALTIME- loading peer from database to memory. Name: %s. Peer objects: %d\n", peer->name, rpeerobjs); 04951 04952 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && !devstate_only) { 04953 /* Cache peer */ 04954 ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); 04955 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 04956 AST_SCHED_REPLACE_UNREF(peer->expire, sched, sip_cfg.rtautoclear * 1000, expire_register, peer, 04957 unref_peer(_data, "remove registration ref"), 04958 unref_peer(peer, "remove registration ref"), 04959 ref_peer(peer, "add registration ref")); 04960 } 04961 ao2_t_link(peers, peer, "link peer into peers table"); 04962 if (peer->addr.sin_addr.s_addr) { 04963 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 04964 } 04965 } 04966 peer->is_realtime = 1; 04967 if (peerlist) 04968 ast_config_destroy(peerlist); 04969 else { 04970 ast_variables_destroy(var); 04971 ast_variables_destroy(varregs); 04972 } 04973 04974 return peer; 04975 }
| static void realtime_update_peer | ( | const char * | peername, | |
| struct sockaddr_in * | sin, | |||
| const char * | username, | |||
| const char * | fullcontact, | |||
| const char * | useragent, | |||
| int | expirey, | |||
| int | deprecated_username, | |||
| int | lastms | |||
| ) | [static] |
Update peer object in realtime storage If the Asterisk system name is set in asterisk.conf, we will use that name and store that in the "regserver" field in the sippeers table to facilitate multi-server setups.
Definition at line 4599 of file chan_sip.c.
References ast_check_realtime(), ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_inet_ntoa(), ast_strlen_zero(), ast_update_realtime(), ipaddr, sip_settings::rtsave_sysname, SENTINEL, and sip_cfg.
Referenced by update_peer().
04600 { 04601 char port[10]; 04602 char ipaddr[INET_ADDRSTRLEN]; 04603 char regseconds[20]; 04604 char *tablename = NULL; 04605 char str_lastms[20]; 04606 04607 const char *sysname = ast_config_AST_SYSTEM_NAME; 04608 char *syslabel = NULL; 04609 04610 time_t nowtime = time(NULL) + expirey; 04611 const char *fc = fullcontact ? "fullcontact" : NULL; 04612 04613 int realtimeregs = ast_check_realtime("sipregs"); 04614 04615 tablename = realtimeregs ? "sipregs" : "sippeers"; 04616 04617 04618 snprintf(str_lastms, sizeof(str_lastms), "%d", lastms); 04619 snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime); /* Expiration time */ 04620 ast_copy_string(ipaddr, ast_inet_ntoa(sin->sin_addr), sizeof(ipaddr)); 04621 snprintf(port, sizeof(port), "%d", ntohs(sin->sin_port)); 04622 04623 if (ast_strlen_zero(sysname)) /* No system name, disable this */ 04624 sysname = NULL; 04625 else if (sip_cfg.rtsave_sysname) 04626 syslabel = "regserver"; 04627 04628 /* XXX IMPORTANT: Anytime you add a new parameter to be updated, you 04629 * must also add it to contrib/scripts/asterisk.ldap-schema, 04630 * contrib/scripts/asterisk.ldif, 04631 * and to configs/res_ldap.conf.sample as described in 04632 * bugs 15156 and 15895 04633 */ 04634 if (fc) { 04635 ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr, 04636 "port", port, "regseconds", regseconds, 04637 deprecated_username ? "username" : "defaultuser", defaultuser, 04638 "useragent", useragent, "lastms", str_lastms, 04639 fc, fullcontact, syslabel, sysname, SENTINEL); /* note fc and syslabel _can_ be NULL */ 04640 } else { 04641 ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr, 04642 "port", port, "regseconds", regseconds, 04643 "useragent", useragent, "lastms", str_lastms, 04644 deprecated_username ? "username" : "defaultuser", defaultuser, 04645 syslabel, sysname, SENTINEL); /* note syslabel _can_ be NULL */ 04646 } 04647 }
| static void receive_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP MESSAGE method messages.
Definition at line 14455 of file chan_sip.c.
References AST_FRAME_TEXT, ast_log(), ast_queue_frame(), ast_verbose, buf, sip_pvt::callid, ast_frame::data, ast_frame::datalen, DEFAULT_TRANS_TIMEOUT, FALSE, ast_frame::frametype, get_header(), get_msg_text(), LOG_WARNING, ast_frame::offset, sip_pvt::owner, ast_frame::ptr, sip_debug_test_pvt(), sip_scheddestroy(), ast_frame::subclass, and transmit_response().
Referenced by handle_request_message().
14456 { 14457 char buf[1400]; 14458 struct ast_frame f; 14459 const char *content_type = get_header(req, "Content-Type"); 14460 14461 if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */ 14462 transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */ 14463 if (!p->owner) 14464 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14465 return; 14466 } 14467 14468 if (get_msg_text(buf, sizeof(buf), req, FALSE)) { 14469 ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid); 14470 transmit_response(p, "202 Accepted", req); 14471 if (!p->owner) 14472 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14473 return; 14474 } 14475 14476 if (p->owner) { 14477 if (sip_debug_test_pvt(p)) 14478 ast_verbose("SIP Text message received: '%s'\n", buf); 14479 memset(&f, 0, sizeof(f)); 14480 f.frametype = AST_FRAME_TEXT; 14481 f.subclass = 0; 14482 f.offset = 0; 14483 f.data.ptr = buf; 14484 f.datalen = strlen(buf); 14485 ast_queue_frame(p->owner, &f); 14486 transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */ 14487 return; 14488 } 14489 14490 /* Message outside of a call, we do not support that */ 14491 ast_log(LOG_WARNING, "Received message to %s from %s, dropped it...\n Content-Type:%s\n Message: %s\n", get_header(req, "To"), get_header(req, "From"), content_type, buf); 14492 transmit_response(p, "405 Method Not Allowed", req); 14493 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14494 return; 14495 }
Definition at line 3141 of file chan_sip.c.
References ao2_t_ref.
Referenced by build_peer(), handle_request_subscribe(), handle_response_peerpoke(), parse_register_contact(), realtime_peer(), reg_source_db(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), and sip_unregister().
03142 { 03143 ao2_t_ref(peer, 1, tag); 03144 return peer; 03145 }
maintain proper refcounts for a sip_pvt's outboundproxy
This function sets pvt's outboundproxy pointer to the one referenced by the proxy parameter. Because proxy may be a refcounted object, and because pvt's old outboundproxy may also be a refcounted object, we need to maintain the proper refcounts.
| pvt | The sip_pvt for which we wish to set the outboundproxy | |
| proxy | The sip_proxy which we will point pvt towards. |
Definition at line 3158 of file chan_sip.c.
References ao2_ref, sip_settings::outboundproxy, sip_pvt::outboundproxy, and sip_cfg.
Referenced by __sip_ack(), __sip_subscribe_mwi_do(), create_addr(), and create_addr_from_peer().
03159 { 03160 struct sip_proxy *old_obproxy = pvt->outboundproxy; 03161 /* The sip_cfg.outboundproxy is statically allocated, and so 03162 * we don't ever need to adjust refcounts for it 03163 */ 03164 if (proxy && proxy != &sip_cfg.outboundproxy) { 03165 ao2_ref(proxy, +1); 03166 } 03167 pvt->outboundproxy = proxy; 03168 if (old_obproxy && old_obproxy != &sip_cfg.outboundproxy) { 03169 ao2_ref(old_obproxy, -1); 03170 } 03171 }
| static const char * referstatus2str | ( | enum referstatus | rstatus | ) | [static] |
Convert transfer status to string.
Definition at line 3271 of file chan_sip.c.
References map_x_s().
Referenced by show_channels_cb().
03272 { 03273 return map_x_s(referstatusstrings, rstatus, ""); 03274 }
| static void reg_source_db | ( | struct sip_peer * | peer | ) | [static] |
Get registration details from Asterisk DB.
Definition at line 12248 of file chan_sip.c.
References sip_peer::addr, ast_db_get(), ast_debug, ast_inet_ntoa(), ast_random(), AST_SCHED_REPLACE_UNREF, ast_string_field_set, sip_peer::expire, expire_register(), inet_aton(), sip_peer::name, sip_peer::pokeexpire, ref_peer(), register_peer_exten(), sip_peer::rt_fromcontact, sip_poke_peer(), sip_poke_peer_s(), strsep(), TRUE, unref_peer(), and sip_peer::username.
Referenced by build_peer(), and temp_peer().
12249 { 12250 char data[256]; 12251 struct in_addr in; 12252 int expire; 12253 int port; 12254 char *scan, *addr, *port_str, *expiry_str, *username, *contact; 12255 12256 if (peer->rt_fromcontact) 12257 return; 12258 if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data))) 12259 return; 12260 12261 scan = data; 12262 addr = strsep(&scan, ":"); 12263 port_str = strsep(&scan, ":"); 12264 expiry_str = strsep(&scan, ":"); 12265 username = strsep(&scan, ":"); 12266 contact = scan; /* Contact include sip: and has to be the last part of the database entry as long as we use : as a separator */ 12267 12268 if (!inet_aton(addr, &in)) 12269 return; 12270 12271 if (port_str) 12272 port = atoi(port_str); 12273 else 12274 return; 12275 12276 if (expiry_str) 12277 expire = atoi(expiry_str); 12278 else 12279 return; 12280 12281 if (username) 12282 ast_string_field_set(peer, username, username); 12283 if (contact) 12284 ast_string_field_set(peer, fullcontact, contact); 12285 12286 ast_debug(2, "SIP Seeding peer from astdb: '%s' at %s@%s:%d for %d\n", 12287 peer->name, peer->username, ast_inet_ntoa(in), port, expire); 12288 12289 memset(&peer->addr, 0, sizeof(peer->addr)); 12290 peer->addr.sin_family = AF_INET; 12291 peer->addr.sin_addr = in; 12292 peer->addr.sin_port = htons(port); 12293 if (sipsock < 0) { 12294 /* SIP isn't up yet, so schedule a poke only, pretty soon */ 12295 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, ast_random() % 5000 + 1, sip_poke_peer_s, peer, 12296 unref_peer(_data, "removing poke peer ref"), 12297 unref_peer(peer, "removing poke peer ref"), 12298 ref_peer(peer, "adding poke peer ref")); 12299 } else { 12300 sip_poke_peer(peer, 0); 12301 } 12302 AST_SCHED_REPLACE_UNREF(peer->expire, sched, (expire + 10) * 1000, expire_register, peer, 12303 unref_peer(_data, "remove registration ref"), 12304 unref_peer(peer, "remove registration ref"), 12305 ref_peer(peer, "add registration ref")); 12306 register_peer_exten(peer, TRUE); 12307 }
| static void register_peer_exten | ( | struct sip_peer * | peer, | |
| int | onoff | |||
| ) | [static] |
Automatically add peer extension to dial plan.
Definition at line 4650 of file chan_sip.c.
References ast_add_extension(), ast_context_find(), ast_context_remove_extension(), ast_copy_string(), ast_exists_extension(), ast_free_ptr, ast_log(), ast_strdup, ast_strlen_zero(), context, E_MATCH, ext, LOG_WARNING, sip_peer::name, pbx_find_extension(), sip_peer::regexten, S_OR, pbx_find_info::stacklen, and strsep().
Referenced by expire_register(), handle_response_peerpoke(), parse_register_contact(), reg_source_db(), sip_destroy_peer(), and sip_poke_noanswer().
04651 { 04652 char multi[256]; 04653 char *stringp, *ext, *context; 04654 struct pbx_find_info q = { .stacklen = 0 }; 04655 04656 /* XXX note that global_regcontext is both a global 'enable' flag and 04657 * the name of the global regexten context, if not specified 04658 * individually. 04659 */ 04660 if (ast_strlen_zero(global_regcontext)) 04661 return; 04662 04663 ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi)); 04664 stringp = multi; 04665 while ((ext = strsep(&stringp, "&"))) { 04666 if ((context = strchr(ext, '@'))) { 04667 *context++ = '\0'; /* split ext@context */ 04668 if (!ast_context_find(context)) { 04669 ast_log(LOG_WARNING, "Context %s must exist in regcontext= in sip.conf!\n", context); 04670 continue; 04671 } 04672 } else { 04673 context = global_regcontext; 04674 } 04675 if (onoff) { 04676 if (!ast_exists_extension(NULL, context, ext, 1, NULL)) { 04677 ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop", 04678 ast_strdup(peer->name), ast_free_ptr, "SIP"); 04679 } 04680 } else if (pbx_find_extension(NULL, NULL, &q, context, ext, 1, NULL, "", E_MATCH)) { 04681 ast_context_remove_extension(context, ext, 1, NULL); 04682 } 04683 } 04684 }
| static enum check_auth_result register_verify | ( | struct sip_pvt * | p, | |
| struct sockaddr_in * | sin, | |||
| struct sip_request * | req, | |||
| char * | uri | |||
| ) | [static] |
Verify registration of user
Definition at line 13116 of file chan_sip.c.
References sip_peer::addr, sip_settings::alwaysauthreject, ao2_t_link, ast_apply_ha(), ast_copy_flags, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_inet_ntoa(), AST_LIST_EMPTY, ast_log(), ast_rtp_codec_setpref(), ast_set_flag, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), AUTH_ACL_FAILED, AUTH_BAD_TRANSPORT, AUTH_NOT_FOUND, AUTH_PEER_NOT_DYNAMIC, AUTH_SECRET_FAILED, AUTH_UNKNOWN_DOMAIN, AUTH_USERNAME_MISMATCH, sip_settings::autocreatepeer, sip_peer::autoframing, sip_pvt::autoframing, build_contact(), check_auth(), check_request_transport, check_sip_domain(), EVENT_FLAG_SYSTEM, sip_pvt::expiry, exten, FALSE, find_peer(), FINDPEERS, sip_peer::flags, sip_pvt::flags, sip_peer::fullcontact, get_header(), get_in_brackets(), sip_peer::ha, sip_peer::host_dynamic, sip_request::ignore, sip_pvt::initreq, sip_peer::lastmsgssent, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, sip_peer::md5secret, sip_peer::name, name, parse_register_contact(), PARSE_REGISTER_DENIED, PARSE_REGISTER_FAILED, PARSE_REGISTER_QUERY, PARSE_REGISTER_UPDATE, sip_settings::pedanticsipchecking, sip_peer::prefs, remove_uri_parameters(), sip_pvt::rtp, sip_peer::secret, sip_cancel_destroy(), sip_cfg, SIP_NAT, SIP_PAGE2_REGISTERTRYING, SIP_PAGE2_SUBSCRIBEMWIONLY, SIP_PENDINGBYE, SIP_REGISTER, strcasestr(), temp_peer(), terminate_uri(), transmit_fake_auth_response(), transmit_response(), transmit_response_with_date(), TRUE, unref_peer(), update_peer(), and XMIT_UNRELIABLE.
Referenced by handle_request_register().
13118 { 13119 enum check_auth_result res = AUTH_NOT_FOUND; 13120 struct sip_peer *peer; 13121 char tmp[256]; 13122 char *name, *c; 13123 char *domain; 13124 13125 terminate_uri(uri); /* warning, overwrite the string */ 13126 13127 ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp)); 13128 if (sip_cfg.pedanticsipchecking) 13129 ast_uri_decode(tmp); 13130 13131 c = get_in_brackets(tmp); 13132 c = remove_uri_parameters(c); 13133 13134 if (!strncasecmp(c, "sip:", 4)) { 13135 name = c + 4; 13136 } else if (!strncasecmp(c, "sips:", 5)) { 13137 name = c + 5; 13138 } else { 13139 name = c; 13140 ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_inet_ntoa(sin->sin_addr)); 13141 } 13142 13143 /*! \todo XXX here too we interpret a missing @domain as a name-only 13144 * URI, whereas the RFC says this is a domain-only uri. 13145 */ 13146 /* Strip off the domain name */ 13147 if ((c = strchr(name, '@'))) { 13148 *c++ = '\0'; 13149 domain = c; 13150 if ((c = strchr(domain, ':'))) /* Remove :port */ 13151 *c = '\0'; 13152 if (!AST_LIST_EMPTY(&domain_list)) { 13153 if (!check_sip_domain(domain, NULL, 0)) { 13154 transmit_response(p, "404 Not found (unknown domain)", &p->initreq); 13155 return AUTH_UNKNOWN_DOMAIN; 13156 } 13157 } 13158 } 13159 c = strchr(name, ';'); /* Remove any Username parameters */ 13160 if (c) 13161 *c = '\0'; 13162 13163 ast_string_field_set(p, exten, name); 13164 build_contact(p); 13165 if (req->ignore) { 13166 /* Expires is a special case, where we only want to load the peer if this isn't a deregistration attempt */ 13167 const char *expires = get_header(req, "Expires"); 13168 int expire = atoi(expires); 13169 13170 if (ast_strlen_zero(expires)) { /* No expires header; look in Contact */ 13171 if ((expires = strcasestr(get_header(req, "Contact"), ";expires="))) { 13172 expire = atoi(expires + 9); 13173 } 13174 } 13175 if (!ast_strlen_zero(expires) && expire == 0) { 13176 transmit_response_with_date(p, "200 OK", req); 13177 return 0; 13178 } 13179 } 13180 peer = find_peer(name, NULL, TRUE, FINDPEERS, FALSE, 0); 13181 if (!(peer && ast_apply_ha(peer->ha, sin))) { 13182 /* Peer fails ACL check */ 13183 if (peer) { 13184 unref_peer(peer, "register_verify: unref_peer: from find_peer operation"); 13185 peer = NULL; 13186 res = AUTH_ACL_FAILED; 13187 } else 13188 res = AUTH_NOT_FOUND; 13189 } 13190 13191 if (peer) { 13192 /*! \todo OEJ Remove this - there's never RTP in a REGISTER dialog... */ 13193 /* Set Frame packetization */ 13194 if (p->rtp) { 13195 ast_rtp_codec_setpref(p->rtp, &peer->prefs); 13196 p->autoframing = peer->autoframing; 13197 } 13198 if (!peer->host_dynamic) { 13199 ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name); 13200 res = AUTH_PEER_NOT_DYNAMIC; 13201 } else { 13202 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_NAT); 13203 if (ast_test_flag(&p->flags[1], SIP_PAGE2_REGISTERTRYING)) 13204 transmit_response(p, "100 Trying", req); 13205 if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri, XMIT_UNRELIABLE, req->ignore))) { 13206 if (sip_cancel_destroy(p)) 13207 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 13208 13209 if (check_request_transport(peer, req)) { 13210 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 13211 transmit_response_with_date(p, "403 Forbidden", req); 13212 res = AUTH_BAD_TRANSPORT; 13213 } else { 13214 13215 /* We have a successful registration attempt with proper authentication, 13216 now, update the peer */ 13217 switch (parse_register_contact(p, peer, req)) { 13218 case PARSE_REGISTER_DENIED: 13219 ast_log(LOG_WARNING, "Registration denied because of contact ACL\n"); 13220 transmit_response_with_date(p, "603 Denied", req); 13221 peer->lastmsgssent = -1; 13222 res = 0; 13223 break; 13224 case PARSE_REGISTER_FAILED: 13225 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 13226 transmit_response_with_date(p, "400 Bad Request", req); 13227 peer->lastmsgssent = -1; 13228 res = 0; 13229 break; 13230 case PARSE_REGISTER_QUERY: 13231 ast_string_field_set(p, fullcontact, peer->fullcontact); 13232 transmit_response_with_date(p, "200 OK", req); 13233 peer->lastmsgssent = -1; 13234 res = 0; 13235 break; 13236 case PARSE_REGISTER_UPDATE: 13237 ast_string_field_set(p, fullcontact, peer->fullcontact); 13238 update_peer(peer, p->expiry); 13239 /* Say OK and ask subsystem to retransmit msg counter */ 13240 transmit_response_with_date(p, "200 OK", req); 13241 if (!ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY)) 13242 peer->lastmsgssent = -1; 13243 res = 0; 13244 break; 13245 } 13246 } 13247 13248 } 13249 } 13250 } 13251 if (!peer && sip_cfg.autocreatepeer) { 13252 /* Create peer if we have autocreate mode enabled */ 13253 peer = temp_peer(name); 13254 if (peer) { 13255 ao2_t_link(peers, peer, "link peer into peer table"); 13256 if (peer->addr.sin_addr.s_addr) { 13257 ao2_t_link(peers_by_ip, peer, "link peer into peers-by-ip table"); 13258 } 13259 13260 if (sip_cancel_destroy(p)) 13261 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 13262 switch (parse_register_contact(p, peer, req)) { 13263 case PARSE_REGISTER_DENIED: 13264 ast_log(LOG_WARNING, "Registration denied because of contact ACL\n"); 13265 transmit_response_with_date(p, "403 Forbidden (ACL)", req); 13266 peer->lastmsgssent = -1; 13267 res = 0; 13268 break; 13269 case PARSE_REGISTER_FAILED: 13270 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 13271 transmit_response_with_date(p, "400 Bad Request", req); 13272 peer->lastmsgssent = -1; 13273 res = 0; 13274 break; 13275 case PARSE_REGISTER_QUERY: 13276 ast_string_field_set(p, fullcontact, peer->fullcontact); 13277 transmit_response_with_date(p, "200 OK", req); 13278 peer->lastmsgssent = -1; 13279 res = 0; 13280 break; 13281 case PARSE_REGISTER_UPDATE: 13282 ast_string_field_set(p, fullcontact, peer->fullcontact); 13283 /* Say OK and ask subsystem to retransmit msg counter */ 13284 transmit_response_with_date(p, "200 OK", req); 13285 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\nPort: %d\r\n", peer->name, ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); 13286 peer->lastmsgssent = -1; 13287 res = 0; 13288 break; 13289 } 13290 } 13291 } 13292 if (!peer && sip_cfg.alwaysauthreject) { 13293 /* If we found a peer, we transmit a 100 Trying. Therefore, if we're 13294 * trying to avoid leaking information, we MUST also transmit the same 13295 * response when we DON'T find a peer. */ 13296 transmit_response(p, "100 Trying", req); 13297 /* Insert a fake delay between the 100 and the subsequent failure. */ 13298 sched_yield(); 13299 } 13300 if (!res) { 13301 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 13302 } 13303 if (res < 0) { 13304 switch (res) { 13305 case AUTH_SECRET_FAILED: 13306 /* Wrong password in authentication. Go away, don't try again until you fixed it */ 13307 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 13308 if (global_authfailureevents) 13309 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Rejected\r\nCause: AUTH_SECRET_FAILED\r\nAddress: %s\r\nPort: %d\r\n", 13310 name, ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); 13311 break; 13312 case AUTH_USERNAME_MISMATCH: 13313 /* Username and digest username does not match. 13314 Asterisk uses the From: username for authentication. We need the 13315 devices to use the same authentication user name until we support 13316 proper authentication by digest auth name */ 13317 case AUTH_NOT_FOUND: 13318 case AUTH_PEER_NOT_DYNAMIC: 13319 case AUTH_ACL_FAILED: 13320 if (sip_cfg.alwaysauthreject) { 13321 transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE); 13322 if (global_authfailureevents) { 13323 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Rejected\r\nCause: %s\r\nAddress: %s\r\nPort: %d\r\n", 13324 name, res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND", 13325 ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); 13326 } 13327 } else { 13328 /* URI not found */ 13329 if (res == AUTH_PEER_NOT_DYNAMIC) { 13330 transmit_response(p, "403 Forbidden", &p->initreq); 13331 if (global_authfailureevents) { 13332 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 13333 "ChannelType: SIP\r\n" 13334 "Peer: SIP/%s\r\n" 13335 "PeerStatus: Rejected\r\n" 13336 "Cause: AUTH_PEER_NOT_DYNAMIC\r\n" 13337 "Address: %s\r\n" 13338 "Port: %d\r\n", 13339 name, ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); 13340 } 13341 } else { 13342 transmit_response(p, "404 Not found", &p->initreq); 13343 if (global_authfailureevents) { 13344 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 13345 "ChannelType: SIP\r\n" 13346 "Peer: SIP/%s\r\n" 13347 "PeerStatus: Rejected\r\n" 13348 "Cause: %s\r\n" 13349 "Address: %s\r\n" 13350 "Port: %d\r\n", 13351 name, 13352 (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND", 13353 ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port)); 13354 } 13355 } 13356 } 13357 break; 13358 case AUTH_BAD_TRANSPORT: 13359 default: 13360 break; 13361 } 13362 } 13363 if (peer) 13364 unref_peer(peer, "register_verify: unref_peer: tossing stack peer pointer at end of func"); 13365 13366 return res; 13367 }
| static struct sip_registry* registry_addref | ( | struct sip_registry * | reg, | |
| char * | tag | |||
| ) | [static, read] |
Add object reference to SIP registry.
Definition at line 3253 of file chan_sip.c.
References ast_debug, ASTOBJ_REF, sip_registry::hostname, and sip_registry::refcount.
Referenced by handle_response_register(), sip_send_all_registers(), and transmit_register().
03254 { 03255 ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount + 1); 03256 return ASTOBJ_REF(reg); /* Add pointer to registry in packet */ 03257 }
| static void * registry_unref | ( | struct sip_registry * | reg, | |
| char * | tag | |||
| ) | [static] |
Definition at line 3245 of file chan_sip.c.
References ast_debug, ASTOBJ_UNREF, sip_registry::hostname, sip_registry::refcount, and sip_registry_destroy().
Referenced by __sip_destroy(), dialog_unlink_all(), handle_response_register(), reload_config(), sip_reg_timeout(), sip_register(), sip_registry_destroy(), sip_reregister(), sip_send_all_registers(), and transmit_register().
03246 { 03247 ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount - 1); 03248 ASTOBJ_UNREF(reg, sip_registry_destroy); 03249 return NULL; 03250 }
| static const char * regstate2str | ( | enum sipregistrystate | regstate | ) | [static] |
Convert registration state status to string.
Definition at line 11614 of file chan_sip.c.
References map_x_s().
Referenced by handle_response_register(), manager_show_registry(), sip_reg_timeout(), and sip_show_registry().
11615 { 11616 return map_x_s(regstatestrings, regstate, "Unknown"); 11617 }
| static int reload | ( | void | ) | [static] |
Part of Asterisk module interface.
Definition at line 25993 of file chan_sip.c.
References sip_reload().
25994 { 25995 if (sip_reload(0, 0, NULL)) 25996 return 0; 25997 return 1; 25998 }
| static int reload_config | ( | enum channelreloadreason | reason | ) | [static] |
Re-read SIP.conf config file.
< Type of address: IPv4
< Don't force proxy usage, use route: headers
< Reset default transport to zero here, default value later on
< Reset default primary transport to zero here, default value later on
< Keep track of hold status for a peer
< Match auth username if available instead of From: Default off.
< Default DTMF setting: RFC2833
< NAT support if requested by device with rport
< Allow re-invites
< Set up call forward on 482 Loop Detected
Definition at line 24558 of file chan_sip.c.
References ast_tcptls_session_args::accept_fd, add_realm_authentication(), add_sip_domain(), sip_peer::addr, sip_settings::allow_external_domains, sip_settings::allowguest, sip_settings::allowsubscribe, sip_settings::allowtransfer, sip_settings::alwaysauthreject, ao2_t_callback, ao2_t_link, ast_append_ha(), ast_category_browse(), AST_CERTFILE, ast_clear_flag, ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load, ast_context_find_or_create(), ast_copy_string(), ast_debug, ast_enable_packet_fragmentation(), ast_false(), ast_find_ourip(), AST_FLAGS_ALL, ast_free, ast_free_ha(), ast_get_version(), ast_inet_ntoa(), ast_jb_read_conf(), AST_LIST_EMPTY, ast_log(), AST_MAX_CONTEXT, ast_mutex_lock(), ast_mutex_unlock(), ast_netsock_set_qos(), ast_parse_allow_disallow(), ast_parse_arg(), AST_SCHED_DEL_UNREF, ast_set2_flag, ast_set_flag, ast_skip_blanks(), AST_SSL_DONT_VERIFY_SERVER, ast_ssl_setup(), AST_SSL_VERIFY_CLIENT, ast_str2cos(), ast_str2tos(), ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero(), ast_stun_request(), ast_tcptls_server_start(), ast_test_flag, ast_true(), ast_unload_realtime(), ast_variable_browse(), ast_variable_retrieve(), ast_verb, ASTOBJ_CONTAINER_DESTROYALL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, sip_settings::autocreatepeer, bindaddr, build_peer(), ast_tls_config::cafile, sip_settings::callevents, ast_tls_config::capath, ast_tls_config::certfile, CHANNEL_MODULE_LOAD, channelreloadreason2txt(), ast_tls_config::cipher, cleanup_stale_contexts(), clear_realm_authentication(), clear_sip_domains(), sip_settings::compactheaders, CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, context, DEFAULT_ALLOW_EXT_DOM, DEFAULT_ALLOWGUEST, DEFAULT_ALWAYSAUTHREJECT, DEFAULT_AUTOCREATEPEER, DEFAULT_CALLCOUNTER, DEFAULT_CALLERID, DEFAULT_CALLEVENTS, DEFAULT_COMPACTHEADERS, DEFAULT_CONTEXT, sip_settings::default_context, DEFAULT_COS_AUDIO, DEFAULT_COS_SIP, DEFAULT_COS_TEXT, DEFAULT_COS_VIDEO, DEFAULT_DEFAULT_EXPIRY, DEFAULT_MATCHEXTERNIPLOCALLY, DEFAULT_MAX_CALL_BITRATE, DEFAULT_MAX_EXPIRY, DEFAULT_MAX_SE, DEFAULT_MAXMS, DEFAULT_MIN_EXPIRY, DEFAULT_MIN_SE, DEFAULT_MOHINTERPRET, DEFAULT_MOHSUGGEST, DEFAULT_MWI_EXPIRY, DEFAULT_NOTIFYCID, DEFAULT_NOTIFYMIME, DEFAULT_NOTIFYRINGING, DEFAULT_PEDANTIC, default_prefs, DEFAULT_QUALIFY, DEFAULT_QUALIFY_GAP, DEFAULT_QUALIFY_PEERS, DEFAULT_QUALIFYFREQ, DEFAULT_REALM, DEFAULT_REGEXTENONQUALIFY, DEFAULT_REGISTRATION_TIMEOUT, DEFAULT_RTPKEEPALIVE, DEFAULT_SDPOWNER, DEFAULT_SDPSESSION, DEFAULT_SRVLOOKUP, sip_settings::default_subscribecontext, DEFAULT_T1MIN, DEFAULT_TIMER_T1, default_tls_cfg, DEFAULT_TOS_AUDIO, DEFAULT_TOS_SIP, DEFAULT_TOS_TEXT, DEFAULT_TOS_VIDEO, DEFAULT_USERAGENT, DEFAULT_VMEXTEN, dialog_unlink_all(), dialog_unref(), sip_settings::directrtpsetup, ast_tls_config::enabled, errno, EVENT_FLAG_SYSTEM, externip, FALSE, ast_tls_config::flags, sip_proxy::force, gen, global_jbconf, handle_common_options(), handle_t38_options(), IGNORE_CONTEXT, sip_settings::ignore_regexpire, inaddrcmp(), internip, sip_proxy::ip, ast_variable::lineno, ast_tcptls_session_args::local_address, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, sip_settings::matchexterniplocally, MAXHOSTNAMELEN, sip_proxy::name, ast_variable::name, netlock, ast_variable::next, sip_settings::notifycid, sip_settings::notifyhold, sip_settings::notifyringing, OBJ_NODATA, sip_settings::outboundproxy, PARSE_INADDR, sip_settings::pedanticsipchecking, peer_markall_func(), sip_settings::peer_rtupdate, proxy_update(), sip_settings::realm, sip_settings::regextenonqualify, registry_unref(), regl, sip_settings::rtautoclear, sip_settings::rtsave_sysname, S_OR, secret, SESSION_TIMER_MODE_ACCEPT, SESSION_TIMER_REFRESHER_UAS, sip_cfg, sip_debug_config, sip_debug_console, SIP_DIRECT_MEDIA, SIP_DOMAIN_AUTO, SIP_DOMAIN_CONFIG, SIP_DTMF_RFC2833, SIP_NAT_RFC3581, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_FAX_DETECT, SIP_PAGE2_FORWARD_LOOP_DETECTED, SIP_PAGE2_IGNORESDPVERSION, SIP_PAGE2_RTAUTOCLEAR, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, sip_parse_host(), sip_register(), sip_registry_destroy(), sip_subscribe_mwi(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, SIP_TYPE_PEER, SIP_TYPE_USER, SIP_USEREQPHONE, sip_request::socket, sip_settings::srvlookup, STANDARD_SIP_PORT, STANDARD_TLS_PORT, str2stmode(), str2strefresher(), strsep(), stunaddr, ast_tcptls_session_args::tls_cfg, TRANSFER_CLOSED, TRANSFER_OPENFORALL, sip_proxy::transport, TRUE, sip_peer::type, unref_peer(), and ast_variable::value.
Referenced by load_module(), and sip_do_reload().
24559 { 24560 struct ast_config *cfg, *ucfg; 24561 struct ast_variable *v; 24562 struct sip_peer *peer; 24563 char *cat, *stringp, *context, *oldregcontext; 24564 char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT]; 24565 struct ast_flags dummy[2]; 24566 struct ast_flags config_flags = { reason == CHANNEL_MODULE_LOAD ? 0 : ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) ? 0 : CONFIG_FLAG_FILEUNCHANGED }; 24567 int auto_sip_domains = FALSE; 24568 struct sockaddr_in old_bindaddr = bindaddr; 24569 int registry_count = 0, peer_count = 0; 24570 time_t run_start, run_end; 24571 24572 run_start = time(0); 24573 ast_unload_realtime("sipregs"); 24574 ast_unload_realtime("sippeers"); 24575 cfg = ast_config_load(config, config_flags); 24576 24577 /* We *must* have a config file otherwise stop immediately */ 24578 if (!cfg) { 24579 ast_log(LOG_NOTICE, "Unable to load config %s\n", config); 24580 return -1; 24581 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 24582 ucfg = ast_config_load("users.conf", config_flags); 24583 if (ucfg == CONFIG_STATUS_FILEUNCHANGED) { 24584 return 1; 24585 } else if (ucfg == CONFIG_STATUS_FILEINVALID) { 24586 ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n"); 24587 return 1; 24588 } 24589 /* Must reread both files, because one changed */ 24590 ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); 24591 if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) { 24592 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config); 24593 ast_config_destroy(ucfg); 24594 return 1; 24595 } 24596 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 24597 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config); 24598 return 1; 24599 } else { 24600 ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); 24601 if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) { 24602 ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n"); 24603 ast_config_destroy(cfg); 24604 return 1; 24605 } 24606 } 24607 24608 /* Initialize tcp sockets */ 24609 memset(&sip_tcp_desc.local_address, 0, sizeof(sip_tcp_desc.local_address)); 24610 memset(&sip_tls_desc.local_address, 0, sizeof(sip_tls_desc.local_address)); 24611 24612 ast_free_ha(global_contact_ha); 24613 global_contact_ha = NULL; 24614 24615 default_tls_cfg.enabled = FALSE; /* Default: Disable TLS */ 24616 24617 sip_tcp_desc.local_address.sin_port = htons(STANDARD_SIP_PORT); 24618 sip_tls_desc.local_address.sin_port = htons(STANDARD_TLS_PORT); 24619 24620 if (reason != CHANNEL_MODULE_LOAD) { 24621 ast_debug(4, "--------------- SIP reload started\n"); 24622 24623 clear_realm_authentication(authl); 24624 clear_sip_domains(); 24625 authl = NULL; 24626 24627 /* First, destroy all outstanding registry calls */ 24628 /* This is needed, since otherwise active registry entries will not be destroyed */ 24629 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { /* regl is locked */ 24630 24631 ASTOBJ_RDLOCK(iterator); /* now regl is locked, and the object is also locked */ 24632 if (iterator->call) { 24633 ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", iterator->username, iterator->hostname); 24634 /* This will also remove references to the registry */ 24635 dialog_unlink_all(iterator->call, TRUE, TRUE); 24636 iterator->call = dialog_unref(iterator->call, "remove iterator->call from registry traversal"); 24637 } 24638 if (iterator->expire > -1) { 24639 AST_SCHED_DEL_UNREF(sched, iterator->expire, registry_unref(iterator, "reg ptr unref from reload config")); 24640 } 24641 if (iterator->timeout > -1) { 24642 AST_SCHED_DEL_UNREF(sched, iterator->timeout, registry_unref(iterator, "reg ptr unref from reload config")); 24643 } 24644 ASTOBJ_UNLOCK(iterator); 24645 24646 } while(0)); 24647 24648 /* Then, actually destroy users and registry */ 24649 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 24650 ast_debug(4, "--------------- Done destroying registry list\n"); 24651 ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, NULL, "callback to mark all peers"); 24652 } 24653 24654 /* Reset certificate handling for TLS sessions */ 24655 if (reason != CHANNEL_MODULE_LOAD) { 24656 ast_free(default_tls_cfg.certfile); 24657 ast_free(default_tls_cfg.cipher); 24658 ast_free(default_tls_cfg.cafile); 24659 ast_free(default_tls_cfg.capath); 24660 } 24661 default_tls_cfg.certfile = ast_strdup(AST_CERTFILE); /*XXX Not sure if this is useful */ 24662 default_tls_cfg.cipher = ast_strdup(""); 24663 default_tls_cfg.cafile = ast_strdup(""); 24664 default_tls_cfg.capath = ast_strdup(""); 24665 24666 24667 /* Initialize copy of current global_regcontext for later use in removing stale contexts */ 24668 ast_copy_string(oldcontexts, global_regcontext, sizeof(oldcontexts)); 24669 oldregcontext = oldcontexts; 24670 24671 /* Clear all flags before setting default values */ 24672 /* Preserve debugging settings for console */ 24673 sipdebug &= sip_debug_console; 24674 ast_clear_flag(&global_flags[0], AST_FLAGS_ALL); 24675 ast_clear_flag(&global_flags[1], AST_FLAGS_ALL); 24676 24677 /* Reset IP addresses */ 24678 memset(&bindaddr, 0, sizeof(bindaddr)); 24679 memset(&stunaddr, 0, sizeof(stunaddr)); 24680 memset(&internip, 0, sizeof(internip)); 24681 24682 /* Free memory for local network address mask */ 24683 ast_free_ha(localaddr); 24684 memset(&localaddr, 0, sizeof(localaddr)); 24685 memset(&externip, 0, sizeof(externip)); 24686 memset(&default_prefs, 0 , sizeof(default_prefs)); 24687 memset(&sip_cfg.outboundproxy, 0, sizeof(struct sip_proxy)); 24688 sip_cfg.outboundproxy.ip.sin_port = htons(STANDARD_SIP_PORT); 24689 sip_cfg.outboundproxy.ip.sin_family = AF_INET; /*!< Type of address: IPv4 */ 24690 sip_cfg.outboundproxy.force = FALSE; /*!< Don't force proxy usage, use route: headers */ 24691 default_transports = 0; /*!< Reset default transport to zero here, default value later on */ 24692 default_primary_transport = 0; /*!< Reset default primary transport to zero here, default value later on */ 24693 ourport_tcp = STANDARD_SIP_PORT; 24694 ourport_tls = STANDARD_TLS_PORT; 24695 bindaddr.sin_port = htons(STANDARD_SIP_PORT); 24696 sip_cfg.srvlookup = DEFAULT_SRVLOOKUP; 24697 global_tos_sip = DEFAULT_TOS_SIP; 24698 global_tos_audio = DEFAULT_TOS_AUDIO; 24699 global_tos_video = DEFAULT_TOS_VIDEO; 24700 global_tos_text = DEFAULT_TOS_TEXT; 24701 global_cos_sip = DEFAULT_COS_SIP; 24702 global_cos_audio = DEFAULT_COS_AUDIO; 24703 global_cos_video = DEFAULT_COS_VIDEO; 24704 global_cos_text = DEFAULT_COS_TEXT; 24705 24706 externhost[0] = '\0'; /* External host name (for behind NAT DynDNS support) */ 24707 externexpire = 0; /* Expiration for DNS re-issuing */ 24708 externrefresh = 10; 24709 24710 /* Reset channel settings to default before re-configuring */ 24711 sip_cfg.allow_external_domains = DEFAULT_ALLOW_EXT_DOM; /* Allow external invites */ 24712 global_regcontext[0] = '\0'; 24713 sip_cfg.regextenonqualify = DEFAULT_REGEXTENONQUALIFY; 24714 sip_cfg.notifyringing = DEFAULT_NOTIFYRINGING; 24715 sip_cfg.notifycid = DEFAULT_NOTIFYCID; 24716 sip_cfg.notifyhold = FALSE; /*!< Keep track of hold status for a peer */ 24717 sip_cfg.directrtpsetup = FALSE; /* Experimental feature, disabled by default */ 24718 sip_cfg.alwaysauthreject = DEFAULT_ALWAYSAUTHREJECT; 24719 sip_cfg.allowsubscribe = FALSE; 24720 snprintf(global_useragent, sizeof(global_useragent), "%s %s", DEFAULT_USERAGENT, ast_get_version()); 24721 snprintf(global_sdpsession, sizeof(global_sdpsession), "%s %s", DEFAULT_SDPSESSION, ast_get_version()); 24722 snprintf(global_sdpowner, sizeof(global_sdpowner), "%s", DEFAULT_SDPOWNER); 24723 global_prematuremediafilter = TRUE; 24724 ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime)); 24725 ast_copy_string(sip_cfg.realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM), sizeof(sip_cfg.realm)); 24726 ast_copy_string(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid)); 24727 sip_cfg.compactheaders = DEFAULT_COMPACTHEADERS; 24728 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 24729 global_regattempts_max = 0; 24730 sip_cfg.pedanticsipchecking = DEFAULT_PEDANTIC; 24731 sip_cfg.autocreatepeer = DEFAULT_AUTOCREATEPEER; 24732 global_autoframing = 0; 24733 sip_cfg.allowguest = DEFAULT_ALLOWGUEST; 24734 global_callcounter = DEFAULT_CALLCOUNTER; 24735 global_match_auth_username = FALSE; /*!< Match auth username if available instead of From: Default off. */ 24736 global_rtptimeout = 0; 24737 global_rtpholdtimeout = 0; 24738 global_rtpkeepalive = DEFAULT_RTPKEEPALIVE; 24739 sip_cfg.allowtransfer = TRANSFER_OPENFORALL; /* Merrily accept all transfers by default */ 24740 sip_cfg.rtautoclear = 120; 24741 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE); /* Default for all devices: TRUE */ 24742 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP); /* Default for all devices: TRUE */ 24743 sip_cfg.peer_rtupdate = TRUE; 24744 global_dynamic_exclude_static = 0; /* Exclude static peers */ 24745 24746 /* Session-Timers */ 24747 global_st_mode = SESSION_TIMER_MODE_ACCEPT; 24748 global_st_refresher = SESSION_TIMER_REFRESHER_UAS; 24749 global_min_se = DEFAULT_MIN_SE; 24750 global_max_se = DEFAULT_MAX_SE; 24751 24752 /* Peer poking settings */ 24753 global_qualify_gap = DEFAULT_QUALIFY_GAP; 24754 global_qualify_peers = DEFAULT_QUALIFY_PEERS; 24755 24756 /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for devices */ 24757 ast_copy_string(sip_cfg.default_context, DEFAULT_CONTEXT, sizeof(sip_cfg.default_context)); 24758 sip_cfg.default_subscribecontext[0] = '\0'; 24759 default_language[0] = '\0'; 24760 default_fromdomain[0] = '\0'; 24761 default_qualify = DEFAULT_QUALIFY; 24762 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 24763 ast_copy_string(default_mohinterpret, DEFAULT_MOHINTERPRET, sizeof(default_mohinterpret)); 24764 ast_copy_string(default_mohsuggest, DEFAULT_MOHSUGGEST, sizeof(default_mohsuggest)); 24765 ast_copy_string(default_vmexten, DEFAULT_VMEXTEN, sizeof(default_vmexten)); 24766 ast_set_flag(&global_flags[0], SIP_DTMF_RFC2833); /*!< Default DTMF setting: RFC2833 */ 24767 ast_set_flag(&global_flags[0], SIP_NAT_RFC3581); /*!< NAT support if requested by device with rport */ 24768 ast_set_flag(&global_flags[0], SIP_DIRECT_MEDIA); /*!< Allow re-invites */ 24769 ast_set_flag(&global_flags[1], SIP_PAGE2_FORWARD_LOOP_DETECTED); /*!< Set up call forward on 482 Loop Detected */ 24770 24771 /* Debugging settings, always default to off */ 24772 dumphistory = FALSE; 24773 recordhistory = FALSE; 24774 sipdebug &= ~sip_debug_config; 24775 24776 /* Misc settings for the channel */ 24777 global_relaxdtmf = FALSE; 24778 sip_cfg.callevents = DEFAULT_CALLEVENTS; 24779 global_authfailureevents = FALSE; 24780 global_t1 = DEFAULT_TIMER_T1; 24781 global_timer_b = 64 * DEFAULT_TIMER_T1; 24782 global_t1min = DEFAULT_T1MIN; 24783 global_qualifyfreq = DEFAULT_QUALIFYFREQ; 24784 global_t38_maxdatagram = -1; 24785 global_shrinkcallerid = 1; 24786 24787 sip_cfg.matchexterniplocally = DEFAULT_MATCHEXTERNIPLOCALLY; 24788 24789 /* Copy the default jb config over global_jbconf */ 24790 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 24791 24792 ast_clear_flag(&global_flags[1], SIP_PAGE2_FAX_DETECT); 24793 ast_clear_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 24794 ast_clear_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT); 24795 ast_clear_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION); 24796 24797 24798 /* Read the [general] config section of sip.conf (or from realtime config) */ 24799 for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { 24800 if (handle_common_options(&global_flags[0], &dummy[0], v)) 24801 continue; 24802 if (handle_t38_options(&global_flags[0], &dummy[0], v, &global_t38_maxdatagram)) { 24803 continue; 24804 } 24805 /* handle jb conf */ 24806 if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) 24807 continue; 24808 24809 if (!strcasecmp(v->name, "context")) { 24810 ast_copy_string(sip_cfg.default_context, v->value, sizeof(sip_cfg.default_context)); 24811 } else if (!strcasecmp(v->name, "subscribecontext")) { 24812 ast_copy_string(sip_cfg.default_subscribecontext, v->value, sizeof(sip_cfg.default_subscribecontext)); 24813 } else if (!strcasecmp(v->name, "callcounter")) { 24814 global_callcounter = ast_true(v->value) ? 1 : 0; 24815 } else if (!strcasecmp(v->name, "allowguest")) { 24816 sip_cfg.allowguest = ast_true(v->value) ? 1 : 0; 24817 } else if (!strcasecmp(v->name, "realm")) { 24818 ast_copy_string(sip_cfg.realm, v->value, sizeof(sip_cfg.realm)); 24819 } else if (!strcasecmp(v->name, "useragent")) { 24820 ast_copy_string(global_useragent, v->value, sizeof(global_useragent)); 24821 ast_debug(1, "Setting SIP channel User-Agent Name to %s\n", global_useragent); 24822 } else if (!strcasecmp(v->name, "sdpsession")) { 24823 ast_copy_string(global_sdpsession, v->value, sizeof(global_sdpsession)); 24824 } else if (!strcasecmp(v->name, "sdpowner")) { 24825 /* Field cannot contain spaces */ 24826 if (!strstr(v->value, " ")) 24827 ast_copy_string(global_sdpowner, v->value, sizeof(global_sdpowner)); 24828 else 24829 ast_log(LOG_WARNING, "'%s' must not contain spaces at line %d. Using default.\n", v->value, v->lineno); 24830 } else if (!strcasecmp(v->name, "allowtransfer")) { 24831 sip_cfg.allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 24832 } else if (!strcasecmp(v->name, "rtcachefriends")) { 24833 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS); 24834 } else if (!strcasecmp(v->name, "rtsavesysname")) { 24835 sip_cfg.rtsave_sysname = ast_true(v->value); 24836 } else if (!strcasecmp(v->name, "rtupdate")) { 24837 sip_cfg.peer_rtupdate = ast_true(v->value); 24838 } else if (!strcasecmp(v->name, "ignoreregexpire")) { 24839 sip_cfg.ignore_regexpire = ast_true(v->value); 24840 } else if (!strcasecmp(v->name, "timert1")) { 24841 /* Defaults to 500ms, but RFC 3261 states that it is recommended 24842 * for the value to be set higher, though a lower value is only 24843 * allowed on private networks unconnected to the Internet. */ 24844 global_t1 = atoi(v->value); 24845 /* Note that timer B is dependent on the value of T1 */ 24846 global_timer_b = global_t1 * 64; 24847 } else if (!strcasecmp(v->name, "t1min")) { 24848 global_t1min = atoi(v->value); 24849 } else if (!strcasecmp(v->name, "transport") && !ast_strlen_zero(v->value)) { 24850 char *val = ast_strdupa(v->value); 24851 char *trans; 24852 24853 while ((trans = strsep(&val, ","))) { 24854 trans = ast_skip_blanks(trans); 24855 24856 if (!strncasecmp(trans, "udp", 3)) 24857 default_transports |= SIP_TRANSPORT_UDP; 24858 else if (!strncasecmp(trans, "tcp", 3)) 24859 default_transports |= SIP_TRANSPORT_TCP; 24860 else if (!strncasecmp(trans, "tls", 3)) 24861 default_transports |= SIP_TRANSPORT_TLS; 24862 else 24863 ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, udp will be used.\n", trans); 24864 if (default_primary_transport == 0) { 24865 default_primary_transport = default_transports; 24866 } 24867 } 24868 } else if (!strcasecmp(v->name, "tcpenable")) { 24869 sip_tcp_desc.local_address.sin_family = ast_false(v->value) ? 0 : AF_INET; 24870 ast_debug(2, "Enabling TCP socket for listening\n"); 24871 } else if (!strcasecmp(v->name, "tcpbindaddr")) { 24872 int family = sip_tcp_desc.local_address.sin_family; 24873 if (ast_parse_arg(v->value, PARSE_INADDR, &sip_tcp_desc.local_address)) 24874 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", v->name, v->value, v->lineno, config); 24875 sip_tcp_desc.local_address.sin_family = family; 24876 ast_debug(2, "Setting TCP socket address to %s\n", v->value); 24877 } else if (!strcasecmp(v->name, "tlsenable")) { 24878 default_tls_cfg.enabled = ast_true(v->value) ? TRUE : FALSE; 24879 sip_tls_desc.local_address.sin_family = AF_INET; 24880 } else if (!strcasecmp(v->name, "tlscertfile")) { 24881 ast_free(default_tls_cfg.certfile); 24882 default_tls_cfg.certfile = ast_strdup(v->value); 24883 } else if (!strcasecmp(v->name, "tlscipher")) { 24884 ast_free(default_tls_cfg.cipher); 24885 default_tls_cfg.cipher = ast_strdup(v->value); 24886 } else if (!strcasecmp(v->name, "tlscafile")) { 24887 ast_free(default_tls_cfg.cafile); 24888 default_tls_cfg.cafile = ast_strdup(v->value); 24889 } else if (!strcasecmp(v->name, "tlscapath")) { 24890 ast_free(default_tls_cfg.capath); 24891 default_tls_cfg.capath = ast_strdup(v->value); 24892 } else if (!strcasecmp(v->name, "tlsverifyclient")) { 24893 ast_set2_flag(&default_tls_cfg.flags, ast_true(v->value), AST_SSL_VERIFY_CLIENT); 24894 } else if (!strcasecmp(v->name, "tlsdontverifyserver")) { 24895 ast_set2_flag(&default_tls_cfg.flags, ast_true(v->value), AST_SSL_DONT_VERIFY_SERVER); 24896 } else if (!strcasecmp(v->name, "tlsbindaddr")) { 24897 if (ast_parse_arg(v->value, PARSE_INADDR, &sip_tls_desc.local_address)) 24898 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", v->name, v->value, v->lineno, config); 24899 } else if (!strcasecmp(v->name, "dynamic_exclude_static") || !strcasecmp(v->name, "dynamic_excludes_static")) { 24900 global_dynamic_exclude_static = ast_true(v->value); 24901 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 24902 int ha_error = 0; 24903 global_contact_ha = ast_append_ha(v->name + 7, v->value, global_contact_ha, &ha_error); 24904 if (ha_error) { 24905 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 24906 } 24907 } else if (!strcasecmp(v->name, "rtautoclear")) { 24908 int i = atoi(v->value); 24909 if (i > 0) 24910 sip_cfg.rtautoclear = i; 24911 else 24912 i = 0; 24913 ast_set2_flag(&global_flags[1], i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR); 24914 } else if (!strcasecmp(v->name, "usereqphone")) { 24915 ast_set2_flag(&global_flags[0], ast_true(v->value), SIP_USEREQPHONE); 24916 } else if (!strcasecmp(v->name, "prematuremedia")) { 24917 global_prematuremediafilter = ast_true(v->value); 24918 } else if (!strcasecmp(v->name, "relaxdtmf")) { 24919 global_relaxdtmf = ast_true(v->value); 24920 } else if (!strcasecmp(v->name, "vmexten")) { 24921 ast_copy_string(default_vmexten, v->value, sizeof(default_vmexten)); 24922 } else if (!strcasecmp(v->name, "rtptimeout")) { 24923 if ((sscanf(v->value, "%30d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) { 24924 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 24925 global_rtptimeout = 0; 24926 } 24927 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 24928 if ((sscanf(v->value, "%30d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) { 24929 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 24930 global_rtpholdtimeout = 0; 24931 } 24932 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 24933 if ((sscanf(v->value, "%30d", &global_rtpkeepalive) != 1) || (global_rtpkeepalive < 0)) { 24934 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 24935 global_rtpkeepalive = DEFAULT_RTPKEEPALIVE; 24936 } 24937 } else if (!strcasecmp(v->name, "compactheaders")) { 24938 sip_cfg.compactheaders = ast_true(v->value); 24939 } else if (!strcasecmp(v->name, "notifymimetype")) { 24940 ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime)); 24941 } else if (!strcasecmp(v->name, "directrtpsetup")) { 24942 sip_cfg.directrtpsetup = ast_true(v->value); 24943 } else if (!strcasecmp(v->name, "notifyringing")) { 24944 sip_cfg.notifyringing = ast_true(v->value); 24945 } else if (!strcasecmp(v->name, "notifyhold")) { 24946 sip_cfg.notifyhold = ast_true(v->value); 24947 } else if (!strcasecmp(v->name, "notifycid")) { 24948 if (!strcasecmp(v->value, "ignore-context")) { 24949 sip_cfg.notifycid = IGNORE_CONTEXT; 24950 } else { 24951 sip_cfg.notifycid = ast_true(v->value); 24952 } 24953 } else if (!strcasecmp(v->name, "alwaysauthreject")) { 24954 sip_cfg.alwaysauthreject = ast_true(v->value); 24955 } else if (!strcasecmp(v->name, "mohinterpret")) { 24956 ast_copy_string(default_mohinterpret, v->value, sizeof(default_mohinterpret)); 24957 } else if (!strcasecmp(v->name, "mohsuggest")) { 24958 ast_copy_string(default_mohsuggest, v->value, sizeof(default_mohsuggest)); 24959 } else if (!strcasecmp(v->name, "language")) { 24960 ast_copy_string(default_language, v->value, sizeof(default_language)); 24961 } else if (!strcasecmp(v->name, "regcontext")) { 24962 ast_copy_string(newcontexts, v->value, sizeof(newcontexts)); 24963 stringp = newcontexts; 24964 /* Let's remove any contexts that are no longer defined in regcontext */ 24965 cleanup_stale_contexts(stringp, oldregcontext); 24966 /* Create contexts if they don't exist already */ 24967 while ((context = strsep(&stringp, "&"))) { 24968 ast_copy_string(used_context, context, sizeof(used_context)); 24969 ast_context_find_or_create(NULL, NULL, context, "SIP"); 24970 } 24971 ast_copy_string(global_regcontext, v->value, sizeof(global_regcontext)); 24972 } else if (!strcasecmp(v->name, "regextenonqualify")) { 24973 sip_cfg.regextenonqualify = ast_true(v->value); 24974 } else if (!strcasecmp(v->name, "callerid")) { 24975 ast_copy_string(default_callerid, v->value, sizeof(default_callerid)); 24976 } else if (!strcasecmp(v->name, "fromdomain")) { 24977 ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain)); 24978 } else if (!strcasecmp(v->name, "outboundproxy")) { 24979 int portnum; 24980 char *tok, *proxyname; 24981 24982 if (ast_strlen_zero(v->value)) { 24983 ast_log(LOG_WARNING, "no value given for outbound proxy on line %d of sip.conf.", v->lineno); 24984 continue; 24985 } 24986 24987 tok = ast_skip_blanks(strtok(ast_strdupa(v->value), ",")); 24988 24989 sip_parse_host(tok, v->lineno, &proxyname, &portnum, &sip_cfg.outboundproxy.transport); 24990 24991 sip_cfg.outboundproxy.ip.sin_port = htons(portnum); 24992 24993 if ((tok = strtok(NULL, ","))) { 24994 sip_cfg.outboundproxy.force = !strncasecmp(ast_skip_blanks(tok), "force", 5); 24995 } else { 24996 sip_cfg.outboundproxy.force = FALSE; 24997 } 24998 24999 if (ast_strlen_zero(proxyname)) { 25000 ast_log(LOG_WARNING, "you must specify a name for the outboundproxy on line %d of sip.conf.", v->lineno); 25001 sip_cfg.outboundproxy.name[0] = '\0'; 25002 continue; 25003 } 25004 25005 ast_copy_string(sip_cfg.outboundproxy.name, proxyname, sizeof(sip_cfg.outboundproxy.name)); 25006 25007 proxy_update(&sip_cfg.outboundproxy); 25008 } else if (!strcasecmp(v->name, "autocreatepeer")) { 25009 sip_cfg.autocreatepeer = ast_true(v->value); 25010 } else if (!strcasecmp(v->name, "match_auth_username")) { 25011 global_match_auth_username = ast_true(v->value); 25012 } else if (!strcasecmp(v->name, "srvlookup")) { 25013 sip_cfg.srvlookup = ast_true(v->value); 25014 } else if (!strcasecmp(v->name, "pedantic")) { 25015 sip_cfg.pedanticsipchecking = ast_true(v->value); 25016 } else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) { 25017 max_expiry = atoi(v->value); 25018 if (max_expiry < 1) 25019 max_expiry = DEFAULT_MAX_EXPIRY; 25020 } else if (!strcasecmp(v->name, "minexpirey") || !strcasecmp(v->name, "minexpiry")) { 25021 min_expiry = atoi(v->value); 25022 if (min_expiry < 1) 25023 min_expiry = DEFAULT_MIN_EXPIRY; 25024 } else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) { 25025 default_expiry = atoi(v->value); 25026 if (default_expiry < 1) 25027 default_expiry = DEFAULT_DEFAULT_EXPIRY; 25028 } else if (!strcasecmp(v->name, "mwiexpiry") || !strcasecmp(v->name, "mwiexpirey")) { 25029 mwi_expiry = atoi(v->value); 25030 if (mwi_expiry < 1) 25031 mwi_expiry = DEFAULT_MWI_EXPIRY; 25032 } else if (!strcasecmp(v->name, "sipdebug")) { 25033 if (ast_true(v->value)) 25034 sipdebug |= sip_debug_config; 25035 } else if (!strcasecmp(v->name, "dumphistory")) { 25036 dumphistory = ast_true(v->value); 25037 } else if (!strcasecmp(v->name, "recordhistory")) { 25038 recordhistory = ast_true(v->value); 25039 } else if (!strcasecmp(v->name, "registertimeout")) { 25040 global_reg_timeout = atoi(v->value); 25041 if (global_reg_timeout < 1) 25042 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 25043 } else if (!strcasecmp(v->name, "registerattempts")) { 25044 global_regattempts_max = atoi(v->value); 25045 } else if (!strcasecmp(v->name, "stunaddr")) { 25046 stunaddr.sin_port = htons(3478); 25047 if (ast_parse_arg(v->value, PARSE_INADDR, &stunaddr)) 25048 ast_log(LOG_WARNING, "Invalid STUN server address: %s\n", v->value); 25049 externexpire = time(NULL); 25050 } else if (!strcasecmp(v->name, "bindaddr") || !strcasecmp(v->name, "udpbindaddr")) { 25051 if (ast_parse_arg(v->value, PARSE_INADDR, &bindaddr)) 25052 ast_log(LOG_WARNING, "Invalid address: %s\n", v->value); 25053 } else if (!strcasecmp(v->name, "localnet")) { 25054 struct ast_ha *na; 25055 int ha_error = 0; 25056 25057 if (!(na = ast_append_ha("d", v->value, localaddr, &ha_error))) 25058 ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value); 25059 else 25060 localaddr = na; 25061 if (ha_error) 25062 ast_log(LOG_ERROR, "Bad localnet configuration value line %d : %s\n", v->lineno, v->value); 25063 } else if (!strcasecmp(v->name, "externip")) { 25064 if (ast_parse_arg(v->value, PARSE_INADDR, &externip)) 25065 ast_log(LOG_WARNING, "Invalid address for externip keyword: %s\n", v->value); 25066 externexpire = 0; 25067 /* If no port was specified use the value of bindport */ 25068 if (!externip.sin_port) 25069 externip.sin_port = bindaddr.sin_port; 25070 } else if (!strcasecmp(v->name, "externhost")) { 25071 ast_copy_string(externhost, v->value, sizeof(externhost)); 25072 if (ast_parse_arg(externhost, PARSE_INADDR, &externip)) 25073 ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost); 25074 externexpire = time(NULL); 25075 /* If no port was specified use the value of bindport */ 25076 if (!externip.sin_port) 25077 externip.sin_port = bindaddr.sin_port; 25078 } else if (!strcasecmp(v->name, "externrefresh")) { 25079 if (sscanf(v->value, "%30d", &externrefresh) != 1) { 25080 ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno); 25081 externrefresh = 10; 25082 } 25083 } else if (!strcasecmp(v->name, "allow")) { 25084 int error = ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, TRUE); 25085 if (error) 25086 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 25087 } else if (!strcasecmp(v->name, "disallow")) { 25088 int error = ast_parse_allow_disallow(&default_prefs, &global_capability, v->value, FALSE); 25089 if (error) 25090 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 25091 } else if (!strcasecmp(v->name, "autoframing")) { 25092 global_autoframing = ast_true(v->value); 25093 } else if (!strcasecmp(v->name, "allowexternaldomains")) { 25094 sip_cfg.allow_external_domains = ast_true(v->value); 25095 } else if (!strcasecmp(v->name, "autodomain")) { 25096 auto_sip_domains = ast_true(v->value); 25097 } else if (!strcasecmp(v->name, "domain")) { 25098 char *domain = ast_strdupa(v->value); 25099 char *cntx = strchr(domain, ','); 25100 25101 if (cntx) 25102 *cntx++ = '\0'; 25103 25104 if (ast_strlen_zero(cntx)) 25105 ast_debug(1, "No context specified at line %d for domain '%s'\n", v->lineno, domain); 25106 if (ast_strlen_zero(domain)) 25107 ast_log(LOG_WARNING, "Empty domain specified at line %d\n", v->lineno); 25108 else 25109 add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, cntx ? ast_strip(cntx) : ""); 25110 } else if (!strcasecmp(v->name, "register")) { 25111 if (sip_register(v->value, v->lineno) == 0) 25112 registry_count++; 25113 } else if (!strcasecmp(v->name, "mwi")) { 25114 sip_subscribe_mwi(v->value, v->lineno); 25115 } else if (!strcasecmp(v->name, "tos_sip")) { 25116 if (ast_str2tos(v->value, &global_tos_sip)) 25117 ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, refer to QoS documentation\n", v->lineno); 25118 } else if (!strcasecmp(v->name, "tos_audio")) { 25119 if (ast_str2tos(v->value, &global_tos_audio)) 25120 ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno); 25121 } else if (!strcasecmp(v->name, "tos_video")) { 25122 if (ast_str2tos(v->value, &global_tos_video)) 25123 ast_log(LOG_WARNING, "Invalid tos_video value at line %d, refer to QoS documentation\n", v->lineno); 25124 } else if (!strcasecmp(v->name, "tos_text")) { 25125 if (ast_str2tos(v->value, &global_tos_text)) 25126 ast_log(LOG_WARNING, "Invalid tos_text value at line %d, refer to QoS documentation\n", v->lineno); 25127 } else if (!strcasecmp(v->name, "cos_sip")) { 25128 if (ast_str2cos(v->value, &global_cos_sip)) 25129 ast_log(LOG_WARNING, "Invalid cos_sip value at line %d, refer to QoS documentation\n", v->lineno); 25130 } else if (!strcasecmp(v->name, "cos_audio")) { 25131 if (ast_str2cos(v->value, &global_cos_audio)) 25132 ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno); 25133 } else if (!strcasecmp(v->name, "cos_video")) { 25134 if (ast_str2cos(v->value, &global_cos_video)) 25135 ast_log(LOG_WARNING, "Invalid cos_video value at line %d, refer to QoS documentation\n", v->lineno); 25136 } else if (!strcasecmp(v->name, "cos_text")) { 25137 if (ast_str2cos(v->value, &global_cos_text)) 25138 ast_log(LOG_WARNING, "Invalid cos_text value at line %d, refer to QoS documentation\n", v->lineno); 25139 } else if (!strcasecmp(v->name, "bindport")) { 25140 int i; 25141 if (sscanf(v->value, "%5d", &i) == 1) { 25142 bindaddr.sin_port = htons(i); 25143 } else { 25144 ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config); 25145 } 25146 } else if (!strcasecmp(v->name, "qualify")) { 25147 if (!strcasecmp(v->value, "no")) { 25148 default_qualify = 0; 25149 } else if (!strcasecmp(v->value, "yes")) { 25150 default_qualify = DEFAULT_MAXMS; 25151 } else if (sscanf(v->value, "%30d", &default_qualify) != 1) { 25152 ast_log(LOG_WARNING, "Qualification default should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", v->lineno); 25153 default_qualify = 0; 25154 } 25155 } else if (!strcasecmp(v->name, "qualifyfreq")) { 25156 int i; 25157 if (sscanf(v->value, "%30d", &i) == 1) 25158 global_qualifyfreq = i * 1000; 25159 else { 25160 ast_log(LOG_WARNING, "Invalid qualifyfreq number '%s' at line %d of %s\n", v->value, v->lineno, config); 25161 global_qualifyfreq = DEFAULT_QUALIFYFREQ; 25162 } 25163 } else if (!strcasecmp(v->name, "callevents")) { 25164 sip_cfg.callevents = ast_true(v->value); 25165 } else if (!strcasecmp(v->name, "authfailureevents")) { 25166 global_authfailureevents = ast_true(v->value); 25167 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 25168 default_maxcallbitrate = atoi(v->value); 25169 if (default_maxcallbitrate < 0) 25170 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 25171 } else if (!strcasecmp(v->name, "matchexterniplocally")) { 25172 sip_cfg.matchexterniplocally = ast_true(v->value); 25173 } else if (!strcasecmp(v->name, "session-timers")) { 25174 int i = (int) str2stmode(v->value); 25175 if (i < 0) { 25176 ast_log(LOG_WARNING, "Invalid session-timers '%s' at line %d of %s\n", v->value, v->lineno, config); 25177 global_st_mode = SESSION_TIMER_MODE_ACCEPT; 25178 } else { 25179 global_st_mode = i; 25180 } 25181 } else if (!strcasecmp(v->name, "session-expires")) { 25182 if (sscanf(v->value, "%30d", &global_max_se) != 1) { 25183 ast_log(LOG_WARNING, "Invalid session-expires '%s' at line %d of %s\n", v->value, v->lineno, config); 25184 global_max_se = DEFAULT_MAX_SE; 25185 } 25186 } else if (!strcasecmp(v->name, "session-minse")) { 25187 if (sscanf(v->value, "%30d", &global_min_se) != 1) { 25188 ast_log(LOG_WARNING, "Invalid session-minse '%s' at line %d of %s\n", v->value, v->lineno, config); 25189 global_min_se = DEFAULT_MIN_SE; 25190 } 25191 if (global_min_se < 90) { 25192 ast_log(LOG_WARNING, "session-minse '%s' at line %d of %s is not allowed to be < 90 secs\n", v->value, v->lineno, config); 25193 global_min_se = DEFAULT_MIN_SE; 25194 } 25195 } else if (!strcasecmp(v->name, "session-refresher")) { 25196 int i = (int) str2strefresher(v->value); 25197 if (i < 0) { 25198 ast_log(LOG_WARNING, "Invalid session-refresher '%s' at line %d of %s\n", v->value, v->lineno, config); 25199 global_st_refresher = SESSION_TIMER_REFRESHER_UAS; 25200 } else { 25201 global_st_refresher = i; 25202 } 25203 } else if (!strcasecmp(v->name, "qualifygap")) { 25204 if (sscanf(v->value, "%30d", &global_qualify_gap) != 1) { 25205 ast_log(LOG_WARNING, "Invalid qualifygap '%s' at line %d of %s\n", v->value, v->lineno, config); 25206 global_qualify_gap = DEFAULT_QUALIFY_GAP; 25207 } 25208 } else if (!strcasecmp(v->name, "qualifypeers")) { 25209 if (sscanf(v->value, "%30d", &global_qualify_peers) != 1) { 25210 ast_log(LOG_WARNING, "Invalid pokepeers '%s' at line %d of %s\n", v->value, v->lineno, config); 25211 global_qualify_peers = DEFAULT_QUALIFY_PEERS; 25212 } 25213 } else if (!strcasecmp(v->name, "shrinkcallerid")) { 25214 if (ast_true(v->value)) { 25215 global_shrinkcallerid = 1; 25216 } else if (ast_false(v->value)) { 25217 global_shrinkcallerid = 0; 25218 } else { 25219 ast_log(LOG_WARNING, "shrinkcallerid value %s is not valid at line %d.\n", v->value, v->lineno); 25220 } 25221 } 25222 } 25223 25224 if (!sip_cfg.allow_external_domains && AST_LIST_EMPTY(&domain_list)) { 25225 ast_log(LOG_WARNING, "To disallow external domains, you need to configure local SIP domains.\n"); 25226 sip_cfg.allow_external_domains = 1; 25227 } 25228 /* If not configured, set default transports */ 25229 if (default_transports == 0) { 25230 default_transports = default_primary_transport = SIP_TRANSPORT_UDP; 25231 } 25232 25233 /* Build list of authentication to various SIP realms, i.e. service providers */ 25234 for (v = ast_variable_browse(cfg, "authentication"); v ; v = v->next) { 25235 /* Format for authentication is auth = username:password@realm */ 25236 if (!strcasecmp(v->name, "auth")) 25237 authl = add_realm_authentication(authl, v->value, v->lineno); 25238 } 25239 25240 /* Set UDP address and open socket */ 25241 bindaddr.sin_family = AF_INET; 25242 internip = bindaddr; 25243 if (ast_find_ourip(&internip.sin_addr, bindaddr)) { 25244 ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n"); 25245 ast_config_destroy(cfg); 25246 return 0; 25247 } 25248 25249 ast_mutex_lock(&netlock); 25250 if ((sipsock > -1) && (memcmp(&old_bindaddr, &bindaddr, sizeof(struct sockaddr_in)))) { 25251 close(sipsock); 25252 sipsock = -1; 25253 } 25254 if (sipsock < 0) { 25255 sipsock = socket(AF_INET, SOCK_DGRAM, 0); 25256 if (sipsock < 0) { 25257 ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno)); 25258 ast_config_destroy(cfg); 25259 ast_mutex_unlock(&netlock); 25260 return -1; 25261 } else { 25262 /* Allow SIP clients on the same host to access us: */ 25263 const int reuseFlag = 1; 25264 25265 setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR, 25266 (const char*)&reuseFlag, 25267 sizeof reuseFlag); 25268 25269 ast_enable_packet_fragmentation(sipsock); 25270 25271 if (bind(sipsock, (struct sockaddr *)&bindaddr, sizeof(bindaddr)) < 0) { 25272 ast_log(LOG_WARNING, "Failed to bind to %s:%d: %s\n", 25273 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port), 25274 strerror(errno)); 25275 close(sipsock); 25276 sipsock = -1; 25277 } else { 25278 ast_verb(2, "SIP Listening on %s:%d\n", 25279 ast_inet_ntoa(bindaddr.sin_addr), ntohs(bindaddr.sin_port)); 25280 ast_netsock_set_qos(sipsock, global_tos_sip, global_cos_sip, "SIP"); 25281 } 25282 } 25283 } else { 25284 ast_netsock_set_qos(sipsock, global_tos_sip, global_cos_sip, "SIP"); 25285 } 25286 if (stunaddr.sin_addr.s_addr != 0) { 25287 ast_debug(1, "stun to %s:%d\n", 25288 ast_inet_ntoa(stunaddr.sin_addr) , ntohs(stunaddr.sin_port)); 25289 ast_stun_request(sipsock, &stunaddr, 25290 NULL, &externip); 25291 ast_debug(1, "STUN sees us at %s:%d\n", 25292 ast_inet_ntoa(externip.sin_addr) , ntohs(externip.sin_port)); 25293 } 25294 ast_mutex_unlock(&netlock); 25295 25296 /* Start TCP server */ 25297 ast_tcptls_server_start(&sip_tcp_desc); 25298 if (sip_tcp_desc.accept_fd == -1 && sip_tcp_desc.local_address.sin_family == AF_INET) { 25299 /* TCP server start failed. Tell the admin */ 25300 ast_log(LOG_ERROR, "SIP TCP Server start failed. Not listening on TCP socket.\n"); 25301 sip_tcp_desc.local_address.sin_family = 0; 25302 } else { 25303 ast_debug(2, "SIP TCP server started\n"); 25304 } 25305 25306 /* Start TLS server if needed */ 25307 memcpy(sip_tls_desc.tls_cfg, &default_tls_cfg, sizeof(default_tls_cfg)); 25308 25309 if (ast_ssl_setup(sip_tls_desc.tls_cfg)) { 25310 ast_tcptls_server_start(&sip_tls_desc); 25311 if (default_tls_cfg.enabled && sip_tls_desc.accept_fd == -1) { 25312 ast_log(LOG_ERROR, "TLS Server start failed. Not listening on TLS socket.\n"); 25313 sip_tls_desc.tls_cfg = NULL; 25314 } 25315 } else if (sip_tls_desc.tls_cfg->enabled) { 25316 sip_tls_desc.tls_cfg = NULL; 25317 ast_log(LOG_WARNING, "SIP TLS server did not load because of errors.\n"); 25318 } 25319 25320 if (ucfg) { 25321 struct ast_variable *gen; 25322 int genhassip, genregistersip; 25323 const char *hassip, *registersip; 25324 25325 genhassip = ast_true(ast_variable_retrieve(ucfg, "general", "hassip")); 25326 genregistersip = ast_true(ast_variable_retrieve(ucfg, "general", "registersip")); 25327 gen = ast_variable_browse(ucfg, "general"); 25328 cat = ast_category_browse(ucfg, NULL); 25329 while (cat) { 25330 if (strcasecmp(cat, "general")) { 25331 hassip = ast_variable_retrieve(ucfg, cat, "hassip"); 25332 registersip = ast_variable_retrieve(ucfg, cat, "registersip"); 25333 if (ast_true(hassip) || (!hassip && genhassip)) { 25334 peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0, 0); 25335 if (peer) { 25336 /* user.conf entries are always of type friend */ 25337 peer->type = SIP_TYPE_USER | SIP_TYPE_PEER; 25338 ao2_t_link(peers, peer, "link peer into peer table"); 25339 if ((peer->type & SIP_TYPE_PEER) && peer->addr.sin_addr.s_addr) { 25340 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 25341 } 25342 25343 unref_peer(peer, "unref_peer: from reload_config"); 25344 peer_count++; 25345 } 25346 } 25347 if (ast_true(registersip) || (!registersip && genregistersip)) { 25348 char tmp[256]; 25349 const char *host = ast_variable_retrieve(ucfg, cat, "host"); 25350 const char *username = ast_variable_retrieve(ucfg, cat, "username"); 25351 const char *secret = ast_variable_retrieve(ucfg, cat, "secret"); 25352 const char *contact = ast_variable_retrieve(ucfg, cat, "contact"); 25353 const char *authuser = ast_variable_retrieve(ucfg, cat, "authuser"); 25354 if (!host) 25355 host = ast_variable_retrieve(ucfg, "general", "host"); 25356 if (!username) 25357 username = ast_variable_retrieve(ucfg, "general", "username"); 25358 if (!secret) 25359 secret = ast_variable_retrieve(ucfg, "general", "secret"); 25360 if (!contact) 25361 contact = "s"; 25362 if (!ast_strlen_zero(username) && !ast_strlen_zero(host)) { 25363 if (!ast_strlen_zero(secret)) { 25364 if (!ast_strlen_zero(authuser)) { 25365 snprintf(tmp, sizeof(tmp), "%s?%s:%s:%s@%s/%s", cat, username, secret, authuser, host, contact); 25366 } else { 25367 snprintf(tmp, sizeof(tmp), "%s?%s:%s@%s/%s", cat, username, secret, host, contact); 25368 } 25369 } else if (!ast_strlen_zero(authuser)) { 25370 snprintf(tmp, sizeof(tmp), "%s?%s::%s@%s/%s", cat, username, authuser, host, contact); 25371 } else { 25372 snprintf(tmp, sizeof(tmp), "%s?%s@%s/%s", cat, username, host, contact); 25373 } 25374 if (sip_register(tmp, 0) == 0) 25375 registry_count++; 25376 } 25377 } 25378 } 25379 cat = ast_category_browse(ucfg, cat); 25380 } 25381 ast_config_destroy(ucfg); 25382 } 25383 25384 /* Load peers, users and friends */ 25385 cat = NULL; 25386 while ( (cat = ast_category_browse(cfg, cat)) ) { 25387 const char *utype; 25388 if (!strcasecmp(cat, "general") || !strcasecmp(cat, "authentication")) 25389 continue; 25390 utype = ast_variable_retrieve(cfg, cat, "type"); 25391 if (!utype) { 25392 ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat); 25393 continue; 25394 } else { 25395 if (!strcasecmp(utype, "user")) { 25396 ; 25397 } else if (!strcasecmp(utype, "friend")) { 25398 ; 25399 } else if (!strcasecmp(utype, "peer")) { 25400 ; 25401 } else { 25402 ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf"); 25403 continue; 25404 } 25405 peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0, 0); 25406 if (peer) { 25407 ao2_t_link(peers, peer, "link peer into peers table"); 25408 if ((peer->type & SIP_TYPE_PEER) && peer->addr.sin_addr.s_addr) { 25409 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 25410 } 25411 unref_peer(peer, "unref the result of the build_peer call. Now, the links from the tables are the only ones left."); 25412 peer_count++; 25413 } 25414 } 25415 } 25416 25417 /* Add default domains - host name, IP address and IP:port 25418 * Only do this if user added any sip domain with "localdomains" 25419 * In order to *not* break backwards compatibility 25420 * Some phones address us at IP only, some with additional port number 25421 */ 25422 if (auto_sip_domains) { 25423 char temp[MAXHOSTNAMELEN]; 25424 25425 /* First our default IP address */ 25426 if (bindaddr.sin_addr.s_addr) { 25427 add_sip_domain(ast_inet_ntoa(bindaddr.sin_addr), SIP_DOMAIN_AUTO, NULL); 25428 } else if (internip.sin_addr.s_addr) { 25429 /* Our internal IP address, if configured */ 25430 add_sip_domain(ast_inet_ntoa(internip.sin_addr), SIP_DOMAIN_AUTO, NULL); 25431 } else { 25432 ast_log(LOG_NOTICE, "Can't add wildcard IP address to domain list, please add IP address to domain manually.\n"); 25433 } 25434 25435 /* If TCP is running on a different IP than UDP, then add it too */ 25436 if (sip_tcp_desc.local_address.sin_addr.s_addr && !inaddrcmp(&bindaddr, &sip_tcp_desc.local_address)) 25437 add_sip_domain(ast_inet_ntoa(sip_tcp_desc.local_address.sin_addr), SIP_DOMAIN_AUTO, NULL); 25438 25439 /* If TLS is running on a differen IP than UDP and TCP, then add that too */ 25440 if (sip_tls_desc.local_address.sin_addr.s_addr && !inaddrcmp(&bindaddr, &sip_tls_desc.local_address) && inaddrcmp(&sip_tcp_desc.local_address, &sip_tls_desc.local_address)) 25441 add_sip_domain(ast_inet_ntoa(sip_tls_desc.local_address.sin_addr), SIP_DOMAIN_AUTO, NULL); 25442 25443 /* Our extern IP address, if configured */ 25444 if (externip.sin_addr.s_addr) 25445 add_sip_domain(ast_inet_ntoa(externip.sin_addr), SIP_DOMAIN_AUTO, NULL); 25446 25447 /* Extern host name (NAT traversal support) */ 25448 if (!ast_strlen_zero(externhost)) 25449 add_sip_domain(externhost, SIP_DOMAIN_AUTO, NULL); 25450 25451 /* Our host name */ 25452 if (!gethostname(temp, sizeof(temp))) 25453 add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL); 25454 } 25455 25456 /* Release configuration from memory */ 25457 ast_config_destroy(cfg); 25458 25459 /* Load the list of manual NOTIFY types to support */ 25460 if (notify_types) 25461 ast_config_destroy(notify_types); 25462 if ((notify_types = ast_config_load(notify_config, config_flags)) == CONFIG_STATUS_FILEINVALID) { 25463 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed.\n", notify_config); 25464 notify_types = NULL; 25465 } 25466 25467 /* Done, tell the manager */ 25468 manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "ChannelType: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count); 25469 run_end = time(0); 25470 ast_debug(4, "SIP reload_config done...Runtime= %d sec\n", (int)(run_end-run_start)); 25471 25472 return 0; 25473 }
| static char * remove_uri_parameters | ( | char * | uri | ) | [static] |
Definition at line 10699 of file chan_sip.c.
Referenced by extract_uri(), parse_moved_contact(), register_verify(), reqprep(), and transmit_state_notify().
10700 { 10701 char *atsign; 10702 atsign = strchr(uri, '@'); /* First, locate the at sign */ 10703 if (!atsign) 10704 atsign = uri; /* Ok hostname only, let's stick with the rest */ 10705 atsign = strchr(atsign, ';'); /* Locate semi colon */ 10706 if (atsign) 10707 *atsign = '\0'; /* Kill at the semi colon */ 10708 return uri; 10709 }
| static void replace_cid | ( | struct sip_pvt * | p, | |
| const char * | rpid_num, | |||
| const char * | calleridname | |||
| ) | [static] |
helper function for check_{user|peer}_ok()
Definition at line 14128 of file chan_sip.c.
References ast_is_shrinkable_phonenumber(), ast_shrink_phone_number(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, cid_name, cid_num, sip_pvt::flags, and SIP_TRUSTRPID.
Referenced by check_peer_ok(), and check_user_full().
14129 { 14130 /* replace callerid if rpid found, and not restricted */ 14131 if (!ast_strlen_zero(rpid_num) && ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) { 14132 char *tmp = ast_strdupa(rpid_num); /* XXX the copy can be done later */ 14133 if (!ast_strlen_zero(calleridname)) 14134 ast_string_field_set(p, cid_name, calleridname); 14135 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) 14136 ast_shrink_phone_number(tmp); 14137 ast_string_field_set(p, cid_num, tmp); 14138 } 14139 }
| static int reply_digest | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| char * | header, | |||
| int | sipmethod, | |||
| char * | digest, | |||
| int | digest_len | |||
| ) | [static] |
reply to authentication for outbound registrations
Definition at line 17249 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_skip_blanks(), ast_string_field_ptr_set, ast_string_field_set, ast_strlen_zero(), build_reply_digest(), sip_pvt::domain, get_header(), LOG_WARNING, sip_registry::nonce, sip_pvt::nonce, sip_registry::noncecount, sip_pvt::noncecount, sip_registry::opaque, sip_pvt::opaque, sip_registry::qop, sip_pvt::qop, sip_registry::realm, sip_pvt::realm, sip_pvt::registry, and strsep().
Referenced by do_proxy_auth(), and do_register_auth().
17250 { 17251 char tmp[512]; 17252 char *c; 17253 char oldnonce[256]; 17254 17255 /* table of recognised keywords, and places where they should be copied */ 17256 const struct x { 17257 const char *key; 17258 const ast_string_field *field; 17259 } *i, keys[] = { 17260 { "realm=", &p->realm }, 17261 { "nonce=", &p->nonce }, 17262 { "opaque=", &p->opaque }, 17263 { "qop=", &p->qop }, 17264 { "domain=", &p->domain }, 17265 { NULL, 0 }, 17266 }; 17267 17268 ast_copy_string(tmp, get_header(req, header), sizeof(tmp)); 17269 if (ast_strlen_zero(tmp)) 17270 return -1; 17271 if (strncasecmp(tmp, "Digest ", strlen("Digest "))) { 17272 ast_log(LOG_WARNING, "missing Digest.\n"); 17273 return -1; 17274 } 17275 c = tmp + strlen("Digest "); 17276 ast_copy_string(oldnonce, p->nonce, sizeof(oldnonce)); 17277 while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */ 17278 for (i = keys; i->key != NULL; i++) { 17279 char *src, *separator; 17280 if (strncasecmp(c, i->key, strlen(i->key)) != 0) 17281 continue; 17282 /* Found. Skip keyword, take text in quotes or up to the separator. */ 17283 c += strlen(i->key); 17284 if (*c == '"') { 17285 src = ++c; 17286 separator = "\""; 17287 } else { 17288 src = c; 17289 separator = ","; 17290 } 17291 strsep(&c, separator); /* clear separator and move ptr */ 17292 ast_string_field_ptr_set(p, i->field, src); 17293 break; 17294 } 17295 if (i->key == NULL) /* not found, try ',' */ 17296 strsep(&c, ","); 17297 } 17298 /* Reset nonce count */ 17299 if (strcmp(p->nonce, oldnonce)) 17300 p->noncecount = 0; 17301 17302 /* Save auth data for following registrations */ 17303 if (p->registry) { 17304 struct sip_registry *r = p->registry; 17305 17306 if (strcmp(r->nonce, p->nonce)) { 17307 ast_string_field_set(r, realm, p->realm); 17308 ast_string_field_set(r, nonce, p->nonce); 17309 ast_string_field_set(r, domain, p->domain); 17310 ast_string_field_set(r, opaque, p->opaque); 17311 ast_string_field_set(r, qop, p->qop); 17312 r->noncecount = 0; 17313 } 17314 } 17315 return build_reply_digest(p, sipmethod, digest, digest_len); 17316 }
| static int reqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod, | |||
| int | seqno, | |||
| int | newbranch | |||
| ) | [static] |
Initialize a SIP request message (not the initial one in a dialog).
< Strict routing flag
Definition at line 9611 of file chan_sip.c.
References add_header(), add_route(), ast_copy_string(), ast_debug, ast_random(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, sip_pvt::branch, build_via(), sip_pvt::callid, copy_header(), DEFAULT_MAX_FORWARDS, FALSE, sip_pvt::flags, get_header(), get_in_brackets(), sip_route::hop, init_req(), sip_pvt::initreq, sip_pvt::invite_branch, sip_pvt::lastmsg, sip_route::next, sip_pvt::ocseq, sip_pvt::okcontacturi, sip_pvt::our_contact, remove_uri_parameters(), REQ_OFFSET_TO_STR, sip_request::rlPart2, sip_pvt::route, sip_pvt::rpid, set_destination(), SIP_ACK, SIP_BYE, SIP_CANCEL, SIP_INVITE, SIP_MESSAGE, sip_methods, SIP_OUTGOING, sip_st_dlg::st_active, sip_st_dlg::st_active_peer_ua, st_get_se(), sip_st_dlg::st_interval, sip_st_dlg::st_ref, sip_pvt::stimer, strcasestr(), strefresher2str(), sip_pvt::tag, text, cfsip_methods::text, sip_pvt::theirtag, TRUE, sip_pvt::uri, url, sip_pvt::url, and sip_pvt::via.
Referenced by transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), and transmit_state_notify().
09612 { 09613 struct sip_request *orig = &p->initreq; 09614 char stripped[80]; 09615 char tmp[80]; 09616 char newto[256]; 09617 const char *c; 09618 const char *ot, *of; 09619 int is_strict = FALSE; /*!< Strict routing flag */ 09620 int is_outbound = ast_test_flag(&p->flags[0], SIP_OUTGOING); /* Session direction */ 09621 09622 memset(req, 0, sizeof(struct sip_request)); 09623 09624 snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text); 09625 09626 if (!seqno) { 09627 p->ocseq++; 09628 seqno = p->ocseq; 09629 } 09630 09631 /* A CANCEL must have the same branch as the INVITE that it is canceling. */ 09632 if (sipmethod == SIP_CANCEL) { 09633 p->branch = p->invite_branch; 09634 build_via(p); 09635 } else if (newbranch && (sipmethod == SIP_INVITE)) { 09636 p->branch ^= ast_random(); 09637 p->invite_branch = p->branch; 09638 build_via(p); 09639 } else if (newbranch) { 09640 p->branch ^= ast_random(); 09641 build_via(p); 09642 } 09643 09644 /* Check for strict or loose router */ 09645 if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop, ";lr") == NULL) { 09646 is_strict = TRUE; 09647 if (sipdebug) 09648 ast_debug(1, "Strict routing enforced for session %s\n", p->callid); 09649 } 09650 09651 if (sipmethod == SIP_CANCEL) 09652 c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); /* Use original URI */ 09653 else if (sipmethod == SIP_ACK) { 09654 /* Use URI from Contact: in 200 OK (if INVITE) 09655 (we only have the contacturi on INVITEs) */ 09656 if (!ast_strlen_zero(p->okcontacturi)) 09657 c = is_strict ? p->route->hop : p->okcontacturi; 09658 else 09659 c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); 09660 } else if (!ast_strlen_zero(p->okcontacturi)) 09661 c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */ 09662 else if (!ast_strlen_zero(p->uri)) 09663 c = p->uri; 09664 else { 09665 char *n; 09666 /* We have no URI, use To: or From: header as URI (depending on direction) */ 09667 ast_copy_string(stripped, get_header(orig, is_outbound ? "To" : "From"), 09668 sizeof(stripped)); 09669 n = get_in_brackets(stripped); 09670 c = remove_uri_parameters(n); 09671 } 09672 init_req(req, sipmethod, c); 09673 09674 snprintf(tmp, sizeof(tmp), "%d %s", seqno, sip_methods[sipmethod].text); 09675 09676 add_header(req, "Via", p->via); 09677 if (p->route) { 09678 set_destination(p, p->route->hop); 09679 add_route(req, is_strict ? p->route->next : p->route); 09680 } 09681 add_header(req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 09682 09683 ot = get_header(orig, "To"); 09684 of = get_header(orig, "From"); 09685 09686 /* Add tag *unless* this is a CANCEL, in which case we need to send it exactly 09687 as our original request, including tag (or presumably lack thereof) */ 09688 if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) { 09689 /* Add the proper tag if we don't have it already. If they have specified 09690 their tag, use it. Otherwise, use our own tag */ 09691 if (is_outbound && !ast_strlen_zero(p->theirtag)) 09692 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 09693 else if (!is_outbound) 09694 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 09695 else 09696 snprintf(newto, sizeof(newto), "%s", ot); 09697 ot = newto; 09698 } 09699 09700 if (is_outbound) { 09701 add_header(req, "From", of); 09702 add_header(req, "To", ot); 09703 } else { 09704 add_header(req, "From", ot); 09705 add_header(req, "To", of); 09706 } 09707 /* Do not add Contact for MESSAGE, BYE and Cancel requests */ 09708 if (sipmethod != SIP_BYE && sipmethod != SIP_CANCEL && sipmethod != SIP_MESSAGE) 09709 add_header(req, "Contact", p->our_contact); 09710 09711 copy_header(req, orig, "Call-ID"); 09712 add_header(req, "CSeq", tmp); 09713 09714 if (!ast_strlen_zero(global_useragent)) 09715 add_header(req, "User-Agent", global_useragent); 09716 09717 if (!ast_strlen_zero(p->rpid)) 09718 add_header(req, "Remote-Party-ID", p->rpid); 09719 09720 if (!ast_strlen_zero(p->url)) { 09721 add_header(req, "Access-URL", p->url); 09722 ast_string_field_set(p, url, NULL); 09723 } 09724 09725 /* Add Session-Timers related headers if the feature is active for this session. 09726 An exception to this behavior is the ACK request. Since Asterisk never requires 09727 session-timers support from a remote end-point (UAS) in an INVITE, it must 09728 not send 'Require: timer' header in the ACK request. 09729 This should only be added in the INVITE transactions, not MESSAGE or REFER or other 09730 in-dialog messages. 09731 */ 09732 if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_active_peer_ua == TRUE 09733 && sipmethod == SIP_INVITE) { 09734 char se_hdr[256]; 09735 snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->stimer->st_interval, 09736 strefresher2str(p->stimer->st_ref)); 09737 add_header(req, "Require", "timer"); 09738 add_header(req, "Session-Expires", se_hdr); 09739 snprintf(se_hdr, sizeof(se_hdr), "%d", st_get_se(p, FALSE)); 09740 add_header(req, "Min-SE", se_hdr); 09741 } 09742 09743 return 0; 09744 }
| static int resp_needs_contact | ( | const char * | msg, | |
| enum sipmethod | method | |||
| ) | [inline, static] |
Test if this response needs a contact header.
Definition at line 9486 of file chan_sip.c.
References SIP_ACK, SIP_BYE, SIP_CANCEL, SIP_INFO, SIP_INVITE, SIP_MESSAGE, SIP_NOTIFY, SIP_OPTIONS, SIP_PING, SIP_PRACK, SIP_PUBLISH, SIP_REFER, SIP_REGISTER, SIP_SUBSCRIBE, and SIP_UPDATE.
Referenced by respprep().
09486 { 09487 /* Requirements for Contact header inclusion in responses generated 09488 * from the header tables found in the following RFCs. Where the 09489 * Contact header was marked mandatory (m) or optional (o) this 09490 * function returns 1. 09491 * 09492 * - RFC 3261 (ACK, BYE, CANCEL, INVITE, OPTIONS, REGISTER) 09493 * - RFC 2976 (INFO) 09494 * - RFC 3262 (PRACK) 09495 * - RFC 3265 (SUBSCRIBE, NOTIFY) 09496 * - RFC 3311 (UPDATE) 09497 * - RFC 3428 (MESSAGE) 09498 * - RFC 3515 (REFER) 09499 * - RFC 3903 (PUBLISH) 09500 */ 09501 09502 switch (method) { 09503 /* 1xx, 2xx, 3xx, 485 */ 09504 case SIP_INVITE: 09505 case SIP_UPDATE: 09506 case SIP_SUBSCRIBE: 09507 case SIP_NOTIFY: 09508 if ((msg[0] >= '1' && msg[0] <= '3') || !strncmp(msg, "485", 3)) 09509 return 1; 09510 break; 09511 09512 /* 2xx, 3xx, 485 */ 09513 case SIP_REGISTER: 09514 case SIP_OPTIONS: 09515 if (msg[0] == '2' || msg[0] == '3' || !strncmp(msg, "485", 3)) 09516 return 1; 09517 break; 09518 09519 /* 3xx, 485 */ 09520 case SIP_BYE: 09521 case SIP_PRACK: 09522 case SIP_MESSAGE: 09523 case SIP_PUBLISH: 09524 if (msg[0] == '3' || !strncmp(msg, "485", 3)) 09525 return 1; 09526 break; 09527 09528 /* 2xx, 3xx, 4xx, 5xx, 6xx */ 09529 case SIP_REFER: 09530 if (msg[0] >= '2' && msg[0] <= '6') 09531 return 1; 09532 break; 09533 09534 /* contact will not be included for everything else */ 09535 case SIP_ACK: 09536 case SIP_CANCEL: 09537 case SIP_INFO: 09538 case SIP_PING: 09539 default: 09540 return 0; 09541 } 09542 return 0; 09543 }
| static int respprep | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p, | |||
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Prepare SIP response packet.
Definition at line 9546 of file chan_sip.c.
References add_header(), add_supported_header(), ALLOWED_METHODS, ast_copy_string(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, copy_all_header(), copy_header(), copy_via_headers(), sip_pvt::expiry, sip_pvt::flags, sip_pvt::fullcontact, get_header(), init_resp(), sip_pvt::method, sip_pvt::our_contact, resp_needs_contact(), SIP_INVITE, SIP_OUTGOING, SIP_REGISTER, SIP_SUBSCRIBE, SIPBUFSIZE, sip_st_dlg::st_active, sip_st_dlg::st_active_peer_ua, sip_st_dlg::st_interval, sip_st_dlg::st_ref, sip_pvt::stimer, strcasestr(), strefresher2str(), sip_pvt::tag, sip_pvt::theirtag, TRUE, url, and sip_pvt::url.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_minse(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
09547 { 09548 char newto[256]; 09549 const char *ot; 09550 09551 init_resp(resp, msg); 09552 copy_via_headers(p, resp, req, "Via"); 09553 if (msg[0] == '1' || msg[0] == '2') 09554 copy_all_header(resp, req, "Record-Route"); 09555 copy_header(resp, req, "From"); 09556 ot = get_header(req, "To"); 09557 if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) { 09558 /* Add the proper tag if we don't have it already. If they have specified 09559 their tag, use it. Otherwise, use our own tag */ 09560 if (!ast_strlen_zero(p->theirtag) && ast_test_flag(&p->flags[0], SIP_OUTGOING)) 09561 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 09562 else if (p->tag && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) 09563 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 09564 else 09565 ast_copy_string(newto, ot, sizeof(newto)); 09566 ot = newto; 09567 } 09568 add_header(resp, "To", ot); 09569 copy_header(resp, req, "Call-ID"); 09570 copy_header(resp, req, "CSeq"); 09571 if (!ast_strlen_zero(global_useragent)) 09572 add_header(resp, "Server", global_useragent); 09573 add_header(resp, "Allow", ALLOWED_METHODS); 09574 add_supported_header(p, resp); 09575 09576 /* If this is an invite, add Session-Timers related headers if the feature is active for this session */ 09577 if (p->method == SIP_INVITE && p->stimer && p->stimer->st_active == TRUE && p->stimer->st_active_peer_ua == TRUE) { 09578 char se_hdr[256]; 09579 snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->stimer->st_interval, 09580 strefresher2str(p->stimer->st_ref)); 09581 add_header(resp, "Session-Expires", se_hdr); 09582 } 09583 09584 if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) { 09585 /* For registration responses, we also need expiry and 09586 contact info */ 09587 char tmp[256]; 09588 09589 snprintf(tmp, sizeof(tmp), "%d", p->expiry); 09590 add_header(resp, "Expires", tmp); 09591 if (p->expiry) { /* Only add contact if we have an expiry time */ 09592 char contact[SIPBUFSIZE]; 09593 const char *contact_uri = p->method == SIP_SUBSCRIBE ? p->our_contact : p->fullcontact; 09594 char *brackets = strchr(contact_uri, '<'); 09595 snprintf(contact, sizeof(contact), "%s%s%s;expires=%d", brackets ? "" : "<", contact_uri, brackets ? "" : ">", p->expiry); 09596 add_header(resp, "Contact", contact); /* Not when we unregister */ 09597 } 09598 } else if (!ast_strlen_zero(p->our_contact) && resp_needs_contact(msg, p->method)) { 09599 add_header(resp, "Contact", p->our_contact); 09600 } 09601 09602 if (!ast_strlen_zero(p->url)) { 09603 add_header(resp, "Access-URL", p->url); 09604 ast_string_field_set(p, url, NULL); 09605 } 09606 09607 return 0; 09608 }
| static int restart_monitor | ( | void | ) | [static] |
Start the channel monitor thread.
Definition at line 22737 of file chan_sip.c.
References ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_pthread_create_background, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, LOG_WARNING, and monlock.
Referenced by load_module(), sip_reload(), and sip_request_call().
22738 { 22739 /* If we're supposed to be stopped -- stay stopped */ 22740 if (monitor_thread == AST_PTHREADT_STOP) 22741 return 0; 22742 ast_mutex_lock(&monlock); 22743 if (monitor_thread == pthread_self()) { 22744 ast_mutex_unlock(&monlock); 22745 ast_log(LOG_WARNING, "Cannot kill myself\n"); 22746 return -1; 22747 } 22748 if (monitor_thread != AST_PTHREADT_NULL) { 22749 /* Wake up the thread */ 22750 pthread_kill(monitor_thread, SIGURG); 22751 } else { 22752 /* Start a new monitor */ 22753 if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) { 22754 ast_mutex_unlock(&monlock); 22755 ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); 22756 return -1; 22757 } 22758 } 22759 ast_mutex_unlock(&monlock); 22760 return 0; 22761 }
| static void restart_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Restart session timer.
Definition at line 22765 of file chan_sip.c.
References ast_debug, ast_log(), AST_SCHED_DEL_UNREF, sip_pvt::callid, dialog_unref(), LOG_WARNING, sip_st_dlg::st_active, sip_st_dlg::st_schedid, start_session_timer(), sip_pvt::stimer, and TRUE.
Referenced by handle_request_invite().
22766 { 22767 if (!p->stimer) { 22768 ast_log(LOG_WARNING, "Null stimer in restart_session_timer - %s\n", p->callid); 22769 return; 22770 } 22771 22772 if (p->stimer->st_active == TRUE) { 22773 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 22774 dialog_unref(p, "Removing session timer ref")); 22775 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 22776 start_session_timer(p); 22777 } 22778 }
| static int retrans_pkt | ( | const void * | data | ) | [static] |
Retransmit SIP message if no answer (Called from scheduler).
Definition at line 3774 of file chan_sip.c.
References __sip_xmit(), append_history, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_PROTOCOL_ERROR, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_free, ast_inet_ntoa(), ast_log(), ast_queue_hangup_with_cause(), ast_verbose, sip_pvt::callid, sip_pkt::data, DEFAULT_RETRANS, dialog_unref(), ast_channel::hangupcause, sip_pkt::is_fatal, sip_pkt::is_resp, LOG_WARNING, MAX_RETRANS, sip_pkt::method, sip_pkt::next, sip_pvt::owner, sip_pkt::owner, sip_pkt::packetlen, sip_pvt::packets, pvt_set_needdestroy(), sip_pkt::retrans, sip_pkt::retransid, sip_pkt::seqno, sip_alreadygone(), SIP_BYE, sip_debug_test_pvt(), SIP_INVITE, sip_methods, sip_nat_mode(), SIP_OPTIONS, sip_pvt_lock, sip_pvt_unlock, sip_real_dst(), SIP_REGISTER, cfsip_methods::text, sip_pkt::timer_a, sip_pkt::timer_t1, UNLINK, and XMIT_ERROR.
Referenced by __sip_reliable_xmit(), and sip_show_sched().
03775 { 03776 struct sip_pkt *pkt = (struct sip_pkt *)data, *prev, *cur = NULL; 03777 int reschedule = DEFAULT_RETRANS; 03778 int xmitres = 0; 03779 03780 /* Lock channel PVT */ 03781 sip_pvt_lock(pkt->owner); 03782 03783 if (pkt->retrans < MAX_RETRANS) { 03784 pkt->retrans++; 03785 if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */ 03786 if (sipdebug) 03787 ast_debug(4, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", pkt->retransid, sip_methods[pkt->method].text, pkt->method); 03788 } else { 03789 int siptimer_a; 03790 03791 if (sipdebug) 03792 ast_debug(4, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", pkt->retransid, pkt->retrans, sip_methods[pkt->method].text, pkt->method); 03793 if (!pkt->timer_a) 03794 pkt->timer_a = 2 ; 03795 else 03796 pkt->timer_a = 2 * pkt->timer_a; 03797 03798 /* For non-invites, a maximum of 4 secs */ 03799 siptimer_a = pkt->timer_t1 * pkt->timer_a; /* Double each time */ 03800 if (pkt->method != SIP_INVITE && siptimer_a > 4000) 03801 siptimer_a = 4000; 03802 03803 /* Reschedule re-transmit */ 03804 reschedule = siptimer_a; 03805 ast_debug(4, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", pkt->retrans +1, siptimer_a, pkt->timer_t1, pkt->retransid); 03806 } 03807 03808 if (sip_debug_test_pvt(pkt->owner)) { 03809 const struct sockaddr_in *dst = sip_real_dst(pkt->owner); 03810 ast_verbose("Retransmitting #%d (%s) to %s:%d:\n%s\n---\n", 03811 pkt->retrans, sip_nat_mode(pkt->owner), 03812 ast_inet_ntoa(dst->sin_addr), 03813 ntohs(dst->sin_port), pkt->data->str); 03814 } 03815 03816 append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data->str); 03817 xmitres = __sip_xmit(pkt->owner, pkt->data, pkt->packetlen); 03818 if (xmitres == XMIT_ERROR) { 03819 ast_log(LOG_WARNING, "Network error on retransmit in dialog %s\n", pkt->owner->callid); 03820 } else { 03821 sip_pvt_unlock(pkt->owner); 03822 return reschedule; 03823 } 03824 } 03825 /* Too many retries */ 03826 if (pkt->owner && pkt->method != SIP_OPTIONS && xmitres == 0) { 03827 if (pkt->is_fatal || sipdebug) /* Tell us if it's critical or if we're debugging */ 03828 ast_log(LOG_WARNING, "Maximum retries exceeded on transmission %s for seqno %d (%s %s) -- See doc/sip-retransmit.txt.\n", 03829 pkt->owner->callid, pkt->seqno, 03830 pkt->is_fatal ? "Critical" : "Non-critical", pkt->is_resp ? "Response" : "Request"); 03831 } else if (pkt->method == SIP_OPTIONS && sipdebug) { 03832 ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) -- See doc/sip-retransmit.txt.\n", pkt->owner->callid); 03833 03834 } 03835 if (xmitres == XMIT_ERROR) { 03836 ast_log(LOG_WARNING, "Transmit error :: Cancelling transmission on Call ID %s\n", pkt->owner->callid); 03837 append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03838 } else { 03839 append_history(pkt->owner, "MaxRetries", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03840 } 03841 pkt->retransid = -1; 03842 03843 if (pkt->is_fatal) { 03844 while(pkt->owner->owner && ast_channel_trylock(pkt->owner->owner)) { 03845 sip_pvt_unlock(pkt->owner); /* SIP_PVT, not channel */ 03846 usleep(1); 03847 sip_pvt_lock(pkt->owner); 03848 } 03849 03850 if (pkt->owner->owner && !pkt->owner->owner->hangupcause) 03851 pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE; 03852 03853 if (pkt->owner->owner) { 03854 sip_alreadygone(pkt->owner); 03855 ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet (see doc/sip-retransmit.txt).\n", pkt->owner->callid); 03856 ast_queue_hangup_with_cause(pkt->owner->owner, AST_CAUSE_PROTOCOL_ERROR); 03857 ast_channel_unlock(pkt->owner->owner); 03858 } else { 03859 /* If no channel owner, destroy now */ 03860 03861 /* Let the peerpoke system expire packets when the timer expires for poke_noanswer */ 03862 if (pkt->method != SIP_OPTIONS && pkt->method != SIP_REGISTER) { 03863 pvt_set_needdestroy(pkt->owner, "no response to critical packet"); 03864 sip_alreadygone(pkt->owner); 03865 append_history(pkt->owner, "DialogKill", "Killing this failed dialog immediately"); 03866 } 03867 } 03868 } 03869 03870 if (pkt->method == SIP_BYE) { 03871 /* We're not getting answers on SIP BYE's. Tear down the call anyway. */ 03872 if (pkt->owner->owner) 03873 ast_channel_unlock(pkt->owner->owner); 03874 append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway."); 03875 pvt_set_needdestroy(pkt->owner, "no response to BYE"); 03876 } 03877 03878 /* Remove the packet */ 03879 for (prev = NULL, cur = pkt->owner->packets; cur; prev = cur, cur = cur->next) { 03880 if (cur == pkt) { 03881 UNLINK(cur, pkt->owner->packets, prev); 03882 sip_pvt_unlock(pkt->owner); 03883 if (pkt->owner) 03884 pkt->owner = dialog_unref(pkt->owner,"pkt is being freed, its dialog ref is dead now"); 03885 if (pkt->data) 03886 ast_free(pkt->data); 03887 pkt->data = NULL; 03888 ast_free(pkt); 03889 return 0; 03890 } 03891 } 03892 /* error case */ 03893 ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n"); 03894 sip_pvt_unlock(pkt->owner); 03895 return 0; 03896 }
| static int scheduler_process_request_queue | ( | const void * | data | ) | [static] |
Definition at line 22044 of file chan_sip.c.
References ast_channel_trylock, ast_channel_unlock, AST_LIST_EMPTY, ast_update_use_count(), dialog_unref(), sip_pvt::owner, process_request_queue(), sip_pvt::request_queue, sip_pvt::request_queue_sched_id, sip_pvt_lock, and sip_pvt_unlock.
Referenced by queue_request().
22045 { 22046 struct sip_pvt *p = (struct sip_pvt *) data; 22047 int recount = 0; 22048 int nounlock = 0; 22049 int lockretry; 22050 22051 for (lockretry = 10; lockretry > 0; lockretry--) { 22052 sip_pvt_lock(p); 22053 22054 /* lock the owner if it has one -- we may need it */ 22055 /* because this is deadlock-prone, we need to try and unlock if failed */ 22056 if (!p->owner || !ast_channel_trylock(p->owner)) { 22057 break; /* locking succeeded */ 22058 } 22059 22060 if (lockretry != 1) { 22061 sip_pvt_unlock(p); 22062 /* Sleep for a very short amount of time */ 22063 usleep(1); 22064 } 22065 } 22066 22067 if (!lockretry) { 22068 int retry = !AST_LIST_EMPTY(&p->request_queue); 22069 22070 /* we couldn't get the owner lock, which is needed to process 22071 the queued requests, so return a non-zero value, which will 22072 cause the scheduler to run this request again later if there 22073 still requests to be processed 22074 */ 22075 sip_pvt_unlock(p); 22076 if (!retry) { 22077 dialog_unref(p, "The ref to a dialog passed to this sched callback is going out of scope; unref it."); 22078 } 22079 return retry; 22080 }; 22081 22082 process_request_queue(p, &recount, &nounlock); 22083 p->request_queue_sched_id = -1; 22084 22085 if (p->owner && !nounlock) { 22086 ast_channel_unlock(p->owner); 22087 } 22088 sip_pvt_unlock(p); 22089 22090 if (recount) { 22091 ast_update_use_count(); 22092 } 22093 22094 dialog_unref(p, "The ref to a dialog passed to this sched callback is going out of scope; unref it."); 22095 22096 return 0; 22097 }
| static int send_provisional_keepalive | ( | const void * | data | ) | [static] |
Definition at line 4236 of file chan_sip.c.
References send_provisional_keepalive_full().
Referenced by update_provisional_keepalive().
04236 { 04237 struct sip_pvt *pvt = (struct sip_pvt *) data; 04238 04239 return send_provisional_keepalive_full(pvt, 0); 04240 }
| static int send_provisional_keepalive_full | ( | struct sip_pvt * | pvt, | |
| int | with_sdp | |||
| ) | [static] |
Definition at line 4216 of file chan_sip.c.
References FALSE, sip_pvt::initreq, INV_COMPLETED, sip_pvt::invitestate, sip_pvt::last_provisional, msg, PROVIS_KEEPALIVE_TIMEOUT, S_OR, transmit_response(), transmit_response_with_sdp(), and XMIT_UNRELIABLE.
Referenced by send_provisional_keepalive(), and send_provisional_keepalive_with_sdp().
04217 { 04218 const char *msg = NULL; 04219 04220 if (!pvt->last_provisional || !strncasecmp(pvt->last_provisional, "100", 3)) { 04221 msg = "183 Session Progress"; 04222 } 04223 04224 if (pvt->invitestate < INV_COMPLETED) { 04225 if (with_sdp) { 04226 transmit_response_with_sdp(pvt, S_OR(msg, pvt->last_provisional), &pvt->initreq, XMIT_UNRELIABLE, FALSE); 04227 } else { 04228 transmit_response(pvt, S_OR(msg, pvt->last_provisional), &pvt->initreq); 04229 } 04230 return PROVIS_KEEPALIVE_TIMEOUT; 04231 } 04232 04233 return 0; 04234 }
| static int send_provisional_keepalive_with_sdp | ( | const void * | data | ) | [static] |
Definition at line 4242 of file chan_sip.c.
References send_provisional_keepalive_full().
Referenced by update_provisional_keepalive().
04242 { 04243 struct sip_pvt *pvt = (void *)data; 04244 04245 return send_provisional_keepalive_full(pvt, 1); 04246 }
| static int send_request | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| int | seqno | |||
| ) | [static] |
Send SIP Request to the other part of the dialogue.
Definition at line 4294 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, ast_inet_ntoa(), ast_test_flag, ast_verbose, sip_request::data, deinit_req(), sip_pvt::do_history, finalize_content(), sip_pvt::flags, get_header(), sip_proxy::ip, sip_request::len, sip_request::method, sip_pvt::outboundproxy, parse_copy(), sip_pvt::recv, sip_request::rlPart1, sip_pvt::sa, sip_debug_test_pvt(), sip_methods, SIP_NAT_ROUTE, cfsip_methods::text, and XMIT_CRITICAL.
Referenced by transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_notify_custom(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), and transmit_state_notify().
04295 { 04296 int res; 04297 04298 /* If we have an outbound proxy, reset peer address 04299 Only do this once. 04300 */ 04301 if (p->outboundproxy) { 04302 p->sa = p->outboundproxy->ip; 04303 } 04304 04305 finalize_content(req); 04306 add_blank(req); 04307 if (sip_debug_test_pvt(p)) { 04308 if (ast_test_flag(&p->flags[0], SIP_NAT_ROUTE)) 04309 ast_verbose("%sTransmitting (NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->recv.sin_addr), ntohs(p->recv.sin_port), req->data->str); 04310 else 04311 ast_verbose("%sTransmitting (no NAT) to %s:%d:\n%s\n---\n", reliable ? "Reliably " : "", ast_inet_ntoa(p->sa.sin_addr), ntohs(p->sa.sin_port), req->data->str); 04312 } 04313 if (p->do_history) { 04314 struct sip_request tmp = { .rlPart1 = 0, }; 04315 parse_copy(&tmp, req); 04316 append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data->str, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text); 04317 deinit_req(&tmp); 04318 } 04319 res = (reliable) ? 04320 __sip_reliable_xmit(p, seqno, 0, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : 04321 __sip_xmit(p, req->data, req->len); 04322 deinit_req(req); 04323 return res; 04324 }
| static int send_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| int | seqno | |||
| ) | [static] |
Transmit response on SIP request.
Definition at line 4257 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, ast_inet_ntoa(), AST_SCHED_DEL_UNREF, ast_verbose, sip_request::data, deinit_req(), dialog_unref(), sip_pvt::do_history, finalize_content(), get_header(), sip_pvt::initreq, sip_request::len, sip_request::method, parse_copy(), sip_pvt::provisional_keepalive_sched_id, REQ_OFFSET_TO_STR, sip_request::rlPart1, sip_request::rlPart2, sip_debug_test_pvt(), SIP_INVITE, sip_methods, sip_nat_mode(), sip_real_dst(), SIP_RESPONSE, SIP_UNKNOWN, cfsip_methods::text, and XMIT_CRITICAL.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_minse(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_response_with_unsupported().
04258 { 04259 int res; 04260 04261 finalize_content(req); 04262 add_blank(req); 04263 if (sip_debug_test_pvt(p)) { 04264 const struct sockaddr_in *dst = sip_real_dst(p); 04265 04266 ast_verbose("\n<--- %sTransmitting (%s) to %s:%d --->\n%s\n<------------>\n", 04267 reliable ? "Reliably " : "", sip_nat_mode(p), 04268 ast_inet_ntoa(dst->sin_addr), 04269 ntohs(dst->sin_port), req->data->str); 04270 } 04271 if (p->do_history) { 04272 struct sip_request tmp = { .rlPart1 = 0, }; 04273 parse_copy(&tmp, req); 04274 append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data->str, get_header(&tmp, "CSeq"), 04275 (tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? REQ_OFFSET_TO_STR(&tmp, rlPart2) : sip_methods[tmp.method].text); 04276 deinit_req(&tmp); 04277 } 04278 04279 /* If we are sending a final response to an INVITE, stop retransmitting provisional responses */ 04280 if (p->initreq.method == SIP_INVITE && reliable == XMIT_CRITICAL) { 04281 AST_SCHED_DEL_UNREF(sched, p->provisional_keepalive_sched_id, dialog_unref(p, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 04282 } 04283 04284 res = (reliable) ? 04285 __sip_reliable_xmit(p, seqno, 1, req->data, req->len, (reliable == XMIT_CRITICAL), req->method) : 04286 __sip_xmit(p, req->data, req->len); 04287 deinit_req(req); 04288 if (res > 0) 04289 return 0; 04290 return res; 04291 }
| static int set_address_from_contact | ( | struct sip_pvt * | pvt | ) | [static] |
Change the other partys IP address based on given contact.
Definition at line 12381 of file chan_sip.c.
References __set_address_from_contact(), ast_test_flag, sip_pvt::flags, sip_pvt::fullcontact, sip_pvt::recv, sip_pvt::sa, SIP_NAT_ROUTE, SIP_TRANSPORT_TLS, sip_pvt::socket, and sip_socket::type.
Referenced by handle_response_invite().
12382 { 12383 if (ast_test_flag(&pvt->flags[0], SIP_NAT_ROUTE)) { 12384 /* NAT: Don't trust the contact field. Just use what they came to us 12385 with. */ 12386 /*! \todo We need to save the TRANSPORT here too */ 12387 pvt->sa = pvt->recv; 12388 return 0; 12389 } 12390 12391 return __set_address_from_contact(pvt->fullcontact, &pvt->sa, pvt->socket.type == SIP_TRANSPORT_TLS ? 1 : 0); 12392 }
| static void set_destination | ( | struct sip_pvt * | p, | |
| char * | uri | |||
| ) | [static] |
Set destination from SIP URI.
Parse uri to h (host) and port - uri is already just the part inside the <> general form we are expecting is sip[s]:username[:password][;parameter][:port][;...] If there's a port given, turn NAPTR/SRV off. NAPTR might indicate SIPS preference even for SIP: uri's
If there's a sips: uri scheme, TLS will be required.
Definition at line 9359 of file chan_sip.c.
References ast_copy_string(), ast_gethostbyname(), ast_inet_ntoa(), ast_log(), ast_verbose, sip_request::debug, FALSE, hostname, hp, LOG_WARNING, sip_pvt::sa, sip_cfg, sip_debug_test_pvt(), sip_settings::srvlookup, STANDARD_SIP_PORT, STANDARD_TLS_PORT, and TRUE.
Referenced by reqprep().
09360 { 09361 char *h, *maddr, hostname[256]; 09362 int port, hn; 09363 struct hostent *hp; 09364 struct ast_hostent ahp; 09365 int debug=sip_debug_test_pvt(p); 09366 int tls_on = FALSE; 09367 int use_dns = sip_cfg.srvlookup; 09368 09369 if (debug) 09370 ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri); 09371 09372 /* Find and parse hostname */ 09373 h = strchr(uri, '@'); 09374 if (h) 09375 ++h; 09376 else { 09377 h = uri; 09378 if (!strncasecmp(h, "sip:", 4)) { 09379 h += 4; 09380 } else if (!strncasecmp(h, "sips:", 5)) { 09381 h += 5; 09382 tls_on = TRUE; 09383 } 09384 } 09385 hn = strcspn(h, ":;>") + 1; 09386 if (hn > sizeof(hostname)) 09387 hn = sizeof(hostname); 09388 ast_copy_string(hostname, h, hn); 09389 /* XXX bug here if string has been trimmed to sizeof(hostname) */ 09390 h += hn - 1; 09391 09392 /* Is "port" present? if not default to STANDARD_SIP_PORT */ 09393 if (*h == ':') { 09394 /* Parse port */ 09395 ++h; 09396 port = strtol(h, &h, 10); 09397 use_dns = FALSE; 09398 } else 09399 port = tls_on ? STANDARD_TLS_PORT : STANDARD_SIP_PORT; 09400 09401 /* Got the hostname:port - but maybe there's a "maddr=" to override address? */ 09402 maddr = strstr(h, "maddr="); 09403 if (maddr) { 09404 maddr += 6; 09405 hn = strspn(maddr, "0123456789.") + 1; 09406 if (hn > sizeof(hostname)) 09407 hn = sizeof(hostname); 09408 ast_copy_string(hostname, maddr, hn); 09409 } 09410 09411 /*! \todo XXX If we have use_dns on, then look for NAPTR/SRV, otherwise, just look for A records */ 09412 09413 hp = ast_gethostbyname(hostname, &ahp); 09414 if (hp == NULL) { 09415 ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname); 09416 return; 09417 } 09418 p->sa.sin_family = AF_INET; 09419 memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr)); 09420 p->sa.sin_port = htons(port); 09421 if (debug) 09422 ast_verbose("set_destination: set destination to %s, port %d\n", ast_inet_ntoa(p->sa.sin_addr), port); 09423 }
| static void set_insecure_flags | ( | struct ast_flags * | flags, | |
| const char * | value, | |||
| int | lineno | |||
| ) | [static] |
Parse insecure= setting in sip.conf and set flags according to setting.
Definition at line 23482 of file chan_sip.c.
References ast_copy_string(), ast_false(), ast_log(), ast_set_flag, ast_strlen_zero(), buf, LOG_WARNING, SIP_INSECURE_INVITE, SIP_INSECURE_PORT, strsep(), and word.
Referenced by get_insecure_variable_from_config(), and handle_common_options().
23483 { 23484 if (ast_strlen_zero(value)) 23485 return; 23486 23487 if (!ast_false(value)) { 23488 char buf[64]; 23489 char *word, *next; 23490 23491 ast_copy_string(buf, value, sizeof(buf)); 23492 next = buf; 23493 while ((word = strsep(&next, ","))) { 23494 if (!strcasecmp(word, "port")) 23495 ast_set_flag(&flags[0], SIP_INSECURE_PORT); 23496 else if (!strcasecmp(word, "invite")) 23497 ast_set_flag(&flags[0], SIP_INSECURE_INVITE); 23498 else 23499 ast_log(LOG_WARNING, "Unknown insecure mode '%s' on line %d\n", value, lineno); 23500 } 23501 } 23502 }
| static void set_nonce_randdata | ( | struct sip_pvt * | p, | |
| int | forceupdate | |||
| ) | [static] |
builds the sip_pvt's randdata field which is used for the nonce challenge. When forceupdate is not set, the nonce is only updated if the current one is stale. In this case, a stalenonce is one which has already received a response, if a nonce has not received a response it is not always necessary or beneficial to create a new one.
Definition at line 12731 of file chan_sip.c.
References ast_random(), ast_string_field_build, ast_strlen_zero(), sip_pvt::randdata, and sip_pvt::stalenonce.
Referenced by check_auth(), and transmit_fake_auth_response().
12732 { 12733 if (p->stalenonce || forceupdate || ast_strlen_zero(p->randdata)) { 12734 ast_string_field_build(p, randdata, "%08lx", ast_random()); /* Create nonce for challenge */ 12735 p->stalenonce = 0; 12736 } 12737 }
| static void set_peer_defaults | ( | struct sip_peer * | peer | ) | [static] |
Set peer defaults before configuring specific configurations.
Definition at line 23854 of file chan_sip.c.
References sip_peer::addr, sip_settings::allowtransfer, sip_peer::allowtransfer, ast_copy_flags, ast_string_field_set, sip_peer::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_peer::capability, cid_name, cid_num, clear_peer_mailboxes(), context, sip_peer::defaddr, sip_settings::default_context, sip_peer::default_outbound_transport, default_prefs, sip_settings::default_subscribecontext, sip_peer::expire, sip_peer::flags, language, sip_peer::maxcallbitrate, sip_peer::maxms, mohinterpret, mohsuggest, sip_peer::pickupgroup, sip_peer::pokeexpire, sip_peer::prefs, sip_peer::qualifyfreq, sip_peer::rtpholdtimeout, sip_peer::rtpkeepalive, sip_peer::rtptimeout, secret, set_socket_transport(), sip_cfg, SIP_FLAGS_TO_COPY, SIP_PAGE2_FLAGS_TO_COPY, SIP_TRANSPORT_UDP, SIP_TYPE_PEER, sip_peer::socket, sip_st_cfg::st_max_se, sip_st_cfg::st_min_se, sip_st_cfg::st_mode_oper, sip_st_cfg::st_ref, STANDARD_SIP_PORT, sip_peer::stimer, sip_peer::t38_maxdatagram, sip_peer::timer_b, sip_peer::timer_t1, sip_peer::transports, and sip_peer::type.
Referenced by build_peer(), and temp_peer().
23855 { 23856 if (peer->expire == 0) { 23857 /* Don't reset expire or port time during reload 23858 if we have an active registration 23859 */ 23860 peer->expire = -1; 23861 peer->pokeexpire = -1; 23862 peer->addr.sin_port = htons(STANDARD_SIP_PORT); 23863 set_socket_transport(&peer->socket, SIP_TRANSPORT_UDP); 23864 } 23865 peer->type = SIP_TYPE_PEER; 23866 ast_copy_flags(&peer->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 23867 ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 23868 ast_string_field_set(peer, context, sip_cfg.default_context); 23869 ast_string_field_set(peer, subscribecontext, sip_cfg.default_subscribecontext); 23870 ast_string_field_set(peer, language, default_language); 23871 ast_string_field_set(peer, mohinterpret, default_mohinterpret); 23872 ast_string_field_set(peer, mohsuggest, default_mohsuggest); 23873 peer->addr.sin_family = AF_INET; 23874 peer->defaddr.sin_family = AF_INET; 23875 peer->capability = global_capability; 23876 peer->maxcallbitrate = default_maxcallbitrate; 23877 peer->rtptimeout = global_rtptimeout; 23878 peer->rtpholdtimeout = global_rtpholdtimeout; 23879 peer->rtpkeepalive = global_rtpkeepalive; 23880 peer->allowtransfer = sip_cfg.allowtransfer; 23881 peer->autoframing = global_autoframing; 23882 peer->t38_maxdatagram = global_t38_maxdatagram; 23883 peer->qualifyfreq = global_qualifyfreq; 23884 if (global_callcounter) 23885 peer->call_limit=INT_MAX; 23886 ast_string_field_set(peer, vmexten, default_vmexten); 23887 ast_string_field_set(peer, secret, ""); 23888 ast_string_field_set(peer, remotesecret, ""); 23889 ast_string_field_set(peer, md5secret, ""); 23890 ast_string_field_set(peer, cid_num, ""); 23891 ast_string_field_set(peer, cid_name, ""); 23892 ast_string_field_set(peer, fromdomain, ""); 23893 ast_string_field_set(peer, fromuser, ""); 23894 ast_string_field_set(peer, regexten, ""); 23895 peer->callgroup = 0; 23896 peer->pickupgroup = 0; 23897 peer->maxms = default_qualify; 23898 peer->prefs = default_prefs; 23899 peer->stimer.st_mode_oper = global_st_mode; /* Session-Timers */ 23900 peer->stimer.st_ref = global_st_refresher; 23901 peer->stimer.st_min_se = global_min_se; 23902 peer->stimer.st_max_se = global_max_se; 23903 peer->timer_t1 = global_t1; 23904 peer->timer_b = global_timer_b; 23905 clear_peer_mailboxes(peer); 23906 peer->transports = default_transports; 23907 peer->default_outbound_transport = default_primary_transport; 23908 }
| static void set_socket_transport | ( | struct sip_socket * | socket, | |
| int | transport | |||
| ) | [static] |
Definition at line 12166 of file chan_sip.c.
References ao2_ref, sip_socket::fd, sip_socket::tcptls_session, and sip_socket::type.
Referenced by __sip_subscribe_mwi_do(), _sip_tcp_helper_thread(), build_peer(), create_addr(), expire_register(), get_transport_pvt(), parse_moved_contact(), parse_register_contact(), set_peer_defaults(), sip_alloc(), sip_request_call(), sip_send_mwi_to_peer(), sipsock_read(), and transmit_register().
12167 { 12168 /* if the transport type changes, clear all socket data */ 12169 if (socket->type != transport) { 12170 socket->fd = -1; 12171 socket->type = transport; 12172 if (socket->tcptls_session) { 12173 ao2_ref(socket->tcptls_session, -1); 12174 socket->tcptls_session = NULL; 12175 } 12176 } 12177 }
| static void set_t38_capabilities | ( | struct sip_pvt * | p | ) | [static] |
Set the global T38 capabilities on a SIP dialog structure.
Definition at line 5140 of file chan_sip.c.
References ast_test_flag, ast_udptl_set_error_correction_scheme(), sip_pvt::flags, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_T38SUPPORT_UDPTL, SIP_PAGE2_T38SUPPORT_UDPTL_FEC, SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY, sip_pvt::udptl, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by check_peer_ok(), create_addr_from_peer(), handle_request_invite(), and sip_alloc().
05141 { 05142 if (p->udptl) { 05143 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY) { 05144 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_REDUNDANCY); 05145 } else if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL_FEC) { 05146 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_FEC); 05147 } else if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL) { 05148 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 05149 } 05150 } 05151 }
| static int show_channels_cb | ( | void * | __cur, | |
| void * | __arg, | |||
| int | flags | |||
| ) | [static] |
callback for show channel|subscription
Definition at line 16399 of file chan_sip.c.
References ast_cli(), ast_extension_state2str(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_str_alloca, ast_test_flag, sip_pvt::callid, sip_pvt::cid_num, cli_yesno(), sip_pvt::expiry, __show_chan_arg::fd, sip_pvt::flags, FORMAT, FORMAT4, sip_pvt::lastmsg, sip_pvt::laststate, MWI_NOTIFICATION, ast_channel::nativeformats, sip_pvt::needdestroy, NONE, __show_chan_arg::numchans, sip_pvt::owner, peer_mailboxes_to_str(), sip_pvt::refer, referstatus2str(), sip_pvt::relatedpeer, S_OR, SIP_PAGE2_CALL_ONHOLD, sip_real_dst(), SIPBUFSIZE, sip_refer::status, sip_pvt::subscribed, sip_pvt::subscribeuri, subscription_type2str(), __show_chan_arg::subscriptions, and sip_pvt::username.
Referenced by sip_show_channels().
16400 { 16401 struct sip_pvt *cur = __cur; 16402 struct __show_chan_arg *arg = __arg; 16403 const struct sockaddr_in *dst = sip_real_dst(cur); 16404 16405 /* XXX indentation preserved to reduce diff. Will be fixed later */ 16406 if (cur->subscribed == NONE && !arg->subscriptions) { 16407 /* set if SIP transfer in progress */ 16408 const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : ""; 16409 char formatbuf[SIPBUFSIZE/2]; 16410 16411 ast_cli(arg->fd, FORMAT, ast_inet_ntoa(dst->sin_addr), 16412 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 16413 cur->callid, 16414 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0), 16415 cli_yesno(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)), 16416 cur->needdestroy ? "(d)" : "", 16417 cur->lastmsg , 16418 referstatus 16419 ); 16420 arg->numchans++; 16421 } 16422 if (cur->subscribed != NONE && arg->subscriptions) { 16423 struct ast_str *mailbox_str = ast_str_alloca(512); 16424 if (cur->subscribed == MWI_NOTIFICATION && cur->relatedpeer) 16425 peer_mailboxes_to_str(&mailbox_str, cur->relatedpeer); 16426 ast_cli(arg->fd, FORMAT4, ast_inet_ntoa(dst->sin_addr), 16427 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 16428 cur->callid, 16429 /* the 'complete' exten/context is hidden in the refer_to field for subscriptions */ 16430 cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, 16431 cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 16432 subscription_type2str(cur->subscribed), 16433 cur->subscribed == MWI_NOTIFICATION ? S_OR(mailbox_str->str, "<none>") : "<none>", 16434 cur->expiry 16435 ); 16436 arg->numchans++; 16437 } 16438 return 0; /* don't care, we scan all channels */ 16439 }
| static int show_chanstats_cb | ( | void * | __cur, | |
| void * | __arg, | |||
| int | flags | |||
| ) | [static] |
Callback for show_chanstats.
Definition at line 16042 of file chan_sip.c.
References ast_cli(), ast_inet_ntoa(), ast_rtp_get_qosvalue(), AST_RTP_RXCOUNT, AST_RTP_RXJITTER, AST_RTP_RXPLOSS, AST_RTP_TXCOUNT, AST_RTP_TXJITTER, AST_RTP_TXPLOSS, ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), sip_pvt::callid, ast_channel::cdr, invstate2stringtable::desc, __show_chan_arg::fd, FORMAT, sip_pvt::invitestate, invitestate2string, NONE, __show_chan_arg::numchans, sip_pvt::owner, sip_pvt::rtp, sip_pvt::sa, ast_cdr::start, and sip_pvt::subscribed.
Referenced by sip_show_channelstats().
16043 { 16044 #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" 16045 #define FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.6u\n" 16046 struct sip_pvt *cur = __cur; 16047 unsigned int rxcount, txcount, rxploss, txploss; 16048 char durbuf[10]; 16049 int duration; 16050 int durh, durm, durs; 16051 struct ast_channel *c = cur->owner; 16052 struct __show_chan_arg *arg = __arg; 16053 int fd = arg->fd; 16054 16055 16056 if (cur->subscribed != NONE) /* Subscriptions */ 16057 return 0; /* don't care, we scan all channels */ 16058 16059 if (!cur->rtp) { 16060 if (sipdebug) 16061 ast_cli(fd, "%-15.15s %-11.11s (inv state: %s) -- %s\n", ast_inet_ntoa(cur->sa.sin_addr), cur->callid, invitestate2string[cur->invitestate].desc, "-- No RTP active"); 16062 return 0; /* don't care, we scan all channels */ 16063 } 16064 rxcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXCOUNT); 16065 txcount = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXCOUNT); 16066 rxploss = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXPLOSS); 16067 txploss = ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXPLOSS); 16068 16069 /* Find the duration of this channel */ 16070 if (c && c->cdr && !ast_tvzero(c->cdr->start)) { 16071 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 16072 durh = duration / 3600; 16073 durm = (duration % 3600) / 60; 16074 durs = duration % 60; 16075 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 16076 } else { 16077 durbuf[0] = '\0'; 16078 } 16079 /* Print stats for every call with RTP */ 16080 ast_cli(fd, FORMAT, 16081 ast_inet_ntoa(cur->sa.sin_addr), 16082 cur->callid, 16083 durbuf, 16084 rxcount > (unsigned int) 100000 ? (unsigned int) (rxcount)/(unsigned int) 1000 : rxcount, 16085 rxcount > (unsigned int) 100000 ? "K":" ", 16086 rxploss, 16087 (rxcount + rxploss) > 0 ? (double) rxploss / (rxcount + rxploss) * 100 : 0, 16088 ast_rtp_get_qosvalue(cur->rtp, AST_RTP_RXJITTER), 16089 txcount > (unsigned int) 100000 ? (unsigned int) (txcount)/(unsigned int) 1000 : txcount, 16090 txcount > (unsigned int) 100000 ? "K":" ", 16091 txploss, 16092 txcount > 0 ? (double) txploss / txcount * 100 : 0, 16093 ast_rtp_get_qosvalue(cur->rtp, AST_RTP_TXJITTER) 16094 ); 16095 arg->numchans++; 16096 16097 return 0; /* don't care, we scan all channels */ 16098 }
| static int sip_addheader | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Add a SIP header to an outbound INVITE.
Definition at line 25731 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_get_encoded_str(), ast_log(), ast_strlen_zero(), FALSE, inbuf(), LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and TRUE.
Referenced by load_module().
25732 { 25733 int no = 0; 25734 int ok = FALSE; 25735 char varbuf[30]; 25736 char *inbuf = data, *subbuf; 25737 25738 if (ast_strlen_zero(inbuf)) { 25739 ast_log(LOG_WARNING, "This application requires the argument: Header\n"); 25740 return 0; 25741 } 25742 ast_channel_lock(chan); 25743 25744 /* Check for headers */ 25745 while (!ok && no <= 50) { 25746 no++; 25747 snprintf(varbuf, sizeof(varbuf), "__SIPADDHEADER%.2d", no); 25748 25749 /* Compare without the leading underscores */ 25750 if ((pbx_builtin_getvar_helper(chan, (const char *) varbuf + 2) == (const char *) NULL)) { 25751 ok = TRUE; 25752 } 25753 } 25754 if (ok) { 25755 size_t len = strlen(inbuf); 25756 subbuf = alloca(len + 1); 25757 ast_get_encoded_str(inbuf, subbuf, len + 1); 25758 pbx_builtin_setvar_helper(chan, varbuf, subbuf); 25759 if (sipdebug) { 25760 ast_debug(1, "SIP Header added \"%s\" as %s\n", inbuf, varbuf); 25761 } 25762 } else { 25763 ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n"); 25764 } 25765 ast_channel_unlock(chan); 25766 return 0; 25767 }
| static struct sip_pvt * sip_alloc | ( | ast_string_field | callid, | |
| struct sockaddr_in * | sin, | |||
| int | useglobal_nat, | |||
| const int | intended_method, | |||
| struct sip_request * | req | |||
| ) | [static, read] |
Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference.
Definition at line 7255 of file chan_sip.c.
References sip_settings::allowtransfer, sip_pvt::allowtransfer, ao2_t_alloc, ao2_t_link, ao2_t_ref, ast_clear_flag, ast_copy_flags, ast_debug, AST_LIST_HEAD_INIT_NOLOCK, ast_log(), ast_random(), ast_rtp_codec_setpref(), AST_RTP_DTMF, ast_rtp_new_with_bindaddr(), ast_rtp_set_rtpholdtimeout(), ast_rtp_set_rtpkeepalive(), ast_rtp_set_rtptimeout(), ast_rtp_setdtmf(), ast_rtp_setdtmfcompensate(), ast_rtp_setqos(), ast_sip_ouraddrfor(), ast_string_field_init, ast_string_field_set, ast_test_flag, ast_udptl_new_with_bindaddr(), ast_udptl_setqos(), ast_variables_destroy(), sip_pvt::autoframing, sip_pvt::autokillid, bindaddr, sip_pvt::branch, build_callid_pvt(), build_via(), sip_pvt::callid, sip_pvt::capability, sip_pvt::chanvars, context, sip_settings::default_context, default_prefs, sip_pvt::do_history, do_setnat(), errno, sip_socket::fd, sip_pvt::flags, sip_pvt::fromdomain, INITIAL_CSEQ, sip_pvt::initid, internip, LOG_ERROR, LOG_WARNING, make_our_tag(), sip_pvt::maxcallbitrate, sip_pvt::method, mohinterpret, mohsuggest, sip_pvt::noncodeccapability, NONE, sip_pvt::ocseq, sip_pvt::ourip, parkinglot, sip_pvt::prefs, sip_pvt::provisional_keepalive_sched_id, sip_pvt::recv, sip_pvt::request_queue, sip_pvt::request_queue_sched_id, sip_pvt::rtp, sip_pvt::sa, sip_pvt::session_modify, sip_pvt::sessionversion_remote, set_socket_transport(), set_t38_capabilities(), sip_cfg, sip_destroy_fn(), SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, sip_methods, SIP_NAT, SIP_NAT_ROUTE, SIP_OPTIONS, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PAGE2_VIDEOSUPPORT_ALWAYS, SIP_REGISTER, SIP_TRANSPORT_UDP, sip_request::socket, sip_pvt::socket, sip_pvt::stateid, sip_pvt::stimer, sip_pvt::subscribed, sip_pvt::t38_maxdatagram, sip_pvt::t38id, sip_pvt::tag, cfsip_methods::text, sip_pvt::timer_b, sip_pvt::timer_t1, sip_pvt::trtp, TRUE, sip_socket::type, sip_pvt::udptl, sip_pvt::vrtp, and sip_pvt::waitid.
Referenced by __sip_subscribe_mwi_do(), find_call(), manager_sipnotify(), sip_cli_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), and transmit_register().
07257 { 07258 struct sip_pvt *p; 07259 07260 if (!(p = ao2_t_alloc(sizeof(*p), sip_destroy_fn, "allocate a dialog(pvt) struct"))) 07261 return NULL; 07262 07263 if (ast_string_field_init(p, 512)) { 07264 ao2_t_ref(p, -1, "failed to string_field_init, drop p"); 07265 return NULL; 07266 } 07267 07268 if (req) { 07269 set_socket_transport(&p->socket, req->socket.type); /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */ 07270 } else { 07271 set_socket_transport(&p->socket, SIP_TRANSPORT_UDP); 07272 } 07273 07274 p->socket.fd = -1; 07275 p->method = intended_method; 07276 p->initid = -1; 07277 p->waitid = -1; 07278 p->autokillid = -1; 07279 p->request_queue_sched_id = -1; 07280 p->provisional_keepalive_sched_id = -1; 07281 p->t38id = -1; 07282 p->subscribed = NONE; 07283 p->stateid = -1; 07284 p->sessionversion_remote = -1; 07285 p->session_modify = TRUE; 07286 p->stimer = NULL; 07287 p->prefs = default_prefs; /* Set default codecs for this call */ 07288 07289 if (intended_method != SIP_OPTIONS) { /* Peerpoke has it's own system */ 07290 p->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */ 07291 p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */ 07292 } 07293 07294 if (!sin) 07295 p->ourip = internip; 07296 else { 07297 p->sa = *sin; 07298 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 07299 } 07300 07301 /* Copy global flags to this PVT at setup. */ 07302 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 07303 ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 07304 07305 p->do_history = recordhistory; 07306 07307 p->branch = ast_random(); 07308 make_our_tag(p->tag, sizeof(p->tag)); 07309 p->ocseq = INITIAL_CSEQ; 07310 07311 if (sip_methods[intended_method].need_rtp) { 07312 p->rtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 07313 /* If the global videosupport flag is on, we always create a RTP interface for video */ 07314 if (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) || 07315 ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS)) 07316 p->vrtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 07317 if (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT)) 07318 p->trtp = ast_rtp_new_with_bindaddr(sched, io, 1, 0, bindaddr.sin_addr); 07319 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) { 07320 if (!(p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, bindaddr.sin_addr))) { 07321 /* udptl creation failed, T38 can not be supported on this dialog */ 07322 ast_log(LOG_ERROR, "UDPTL creation failed\n"); 07323 ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT); 07324 } 07325 } 07326 if (!p->rtp|| (ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) && !p->vrtp) 07327 || (ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) && !p->trtp)) { 07328 ast_log(LOG_WARNING, "Unable to create RTP audio %s%ssession: %s\n", 07329 ast_test_flag(&p->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "and video " : "", 07330 ast_test_flag(&p->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "and text " : "", strerror(errno)); 07331 if (p->chanvars) { 07332 ast_variables_destroy(p->chanvars); 07333 p->chanvars = NULL; 07334 } 07335 ao2_t_ref(p, -1, "failed to create RTP audio session, drop p"); 07336 return NULL; 07337 p->t38_maxdatagram = global_t38_maxdatagram; 07338 } 07339 ast_rtp_setqos(p->rtp, global_tos_audio, global_cos_audio, "SIP RTP"); 07340 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 07341 ast_rtp_setdtmfcompensate(p->rtp, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 07342 ast_rtp_set_rtptimeout(p->rtp, global_rtptimeout); 07343 ast_rtp_set_rtpholdtimeout(p->rtp, global_rtpholdtimeout); 07344 ast_rtp_set_rtpkeepalive(p->rtp, global_rtpkeepalive); 07345 if (p->vrtp) { 07346 ast_rtp_setqos(p->vrtp, global_tos_video, global_cos_video, "SIP VRTP"); 07347 ast_rtp_setdtmf(p->vrtp, 0); 07348 ast_rtp_setdtmfcompensate(p->vrtp, 0); 07349 ast_rtp_set_rtptimeout(p->vrtp, global_rtptimeout); 07350 ast_rtp_set_rtpholdtimeout(p->vrtp, global_rtpholdtimeout); 07351 ast_rtp_set_rtpkeepalive(p->vrtp, global_rtpkeepalive); 07352 } 07353 if (p->trtp) { 07354 ast_rtp_setqos(p->trtp, global_tos_text, global_cos_text, "SIP TRTP"); 07355 ast_rtp_setdtmf(p->trtp, 0); 07356 ast_rtp_setdtmfcompensate(p->trtp, 0); 07357 } 07358 if (p->udptl) 07359 ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio); 07360 p->maxcallbitrate = default_maxcallbitrate; 07361 p->autoframing = global_autoframing; 07362 ast_rtp_codec_setpref(p->rtp, &p->prefs); 07363 } 07364 07365 if (useglobal_nat && sin) { 07366 /* Setup NAT structure according to global settings if we have an address */ 07367 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT); 07368 p->recv = *sin; 07369 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 07370 } 07371 07372 if (p->method != SIP_REGISTER) 07373 ast_string_field_set(p, fromdomain, default_fromdomain); 07374 build_via(p); 07375 if (!callid) 07376 build_callid_pvt(p); 07377 else 07378 ast_string_field_set(p, callid, callid); 07379 /* Assign default music on hold class */ 07380 ast_string_field_set(p, mohinterpret, default_mohinterpret); 07381 ast_string_field_set(p, mohsuggest, default_mohsuggest); 07382 p->capability = global_capability; 07383 p->allowtransfer = sip_cfg.allowtransfer; 07384 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 07385 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 07386 p->noncodeccapability |= AST_RTP_DTMF; 07387 if (p->udptl) { 07388 p->t38_maxdatagram = global_t38_maxdatagram; 07389 set_t38_capabilities(p); 07390 } 07391 ast_string_field_set(p, context, sip_cfg.default_context); 07392 ast_string_field_set(p, parkinglot, default_parkinglot); 07393 07394 AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue); 07395 07396 /* Add to active dialog list */ 07397 07398 ao2_t_link(dialogs, p, "link pvt into dialogs table"); 07399 07400 ast_debug(1, "Allocating new SIP dialog for %s - %s (%s)\n", callid ? callid : p->callid, sip_methods[intended_method].text, p->rtp ? "With RTP" : "No RTP"); 07401 return p; 07402 }
| static void sip_alreadygone | ( | struct sip_pvt * | dialog | ) | [static] |
Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging.
Definition at line 3299 of file chan_sip.c.
References sip_pvt::alreadygone, ast_debug, and sip_pvt::callid.
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_subscribe(), retrans_pkt(), sip_indicate(), and sip_sipredirect().
03300 { 03301 ast_debug(3, "Setting SIP_ALREADYGONE on dialog %s\n", dialog->callid); 03302 dialog->alreadygone = 1; 03303 }
| static int sip_answer | ( | struct ast_channel * | ast | ) | [static] |
sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface
Definition at line 6261 of file chan_sip.c.
References ast_channel::_state, ast_debug, ast_rtp_new_source(), ast_set_flag, ast_setstate(), AST_STATE_UP, FALSE, sip_pvt::flags, sip_pvt::initreq, ast_channel::name, sip_pvt::rtp, SIP_PAGE2_DIALOG_ESTABLISHED, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_response_with_sdp(), try_suggested_sip_codec(), and XMIT_CRITICAL.
06262 { 06263 int res = 0; 06264 struct sip_pvt *p = ast->tech_pvt; 06265 06266 sip_pvt_lock(p); 06267 if (ast->_state != AST_STATE_UP) { 06268 try_suggested_sip_codec(p); 06269 06270 ast_setstate(ast, AST_STATE_UP); 06271 ast_debug(1, "SIP answering channel: %s\n", ast->name); 06272 ast_rtp_new_source(p->rtp); 06273 res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE); 06274 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 06275 } 06276 sip_pvt_unlock(p); 06277 return res; 06278 }
| static int sip_call | ( | struct ast_channel * | ast, | |
| char * | dest, | |||
| int | timeout | |||
| ) | [static] |
Initiate SIP call from PBX used from the dial() application.
Definition at line 5443 of file chan_sip.c.
References ast_channel::_state, sip_invite_param::addsipheaders, AST_CAUSE_USER_BUSY, ast_clear_flag, ast_debug, AST_FORMAT_AUDIO_MASK, AST_LIST_TRAVERSE, ast_log(), AST_SCHED_REPLACE_UNREF, ast_set_flag, AST_STATE_DOWN, AST_STATE_RESERVED, ast_string_field_set, ast_translate_available_formats(), ast_var_name(), ast_var_value(), auto_congest(), buf, sip_pvt::callingpres, sip_pvt::capability, ast_channel::cid, cid_name, sip_pvt::cid_name, ast_callerid::cid_pres, dialog_ref(), dialog_unref(), ast_var_t::entries, sip_pvt::flags, ast_channel::hangupcause, INC_CALL_RINGING, sip_pvt::initid, INV_CALLING, sip_pvt::invitestate, sip_pvt::jointcapability, sip_pvt::jointnoncodeccapability, LOG_WARNING, ast_channel::name, sip_pvt::noncodeccapability, sip_pvt::options, sip_pvt::prefcodec, sip_invite_param::replaces, SIP_INVITE, SIP_OUTGOING, SIP_PAGE2_FAX_DETECT_T38, SIPBUFSIZE, ast_channel::tech_pvt, sip_pvt::timer_b, sip_invite_param::transfer, transmit_invite(), update_call_counter(), sip_invite_param::uri_options, sip_pvt::username, ast_channel::varshead, sip_invite_param::vxml_url, and XMIT_ERROR.
05444 { 05445 int res; 05446 struct sip_pvt *p = ast->tech_pvt; /* chan is locked, so the reference cannot go away */ 05447 struct varshead *headp; 05448 struct ast_var_t *current; 05449 const char *referer = NULL; /* SIP referrer */ 05450 05451 if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { 05452 ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name); 05453 return -1; 05454 } 05455 05456 /* Check whether there is vxml_url, distinctive ring variables */ 05457 headp=&ast->varshead; 05458 AST_LIST_TRAVERSE(headp, current, entries) { 05459 /* Check whether there is a VXML_URL variable */ 05460 if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) { 05461 p->options->vxml_url = ast_var_value(current); 05462 } else if (!p->options->uri_options && !strcasecmp(ast_var_name(current), "SIP_URI_OPTIONS")) { 05463 p->options->uri_options = ast_var_value(current); 05464 } else if (!p->options->addsipheaders && !strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 05465 /* Check whether there is a variable with a name starting with SIPADDHEADER */ 05466 p->options->addsipheaders = 1; 05467 } else if (!strcasecmp(ast_var_name(current), "SIPFROMDOMAIN")) { 05468 ast_string_field_set(p, fromdomain, ast_var_value(current)); 05469 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER")) { 05470 /* This is a transfered call */ 05471 p->options->transfer = 1; 05472 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REFERER")) { 05473 /* This is the referrer */ 05474 referer = ast_var_value(current); 05475 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) { 05476 /* We're replacing a call. */ 05477 p->options->replaces = ast_var_value(current); 05478 } 05479 } 05480 05481 res = 0; 05482 ast_set_flag(&p->flags[0], SIP_OUTGOING); 05483 05484 /* T.38 re-INVITE FAX detection should never be done for outgoing calls, 05485 * so ensure it is disabled. 05486 */ 05487 ast_clear_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38); 05488 05489 if (p->options->transfer) { 05490 char buf[SIPBUFSIZE/2]; 05491 05492 if (referer) { 05493 if (sipdebug) 05494 ast_debug(3, "Call for %s transfered by %s\n", p->username, referer); 05495 snprintf(buf, sizeof(buf)-1, "-> %s (via %s)", p->cid_name, referer); 05496 } else 05497 snprintf(buf, sizeof(buf)-1, "-> %s", p->cid_name); 05498 ast_string_field_set(p, cid_name, buf); 05499 } 05500 ast_debug(1, "Outgoing Call for %s\n", p->username); 05501 05502 res = update_call_counter(p, INC_CALL_RINGING); 05503 05504 if (res == -1) { 05505 ast->hangupcause = AST_CAUSE_USER_BUSY; 05506 return res; 05507 } 05508 p->callingpres = ast->cid.cid_pres; 05509 p->jointcapability = ast_translate_available_formats(p->capability, p->prefcodec); 05510 p->jointnoncodeccapability = p->noncodeccapability; 05511 05512 /* If there are no audio formats left to offer, punt */ 05513 if (!(p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 05514 ast_log(LOG_WARNING, "No audio format found to offer. Cancelling call to %s\n", p->username); 05515 res = -1; 05516 } else { 05517 int xmitres; 05518 05519 xmitres = transmit_invite(p, SIP_INVITE, 1, 2); 05520 if (xmitres == XMIT_ERROR) 05521 return -1; 05522 p->invitestate = INV_CALLING; 05523 05524 /* Initialize auto-congest time */ 05525 AST_SCHED_REPLACE_UNREF(p->initid, sched, p->timer_b, auto_congest, p, 05526 dialog_unref(_data, "dialog ptr dec when SCHED_REPLACE del op succeeded"), 05527 dialog_unref(p, "dialog ptr dec when SCHED_REPLACE add failed"), 05528 dialog_ref(p, "dialog ptr inc when SCHED_REPLACE add succeeded") ); 05529 } 05530 return res; 05531 }
| static int sip_cancel_destroy | ( | struct sip_pvt * | p | ) | [static] |
Cancel destruction of SIP dialog. Be careful as this also absorbs the reference - if you call it from within the scheduler, this might be the last reference.
Definition at line 4077 of file chan_sip.c.
References append_history, ast_sched_del(), sip_pvt::autokillid, and dialog_unref().
Referenced by cb_extensionstate(), handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), register_verify(), sip_hangup(), and sip_scheddestroy().
04078 { 04079 int res = 0; 04080 if (p->autokillid > -1) { 04081 int res3; 04082 04083 if (!(res3 = ast_sched_del(sched, p->autokillid))) { 04084 append_history(p, "CancelDestroy", ""); 04085 p->autokillid = -1; 04086 dialog_unref(p, "dialog unrefd because autokillid is de-sched'd"); 04087 } 04088 } 04089 return res; 04090 }
| static char * sip_cli_notify | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Cli command to send SIP notify to peer.
Definition at line 17101 of file chan_sip.c.
References ao2_t_link, ao2_t_unlink, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_log(), ast_set_flag, ast_sip_ouraddrfor(), ast_variable_browse(), build_callid_pvt(), build_via(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sipnotify(), create_addr(), dialog_ref(), dialog_unlink_all(), dialog_unref(), ast_cli_args::fd, sip_pvt::flags, ast_cli_args::line, LOG_WARNING, ast_cli_args::n, sip_pvt::ourip, ast_cli_args::pos, sip_pvt::sa, sip_alloc(), SIP_NOTIFY, SIP_OUTGOING, sip_scheddestroy(), SIP_TRANS_TIMEOUT, transmit_notify_custom(), TRUE, ast_cli_entry::usage, and ast_cli_args::word.
17102 { 17103 struct ast_variable *varlist; 17104 int i; 17105 17106 switch (cmd) { 17107 case CLI_INIT: 17108 e->command = "sip notify"; 17109 e->usage = 17110 "Usage: sip notify <type> <peer> [<peer>...]\n" 17111 " Send a NOTIFY message to a SIP peer or peers\n" 17112 " Message types are defined in sip_notify.conf\n"; 17113 return NULL; 17114 case CLI_GENERATE: 17115 return complete_sipnotify(a->line, a->word, a->pos, a->n); 17116 } 17117 17118 if (a->argc < 4) 17119 return CLI_SHOWUSAGE; 17120 17121 if (!notify_types) { 17122 ast_cli(a->fd, "No %s file found, or no types listed there\n", notify_config); 17123 return CLI_FAILURE; 17124 } 17125 17126 varlist = ast_variable_browse(notify_types, a->argv[2]); 17127 17128 if (!varlist) { 17129 ast_cli(a->fd, "Unable to find notify type '%s'\n", a->argv[2]); 17130 return CLI_FAILURE; 17131 } 17132 17133 for (i = 3; i < a->argc; i++) { 17134 struct sip_pvt *p; 17135 17136 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) { 17137 ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n"); 17138 return CLI_FAILURE; 17139 } 17140 17141 if (create_addr(p, a->argv[i], NULL, 1)) { 17142 /* Maybe they're not registered, etc. */ 17143 dialog_unlink_all(p, TRUE, TRUE); 17144 dialog_unref(p, "unref dialog inside for loop" ); 17145 /* sip_destroy(p); */ 17146 ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]); 17147 continue; 17148 } 17149 17150 /* Notify is outgoing call */ 17151 ast_set_flag(&p->flags[0], SIP_OUTGOING); 17152 17153 /* Recalculate our side, and recalculate Call ID */ 17154 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 17155 build_via(p); 17156 ao2_t_unlink(dialogs, p, "About to change the callid -- remove the old name"); 17157 build_callid_pvt(p); 17158 ao2_t_link(dialogs, p, "Linking in new name"); 17159 ast_cli(a->fd, "Sending NOTIFY of type '%s' to '%s'\n", a->argv[2], a->argv[i]); 17160 dialog_ref(p, "bump the count of p, which transmit_sip_request will decrement."); 17161 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); 17162 transmit_notify_custom(p, varlist); 17163 } 17164 17165 return CLI_SUCCESS; 17166 }
| static int sip_debug_test_addr | ( | const struct sockaddr_in * | addr | ) | [inline, static] |
See if we pass debug IP filter.
Definition at line 3458 of file chan_sip.c.
References debugaddr.
Referenced by check_peer_ok(), handle_request_do(), and sip_debug_test_pvt().
03459 { 03460 if (!sipdebug) 03461 return 0; 03462 if (debugaddr.sin_addr.s_addr) { 03463 if (((ntohs(debugaddr.sin_port) != 0) 03464 && (debugaddr.sin_port != addr->sin_port)) 03465 || (debugaddr.sin_addr.s_addr != addr->sin_addr.s_addr)) 03466 return 0; 03467 } 03468 return 1; 03469 }
| static int sip_debug_test_pvt | ( | struct sip_pvt * | p | ) | [inline, static] |
Test PVT for debugging output.
Definition at line 3487 of file chan_sip.c.
References sip_debug_test_addr(), and sip_real_dst().
Referenced by __sip_destroy(), add_sdp(), build_route(), check_via(), do_register_auth(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), handle_incoming(), process_sdp(), process_sdp_a_audio(), process_sdp_a_text(), process_sdp_a_video(), receive_message(), retrans_pkt(), send_request(), send_response(), set_destination(), sip_scheddestroy(), sip_sendhtml(), sip_sendtext(), and transmit_register().
03488 { 03489 if (!sipdebug) 03490 return 0; 03491 return sip_debug_test_addr(sip_real_dst(p)); 03492 }
Destroy SIP call structure. Make it return NULL so the caller can do things like foo = sip_destroy(foo); and reduce the chance of bugs due to dangling pointers.
Definition at line 5860 of file chan_sip.c.
References __sip_destroy(), ast_debug, sip_pvt::callid, and TRUE.
Referenced by sip_destroy_fn(), and sip_subscribe_mwi_destroy().
05861 { 05862 ast_debug(3, "Destroying SIP dialog %s\n", p->callid); 05863 __sip_destroy(p, TRUE, TRUE); 05864 return NULL; 05865 }
| static void sip_destroy_fn | ( | void * | p | ) | [static] |
Definition at line 5850 of file chan_sip.c.
References sip_destroy().
Referenced by sip_alloc().
05851 { 05852 sip_destroy(p); 05853 }
| static void sip_destroy_peer | ( | struct sip_peer * | peer | ) | [static] |
Destroy peer object from memory.
Definition at line 4713 of file chan_sip.c.
References ao2_ref, ast_atomic_fetchadd_int(), ast_debug, ast_dnsmgr_release(), ast_free_ha(), ast_string_field_free_memory, ast_variables_destroy(), sip_peer::auth, sip_peer::call, sip_peer::chanvars, clear_peer_mailboxes(), clear_realm_authentication(), dialog_unlink_all(), dialog_unref(), sip_peer::dnsmgr, FALSE, sip_peer::ha, sip_peer::is_realtime, sip_peer::mwipvt, sip_peer::name, sip_peer::outboundproxy, register_peer_exten(), sip_peer::selfdestruct, sip_peer::socket, sip_socket::tcptls_session, and TRUE.
Referenced by sip_destroy_peer_fn().
04714 { 04715 ast_debug(3, "Destroying SIP peer %s\n", peer->name); 04716 if (peer->outboundproxy) 04717 ao2_ref(peer->outboundproxy, -1); 04718 peer->outboundproxy = NULL; 04719 04720 /* Delete it, it needs to disappear */ 04721 if (peer->call) { 04722 dialog_unlink_all(peer->call, TRUE, TRUE); 04723 peer->call = dialog_unref(peer->call, "peer->call is being unset"); 04724 } 04725 04726 04727 if (peer->mwipvt) { /* We have an active subscription, delete it */ 04728 dialog_unlink_all(peer->mwipvt, TRUE, TRUE); 04729 peer->mwipvt = dialog_unref(peer->mwipvt, "unreffing peer->mwipvt"); 04730 } 04731 04732 if (peer->chanvars) { 04733 ast_variables_destroy(peer->chanvars); 04734 peer->chanvars = NULL; 04735 } 04736 04737 register_peer_exten(peer, FALSE); 04738 ast_free_ha(peer->ha); 04739 if (peer->selfdestruct) 04740 ast_atomic_fetchadd_int(&apeerobjs, -1); 04741 else if (peer->is_realtime) { 04742 ast_atomic_fetchadd_int(&rpeerobjs, -1); 04743 ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs); 04744 } else 04745 ast_atomic_fetchadd_int(&speerobjs, -1); 04746 clear_realm_authentication(peer->auth); 04747 peer->auth = NULL; 04748 if (peer->dnsmgr) 04749 ast_dnsmgr_release(peer->dnsmgr); 04750 clear_peer_mailboxes(peer); 04751 04752 if (peer->socket.tcptls_session) { 04753 ao2_ref(peer->socket.tcptls_session, -1); 04754 peer->socket.tcptls_session = NULL; 04755 } 04756 04757 ast_string_field_free_memory(peer); 04758 }
| static void sip_destroy_peer_fn | ( | void * | peer | ) | [static] |
Definition at line 4707 of file chan_sip.c.
References sip_destroy_peer().
Referenced by build_peer(), and temp_peer().
04708 { 04709 sip_destroy_peer(peer); 04710 }
| static int sip_devicestate | ( | void * | data | ) | [static] |
Part of PBX channel interface.
For peers with call limit:
For peers without call limit:
Peers that does not have a known call and can't be reached by OPTIONS
If we return AST_DEVICE_UNKNOWN, the device state engine will try to find out a state by walking the channel list.
The queue system (app_queue.c) treats a member as "active" if devicestate is != AST_DEVICE_UNAVAILBALE && != AST_DEVICE_INVALID
When placing a call to the queue member, queue system sets a member to busy if != AST_DEVICE_NOT_INUSE and != AST_DEVICE_UNKNOWN
Definition at line 23240 of file chan_sip.c.
References sip_peer::addr, ast_debug, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, AST_DEVICE_UNKNOWN, ast_strdupa, sip_peer::busy_level, sip_peer::call_limit, sip_peer::defaddr, FALSE, find_peer(), FINDALLDEVICES, sip_peer::inRinging, sip_peer::inUse, sip_peer::lastms, sip_peer::maxms, sip_peer::onHold, TRUE, and unref_peer().
23241 { 23242 char *host; 23243 char *tmp; 23244 struct sip_peer *p; 23245 23246 int res = AST_DEVICE_INVALID; 23247 23248 /* make sure data is not null. Maybe unnecessary, but better be safe */ 23249 host = ast_strdupa(data ? data : ""); 23250 if ((tmp = strchr(host, '@'))) 23251 host = tmp + 1; 23252 23253 ast_debug(3, "Checking device state for peer %s\n", host); 23254 23255 /* If find_peer asks for a realtime peer, then this breaks rtautoclear. This 23256 * is because when a peer tries to autoexpire, the last thing it does is to 23257 * queue up an event telling the system that the devicestate has changed 23258 * (presumably to unavailable). If we ask for a realtime peer here, this would 23259 * load it BACK into memory, thus defeating the point of trying to clear dead 23260 * hosts out of memory. 23261 */ 23262 if ((p = find_peer(host, NULL, FALSE, FINDALLDEVICES, TRUE, 0))) { 23263 if (p->addr.sin_addr.s_addr || p->defaddr.sin_addr.s_addr) { 23264 /* we have an address for the peer */ 23265 23266 /* Check status in this order 23267 - Hold 23268 - Ringing 23269 - Busy (enforced only by call limit) 23270 - Inuse (we have a call) 23271 - Unreachable (qualify) 23272 If we don't find any of these state, report AST_DEVICE_NOT_INUSE 23273 for registered devices */ 23274 23275 if (p->onHold) 23276 /* First check for hold or ring states */ 23277 res = AST_DEVICE_ONHOLD; 23278 else if (p->inRinging) { 23279 if (p->inRinging == p->inUse) 23280 res = AST_DEVICE_RINGING; 23281 else 23282 res = AST_DEVICE_RINGINUSE; 23283 } else if (p->call_limit && (p->inUse == p->call_limit)) 23284 /* check call limit */ 23285 res = AST_DEVICE_BUSY; 23286 else if (p->call_limit && p->busy_level && p->inUse >= p->busy_level) 23287 /* We're forcing busy before we've reached the call limit */ 23288 res = AST_DEVICE_BUSY; 23289 else if (p->call_limit && p->inUse) 23290 /* Not busy, but we do have a call */ 23291 res = AST_DEVICE_INUSE; 23292 else if (p->maxms && ((p->lastms > p->maxms) || (p->lastms < 0))) 23293 /* We don't have a call. Are we reachable at all? Requires qualify= */ 23294 res = AST_DEVICE_UNAVAILABLE; 23295 else /* Default reply if we're registered and have no other data */ 23296 res = AST_DEVICE_NOT_INUSE; 23297 } else { 23298 /* there is no address, it's unavailable */ 23299 res = AST_DEVICE_UNAVAILABLE; 23300 } 23301 unref_peer(p, "unref_peer, from sip_devicestate, release ref from find_peer"); 23302 } else { 23303 res = AST_DEVICE_UNKNOWN; 23304 } 23305 23306 return res; 23307 }
| static char * sip_do_debug | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Turn on SIP debugging (CLI command).
Definition at line 17058 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_peer(), debugaddr, ast_cli_args::fd, ast_cli_args::n, ast_cli_args::pos, sip_debug_console, sip_do_debug_ip(), sip_do_debug_peer(), ast_cli_entry::usage, and ast_cli_args::word.
17059 { 17060 int oldsipdebug = sipdebug & sip_debug_console; 17061 char *what; 17062 17063 if (cmd == CLI_INIT) { 17064 e->command = "sip set debug {on|off|ip|peer}"; 17065 e->usage = 17066 "Usage: sip set debug {off|on|ip addr[:port]|peer peername}\n" 17067 " Globally disables dumping of SIP packets,\n" 17068 " or enables it either globally or for a (single)\n" 17069 " IP address or registered peer.\n"; 17070 return NULL; 17071 } else if (cmd == CLI_GENERATE) { 17072 if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) 17073 return complete_sip_peer(a->word, a->n, 0); 17074 return NULL; 17075 } 17076 17077 what = a->argv[e->args-1]; /* guaranteed to exist */ 17078 if (a->argc == e->args) { /* on/off */ 17079 if (!strcasecmp(what, "on")) { 17080 sipdebug |= sip_debug_console; 17081 sipdebug_text = 1; /*! \note this can be a special debug command - "sip debug text" or something */ 17082 memset(&debugaddr, 0, sizeof(debugaddr)); 17083 ast_cli(a->fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : ""); 17084 return CLI_SUCCESS; 17085 } else if (!strcasecmp(what, "off")) { 17086 sipdebug &= ~sip_debug_console; 17087 sipdebug_text = 0; 17088 ast_cli(a->fd, "SIP Debugging Disabled\n"); 17089 return CLI_SUCCESS; 17090 } 17091 } else if (a->argc == e->args +1) {/* ip/peer */ 17092 if (!strcasecmp(what, "ip")) 17093 return sip_do_debug_ip(a->fd, a->argv[e->args]); 17094 else if (!strcasecmp(what, "peer")) 17095 return sip_do_debug_peer(a->fd, a->argv[e->args]); 17096 } 17097 return CLI_SHOWUSAGE; /* default, failure */ 17098 }
| static char * sip_do_debug_ip | ( | int | fd, | |
| char * | arg | |||
| ) | [static] |
Enable SIP Debugging for a single IP.
Definition at line 17008 of file chan_sip.c.
References ast_cli(), ast_gethostbyname(), ast_inet_ntoa(), CLI_SHOWUSAGE, CLI_SUCCESS, debugaddr, hp, sip_debug_console, and strsep().
Referenced by sip_do_debug().
17009 { 17010 struct hostent *hp; 17011 struct ast_hostent ahp; 17012 int port = 0; 17013 char *p; 17014 17015 p = arg; 17016 strsep(&p, ":"); 17017 if (p) 17018 port = atoi(p); 17019 hp = ast_gethostbyname(arg, &ahp); 17020 if (hp == NULL) 17021 return CLI_SHOWUSAGE; 17022 17023 debugaddr.sin_family = AF_INET; 17024 memcpy(&debugaddr.sin_addr, hp->h_addr, sizeof(debugaddr.sin_addr)); 17025 debugaddr.sin_port = htons(port); 17026 if (port == 0) 17027 ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_inet_ntoa(debugaddr.sin_addr)); 17028 else 17029 ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", ast_inet_ntoa(debugaddr.sin_addr), port); 17030 17031 sipdebug |= sip_debug_console; 17032 17033 return CLI_SUCCESS; 17034 }
| static char * sip_do_debug_peer | ( | int | fd, | |
| char * | arg | |||
| ) | [static] |
Turn on SIP debugging for a given peer.
Definition at line 17037 of file chan_sip.c.
References sip_peer::addr, ast_cli(), ast_inet_ntoa(), CLI_SUCCESS, debugaddr, FALSE, find_peer(), FINDPEERS, sip_debug_console, TRUE, and unref_peer().
Referenced by sip_do_debug().
17038 { 17039 struct sip_peer *peer = find_peer(arg, NULL, TRUE, FINDPEERS, FALSE, 0); 17040 if (!peer) 17041 ast_cli(fd, "No such peer '%s'\n", arg); 17042 else if (peer->addr.sin_addr.s_addr == 0) 17043 ast_cli(fd, "Unable to get IP address of peer '%s'\n", arg); 17044 else { 17045 debugaddr.sin_family = AF_INET; 17046 debugaddr.sin_addr = peer->addr.sin_addr; 17047 debugaddr.sin_port = peer->addr.sin_port; 17048 ast_cli(fd, "SIP Debugging Enabled for IP: %s:%d\n", 17049 ast_inet_ntoa(debugaddr.sin_addr), ntohs(debugaddr.sin_port)); 17050 sipdebug |= sip_debug_console; 17051 } 17052 if (peer) 17053 unref_peer(peer, "sip_do_debug_peer: unref_peer, from find_peer call"); 17054 return CLI_SUCCESS; 17055 }
| static int sip_do_reload | ( | enum channelreloadreason | reason | ) | [static] |
Reload module.
Definition at line 25934 of file chan_sip.c.
References ast_debug, ast_sched_dump(), reload_config(), sip_poke_all_peers(), sip_send_all_mwi_subscriptions(), sip_send_all_registers(), and unlink_marked_peers_from_tables().
Referenced by do_monitor().
25935 { 25936 time_t start_poke, end_poke; 25937 25938 reload_config(reason); 25939 ast_sched_dump(sched); 25940 25941 start_poke = time(0); 25942 /* Prune peers who still are supposed to be deleted */ 25943 unlink_marked_peers_from_tables(); 25944 25945 ast_debug(4, "--------------- Done destroying pruned peers\n"); 25946 25947 /* Send qualify (OPTIONS) to all peers */ 25948 sip_poke_all_peers(); 25949 25950 /* Register with all services */ 25951 sip_send_all_registers(); 25952 25953 sip_send_all_mwi_subscriptions(); 25954 25955 end_poke = time(0); 25956 25957 ast_debug(4, "do_reload finished. peer poke/prune reg contact time = %d sec.\n", (int)(end_poke-start_poke)); 25958 25959 ast_debug(4, "--------------- SIP reload done\n"); 25960 25961 return 0; 25962 }
| static int sip_dtmfmode | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Set the DTMFmode for an outbound SIP call (application).
Definition at line 25673 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_dsp_free(), ast_dsp_new(), ast_dsp_set_features(), ast_log(), AST_RTP_DTMF, ast_rtp_setdtmf(), ast_set_flag, ast_test_flag, sip_pvt::dsp, DSP_FEATURE_DIGIT_DETECT, sip_pvt::flags, IS_SIP_TECH, sip_pvt::jointnoncodeccapability, LOG_WARNING, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, SIP_DTMF_SHORTINFO, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
Referenced by load_module().
25674 { 25675 struct sip_pvt *p; 25676 char *mode = data; 25677 25678 if (!data) { 25679 ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n"); 25680 return 0; 25681 } 25682 ast_channel_lock(chan); 25683 if (!IS_SIP_TECH(chan->tech)) { 25684 ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n"); 25685 ast_channel_unlock(chan); 25686 return 0; 25687 } 25688 p = chan->tech_pvt; 25689 if (!p) { 25690 ast_channel_unlock(chan); 25691 return 0; 25692 } 25693 sip_pvt_lock(p); 25694 if (!strcasecmp(mode, "info")) { 25695 ast_clear_flag(&p->flags[0], SIP_DTMF); 25696 ast_set_flag(&p->flags[0], SIP_DTMF_INFO); 25697 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 25698 } else if (!strcasecmp(mode, "shortinfo")) { 25699 ast_clear_flag(&p->flags[0], SIP_DTMF); 25700 ast_set_flag(&p->flags[0], SIP_DTMF_SHORTINFO); 25701 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 25702 } else if (!strcasecmp(mode, "rfc2833")) { 25703 ast_clear_flag(&p->flags[0], SIP_DTMF); 25704 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 25705 p->jointnoncodeccapability |= AST_RTP_DTMF; 25706 } else if (!strcasecmp(mode, "inband")) { 25707 ast_clear_flag(&p->flags[0], SIP_DTMF); 25708 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 25709 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 25710 } else 25711 ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n", mode); 25712 if (p->rtp) 25713 ast_rtp_setdtmf(p->rtp, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 25714 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) { 25715 if (!p->dsp) { 25716 p->dsp = ast_dsp_new(); 25717 ast_dsp_set_features(p->dsp, DSP_FEATURE_DIGIT_DETECT); 25718 } 25719 } else { 25720 if (p->dsp) { 25721 ast_dsp_free(p->dsp); 25722 p->dsp = NULL; 25723 } 25724 } 25725 sip_pvt_unlock(p); 25726 ast_channel_unlock(chan); 25727 return 0; 25728 }
| static void sip_dump_history | ( | struct sip_pvt * | dialog | ) | [static] |
Dump SIP history to debug log file at end of lifespan for SIP dialog.
Definition at line 16793 of file chan_sip.c.
References ast_debug, AST_LIST_TRAVERSE, ast_log(), sip_pvt::callid, sip_history::event, sip_pvt::history, LOG_NOTICE, option_debug, and sip_pvt::subscribed.
Referenced by __sip_destroy().
16794 { 16795 int x = 0; 16796 struct sip_history *hist; 16797 static int errmsg = 0; 16798 16799 if (!dialog) 16800 return; 16801 16802 if (!option_debug && !sipdebug) { 16803 if (!errmsg) { 16804 ast_log(LOG_NOTICE, "You must have debugging enabled (SIP or Asterisk) in order to dump SIP history.\n"); 16805 errmsg = 1; 16806 } 16807 return; 16808 } 16809 16810 ast_debug(1, "\n---------- SIP HISTORY for '%s' \n", dialog->callid); 16811 if (dialog->subscribed) 16812 ast_debug(1, " * Subscription\n"); 16813 else 16814 ast_debug(1, " * SIP Call\n"); 16815 if (dialog->history) 16816 AST_LIST_TRAVERSE(dialog->history, hist, list) 16817 ast_debug(1, " %-3.3d. %s\n", ++x, hist->event); 16818 if (!x) 16819 ast_debug(1, "Call '%s' has no history\n", dialog->callid); 16820 ast_debug(1, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid); 16821 }
| static int sip_fixup | ( | struct ast_channel * | oldchan, | |
| struct ast_channel * | newchan | |||
| ) | [static] |
sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links
Definition at line 6391 of file chan_sip.c.
References append_history, ast_debug, AST_FLAG_ZOMBIE, ast_log(), ast_test_flag, sip_pvt::callid, LOG_WARNING, ast_channel::name, sip_pvt::owner, sip_pvt_lock, sip_pvt_unlock, sip_set_rtp_peer(), and ast_channel::tech_pvt.
06392 { 06393 int ret = -1; 06394 struct sip_pvt *p; 06395 06396 if (newchan && ast_test_flag(newchan, AST_FLAG_ZOMBIE)) 06397 ast_debug(1, "New channel is zombie\n"); 06398 if (oldchan && ast_test_flag(oldchan, AST_FLAG_ZOMBIE)) 06399 ast_debug(1, "Old channel is zombie\n"); 06400 06401 if (!newchan || !newchan->tech_pvt) { 06402 if (!newchan) 06403 ast_log(LOG_WARNING, "No new channel! Fixup of %s failed.\n", oldchan->name); 06404 else 06405 ast_log(LOG_WARNING, "No SIP tech_pvt! Fixup of %s failed.\n", oldchan->name); 06406 return -1; 06407 } 06408 p = newchan->tech_pvt; 06409 06410 sip_pvt_lock(p); 06411 append_history(p, "Masq", "Old channel: %s\n", oldchan->name); 06412 append_history(p, "Masq (cont)", "...new owner: %s\n", newchan->name); 06413 if (p->owner != oldchan) 06414 ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner); 06415 else { 06416 p->owner = newchan; 06417 /* Re-invite RTP back to Asterisk. Needed if channel is masqueraded out of a native 06418 RTP bridge (i.e., RTP not going through Asterisk): RTP bridge code might not be 06419 able to do this if the masquerade happens before the bridge breaks (e.g., AMI 06420 redirect of both channels). Note that a channel can not be masqueraded *into* 06421 a native bridge. So there is no danger that this breaks a native bridge that 06422 should stay up. */ 06423 sip_set_rtp_peer(newchan, NULL, NULL, 0, 0, 0); 06424 ret = 0; 06425 } 06426 ast_debug(3, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, p->owner->name, oldchan->name); 06427 06428 sip_pvt_unlock(p); 06429 return ret; 06430 }
| static const char * sip_get_callid | ( | struct ast_channel * | chan | ) | [static] |
Deliver SIP call ID for the call.
Definition at line 4568 of file chan_sip.c.
References ast_channel::tech_pvt.
| static int sip_get_codec | ( | struct ast_channel * | chan | ) | [static] |
Return SIP UA's codec (part of the RTP interface).
Definition at line 25862 of file chan_sip.c.
References sip_pvt::capability, sip_pvt::jointcapability, and ast_channel::tech_pvt.
25863 { 25864 struct sip_pvt *p = chan->tech_pvt; 25865 return p->jointcapability ? p->jointcapability : p->capability; 25866 }
| static enum ast_rtp_get_result sip_get_rtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp ** | rtp | |||
| ) | [static] |
Returns null if we can't reinvite audio (part of RTP interface).
Definition at line 25519 of file chan_sip.c.
References AST_JB_FORCED, AST_RTP_GET_FAILED, ast_rtp_getnat(), AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_test_flag, sip_pvt::flags, global_jbconf, sip_pvt::rtp, SIP_DIRECT_MEDIA, SIP_DIRECT_MEDIA_NAT, sip_pvt_lock, sip_pvt_unlock, and ast_channel::tech_pvt.
25520 { 25521 struct sip_pvt *p = NULL; 25522 enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL; 25523 25524 if (!(p = chan->tech_pvt)) 25525 return AST_RTP_GET_FAILED; 25526 25527 sip_pvt_lock(p); 25528 if (!(p->rtp)) { 25529 sip_pvt_unlock(p); 25530 return AST_RTP_GET_FAILED; 25531 } 25532 25533 *rtp = p->rtp; 25534 25535 if (ast_rtp_getnat(*rtp) && !ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA_NAT)) 25536 res = AST_RTP_TRY_PARTIAL; 25537 else if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) 25538 res = AST_RTP_TRY_NATIVE; 25539 else if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) 25540 res = AST_RTP_GET_FAILED; 25541 25542 sip_pvt_unlock(p); 25543 25544 return res; 25545 }
| static enum ast_rtp_get_result sip_get_trtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp ** | rtp | |||
| ) | [static] |
Returns null if we can't reinvite text (part of RTP interface).
Definition at line 25573 of file chan_sip.c.
References AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_test_flag, sip_pvt::flags, SIP_DIRECT_MEDIA, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and sip_pvt::trtp.
25574 { 25575 struct sip_pvt *p = NULL; 25576 enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL; 25577 25578 if (!(p = chan->tech_pvt)) 25579 return AST_RTP_GET_FAILED; 25580 25581 sip_pvt_lock(p); 25582 if (!(p->trtp)) { 25583 sip_pvt_unlock(p); 25584 return AST_RTP_GET_FAILED; 25585 } 25586 25587 *rtp = p->trtp; 25588 25589 if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) 25590 res = AST_RTP_TRY_NATIVE; 25591 25592 sip_pvt_unlock(p); 25593 25594 return res; 25595 }
| static struct ast_udptl * sip_get_udptl_peer | ( | struct ast_channel * | chan | ) | [static, read] |
Definition at line 25475 of file chan_sip.c.
References ast_test_flag, sip_pvt::flags, SIP_DIRECT_MEDIA, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and sip_pvt::udptl.
25476 { 25477 struct sip_pvt *p; 25478 struct ast_udptl *udptl = NULL; 25479 25480 p = chan->tech_pvt; 25481 if (!p) 25482 return NULL; 25483 25484 sip_pvt_lock(p); 25485 if (p->udptl && ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) 25486 udptl = p->udptl; 25487 sip_pvt_unlock(p); 25488 return udptl; 25489 }
| static enum ast_rtp_get_result sip_get_vrtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp ** | rtp | |||
| ) | [static] |
Returns null if we can't reinvite video (part of RTP interface).
Definition at line 25548 of file chan_sip.c.
References AST_RTP_GET_FAILED, AST_RTP_TRY_NATIVE, AST_RTP_TRY_PARTIAL, ast_test_flag, sip_pvt::flags, SIP_DIRECT_MEDIA, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and sip_pvt::vrtp.
25549 { 25550 struct sip_pvt *p = NULL; 25551 enum ast_rtp_get_result res = AST_RTP_TRY_PARTIAL; 25552 25553 if (!(p = chan->tech_pvt)) 25554 return AST_RTP_GET_FAILED; 25555 25556 sip_pvt_lock(p); 25557 if (!(p->vrtp)) { 25558 sip_pvt_unlock(p); 25559 return AST_RTP_GET_FAILED; 25560 } 25561 25562 *rtp = p->vrtp; 25563 25564 if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) 25565 res = AST_RTP_TRY_NATIVE; 25566 25567 sip_pvt_unlock(p); 25568 25569 return res; 25570 }
| static int sip_hangup | ( | struct ast_channel * | ast | ) | [static] |
sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup
Definition at line 6030 of file chan_sip.c.
References __sip_semi_ack(), ast_channel::_state, sip_pvt::alreadygone, sip_pvt::answered_elsewhere, append_history, ast_bridged_channel(), ast_cause2str(), AST_CAUSE_ANSWERED_ELSEWHERE, ast_channel_trylock, ast_channel_unlock, ast_clear_flag, ast_debug, ast_dsp_free(), AST_FLAG_ANSWERED_ELSEWHERE, AST_FLAG_ZOMBIE, ast_log(), ast_module_unref(), ast_rtp_get_quality(), ast_rtp_set_vars(), AST_SCHED_DEL_UNREF, ast_set_flag, ast_state2str(), AST_STATE_UP, ast_strlen_zero(), ast_test_flag, sip_pvt::autokillid, ast_channel::bridge, sip_pvt::callid, CHANNEL_DEADLOCK_AVOIDANCE, sip_pkt::data, sip_request::data, DEC_CALL_LIMIT, DEFAULT_TRANS_TIMEOUT, dialog_unref(), sip_pvt::do_history, sip_pvt::dsp, FALSE, find_sip_method(), sip_pvt::flags, hangup_cause2sip(), sip_pvt::hangupcause, ast_channel::hangupcause, sip_pvt::initreq, INV_CALLING, INV_CANCELLED, INV_COMPLETED, INV_TERMINATED, sip_pvt::invitestate, sip_pkt::is_resp, IS_SIP_TECH, sip_pvt::lastinvite, LOG_WARNING, sip_pkt::method, ast_channel::name, sip_pvt::needdestroy, sip_pkt::next, sip_pvt::owner, sip_pvt::packets, pbx_builtin_setvar_helper(), sip_pvt::pendinginvite, sip_pvt::provisional_keepalive_sched_id, pvt_set_needdestroy(), sip_pvt::refer, sip_pvt::rtp, RTPQOS_SUMMARY, sip_pkt::seqno, SIP_BYE, SIP_CANCEL, sip_cancel_destroy(), SIP_DEFER_BYE_ON_TRANSFER, SIP_INC_COUNT, SIP_NEEDREINVITE, SIP_OUTGOING, SIP_PAGE2_CALL_ONHOLD, SIP_PENDINGBYE, sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, sip_scheddestroy(), sip_st_dlg::st_active, sip_pvt::stimer, stop_media_flows(), stop_session_timer(), ast_channel::tech, ast_channel::tech_pvt, transmit_request(), transmit_request_with_auth(), transmit_response_reliable(), sip_pvt::trtp, TRUE, update_call_counter(), sip_pvt::username, sip_pvt::vrtp, sip_pvt::waitid, and XMIT_RELIABLE.
06031 { 06032 struct sip_pvt *p = ast->tech_pvt; 06033 int needcancel = FALSE; 06034 int needdestroy = 0; 06035 struct ast_channel *oldowner = ast; 06036 06037 if (!p) { 06038 ast_debug(1, "Asked to hangup channel that was not connected\n"); 06039 return 0; 06040 } 06041 if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE) || ast->hangupcause == AST_CAUSE_ANSWERED_ELSEWHERE) { 06042 ast_debug(1, "This call was answered elsewhere"); 06043 if (ast->hangupcause == AST_CAUSE_ANSWERED_ELSEWHERE) { 06044 ast_debug(1, "####### It's the cause code, buddy. The cause code!!!\n"); 06045 } 06046 append_history(p, "Cancel", "Call answered elsewhere"); 06047 p->answered_elsewhere = TRUE; 06048 } 06049 06050 /* Store hangupcause locally in PVT so we still have it before disconnect */ 06051 if (p->owner) 06052 p->hangupcause = p->owner->hangupcause; 06053 06054 if (ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 06055 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 06056 if (sipdebug) 06057 ast_debug(1, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 06058 update_call_counter(p, DEC_CALL_LIMIT); 06059 } 06060 ast_debug(4, "SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->callid); 06061 if (p->autokillid > -1 && sip_cancel_destroy(p)) 06062 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 06063 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06064 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Really hang up next time */ 06065 p->needdestroy = 0; 06066 p->owner->tech_pvt = dialog_unref(p->owner->tech_pvt, "unref p->owner->tech_pvt"); 06067 sip_pvt_lock(p); 06068 p->owner = NULL; /* Owner will be gone after we return, so take it away */ 06069 sip_pvt_unlock(p); 06070 ast_module_unref(ast_module_info->self); 06071 return 0; 06072 } 06073 06074 if (ast_test_flag(ast, AST_FLAG_ZOMBIE)) { 06075 if (p->refer) 06076 ast_debug(1, "SIP Transfer: Hanging up Zombie channel %s after transfer ... Call-ID: %s\n", ast->name, p->callid); 06077 else 06078 ast_debug(1, "Hanging up zombie call. Be scared.\n"); 06079 } else 06080 ast_debug(1, "Hangup call %s, SIP callid %s\n", ast->name, p->callid); 06081 06082 sip_pvt_lock(p); 06083 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 06084 if (sipdebug) 06085 ast_debug(1, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 06086 update_call_counter(p, DEC_CALL_LIMIT); 06087 } 06088 06089 /* Determine how to disconnect */ 06090 if (p->owner != ast) { 06091 ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n"); 06092 sip_pvt_unlock(p); 06093 return 0; 06094 } 06095 /* If the call is not UP, we need to send CANCEL instead of BYE */ 06096 /* In case of re-invites, the call might be UP even though we have an incomplete invite transaction */ 06097 if (p->invitestate < INV_COMPLETED && p->owner->_state != AST_STATE_UP) { 06098 needcancel = TRUE; 06099 ast_debug(4, "Hanging up channel in state %s (not UP)\n", ast_state2str(ast->_state)); 06100 } 06101 06102 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 06103 06104 append_history(p, needcancel ? "Cancel" : "Hangup", "Cause %s", p->owner ? ast_cause2str(p->hangupcause) : "Unknown"); 06105 06106 /* Disconnect */ 06107 if (p->dsp) 06108 ast_dsp_free(p->dsp); 06109 06110 p->owner = NULL; 06111 ast->tech_pvt = dialog_unref(ast->tech_pvt, "unref ast->tech_pvt"); 06112 06113 ast_module_unref(ast_module_info->self); 06114 /* Do not destroy this pvt until we have timeout or 06115 get an answer to the BYE or INVITE/CANCEL 06116 If we get no answer during retransmit period, drop the call anyway. 06117 (Sorry, mother-in-law, you can't deny a hangup by sending 06118 603 declined to BYE...) 06119 */ 06120 if (p->alreadygone) 06121 needdestroy = 1; /* Set destroy flag at end of this function */ 06122 else if (p->invitestate != INV_CALLING) 06123 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06124 06125 /* Start the process if it's not already started */ 06126 if (!p->alreadygone && p->initreq.data && !ast_strlen_zero(p->initreq.data->str)) { 06127 if (needcancel) { /* Outgoing call, not up */ 06128 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06129 /* stop retransmitting an INVITE that has not received a response */ 06130 /* if we can't send right now, mark it pending */ 06131 if (p->invitestate == INV_CALLING) { 06132 /* We can't send anything in CALLING state */ 06133 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 06134 /* Do we need a timer here if we don't hear from them at all? Yes we do or else we will get hung dialogs and those are no fun. */ 06135 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06136 append_history(p, "DELAY", "Not sending cancel, waiting for timeout"); 06137 } else { 06138 struct sip_pkt *cur; 06139 06140 for (cur = p->packets; cur; cur = cur->next) { 06141 __sip_semi_ack(p, cur->seqno, cur->is_resp, cur->method ? cur->method : find_sip_method(cur->data->str)); 06142 } 06143 p->invitestate = INV_CANCELLED; 06144 /* Send a new request: CANCEL */ 06145 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 06146 /* Actually don't destroy us yet, wait for the 487 on our original 06147 INVITE, but do set an autodestruct just in case we never get it. */ 06148 needdestroy = 0; 06149 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06150 } 06151 } else { /* Incoming call, not up */ 06152 const char *res; 06153 AST_SCHED_DEL_UNREF(sched, p->provisional_keepalive_sched_id, dialog_unref(p, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 06154 if (p->hangupcause && (res = hangup_cause2sip(p->hangupcause))) 06155 transmit_response_reliable(p, res, &p->initreq); 06156 else 06157 transmit_response_reliable(p, "603 Declined", &p->initreq); 06158 p->invitestate = INV_TERMINATED; 06159 } 06160 } else { /* Call is in UP state, send BYE */ 06161 if (p->stimer->st_active == TRUE) { 06162 stop_session_timer(p); 06163 } 06164 06165 if (!p->pendinginvite) { 06166 struct ast_channel *bridge = ast_bridged_channel(oldowner); 06167 char *audioqos = ""; 06168 char *videoqos = ""; 06169 char *textqos = ""; 06170 06171 /* We need to get the lock on bridge because ast_rtp_set_vars will attempt 06172 * to lock the bridge. This may get hairy... 06173 */ 06174 while (bridge && ast_channel_trylock(bridge)) { 06175 sip_pvt_unlock(p); 06176 do { 06177 /* Use oldowner since p->owner is already NULL */ 06178 CHANNEL_DEADLOCK_AVOIDANCE(oldowner); 06179 } while (sip_pvt_trylock(p)); 06180 bridge = ast_bridged_channel(oldowner); 06181 } 06182 06183 if (p->rtp) 06184 ast_rtp_set_vars(oldowner, p->rtp); 06185 06186 if (bridge) { 06187 struct sip_pvt *q = bridge->tech_pvt; 06188 06189 if (IS_SIP_TECH(bridge->tech) && q && q->rtp) 06190 ast_rtp_set_vars(bridge, q->rtp); 06191 ast_channel_unlock(bridge); 06192 } 06193 06194 if (p->vrtp) 06195 videoqos = ast_rtp_get_quality(p->vrtp, NULL, RTPQOS_SUMMARY); 06196 if (p->trtp) 06197 textqos = ast_rtp_get_quality(p->trtp, NULL, RTPQOS_SUMMARY); 06198 /* Send a hangup */ 06199 if (oldowner->_state == AST_STATE_UP) { 06200 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 06201 } 06202 06203 /* Get RTCP quality before end of call */ 06204 if (p->do_history) { 06205 if (p->rtp) 06206 append_history(p, "RTCPaudio", "Quality:%s", audioqos); 06207 if (p->vrtp) 06208 append_history(p, "RTCPvideo", "Quality:%s", videoqos); 06209 if (p->trtp) 06210 append_history(p, "RTCPtext", "Quality:%s", textqos); 06211 } 06212 if (p->rtp && oldowner) 06213 pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", audioqos); 06214 if (p->vrtp && oldowner) 06215 pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", videoqos); 06216 if (p->trtp && oldowner) 06217 pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", textqos); 06218 } else { 06219 /* Note we will need a BYE when this all settles out 06220 but we can't send one while we have "INVITE" outstanding. */ 06221 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 06222 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 06223 AST_SCHED_DEL_UNREF(sched, p->waitid, dialog_unref(p, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr")); 06224 if (sip_cancel_destroy(p)) 06225 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 06226 } 06227 } 06228 } 06229 if (needdestroy) { 06230 pvt_set_needdestroy(p, "hangup"); 06231 } 06232 sip_pvt_unlock(p); 06233 return 0; 06234 }
| static int sip_indicate | ( | struct ast_channel * | ast, | |
| int | condition, | |||
| const void * | data, | |||
| size_t | datalen | |||
| ) | [static] |
Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc.
Definition at line 6586 of file chan_sip.c.
References ast_channel::_state, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_HOLD, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_VIDUPDATE, ast_log(), ast_moh_start(), ast_moh_stop(), ast_rtp_change_source(), ast_rtp_new_source(), ast_set_flag, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_RING, AST_STATE_UP, ast_test_flag, sip_pvt::flags, sip_pvt::initreq, interpret_t38_parameters(), INV_COMPLETED, INV_EARLY_MEDIA, INV_PROCEEDING, sip_pvt::invitestate, LOG_ERROR, LOG_WARNING, sip_pvt::mohinterpret, sip_pvt::novideo, sip_pvt::rtp, sip_alreadygone(), SIP_OUTGOING, SIP_PROG_INBAND, SIP_PROG_INBAND_NEVER, SIP_PROG_INBAND_YES, SIP_PROGRESS_SENT, sip_pvt_lock, sip_pvt_unlock, SIP_RINGING, ast_channel::tech_pvt, transmit_info_with_vidupdate(), transmit_provisional_response(), transmit_response(), transmit_response_reliable(), TRUE, and sip_pvt::vrtp.
06587 { 06588 struct sip_pvt *p = ast->tech_pvt; 06589 int res = 0; 06590 06591 sip_pvt_lock(p); 06592 switch(condition) { 06593 case AST_CONTROL_RINGING: 06594 if (ast->_state == AST_STATE_RING) { 06595 p->invitestate = INV_EARLY_MEDIA; 06596 if (!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) || 06597 (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER)) { 06598 /* Send 180 ringing if out-of-band seems reasonable */ 06599 transmit_provisional_response(p, "180 Ringing", &p->initreq, 0); 06600 ast_set_flag(&p->flags[0], SIP_RINGING); 06601 if (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_YES) 06602 break; 06603 } else { 06604 /* Well, if it's not reasonable, just send in-band */ 06605 } 06606 } 06607 res = -1; 06608 break; 06609 case AST_CONTROL_BUSY: 06610 if (ast->_state != AST_STATE_UP) { 06611 transmit_response_reliable(p, "486 Busy Here", &p->initreq); 06612 p->invitestate = INV_COMPLETED; 06613 sip_alreadygone(p); 06614 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06615 break; 06616 } 06617 res = -1; 06618 break; 06619 case AST_CONTROL_CONGESTION: 06620 if (ast->_state != AST_STATE_UP) { 06621 transmit_response_reliable(p, "503 Service Unavailable", &p->initreq); 06622 p->invitestate = INV_COMPLETED; 06623 sip_alreadygone(p); 06624 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06625 break; 06626 } 06627 res = -1; 06628 break; 06629 case AST_CONTROL_PROCEEDING: 06630 if ((ast->_state != AST_STATE_UP) && 06631 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06632 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06633 transmit_response(p, "100 Trying", &p->initreq); 06634 p->invitestate = INV_PROCEEDING; 06635 break; 06636 } 06637 res = -1; 06638 break; 06639 case AST_CONTROL_PROGRESS: 06640 if ((ast->_state != AST_STATE_UP) && 06641 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06642 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06643 p->invitestate = INV_EARLY_MEDIA; 06644 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06645 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06646 break; 06647 } 06648 res = -1; 06649 break; 06650 case AST_CONTROL_HOLD: 06651 ast_rtp_new_source(p->rtp); 06652 ast_moh_start(ast, data, p->mohinterpret); 06653 break; 06654 case AST_CONTROL_UNHOLD: 06655 ast_rtp_new_source(p->rtp); 06656 ast_moh_stop(ast); 06657 break; 06658 case AST_CONTROL_VIDUPDATE: /* Request a video frame update */ 06659 if (p->vrtp && !p->novideo) { 06660 transmit_info_with_vidupdate(p); 06661 /* ast_rtcp_send_h261fur(p->vrtp); */ 06662 } else 06663 res = -1; 06664 break; 06665 case AST_CONTROL_T38_PARAMETERS: 06666 if (datalen != sizeof(struct ast_control_t38_parameters)) { 06667 ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38_PARAMETERS. Expected %d, got %d\n", (int) sizeof(struct ast_control_t38_parameters), (int) datalen); 06668 res = -1; 06669 } else { 06670 const struct ast_control_t38_parameters *parameters = data; 06671 res = interpret_t38_parameters(p, parameters); 06672 } 06673 break; 06674 case AST_CONTROL_SRCUPDATE: 06675 ast_rtp_new_source(p->rtp); 06676 break; 06677 case AST_CONTROL_SRCCHANGE: 06678 ast_rtp_change_source(p->rtp); 06679 break; 06680 case -1: 06681 res = -1; 06682 break; 06683 default: 06684 ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition); 06685 res = -1; 06686 break; 06687 } 06688 sip_pvt_unlock(p); 06689 return res; 06690 }
| static const char * sip_nat_mode | ( | const struct sip_pvt * | p | ) | [static] |
Display SIP nat mode.
Definition at line 3481 of file chan_sip.c.
References ast_test_flag, sip_pvt::flags, SIP_NAT, and SIP_NAT_ROUTE.
Referenced by check_via(), retrans_pkt(), and send_response().
03482 { 03483 return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? "NAT" : "no NAT"; 03484 }
| static struct ast_channel* sip_new | ( | struct sip_pvt * | i, | |
| int | state, | |||
| const char * | title | |||
| ) | [static, read] |
Initiate a call in the SIP channel called from sip_request_call (calls from the pbx ) for outbound channels and from handle_request_invite for inbound channels.
Definition at line 6698 of file chan_sip.c.
References accountcode, sip_pvt::accountcode, ast_channel::adsicpe, ast_channel::amaflags, sip_pvt::amaflags, append_history, AST_ADSI_UNAVAILABLE, ast_atomic_fetchadd_int(), ast_best_codec(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc, ast_channel_set_fd(), ast_codec_choose(), ast_copy_string(), ast_debug, ast_dsp_new(), ast_dsp_set_digitmode(), ast_dsp_set_features(), ast_exists_extension(), AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_get_encoded_str(), ast_getformatname_multiple(), ast_hangup(), ast_jb_configure(), ast_log(), ast_module_ref(), ast_pbx_start(), ast_rtcp_fd(), ast_rtp_fd(), AST_STATE_DOWN, AST_STATE_RING, ast_strdup, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_fd(), ast_uri_decode(), buf, sip_settings::callevents, sip_pvt::callgroup, ast_channel::callgroup, sip_pvt::callid, sip_pvt::callingpres, sip_pvt::capability, sip_pvt::chanvars, ast_channel::cid, ast_callerid::cid_ani, ast_callerid::cid_dnid, sip_pvt::cid_name, sip_pvt::cid_num, ast_callerid::cid_pres, ast_callerid::cid_rdnis, ast_channel::context, sip_pvt::context, dialog_ref(), sip_pvt::do_history, sip_pvt::domain, sip_pvt::dsp, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_RELAXDTMF, DSP_FEATURE_DIGIT_DETECT, DSP_FEATURE_FAX_DETECT, EVENT_FLAG_SYSTEM, ast_channel::exten, sip_pvt::exten, sip_pvt::flags, sip_pvt::fromdomain, sip_pvt::fullcontact, global_jbconf, ast_channel::hangupcause, sip_pvt::jointcapability, language, sip_pvt::language, LOG_WARNING, manager_event, ast_channel::name, ast_variable::name, ast_channel::nativeformats, ast_variable::next, sip_pvt::owner, parkinglot, sip_pvt::parkinglot, pbx_builtin_setvar_helper(), sip_pvt::pickupgroup, ast_channel::pickupgroup, sip_pvt::prefcodec, sip_pvt::prefs, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, sip_pvt::rdnis, ast_channel::readformat, ast_channel::rings, sip_pvt::rtp, sip_cfg, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_SHORTINFO, SIP_PAGE2_FAX_DETECT, SIP_PAGE2_VIDEOSUPPORT, sip_pvt_lock, sip_pvt_unlock, sip_tech_info, SIPBUFSIZE, ast_channel::tech, ast_channel::tech_pvt, text, sip_pvt::trtp, sip_pvt::udptl, ast_channel::uniqueid, sip_pvt::uri, ast_variable::value, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by handle_request_invite(), and sip_request_call().
06699 { 06700 struct ast_channel *tmp; 06701 struct ast_variable *v = NULL; 06702 int fmt; 06703 int what; 06704 int video; 06705 int text; 06706 int needvideo = 0; 06707 int needtext = 0; 06708 char buf[SIPBUFSIZE]; 06709 char *decoded_exten; 06710 06711 { 06712 const char *my_name; /* pick a good name */ 06713 06714 if (title) { 06715 my_name = title; 06716 } else { 06717 char *port = NULL; 06718 my_name = ast_strdupa(i->fromdomain); 06719 if ((port = strchr(i->fromdomain, ':'))) { 06720 *port = '\0'; 06721 } 06722 } 06723 06724 sip_pvt_unlock(i); 06725 /* Don't hold a sip pvt lock while we allocate a channel */ 06726 tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, i->amaflags, "SIP/%s-%08x", my_name, ast_atomic_fetchadd_int((int *)&chan_idx, +1)); 06727 06728 } 06729 if (!tmp) { 06730 ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n"); 06731 sip_pvt_lock(i); 06732 return NULL; 06733 } 06734 sip_pvt_lock(i); 06735 06736 tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ? &sip_tech_info : &sip_tech; 06737 06738 /* Select our native format based on codec preference until we receive 06739 something from another device to the contrary. */ 06740 if (i->jointcapability) { /* The joint capabilities of us and peer */ 06741 what = i->jointcapability; 06742 video = i->jointcapability & AST_FORMAT_VIDEO_MASK; 06743 text = i->jointcapability & AST_FORMAT_TEXT_MASK; 06744 } else if (i->capability) { /* Our configured capability for this peer */ 06745 what = i->capability; 06746 video = i->capability & AST_FORMAT_VIDEO_MASK; 06747 text = i->capability & AST_FORMAT_TEXT_MASK; 06748 } else { 06749 what = global_capability; /* Global codec support */ 06750 video = global_capability & AST_FORMAT_VIDEO_MASK; 06751 text = global_capability & AST_FORMAT_TEXT_MASK; 06752 } 06753 06754 /* Set the native formats for audio and merge in video */ 06755 tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | video | text; 06756 ast_debug(3, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats)); 06757 ast_debug(3, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcapability)); 06758 ast_debug(3, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->capability)); 06759 ast_debug(3, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, ast_codec_choose(&i->prefs, what, 1))); 06760 if (i->prefcodec) 06761 ast_debug(3, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec)); 06762 06763 /* XXX Why are we choosing a codec from the native formats?? */ 06764 fmt = ast_best_codec(tmp->nativeformats); 06765 06766 /* If we have a prefcodec setting, we have an inbound channel that set a 06767 preferred format for this call. Otherwise, we check the jointcapability 06768 We also check for vrtp. If it's not there, we are not allowed do any video anyway. 06769 */ 06770 if (i->vrtp) { 06771 if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT)) 06772 needvideo = AST_FORMAT_VIDEO_MASK; 06773 else if (i->prefcodec) 06774 needvideo = i->prefcodec & AST_FORMAT_VIDEO_MASK; /* Outbound call */ 06775 else 06776 needvideo = i->jointcapability & AST_FORMAT_VIDEO_MASK; /* Inbound call */ 06777 } 06778 06779 if (i->trtp) { 06780 if (i->prefcodec) 06781 needtext = i->prefcodec & AST_FORMAT_TEXT_MASK; /* Outbound call */ 06782 else 06783 needtext = i->jointcapability & AST_FORMAT_TEXT_MASK; /* Inbound call */ 06784 } 06785 06786 if (needvideo) 06787 ast_debug(3, "This channel can handle video! HOLLYWOOD next!\n"); 06788 else 06789 ast_debug(3, "This channel will not be able to handle video.\n"); 06790 06791 if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) || 06792 (ast_test_flag(&i->flags[1], SIP_PAGE2_FAX_DETECT))) { 06793 int features = 0; 06794 06795 if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 06796 features |= DSP_FEATURE_DIGIT_DETECT; 06797 } 06798 06799 if (ast_test_flag(&i->flags[1], SIP_PAGE2_FAX_DETECT)) { 06800 features |= DSP_FEATURE_FAX_DETECT; 06801 } 06802 06803 i->dsp = ast_dsp_new(); 06804 ast_dsp_set_features(i->dsp, features); 06805 if (global_relaxdtmf) 06806 ast_dsp_set_digitmode(i->dsp, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF); 06807 } 06808 06809 /* Set file descriptors for audio, video, realtime text and UDPTL as needed */ 06810 if (i->rtp) { 06811 ast_channel_set_fd(tmp, 0, ast_rtp_fd(i->rtp)); 06812 ast_channel_set_fd(tmp, 1, ast_rtcp_fd(i->rtp)); 06813 } 06814 if (needvideo && i->vrtp) { 06815 ast_channel_set_fd(tmp, 2, ast_rtp_fd(i->vrtp)); 06816 ast_channel_set_fd(tmp, 3, ast_rtcp_fd(i->vrtp)); 06817 } 06818 if (needtext && i->trtp) 06819 ast_channel_set_fd(tmp, 4, ast_rtp_fd(i->trtp)); 06820 if (i->udptl) 06821 ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl)); 06822 06823 if (state == AST_STATE_RING) 06824 tmp->rings = 1; 06825 tmp->adsicpe = AST_ADSI_UNAVAILABLE; 06826 tmp->writeformat = fmt; 06827 tmp->rawwriteformat = fmt; 06828 tmp->readformat = fmt; 06829 tmp->rawreadformat = fmt; 06830 tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i"); 06831 06832 tmp->callgroup = i->callgroup; 06833 tmp->pickupgroup = i->pickupgroup; 06834 tmp->cid.cid_pres = i->callingpres; 06835 if (!ast_strlen_zero(i->parkinglot)) 06836 ast_string_field_set(tmp, parkinglot, i->parkinglot); 06837 if (!ast_strlen_zero(i->accountcode)) 06838 ast_string_field_set(tmp, accountcode, i->accountcode); 06839 if (i->amaflags) 06840 tmp->amaflags = i->amaflags; 06841 if (!ast_strlen_zero(i->language)) 06842 ast_string_field_set(tmp, language, i->language); 06843 i->owner = tmp; 06844 ast_module_ref(ast_module_info->self); 06845 ast_copy_string(tmp->context, i->context, sizeof(tmp->context)); 06846 /*Since it is valid to have extensions in the dialplan that have unescaped characters in them 06847 * we should decode the uri before storing it in the channel, but leave it encoded in the sip_pvt 06848 * structure so that there aren't issues when forming URI's 06849 */ 06850 if (ast_exists_extension(NULL, i->context, i->exten, 1, i->cid_num)) { 06851 /* encoded in dialplan, so keep extension encoded */ 06852 ast_copy_string(tmp->exten, i->exten, sizeof(tmp->exten)); 06853 } else { 06854 decoded_exten = ast_strdupa(i->exten); 06855 ast_uri_decode(decoded_exten); 06856 ast_copy_string(tmp->exten, decoded_exten, sizeof(tmp->exten)); 06857 } 06858 06859 /* Don't use ast_set_callerid() here because it will 06860 * generate an unnecessary NewCallerID event */ 06861 tmp->cid.cid_ani = ast_strdup(i->cid_num); 06862 if (!ast_strlen_zero(i->rdnis)) 06863 tmp->cid.cid_rdnis = ast_strdup(i->rdnis); 06864 06865 if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) 06866 tmp->cid.cid_dnid = ast_strdup(i->exten); 06867 06868 tmp->priority = 1; 06869 if (!ast_strlen_zero(i->uri)) 06870 pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri); 06871 if (!ast_strlen_zero(i->domain)) 06872 pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain); 06873 if (!ast_strlen_zero(i->callid)) 06874 pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid); 06875 if (i->rtp) 06876 ast_jb_configure(tmp, &global_jbconf); 06877 06878 /* Set channel variables for this call from configuration */ 06879 for (v = i->chanvars ; v ; v = v->next) { 06880 char valuebuf[1024]; 06881 pbx_builtin_setvar_helper(tmp, v->name, ast_get_encoded_str(v->value, valuebuf, sizeof(valuebuf))); 06882 } 06883 06884 if (state != AST_STATE_DOWN && ast_pbx_start(tmp)) { 06885 ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name); 06886 tmp->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 06887 ast_hangup(tmp); 06888 tmp = NULL; 06889 } 06890 06891 if (i->do_history) 06892 append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid); 06893 06894 /* Inform manager user about new channel and their SIP call ID */ 06895 if (sip_cfg.callevents) 06896 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 06897 "Channel: %s\r\nUniqueid: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\n", 06898 tmp->name, tmp->uniqueid, "SIP", i->callid, i->fullcontact); 06899 06900 return tmp; 06901 }
| static int sip_park | ( | struct ast_channel * | chan1, | |
| struct ast_channel * | chan2, | |||
| struct sip_request * | req, | |||
| int | seqno | |||
| ) | [static] |
Park a call using the subsystem in res_features.c This is executed in a separate thread.
Definition at line 19009 of file chan_sip.c.
References ast_channel::accountcode, ast_channel::amaflags, ast_calloc, AST_CAUSE_SWITCH_CONGESTION, ast_channel_alloc, ast_channel_lock, ast_channel_masquerade(), ast_channel_trylock, ast_channel_unlock, ast_copy_string(), ast_debug, ast_do_masquerade(), ast_free, ast_hangup(), ast_log(), ast_pthread_create_detached_background, AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), sip_dual::chan1, sip_dual::chan2, ast_channel::context, copy_request(), deinit_req(), ast_channel::exten, ast_channel::hangupcause, LOG_WARNING, ast_channel::name, parkinglot, ast_channel::parkinglot, ast_channel::priority, ast_channel::readformat, sip_dual::req, sip_dual::seqno, sip_park_thread(), sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and ast_channel::writeformat.
Referenced by handle_request_refer().
19010 { 19011 struct sip_dual *d; 19012 struct ast_channel *transferee, *transferer; 19013 /* Chan2m: The transferer, chan1m: The transferee */ 19014 pthread_t th; 19015 19016 transferee = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan1->accountcode, chan1->exten, chan1->context, chan1->amaflags, "Parking/%s", chan1->name); 19017 transferer = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan2->accountcode, chan2->exten, chan2->context, chan2->amaflags, "SIPPeer/%s", chan2->name); 19018 if ((!transferer) || (!transferee)) { 19019 if (transferee) { 19020 transferee->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 19021 ast_hangup(transferee); 19022 } 19023 if (transferer) { 19024 transferer->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 19025 ast_hangup(transferer); 19026 } 19027 return -1; 19028 } 19029 19030 /* Make formats okay */ 19031 transferee->readformat = chan1->readformat; 19032 transferee->writeformat = chan1->writeformat; 19033 19034 /* Prepare for taking over the channel */ 19035 ast_channel_masquerade(transferee, chan1); 19036 19037 /* Setup the extensions and such */ 19038 ast_copy_string(transferee->context, chan1->context, sizeof(transferee->context)); 19039 ast_copy_string(transferee->exten, chan1->exten, sizeof(transferee->exten)); 19040 transferee->priority = chan1->priority; 19041 19042 /* We make a clone of the peer channel too, so we can play 19043 back the announcement */ 19044 19045 /* Make formats okay */ 19046 transferer->readformat = chan2->readformat; 19047 transferer->writeformat = chan2->writeformat; 19048 if (!ast_strlen_zero(chan2->parkinglot)) 19049 ast_string_field_set(transferer, parkinglot, chan2->parkinglot); 19050 19051 /* Prepare for taking over the channel. Go ahead and grab this channel 19052 * lock here to avoid a deadlock with callbacks into the channel driver 19053 * that hold the channel lock and want the pvt lock. */ 19054 while (ast_channel_trylock(chan2)) { 19055 struct sip_pvt *pvt = chan2->tech_pvt; 19056 sip_pvt_unlock(pvt); 19057 usleep(1); 19058 sip_pvt_lock(pvt); 19059 } 19060 ast_channel_masquerade(transferer, chan2); 19061 ast_channel_unlock(chan2); 19062 19063 /* Setup the extensions and such */ 19064 ast_copy_string(transferer->context, chan2->context, sizeof(transferer->context)); 19065 ast_copy_string(transferer->exten, chan2->exten, sizeof(transferer->exten)); 19066 transferer->priority = chan2->priority; 19067 19068 ast_channel_lock(transferer); 19069 if (ast_do_masquerade(transferer)) { 19070 ast_log(LOG_WARNING, "Masquerade failed :(\n"); 19071 ast_channel_unlock(transferer); 19072 transferer->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 19073 ast_hangup(transferer); 19074 return -1; 19075 } 19076 ast_channel_unlock(transferer); 19077 if (!transferer || !transferee) { 19078 if (!transferer) { 19079 ast_debug(1, "No transferer channel, giving up parking\n"); 19080 } 19081 if (!transferee) { 19082 ast_debug(1, "No transferee channel, giving up parking\n"); 19083 } 19084 return -1; 19085 } 19086 if ((d = ast_calloc(1, sizeof(*d)))) { 19087 19088 /* Save original request for followup */ 19089 copy_request(&d->req, req); 19090 d->chan1 = transferee; /* Transferee */ 19091 d->chan2 = transferer; /* Transferer */ 19092 d->seqno = seqno; 19093 if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) { 19094 /* Could not start thread */ 19095 deinit_req(&d->req); 19096 ast_free(d); /* We don't need it anymore. If thread is created, d will be free'd 19097 by sip_park_thread() */ 19098 return 0; 19099 } 19100 } 19101 return -1; 19102 }
| static void * sip_park_thread | ( | void * | stuff | ) | [static] |
Park SIP call support function Starts in a new thread, then parks the call XXX Should we add a wait period after streaming audio and before hangup?? Sometimes the audio can't be heard before hangup.
Definition at line 18940 of file chan_sip.c.
References append_history, AST_CAUSE_NORMAL_CLEARING, ast_channel_lock, ast_channel_unlock, ast_debug, ast_do_masquerade(), ast_hangup(), ast_log(), ast_park_call(), buf, sip_dual::chan1, sip_dual::chan2, copy_request(), deinit_req(), ext, free, ast_channel::hangupcause, LOG_ERROR, LOG_WARNING, ast_channel::name, sip_dual::req, sip_dual::seqno, ast_channel::tech_pvt, transmit_message_with_text(), transmit_notify_with_sipfrag(), transmit_response(), and TRUE.
Referenced by sip_park().
18941 { 18942 struct ast_channel *transferee, *transferer; /* Chan1: The transferee, Chan2: The transferer */ 18943 struct sip_dual *d; 18944 struct sip_request req = {0,}; 18945 int ext; 18946 int res; 18947 18948 d = stuff; 18949 transferee = d->chan1; 18950 transferer = d->chan2; 18951 copy_request(&req, &d->req); 18952 18953 if (!transferee || !transferer) { 18954 ast_log(LOG_ERROR, "Missing channels for parking! Transferer %s Transferee %s\n", transferer ? "<available>" : "<missing>", transferee ? "<available>" : "<missing>" ); 18955 deinit_req(&d->req); 18956 free(d); 18957 return NULL; 18958 } 18959 ast_debug(4, "SIP Park: Transferer channel %s, Transferee %s\n", transferer->name, transferee->name); 18960 18961 ast_channel_lock(transferee); 18962 if (ast_do_masquerade(transferee)) { 18963 ast_log(LOG_WARNING, "Masquerade failed.\n"); 18964 transmit_response(transferer->tech_pvt, "503 Internal error", &req); 18965 ast_channel_unlock(transferee); 18966 deinit_req(&d->req); 18967 free(d); 18968 return NULL; 18969 } 18970 ast_channel_unlock(transferee); 18971 18972 res = ast_park_call(transferee, transferer, 0, &ext); 18973 18974 18975 #ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE 18976 if (!res) { 18977 transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n"); 18978 } else { 18979 /* Then tell the transferer what happened */ 18980 sprintf(buf, "Call parked on extension '%d'", ext); 18981 transmit_message_with_text(transferer->tech_pvt, buf); 18982 } 18983 #endif 18984 18985 /* Any way back to the current call??? */ 18986 /* Transmit response to the REFER request */ 18987 transmit_response(transferer->tech_pvt, "202 Accepted", &req); 18988 if (!res) { 18989 /* Transfer succeeded */ 18990 append_history(transferer->tech_pvt, "SIPpark", "Parked call on %d", ext); 18991 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "200 OK", TRUE); 18992 transferer->hangupcause = AST_CAUSE_NORMAL_CLEARING; 18993 ast_hangup(transferer); /* This will cause a BYE */ 18994 ast_debug(1, "SIP Call parked on extension '%d'\n", ext); 18995 } else { 18996 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "503 Service Unavailable", TRUE); 18997 append_history(transferer->tech_pvt, "SIPpark", "Parking failed\n"); 18998 ast_debug(1, "SIP Call parked failed \n"); 18999 /* Do not hangup call */ 19000 } 19001 deinit_req(&d->req); 19002 free(d); 19003 return NULL; 19004 }
| static int sip_parse_host | ( | char * | line, | |
| int | lineno, | |||
| char ** | hostname, | |||
| int * | portnum, | |||
| enum sip_transport * | transport | |||
| ) | [static] |
Small function to parse a config line for a host with a transport i.e. tls://www.google.com:8056.
Definition at line 22457 of file chan_sip.c.
References ast_log(), LOG_NOTICE, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, STANDARD_SIP_PORT, and STANDARD_TLS_PORT.
Referenced by reload_config(), and sip_subscribe_mwi().
22458 { 22459 char *port; 22460 22461 if ((*hostname = strstr(line, "://"))) { 22462 *hostname += 3; 22463 22464 if (!strncasecmp(line, "tcp", 3)) 22465 *transport = SIP_TRANSPORT_TCP; 22466 else if (!strncasecmp(line, "tls", 3)) 22467 *transport = SIP_TRANSPORT_TLS; 22468 else if (!strncasecmp(line, "udp", 3)) 22469 *transport = SIP_TRANSPORT_UDP; 22470 else 22471 ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", line, lineno); 22472 } else { 22473 *hostname = line; 22474 *transport = SIP_TRANSPORT_UDP; 22475 } 22476 22477 if ((line = strrchr(*hostname, '@'))) 22478 line++; 22479 else 22480 line = *hostname; 22481 22482 if ((port = strrchr(line, ':'))) { 22483 *port++ = '\0'; 22484 22485 if (!sscanf(port, "%5u", portnum)) { 22486 ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", port, lineno); 22487 port = NULL; 22488 } 22489 } 22490 22491 if (!port) { 22492 if (*transport & SIP_TRANSPORT_TLS) { 22493 *portnum = STANDARD_TLS_PORT; 22494 } else { 22495 *portnum = STANDARD_SIP_PORT; 22496 } 22497 } 22498 22499 return 0; 22500 }
| static void sip_peer_hold | ( | struct sip_pvt * | p, | |
| int | hold | |||
| ) | [static] |
Change onhold state of a peer using a pvt structure.
Definition at line 12925 of file chan_sip.c.
References ast_atomic_fetchadd_int(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), FALSE, find_peer(), FINDALLDEVICES, sip_peer::name, sip_peer::onHold, sip_pvt::peername, and unref_peer().
Referenced by change_hold_state(), and update_call_counter().
12926 { 12927 struct sip_peer *peer = find_peer(p->peername, NULL, 1, FINDALLDEVICES, FALSE, 0); 12928 12929 if (!peer) 12930 return; 12931 12932 /* If they put someone on hold, increment the value... otherwise decrement it */ 12933 ast_atomic_fetchadd_int(&peer->onHold, (hold ? +1 : -1)); 12934 12935 /* Request device state update */ 12936 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 12937 unref_peer(peer, "sip_peer_hold: from find_peer operation"); 12938 12939 return; 12940 }
| static void sip_poke_all_peers | ( | void | ) | [static] |
Send a poke to all known peers.
Definition at line 25869 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock(), ao2_t_iterator_next, ao2_unlock(), AST_SCHED_REPLACE_UNREF, num, sip_peer::pokeexpire, ref_peer(), sip_poke_peer_s(), and unref_peer().
Referenced by load_module(), and sip_do_reload().
25870 { 25871 int ms = 0, num = 0; 25872 struct ao2_iterator i; 25873 struct sip_peer *peer; 25874 25875 if (!speerobjs) /* No peers, just give up */ 25876 return; 25877 25878 i = ao2_iterator_init(peers, 0); 25879 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 25880 ao2_lock(peer); 25881 if (num == global_qualify_peers) { 25882 ms += global_qualify_gap; 25883 num = 0; 25884 } else { 25885 num++; 25886 } 25887 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, ms, sip_poke_peer_s, peer, 25888 unref_peer(_data, "removing poke peer ref"), 25889 unref_peer(peer, "removing poke peer ref"), 25890 ref_peer(peer, "adding poke peer ref")); 25891 ao2_unlock(peer); 25892 unref_peer(peer, "toss iterator peer ptr"); 25893 } 25894 ao2_iterator_destroy(&i); 25895 }
| static int sip_poke_noanswer | ( | const void * | data | ) | [static] |
React to lack of answer to Qualify poke.
Definition at line 23082 of file chan_sip.c.
References ast_check_realtime(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), AST_SCHED_REPLACE_UNREF, ast_update_realtime(), sip_peer::call, DEFAULT_FREQ_NOTOK, dialog_unlink_all(), dialog_unref(), EVENT_FLAG_SYSTEM, FALSE, sip_peer::lastms, LOG_NOTICE, manager_event, sip_peer::name, sip_settings::peer_rtupdate, sip_peer::pokeexpire, ref_peer(), sip_settings::regextenonqualify, register_peer_exten(), SENTINEL, sip_cfg, sip_poke_peer_s(), TRUE, and unref_peer().
Referenced by sip_poke_peer(), and sip_show_sched().
23083 { 23084 struct sip_peer *peer = (struct sip_peer *)data; 23085 23086 peer->pokeexpire = -1; 23087 23088 if (peer->lastms > -1) { 23089 ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Last qualify: %d\n", peer->name, peer->lastms); 23090 if (sip_cfg.peer_rtupdate) { 23091 ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", "-1", SENTINEL); 23092 } 23093 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1); 23094 if (sip_cfg.regextenonqualify) { 23095 register_peer_exten(peer, FALSE); 23096 } 23097 } 23098 23099 if (peer->call) { 23100 dialog_unlink_all(peer->call, TRUE, TRUE); 23101 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 23102 /* peer->call = sip_destroy(peer->call);*/ 23103 } 23104 23105 /* Don't send a devstate change if nothing changed. */ 23106 if (peer->lastms > -1) { 23107 peer->lastms = -1; 23108 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 23109 } 23110 23111 /* Try again quickly */ 23112 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, 23113 DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer, 23114 unref_peer(_data, "removing poke peer ref"), 23115 unref_peer(peer, "removing poke peer ref"), 23116 ref_peer(peer, "adding poke peer ref")); 23117 23118 /* Release the ref held by the running scheduler entry */ 23119 unref_peer(peer, "release peer poke noanswer ref"); 23120 23121 return 0; 23122 }
| static int sip_poke_peer | ( | struct sip_peer * | peer, | |
| int | force | |||
| ) | [static] |
Check availability of peer, also keep NAT open.
Definition at line 23129 of file chan_sip.c.
References sip_peer::addr, ao2_t_link, ao2_t_unlink, ast_copy_flags, ast_copy_string(), ast_inet_ntoa(), ast_log(), AST_SCHED_DEL_UNREF, AST_SCHED_REPLACE_UNREF, ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_set, ast_strlen_zero(), ast_tvnow(), build_callid_pvt(), build_via(), sip_peer::call, copy_socket_data(), dialog_ref(), dialog_unlink_all(), dialog_unref(), sip_peer::flags, sip_pvt::flags, sip_pvt::fullcontact, sip_peer::fullcontact, sip_peer::lastms, LOG_NOTICE, sip_peer::maxms, sip_pvt::ourip, sip_peer::pokeexpire, sip_peer::ps, sip_pvt::recv, ref_peer(), sip_pvt::relatedpeer, sip_pvt::sa, sip_alloc(), SIP_FLAGS_TO_COPY, SIP_INVITE, SIP_OPTIONS, SIP_OUTGOING, SIP_PAGE2_FLAGS_TO_COPY, sip_poke_noanswer(), sip_peer::socket, sip_pvt::socket, sip_pvt::tohost, sip_peer::tohost, transmit_invite(), TRUE, unref_peer(), sip_pvt::username, and XMIT_ERROR.
Referenced by _sip_qualify_peer(), build_peer(), parse_register_contact(), reg_source_db(), and sip_poke_peer_s().
23130 { 23131 struct sip_pvt *p; 23132 int xmitres = 0; 23133 23134 if ((!peer->maxms && !force) || !peer->addr.sin_addr.s_addr) { 23135 /* IF we have no IP, or this isn't to be monitored, return 23136 immediately after clearing things out */ 23137 AST_SCHED_DEL_UNREF(sched, peer->pokeexpire, 23138 unref_peer(peer, "removing poke peer ref")); 23139 23140 peer->lastms = 0; 23141 if (peer->call) { 23142 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 23143 } 23144 return 0; 23145 } 23146 if (peer->call) { 23147 if (sipdebug) { 23148 ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n"); 23149 } 23150 dialog_unlink_all(peer->call, TRUE, TRUE); 23151 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 23152 /* peer->call = sip_destroy(peer->call); */ 23153 } 23154 if (!(p = sip_alloc(NULL, NULL, 0, SIP_OPTIONS, NULL))) { 23155 return -1; 23156 } 23157 peer->call = dialog_ref(p, "copy sip alloc from p to peer->call"); 23158 23159 p->sa = peer->addr; 23160 p->recv = peer->addr; 23161 copy_socket_data(&p->socket, &peer->socket); 23162 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 23163 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 23164 23165 /* Send OPTIONs to peer's fullcontact */ 23166 if (!ast_strlen_zero(peer->fullcontact)) 23167 ast_string_field_set(p, fullcontact, peer->fullcontact); 23168 23169 if (!ast_strlen_zero(peer->tohost)) 23170 ast_string_field_set(p, tohost, peer->tohost); 23171 else 23172 ast_string_field_set(p, tohost, ast_inet_ntoa(peer->addr.sin_addr)); 23173 23174 /* Recalculate our side, and recalculate Call ID */ 23175 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 23176 build_via(p); 23177 ao2_t_unlink(dialogs, p, "About to change the callid -- remove the old name"); 23178 build_callid_pvt(p); 23179 ao2_t_link(dialogs, p, "Linking in under new name"); 23180 23181 AST_SCHED_DEL_UNREF(sched, peer->pokeexpire, 23182 unref_peer(peer, "removing poke peer ref")); 23183 23184 if (p->relatedpeer) 23185 p->relatedpeer = unref_peer(p->relatedpeer,"unsetting the relatedpeer field in the dialog, before it is set to something else."); 23186 p->relatedpeer = ref_peer(peer, "setting the relatedpeer field in the dialog"); 23187 ast_set_flag(&p->flags[0], SIP_OUTGOING); 23188 #ifdef VOCAL_DATA_HACK 23189 ast_copy_string(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username)); 23190 xmitres = transmit_invite(p, SIP_INVITE, 0, 2); /* sinks the p refcount */ 23191 #else 23192 xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2); /* sinks the p refcount */ 23193 #endif 23194 peer->ps = ast_tvnow(); 23195 if (xmitres == XMIT_ERROR) { 23196 sip_poke_noanswer(peer); /* Immediately unreachable, network problems */ 23197 } else if (!force) { 23198 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, peer->maxms * 2, sip_poke_noanswer, peer, 23199 unref_peer(_data, "removing poke peer ref"), 23200 unref_peer(peer, "removing poke peer ref"), 23201 ref_peer(peer, "adding poke peer ref")); 23202 } 23203 dialog_unref(p, "unref dialog at end of sip_poke_peer, obtained from sip_alloc, just before it goes out of scope"); 23204 return 0; 23205 }
| static int sip_poke_peer_s | ( | const void * | data | ) | [static] |
Poke peer (send qualify to check if peer is alive and well).
Definition at line 12223 of file chan_sip.c.
References ao2_find, sip_peer::name, OBJ_POINTER, sip_peer::pokeexpire, sip_poke_peer(), and unref_peer().
Referenced by handle_response_peerpoke(), reg_source_db(), sip_poke_all_peers(), sip_poke_noanswer(), and sip_show_sched().
12224 { 12225 struct sip_peer *peer = (struct sip_peer *)data; 12226 struct sip_peer *foundpeer; 12227 12228 peer->pokeexpire = -1; 12229 12230 foundpeer = ao2_find(peers, peer, OBJ_POINTER); 12231 if (!foundpeer) { 12232 unref_peer(peer, "removing poke peer ref"); 12233 return 0; 12234 } else if (foundpeer->name != peer->name) { 12235 unref_peer(foundpeer, "removing above peer ref"); 12236 unref_peer(peer, "removing poke peer ref"); 12237 return 0; 12238 } 12239 12240 unref_peer(foundpeer, "removing above peer ref"); 12241 sip_poke_peer(peer, 0); 12242 unref_peer(peer, "removing poke peer ref"); 12243 12244 return 0; 12245 }
| static int sip_prepare_socket | ( | struct sip_pvt * | p | ) | [static] |
Definition at line 22323 of file chan_sip.c.
References ast_tcptls_session_args::accept_fd, ao2_alloc, ao2_ref, ao2_t_ref, ao2_t_unlink, ast_calloc, ast_copy_string(), ast_debug, ast_pthread_create_background, ast_strdup, ast_strlen_zero(), ast_tcptls_client_create(), ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, default_tls_cfg, ast_tcptls_session_instance::fd, sip_socket::fd, ast_tcptls_session_args::hostname, ast_tcptls_session_args::master, ast_tcptls_session_args::name, name, sip_pvt::outboundproxy, ast_tcptls_session_args::remote_address, s, sip_real_dst(), sip_tcp_locate(), sip_tcp_worker_fn(), sip_tcptls_client_args_destructor(), sip_threadinfo_create(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, sip_pvt::socket, sip_socket::tcptls_session, ast_tcptls_session_args::tls_cfg, sip_pvt::tohost, sip_proxy::transport, and sip_socket::type.
Referenced by __sip_xmit().
22324 { 22325 struct sip_socket *s = &p->socket; 22326 static const char name[] = "SIP socket"; 22327 struct sip_threadinfo *th = NULL; 22328 struct ast_tcptls_session_instance *tcptls_session; 22329 struct ast_tcptls_session_args tmp_ca = { 22330 .name = name, 22331 .accept_fd = -1, 22332 }; 22333 struct ast_tcptls_session_args *ca; 22334 22335 /* check to see if a socket is already active */ 22336 if ((s->fd != -1) && (s->type == SIP_TRANSPORT_UDP)) { 22337 return s->fd; 22338 } 22339 if ((s->type & (SIP_TRANSPORT_TCP | SIP_TRANSPORT_TLS)) && 22340 (s->tcptls_session) && 22341 (s->tcptls_session->fd != -1)) { 22342 return s->tcptls_session->fd; 22343 } 22344 22345 /*! \todo Check this... This might be wrong, depending on the proxy configuration 22346 If proxy is in "force" mode its correct. 22347 */ 22348 if (p->outboundproxy && p->outboundproxy->transport) { 22349 s->type = p->outboundproxy->transport; 22350 } 22351 22352 if (s->type == SIP_TRANSPORT_UDP) { 22353 s->fd = sipsock; 22354 return s->fd; 22355 } 22356 22357 /* At this point we are dealing with a TCP/TLS connection 22358 * 1. We need to check to see if a connectin thread exists 22359 * for this address, if so use that. 22360 * 2. If a thread does not exist for this address, but the tcptls_session 22361 * exists on the socket, the connection was closed. 22362 * 3. If no tcptls_session thread exists for the address, and no tcptls_session 22363 * already exists on the socket, create a new one and launch a new thread. 22364 */ 22365 22366 /* 1. check for existing threads */ 22367 tmp_ca.remote_address = *(sip_real_dst(p)); 22368 if ((tcptls_session = sip_tcp_locate(&tmp_ca.remote_address))) { 22369 s->fd = tcptls_session->fd; 22370 if (s->tcptls_session) { 22371 ao2_ref(s->tcptls_session, -1); 22372 s->tcptls_session = NULL; 22373 } 22374 s->tcptls_session = tcptls_session; 22375 return s->fd; 22376 /* 2. Thread not found, if tcptls_session already exists, it once had a thread and is now terminated */ 22377 } else if (s->tcptls_session) { 22378 return s->fd; /* XXX whether reconnection is ever necessary here needs to be investigated further */ 22379 } 22380 22381 /* 3. Create a new TCP/TLS client connection */ 22382 /* create new session arguments for the client connection */ 22383 if (!(ca = ao2_alloc(sizeof(*ca), sip_tcptls_client_args_destructor)) || 22384 !(ca->name = ast_strdup(name))) { 22385 goto create_tcptls_session_fail; 22386 } 22387 ca->accept_fd = -1; 22388 ca->remote_address = *(sip_real_dst(p)); 22389 /* if type is TLS, we need to create a tls cfg for this session arg */ 22390 if (s->type == SIP_TRANSPORT_TLS) { 22391 if (!(ca->tls_cfg = ast_calloc(1, sizeof(*ca->tls_cfg)))) { 22392 goto create_tcptls_session_fail; 22393 } 22394 memcpy(ca->tls_cfg, &default_tls_cfg, sizeof(*ca->tls_cfg)); 22395 22396 if (!(ca->tls_cfg->certfile = ast_strdup(default_tls_cfg.certfile)) || 22397 !(ca->tls_cfg->cipher = ast_strdup(default_tls_cfg.cipher)) || 22398 !(ca->tls_cfg->cafile = ast_strdup(default_tls_cfg.cafile)) || 22399 !(ca->tls_cfg->capath = ast_strdup(default_tls_cfg.capath))) { 22400 22401 goto create_tcptls_session_fail; 22402 } 22403 22404 /* this host is used as the common name in ssl/tls */ 22405 if (!ast_strlen_zero(p->tohost)) { 22406 ast_copy_string(ca->hostname, p->tohost, sizeof(ca->hostname)); 22407 } 22408 } 22409 /* Create a client connection for address, this does not start the connection, just sets it up. */ 22410 if (!(s->tcptls_session = ast_tcptls_client_create(ca))) { 22411 goto create_tcptls_session_fail; 22412 } 22413 22414 s->fd = s->tcptls_session->fd; 22415 22416 /* client connections need to have the sip_threadinfo object created before 22417 * the thread is detached. This ensures the alert_pipe is up before it will 22418 * be used. Note that this function links the new threadinfo object into the 22419 * threadt container. */ 22420 if (!(th = sip_threadinfo_create(s->tcptls_session, s->type))) { 22421 goto create_tcptls_session_fail; 22422 22423 } 22424 22425 /* Give the new thread a reference to the tcptls_session */ 22426 ao2_ref(s->tcptls_session, +1); 22427 22428 if (ast_pthread_create_background(&ca->master, NULL, sip_tcp_worker_fn, s->tcptls_session)) { 22429 ast_debug(1, "Unable to launch '%s'.", ca->name); 22430 ao2_ref(s->tcptls_session, -1); /* take away the thread ref we just gave it */ 22431 goto create_tcptls_session_fail; 22432 } 22433 22434 return s->fd; 22435 22436 create_tcptls_session_fail: 22437 if (ca) { 22438 ao2_t_ref(ca, -1, "failed to create client, getting rid of client tcptls_session arguments"); 22439 } 22440 if (s->tcptls_session) { 22441 close(tcptls_session->fd); 22442 s->fd = tcptls_session->fd = -1; 22443 ao2_ref(s->tcptls_session, -1); 22444 s->tcptls_session = NULL; 22445 } 22446 if (th) { 22447 ao2_t_unlink(threadt, th, "Removing tcptls thread info object, thread failed to open"); 22448 } 22449 22450 return -1; 22451 }
| static char * sip_prune_realtime | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Remove temporary realtime objects from memory (CLI).
Definition at line 15232 of file chan_sip.c.
References sip_peer::addr, ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock(), ao2_t_find, ao2_t_iterator_next, ao2_t_link, ao2_t_unlink, ao2_unlock(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), ast_copy_string(), ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_peer(), FALSE, ast_cli_args::fd, sip_peer::flags, ast_cli_args::n, sip_peer::name, name, OBJ_POINTER, OBJ_UNLINK, ast_cli_args::pos, SIP_PAGE2_RTCACHEFRIENDS, sip_peer::the_mark, TRUE, unlink_marked_peers_from_tables(), unref_peer(), ast_cli_entry::usage, and ast_cli_args::word.
15233 { 15234 struct sip_peer *peer, *pi; 15235 int prunepeer = FALSE; 15236 int multi = FALSE; 15237 char *name = NULL; 15238 regex_t regexbuf; 15239 struct ao2_iterator i; 15240 static char *choices[] = { "all", "like", NULL }; 15241 char *cmplt; 15242 15243 if (cmd == CLI_INIT) { 15244 e->command = "sip prune realtime [peer|all]"; 15245 e->usage = 15246 "Usage: sip prune realtime [peer [<name>|all|like <pattern>]|all]\n" 15247 " Prunes object(s) from the cache.\n" 15248 " Optional regular expression pattern is used to filter the objects.\n"; 15249 return NULL; 15250 } else if (cmd == CLI_GENERATE) { 15251 if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) { 15252 cmplt = ast_cli_complete(a->word, choices, a->n); 15253 if (!cmplt) 15254 cmplt = complete_sip_peer(a->word, a->n - sizeof(choices), SIP_PAGE2_RTCACHEFRIENDS); 15255 return cmplt; 15256 } 15257 if (a->pos == 5 && !strcasecmp(a->argv[4], "like")) 15258 return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS); 15259 return NULL; 15260 } 15261 switch (a->argc) { 15262 case 4: 15263 name = a->argv[3]; 15264 /* we accept a name in position 3, but keywords are not good. */ 15265 if (!strcasecmp(name, "peer") || !strcasecmp(name, "like")) 15266 return CLI_SHOWUSAGE; 15267 prunepeer = TRUE; 15268 if (!strcasecmp(name, "all")) { 15269 multi = TRUE; 15270 name = NULL; 15271 } 15272 /* else a single name, already set */ 15273 break; 15274 case 5: 15275 /* sip prune realtime {peer|like} name */ 15276 name = a->argv[4]; 15277 if (!strcasecmp(a->argv[3], "peer")) 15278 prunepeer = TRUE; 15279 else if (!strcasecmp(a->argv[3], "like")) { 15280 prunepeer = TRUE; 15281 multi = TRUE; 15282 } else 15283 return CLI_SHOWUSAGE; 15284 if (!strcasecmp(name, "like")) 15285 return CLI_SHOWUSAGE; 15286 if (!multi && !strcasecmp(name, "all")) { 15287 multi = TRUE; 15288 name = NULL; 15289 } 15290 break; 15291 case 6: 15292 name = a->argv[5]; 15293 multi = TRUE; 15294 /* sip prune realtime {peer} like name */ 15295 if (strcasecmp(a->argv[4], "like")) 15296 return CLI_SHOWUSAGE; 15297 if (!strcasecmp(a->argv[3], "peer")) { 15298 prunepeer = TRUE; 15299 } else 15300 return CLI_SHOWUSAGE; 15301 break; 15302 default: 15303 return CLI_SHOWUSAGE; 15304 } 15305 15306 if (multi && name) { 15307 if (regcomp(®exbuf, name, REG_EXTENDED | REG_NOSUB)) 15308 return CLI_SHOWUSAGE; 15309 } 15310 15311 if (multi) { 15312 if (prunepeer) { 15313 int pruned = 0; 15314 15315 i = ao2_iterator_init(peers, 0); 15316 while ((pi = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 15317 ao2_lock(pi); 15318 if (name && regexec(®exbuf, pi->name, 0, NULL, 0)) { 15319 unref_peer(pi, "toss iterator peer ptr before continue"); 15320 ao2_unlock(pi); 15321 continue; 15322 }; 15323 if (ast_test_flag(&pi->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 15324 pi->the_mark = 1; 15325 pruned++; 15326 } 15327 ao2_unlock(pi); 15328 unref_peer(pi, "toss iterator peer ptr"); 15329 } 15330 ao2_iterator_destroy(&i); 15331 if (pruned) { 15332 unlink_marked_peers_from_tables(); 15333 ast_cli(a->fd, "%d peers pruned.\n", pruned); 15334 } else 15335 ast_cli(a->fd, "No peers found to prune.\n"); 15336 } 15337 } else { 15338 if (prunepeer) { 15339 struct sip_peer tmp; 15340 ast_copy_string(tmp.name, name, sizeof(tmp.name)); 15341 if ((peer = ao2_t_find(peers, &tmp, OBJ_POINTER | OBJ_UNLINK, "finding to unlink from peers"))) { 15342 if (peer->addr.sin_addr.s_addr) { 15343 ao2_t_unlink(peers_by_ip, peer, "unlinking peer from peers_by_ip also"); 15344 } 15345 if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 15346 ast_cli(a->fd, "Peer '%s' is not a Realtime peer, cannot be pruned.\n", name); 15347 /* put it back! */ 15348 ao2_t_link(peers, peer, "link peer into peer table"); 15349 if (peer->addr.sin_addr.s_addr) { 15350 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 15351 } 15352 15353 } else 15354 ast_cli(a->fd, "Peer '%s' pruned.\n", name); 15355 unref_peer(peer, "sip_prune_realtime: unref_peer: tossing temp peer ptr"); 15356 } else 15357 ast_cli(a->fd, "Peer '%s' not found.\n", name); 15358 } 15359 } 15360 15361 return CLI_SUCCESS; 15362 }
| static char * sip_qualify_peer | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Send an OPTIONS packet to a SIP peer.
Definition at line 15516 of file chan_sip.c.
References _sip_qualify_peer(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, complete_sip_show_peer(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
15517 { 15518 switch (cmd) { 15519 case CLI_INIT: 15520 e->command = "sip qualify peer"; 15521 e->usage = 15522 "Usage: sip qualify peer <name> [load]\n" 15523 " Requests a response from one SIP peer and the current status.\n" 15524 " Option \"load\" forces lookup of peer in realtime storage.\n"; 15525 return NULL; 15526 case CLI_GENERATE: 15527 return complete_sip_show_peer(a->line, a->word, a->pos, a->n); 15528 } 15529 return _sip_qualify_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); 15530 }
| static int sip_queryoption | ( | struct ast_channel * | chan, | |
| int | option, | |||
| void * | data, | |||
| int * | datalen | |||
| ) | [static] |
Query an option on a SIP dialog.
Definition at line 4327 of file chan_sip.c.
References ast_log(), AST_OPTION_T38_STATE, ast_test_flag, sip_pvt::flags, LOG_ERROR, SIP_PAGE2_T38SUPPORT, sip_pvt_lock, sip_pvt_unlock, t38properties::state, sip_pvt::t38, T38_ENABLED, T38_LOCAL_REINVITE, T38_PEER_REINVITE, T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, T38_STATE_UNAVAILABLE, T38_STATE_UNKNOWN, and ast_channel::tech_pvt.
04328 { 04329 int res = -1; 04330 enum ast_t38_state state = T38_STATE_UNAVAILABLE; 04331 struct sip_pvt *p = (struct sip_pvt *) chan->tech_pvt; 04332 04333 switch (option) { 04334 case AST_OPTION_T38_STATE: 04335 /* Make sure we got an ast_t38_state enum passed in */ 04336 if (*datalen != sizeof(enum ast_t38_state)) { 04337 ast_log(LOG_ERROR, "Invalid datalen for AST_OPTION_T38_STATE option. Expected %d, got %d\n", (int)sizeof(enum ast_t38_state), *datalen); 04338 return -1; 04339 } 04340 04341 sip_pvt_lock(p); 04342 04343 /* Now if T38 support is enabled we need to look and see what the current state is to get what we want to report back */ 04344 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) { 04345 switch (p->t38.state) { 04346 case T38_LOCAL_REINVITE: 04347 case T38_PEER_REINVITE: 04348 state = T38_STATE_NEGOTIATING; 04349 break; 04350 case T38_ENABLED: 04351 state = T38_STATE_NEGOTIATED; 04352 break; 04353 default: 04354 state = T38_STATE_UNKNOWN; 04355 } 04356 } 04357 04358 sip_pvt_unlock(p); 04359 04360 *((enum ast_t38_state *) data) = state; 04361 res = 0; 04362 04363 break; 04364 default: 04365 break; 04366 } 04367 04368 return res; 04369 }
| static struct ast_frame * sip_read | ( | struct ast_channel * | ast | ) | [static, read] |
Read SIP RTP from channel.
Definition at line 7149 of file chan_sip.c.
References ast_channel::_state, ast_async_goto(), ast_channel_lock, ast_channel_unlock, ast_exists_extension(), AST_FRAME_VOICE, ast_log(), ast_null_frame, AST_STATE_UP, ast_test_flag, ast_verbose, ast_channel::cid, ast_callerid::cid_num, ast_channel::context, ast_channel::exten, FALSE, sip_pvt::flags, ast_frame::frametype, INV_EARLY_MEDIA, sip_pvt::invitestate, sip_pvt::lastrtprx, LOG_NOTICE, ast_channel::macrocontext, ast_channel::name, pbx_builtin_setvar_helper(), S_OR, SIP_PAGE2_FAX_DETECT_CNG, sip_pvt_lock, sip_pvt_unlock, sip_rtp_read(), ast_channel::tech_pvt, and VERBOSE_PREFIX_2.
07150 { 07151 struct ast_frame *fr; 07152 struct sip_pvt *p = ast->tech_pvt; 07153 int faxdetected = FALSE; 07154 07155 sip_pvt_lock(p); 07156 fr = sip_rtp_read(ast, p, &faxdetected); 07157 p->lastrtprx = time(NULL); 07158 07159 /* If we detect a CNG tone and fax detection is enabled then send us off to the fax extension */ 07160 if (faxdetected && ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) { 07161 ast_channel_lock(ast); 07162 if (strcmp(ast->exten, "fax")) { 07163 const char *target_context = S_OR(ast->macrocontext, ast->context); 07164 ast_channel_unlock(ast); 07165 if (ast_exists_extension(ast, target_context, "fax", 1, ast->cid.cid_num)) { 07166 ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to CNG detection\n", ast->name); 07167 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten); 07168 if (ast_async_goto(ast, target_context, "fax", 1)) { 07169 ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context); 07170 } 07171 fr = &ast_null_frame; 07172 } else { 07173 ast_log(LOG_NOTICE, "FAX CNG detected but no fax extension\n"); 07174 } 07175 } else { 07176 ast_channel_unlock(ast); 07177 } 07178 } 07179 07180 /* Only allow audio through if they sent progress with SDP, or if the channel is actually answered */ 07181 if (fr && fr->frametype == AST_FRAME_VOICE && p->invitestate != INV_EARLY_MEDIA && ast->_state != AST_STATE_UP) { 07182 fr = &ast_null_frame; 07183 } 07184 07185 sip_pvt_unlock(p); 07186 07187 return fr; 07188 }
| static struct sockaddr_in * sip_real_dst | ( | const struct sip_pvt * | p | ) | [static, read] |
The real destination address for a write.
Definition at line 3472 of file chan_sip.c.
References ast_test_flag, sip_pvt::flags, sip_proxy::ip, sip_pvt::outboundproxy, sip_pvt::recv, sip_pvt::sa, SIP_NAT, and SIP_NAT_ROUTE.
Referenced by __sip_xmit(), check_via(), retrans_pkt(), send_response(), show_channels_cb(), sip_debug_test_pvt(), and sip_prepare_socket().
03473 { 03474 if (p->outboundproxy) 03475 return &p->outboundproxy->ip; 03476 03477 return ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE ? &p->recv : &p->sa; 03478 }
| static int sip_refer_allocate | ( | struct sip_pvt * | p | ) | [static] |
Allocate SIP refer structure.
Definition at line 11982 of file chan_sip.c.
References ast_calloc, and sip_pvt::refer.
Referenced by get_also_info(), handle_request_invite(), handle_request_refer(), and transmit_refer().
11983 { 11984 p->refer = ast_calloc(1, sizeof(struct sip_refer)); 11985 return p->refer ? 1 : 0; 11986 }
| static int sip_reg_timeout | ( | const void * | data | ) | [static] |
Registration timeout, register again Registered as a timeout handler during transmit_register(), to retransmit the packet if a reply does not come back. This is called by the scheduler so the event is not pending anymore when we are called.
Definition at line 11663 of file chan_sip.c.
References __sip_pretend_ack(), ast_dnsmgr_refresh(), ast_log(), sip_registry::call, dialog_unref(), sip_registry::dnsmgr, EVENT_FLAG_SYSTEM, sip_registry::hostname, LOG_NOTICE, manager_event, pvt_set_needdestroy(), REG_STATE_FAILED, REG_STATE_UNREGISTERED, sip_registry::regattempts, sip_pvt::registry, registry_unref(), sip_registry::regstate, regstate2str(), sip_pvt_lock, sip_pvt_unlock, SIP_REGISTER, sip_registry::timeout, transmit_register(), and sip_registry::username.
Referenced by sip_show_sched(), and transmit_register().
11664 { 11665 11666 /* if we are here, our registration timed out, so we'll just do it over */ 11667 struct sip_registry *r = (struct sip_registry *)data; /* the ref count should have been bumped when the sched item was added */ 11668 struct sip_pvt *p; 11669 int res; 11670 11671 /* if we couldn't get a reference to the registry object, punt */ 11672 if (!r) 11673 return 0; 11674 11675 if (r->dnsmgr) { 11676 /* If the registration has timed out, maybe the IP changed. Force a refresh. */ 11677 ast_dnsmgr_refresh(r->dnsmgr); 11678 } 11679 11680 ast_log(LOG_NOTICE, " -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts); 11681 /* If the initial tranmission failed, we may not have an existing dialog, 11682 * so it is possible that r->call == NULL. 11683 * Otherwise destroy it, as we have a timeout so we don't want it. 11684 */ 11685 if (r->call) { 11686 /* Unlink us, destroy old call. Locking is not relevant here because all this happens 11687 in the single SIP manager thread. */ 11688 p = r->call; 11689 sip_pvt_lock(p); 11690 pvt_set_needdestroy(p, "registration timeout"); 11691 /* Pretend to ACK anything just in case */ 11692 __sip_pretend_ack(p); 11693 sip_pvt_unlock(p); 11694 11695 /* decouple the two objects */ 11696 /* p->registry == r, so r has 2 refs, and the unref won't take the object away */ 11697 if (p->registry) 11698 p->registry = registry_unref(p->registry, "p->registry unreffed"); 11699 r->call = dialog_unref(r->call, "unrefing r->call"); 11700 } 11701 /* If we have a limit, stop registration and give up */ 11702 r->timeout = -1; 11703 if (global_regattempts_max && r->regattempts > global_regattempts_max) { 11704 /* Ok, enough is enough. Don't try any more */ 11705 /* We could add an external notification here... 11706 steal it from app_voicemail :-) */ 11707 ast_log(LOG_NOTICE, " -- Giving up forever trying to register '%s@%s'\n", r->username, r->hostname); 11708 r->regstate = REG_STATE_FAILED; 11709 } else { 11710 r->regstate = REG_STATE_UNREGISTERED; 11711 res=transmit_register(r, SIP_REGISTER, NULL, NULL); 11712 } 11713 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate)); 11714 registry_unref(r, "unreffing registry_unref r"); 11715 return 0; 11716 }
| static int sip_register | ( | const char * | value, | |
| int | lineno | |||
| ) | [static] |
Parse register=> line in sip.conf and add to registry.
register => [peer?][transport://]user[][:secret[:authuser]][:port][/extension][~expiry] becomes userpart => [peer?][transport://]user[][:secret[:authuser]] hostpart => host[:port][/extension][~expiry]
pre1.peer => peer pre1.userpart => [transport://]user[][:secret[:authuser]] hostpart => host[:port][/extension][~expiry]
pre1.peer => peer pre2.transport = transport pre2.userpart => user[][:secret[:authuser]] hostpart => host[:port][/extension][~expiry]
pre1.peer => peer pre2.transport = transport user1.userpart => user[] user1.secret => secret user1.authuser => authuser hostpart => host[:port][/extension][~expiry]
pre1.peer => peer pre2.transport = transport user1.userpart => user[] user1.secret => secret user1.authuser => authuser host1.hostpart => host[:port][/extension] host1.expiry => [expiry]
pre1.peer => peer pre2.transport = transport user1.userpart => user[] user1.secret => secret user1.authuser => authuser host2.hostpart => host[:port] host2.extension => [extension] host1.expiry => [expiry]
pre1.peer => peer pre2.transport = transport user1.userpart => user[] user1.secret => secret user1.authuser => authuser host3.host => host host3.port => port host2.extension => extension host1.expiry => expiry
Definition at line 7582 of file chan_sip.c.
References AST_APP_ARG, ast_atomic_fetchadd_int(), ast_calloc, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_free, ast_log(), AST_NONSTANDARD_RAW_ARGS, ast_string_field_init, ast_string_field_set, ast_strip_quoted(), ast_strlen_zero(), ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, sip_registry::authuser, buf, sip_registry::callback, sip_registry::callid_valid, sip_registry::configured_expiry, sip_registry::expire, sip_registry::expiry, FALSE, hostname, INITIAL_CSEQ, LOG_ERROR, LOG_NOTICE, LOG_WARNING, sip_registry::ocseq, sip_registry::peername, port_str2int(), sip_registry::portno, sip_registry::refresh, registry_unref(), regl, S_OR, secret, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, STANDARD_SIP_PORT, STANDARD_TLS_PORT, sip_registry::timeout, sip_registry::transport, and sip_registry::username.
Referenced by build_peer(), and reload_config().
07583 { 07584 struct sip_registry *reg; 07585 int portnum = 0; 07586 enum sip_transport transport = SIP_TRANSPORT_UDP; 07587 char buf[256] = ""; 07588 char *userpart = NULL, *hostpart = NULL; 07589 /* register => [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] */ 07590 AST_DECLARE_APP_ARGS(pre1, 07591 AST_APP_ARG(peer); 07592 AST_APP_ARG(userpart); 07593 ); 07594 AST_DECLARE_APP_ARGS(pre2, 07595 AST_APP_ARG(transport); 07596 AST_APP_ARG(blank); 07597 AST_APP_ARG(userpart); 07598 ); 07599 AST_DECLARE_APP_ARGS(user1, 07600 AST_APP_ARG(userpart); 07601 AST_APP_ARG(secret); 07602 AST_APP_ARG(authuser); 07603 ); 07604 AST_DECLARE_APP_ARGS(host1, 07605 AST_APP_ARG(hostpart); 07606 AST_APP_ARG(expiry); 07607 ); 07608 AST_DECLARE_APP_ARGS(host2, 07609 AST_APP_ARG(hostpart); 07610 AST_APP_ARG(extension); 07611 ); 07612 AST_DECLARE_APP_ARGS(host3, 07613 AST_APP_ARG(host); 07614 AST_APP_ARG(port); 07615 ); 07616 07617 if (!value) 07618 return -1; 07619 ast_copy_string(buf, value, sizeof(buf)); 07620 07621 /*! register => [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] 07622 * becomes 07623 * userpart => [peer?][transport://]user[@domain][:secret[:authuser]] 07624 * hostpart => host[:port][/extension][~expiry] 07625 */ 07626 if ((hostpart = strrchr(buf, '@'))) { 07627 *hostpart++ = '\0'; 07628 userpart = buf; 07629 } 07630 07631 if (ast_strlen_zero(userpart) || ast_strlen_zero(hostpart)) { 07632 ast_log(LOG_WARNING, "Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno); 07633 return -1; 07634 } 07635 07636 /*! 07637 * pre1.peer => peer 07638 * pre1.userpart => [transport://]user[@domain][:secret[:authuser]] 07639 * hostpart => host[:port][/extension][~expiry] 07640 */ 07641 AST_NONSTANDARD_RAW_ARGS(pre1, userpart, '?'); 07642 if (ast_strlen_zero(pre1.userpart)) { 07643 pre1.userpart = pre1.peer; 07644 pre1.peer = NULL; 07645 } 07646 07647 /*! 07648 * pre1.peer => peer 07649 * pre2.transport = transport 07650 * pre2.userpart => user[@domain][:secret[:authuser]] 07651 * hostpart => host[:port][/extension][~expiry] 07652 */ 07653 AST_NONSTANDARD_RAW_ARGS(pre2, pre1.userpart, '/'); 07654 if (ast_strlen_zero(pre2.userpart)) { 07655 pre2.userpart = pre2.transport; 07656 pre2.transport = NULL; 07657 } else { 07658 pre2.transport[strlen(pre2.transport) - 1] = '\0'; /* Remove trailing : */ 07659 } 07660 07661 if (!ast_strlen_zero(pre2.blank)) { 07662 ast_log(LOG_WARNING, "Format for registration is [peer?][transport://]user[@domain][:secret[:authuser]]@host[:port][/extension][~expiry] at line %d\n", lineno); 07663 return -1; 07664 } 07665 07666 /*! 07667 * pre1.peer => peer 07668 * pre2.transport = transport 07669 * user1.userpart => user[@domain] 07670 * user1.secret => secret 07671 * user1.authuser => authuser 07672 * hostpart => host[:port][/extension][~expiry] 07673 */ 07674 AST_NONSTANDARD_RAW_ARGS(user1, pre2.userpart, ':'); 07675 07676 /*! 07677 * pre1.peer => peer 07678 * pre2.transport = transport 07679 * user1.userpart => user[@domain] 07680 * user1.secret => secret 07681 * user1.authuser => authuser 07682 * host1.hostpart => host[:port][/extension] 07683 * host1.expiry => [expiry] 07684 */ 07685 AST_NONSTANDARD_RAW_ARGS(host1, hostpart, '~'); 07686 07687 /*! 07688 * pre1.peer => peer 07689 * pre2.transport = transport 07690 * user1.userpart => user[@domain] 07691 * user1.secret => secret 07692 * user1.authuser => authuser 07693 * host2.hostpart => host[:port] 07694 * host2.extension => [extension] 07695 * host1.expiry => [expiry] 07696 */ 07697 AST_NONSTANDARD_RAW_ARGS(host2, host1.hostpart, '/'); 07698 07699 /*! 07700 * pre1.peer => peer 07701 * pre2.transport = transport 07702 * user1.userpart => user[@domain] 07703 * user1.secret => secret 07704 * user1.authuser => authuser 07705 * host3.host => host 07706 * host3.port => port 07707 * host2.extension => extension 07708 * host1.expiry => expiry 07709 */ 07710 AST_NONSTANDARD_RAW_ARGS(host3, host2.hostpart, ':'); 07711 07712 if (host3.port) { 07713 if (!(portnum = port_str2int(host3.port, 0))) { 07714 ast_log(LOG_NOTICE, "'%s' is not a valid port number on line %d of sip.conf. using default.\n", host3.port, lineno); 07715 } 07716 } 07717 07718 /* set transport type */ 07719 if (!pre2.transport) { 07720 transport = SIP_TRANSPORT_UDP; 07721 } else if (!strncasecmp(pre2.transport, "tcp", 3)) { 07722 transport = SIP_TRANSPORT_TCP; 07723 } else if (!strncasecmp(pre2.transport, "tls", 3)) { 07724 transport = SIP_TRANSPORT_TLS; 07725 } else if (!strncasecmp(pre2.transport, "udp", 3)) { 07726 transport = SIP_TRANSPORT_UDP; 07727 } else { 07728 transport = SIP_TRANSPORT_UDP; 07729 ast_log(LOG_NOTICE, "'%.3s' is not a valid transport type on line %d of sip.conf. defaulting to udp.\n", pre2.transport, lineno); 07730 } 07731 07732 /* if no portnum specified, set default for transport */ 07733 if (!portnum) { 07734 if (transport == SIP_TRANSPORT_TLS) { 07735 portnum = STANDARD_TLS_PORT; 07736 } else { 07737 portnum = STANDARD_SIP_PORT; 07738 } 07739 } 07740 07741 if (!(reg = ast_calloc(1, sizeof(*reg)))) { 07742 ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n"); 07743 return -1; 07744 } 07745 07746 if (ast_string_field_init(reg, 256)) { 07747 ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry strings\n"); 07748 ast_free(reg); 07749 return -1; 07750 } 07751 07752 ast_atomic_fetchadd_int(®objs, 1); 07753 ASTOBJ_INIT(reg); 07754 ast_string_field_set(reg, callback, ast_strip_quoted(S_OR(host2.extension, "s"), "\"", "\"")); 07755 ast_string_field_set(reg, username, ast_strip_quoted(S_OR(user1.userpart, ""), "\"", "\"")); 07756 ast_string_field_set(reg, hostname, ast_strip_quoted(S_OR(host3.host, ""), "\"", "\"")); 07757 ast_string_field_set(reg, authuser, ast_strip_quoted(S_OR(user1.authuser, ""), "\"", "\"")); 07758 ast_string_field_set(reg, secret, ast_strip_quoted(S_OR(user1.secret, ""), "\"", "\"")); 07759 ast_string_field_set(reg, peername, ast_strip_quoted(S_OR(pre1.peer, ""), "\"", "\"")); 07760 07761 reg->transport = transport; 07762 reg->timeout = reg->expire = -1; 07763 reg->refresh = reg->expiry = reg->configured_expiry = (host1.expiry ? atoi(ast_strip_quoted(host1.expiry, "\"", "\"")) : default_expiry); 07764 reg->portno = portnum; 07765 reg->callid_valid = FALSE; 07766 reg->ocseq = INITIAL_CSEQ; 07767 ASTOBJ_CONTAINER_LINK(®l, reg); /* Add the new registry entry to the list */ 07768 registry_unref(reg, "unref the reg pointer"); /* release the reference given by ASTOBJ_INIT. The container has another reference */ 07769 return 0; 07770 }
| static void sip_registry_destroy | ( | struct sip_registry * | reg | ) | [static] |
Destroy registry object Objects created with the register= statement in static configuration.
Definition at line 5535 of file chan_sip.c.
References ast_atomic_fetchadd_int(), ast_debug, ast_dnsmgr_release(), ast_free, AST_SCHED_DEL, ast_string_field_free_memory, sip_registry::call, dialog_unlink_all(), dialog_unref(), sip_registry::dnsmgr, sip_registry::expire, sip_registry::hostname, sip_pvt::registry, registry_unref(), sip_registry::timeout, TRUE, and sip_registry::username.
Referenced by registry_unref(), reload_config(), and unload_module().
05536 { 05537 /* Really delete */ 05538 ast_debug(3, "Destroying registry entry for %s@%s\n", reg->username, reg->hostname); 05539 05540 if (reg->call) { 05541 /* Clear registry before destroying to ensure 05542 we don't get reentered trying to grab the registry lock */ 05543 reg->call->registry = registry_unref(reg->call->registry, "destroy reg->call->registry"); 05544 ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname); 05545 dialog_unlink_all(reg->call, TRUE, TRUE); 05546 reg->call = dialog_unref(reg->call, "unref reg->call"); 05547 /* reg->call = sip_destroy(reg->call); */ 05548 } 05549 AST_SCHED_DEL(sched, reg->expire); 05550 AST_SCHED_DEL(sched, reg->timeout); 05551 05552 ast_string_field_free_memory(reg); 05553 ast_atomic_fetchadd_int(®objs, -1); 05554 ast_dnsmgr_release(reg->dnsmgr); 05555 ast_free(reg); 05556 }
| static int sip_reinvite_retry | ( | const void * | data | ) | [static] |
Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. Called from the scheduler.
Definition at line 17776 of file chan_sip.c.
References ast_channel_trylock, ast_channel_unlock, ast_set_flag, check_pendings(), dialog_unref(), sip_pvt::flags, sip_pvt::owner, SIP_NEEDREINVITE, sip_pvt_lock, sip_pvt_unlock, and sip_pvt::waitid.
Referenced by handle_response_invite(), and sip_show_sched().
17777 { 17778 struct sip_pvt *p = (struct sip_pvt *) data; 17779 struct ast_channel *owner; 17780 17781 sip_pvt_lock(p); /* called from schedule thread which requires a lock */ 17782 while ((owner = p->owner) && ast_channel_trylock(owner)) { 17783 sip_pvt_unlock(p); 17784 usleep(1); 17785 sip_pvt_lock(p); 17786 } 17787 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 17788 p->waitid = -1; 17789 check_pendings(p); 17790 sip_pvt_unlock(p); 17791 if (owner) { 17792 ast_channel_unlock(owner); 17793 } 17794 dialog_unref(p, "unref the dialog ptr from sip_reinvite_retry, because it held a dialog ptr"); 17795 return 0; 17796 }
| static char * sip_reload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Force reload of module from cli.
Definition at line 25965 of file chan_sip.c.
References ast_mutex_lock(), ast_mutex_unlock(), ast_verbose, CHANNEL_CLI_RELOAD, CHANNEL_MODULE_RELOAD, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, restart_monitor(), sip_reload_lock, TRUE, and ast_cli_entry::usage.
Referenced by reload().
25966 { 25967 25968 switch (cmd) { 25969 case CLI_INIT: 25970 e->command = "sip reload"; 25971 e->usage = 25972 "Usage: sip reload\n" 25973 " Reloads SIP configuration from sip.conf\n"; 25974 return NULL; 25975 case CLI_GENERATE: 25976 return NULL; 25977 } 25978 25979 ast_mutex_lock(&sip_reload_lock); 25980 if (sip_reloading) 25981 ast_verbose("Previous SIP reload not yet done\n"); 25982 else { 25983 sip_reloading = TRUE; 25984 sip_reloadreason = (a && a->fd) ? CHANNEL_CLI_RELOAD : CHANNEL_MODULE_RELOAD; 25985 } 25986 ast_mutex_unlock(&sip_reload_lock); 25987 restart_monitor(); 25988 25989 return CLI_SUCCESS; 25990 }
| static int sip_removeheader | ( | struct ast_channel * | chan, | |
| void * | data | |||
| ) | [static] |
Remove SIP headers added previously with SipAddHeader application.
Definition at line 25770 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_strlen_zero(), ast_var_delete(), ast_var_name(), ast_var_value(), inbuf(), LOG_DEBUG, and ast_channel::varshead.
Referenced by load_module().
25771 { 25772 struct ast_var_t *newvariable; 25773 struct varshead *headp; 25774 int removeall = 0; 25775 char *inbuf = (char *) data; 25776 25777 if (ast_strlen_zero(inbuf)) { 25778 removeall = 1; 25779 } 25780 ast_channel_lock(chan); 25781 25782 headp=&chan->varshead; 25783 AST_LIST_TRAVERSE_SAFE_BEGIN (headp, newvariable, entries) { 25784 if (strncasecmp(ast_var_name(newvariable), "SIPADDHEADER", strlen("SIPADDHEADER")) == 0) { 25785 if (removeall || (!strncasecmp(ast_var_value(newvariable),inbuf,strlen(inbuf)))) { 25786 if (sipdebug) 25787 ast_log(LOG_DEBUG,"removing SIP Header \"%s\" as %s\n", 25788 ast_var_value(newvariable), 25789 ast_var_name(newvariable)); 25790 AST_LIST_REMOVE_CURRENT(entries); 25791 ast_var_delete(newvariable); 25792 } 25793 } 25794 } 25795 AST_LIST_TRAVERSE_SAFE_END; 25796 25797 ast_channel_unlock(chan); 25798 return 0; 25799 }
| static struct ast_channel * sip_request_call | ( | const char * | type, | |
| int | format, | |||
| void * | data, | |||
| int * | cause | |||
| ) | [static, read] |
PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here.
* SIP Dial string syntax * SIP/exten@host!dnid * or SIP/host/exten!dnid * or SIP/host!dnid *
Definition at line 23319 of file chan_sip.c.
References ao2_t_link, ao2_t_unlink, ast_calloc, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNREGISTERED, ast_copy_string(), ast_debug, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_sip_ouraddrfor(), AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), ast_update_use_count(), build_callid_pvt(), build_via(), sip_settings::callevents, sip_pvt::callid, sip_pvt::capability, create_addr(), dialog_unlink_all(), dialog_unref(), EVENT_FLAG_SYSTEM, ext, sip_pvt::fullcontact, sip_pvt::jointcapability, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, ast_channel::name, sip_pvt::options, sip_pvt::ourip, sip_pvt::outgoing_call, sip_pvt::owner, sip_pvt::peername, sip_pvt::prefcodec, restart_monitor(), sip_pvt::sa, secret, set_socket_transport(), sip_alloc(), sip_cfg, SIP_INVITE, sip_new(), sip_pvt_lock, sip_pvt_unlock, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, SIP_TRANSPORT_UDP, sip_pvt::socket, and TRUE.
23320 { 23321 struct sip_pvt *p; 23322 struct ast_channel *tmpc = NULL; 23323 char *ext = NULL, *host; 23324 char tmp[256]; 23325 char *dest = data; 23326 char *dnid; 23327 char *secret = NULL; 23328 char *md5secret = NULL; 23329 char *authname = NULL; 23330 char *trans = NULL; 23331 enum sip_transport transport = 0; 23332 int oldformat = format; 23333 23334 /* mask request with some set of allowed formats. 23335 * XXX this needs to be fixed. 23336 * The original code uses AST_FORMAT_AUDIO_MASK, but it is 23337 * unclear what to use here. We have global_capabilities, which is 23338 * configured from sip.conf, and sip_tech.capabilities, which is 23339 * hardwired to all audio formats. 23340 */ 23341 format &= AST_FORMAT_AUDIO_MASK; 23342 if (!format) { 23343 ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format %s while capability is %s\n", ast_getformatname(oldformat), ast_getformatname(global_capability)); 23344 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; /* Can't find codec to connect to host */ 23345 return NULL; 23346 } 23347 ast_debug(1, "Asked to create a SIP channel with formats: %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), oldformat)); 23348 23349 if (!(p = sip_alloc(NULL, NULL, 0, SIP_INVITE, NULL))) { 23350 ast_log(LOG_ERROR, "Unable to build sip pvt data for '%s' (Out of memory or socket error)\n", dest); 23351 *cause = AST_CAUSE_SWITCH_CONGESTION; 23352 return NULL; 23353 } 23354 23355 p->outgoing_call = TRUE; 23356 23357 if (!(p->options = ast_calloc(1, sizeof(*p->options)))) { 23358 dialog_unlink_all(p, TRUE, TRUE); 23359 dialog_unref(p, "unref dialog p from mem fail"); 23360 /* sip_destroy(p); */ 23361 ast_log(LOG_ERROR, "Unable to build option SIP data structure - Out of memory\n"); 23362 *cause = AST_CAUSE_SWITCH_CONGESTION; 23363 return NULL; 23364 } 23365 23366 /* Save the destination, the SIP dial string */ 23367 ast_copy_string(tmp, dest, sizeof(tmp)); 23368 23369 23370 /* Find DNID and take it away */ 23371 dnid = strchr(tmp, '!'); 23372 if (dnid != NULL) { 23373 *dnid++ = '\0'; 23374 ast_string_field_set(p, todnid, dnid); 23375 } 23376 23377 /* Find at sign - @ */ 23378 host = strchr(tmp, '@'); 23379 if (host) { 23380 *host++ = '\0'; 23381 ext = tmp; 23382 secret = strchr(ext, ':'); 23383 } 23384 if (secret) { 23385 *secret++ = '\0'; 23386 md5secret = strchr(secret, ':'); 23387 } 23388 if (md5secret) { 23389 *md5secret++ = '\0'; 23390 authname = strchr(md5secret, ':'); 23391 } 23392 if (authname) { 23393 *authname++ = '\0'; 23394 trans = strchr(authname, ':'); 23395 } 23396 if (trans) { 23397 *trans++ = '\0'; 23398 if (!strcasecmp(trans, "tcp")) 23399 transport = SIP_TRANSPORT_TCP; 23400 else if (!strcasecmp(trans, "tls")) 23401 transport = SIP_TRANSPORT_TLS; 23402 else { 23403 if (strcasecmp(trans, "udp")) 23404 ast_log(LOG_WARNING, "'%s' is not a valid transport option to Dial() for SIP calls, using udp by default.\n", trans); 23405 transport = SIP_TRANSPORT_UDP; 23406 } 23407 } else { /* use default */ 23408 transport = SIP_TRANSPORT_UDP; 23409 } 23410 23411 if (!host) { 23412 ext = strchr(tmp, '/'); 23413 if (ext) 23414 *ext++ = '\0'; 23415 host = tmp; 23416 } 23417 23418 set_socket_transport(&p->socket, transport); 23419 23420 /* We now have 23421 host = peer name, DNS host name or DNS domain (for SRV) 23422 ext = extension (user part of URI) 23423 dnid = destination of the call (applies to the To: header) 23424 */ 23425 if (create_addr(p, host, NULL, 1)) { 23426 *cause = AST_CAUSE_UNREGISTERED; 23427 ast_debug(3, "Cant create SIP call - target device not registered\n"); 23428 dialog_unlink_all(p, TRUE, TRUE); 23429 dialog_unref(p, "unref dialog p UNREGISTERED"); 23430 /* sip_destroy(p); */ 23431 return NULL; 23432 } 23433 if (ast_strlen_zero(p->peername) && ext) 23434 ast_string_field_set(p, peername, ext); 23435 /* Recalculate our side, and recalculate Call ID */ 23436 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 23437 build_via(p); 23438 ao2_t_unlink(dialogs, p, "About to change the callid -- remove the old name"); 23439 build_callid_pvt(p); 23440 ao2_t_link(dialogs, p, "Linking in under new name"); 23441 23442 /* We have an extension to call, don't use the full contact here */ 23443 /* This to enable dialing registered peers with extension dialling, 23444 like SIP/peername/extension 23445 SIP/peername will still use the full contact 23446 */ 23447 if (ext) { 23448 ast_string_field_set(p, username, ext); 23449 ast_string_field_set(p, fullcontact, NULL); 23450 } 23451 if (secret && !ast_strlen_zero(secret)) 23452 ast_string_field_set(p, peersecret, secret); 23453 23454 if (md5secret && !ast_strlen_zero(md5secret)) 23455 ast_string_field_set(p, peermd5secret, md5secret); 23456 23457 if (authname && !ast_strlen_zero(authname)) 23458 ast_string_field_set(p, authname, authname); 23459 #if 0 23460 printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host); 23461 #endif 23462 p->prefcodec = oldformat; /* Format for this call */ 23463 p->jointcapability = oldformat & p->capability; 23464 sip_pvt_lock(p); 23465 tmpc = sip_new(p, AST_STATE_DOWN, host); /* Place the call */ 23466 if (sip_cfg.callevents) 23467 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 23468 "Channel: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\nPeername: %s\r\n", 23469 p->owner? p->owner->name : "", "SIP", p->callid, p->fullcontact, p->peername); 23470 sip_pvt_unlock(p); 23471 if (!tmpc) { 23472 dialog_unlink_all(p, TRUE, TRUE); 23473 /* sip_destroy(p); */ 23474 } 23475 dialog_unref(p, "toss pvt ptr at end of sip_request_call"); 23476 ast_update_use_count(); 23477 restart_monitor(); 23478 return tmpc; 23479 }
| static int sip_reregister | ( | const void * | data | ) | [static] |
Update registration with SIP Proxy. Called from the scheduler when the previous registration expires, so we don't have to cancel the pending event. We assume the reference so the sip_registry is valid, since it is stored in the scheduled event anyways.
Definition at line 11625 of file chan_sip.c.
References __sip_do_register(), append_history, ast_log(), sip_registry::call, sip_registry::configured_expiry, sip_pvt::do_history, sip_registry::expire, sip_registry::expiry, sip_registry::hostname, LOG_NOTICE, registry_unref(), and sip_registry::username.
Referenced by handle_response_register(), sip_send_all_registers(), and sip_show_sched().
11626 { 11627 /* if we are here, we know that we need to reregister. */ 11628 struct sip_registry *r= (struct sip_registry *) data; 11629 11630 /* if we couldn't get a reference to the registry object, punt */ 11631 if (!r) 11632 return 0; 11633 11634 if (r->call && r->call->do_history) 11635 append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname); 11636 /* Since registry's are only added/removed by the the monitor thread, this 11637 may be overkill to reference/dereference at all here */ 11638 if (sipdebug) 11639 ast_log(LOG_NOTICE, " -- Re-registration for %s@%s\n", r->username, r->hostname); 11640 11641 r->expire = -1; 11642 r->expiry = r->configured_expiry; 11643 __sip_do_register(r); 11644 registry_unref(r, "unref the re-register scheduled event"); 11645 return 0; 11646 }
| static struct ast_frame * sip_rtp_read | ( | struct ast_channel * | ast, | |
| struct sip_pvt * | p, | |||
| int * | faxdetect | |||
| ) | [static, read] |
Read RTP from network.
Definition at line 7059 of file chan_sip.c.
References ast_debug, ast_dsp_free(), ast_dsp_process(), ast_dsp_set_features(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_getformatname(), ast_log(), ast_null_frame, ast_rtcp_read(), ast_rtp_read(), ast_set_read_format(), ast_set_write_format(), ast_test_flag, ast_udptl_read(), ast_verbose, ast_frame::data, ast_frame::datalen, sip_pvt::dsp, DSP_FEATURE_DIGIT_DETECT, f, ast_channel::fdno, sip_pvt::flags, ast_frame::frametype, sip_pvt::jointcapability, LOG_DEBUG, ast_channel::name, ast_channel::nativeformats, option_debug, sip_pvt::owner, ast_frame::ptr, ast_channel::readformat, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, SIP_PAGE2_FAX_DETECT, ast_frame::subclass, sip_pvt::trtp, sip_pvt::udptl, sip_pvt::vrtp, and ast_channel::writeformat.
Referenced by sip_read().
07060 { 07061 /* Retrieve audio/etc from channel. Assumes p->lock is already held. */ 07062 struct ast_frame *f; 07063 07064 if (!p->rtp) { 07065 /* We have no RTP allocated for this channel */ 07066 return &ast_null_frame; 07067 } 07068 07069 switch(ast->fdno) { 07070 case 0: 07071 f = ast_rtp_read(p->rtp); /* RTP Audio */ 07072 break; 07073 case 1: 07074 f = ast_rtcp_read(p->rtp); /* RTCP Control Channel */ 07075 break; 07076 case 2: 07077 f = ast_rtp_read(p->vrtp); /* RTP Video */ 07078 break; 07079 case 3: 07080 f = ast_rtcp_read(p->vrtp); /* RTCP Control Channel for video */ 07081 break; 07082 case 4: 07083 f = ast_rtp_read(p->trtp); /* RTP Text */ 07084 if (sipdebug_text) { 07085 int i; 07086 unsigned char* arr = f->data.ptr; 07087 for (i=0; i < f->datalen; i++) 07088 ast_verbose("%c", (arr[i] > ' ' && arr[i] < '}') ? arr[i] : '.'); 07089 ast_verbose(" -> "); 07090 for (i=0; i < f->datalen; i++) 07091 ast_verbose("%02X ", arr[i]); 07092 ast_verbose("\n"); 07093 } 07094 break; 07095 case 5: 07096 f = ast_udptl_read(p->udptl); /* UDPTL for T.38 */ 07097 break; 07098 default: 07099 f = &ast_null_frame; 07100 } 07101 /* Don't forward RFC2833 if we're not supposed to */ 07102 if (f && (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && 07103 (ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_RFC2833)) { 07104 ast_debug(1, "Ignoring DTMF (%c) RTP frame because dtmfmode is not RFC2833\n", f->subclass); 07105 return &ast_null_frame; 07106 } 07107 07108 /* We already hold the channel lock */ 07109 if (!p->owner || (f && f->frametype != AST_FRAME_VOICE)) 07110 return f; 07111 07112 if (f && f->subclass != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) { 07113 if (!(f->subclass & p->jointcapability)) { 07114 ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n", 07115 ast_getformatname(f->subclass), p->owner->name); 07116 return &ast_null_frame; 07117 } 07118 ast_debug(1, "Oooh, format changed to %d %s\n", 07119 f->subclass, ast_getformatname(f->subclass)); 07120 p->owner->nativeformats = (p->owner->nativeformats & (AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK)) | f->subclass; 07121 ast_set_read_format(p->owner, p->owner->readformat); 07122 ast_set_write_format(p->owner, p->owner->writeformat); 07123 } 07124 07125 if (f && ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT)) && p->dsp) { 07126 f = ast_dsp_process(p->owner, p->dsp, f); 07127 if (f && f->frametype == AST_FRAME_DTMF) { 07128 if (f->subclass == 'f') { 07129 if (option_debug) 07130 ast_log(LOG_DEBUG, "Fax CNG detected on %s\n", ast->name); 07131 *faxdetect = 1; 07132 /* If we only needed this DSP for fax detection purposes we can just drop it now */ 07133 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) { 07134 ast_dsp_set_features(p->dsp, DSP_FEATURE_DIGIT_DETECT); 07135 } else { 07136 ast_dsp_free(p->dsp); 07137 p->dsp = NULL; 07138 } 07139 } else { 07140 ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass); 07141 } 07142 } 07143 } 07144 07145 return f; 07146 }
| static void sip_scheddestroy | ( | struct sip_pvt * | p, | |
| int | ms | |||
| ) | [static] |
Schedule destruction of SIP dialog.
Definition at line 4051 of file chan_sip.c.
References __sip_autodestruct(), append_history, ast_log(), ast_sched_add(), ast_verbose, sip_pvt::autokillid, sip_pvt::callid, dialog_ref(), sip_pvt::do_history, LOG_WARNING, sip_pvt::method, sip_cancel_destroy(), sip_debug_test_pvt(), sip_methods, sip_st_dlg::st_active, sip_st_dlg::st_schedid, sip_pvt::stimer, stop_session_timer(), cfsip_methods::text, sip_pvt::timer_b, sip_pvt::timer_t1, and TRUE.
Referenced by __sip_autodestruct(), auto_congest(), cb_extensionstate(), check_auth(), check_pendings(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_register(), handle_request_subscribe(), handle_response_invite(), handle_response_register(), manager_sipnotify(), receive_message(), sip_cli_notify(), sip_hangup(), sip_send_mwi_to_peer(), sip_sipredirect(), and transmit_fake_auth_response().
04052 { 04053 if (ms < 0) { 04054 if (p->timer_t1 == 0) { 04055 p->timer_t1 = global_t1; /* Set timer T1 if not set (RFC 3261) */ 04056 p->timer_b = global_timer_b; /* Set timer B if not set (RFC 3261) */ 04057 } 04058 ms = p->timer_t1 * 64; 04059 } 04060 if (sip_debug_test_pvt(p)) 04061 ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text); 04062 if (sip_cancel_destroy(p)) 04063 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 04064 04065 if (p->do_history) 04066 append_history(p, "SchedDestroy", "%d ms", ms); 04067 p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p, "setting ref as passing into ast_sched_add for __sip_autodestruct")); 04068 04069 if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_schedid > 0) 04070 stop_session_timer(p); 04071 }
| static void sip_send_all_mwi_subscriptions | ( | void | ) | [static] |
Send all MWI subscriptions.
Definition at line 25921 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_REF, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, sip_subscribe_mwi_destroy(), sip_subscribe_mwi_do(), and submwil.
Referenced by load_module(), and sip_do_reload().
25922 { 25923 ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do { 25924 ASTOBJ_WRLOCK(iterator); 25925 AST_SCHED_DEL(sched, iterator->resub); 25926 if ((iterator->resub = ast_sched_add(sched, 1, sip_subscribe_mwi_do, ASTOBJ_REF(iterator))) < 0) { 25927 ASTOBJ_UNREF(iterator, sip_subscribe_mwi_destroy); 25928 } 25929 ASTOBJ_UNLOCK(iterator); 25930 } while (0)); 25931 }
| static void sip_send_all_registers | ( | void | ) | [static] |
Send all known registrations.
Definition at line 25898 of file chan_sip.c.
References AST_SCHED_REPLACE_UNREF, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, registry_addref(), registry_unref(), regl, and sip_reregister().
Referenced by load_module(), and sip_do_reload().
25899 { 25900 int ms; 25901 int regspacing; 25902 if (!regobjs) 25903 return; 25904 regspacing = default_expiry * 1000/regobjs; 25905 if (regspacing > 100) 25906 regspacing = 100; 25907 ms = regspacing; 25908 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 25909 ASTOBJ_WRLOCK(iterator); 25910 ms += regspacing; 25911 AST_SCHED_REPLACE_UNREF(iterator->expire, sched, ms, sip_reregister, iterator, 25912 registry_unref(_data, "REPLACE sched del decs the refcount"), 25913 registry_unref(iterator, "REPLACE sched add failure decs the refcount"), 25914 registry_addref(iterator, "REPLACE sched add incs the refcount")); 25915 ASTOBJ_UNLOCK(iterator); 25916 } while (0) 25917 ); 25918 }
| static int sip_send_mwi_to_peer | ( | struct sip_peer * | peer, | |
| const struct ast_event * | event, | |||
| int | cache_only | |||
| ) | [static] |
Send message waiting indication to alert peer that they've got voicemail.
Definition at line 22528 of file chan_sip.c.
References sip_peer::addr, ao2_t_link, ao2_t_unlink, ast_app_inboxcount(), ast_event_get_ie_uint(), AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, ast_set_flag, ast_sip_ouraddrfor(), ast_str_alloca, ast_test_flag, build_callid_pvt(), build_via(), create_addr_from_peer(), sip_peer::defaddr, DEFAULT_TRANS_TIMEOUT, dialog_ref(), dialog_unlink_all(), dialog_unref(), sip_pvt::flags, sip_peer::flags, get_cached_mwi(), sip_peer::mwipvt, sip_pvt::ourip, peer_mailboxes_to_str(), sip_pvt::sa, set_socket_transport(), sip_alloc(), SIP_NOTIFY, SIP_OUTGOING, SIP_PAGE2_SUBSCRIBEMWIONLY, sip_scheddestroy(), sip_pvt::socket, transmit_notify_with_mwi(), TRUE, and sip_peer::vmexten.
Referenced by build_peer(), handle_request_subscribe(), and mwi_event_cb().
22529 { 22530 /* Called with peerl lock, but releases it */ 22531 struct sip_pvt *p; 22532 int newmsgs = 0, oldmsgs = 0; 22533 22534 if (ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY) && !peer->mwipvt) 22535 return 0; 22536 22537 /* Do we have an IP address? If not, skip this peer */ 22538 if (!peer->addr.sin_addr.s_addr && !peer->defaddr.sin_addr.s_addr) 22539 return 0; 22540 22541 if (event) { 22542 newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); 22543 oldmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS); 22544 } else if (!cache_only) { /* Fall back to manually checking the mailbox */ 22545 struct ast_str *mailbox_str = ast_str_alloca(512); 22546 peer_mailboxes_to_str(&mailbox_str, peer); 22547 ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs); 22548 } else { 22549 get_cached_mwi(peer, &newmsgs, &oldmsgs); 22550 } 22551 22552 if (peer->mwipvt) { 22553 /* Base message on subscription */ 22554 p = dialog_ref(peer->mwipvt, "sip_send_mwi_to_peer: Setting dialog ptr p from peer->mwipvt-- should this be done?"); 22555 } else { 22556 /* Build temporary dialog for this message */ 22557 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) 22558 return -1; 22559 /* If we don't set the socket type to 0, then create_addr_from_peer will fail immediately if the peer 22560 * uses any transport other than UDP. We set the type to 0 here and then let create_addr_from_peer copy 22561 * the peer's socket information to the sip_pvt we just allocated 22562 */ 22563 set_socket_transport(&p->socket, 0); 22564 if (create_addr_from_peer(p, peer)) { 22565 /* Maybe they're not registered, etc. */ 22566 dialog_unlink_all(p, TRUE, TRUE); 22567 dialog_unref(p, "unref dialog p just created via sip_alloc"); 22568 /* sip_destroy(p); */ 22569 return 0; 22570 } 22571 /* Recalculate our side, and recalculate Call ID */ 22572 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 22573 build_via(p); 22574 ao2_t_unlink(dialogs, p, "About to change the callid -- remove the old name"); 22575 build_callid_pvt(p); 22576 ao2_t_link(dialogs, p, "Linking in under new name"); 22577 /* Destroy this session after 32 secs */ 22578 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22579 } 22580 22581 /* Send MWI */ 22582 ast_set_flag(&p->flags[0], SIP_OUTGOING); 22583 /* the following will decrement the refcount on p as it finishes */ 22584 transmit_notify_with_mwi(p, newmsgs, oldmsgs, peer->vmexten); 22585 dialog_unref(p, "unref dialog ptr p just before it goes out of scope at the end of sip_send_mwi_to_peer."); 22586 return 0; 22587 }
| static int sip_senddigit_begin | ( | struct ast_channel * | ast, | |
| char | digit | |||
| ) | [static] |
Definition at line 6432 of file chan_sip.c.
References ast_rtp_senddigit_begin(), ast_test_flag, sip_pvt::flags, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_RFC2833, sip_pvt_lock, sip_pvt_unlock, and ast_channel::tech_pvt.
06433 { 06434 struct sip_pvt *p = ast->tech_pvt; 06435 int res = 0; 06436 06437 sip_pvt_lock(p); 06438 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 06439 case SIP_DTMF_INBAND: 06440 res = -1; /* Tell Asterisk to generate inband indications */ 06441 break; 06442 case SIP_DTMF_RFC2833: 06443 if (p->rtp) 06444 ast_rtp_senddigit_begin(p->rtp, digit); 06445 break; 06446 default: 06447 break; 06448 } 06449 sip_pvt_unlock(p); 06450 06451 return res; 06452 }
| static int sip_senddigit_end | ( | struct ast_channel * | ast, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Send DTMF character on SIP channel within one call, we're able to transmit in many methods simultaneously.
Definition at line 6456 of file chan_sip.c.
References ast_rtp_senddigit_end_with_duration(), ast_test_flag, sip_pvt::flags, sip_pvt::rtp, SIP_DTMF, SIP_DTMF_INBAND, SIP_DTMF_INFO, SIP_DTMF_RFC2833, SIP_DTMF_SHORTINFO, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and transmit_info_with_digit().
06457 { 06458 struct sip_pvt *p = ast->tech_pvt; 06459 int res = 0; 06460 06461 sip_pvt_lock(p); 06462 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 06463 case SIP_DTMF_INFO: 06464 case SIP_DTMF_SHORTINFO: 06465 transmit_info_with_digit(p, digit, duration); 06466 break; 06467 case SIP_DTMF_RFC2833: 06468 if (p->rtp) 06469 ast_rtp_senddigit_end_with_duration(p->rtp, digit, duration); 06470 break; 06471 case SIP_DTMF_INBAND: 06472 res = -1; /* Tell Asterisk to stop inband indications */ 06473 break; 06474 } 06475 sip_pvt_unlock(p); 06476 06477 return res; 06478 }
| static int sip_sendhtml | ( | struct ast_channel * | chan, | |
| int | subclass, | |||
| const char * | data, | |||
| int | datalen | |||
| ) | [static] |
Send message with Access-URL header, if this is an HTML URL only!
Definition at line 4534 of file chan_sip.c.
References ast_channel::_state, ast_debug, AST_HTML_URL, ast_log(), ast_set_flag, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_string_field_build, ast_test_flag, FALSE, sip_pvt::flags, sip_pvt::initreq, LOG_WARNING, sip_pvt::pendinginvite, sip_debug_test_pvt(), SIP_NEEDREINVITE, SIP_PENDINGBYE, ast_channel::tech_pvt, transmit_reinvite_with_sdp(), transmit_response(), and url.
04535 { 04536 struct sip_pvt *p = chan->tech_pvt; 04537 04538 if (subclass != AST_HTML_URL) 04539 return -1; 04540 04541 ast_string_field_build(p, url, "<%s>;mode=active", data); 04542 04543 if (sip_debug_test_pvt(p)) 04544 ast_debug(1, "Send URL %s, state = %d!\n", data, chan->_state); 04545 04546 switch (chan->_state) { 04547 case AST_STATE_RING: 04548 transmit_response(p, "100 Trying", &p->initreq); 04549 break; 04550 case AST_STATE_RINGING: 04551 transmit_response(p, "180 Ringing", &p->initreq); 04552 break; 04553 case AST_STATE_UP: 04554 if (!p->pendinginvite) { /* We are up, and have no outstanding invite */ 04555 transmit_reinvite_with_sdp(p, FALSE, FALSE); 04556 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 04557 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 04558 } 04559 break; 04560 default: 04561 ast_log(LOG_WARNING, "Don't know how to send URI when state is %d!\n", chan->_state); 04562 } 04563 04564 return 0; 04565 }
| static int sip_sendtext | ( | struct ast_channel * | ast, | |
| const char * | text | |||
| ) | [static] |
Send SIP MESSAGE text within a call Called from PBX core sendtext() application.
Definition at line 4575 of file chan_sip.c.
References ast_verbose, sip_request::debug, ast_channel::name, sip_debug_test_pvt(), ast_channel::tech_pvt, and transmit_message_with_text().
04576 { 04577 struct sip_pvt *p = ast->tech_pvt; 04578 int debug = sip_debug_test_pvt(p); 04579 04580 if (debug) 04581 ast_verbose("Sending text %s on %s\n", text, ast->name); 04582 if (!p) 04583 return -1; 04584 /* NOT ast_strlen_zero, because a zero-length message is specifically 04585 * allowed by RFC 3428 (See section 10, Examples) */ 04586 if (!text) 04587 return 0; 04588 if (debug) 04589 ast_verbose("Really sending text %s on %s\n", text, ast->name); 04590 transmit_message_with_text(p, text); 04591 return 0; 04592 }
| static char * sip_set_history | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Enable/Disable SIP History logging (CLI).
Definition at line 17169 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, FALSE, ast_cli_args::fd, TRUE, and ast_cli_entry::usage.
17170 { 17171 switch (cmd) { 17172 case CLI_INIT: 17173 e->command = "sip set history {on|off}"; 17174 e->usage = 17175 "Usage: sip set history {on|off}\n" 17176 " Enables/Disables recording of SIP dialog history for debugging purposes.\n" 17177 " Use 'sip show history' to view the history of a call number.\n"; 17178 return NULL; 17179 case CLI_GENERATE: 17180 return NULL; 17181 } 17182 17183 if (a->argc != e->args) 17184 return CLI_SHOWUSAGE; 17185 17186 if (!strncasecmp(a->argv[e->args - 1], "on", 2)) { 17187 recordhistory = TRUE; 17188 ast_cli(a->fd, "SIP History Recording Enabled (use 'sip show history')\n"); 17189 } else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) { 17190 recordhistory = FALSE; 17191 ast_cli(a->fd, "SIP History Recording Disabled\n"); 17192 } else { 17193 return CLI_SHOWUSAGE; 17194 } 17195 return CLI_SUCCESS; 17196 }
| static void sip_set_redirstr | ( | struct sip_pvt * | p, | |
| char * | reason | |||
| ) | [static] |
Translate referring cause.
Definition at line 13370 of file chan_sip.c.
References ast_string_field_set.
Referenced by get_rdnis().
13370 { 13371 13372 if (!strcmp(reason, "unknown")) { 13373 ast_string_field_set(p, redircause, "UNKNOWN"); 13374 } else if (!strcmp(reason, "user-busy")) { 13375 ast_string_field_set(p, redircause, "BUSY"); 13376 } else if (!strcmp(reason, "no-answer")) { 13377 ast_string_field_set(p, redircause, "NOANSWER"); 13378 } else if (!strcmp(reason, "unavailable")) { 13379 ast_string_field_set(p, redircause, "UNREACHABLE"); 13380 } else if (!strcmp(reason, "unconditional")) { 13381 ast_string_field_set(p, redircause, "UNCONDITIONAL"); 13382 } else if (!strcmp(reason, "time-of-day")) { 13383 ast_string_field_set(p, redircause, "UNKNOWN"); 13384 } else if (!strcmp(reason, "do-not-disturb")) { 13385 ast_string_field_set(p, redircause, "UNKNOWN"); 13386 } else if (!strcmp(reason, "deflection")) { 13387 ast_string_field_set(p, redircause, "UNKNOWN"); 13388 } else if (!strcmp(reason, "follow-me")) { 13389 ast_string_field_set(p, redircause, "UNKNOWN"); 13390 } else if (!strcmp(reason, "out-of-service")) { 13391 ast_string_field_set(p, redircause, "UNREACHABLE"); 13392 } else if (!strcmp(reason, "away")) { 13393 ast_string_field_set(p, redircause, "UNREACHABLE"); 13394 } else { 13395 ast_string_field_set(p, redircause, "UNKNOWN"); 13396 } 13397 }
| static int sip_set_rtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp * | rtp, | |||
| struct ast_rtp * | vrtp, | |||
| struct ast_rtp * | trtp, | |||
| int | codecs, | |||
| int | nat_active | |||
| ) | [static] |
Set the RTP peer for this call.
Definition at line 25598 of file chan_sip.c.
References ast_channel::_state, sip_pvt::alreadygone, append_history, ast_bridged_channel(), ast_debug, ast_inet_ntoa(), ast_rtp_get_peer(), ast_set_flag, AST_STATE_UP, ast_test_flag, sip_pvt::callid, sip_settings::directrtpsetup, sip_pvt::do_history, FALSE, sip_pvt::flags, sip_pvt::lastrtprx, sip_pvt::lastrtptx, sip_pvt::ourip, sip_pvt::pendinginvite, sip_pvt::redircodecs, sip_pvt::redirip, sip_cfg, SIP_DEFER_BYE_ON_TRANSFER, SIP_DIRECT_MEDIA_NAT, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_PENDINGBYE, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_reinvite_with_sdp(), sip_pvt::tredirip, and sip_pvt::vredirip.
Referenced by sip_fixup().
25599 { 25600 struct sip_pvt *p; 25601 int changed = 0; 25602 25603 p = chan->tech_pvt; 25604 if (!p) 25605 return -1; 25606 25607 /* Disable early RTP bridge */ 25608 if (!ast_bridged_channel(chan) && !sip_cfg.directrtpsetup) /* We are in early state */ 25609 return 0; 25610 25611 sip_pvt_lock(p); 25612 if (p->alreadygone) { 25613 /* If we're destroyed, don't bother */ 25614 sip_pvt_unlock(p); 25615 return 0; 25616 } 25617 25618 /* if this peer cannot handle reinvites of the media stream to devices 25619 that are known to be behind a NAT, then stop the process now 25620 */ 25621 if (nat_active && !ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA_NAT)) { 25622 sip_pvt_unlock(p); 25623 return 0; 25624 } 25625 25626 if (rtp) { 25627 changed |= ast_rtp_get_peer(rtp, &p->redirip); 25628 } else if (p->redirip.sin_addr.s_addr || ntohs(p->redirip.sin_port) != 0) { 25629 memset(&p->redirip, 0, sizeof(p->redirip)); 25630 changed = 1; 25631 } 25632 if (vrtp) { 25633 changed |= ast_rtp_get_peer(vrtp, &p->vredirip); 25634 } else if (p->vredirip.sin_addr.s_addr || ntohs(p->vredirip.sin_port) != 0) { 25635 memset(&p->vredirip, 0, sizeof(p->vredirip)); 25636 changed = 1; 25637 } 25638 if (trtp) { 25639 changed |= ast_rtp_get_peer(trtp, &p->tredirip); 25640 } else if (p->tredirip.sin_addr.s_addr || ntohs(p->tredirip.sin_port) != 0) { 25641 memset(&p->tredirip, 0, sizeof(p->tredirip)); 25642 changed = 1; 25643 } 25644 if (codecs && (p->redircodecs != codecs)) { 25645 p->redircodecs = codecs; 25646 changed = 1; 25647 } 25648 if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER) && !ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 25649 if (chan->_state != AST_STATE_UP) { /* We are in early state */ 25650 if (p->do_history) 25651 append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal."); 25652 ast_debug(1, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr)); 25653 } else if (!p->pendinginvite) { /* We are up, and have no outstanding invite */ 25654 ast_debug(3, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr)); 25655 transmit_reinvite_with_sdp(p, FALSE, FALSE); 25656 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 25657 ast_debug(3, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_inet_ntoa(rtp ? p->redirip.sin_addr : p->ourip.sin_addr)); 25658 /* We have a pending Invite. Send re-invite when we're done with the invite */ 25659 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 25660 } 25661 } 25662 /* Reset lastrtprx timer */ 25663 p->lastrtprx = p->lastrtptx = time(NULL); 25664 sip_pvt_unlock(p); 25665 return 0; 25666 }
| static int sip_set_udptl_peer | ( | struct ast_channel * | chan, | |
| struct ast_udptl * | udptl | |||
| ) | [static] |
Definition at line 25491 of file chan_sip.c.
References ast_debug, ast_inet_ntoa(), ast_set_flag, ast_test_flag, ast_udptl_get_peer(), sip_pvt::callid, FALSE, sip_pvt::flags, sip_pvt::lastrtprx, sip_pvt::lastrtptx, sip_pvt::ourip, sip_pvt::pendinginvite, SIP_GOTREFER, SIP_NEEDREINVITE, SIP_PENDINGBYE, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_reinvite_with_sdp(), TRUE, and sip_pvt::udptlredirip.
25492 { 25493 struct sip_pvt *p; 25494 25495 p = chan->tech_pvt; 25496 if (!p) 25497 return -1; 25498 sip_pvt_lock(p); 25499 if (udptl) 25500 ast_udptl_get_peer(udptl, &p->udptlredirip); 25501 else 25502 memset(&p->udptlredirip, 0, sizeof(p->udptlredirip)); 25503 if (!ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 25504 if (!p->pendinginvite) { 25505 ast_debug(3, "Sending reinvite on SIP '%s' - It's UDPTL soon redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(udptl ? p->udptlredirip.sin_addr : p->ourip.sin_addr), udptl ? ntohs(p->udptlredirip.sin_port) : 0); 25506 transmit_reinvite_with_sdp(p, TRUE, FALSE); 25507 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 25508 ast_debug(3, "Deferring reinvite on SIP '%s' - It's UDPTL will be redirected to IP %s:%d\n", p->callid, ast_inet_ntoa(udptl ? p->udptlredirip.sin_addr : p->ourip.sin_addr), udptl ? ntohs(p->udptlredirip.sin_port) : 0); 25509 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 25510 } 25511 } 25512 /* Reset lastrtprx timer */ 25513 p->lastrtprx = p->lastrtptx = time(NULL); 25514 sip_pvt_unlock(p); 25515 return 0; 25516 }
| static char * sip_show_channel | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show details of one active dialog.
Definition at line 16625 of file chan_sip.c.
References sip_pvt::allowtransfer, ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli_args::argv, ARRAY_LEN, ast_cli(), ast_getformatname_multiple(), ast_inet_ntoa(), ast_strlen_zero(), ast_test_flag, sip_pvt::callid, sip_pvt::capability, sip_pvt::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, cli_yesno(), ast_cli_entry::command, complete_sipch(), dtmfmode2str(), ast_cli_args::fd, sip_pvt::flags, sip_route::hop, cfsip_options::id, sip_pvt::jointcapability, sip_pvt::lastmsg, ast_cli_args::line, sip_pvt::maxcallbitrate, ast_cli_args::n, ast_channel::name, nat2str(), ast_channel::nativeformats, sip_pvt::needdestroy, sip_pvt::noncodeccapability, NONE, sip_pvt::ourip, sip_pvt::owner, sip_pvt::peercapability, sip_pvt::peername, ast_cli_args::pos, sip_pvt::recv, sip_pvt::redirip, sip_pvt::route, sip_pvt::sa, SIP_DTMF, SIP_NAT, sip_options, SIP_OUTGOING, SIP_PROMISCREDIR, sip_pvt_lock, sip_pvt_unlock, SIPBUFSIZE, sip_pvt::sipoptions, sip_st_dlg::st_active, sip_st_dlg::st_active_peer_ua, sip_st_dlg::st_cached_max_se, sip_st_dlg::st_cached_min_se, sip_st_dlg::st_cached_mode, sip_st_dlg::st_cached_ref, sip_st_dlg::st_expirys, sip_st_dlg::st_interval, sip_st_dlg::st_ref, sip_st_dlg::st_schedid, sip_pvt::stimer, stmode2str(), strefresher2str(), sip_pvt::subscribed, subscription_type2str(), sip_pvt::tag, cfsip_options::text, sip_pvt::theirtag, transfermode2str(), TRUE, sip_pvt::udptl, sip_pvt::uri, ast_cli_entry::usage, sip_pvt::useragent, sip_pvt::username, sip_pvt::vrtp, and ast_cli_args::word.
16626 { 16627 struct sip_pvt *cur; 16628 size_t len; 16629 int found = 0; 16630 struct ao2_iterator i; 16631 16632 switch (cmd) { 16633 case CLI_INIT: 16634 e->command = "sip show channel"; 16635 e->usage = 16636 "Usage: sip show channel <call-id>\n" 16637 " Provides detailed status on a given SIP dialog (identified by SIP call-id).\n"; 16638 return NULL; 16639 case CLI_GENERATE: 16640 return complete_sipch(a->line, a->word, a->pos, a->n); 16641 } 16642 16643 if (a->argc != 4) 16644 return CLI_SHOWUSAGE; 16645 len = strlen(a->argv[3]); 16646 16647 i = ao2_iterator_init(dialogs, 0); 16648 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 16649 sip_pvt_lock(cur); 16650 16651 if (!strncasecmp(cur->callid, a->argv[3], len)) { 16652 char formatbuf[SIPBUFSIZE/2]; 16653 ast_cli(a->fd, "\n"); 16654 if (cur->subscribed != NONE) 16655 ast_cli(a->fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed)); 16656 else 16657 ast_cli(a->fd, " * SIP Call\n"); 16658 ast_cli(a->fd, " Curr. trans. direction: %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming"); 16659 ast_cli(a->fd, " Call-ID: %s\n", cur->callid); 16660 ast_cli(a->fd, " Owner channel ID: %s\n", cur->owner ? cur->owner->name : "<none>"); 16661 ast_cli(a->fd, " Our Codec Capability: %d\n", cur->capability); 16662 ast_cli(a->fd, " Non-Codec Capability (DTMF): %d\n", cur->noncodeccapability); 16663 ast_cli(a->fd, " Their Codec Capability: %d\n", cur->peercapability); 16664 ast_cli(a->fd, " Joint Codec Capability: %d\n", cur->jointcapability); 16665 ast_cli(a->fd, " Format: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) ); 16666 ast_cli(a->fd, " T.38 support %s\n", cli_yesno(cur->udptl != NULL)); 16667 ast_cli(a->fd, " Video support %s\n", cli_yesno(cur->vrtp != NULL)); 16668 ast_cli(a->fd, " MaxCallBR: %d kbps\n", cur->maxcallbitrate); 16669 ast_cli(a->fd, " Theoretical Address: %s:%d\n", ast_inet_ntoa(cur->sa.sin_addr), ntohs(cur->sa.sin_port)); 16670 ast_cli(a->fd, " Received Address: %s:%d\n", ast_inet_ntoa(cur->recv.sin_addr), ntohs(cur->recv.sin_port)); 16671 ast_cli(a->fd, " SIP Transfer mode: %s\n", transfermode2str(cur->allowtransfer)); 16672 ast_cli(a->fd, " NAT Support: %s\n", nat2str(ast_test_flag(&cur->flags[0], SIP_NAT))); 16673 ast_cli(a->fd, " Audio IP: %s %s\n", ast_inet_ntoa(cur->redirip.sin_addr.s_addr ? cur->redirip.sin_addr : cur->ourip.sin_addr), cur->redirip.sin_addr.s_addr ? "(Outside bridge)" : "(local)" ); 16674 ast_cli(a->fd, " Our Tag: %s\n", cur->tag); 16675 ast_cli(a->fd, " Their Tag: %s\n", cur->theirtag); 16676 ast_cli(a->fd, " SIP User agent: %s\n", cur->useragent); 16677 if (!ast_strlen_zero(cur->username)) 16678 ast_cli(a->fd, " Username: %s\n", cur->username); 16679 if (!ast_strlen_zero(cur->peername)) 16680 ast_cli(a->fd, " Peername: %s\n", cur->peername); 16681 if (!ast_strlen_zero(cur->uri)) 16682 ast_cli(a->fd, " Original uri: %s\n", cur->uri); 16683 if (!ast_strlen_zero(cur->cid_num)) 16684 ast_cli(a->fd, " Caller-ID: %s\n", cur->cid_num); 16685 ast_cli(a->fd, " Need Destroy: %s\n", cli_yesno(cur->needdestroy)); 16686 ast_cli(a->fd, " Last Message: %s\n", cur->lastmsg); 16687 ast_cli(a->fd, " Promiscuous Redir: %s\n", cli_yesno(ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR))); 16688 ast_cli(a->fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); 16689 ast_cli(a->fd, " DTMF Mode: %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF))); 16690 ast_cli(a->fd, " SIP Options: "); 16691 if (cur->sipoptions) { 16692 int x; 16693 for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { 16694 if (cur->sipoptions & sip_options[x].id) 16695 ast_cli(a->fd, "%s ", sip_options[x].text); 16696 } 16697 ast_cli(a->fd, "\n"); 16698 } else 16699 ast_cli(a->fd, "(none)\n"); 16700 16701 if (!cur->stimer) 16702 ast_cli(a->fd, " Session-Timer: Uninitiallized\n"); 16703 else { 16704 ast_cli(a->fd, " Session-Timer: %s\n", cur->stimer->st_active ? "Active" : "Inactive"); 16705 if (cur->stimer->st_active == TRUE) { 16706 ast_cli(a->fd, " S-Timer Interval: %d\n", cur->stimer->st_interval); 16707 ast_cli(a->fd, " S-Timer Refresher: %s\n", strefresher2str(cur->stimer->st_ref)); 16708 ast_cli(a->fd, " S-Timer Expirys: %d\n", cur->stimer->st_expirys); 16709 ast_cli(a->fd, " S-Timer Sched Id: %d\n", cur->stimer->st_schedid); 16710 ast_cli(a->fd, " S-Timer Peer Sts: %s\n", cur->stimer->st_active_peer_ua ? "Active" : "Inactive"); 16711 ast_cli(a->fd, " S-Timer Cached Min-SE: %d\n", cur->stimer->st_cached_min_se); 16712 ast_cli(a->fd, " S-Timer Cached SE: %d\n", cur->stimer->st_cached_max_se); 16713 ast_cli(a->fd, " S-Timer Cached Ref: %s\n", strefresher2str(cur->stimer->st_cached_ref)); 16714 ast_cli(a->fd, " S-Timer Cached Mode: %s\n", stmode2str(cur->stimer->st_cached_mode)); 16715 } 16716 } 16717 16718 ast_cli(a->fd, "\n\n"); 16719 16720 found++; 16721 } 16722 16723 sip_pvt_unlock(cur); 16724 16725 ao2_t_ref(cur, -1, "toss dialog ptr set by iterator_next"); 16726 } 16727 ao2_iterator_destroy(&i); 16728 16729 if (!found) 16730 ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]); 16731 16732 return CLI_SUCCESS; 16733 }
| static char* sip_show_channels | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI for show channels or subscriptions. This is a new-style CLI handler so a single function contains the prototype for the function, the 'generator' to produce multiple entries in case it is required, and the actual handler for the command.
Definition at line 16446 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, __show_chan_arg::fd, FORMAT2, FORMAT3, __show_chan_arg::numchans, OBJ_NODATA, show_channels_cb(), __show_chan_arg::subscriptions, and ast_cli_entry::usage.
16447 { 16448 struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; 16449 16450 16451 if (cmd == CLI_INIT) { 16452 e->command = "sip show {channels|subscriptions}"; 16453 e->usage = 16454 "Usage: sip show channels\n" 16455 " Lists all currently active SIP calls (dialogs).\n" 16456 "Usage: sip show subscriptions\n" 16457 " Lists active SIP subscriptions.\n"; 16458 return NULL; 16459 } else if (cmd == CLI_GENERATE) 16460 return NULL; 16461 16462 if (a->argc != e->args) 16463 return CLI_SHOWUSAGE; 16464 arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions"); 16465 if (!arg.subscriptions) 16466 ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Format", "Hold", "Last Message", "Expiry"); 16467 else 16468 ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox", "Expiry"); 16469 16470 /* iterate on the container and invoke the callback on each item */ 16471 ao2_t_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg, "callback to show channels"); 16472 16473 /* print summary information */ 16474 ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, 16475 (arg.subscriptions ? "subscription" : "dialog"), 16476 ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ 16477 return CLI_SUCCESS; 16478 #undef FORMAT 16479 #undef FORMAT2 16480 #undef FORMAT3 16481 }
| static char * sip_show_channelstats | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
SIP show channelstats CLI (main function).
Definition at line 16101 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, __show_chan_arg::fd, FORMAT2, __show_chan_arg::numchans, OBJ_NODATA, show_chanstats_cb(), and ast_cli_entry::usage.
16102 { 16103 struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; 16104 16105 switch (cmd) { 16106 case CLI_INIT: 16107 e->command = "sip show channelstats"; 16108 e->usage = 16109 "Usage: sip show channelstats\n" 16110 " Lists all currently active SIP channel's RTCP statistics.\n" 16111 " Note that calls in the much optimized RTP P2P bridge mode will not show any packets here."; 16112 return NULL; 16113 case CLI_GENERATE: 16114 return NULL; 16115 } 16116 16117 if (a->argc != 3) 16118 return CLI_SHOWUSAGE; 16119 16120 ast_cli(a->fd, FORMAT2, "Peer", "Call ID", "Duration", "Recv: Pack", "Lost", "Jitter", "Send: Pack", "Lost", "Jitter"); 16121 /* iterate on the container and invoke the callback on each item */ 16122 ao2_t_callback(dialogs, OBJ_NODATA, show_chanstats_cb, &arg, "callback to sip show chanstats"); 16123 ast_cli(a->fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : ""); 16124 return CLI_SUCCESS; 16125 }
| static char * sip_show_domains | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command to list local domains.
Definition at line 15396 of file chan_sip.c.
References ast_cli(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, domain::context, domain::domain, domain_mode_to_text(), ast_cli_args::fd, FORMAT, domain::mode, S_OR, and ast_cli_entry::usage.
15397 { 15398 struct domain *d; 15399 #define FORMAT "%-40.40s %-20.20s %-16.16s\n" 15400 15401 switch (cmd) { 15402 case CLI_INIT: 15403 e->command = "sip show domains"; 15404 e->usage = 15405 "Usage: sip show domains\n" 15406 " Lists all configured SIP local domains.\n" 15407 " Asterisk only responds to SIP messages to local domains.\n"; 15408 return NULL; 15409 case CLI_GENERATE: 15410 return NULL; 15411 } 15412 15413 if (AST_LIST_EMPTY(&domain_list)) { 15414 ast_cli(a->fd, "SIP Domain support not enabled.\n\n"); 15415 return CLI_SUCCESS; 15416 } else { 15417 ast_cli(a->fd, FORMAT, "Our local SIP domains:", "Context", "Set by"); 15418 AST_LIST_LOCK(&domain_list); 15419 AST_LIST_TRAVERSE(&domain_list, d, list) 15420 ast_cli(a->fd, FORMAT, d->domain, S_OR(d->context, "(default)"), 15421 domain_mode_to_text(d->mode)); 15422 AST_LIST_UNLOCK(&domain_list); 15423 ast_cli(a->fd, "\n"); 15424 return CLI_SUCCESS; 15425 } 15426 }
| static char * sip_show_history | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show history details of one dialog.
Definition at line 16736 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_TRAVERSE, sip_pvt::callid, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_show_history(), sip_history::event, ast_cli_args::fd, sip_pvt::history, ast_cli_args::line, ast_cli_args::n, NONE, ast_cli_args::pos, sip_pvt_lock, sip_pvt_unlock, sip_pvt::subscribed, ast_cli_entry::usage, and ast_cli_args::word.
16737 { 16738 struct sip_pvt *cur; 16739 size_t len; 16740 int found = 0; 16741 struct ao2_iterator i; 16742 16743 switch (cmd) { 16744 case CLI_INIT: 16745 e->command = "sip show history"; 16746 e->usage = 16747 "Usage: sip show history <call-id>\n" 16748 " Provides detailed dialog history on a given SIP call (specified by call-id).\n"; 16749 return NULL; 16750 case CLI_GENERATE: 16751 return complete_sip_show_history(a->line, a->word, a->pos, a->n); 16752 } 16753 16754 if (a->argc != 4) 16755 return CLI_SHOWUSAGE; 16756 16757 if (!recordhistory) 16758 ast_cli(a->fd, "\n***Note: History recording is currently DISABLED. Use 'sip set history on' to ENABLE.\n"); 16759 16760 len = strlen(a->argv[3]); 16761 16762 i = ao2_iterator_init(dialogs, 0); 16763 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 16764 sip_pvt_lock(cur); 16765 if (!strncasecmp(cur->callid, a->argv[3], len)) { 16766 struct sip_history *hist; 16767 int x = 0; 16768 16769 ast_cli(a->fd, "\n"); 16770 if (cur->subscribed != NONE) 16771 ast_cli(a->fd, " * Subscription\n"); 16772 else 16773 ast_cli(a->fd, " * SIP Call\n"); 16774 if (cur->history) 16775 AST_LIST_TRAVERSE(cur->history, hist, list) 16776 ast_cli(a->fd, "%d. %s\n", ++x, hist->event); 16777 if (x == 0) 16778 ast_cli(a->fd, "Call '%s' has no history\n", cur->callid); 16779 found++; 16780 } 16781 sip_pvt_unlock(cur); 16782 ao2_t_ref(cur, -1, "toss dialog ptr from iterator_next"); 16783 } 16784 ao2_iterator_destroy(&i); 16785 16786 if (!found) 16787 ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]); 16788 16789 return CLI_SUCCESS; 16790 }
| static char * sip_show_inuse | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Command to show calls within limits set by call_limit.
Definition at line 14498 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock(), ao2_t_iterator_next, ao2_unlock(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), sip_peer::call_limit, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, FALSE, ast_cli_args::fd, FORMAT, FORMAT2, sip_peer::inRinging, sip_peer::inUse, sip_peer::name, sip_peer::onHold, TRUE, unref_peer(), and ast_cli_entry::usage.
14499 { 14500 #define FORMAT "%-25.25s %-15.15s %-15.15s \n" 14501 #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" 14502 char ilimits[40]; 14503 char iused[40]; 14504 int showall = FALSE; 14505 struct ao2_iterator i; 14506 struct sip_peer *peer; 14507 14508 switch (cmd) { 14509 case CLI_INIT: 14510 e->command = "sip show inuse"; 14511 e->usage = 14512 "Usage: sip show inuse [all]\n" 14513 " List all SIP devices usage counters and limits.\n" 14514 " Add option \"all\" to show all devices, not only those with a limit.\n"; 14515 return NULL; 14516 case CLI_GENERATE: 14517 return NULL; 14518 } 14519 14520 if (a->argc < 3) 14521 return CLI_SHOWUSAGE; 14522 14523 if (a->argc == 4 && !strcmp(a->argv[3], "all")) 14524 showall = TRUE; 14525 14526 ast_cli(a->fd, FORMAT, "* Peer name", "In use", "Limit"); 14527 14528 i = ao2_iterator_init(peers, 0); 14529 while ((peer = ao2_t_iterator_next(&i, "iterate thru peer table"))) { 14530 ao2_lock(peer); 14531 if (peer->call_limit) 14532 snprintf(ilimits, sizeof(ilimits), "%d", peer->call_limit); 14533 else 14534 ast_copy_string(ilimits, "N/A", sizeof(ilimits)); 14535 snprintf(iused, sizeof(iused), "%d/%d/%d", peer->inUse, peer->inRinging, peer->onHold); 14536 if (showall || peer->call_limit) 14537 ast_cli(a->fd, FORMAT2, peer->name, iused, ilimits); 14538 ao2_unlock(peer); 14539 unref_peer(peer, "toss iterator pointer"); 14540 } 14541 ao2_iterator_destroy(&i); 14542 14543 return CLI_SUCCESS; 14544 #undef FORMAT 14545 #undef FORMAT2 14546 }
| static char * sip_show_mwi | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 16330 of file chan_sip.c.
References ast_cli(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, STANDARD_SIP_PORT, submwil, and ast_cli_entry::usage.
16331 { 16332 #define FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" 16333 char host[80]; 16334 16335 switch (cmd) { 16336 case CLI_INIT: 16337 e->command = "sip show mwi"; 16338 e->usage = 16339 "Usage: sip show mwi\n" 16340 " Provides a list of MWI subscriptions and status.\n"; 16341 return NULL; 16342 case CLI_GENERATE: 16343 return NULL; 16344 } 16345 16346 ast_cli(a->fd, FORMAT, "Host", "Username", "Mailbox", "Subscribed"); 16347 16348 ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do { 16349 ASTOBJ_RDLOCK(iterator); 16350 snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); 16351 ast_cli(a->fd, FORMAT, host, iterator->username, iterator->mailbox, iterator->subscribed ? "Yes" : "No"); 16352 ASTOBJ_UNLOCK(iterator); 16353 } while(0)); 16354 16355 return CLI_SUCCESS; 16356 #undef FORMAT 16357 }
| static char * sip_show_objects | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
List all allocated SIP Objects (realtime or static).
Definition at line 15081 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli(), ASTOBJ_CONTAINER_DUMP, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dialog_dump_func(), ast_cli_args::fd, OBJ_NODATA, peer_dump_func(), regl, and ast_cli_entry::usage.
15082 { 15083 char tmp[256]; 15084 15085 switch (cmd) { 15086 case CLI_INIT: 15087 e->command = "sip show objects"; 15088 e->usage = 15089 "Usage: sip show objects\n" 15090 " Lists status of known SIP objects\n"; 15091 return NULL; 15092 case CLI_GENERATE: 15093 return NULL; 15094 } 15095 15096 if (a->argc != 3) 15097 return CLI_SHOWUSAGE; 15098 ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs); 15099 ao2_t_callback(peers, OBJ_NODATA, peer_dump_func, &a->fd, "initiate ao2_callback to dump peers"); 15100 ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs); 15101 ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), ®l); 15102 ast_cli(a->fd, "-= Dialog objects:\n\n"); 15103 ao2_t_callback(dialogs, OBJ_NODATA, dialog_dump_func, &a->fd, "initiate ao2_callback to dump dialogs"); 15104 return CLI_SUCCESS; 15105 }
| static char * sip_show_peer | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show one peer in detail.
Definition at line 15457 of file chan_sip.c.
References _sip_show_peer(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, complete_sip_show_peer(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
15458 { 15459 switch (cmd) { 15460 case CLI_INIT: 15461 e->command = "sip show peer"; 15462 e->usage = 15463 "Usage: sip show peer <name> [load]\n" 15464 " Shows all details on one SIP peer and the current status.\n" 15465 " Option \"load\" forces lookup of peer in realtime storage.\n"; 15466 return NULL; 15467 case CLI_GENERATE: 15468 return complete_sip_show_peer(a->line, a->word, a->pos, a->n); 15469 } 15470 return _sip_show_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); 15471 }
| static char * sip_show_peers | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Show Peers command.
Definition at line 14857 of file chan_sip.c.
References _sip_show_peers(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
14858 { 14859 switch (cmd) { 14860 case CLI_INIT: 14861 e->command = "sip show peers"; 14862 e->usage = 14863 "Usage: sip show peers [like <pattern>]\n" 14864 " Lists all known SIP peers.\n" 14865 " Optional regular expression pattern is used to filter the peer list.\n"; 14866 return NULL; 14867 case CLI_GENERATE: 14868 return NULL; 14869 } 14870 14871 return _sip_show_peers(a->fd, NULL, NULL, NULL, a->argc, (const char **) a->argv); 14872 }
| static char * sip_show_registry | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show SIP Registry (registrations with other SIP proxies.
Definition at line 15959 of file chan_sip.c.
References ast_cli_args::argc, ast_cli(), ast_localtime(), ast_strftime(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, FORMAT2, regl, regstate2str(), STANDARD_SIP_PORT, and ast_cli_entry::usage.
15960 { 15961 #define FORMAT2 "%-30.30s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" 15962 #define FORMAT "%-30.30s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" 15963 char host[80]; 15964 char tmpdat[256]; 15965 struct ast_tm tm; 15966 int counter = 0; 15967 15968 switch (cmd) { 15969 case CLI_INIT: 15970 e->command = "sip show registry"; 15971 e->usage = 15972 "Usage: sip show registry\n" 15973 " Lists all registration requests and status.\n"; 15974 return NULL; 15975 case CLI_GENERATE: 15976 return NULL; 15977 } 15978 15979 if (a->argc != 3) 15980 return CLI_SHOWUSAGE; 15981 ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time"); 15982 15983 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 15984 ASTOBJ_RDLOCK(iterator); 15985 snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); 15986 if (iterator->regtime.tv_sec) { 15987 ast_localtime(&iterator->regtime, &tm, NULL); 15988 ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); 15989 } else 15990 tmpdat[0] = '\0'; 15991 ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat); 15992 ASTOBJ_UNLOCK(iterator); 15993 counter++; 15994 } while(0)); 15995 ast_cli(a->fd, "%d SIP registrations.\n", counter); 15996 return CLI_SUCCESS; 15997 #undef FORMAT 15998 #undef FORMAT2 15999 }
| static char * sip_show_sched | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 15916 of file chan_sip.c.
References __sip_autodestruct(), ast_cli(), ast_sched_report(), ast_str_alloca, auto_congest(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, expire_register(), ast_cli_args::fd, retrans_pkt(), sip_poke_noanswer(), sip_poke_peer_s(), sip_reg_timeout(), sip_reinvite_retry(), sip_reregister(), and ast_cli_entry::usage.
15917 { 15918 struct ast_str *cbuf; 15919 struct ast_cb_names cbnames = {9, { "retrans_pkt", 15920 "__sip_autodestruct", 15921 "expire_register", 15922 "auto_congest", 15923 "sip_reg_timeout", 15924 "sip_poke_peer_s", 15925 "sip_poke_noanswer", 15926 "sip_reregister", 15927 "sip_reinvite_retry"}, 15928 { retrans_pkt, 15929 __sip_autodestruct, 15930 expire_register, 15931 auto_congest, 15932 sip_reg_timeout, 15933 sip_poke_peer_s, 15934 sip_poke_noanswer, 15935 sip_reregister, 15936 sip_reinvite_retry}}; 15937 15938 switch (cmd) { 15939 case CLI_INIT: 15940 e->command = "sip show sched"; 15941 e->usage = 15942 "Usage: sip show sched\n" 15943 " Shows stats on what's in the sched queue at the moment\n"; 15944 return NULL; 15945 case CLI_GENERATE: 15946 return NULL; 15947 } 15948 15949 cbuf = ast_str_alloca(2048); 15950 15951 ast_cli(a->fd, "\n"); 15952 ast_sched_report(sched, &cbuf, &cbnames); 15953 ast_cli(a->fd, "%s", cbuf->str); 15954 15955 return CLI_SUCCESS; 15956 }
| static char * sip_show_settings | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
List global settings for the SIP channel.
Definition at line 16130 of file chan_sip.c.
References sip_settings::allow_external_domains, sip_settings::allowguest, sip_settings::allowtransfer, sip_settings::alwaysauthreject, ast_cli_args::argc, ast_check_realtime(), ast_cli(), ast_getformatname_multiple(), ast_inet_ntoa(), AST_JB_ENABLED, AST_JB_FORCED, AST_JB_LOG, AST_LIST_EMPTY, ast_strlen_zero(), ast_test_flag, ast_tos2str(), sip_settings::autocreatepeer, bindaddr, buf, sip_settings::callevents, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, cli_yesno(), ast_cli_entry::command, sip_settings::compactheaders, sip_settings::default_context, default_prefs, default_tls_cfg, sip_settings::directrtpsetup, dtmfmode2str(), ast_tls_config::enabled, externip, FALSE, faxec2str(), ast_cli_args::fd, sip_proxy::force, get_transport(), get_transport_list(), global_jbconf, IGNORE_CONTEXT, sip_settings::ignore_regexpire, ast_jb_conf::impl, ast_tcptls_session_args::local_address, ast_jb_conf::max_size, msg, sip_proxy::name, nat2str(), ast_ha::netaddr, ast_ha::netmask, ast_ha::next, sip_settings::notifycid, sip_settings::notifyhold, sip_settings::notifyringing, sip_settings::outboundproxy, sip_settings::pedanticsipchecking, sip_settings::peer_rtupdate, prefix, print_codec_to_cli(), sip_settings::realm, sip_settings::regextenonqualify, ast_jb_conf::resync_threshold, sip_settings::rtautoclear, sip_settings::rtsave_sysname, S_OR, sip_cfg, SIP_DTMF, SIP_NAT, SIP_PAGE2_ALLOWOVERLAP, SIP_PAGE2_ALLOWSUBSCRIBE, SIP_PAGE2_FORWARD_LOOP_DETECTED, SIP_PAGE2_IGNORESDPVERSION, SIP_PAGE2_RFC2833_COMPENSATE, SIP_PAGE2_RTAUTOCLEAR, SIP_PAGE2_RTCACHEFRIENDS, SIP_PAGE2_T38SUPPORT, SIP_PAGE2_TEXTSUPPORT, SIP_PAGE2_VIDEOSUPPORT, SIP_PROG_INBAND, SIP_PROG_INBAND_NEVER, SIP_PROG_INBAND_NO, SIP_PROMISCREDIR, SIP_USECLIENTCODE, SIP_USEREQPHONE, SIPBUFSIZE, sip_settings::srvlookup, stmode2str(), strefresher2str(), stunaddr, transfermode2str(), and ast_cli_entry::usage.
16131 { 16132 int realtimepeers; 16133 int realtimeregs; 16134 char codec_buf[SIPBUFSIZE]; 16135 const char *msg; /* temporary msg pointer */ 16136 16137 switch (cmd) { 16138 case CLI_INIT: 16139 e->command = "sip show settings"; 16140 e->usage = 16141 "Usage: sip show settings\n" 16142 " Provides detailed list of the configuration of the SIP channel.\n"; 16143 return NULL; 16144 case CLI_GENERATE: 16145 return NULL; 16146 } 16147 16148 16149 realtimepeers = ast_check_realtime("sippeers"); 16150 realtimeregs = ast_check_realtime("sipregs"); 16151 16152 if (a->argc != 3) 16153 return CLI_SHOWUSAGE; 16154 ast_cli(a->fd, "\n\nGlobal Settings:\n"); 16155 ast_cli(a->fd, "----------------\n"); 16156 ast_cli(a->fd, " UDP SIP Port: %d\n", ntohs(bindaddr.sin_port)); 16157 ast_cli(a->fd, " UDP Bindaddress: %s\n", ast_inet_ntoa(bindaddr.sin_addr)); 16158 ast_cli(a->fd, " TCP SIP Port: "); 16159 if (sip_tcp_desc.local_address.sin_family == AF_INET) { 16160 ast_cli(a->fd, "%d\n", ntohs(sip_tcp_desc.local_address.sin_port)); 16161 ast_cli(a->fd, " TCP Bindaddress: %s\n", ast_inet_ntoa(sip_tcp_desc.local_address.sin_addr)); 16162 } else { 16163 ast_cli(a->fd, "Disabled\n"); 16164 } 16165 ast_cli(a->fd, " TLS SIP Port: "); 16166 if (default_tls_cfg.enabled != FALSE) { 16167 ast_cli(a->fd, "%d\n", ntohs(sip_tls_desc.local_address.sin_port)); 16168 ast_cli(a->fd, " TLS Bindaddress: %s\n", ast_inet_ntoa(sip_tls_desc.local_address.sin_addr)); 16169 } else { 16170 ast_cli(a->fd, "Disabled\n"); 16171 } 16172 ast_cli(a->fd, " Videosupport: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT))); 16173 ast_cli(a->fd, " Textsupport: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT))); 16174 ast_cli(a->fd, " Ignore SDP sess. ver.: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION))); 16175 ast_cli(a->fd, " AutoCreate Peer: %s\n", cli_yesno(sip_cfg.autocreatepeer)); 16176 ast_cli(a->fd, " Match Auth Username: %s\n", cli_yesno(global_match_auth_username)); 16177 ast_cli(a->fd, " Allow unknown access: %s\n", cli_yesno(sip_cfg.allowguest)); 16178 ast_cli(a->fd, " Allow subscriptions: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); 16179 ast_cli(a->fd, " Allow overlap dialing: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP))); 16180 ast_cli(a->fd, " Allow promsic. redir: %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_PROMISCREDIR))); 16181 ast_cli(a->fd, " Enable call counters: %s\n", cli_yesno(global_callcounter)); 16182 ast_cli(a->fd, " SIP domain support: %s\n", cli_yesno(!AST_LIST_EMPTY(&domain_list))); 16183 ast_cli(a->fd, " Realm. auth: %s\n", cli_yesno(authl != NULL)); 16184 ast_cli(a->fd, " Our auth realm %s\n", sip_cfg.realm); 16185 ast_cli(a->fd, " Call to non-local dom.: %s\n", cli_yesno(sip_cfg.allow_external_domains)); 16186 ast_cli(a->fd, " URI user is phone no: %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_USEREQPHONE))); 16187 ast_cli(a->fd, " Always auth rejects: %s\n", cli_yesno(sip_cfg.alwaysauthreject)); 16188 ast_cli(a->fd, " Direct RTP setup: %s\n", cli_yesno(sip_cfg.directrtpsetup)); 16189 ast_cli(a->fd, " User Agent: %s\n", global_useragent); 16190 ast_cli(a->fd, " SDP Session Name: %s\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession); 16191 ast_cli(a->fd, " SDP Owner Name: %s\n", ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner); 16192 ast_cli(a->fd, " Reg. context: %s\n", S_OR(global_regcontext, "(not set)")); 16193 ast_cli(a->fd, " Regexten on Qualify: %s\n", cli_yesno(sip_cfg.regextenonqualify)); 16194 ast_cli(a->fd, " Caller ID: %s\n", default_callerid); 16195 ast_cli(a->fd, " From: Domain: %s\n", default_fromdomain); 16196 ast_cli(a->fd, " Record SIP history: %s\n", recordhistory ? "On" : "Off"); 16197 ast_cli(a->fd, " Call Events: %s\n", sip_cfg.callevents ? "On" : "Off"); 16198 ast_cli(a->fd, " Auth. Failure Events: %s\n", global_authfailureevents ? "On" : "Off"); 16199 16200 ast_cli(a->fd, " T.38 support: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT))); 16201 ast_cli(a->fd, " T.38 EC mode: %s\n", faxec2str(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT))); 16202 ast_cli(a->fd, " T.38 MaxDtgrm: %d\n", global_t38_maxdatagram); 16203 16204 if (!realtimepeers && !realtimeregs) 16205 ast_cli(a->fd, " SIP realtime: Disabled\n" ); 16206 else 16207 ast_cli(a->fd, " SIP realtime: Enabled\n" ); 16208 ast_cli(a->fd, " Qualify Freq : %d ms\n", global_qualifyfreq); 16209 ast_cli(a->fd, "\nNetwork QoS Settings:\n"); 16210 ast_cli(a->fd, "---------------------------\n"); 16211 ast_cli(a->fd, " IP ToS SIP: %s\n", ast_tos2str(global_tos_sip)); 16212 ast_cli(a->fd, " IP ToS RTP audio: %s\n", ast_tos2str(global_tos_audio)); 16213 ast_cli(a->fd, " IP ToS RTP video: %s\n", ast_tos2str(global_tos_video)); 16214 ast_cli(a->fd, " IP ToS RTP text: %s\n", ast_tos2str(global_tos_text)); 16215 ast_cli(a->fd, " 802.1p CoS SIP: %d\n", global_cos_sip); 16216 ast_cli(a->fd, " 802.1p CoS RTP audio: %d\n", global_cos_audio); 16217 ast_cli(a->fd, " 802.1p CoS RTP video: %d\n", global_cos_video); 16218 ast_cli(a->fd, " 802.1p CoS RTP text: %d\n", global_cos_text); 16219 ast_cli(a->fd, " Jitterbuffer enabled: %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_ENABLED))); 16220 ast_cli(a->fd, " Jitterbuffer forced: %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_FORCED))); 16221 ast_cli(a->fd, " Jitterbuffer max size: %ld\n", global_jbconf.max_size); 16222 ast_cli(a->fd, " Jitterbuffer resync: %ld\n", global_jbconf.resync_threshold); 16223 ast_cli(a->fd, " Jitterbuffer impl: %s\n", global_jbconf.impl); 16224 ast_cli(a->fd, " Jitterbuffer log: %s\n", cli_yesno(ast_test_flag(&global_jbconf, AST_JB_LOG))); 16225 16226 ast_cli(a->fd, "\nNetwork Settings:\n"); 16227 ast_cli(a->fd, "---------------------------\n"); 16228 /* determine if/how SIP address can be remapped */ 16229 if (localaddr == NULL) 16230 msg = "Disabled, no localnet list"; 16231 else if (externip.sin_addr.s_addr == 0) 16232 msg = "Disabled, externip is 0.0.0.0"; 16233 else if (stunaddr.sin_addr.s_addr != 0) 16234 msg = "Enabled using STUN"; 16235 else if (!ast_strlen_zero(externhost)) 16236 msg = "Enabled using externhost"; 16237 else 16238 msg = "Enabled using externip"; 16239 ast_cli(a->fd, " SIP address remapping: %s\n", msg); 16240 ast_cli(a->fd, " Externhost: %s\n", S_OR(externhost, "<none>")); 16241 ast_cli(a->fd, " Externip: %s:%d\n", ast_inet_ntoa(externip.sin_addr), ntohs(externip.sin_port)); 16242 ast_cli(a->fd, " Externrefresh: %d\n", externrefresh); 16243 { 16244 struct ast_ha *d; 16245 const char *prefix = "Localnet:"; 16246 char buf[INET_ADDRSTRLEN]; /* need to print two addresses */ 16247 16248 for (d = localaddr; d ; prefix = "", d = d->next) { 16249 ast_cli(a->fd, " %-24s%s/%s\n", 16250 prefix, ast_inet_ntoa(d->netaddr), 16251 inet_ntop(AF_INET, &d->netmask, buf, sizeof(buf)) ); 16252 } 16253 } 16254 ast_cli(a->fd, " STUN server: %s:%d\n", ast_inet_ntoa(stunaddr.sin_addr), ntohs(stunaddr.sin_port)); 16255 16256 ast_cli(a->fd, "\nGlobal Signalling Settings:\n"); 16257 ast_cli(a->fd, "---------------------------\n"); 16258 ast_cli(a->fd, " Codecs: "); 16259 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, global_capability); 16260 ast_cli(a->fd, "%s\n", codec_buf); 16261 ast_cli(a->fd, " Codec Order: "); 16262 print_codec_to_cli(a->fd, &default_prefs); 16263 ast_cli(a->fd, "\n"); 16264 ast_cli(a->fd, " Relax DTMF: %s\n", cli_yesno(global_relaxdtmf)); 16265 ast_cli(a->fd, " RFC2833 Compensation: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE))); 16266 ast_cli(a->fd, " Compact SIP headers: %s\n", cli_yesno(sip_cfg.compactheaders)); 16267 ast_cli(a->fd, " RTP Keepalive: %d %s\n", global_rtpkeepalive, global_rtpkeepalive ? "" : "(Disabled)" ); 16268 ast_cli(a->fd, " RTP Timeout: %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" ); 16269 ast_cli(a->fd, " RTP Hold Timeout: %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)"); 16270 ast_cli(a->fd, " MWI NOTIFY mime type: %s\n", default_notifymime); 16271 ast_cli(a->fd, " DNS SRV lookup: %s\n", cli_yesno(sip_cfg.srvlookup)); 16272 ast_cli(a->fd, " Pedantic SIP support: %s\n", cli_yesno(sip_cfg.pedanticsipchecking)); 16273 ast_cli(a->fd, " Reg. min duration %d secs\n", min_expiry); 16274 ast_cli(a->fd, " Reg. max duration: %d secs\n", max_expiry); 16275 ast_cli(a->fd, " Reg. default duration: %d secs\n", default_expiry); 16276 ast_cli(a->fd, " Outbound reg. timeout: %d secs\n", global_reg_timeout); 16277 ast_cli(a->fd, " Outbound reg. attempts: %d\n", global_regattempts_max); 16278 ast_cli(a->fd, " Notify ringing state: %s\n", cli_yesno(sip_cfg.notifyringing)); 16279 if (sip_cfg.notifyringing) { 16280 ast_cli(a->fd, " Include CID: %s%s\n", 16281 cli_yesno(sip_cfg.notifycid), 16282 sip_cfg.notifycid == IGNORE_CONTEXT ? " (Ignoring context)" : ""); 16283 } 16284 ast_cli(a->fd, " Notify hold state: %s\n", cli_yesno(sip_cfg.notifyhold)); 16285 ast_cli(a->fd, " SIP Transfer mode: %s\n", transfermode2str(sip_cfg.allowtransfer)); 16286 ast_cli(a->fd, " Max Call Bitrate: %d kbps\n", default_maxcallbitrate); 16287 ast_cli(a->fd, " Auto-Framing: %s\n", cli_yesno(global_autoframing)); 16288 ast_cli(a->fd, " Outb. proxy: %s %s\n", ast_strlen_zero(sip_cfg.outboundproxy.name) ? "<not set>" : sip_cfg.outboundproxy.name, 16289 sip_cfg.outboundproxy.force ? "(forced)" : ""); 16290 ast_cli(a->fd, " Session Timers: %s\n", stmode2str(global_st_mode)); 16291 ast_cli(a->fd, " Session Refresher: %s\n", strefresher2str (global_st_refresher)); 16292 ast_cli(a->fd, " Session Expires: %d secs\n", global_max_se); 16293 ast_cli(a->fd, " Session Min-SE: %d secs\n", global_min_se); 16294 ast_cli(a->fd, " Timer T1: %d\n", global_t1); 16295 ast_cli(a->fd, " Timer T1 minimum: %d\n", global_t1min); 16296 ast_cli(a->fd, " Timer B: %d\n", global_timer_b); 16297 ast_cli(a->fd, " No premature media: %s\n", global_prematuremediafilter ? "Yes" : "No"); 16298 16299 ast_cli(a->fd, "\nDefault Settings:\n"); 16300 ast_cli(a->fd, "-----------------\n"); 16301 ast_cli(a->fd, " Allowed transports: %s\n", get_transport_list(default_transports)); 16302 ast_cli(a->fd, " Outbound transport: %s\n", get_transport(default_primary_transport)); 16303 ast_cli(a->fd, " Context: %s\n", sip_cfg.default_context); 16304 ast_cli(a->fd, " Nat: %s\n", nat2str(ast_test_flag(&global_flags[0], SIP_NAT))); 16305 ast_cli(a->fd, " DTMF: %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF))); 16306 ast_cli(a->fd, " Qualify: %d\n", default_qualify); 16307 ast_cli(a->fd, " Use ClientCode: %s\n", cli_yesno(ast_test_flag(&global_flags[0], SIP_USECLIENTCODE))); 16308 ast_cli(a->fd, " Progress inband: %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NO) ? "No" : "Yes" ); 16309 ast_cli(a->fd, " Language: %s\n", default_language); 16310 ast_cli(a->fd, " MOH Interpret: %s\n", default_mohinterpret); 16311 ast_cli(a->fd, " MOH Suggest: %s\n", default_mohsuggest); 16312 ast_cli(a->fd, " Voice Mail Extension: %s\n", default_vmexten); 16313 ast_cli(a->fd, " Forward Detected Loops: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_FORWARD_LOOP_DETECTED))); 16314 16315 if (realtimepeers || realtimeregs) { 16316 ast_cli(a->fd, "\nRealtime SIP Settings:\n"); 16317 ast_cli(a->fd, "----------------------\n"); 16318 ast_cli(a->fd, " Realtime Peers: %s\n", cli_yesno(realtimepeers)); 16319 ast_cli(a->fd, " Realtime Regs: %s\n", cli_yesno(realtimeregs)); 16320 ast_cli(a->fd, " Cache Friends: %s\n", cli_yesno(ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS))); 16321 ast_cli(a->fd, " Update: %s\n", cli_yesno(sip_cfg.peer_rtupdate)); 16322 ast_cli(a->fd, " Ignore Reg. Expire: %s\n", cli_yesno(sip_cfg.ignore_regexpire)); 16323 ast_cli(a->fd, " Save sys. name: %s\n", cli_yesno(sip_cfg.rtsave_sysname)); 16324 ast_cli(a->fd, " Auto Clear: %d (%s)\n", sip_cfg.rtautoclear, ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR) ? "Enabled" : "Disabled"); 16325 } 16326 ast_cli(a->fd, "\n----\n"); 16327 return CLI_SUCCESS; 16328 }
| static char* sip_show_tcp | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show active TCP connections.
Definition at line 14669 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli(), ast_inet_ntoa(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_tcptls_session_instance::client, ast_cli_entry::command, ast_cli_args::fd, FORMAT, FORMAT2, get_transport(), ast_tcptls_session_instance::remote_address, sip_threadinfo::tcptls_session, sip_threadinfo::type, and ast_cli_entry::usage.
14670 { 14671 struct sip_threadinfo *th; 14672 struct ao2_iterator i; 14673 14674 #define FORMAT2 "%-30.30s %3.6s %9.9s %6.6s\n" 14675 #define FORMAT "%-30.30s %-6d %-9.9s %-6.6s\n" 14676 14677 switch (cmd) { 14678 case CLI_INIT: 14679 e->command = "sip show tcp"; 14680 e->usage = 14681 "Usage: sip show tcp\n" 14682 " Lists all active TCP/TLS sessions.\n"; 14683 return NULL; 14684 case CLI_GENERATE: 14685 return NULL; 14686 } 14687 14688 if (a->argc != 3) 14689 return CLI_SHOWUSAGE; 14690 14691 ast_cli(a->fd, FORMAT2, "Host", "Port", "Transport", "Type"); 14692 i = ao2_iterator_init(threadt, 0); 14693 while ((th = ao2_t_iterator_next(&i, "iterate through tcp threads for 'sip show tcp'"))) { 14694 ast_cli(a->fd, FORMAT, ast_inet_ntoa(th->tcptls_session->remote_address.sin_addr), 14695 ntohs(th->tcptls_session->remote_address.sin_port), 14696 get_transport(th->type), 14697 (th->tcptls_session->client ? "Client" : "Server")); 14698 ao2_t_ref(th, -1, "decrement ref from iterator"); 14699 } 14700 ao2_iterator_destroy(&i); 14701 return CLI_SUCCESS; 14702 #undef FORMAT 14703 #undef FORMAT2 14704 }
| static char* sip_show_user | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show one user in detail.
Definition at line 15841 of file chan_sip.c.
References sip_peer::accountcode, sip_peer::allowtransfer, sip_peer::amaflags, ao2_lock(), ao2_unlock(), ast_cli_args::argc, ast_cli_args::argv, ast_callerid_merge(), ast_cdr_flags2str(), ast_cli(), ast_describe_caller_presentation(), ast_strlen_zero(), sip_peer::autoframing, sip_peer::call_limit, sip_peer::callgroup, sip_peer::callingpres, sip_peer::chanvars, sip_peer::cid_name, sip_peer::cid_num, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, cli_yesno(), ast_cli_entry::command, complete_sip_show_user(), sip_peer::context, FALSE, ast_cli_args::fd, find_peer(), FINDUSERS, sip_peer::ha, sip_peer::language, ast_cli_args::line, sip_peer::maxcallbitrate, sip_peer::md5secret, ast_cli_args::n, ast_variable::name, sip_peer::name, ast_variable::next, sip_peer::pickupgroup, ast_cli_args::pos, sip_peer::prefs, print_codec_to_cli(), print_group(), sip_peer::secret, sip_st_cfg::st_max_se, sip_st_cfg::st_min_se, sip_st_cfg::st_mode_oper, sip_st_cfg::st_ref, sip_peer::stimer, stmode2str(), strefresher2str(), transfermode2str(), TRUE, unref_peer(), ast_cli_entry::usage, ast_variable::value, and ast_cli_args::word.
15842 { 15843 char cbuf[256]; 15844 struct sip_peer *user; 15845 struct ast_variable *v; 15846 int load_realtime; 15847 15848 switch (cmd) { 15849 case CLI_INIT: 15850 e->command = "sip show user"; 15851 e->usage = 15852 "Usage: sip show user <name> [load]\n" 15853 " Shows all details on one SIP user and the current status.\n" 15854 " Option \"load\" forces lookup of peer in realtime storage.\n"; 15855 return NULL; 15856 case CLI_GENERATE: 15857 return complete_sip_show_user(a->line, a->word, a->pos, a->n); 15858 } 15859 15860 if (a->argc < 4) 15861 return CLI_SHOWUSAGE; 15862 15863 /* Load from realtime storage? */ 15864 load_realtime = (a->argc == 5 && !strcmp(a->argv[4], "load")) ? TRUE : FALSE; 15865 15866 if ((user = find_peer(a->argv[3], NULL, load_realtime, FINDUSERS, FALSE, 0))) { 15867 ao2_lock(user); 15868 ast_cli(a->fd, "\n\n"); 15869 ast_cli(a->fd, " * Name : %s\n", user->name); 15870 ast_cli(a->fd, " Secret : %s\n", ast_strlen_zero(user->secret)?"<Not set>":"<Set>"); 15871 ast_cli(a->fd, " MD5Secret : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>"); 15872 ast_cli(a->fd, " Context : %s\n", user->context); 15873 ast_cli(a->fd, " Language : %s\n", user->language); 15874 if (!ast_strlen_zero(user->accountcode)) 15875 ast_cli(a->fd, " Accountcode : %s\n", user->accountcode); 15876 ast_cli(a->fd, " AMA flags : %s\n", ast_cdr_flags2str(user->amaflags)); 15877 ast_cli(a->fd, " Transfer mode: %s\n", transfermode2str(user->allowtransfer)); 15878 ast_cli(a->fd, " MaxCallBR : %d kbps\n", user->maxcallbitrate); 15879 ast_cli(a->fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres)); 15880 ast_cli(a->fd, " Call limit : %d\n", user->call_limit); 15881 ast_cli(a->fd, " Callgroup : "); 15882 print_group(a->fd, user->callgroup, 0); 15883 ast_cli(a->fd, " Pickupgroup : "); 15884 print_group(a->fd, user->pickupgroup, 0); 15885 ast_cli(a->fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>")); 15886 ast_cli(a->fd, " ACL : %s\n", cli_yesno(user->ha != NULL)); 15887 ast_cli(a->fd, " Sess-Timers : %s\n", stmode2str(user->stimer.st_mode_oper)); 15888 ast_cli(a->fd, " Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref)); 15889 ast_cli(a->fd, " Sess-Expires : %d secs\n", user->stimer.st_max_se); 15890 ast_cli(a->fd, " Sess-Min-SE : %d secs\n", user->stimer.st_min_se); 15891 15892 ast_cli(a->fd, " Codec Order : ("); 15893 print_codec_to_cli(a->fd, &user->prefs); 15894 ast_cli(a->fd, ")\n"); 15895 15896 ast_cli(a->fd, " Auto-Framing: %s \n", cli_yesno(user->autoframing)); 15897 if (user->chanvars) { 15898 ast_cli(a->fd, " Variables :\n"); 15899 for (v = user->chanvars ; v ; v = v->next) 15900 ast_cli(a->fd, " %s = %s\n", v->name, v->value); 15901 } 15902 15903 ast_cli(a->fd, "\n"); 15904 15905 ao2_unlock(user); 15906 unref_peer(user, "sip show user"); 15907 } else { 15908 ast_cli(a->fd, "User %s not found.\n", a->argv[3]); 15909 ast_cli(a->fd, "\n"); 15910 } 15911 15912 return CLI_SUCCESS; 15913 }
| static char* sip_show_users | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Command 'SIP Show Users'.
Definition at line 14707 of file chan_sip.c.
References sip_peer::accountcode, ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock(), ao2_unlock(), ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, cli_yesno(), ast_cli_entry::command, sip_peer::context, FALSE, ast_cli_args::fd, sip_peer::flags, FORMAT, sip_peer::ha, sip_peer::name, nat2str(), sip_peer::secret, SIP_NAT, SIP_TYPE_USER, TRUE, sip_peer::type, unref_peer(), and ast_cli_entry::usage.
14708 { 14709 regex_t regexbuf; 14710 int havepattern = FALSE; 14711 struct ao2_iterator user_iter; 14712 struct sip_peer *user; 14713 14714 #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" 14715 14716 switch (cmd) { 14717 case CLI_INIT: 14718 e->command = "sip show users"; 14719 e->usage = 14720 "Usage: sip show users [like <pattern>]\n" 14721 " Lists all known SIP users.\n" 14722 " Optional regular expression pattern is used to filter the user list.\n"; 14723 return NULL; 14724 case CLI_GENERATE: 14725 return NULL; 14726 } 14727 14728 switch (a->argc) { 14729 case 5: 14730 if (!strcasecmp(a->argv[3], "like")) { 14731 if (regcomp(®exbuf, a->argv[4], REG_EXTENDED | REG_NOSUB)) 14732 return CLI_SHOWUSAGE; 14733 havepattern = TRUE; 14734 } else 14735 return CLI_SHOWUSAGE; 14736 case 3: 14737 break; 14738 default: 14739 return CLI_SHOWUSAGE; 14740 } 14741 14742 ast_cli(a->fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "NAT"); 14743 14744 user_iter = ao2_iterator_init(peers, 0); 14745 while ((user = ao2_iterator_next(&user_iter))) { 14746 ao2_lock(user); 14747 if (!(user->type & SIP_TYPE_USER)) { 14748 ao2_unlock(user); 14749 unref_peer(user, "sip show users"); 14750 continue; 14751 } 14752 14753 if (havepattern && regexec(®exbuf, user->name, 0, NULL, 0)) { 14754 ao2_unlock(user); 14755 unref_peer(user, "sip show users"); 14756 continue; 14757 } 14758 14759 ast_cli(a->fd, FORMAT, user->name, 14760 user->secret, 14761 user->accountcode, 14762 user->context, 14763 cli_yesno(user->ha != NULL), 14764 nat2str(ast_test_flag(&user->flags[0], SIP_NAT))); 14765 ao2_unlock(user); 14766 unref_peer(user, "sip show users"); 14767 } 14768 ao2_iterator_destroy(&user_iter); 14769 14770 if (havepattern) 14771 regfree(®exbuf); 14772 14773 return CLI_SUCCESS; 14774 #undef FORMAT 14775 }
| static int sip_sipredirect | ( | struct sip_pvt * | p, | |
| const char * | dest | |||
| ) | [static] |
Transfer call before connect with a 302 redirect.
Definition at line 25807 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strdupa, ast_string_field_build, ast_strlen_zero(), get_header(), sip_pvt::initreq, LOG_ERROR, sip_alreadygone(), sip_scheddestroy(), SIP_TRANS_TIMEOUT, strcasestr(), strsep(), and transmit_response_reliable().
Referenced by sip_transfer().
25808 { 25809 char *cdest; 25810 char *extension, *host, *port; 25811 char tmp[80]; 25812 25813 cdest = ast_strdupa(dest); 25814 25815 extension = strsep(&cdest, "@"); 25816 host = strsep(&cdest, ":"); 25817 port = strsep(&cdest, ":"); 25818 if (ast_strlen_zero(extension)) { 25819 ast_log(LOG_ERROR, "Missing mandatory argument: extension\n"); 25820 return 0; 25821 } 25822 25823 /* we'll issue the redirect message here */ 25824 if (!host) { 25825 char *localtmp; 25826 25827 ast_copy_string(tmp, get_header(&p->initreq, "To"), sizeof(tmp)); 25828 if (ast_strlen_zero(tmp)) { 25829 ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n"); 25830 return 0; 25831 } 25832 if ( ( (localtmp = strcasestr(tmp, "sip:")) || (localtmp = strcasestr(tmp, "sips:")) ) 25833 && (localtmp = strchr(localtmp, '@'))) { 25834 char lhost[80], lport[80]; 25835 25836 memset(lhost, 0, sizeof(lhost)); 25837 memset(lport, 0, sizeof(lport)); 25838 localtmp++; 25839 /* This is okey because lhost and lport are as big as tmp */ 25840 sscanf(localtmp, "%80[^<>:; ]:%80[^<>:; ]", lhost, lport); 25841 if (ast_strlen_zero(lhost)) { 25842 ast_log(LOG_ERROR, "Can't find the host address\n"); 25843 return 0; 25844 } 25845 host = ast_strdupa(lhost); 25846 if (!ast_strlen_zero(lport)) { 25847 port = ast_strdupa(lport); 25848 } 25849 } 25850 } 25851 25852 ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s%s%s>", extension, host, port ? ":" : "", port ? port : ""); 25853 transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq); 25854 25855 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */ 25856 sip_alreadygone(p); 25857 /* hangup here */ 25858 return 0; 25859 }
| static struct sip_st_dlg * sip_st_alloc | ( | struct sip_pvt *const | p | ) | [static, read] |
Allocate Session-Timers struct w/in dialog.
Definition at line 7232 of file chan_sip.c.
References ast_calloc, ast_log(), LOG_ERROR, sip_st_dlg::st_schedid, and sip_pvt::stimer.
Referenced by handle_request_invite(), and st_get_mode().
07233 { 07234 struct sip_st_dlg *stp; 07235 07236 if (p->stimer) { 07237 ast_log(LOG_ERROR, "Session-Timer struct already allocated\n"); 07238 return p->stimer; 07239 } 07240 07241 if (!(stp = ast_calloc(1, sizeof(struct sip_st_dlg)))) 07242 return NULL; 07243 07244 p->stimer = stp; 07245 07246 stp->st_schedid = -1; /* Session-Timers ast_sched scheduler id */ 07247 07248 return p->stimer; 07249 }
| static int sip_standard_port | ( | enum sip_transport | type, | |
| int | port | |||
| ) | [static] |
Returns the port to use for this socket.
| type | The type of transport used | |
| port | Port we are checking to see if it's the standard port. |
Definition at line 22285 of file chan_sip.c.
References SIP_TRANSPORT_TLS, STANDARD_SIP_PORT, and STANDARD_TLS_PORT.
Referenced by build_contact(), initreqprep(), and transmit_notify_with_mwi().
22286 { 22287 if (type & SIP_TRANSPORT_TLS) 22288 return port == STANDARD_TLS_PORT; 22289 else 22290 return port == STANDARD_SIP_PORT; 22291 }
| static int sip_subscribe_mwi | ( | const char * | value, | |
| int | lineno | |||
| ) | [static] |
Parse mwi=> line in sip.conf and add to list.
--- SIP MWI Subscription support
Definition at line 7773 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_free, ast_log(), ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, ASTOBJ_UNREF, sip_subscription_mwi::authuser, buf, hostname, LOG_WARNING, mailbox, sip_subscription_mwi::portno, sip_subscription_mwi::resub, secret, sip_parse_host(), sip_subscribe_mwi_destroy(), SIP_TRANSPORT_UDP, submwil, sip_subscription_mwi::transport, and sip_subscription_mwi::username.
Referenced by reload_config().
07774 { 07775 struct sip_subscription_mwi *mwi; 07776 int portnum = 0; 07777 enum sip_transport transport = SIP_TRANSPORT_UDP; 07778 char buf[256] = ""; 07779 char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL; 07780 07781 if (!value) { 07782 return -1; 07783 } 07784 07785 ast_copy_string(buf, value, sizeof(buf)); 07786 07787 sip_parse_host(buf, lineno, &username, &portnum, &transport); 07788 07789 if ((hostname = strrchr(username, '@'))) { 07790 *hostname++ = '\0'; 07791 } 07792 07793 if ((secret = strchr(username, ':'))) { 07794 *secret++ = '\0'; 07795 if ((authuser = strchr(secret, ':'))) { 07796 *authuser++ = '\0'; 07797 } 07798 } 07799 07800 if ((mailbox = strchr(hostname, '/'))) { 07801 *mailbox++ = '\0'; 07802 } 07803 07804 if (ast_strlen_zero(username) || ast_strlen_zero(hostname) || ast_strlen_zero(mailbox)) { 07805 ast_log(LOG_WARNING, "Format for MWI subscription is user[:secret[:authuser]]@host[:port][/mailbox] at line %d\n", lineno); 07806 return -1; 07807 } 07808 07809 if ((porta = strchr(hostname, ':'))) { 07810 *porta++ = '\0'; 07811 if (!(portnum = atoi(porta))) { 07812 ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno); 07813 return -1; 07814 } 07815 } 07816 07817 if (!(mwi = ast_calloc(1, sizeof(*mwi)))) { 07818 return -1; 07819 } 07820 07821 if (ast_string_field_init(mwi, 256)) { 07822 ast_free(mwi); 07823 return -1; 07824 } 07825 07826 ASTOBJ_INIT(mwi); 07827 ast_string_field_set(mwi, username, username); 07828 if (secret) { 07829 ast_string_field_set(mwi, secret, secret); 07830 } 07831 if (authuser) { 07832 ast_string_field_set(mwi, authuser, authuser); 07833 } 07834 ast_string_field_set(mwi, hostname, hostname); 07835 ast_string_field_set(mwi, mailbox, mailbox); 07836 mwi->resub = -1; 07837 mwi->portno = portnum; 07838 mwi->transport = transport; 07839 07840 ASTOBJ_CONTAINER_LINK(&submwil, mwi); 07841 ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy); 07842 07843 return 0; 07844 }
| static void sip_subscribe_mwi_destroy | ( | struct sip_subscription_mwi * | mwi | ) | [static] |
Destroy MWI subscription object.
Definition at line 5559 of file chan_sip.c.
References ast_dnsmgr_release(), ast_free, AST_SCHED_DEL, ast_string_field_free_memory, sip_subscription_mwi::call, sip_subscription_mwi::dnsmgr, sip_pvt::mwi, sip_subscription_mwi::resub, and sip_destroy().
Referenced by handle_response_subscribe(), sip_send_all_mwi_subscriptions(), sip_subscribe_mwi(), sip_subscribe_mwi_do(), and unload_module().
05560 { 05561 if (mwi->call) { 05562 mwi->call->mwi = NULL; 05563 sip_destroy(mwi->call); 05564 } 05565 05566 AST_SCHED_DEL(sched, mwi->resub); 05567 ast_string_field_free_memory(mwi); 05568 ast_dnsmgr_release(mwi->dnsmgr); 05569 ast_free(mwi); 05570 }
| static int sip_subscribe_mwi_do | ( | const void * | data | ) | [static] |
Send a subscription or resubscription for MWI.
Definition at line 11114 of file chan_sip.c.
References __sip_subscribe_mwi_do(), ASTOBJ_UNREF, sip_subscription_mwi::resub, and sip_subscribe_mwi_destroy().
Referenced by handle_response_subscribe(), and sip_send_all_mwi_subscriptions().
11115 { 11116 struct sip_subscription_mwi *mwi = (struct sip_subscription_mwi*)data; 11117 11118 if (!mwi) { 11119 return -1; 11120 } 11121 11122 mwi->resub = -1; 11123 __sip_subscribe_mwi_do(mwi); 11124 ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy); 11125 11126 return 0; 11127 }
| static int sip_t38_abort | ( | const void * | data | ) | [static] |
Called to deny a T38 reinvite if the core does not respond to our request.
Definition at line 19840 of file chan_sip.c.
References change_t38_state(), dialog_unref(), sip_pvt::initreq, sip_pvt_lock, sip_pvt_unlock, T38_DISABLED, sip_pvt::t38id, and transmit_response_reliable().
Referenced by handle_request_invite().
19841 { 19842 struct sip_pvt *p = (struct sip_pvt *) data; 19843 19844 sip_pvt_lock(p); 19845 /* an application may have taken ownership of the T.38 negotiation on this 19846 * channel while we were waiting to grab the lock... if it did, the scheduler 19847 * id will have been reset to -1, which is our indication that we do *not* 19848 * want to abort the negotiation process 19849 */ 19850 if (p->t38id != -1) { 19851 change_t38_state(p, T38_DISABLED); 19852 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 19853 p->t38id = -1; 19854 dialog_unref(p, "unref the dialog ptr from sip_t38_abort, because it held a dialog ptr"); 19855 } 19856 sip_pvt_unlock(p); 19857 return 0; 19858 }
| static struct ast_tcptls_session_instance* sip_tcp_locate | ( | struct sockaddr_in * | s | ) | [static, read] |
Find thread for TCP/TLS session (based on IP/Port.
Definition at line 22310 of file chan_sip.c.
References ao2_callback, ao2_ref, ao2_t_ref, sip_threadinfo::tcptls_session, and threadinfo_locate_cb().
Referenced by sip_prepare_socket().
22311 { 22312 struct sip_threadinfo *th; 22313 struct ast_tcptls_session_instance *tcptls_instance = NULL; 22314 22315 if ((th = ao2_callback(threadt, 0, threadinfo_locate_cb, s))) { 22316 tcptls_instance = (ao2_ref(th->tcptls_session, +1), th->tcptls_session); 22317 ao2_t_ref(th, -1, "decrement ref from callback"); 22318 } 22319 return tcptls_instance; 22320 }
| static void * sip_tcp_worker_fn | ( | void * | data | ) | [static] |
SIP TCP connection handler.
Definition at line 2896 of file chan_sip.c.
References _sip_tcp_helper_thread().
Referenced by sip_prepare_socket().
02897 { 02898 struct ast_tcptls_session_instance *tcptls_session = data; 02899 02900 return _sip_tcp_helper_thread(NULL, tcptls_session); 02901 }
| static void sip_tcptls_client_args_destructor | ( | void * | obj | ) | [static] |
Definition at line 2779 of file chan_sip.c.
References ast_free, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, ast_tcptls_session_args::name, and ast_tcptls_session_args::tls_cfg.
Referenced by sip_prepare_socket().
02780 { 02781 struct ast_tcptls_session_args *args = obj; 02782 if (args->tls_cfg) { 02783 ast_free(args->tls_cfg->certfile); 02784 ast_free(args->tls_cfg->cipher); 02785 ast_free(args->tls_cfg->cafile); 02786 ast_free(args->tls_cfg->capath); 02787 } 02788 ast_free(args->tls_cfg); 02789 ast_free((char *) args->name); 02790 }
| static int sip_tcptls_write | ( | struct ast_tcptls_session_instance * | tcptls_session, | |
| const void * | buf, | |||
| size_t | len | |||
| ) | [static] |
used to indicate to a tcptls thread that data is ready to be written
Definition at line 2838 of file chan_sip.c.
References sip_threadinfo::alert_pipe, ao2_alloc, ao2_lock(), ao2_t_find, ao2_t_ref, ao2_unlock(), AST_LIST_INSERT_TAIL, ast_log(), ast_mutex_lock(), ast_mutex_unlock(), ast_str_create(), ast_str_set(), tcptls_packet::data, errno, ast_tcptls_session_instance::fd, tcptls_packet::len, ast_tcptls_session_instance::lock, LOG_ERROR, OBJ_POINTER, sip_threadinfo::packet_q, TCPTLS_ALERT_DATA, tcptls_packet_destructor(), sip_threadinfo::tcptls_session, and XMIT_ERROR.
Referenced by __sip_xmit().
02839 { 02840 int res = len; 02841 struct sip_threadinfo *th = NULL; 02842 struct tcptls_packet *packet = NULL; 02843 struct sip_threadinfo tmp = { 02844 .tcptls_session = tcptls_session, 02845 }; 02846 enum sip_tcptls_alert alert = TCPTLS_ALERT_DATA; 02847 02848 if (!tcptls_session) { 02849 return XMIT_ERROR; 02850 } 02851 02852 ast_mutex_lock(&tcptls_session->lock); 02853 02854 if ((tcptls_session->fd == -1) || 02855 !(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) || 02856 !(packet = ao2_alloc(sizeof(*packet), tcptls_packet_destructor)) || 02857 !(packet->data = ast_str_create(len))) { 02858 goto tcptls_write_setup_error; 02859 } 02860 02861 /* goto tcptls_write_error should _NOT_ be used beyond this point */ 02862 ast_str_set(&packet->data, 0, "%s", (char *) buf); 02863 packet->len = len; 02864 02865 /* alert tcptls thread handler that there is a packet to be sent. 02866 * must lock the thread info object to guarantee control of the 02867 * packet queue */ 02868 ao2_lock(th); 02869 if (write(th->alert_pipe[1], &alert, sizeof(alert)) == -1) { 02870 ast_log(LOG_ERROR, "write() to alert pipe failed: %s\n", strerror(errno)); 02871 ao2_t_ref(packet, -1, "could not write to alert pipe, remove packet"); 02872 packet = NULL; 02873 res = XMIT_ERROR; 02874 } else { /* it is safe to queue the frame after issuing the alert when we hold the threadinfo lock */ 02875 AST_LIST_INSERT_TAIL(&th->packet_q, packet, entry); 02876 } 02877 ao2_unlock(th); 02878 02879 ast_mutex_unlock(&tcptls_session->lock); 02880 ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo object after finding it"); 02881 return res; 02882 02883 tcptls_write_setup_error: 02884 if (th) { 02885 ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo obj, could not create packet"); 02886 } 02887 if (packet) { 02888 ao2_t_ref(packet, -1, "could not allocate packet's data"); 02889 } 02890 ast_mutex_unlock(&tcptls_session->lock); 02891 02892 return XMIT_ERROR; 02893 }
| static struct sip_threadinfo* sip_threadinfo_create | ( | struct ast_tcptls_session_instance * | tcptls_session, | |
| int | transport | |||
| ) | [static, read] |
creates a sip_threadinfo object and links it into the threadt table.
Definition at line 2814 of file chan_sip.c.
References sip_threadinfo::alert_pipe, ao2_alloc, ao2_t_link, ao2_t_ref, ast_log(), errno, LOG_ERROR, sip_threadinfo_destructor(), SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, ast_tcptls_session_instance::ssl, sip_threadinfo::tcptls_session, and sip_threadinfo::type.
Referenced by _sip_tcp_helper_thread(), and sip_prepare_socket().
02815 { 02816 struct sip_threadinfo *th; 02817 02818 if (!tcptls_session || !(th = ao2_alloc(sizeof(*th), sip_threadinfo_destructor))) { 02819 return NULL; 02820 } 02821 02822 th->alert_pipe[0] = th->alert_pipe[1] = -1; 02823 02824 if (pipe(th->alert_pipe) == -1) { 02825 ao2_t_ref(th, -1, "Failed to open alert pipe on sip_threadinfo"); 02826 ast_log(LOG_ERROR, "Could not create sip alert pipe in tcptls thread, error %s\n", strerror(errno)); 02827 return NULL; 02828 } 02829 ao2_t_ref(tcptls_session, +1, "tcptls_session ref for sip_threadinfo object"); 02830 th->tcptls_session = tcptls_session; 02831 th->type = transport ? transport : (tcptls_session->ssl ? SIP_TRANSPORT_TLS: SIP_TRANSPORT_TCP); 02832 ao2_t_link(threadt, th, "Adding new tcptls helper thread"); 02833 ao2_t_ref(th, -1, "Decrementing threadinfo ref from alloc, only table ref remains"); 02834 return th; 02835 }
| static void sip_threadinfo_destructor | ( | void * | obj | ) | [static] |
Definition at line 2792 of file chan_sip.c.
References sip_threadinfo::alert_pipe, ao2_t_ref, AST_LIST_REMOVE_HEAD, sip_threadinfo::packet_q, and sip_threadinfo::tcptls_session.
Referenced by sip_threadinfo_create().
02793 { 02794 struct sip_threadinfo *th = obj; 02795 struct tcptls_packet *packet; 02796 if (th->alert_pipe[1] > -1) { 02797 close(th->alert_pipe[0]); 02798 } 02799 if (th->alert_pipe[1] > -1) { 02800 close(th->alert_pipe[1]); 02801 } 02802 th->alert_pipe[0] = th->alert_pipe[1] = -1; 02803 02804 while ((packet = AST_LIST_REMOVE_HEAD(&th->packet_q, entry))) { 02805 ao2_t_ref(packet, -1, "thread destruction, removing packet from frame queue"); 02806 } 02807 02808 if (th->tcptls_session) { 02809 ao2_t_ref(th->tcptls_session, -1, "remove tcptls_session for sip_threadinfo object"); 02810 } 02811 }
| static int sip_transfer | ( | struct ast_channel * | ast, | |
| const char * | dest | |||
| ) | [static] |
Transfer SIP call.
Definition at line 6481 of file chan_sip.c.
References ast_channel::_state, AST_STATE_RING, sip_pvt_lock, sip_pvt_unlock, sip_sipredirect(), ast_channel::tech_pvt, and transmit_refer().
06482 { 06483 struct sip_pvt *p = ast->tech_pvt; 06484 int res; 06485 06486 if (dest == NULL) /* functions below do not take a NULL */ 06487 dest = ""; 06488 sip_pvt_lock(p); 06489 if (ast->_state == AST_STATE_RING) 06490 res = sip_sipredirect(p, dest); 06491 else 06492 res = transmit_refer(p, dest); 06493 sip_pvt_unlock(p); 06494 return res; 06495 }
| static char * sip_unregister | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Unregister (force expiration) a SIP peer in the registry via CLI.
Definition at line 16005 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_SCHED_DEL_UNREF, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_unregister(), sip_peer::expire, expire_register(), ast_cli_args::fd, find_peer(), FINDPEERS, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ref_peer(), TRUE, unref_peer(), ast_cli_entry::usage, and ast_cli_args::word.
16006 { 16007 struct sip_peer *peer; 16008 int load_realtime = 0; 16009 16010 switch (cmd) { 16011 case CLI_INIT: 16012 e->command = "sip unregister"; 16013 e->usage = 16014 "Usage: sip unregister <peer>\n" 16015 " Unregister (force expiration) a SIP peer from the registry\n"; 16016 return NULL; 16017 case CLI_GENERATE: 16018 return complete_sip_unregister(a->line, a->word, a->pos, a->n); 16019 } 16020 16021 if (a->argc != 3) 16022 return CLI_SHOWUSAGE; 16023 16024 if ((peer = find_peer(a->argv[2], NULL, load_realtime, FINDPEERS, TRUE, 0))) { 16025 if (peer->expire > 0) { 16026 AST_SCHED_DEL_UNREF(sched, peer->expire, 16027 unref_peer(peer, "remove register expire ref")); 16028 expire_register(ref_peer(peer, "ref for expire_register")); 16029 ast_cli(a->fd, "Unregistered peer \'%s\'\n\n", a->argv[2]); 16030 } else { 16031 ast_cli(a->fd, "Peer %s not registered\n", a->argv[2]); 16032 } 16033 unref_peer(peer, "sip_unregister: unref_peer via sip_unregister: done with peer from find_peer call"); 16034 } else { 16035 ast_cli(a->fd, "Peer unknown: \'%s\'. Not unregistered.\n", a->argv[2]); 16036 } 16037 16038 return CLI_SUCCESS; 16039 }
| static int sip_uri_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
Definition at line 19735 of file chan_sip.c.
References ast_strdupa, S_OR, sip_uri_headers_cmp(), sip_uri_params_cmp(), and strsep().
Referenced by handle_request_invite().
19736 { 19737 char *uri1 = ast_strdupa(input1); 19738 char *uri2 = ast_strdupa(input2); 19739 char *host1; 19740 char *host2; 19741 char *params1; 19742 char *params2; 19743 char *headers1; 19744 char *headers2; 19745 19746 /* Strip off "sip:" from the URI. We know this is present 19747 * because it was checked back in parse_request() 19748 */ 19749 strsep(&uri1, ":"); 19750 strsep(&uri2, ":"); 19751 19752 if ((host1 = strchr(uri1, '@'))) { 19753 *host1++ = '\0'; 19754 } 19755 if ((host2 = strchr(uri2, '@'))) { 19756 *host2++ = '\0'; 19757 } 19758 19759 /* Check for mismatched username and passwords. This is the 19760 * only case-sensitive comparison of a SIP URI 19761 */ 19762 if ((host1 && !host2) || 19763 (host2 && !host1) || 19764 (host1 && host2 && strcmp(uri1, uri2))) { 19765 return 1; 19766 } 19767 19768 if (!host1) 19769 host1 = uri1; 19770 if (!host2) 19771 host2 = uri2; 19772 19773 /* Strip off the parameters and headers so we can compare 19774 * host and port 19775 */ 19776 19777 if ((params1 = strchr(host1, ';'))) { 19778 *params1++ = '\0'; 19779 } 19780 if ((params2 = strchr(host2, ';'))) { 19781 *params2++ = '\0'; 19782 } 19783 19784 /* Headers come after parameters, but there may be headers without 19785 * parameters, thus the S_OR 19786 */ 19787 if ((headers1 = strchr(S_OR(params1, host1), '?'))) { 19788 *headers1++ = '\0'; 19789 } 19790 if ((headers2 = strchr(S_OR(params2, host2), '?'))) { 19791 *headers2++ = '\0'; 19792 } 19793 19794 /* Now the host/port are properly isolated. We can get by with a string comparison 19795 * because the SIP URI checking rules have some interesting exceptions that make 19796 * this possible. I will note 2 in particular 19797 * 1. hostnames which resolve to the same IP address as well as a hostname and its 19798 * IP address are not considered a match with SIP URI's. 19799 * 2. If one URI specifies a port and the other does not, then the URIs do not match. 19800 * This includes if one URI explicitly contains port 5060 and the other implies it 19801 * by not having a port specified. 19802 */ 19803 19804 if (strcasecmp(host1, host2)) { 19805 return 1; 19806 } 19807 19808 /* Headers have easier rules to follow, so do those first */ 19809 if (sip_uri_headers_cmp(headers1, headers2)) { 19810 return 1; 19811 } 19812 19813 /* And now the parameters. Ugh */ 19814 return sip_uri_params_cmp(params1, params2); 19815 }
| static int sip_uri_headers_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
helper routine for sip_uri_cmp
This takes the "headers" from two SIP URIs and determines if the URIs match. The rules for headers is simple. If a header appears in one URI, then it must also appear in the other URI. The order in which the headers appear does not matter.
| input1 | Headers from URI 1 | |
| input2 | Headers from URI 2 |
Definition at line 19689 of file chan_sip.c.
References ast_strdupa, ast_strlen_zero(), strcasestr(), and strsep().
Referenced by sip_uri_cmp().
19690 { 19691 char *headers1 = NULL; 19692 char *headers2 = NULL; 19693 int zerolength1 = 0; 19694 int zerolength2 = 0; 19695 int different = 0; 19696 char *header1; 19697 19698 if (ast_strlen_zero(input1)) { 19699 zerolength1 = 1; 19700 } else { 19701 headers1 = ast_strdupa(input1); 19702 } 19703 19704 if (ast_strlen_zero(input2)) { 19705 zerolength2 = 1; 19706 } else { 19707 headers2 = ast_strdupa(input2); 19708 } 19709 19710 if ((zerolength1 && !zerolength2) || 19711 (zerolength2 && !zerolength1)) 19712 return 1; 19713 19714 if (zerolength1 && zerolength2) 19715 return 0; 19716 19717 /* At this point, we can definitively state that both inputs are 19718 * not zero-length. First, one more optimization. If the length 19719 * of the headers is not equal, then we definitely have no match 19720 */ 19721 if (strlen(headers1) != strlen(headers2)) { 19722 return 1; 19723 } 19724 19725 for (header1 = strsep(&headers1, "&"); header1; header1 = strsep(&headers1, "&")) { 19726 if (!strcasestr(headers2, header1)) { 19727 different = 1; 19728 break; 19729 } 19730 } 19731 19732 return different; 19733 }
| static int sip_uri_params_cmp | ( | const char * | input1, | |
| const char * | input2 | |||
| ) | [static] |
helper routine for sip_uri_cmp to compare URI parameters
This takes the parameters from two SIP URIs and determines if the URIs match. The rules for parameters *suck*. Here's a breakdown 1. If a parameter appears in both URIs, then they must have the same value in order for the URIs to match 2. If one URI has a user, maddr, ttl, or method parameter, then the other URI must also have that parameter and must have the same value in order for the URIs to match 3. All other headers appearing in only one URI are not considered when determining if URIs match
| input1 | Parameters from URI 1 | |
| input2 | Parameters from URI 2 |
| 0 | URIs' parameters match | |
| nonzero | URIs' parameters do not match |
Definition at line 19564 of file chan_sip.c.
References ast_strdupa, ast_strlen_zero(), and strsep().
Referenced by sip_uri_cmp().
19565 { 19566 char *params1 = NULL; 19567 char *params2 = NULL; 19568 char *pos1; 19569 char *pos2; 19570 int zerolength1 = 0; 19571 int zerolength2 = 0; 19572 int maddrmatch = 0; 19573 int ttlmatch = 0; 19574 int usermatch = 0; 19575 int methodmatch = 0; 19576 19577 if (ast_strlen_zero(input1)) { 19578 zerolength1 = 1; 19579 } else { 19580 params1 = ast_strdupa(input1); 19581 } 19582 if (ast_strlen_zero(input2)) { 19583 zerolength2 = 1; 19584 } else { 19585 params2 = ast_strdupa(input2); 19586 } 19587 19588 /* Quick optimization. If both params are zero-length, then 19589 * they match 19590 */ 19591 if (zerolength1 && zerolength2) { 19592 return 0; 19593 } 19594 19595 for (pos1 = strsep(¶ms1, ";"); pos1; pos1 = strsep(¶ms1, ";")) { 19596 char *value1 = pos1; 19597 char *name1 = strsep(&value1, "="); 19598 char *params2dup = NULL; 19599 int matched = 0; 19600 if (!value1) { 19601 value1 = ""; 19602 } 19603 /* Checkpoint reached. We have the name and value parsed for param1 19604 * We have to duplicate params2 each time through this loop 19605 * or else the inner loop below will not work properly. 19606 */ 19607 if (!zerolength2) { 19608 params2dup = ast_strdupa(params2); 19609 } 19610 for (pos2 = strsep(¶ms2dup, ";"); pos2; pos2 = strsep(¶ms2dup, ";")) { 19611 char *name2 = pos2; 19612 char *value2 = strchr(pos2, '='); 19613 if (!value2) { 19614 value2 = ""; 19615 } else { 19616 *value2++ = '\0'; 19617 } 19618 if (!strcasecmp(name1, name2)) { 19619 if (strcasecmp(value1, value2)) { 19620 goto fail; 19621 } else { 19622 matched = 1; 19623 break; 19624 } 19625 } 19626 } 19627 /* Check to see if the parameter is one of the 'must-match' parameters */ 19628 if (!strcasecmp(name1, "maddr")) { 19629 if (matched) { 19630 maddrmatch = 1; 19631 } else { 19632 goto fail; 19633 } 19634 } else if (!strcasecmp(name1, "ttl")) { 19635 if (matched) { 19636 ttlmatch = 1; 19637 } else { 19638 goto fail; 19639 } 19640 } else if (!strcasecmp(name1, "user")) { 19641 if (matched) { 19642 usermatch = 1; 19643 } else { 19644 goto fail; 19645 } 19646 } else if (!strcasecmp(name1, "method")) { 19647 if (matched) { 19648 methodmatch = 1; 19649 } else { 19650 goto fail; 19651 } 19652 } 19653 } 19654 19655 /* We've made it out of that horrible O(m*n) construct and there are no 19656 * failures yet. We're not done yet, though, because params2 could have 19657 * an maddr, ttl, user, or method header and params1 did not. 19658 */ 19659 for (pos2 = strsep(¶ms2, ";"); pos2; pos2 = strsep(¶ms2, ";")) { 19660 char *value2 = pos2; 19661 char *name2 = strsep(&value2, "="); 19662 if (!value2) { 19663 value2 = ""; 19664 } 19665 if ((!strcasecmp(name2, "maddr") && !maddrmatch) || 19666 (!strcasecmp(name2, "ttl") && !ttlmatch) || 19667 (!strcasecmp(name2, "user") && !usermatch) || 19668 (!strcasecmp(name2, "method") && !methodmatch)) { 19669 goto fail; 19670 } 19671 } 19672 return 0; 19673 19674 fail: 19675 return 1; 19676 }
| static int sip_write | ( | struct ast_channel * | ast, | |
| struct ast_frame * | frame | |||
| ) | [static] |
Send frame to media channel (rtp).
Definition at line 6281 of file chan_sip.c.
References ast_channel::_state, AST_FORMAT_AUDIO_MASK, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_getformatname_multiple(), ast_log(), ast_rtp_new_source(), ast_rtp_write(), ast_set_flag, AST_STATE_UP, ast_test_flag, ast_udptl_write(), sip_pvt::flags, ast_frame::frametype, sip_pvt::initreq, INV_EARLY_MEDIA, sip_pvt::invitestate, sip_pvt::lastrtptx, LOG_WARNING, ast_channel::nativeformats, ast_channel::readformat, sip_pvt::red, red_buffer_t140(), sip_pvt::rtp, SIP_OUTGOING, SIP_PROGRESS_SENT, sip_pvt_lock, sip_pvt_unlock, t38properties::state, ast_frame::subclass, sip_pvt::t38, T38_ENABLED, ast_channel::tech_pvt, transmit_provisional_response(), sip_pvt::trtp, TRUE, sip_pvt::udptl, sip_pvt::vrtp, and ast_channel::writeformat.
06282 { 06283 struct sip_pvt *p = ast->tech_pvt; 06284 int res = 0; 06285 06286 switch (frame->frametype) { 06287 case AST_FRAME_VOICE: 06288 if (!(frame->subclass & ast->nativeformats)) { 06289 char s1[512], s2[512], s3[512]; 06290 ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %s(%d) read/write = %s(%d)/%s(%d)\n", 06291 frame->subclass, 06292 ast_getformatname_multiple(s1, sizeof(s1) - 1, ast->nativeformats & AST_FORMAT_AUDIO_MASK), 06293 ast->nativeformats & AST_FORMAT_AUDIO_MASK, 06294 ast_getformatname_multiple(s2, sizeof(s2) - 1, ast->readformat), 06295 ast->readformat, 06296 ast_getformatname_multiple(s3, sizeof(s3) - 1, ast->writeformat), 06297 ast->writeformat); 06298 return 0; 06299 } 06300 if (p) { 06301 sip_pvt_lock(p); 06302 if (p->rtp) { 06303 /* If channel is not up, activate early media session */ 06304 if ((ast->_state != AST_STATE_UP) && 06305 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06306 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06307 ast_rtp_new_source(p->rtp); 06308 if (!global_prematuremediafilter) { 06309 p->invitestate = INV_EARLY_MEDIA; 06310 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06311 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06312 } 06313 } else if (p->t38.state == T38_ENABLED) { 06314 /* drop frame, can't sent VOICE frames while in T.38 mode */ 06315 } else { 06316 p->lastrtptx = time(NULL); 06317 res = ast_rtp_write(p->rtp, frame); 06318 } 06319 } 06320 sip_pvt_unlock(p); 06321 } 06322 break; 06323 case AST_FRAME_VIDEO: 06324 if (p) { 06325 sip_pvt_lock(p); 06326 if (p->vrtp) { 06327 /* Activate video early media */ 06328 if ((ast->_state != AST_STATE_UP) && 06329 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06330 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06331 p->invitestate = INV_EARLY_MEDIA; 06332 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06333 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06334 } 06335 p->lastrtptx = time(NULL); 06336 res = ast_rtp_write(p->vrtp, frame); 06337 } 06338 sip_pvt_unlock(p); 06339 } 06340 break; 06341 case AST_FRAME_TEXT: 06342 if (p) { 06343 sip_pvt_lock(p); 06344 if (p->red) { 06345 red_buffer_t140(p->trtp, frame); 06346 } else { 06347 if (p->trtp) { 06348 /* Activate text early media */ 06349 if ((ast->_state != AST_STATE_UP) && 06350 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06351 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06352 p->invitestate = INV_EARLY_MEDIA; 06353 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06354 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06355 } 06356 p->lastrtptx = time(NULL); 06357 res = ast_rtp_write(p->trtp, frame); 06358 } 06359 } 06360 sip_pvt_unlock(p); 06361 } 06362 break; 06363 case AST_FRAME_IMAGE: 06364 return 0; 06365 break; 06366 case AST_FRAME_MODEM: 06367 if (p) { 06368 sip_pvt_lock(p); 06369 /* UDPTL requires two-way communication, so early media is not needed here. 06370 we simply forget the frames if we get modem frames before the bridge is up. 06371 Fax will re-transmit. 06372 */ 06373 if ((ast->_state == AST_STATE_UP) && 06374 p->udptl && 06375 (p->t38.state == T38_ENABLED)) { 06376 res = ast_udptl_write(p->udptl, frame); 06377 } 06378 sip_pvt_unlock(p); 06379 } 06380 break; 06381 default: 06382 ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype); 06383 return 0; 06384 } 06385 06386 return res; 06387 }
| static int sipsock_read | ( | int * | id, | |
| int | fd, | |||
| short | events, | |||
| void * | ignore | |||
| ) | [static] |
Read data from SIP UDP socket.
Definition at line 22123 of file chan_sip.c.
References AST_DYNSTR_BUILD_FAILED, ast_log(), ast_str_create(), ast_str_set(), bindaddr, sip_request::data, deinit_req(), errno, sip_socket::fd, handle_request_do(), sip_request::len, LOG_NOTICE, LOG_WARNING, sip_socket::port, set_socket_transport(), SIP_MIN_PACKET, SIP_TRANSPORT_UDP, sip_request::socket, and sip_socket::tcptls_session.
Referenced by do_monitor().
22124 { 22125 struct sip_request req; 22126 struct sockaddr_in sin = { 0, }; 22127 int res; 22128 socklen_t len = sizeof(sin); 22129 static char readbuf[65535]; 22130 22131 memset(&req, 0, sizeof(req)); 22132 res = recvfrom(fd, readbuf, sizeof(readbuf) - 1, 0, (struct sockaddr *)&sin, &len); 22133 if (res < 0) { 22134 #if !defined(__FreeBSD__) 22135 if (errno == EAGAIN) 22136 ast_log(LOG_NOTICE, "SIP: Received packet with bad UDP checksum\n"); 22137 else 22138 #endif 22139 if (errno != ECONNREFUSED) 22140 ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno)); 22141 return 1; 22142 } 22143 22144 readbuf[res] = '\0'; 22145 22146 if (!(req.data = ast_str_create(SIP_MIN_PACKET))) { 22147 return 1; 22148 } 22149 22150 if (ast_str_set(&req.data, 0, "%s", readbuf) == AST_DYNSTR_BUILD_FAILED) { 22151 return -1; 22152 } 22153 22154 req.len = res; 22155 req.socket.fd = sipsock; 22156 set_socket_transport(&req.socket, SIP_TRANSPORT_UDP); 22157 req.socket.tcptls_session = NULL; 22158 req.socket.port = bindaddr.sin_port; 22159 22160 handle_request_do(&req, &sin); 22161 deinit_req(&req); 22162 22163 return 1; 22164 }
Get the session-timer mode.
| p | pointer to the SIP dialog |
Definition at line 23059 of file chan_sip.c.
References FALSE, find_peer(), FINDPEERS, sip_pvt::peername, pp, SESSION_TIMER_MODE_INVALID, sip_st_alloc(), sip_st_dlg::st_cached_mode, sip_st_cfg::st_mode_oper, sip_peer::stimer, sip_pvt::stimer, TRUE, and unref_peer().
Referenced by add_supported_header(), handle_request_invite(), handle_response_invite(), and transmit_invite().
23060 { 23061 if (!p->stimer) 23062 sip_st_alloc(p); 23063 23064 if (p->stimer->st_cached_mode != SESSION_TIMER_MODE_INVALID) 23065 return p->stimer->st_cached_mode; 23066 23067 if (p->peername) { 23068 struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0); 23069 if (pp) { 23070 p->stimer->st_cached_mode = pp->stimer.st_mode_oper; 23071 unref_peer(pp, "unref peer pointer from find_peer call in st_get_mode"); 23072 return pp->stimer.st_mode_oper; 23073 } 23074 } 23075 23076 p->stimer->st_cached_mode = global_st_mode; 23077 return global_st_mode; 23078 }
| enum st_refresher st_get_refresher | ( | struct sip_pvt * | p | ) | [static] |
Get the entity (UAC or UAS) that's acting as the session-timer refresher.
| p | pointer to the SIP dialog |
Definition at line 23037 of file chan_sip.c.
References FALSE, find_peer(), FINDPEERS, sip_pvt::peername, pp, SESSION_TIMER_REFRESHER_AUTO, sip_st_dlg::st_cached_ref, sip_st_cfg::st_ref, sip_peer::stimer, sip_pvt::stimer, TRUE, and unref_peer().
Referenced by handle_request_invite().
23038 { 23039 if (p->stimer->st_cached_ref != SESSION_TIMER_REFRESHER_AUTO) 23040 return p->stimer->st_cached_ref; 23041 23042 if (p->peername) { 23043 struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0); 23044 if (pp) { 23045 p->stimer->st_cached_ref = pp->stimer.st_ref; 23046 unref_peer(pp, "unref peer pointer from find_peer call in st_get_refresher"); 23047 return pp->stimer.st_ref; 23048 } 23049 } 23050 23051 p->stimer->st_cached_ref = global_st_refresher; 23052 return global_st_refresher; 23053 }
| int st_get_se | ( | struct sip_pvt * | p, | |
| int | max | |||
| ) | [static] |
Get Max or Min SE (session timer expiry).
| p | pointer to the SIP dialog | |
| max | if true, get max se, otherwise min se |
Definition at line 23002 of file chan_sip.c.
References FALSE, find_peer(), FINDPEERS, sip_pvt::peername, pp, sip_st_dlg::st_cached_max_se, sip_st_dlg::st_cached_min_se, sip_st_cfg::st_max_se, sip_st_cfg::st_min_se, sip_peer::stimer, sip_pvt::stimer, TRUE, and unref_peer().
Referenced by handle_request_invite(), reqprep(), and transmit_invite().
23003 { 23004 if (max == TRUE) { 23005 if (p->stimer->st_cached_max_se) { 23006 return p->stimer->st_cached_max_se; 23007 } else if (p->peername) { 23008 struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0); 23009 if (pp) { 23010 p->stimer->st_cached_max_se = pp->stimer.st_max_se; 23011 unref_peer(pp, "unref peer pointer from find_peer call in st_get_se"); 23012 return (p->stimer->st_cached_max_se); 23013 } 23014 } 23015 p->stimer->st_cached_max_se = global_max_se; 23016 return (p->stimer->st_cached_max_se); 23017 } else { 23018 if (p->stimer->st_cached_min_se) { 23019 return p->stimer->st_cached_min_se; 23020 } else if (p->peername) { 23021 struct sip_peer *pp = find_peer(p->peername, NULL, TRUE, FINDPEERS, FALSE, 0); 23022 if (pp) { 23023 p->stimer->st_cached_min_se = pp->stimer.st_min_se; 23024 unref_peer(pp, "unref peer pointer from find_peer call in st_get_se (2)"); 23025 return (p->stimer->st_cached_min_se); 23026 } 23027 } 23028 p->stimer->st_cached_min_se = global_min_se; 23029 return (p->stimer->st_cached_min_se); 23030 } 23031 }
| static void start_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Start session timer.
Definition at line 22799 of file chan_sip.c.
References ast_debug, ast_log(), ast_sched_add(), sip_pvt::callid, dialog_ref(), dialog_unref(), LOG_ERROR, LOG_WARNING, proc_session_timer(), sip_st_dlg::st_interval, sip_st_dlg::st_schedid, and sip_pvt::stimer.
Referenced by handle_request_invite(), handle_response_invite(), and restart_session_timer().
22800 { 22801 if (!p->stimer) { 22802 ast_log(LOG_WARNING, "Null stimer in start_session_timer - %s\n", p->callid); 22803 return; 22804 } 22805 22806 p->stimer->st_schedid = ast_sched_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, 22807 dialog_ref(p, "adding session timer ref")); 22808 if (p->stimer->st_schedid < 0) { 22809 dialog_unref(p, "removing session timer ref"); 22810 ast_log(LOG_ERROR, "ast_sched_add failed.\n"); 22811 } 22812 ast_debug(2, "Session timer started: %d - %s\n", p->stimer->st_schedid, p->callid); 22813 }
| static const char* stmode2str | ( | enum st_mode | m | ) | [static] |
Definition at line 14606 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_user().
| static void stop_media_flows | ( | struct sip_pvt * | p | ) | [static] |
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition at line 18481 of file chan_sip.c.
References ast_rtp_stop(), ast_udptl_stop(), sip_pvt::rtp, sip_pvt::trtp, sip_pvt::udptl, and sip_pvt::vrtp.
Referenced by handle_request_bye(), handle_request_cancel(), handle_response(), and sip_hangup().
18482 { 18483 /* Immediately stop RTP, VRTP and UDPTL as applicable */ 18484 if (p->rtp) 18485 ast_rtp_stop(p->rtp); 18486 if (p->vrtp) 18487 ast_rtp_stop(p->vrtp); 18488 if (p->trtp) 18489 ast_rtp_stop(p->trtp); 18490 if (p->udptl) 18491 ast_udptl_stop(p->udptl); 18492 }
| static void stop_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Stop session timer.
Definition at line 22782 of file chan_sip.c.
References ast_debug, ast_log(), AST_SCHED_DEL_UNREF, sip_pvt::callid, dialog_unref(), FALSE, LOG_WARNING, sip_st_dlg::st_active, sip_st_dlg::st_schedid, sip_pvt::stimer, and TRUE.
Referenced by handle_request_bye(), proc_session_timer(), sip_hangup(), and sip_scheddestroy().
22783 { 22784 if (!p->stimer) { 22785 ast_log(LOG_WARNING, "Null stimer in stop_session_timer - %s\n", p->callid); 22786 return; 22787 } 22788 22789 if (p->stimer->st_active == TRUE) { 22790 p->stimer->st_active = FALSE; 22791 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 22792 dialog_unref(p, "removing session timer ref")); 22793 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 22794 } 22795 }
| static int str2dtmfmode | ( | const char * | str | ) | [static] |
| static enum st_mode str2stmode | ( | const char * | s | ) | [static] |
Definition at line 14611 of file chan_sip.c.
References map_s_x().
Referenced by build_peer(), and reload_config().
| static enum st_refresher str2strefresher | ( | const char * | s | ) | [static] |
Definition at line 14629 of file chan_sip.c.
References map_s_x().
Referenced by build_peer(), and reload_config().
14630 { 14631 return map_s_x(strefreshers, s, -1); 14632 }
| static const char * strefresher2str | ( | enum st_refresher | r | ) | [static] |
Definition at line 14624 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), reqprep(), respprep(), sip_show_channel(), sip_show_settings(), and sip_show_user().
14625 { 14626 return map_x_s(strefreshers, r, "Unknown"); 14627 }
| static const char * subscription_type2str | ( | enum subscriptiontype | subtype | ) | [static] |
Show subscription type in string format.
Definition at line 16361 of file chan_sip.c.
References ARRAY_LEN, subscription_types, and cfsubscription_types::text.
Referenced by show_channels_cb(), and sip_show_channel().
16362 { 16363 int i; 16364 16365 for (i = 1; i < ARRAY_LEN(subscription_types); i++) { 16366 if (subscription_types[i].type == subtype) { 16367 return subscription_types[i].text; 16368 } 16369 } 16370 return subscription_types[0].text; 16371 }
| static unsigned int t38_get_rate | ( | enum ast_control_t38_rate | rate | ) | [static] |
Get Max T.38 Transmission rate from T38 capabilities.
Definition at line 10111 of file chan_sip.c.
References AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, and AST_T38_RATE_9600.
Referenced by add_sdp().
10112 { 10113 switch (rate) { 10114 case AST_T38_RATE_2400: 10115 return 2400; 10116 case AST_T38_RATE_4800: 10117 return 4800; 10118 case AST_T38_RATE_7200: 10119 return 7200; 10120 case AST_T38_RATE_9600: 10121 return 9600; 10122 case AST_T38_RATE_12000: 10123 return 12000; 10124 case AST_T38_RATE_14400: 10125 return 14400; 10126 default: 10127 return 0; 10128 } 10129 }
| static void tcptls_packet_destructor | ( | void * | obj | ) | [static] |
Definition at line 2772 of file chan_sip.c.
References ast_free, and tcptls_packet::data.
Referenced by sip_tcptls_write().
02773 { 02774 struct tcptls_packet *packet = obj; 02775 02776 ast_free(packet->data); 02777 }
| static struct sip_peer * temp_peer | ( | const char * | name | ) | [static, read] |
Create temporary peer (used in autocreatepeer mode).
Definition at line 23911 of file chan_sip.c.
References ao2_t_alloc, ao2_t_ref, ast_atomic_fetchadd_int(), ast_copy_string(), ast_string_field_init, default_prefs, sip_peer::host_dynamic, sip_peer::name, sip_peer::prefs, reg_source_db(), sip_peer::selfdestruct, set_peer_defaults(), sip_destroy_peer_fn(), and TRUE.
Referenced by register_verify().
23912 { 23913 struct sip_peer *peer; 23914 23915 if (!(peer = ao2_t_alloc(sizeof(*peer), sip_destroy_peer_fn, "allocate a peer struct"))) 23916 return NULL; 23917 23918 if (ast_string_field_init(peer, 512)) { 23919 ao2_t_ref(peer, -1, "failed to string_field_init, drop peer"); 23920 return NULL; 23921 } 23922 23923 ast_atomic_fetchadd_int(&apeerobjs, 1); 23924 set_peer_defaults(peer); 23925 23926 ast_copy_string(peer->name, name, sizeof(peer->name)); 23927 23928 peer->selfdestruct = TRUE; 23929 peer->host_dynamic = TRUE; 23930 peer->prefs = default_prefs; 23931 reg_source_db(peer); 23932 23933 return peer; 23934 }
| static void temp_pvt_cleanup | ( | void * | data | ) | [static] |
Definition at line 9777 of file chan_sip.c.
References ast_free, and ast_string_field_free_memory.
09778 { 09779 struct sip_pvt *p = data; 09780 09781 ast_string_field_free_memory(p); 09782 09783 ast_free(data); 09784 }
| static int temp_pvt_init | ( | void * | data | ) | [static] |
Definition at line 9769 of file chan_sip.c.
References ast_string_field_init, and sip_pvt::do_history.
09770 { 09771 struct sip_pvt *p = data; 09772 09773 p->do_history = 0; /* XXX do we need it ? isn't already all 0 ? */ 09774 return ast_string_field_init(p, 512); 09775 }
| static char* terminate_uri | ( | char * | uri | ) | [static] |
Terminate the uri at the first ';' or space. Technically we should ignore escaped space per RFC3261 (19.1.1 etc) but don't do it for the time being. Remember the uri format is: (User-parameters was added after RFC 3261)
* * sip:user:password;user-parameters@host:port;uri-parameters?headers * sips:user:password;user-parameters@host:port;uri-parameters?headers * *
Definition at line 13102 of file chan_sip.c.
Referenced by check_user_full(), and register_verify().
13103 { 13104 char *t = uri; 13105 while (*t && *t > ' ' && *t != ';') 13106 t++; 13107 *t = '\0'; 13108 return uri; 13109 }
| static int threadinfo_locate_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 22293 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, inaddrcmp(), ast_tcptls_session_instance::remote_address, s, and sip_threadinfo::tcptls_session.
Referenced by sip_tcp_locate().
22294 { 22295 struct sip_threadinfo *th = obj; 22296 struct sockaddr_in *s = arg; 22297 22298 if (!inaddrcmp(&th->tcptls_session->remote_address, s)) { 22299 return CMP_MATCH | CMP_STOP; 22300 } 22301 22302 return 0; 22303 }
| static int threadt_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 2107 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, and sip_threadinfo::tcptls_session.
Referenced by load_module().
02108 { 02109 struct sip_threadinfo *th = obj, *th2 = arg; 02110 02111 return (th->tcptls_session == th2->tcptls_session) ? CMP_MATCH | CMP_STOP : 0; 02112 }
| static int threadt_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 2100 of file chan_sip.c.
References ast_tcptls_session_instance::remote_address, and sip_threadinfo::tcptls_session.
Referenced by load_module().
02101 { 02102 const struct sip_threadinfo *th = obj; 02103 02104 return (int) th->tcptls_session->remote_address.sin_addr.s_addr; 02105 }
| static char * transfermode2str | ( | enum transfermodes | mode | ) | [static] |
Convert transfer mode to text string.
Definition at line 14550 of file chan_sip.c.
References TRANSFER_CLOSED, and TRANSFER_OPENFORALL.
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_user().
14551 { 14552 if (mode == TRANSFER_OPENFORALL) 14553 return "open"; 14554 else if (mode == TRANSFER_CLOSED) 14555 return "closed"; 14556 return "strict"; 14557 }
| static void transmit_fake_auth_response | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Send a fake 401 Unauthorized response when the administrator wants to hide the names of local devices from fishers.
Definition at line 12996 of file chan_sip.c.
References AST_DYNSTR_BUILD_FAILED, ast_skip_blanks(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero(), buf, check_auth_buf, CHECK_AUTH_BUF_INITLEN, DEFAULT_TRANS_TIMEOUT, FALSE, get_header(), sip_request::ignore, sip_pvt::initreq, sip_pvt::randdata, s, set_nonce_randdata(), SIP_REGISTER, sip_scheddestroy(), SIP_SUBSCRIBE, strsep(), transmit_response(), and transmit_response_with_auth().
Referenced by handle_request_invite(), handle_request_subscribe(), and register_verify().
12997 { 12998 /* We have to emulate EXACTLY what we'd get with a good peer 12999 * and a bad password, or else we leak information. */ 13000 const char *response = "407 Proxy Authentication Required"; 13001 const char *reqheader = "Proxy-Authorization"; 13002 const char *respheader = "Proxy-Authenticate"; 13003 const char *authtoken; 13004 struct ast_str *buf; 13005 char *c; 13006 13007 /* table of recognised keywords, and their value in the digest */ 13008 enum keys { K_NONCE, K_LAST }; 13009 struct x { 13010 const char *key; 13011 const char *s; 13012 } *i, keys[] = { 13013 [K_NONCE] = { "nonce=", "" }, 13014 [K_LAST] = { NULL, NULL} 13015 }; 13016 13017 if (sipmethod == SIP_REGISTER || sipmethod == SIP_SUBSCRIBE) { 13018 response = "401 Unauthorized"; 13019 reqheader = "Authorization"; 13020 respheader = "WWW-Authenticate"; 13021 } 13022 authtoken = get_header(req, reqheader); 13023 if (req->ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) { 13024 /* This is a retransmitted invite/register/etc, don't reconstruct authentication 13025 * information */ 13026 transmit_response_with_auth(p, response, req, p->randdata, 0, respheader, 0); 13027 /* Schedule auto destroy in 32 seconds (according to RFC 3261) */ 13028 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13029 return; 13030 } else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) { 13031 /* We have no auth, so issue challenge and request authentication */ 13032 set_nonce_randdata(p, 1); 13033 transmit_response_with_auth(p, response, req, p->randdata, 0, respheader, 0); 13034 /* Schedule auto destroy in 32 seconds */ 13035 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13036 return; 13037 } 13038 13039 if (!(buf = ast_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) { 13040 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 13041 return; 13042 } 13043 13044 /* Make a copy of the response and parse it */ 13045 if (ast_str_set(&buf, 0, "%s", authtoken) == AST_DYNSTR_BUILD_FAILED) { 13046 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 13047 return; 13048 } 13049 13050 c = buf->str; 13051 13052 while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */ 13053 for (i = keys; i->key != NULL; i++) { 13054 const char *separator = ","; /* default */ 13055 13056 if (strncasecmp(c, i->key, strlen(i->key)) != 0) { 13057 continue; 13058 } 13059 /* Found. Skip keyword, take text in quotes or up to the separator. */ 13060 c += strlen(i->key); 13061 if (*c == '"') { /* in quotes. Skip first and look for last */ 13062 c++; 13063 separator = "\""; 13064 } 13065 i->s = c; 13066 strsep(&c, separator); 13067 break; 13068 } 13069 if (i->key == NULL) { /* not found, jump after space or comma */ 13070 strsep(&c, " ,"); 13071 } 13072 } 13073 13074 /* Verify nonce from request matches our nonce. If not, send 401 with new nonce */ 13075 if (strcasecmp(p->randdata, keys[K_NONCE].s)) { 13076 if (!req->ignore) { 13077 set_nonce_randdata(p, 1); 13078 } 13079 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE); 13080 13081 /* Schedule auto destroy in 32 seconds */ 13082 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 13083 } else { 13084 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 13085 } 13086 }
| static int transmit_info_with_digit | ( | struct sip_pvt * | p, | |
| const char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Send SIP INFO dtmf message, see Cisco documentation on cisco.com.
Definition at line 12069 of file chan_sip.c.
References add_digit(), ast_test_flag, sip_pvt::flags, sip_pvt::ocseq, reqprep(), send_request(), SIP_DTMF, SIP_DTMF_SHORTINFO, SIP_INFO, and XMIT_RELIABLE.
Referenced by sip_senddigit_end().
12070 { 12071 struct sip_request req; 12072 12073 reqprep(&req, p, SIP_INFO, 0, 1); 12074 add_digit(&req, digit, duration, (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO)); 12075 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12076 }
| static int transmit_info_with_vidupdate | ( | struct sip_pvt * | p | ) | [static] |
Send SIP INFO with video update request.
Definition at line 12079 of file chan_sip.c.
References add_vidupdate(), sip_pvt::ocseq, reqprep(), send_request(), SIP_INFO, and XMIT_RELIABLE.
Referenced by sip_indicate().
12080 { 12081 struct sip_request req; 12082 12083 reqprep(&req, p, SIP_INFO, 0, 1); 12084 add_vidupdate(&req); 12085 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12086 }
| static int transmit_invite | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | sdp, | |||
| int | init | |||
| ) | [static] |
Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it.
| init | 0 = Prepare request within dialog, 1= prepare request, new branch, 2= prepare new request and new dialog. do_proxy_auth calls this with init!=2 | |
| p | sip_pvt structure | |
| sdp | unknown | |
| sipmethod | unknown |
Definition at line 10987 of file chan_sip.c.
References add_header(), add_sdp(), add_supported_header(), sip_invite_param::addsipheaders, ALLOWED_METHODS, append_date(), ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_debug, AST_LIST_TRAVERSE, ast_log(), ast_random(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), ast_unescape_semicolon(), ast_var_name(), ast_var_value(), sip_invite_param::auth, sip_invite_param::authheader, sip_pvt::branch, buf, build_via(), chan, sip_request::content, ast_var_t::entries, FALSE, sip_request::header, sip_request::headers, initialize_initreq(), sip_pvt::initreq, initreqprep(), sip_pvt::invite_branch, sip_pvt::lastinvite, LOG_WARNING, sip_request::method, ast_channel::name, ast_variable::name, ast_variable::next, sip_pvt::notify_headers, sip_pvt::ocseq, sip_pvt::offered_media, sip_pvt::options, sip_pvt::owner, sip_pvt::refer, sip_refer::refer_to, sip_refer::referred_by, sip_refer::referred_by_name, sip_invite_param::replaces, reqprep(), sip_pvt::rtp, send_request(), SESSION_TIMER_MODE_ORIGINATE, SIP_REFER, SIP_SUBSCRIBE, SIPBUFSIZE, sip_st_dlg::st_active, st_get_mode(), st_get_se(), sip_st_dlg::st_interval, t38properties::state, sip_pvt::stimer, sip_pvt::t38, T38_LOCAL_REINVITE, TRUE, sip_pvt::udptl, ast_variable::value, var, ast_channel::varshead, XMIT_CRITICAL, and XMIT_RELIABLE.
Referenced by __sip_subscribe_mwi_do(), do_proxy_auth(), proc_422_rsp(), sip_call(), and sip_poke_peer().
10988 { 10989 struct sip_request req; 10990 struct ast_variable *var; 10991 10992 req.method = sipmethod; 10993 if (init) {/* Bump branch even on initial requests */ 10994 p->branch ^= ast_random(); 10995 p->invite_branch = p->branch; 10996 build_via(p); 10997 } 10998 if (init > 1) 10999 initreqprep(&req, p, sipmethod); 11000 else 11001 /* If init=1, we should not generate a new branch. If it's 0, we need a new branch. */ 11002 reqprep(&req, p, sipmethod, 0, init ? 0 : 1); 11003 11004 if (p->options && p->options->auth) 11005 add_header(&req, p->options->authheader, p->options->auth); 11006 append_date(&req); 11007 if (sipmethod == SIP_REFER) { /* Call transfer */ 11008 if (p->refer) { 11009 char buf[SIPBUFSIZE]; 11010 if (!ast_strlen_zero(p->refer->refer_to)) 11011 add_header(&req, "Refer-To", p->refer->refer_to); 11012 if (!ast_strlen_zero(p->refer->referred_by)) { 11013 snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by); 11014 add_header(&req, "Referred-By", buf); 11015 } 11016 } 11017 } else if (sipmethod == SIP_SUBSCRIBE) { /* We only support sending MWI subscriptions right now */ 11018 char buf[SIPBUFSIZE]; 11019 11020 add_header(&req, "Event", "message-summary"); 11021 add_header(&req, "Accept", "application/simple-message-summary"); 11022 snprintf(buf, sizeof(buf), "%d", mwi_expiry); 11023 add_header(&req, "Expires", buf); 11024 } 11025 11026 /* This new INVITE is part of an attended transfer. Make sure that the 11027 other end knows and replace the current call with this new call */ 11028 if (p->options && !ast_strlen_zero(p->options->replaces)) { 11029 add_header(&req, "Replaces", p->options->replaces); 11030 add_header(&req, "Require", "replaces"); 11031 } 11032 11033 /* Add Session-Timers related headers */ 11034 if (st_get_mode(p) == SESSION_TIMER_MODE_ORIGINATE) { 11035 char i2astr[10]; 11036 11037 if (!p->stimer->st_interval) 11038 p->stimer->st_interval = st_get_se(p, TRUE); 11039 11040 p->stimer->st_active = TRUE; 11041 11042 snprintf(i2astr, sizeof(i2astr), "%d", p->stimer->st_interval); 11043 add_header(&req, "Session-Expires", i2astr); 11044 snprintf(i2astr, sizeof(i2astr), "%d", st_get_se(p, FALSE)); 11045 add_header(&req, "Min-SE", i2astr); 11046 } 11047 11048 add_header(&req, "Allow", ALLOWED_METHODS); 11049 add_supported_header(p, &req); 11050 11051 if(p->notify_headers) { 11052 char buf[512]; 11053 for (var = p->notify_headers; var; var = var->next) { 11054 ast_copy_string(buf, var->value, sizeof(buf)); 11055 add_header(&req, var->name, ast_unescape_semicolon(buf)); 11056 } 11057 } 11058 if (p->options && p->options->addsipheaders && p->owner) { 11059 struct ast_channel *chan = p->owner; /* The owner channel */ 11060 struct varshead *headp; 11061 11062 ast_channel_lock(chan); 11063 11064 headp = &chan->varshead; 11065 11066 if (!headp) 11067 ast_log(LOG_WARNING, "No Headp for the channel...ooops!\n"); 11068 else { 11069 const struct ast_var_t *current; 11070 AST_LIST_TRAVERSE(headp, current, entries) { 11071 /* SIPADDHEADER: Add SIP header to outgoing call */ 11072 if (!strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 11073 char *content, *end; 11074 const char *header = ast_var_value(current); 11075 char *headdup = ast_strdupa(header); 11076 11077 /* Strip of the starting " (if it's there) */ 11078 if (*headdup == '"') 11079 headdup++; 11080 if ((content = strchr(headdup, ':'))) { 11081 *content++ = '\0'; 11082 content = ast_skip_blanks(content); /* Skip white space */ 11083 /* Strip the ending " (if it's there) */ 11084 end = content + strlen(content) -1; 11085 if (*end == '"') 11086 *end = '\0'; 11087 11088 add_header(&req, headdup, content); 11089 if (sipdebug) 11090 ast_debug(1, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content); 11091 } 11092 } 11093 } 11094 } 11095 11096 ast_channel_unlock(chan); 11097 } 11098 if (sdp) { 11099 memset(p->offered_media, 0, sizeof(p->offered_media)); 11100 if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) { 11101 ast_debug(1, "T38 is in state %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 11102 add_sdp(&req, p, FALSE, FALSE, TRUE); 11103 } else if (p->rtp) 11104 add_sdp(&req, p, FALSE, TRUE, FALSE); 11105 } 11106 11107 if (!p->initreq.headers || init > 2) 11108 initialize_initreq(p, &req); 11109 p->lastinvite = p->ocseq; 11110 return send_request(p, &req, init ? XMIT_CRITICAL : XMIT_RELIABLE, p->ocseq); 11111 }
| static int transmit_message_with_text | ( | struct sip_pvt * | p, | |
| const char * | text | |||
| ) | [static] |
Transmit text with SIP MESSAGE method.
Definition at line 11972 of file chan_sip.c.
References add_text(), sip_pvt::ocseq, reqprep(), send_request(), SIP_MESSAGE, and XMIT_RELIABLE.
Referenced by sip_park_thread(), and sip_sendtext().
11973 { 11974 struct sip_request req; 11975 11976 reqprep(&req, p, SIP_MESSAGE, 0, 1); 11977 add_text(&req, text); 11978 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 11979 }
| static int transmit_notify_custom | ( | struct sip_pvt * | p, | |
| struct ast_variable * | vars | |||
| ) | [static] |
Notify device with custom headers from sip_notify.conf.
Definition at line 11511 of file chan_sip.c.
References add_header(), ast_copy_string(), ast_debug, ast_unescape_semicolon(), ast_variable_new(), buf, sip_request::headers, initialize_initreq(), sip_pvt::initreq, initreqprep(), ast_variable::name, ast_variable::next, sip_pvt::notify_headers, sip_pvt::ocseq, send_request(), SIP_NOTIFY, ast_variable::value, var, and XMIT_RELIABLE.
Referenced by manager_sipnotify(), and sip_cli_notify().
11511 { 11512 struct sip_request req; 11513 struct ast_variable *var, *newvar; 11514 11515 initreqprep(&req, p, SIP_NOTIFY); 11516 11517 /* Copy notify vars and add headers */ 11518 p->notify_headers = newvar = ast_variable_new("Subscription-State", "terminated", ""); 11519 add_header(&req, newvar->name, newvar->value); 11520 for (var = vars; var; var = var->next) { 11521 char buf[512]; 11522 11523 if (!strcasecmp(var->name, "Content-Length")) { 11524 ast_debug(2, "Ignoring pair %s=%s\n", var->name, var->value); 11525 continue; /* ignore content-length, it is calculated automatically */ 11526 } 11527 11528 ast_debug(2, " Adding pair %s=%s\n", var->name, var->value); 11529 ast_copy_string(buf, var->value, sizeof(buf)); 11530 add_header(&req, var->name, ast_unescape_semicolon(buf)); 11531 newvar->next = ast_variable_new(var->name, var->value, ""); 11532 newvar = newvar->next; 11533 } 11534 11535 if (!p->initreq.headers) { /* Initialize first request before sending */ 11536 initialize_initreq(p, &req); 11537 } 11538 11539 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 11540 }
| static int transmit_notify_with_mwi | ( | struct sip_pvt * | p, | |
| int | newmsgs, | |||
| int | oldmsgs, | |||
| const char * | vmexten | |||
| ) | [static] |
Notify user of messages waiting in voicemail (RFC3842).
Definition at line 11440 of file chan_sip.c.
References add_content(), add_header(), ast_inet_ntoa(), ast_str_alloca, ast_str_append(), ast_strlen_zero(), ast_test_flag, sip_pvt::expiry, exten, sip_pvt::flags, sip_pvt::fromdomain, get_transport(), sip_request::headers, initialize_initreq(), sip_pvt::initreq, initreqprep(), sip_pvt::ocseq, sip_pvt::ourip, ourport, S_OR, send_request(), SIP_NOTIFY, SIP_PAGE2_BUGGY_MWI, sip_standard_port(), SIP_TRANSPORT_UDP, sip_pvt::socket, sip_pvt::subscribed, sip_socket::type, and XMIT_RELIABLE.
Referenced by sip_send_mwi_to_peer().
11441 { 11442 struct sip_request req; 11443 struct ast_str *out = ast_str_alloca(500); 11444 int ourport = ntohs(p->ourip.sin_port); 11445 const char *exten = S_OR(vmexten, default_vmexten); 11446 11447 initreqprep(&req, p, SIP_NOTIFY); 11448 add_header(&req, "Event", "message-summary"); 11449 add_header(&req, "Content-Type", default_notifymime); 11450 ast_str_append(&out, 0, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no"); 11451 11452 if (!ast_strlen_zero(p->fromdomain)) { 11453 ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, p->fromdomain); 11454 } else if (!sip_standard_port(p->socket.type, ourport)) { 11455 if (p->socket.type == SIP_TRANSPORT_UDP) { 11456 ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), ourport); 11457 } else { 11458 ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), ourport, get_transport(p->socket.type)); 11459 } 11460 } else { 11461 if (p->socket.type == SIP_TRANSPORT_UDP) { 11462 ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr)); 11463 } else { 11464 ast_str_append(&out, 0, "Message-Account: sip:%s@%s;transport=%s\r\n", exten, ast_inet_ntoa(p->ourip.sin_addr), get_transport(p->socket.type)); 11465 } 11466 } 11467 /* Cisco has a bug in the SIP stack where it can't accept the 11468 (0/0) notification. This can temporarily be disabled in 11469 sip.conf with the "buggymwi" option */ 11470 ast_str_append(&out, 0, "Voice-Message: %d/%d%s\r\n", 11471 newmsgs, oldmsgs, (ast_test_flag(&p->flags[1], SIP_PAGE2_BUGGY_MWI) ? "" : " (0/0)")); 11472 11473 if (p->subscribed) { 11474 if (p->expiry) 11475 add_header(&req, "Subscription-State", "active"); 11476 else /* Expired */ 11477 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 11478 } 11479 11480 add_content(&req, out->str); 11481 11482 if (!p->initreq.headers) 11483 initialize_initreq(p, &req); 11484 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 11485 }
| static int transmit_notify_with_sipfrag | ( | struct sip_pvt * | p, | |
| int | cseq, | |||
| char * | message, | |||
| int | terminate | |||
| ) | [static] |
Notify a transferring party of the status of transfer (RFC3515).
Definition at line 11488 of file chan_sip.c.
References add_content(), add_header(), add_supported_header(), ALLOWED_METHODS, sip_request::headers, initialize_initreq(), sip_pvt::initreq, sip_pvt::ocseq, reqprep(), send_request(), SIP_NOTIFY, SIPBUFSIZE, and XMIT_RELIABLE.
Referenced by handle_request_refer(), local_attended_transfer(), and sip_park_thread().
11489 { 11490 struct sip_request req; 11491 char tmp[SIPBUFSIZE/2]; 11492 11493 reqprep(&req, p, SIP_NOTIFY, 0, 1); 11494 snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq); 11495 add_header(&req, "Event", tmp); 11496 add_header(&req, "Subscription-state", terminate ? "terminated;reason=noresource" : "active"); 11497 add_header(&req, "Content-Type", "message/sipfrag;version=2.0"); 11498 add_header(&req, "Allow", ALLOWED_METHODS); 11499 add_supported_header(p, &req); 11500 11501 snprintf(tmp, sizeof(tmp), "SIP/2.0 %s\r\n", message); 11502 add_content(&req, tmp); 11503 11504 if (!p->initreq.headers) 11505 initialize_initreq(p, &req); 11506 11507 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 11508 }
| static int transmit_provisional_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| int | with_sdp | |||
| ) | [static] |
Definition at line 9928 of file chan_sip.c.
References FALSE, sip_pvt::last_provisional, transmit_response(), transmit_response_with_sdp(), update_provisional_keepalive(), and XMIT_UNRELIABLE.
Referenced by handle_request_invite(), sip_indicate(), and sip_write().
09929 { 09930 int res; 09931 09932 if (!(res = with_sdp ? transmit_response_with_sdp(p, msg, req, XMIT_UNRELIABLE, FALSE) : transmit_response(p, msg, req))) { 09933 p->last_provisional = msg; 09934 update_provisional_keepalive(p, with_sdp); 09935 } 09936 09937 return res; 09938 }
| static int transmit_refer | ( | struct sip_pvt * | p, | |
| const char * | dest | |||
| ) | [static] |
Transmit SIP REFER message (initiated by the transfer() dialplan application.
Definition at line 11993 of file chan_sip.c.
References add_header(), add_supported_header(), ALLOWED_METHODS, ast_copy_string(), ast_debug, ast_log(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, sip_pvt::callid, FALSE, sip_pvt::flags, get_header(), get_in_brackets(), sip_request::headers, sip_pvt::initreq, LOG_NOTICE, sip_pvt::ocseq, sip_pvt::our_contact, sip_pvt::refer, REFER_SENT, sip_refer::refer_to, sip_refer::referred_by, reqprep(), send_request(), SIP_OUTGOING, SIP_REFER, sip_refer_allocate(), sip_refer::status, sip_pvt::tag, sip_pvt::theirtag, TRUE, and XMIT_RELIABLE.
Referenced by sip_transfer().
11994 { 11995 struct sip_request req = { 11996 .headers = 0, 11997 }; 11998 char from[256]; 11999 const char *of; 12000 char *c; 12001 char referto[256]; 12002 char *ttag, *ftag; 12003 char *theirtag = ast_strdupa(p->theirtag); 12004 int use_tls=FALSE; 12005 12006 if (sipdebug) 12007 ast_debug(1, "SIP transfer of %s to %s\n", p->callid, dest); 12008 12009 /* Are we transfering an inbound or outbound call ? */ 12010 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 12011 of = get_header(&p->initreq, "To"); 12012 ttag = theirtag; 12013 ftag = p->tag; 12014 } else { 12015 of = get_header(&p->initreq, "From"); 12016 ftag = theirtag; 12017 ttag = p->tag; 12018 } 12019 12020 ast_copy_string(from, of, sizeof(from)); 12021 of = get_in_brackets(from); 12022 ast_string_field_set(p, from, of); 12023 if (!strncasecmp(of, "sip:", 4)) { 12024 of += 4; 12025 }else if (!strncasecmp(of, "sips:", 5)) { 12026 of += 5; 12027 use_tls = TRUE; 12028 } else { 12029 ast_log(LOG_NOTICE, "From address missing 'sip(s):', assuming sip:\n"); 12030 } 12031 /* Get just the username part */ 12032 if ((c = strchr(dest, '@'))) 12033 c = NULL; 12034 else if ((c = strchr(of, '@'))) 12035 *c++ = '\0'; 12036 if (c) 12037 snprintf(referto, sizeof(referto), "<sip%s:%s@%s>", use_tls ? "s" : "", dest, c); 12038 else 12039 snprintf(referto, sizeof(referto), "<sip%s:%s>", use_tls ? "s" : "", dest); 12040 12041 /* save in case we get 407 challenge */ 12042 sip_refer_allocate(p); 12043 ast_copy_string(p->refer->refer_to, referto, sizeof(p->refer->refer_to)); 12044 ast_copy_string(p->refer->referred_by, p->our_contact, sizeof(p->refer->referred_by)); 12045 p->refer->status = REFER_SENT; /* Set refer status */ 12046 12047 reqprep(&req, p, SIP_REFER, 0, 1); 12048 12049 add_header(&req, "Refer-To", referto); 12050 add_header(&req, "Allow", ALLOWED_METHODS); 12051 add_supported_header(p, &req); 12052 if (!ast_strlen_zero(p->our_contact)) 12053 add_header(&req, "Referred-By", p->our_contact); 12054 12055 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12056 12057 /* We should propably wait for a NOTIFY here until we ack the transfer */ 12058 /* Maybe fork a new thread and wait for a STATUS of REFER_200OK on the refer status before returning to app_transfer */ 12059 12060 /*! \todo In theory, we should hang around and wait for a reply, before 12061 returning to the dial plan here. Don't know really how that would 12062 affect the transfer() app or the pbx, but, well, to make this 12063 useful we should have a STATUS code on transfer(). 12064 */ 12065 }
| static int transmit_register | ( | struct sip_registry * | r, | |
| int | sipmethod, | |||
| const char * | auth, | |||
| const char * | authheader | |||
| ) | [static] |
Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister()).
Definition at line 11721 of file chan_sip.c.
References add_header(), append_history, ast_debug, ast_dnsmgr_lookup(), ast_log(), ast_random(), ast_sched_add(), AST_SCHED_REPLACE_UNREF, ast_set_flag, ast_sip_ouraddrfor(), ast_string_field_set, ast_strlen_zero(), ast_verbose, sip_registry::authuser, sip_pvt::branch, build_callid_registry(), build_contact(), build_reply_digest(), build_via(), sip_registry::call, sip_registry::callback, sip_pvt::callid, sip_registry::callid, sip_registry::callid_valid, create_addr(), DEFAULT_MAX_FORWARDS, dialog_ref(), dialog_unlink_all(), dialog_unref(), sip_registry::dnsmgr, sip_pvt::do_history, sip_registry::domain, sip_registry::expiry, exten, FALSE, find_peer(), FINDPEERS, sip_pvt::flags, sip_pvt::fromdomain, sip_peer::fromdomain, sip_peer::fromuser, get_srv_protocol(), get_srv_service(), sip_request::headers, sip_registry::hostname, init_req(), initialize_initreq(), sip_pvt::initreq, internip, sip_request::lines, ast_tcptls_session_args::local_address, LOG_NOTICE, LOG_WARNING, make_our_tag(), MAXHOSTNAMELEN, sip_registry::md5secret, sip_registry::nonce, sip_registry::noncecount, sip_pvt::noncecount, sip_pvt::ocseq, sip_registry::ocseq, sip_registry::opaque, sip_pvt::our_contact, sip_pvt::ourip, sip_registry::peername, sip_socket::port, sip_registry::portno, sip_registry::qop, sip_registry::realm, sip_pvt::recv, REG_STATE_AUTHSENT, REG_STATE_REGSENT, sip_registry::regattempts, sip_pvt::registry, registry_addref(), registry_unref(), sip_registry::regstate, S_OR, sip_pvt::sa, sip_registry::secret, send_request(), set_socket_transport(), sip_alloc(), sip_cfg, sip_debug_test_pvt(), sip_methods, SIP_OUTGOING, sip_reg_timeout(), SIP_REGISTER, SIP_TRANSPORT_TCP, SIP_TRANSPORT_TLS, sip_pvt::socket, sip_settings::srvlookup, STANDARD_SIP_PORT, sip_pvt::tag, cfsip_methods::text, sip_pvt::theirtag, sip_registry::timeout, sip_pvt::tohost, sip_peer::tohost, sip_registry::transport, TRUE, unref_peer(), sip_registry::us, sip_peer::username, sip_registry::username, sip_pvt::via, and XMIT_CRITICAL.
Referenced by __sip_do_register(), do_register_auth(), handle_response_register(), and sip_reg_timeout().
11722 { 11723 struct sip_request req; 11724 char from[256]; 11725 char to[256]; 11726 char tmp[80]; 11727 char addr[80]; 11728 struct sip_pvt *p; 11729 struct sip_peer *peer = NULL; 11730 int res; 11731 char *fromdomain; 11732 char *domainport = NULL; 11733 11734 /* exit if we are already in process with this registrar ?*/ 11735 if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) { 11736 if (r) { 11737 ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname); 11738 } 11739 return 0; 11740 } 11741 11742 if (r->dnsmgr == NULL) { 11743 char transport[MAXHOSTNAMELEN]; 11744 peer = find_peer(r->hostname, NULL, TRUE, FINDPEERS, FALSE, 0); 11745 snprintf(transport, sizeof(transport), "_%s._%s",get_srv_service(r->transport), get_srv_protocol(r->transport)); /* have to use static get_transport function */ 11746 ast_dnsmgr_lookup(peer ? peer->tohost : r->hostname, &r->us, &r->dnsmgr, sip_cfg.srvlookup ? transport : NULL); 11747 if (peer) { 11748 peer = unref_peer(peer, "removing peer ref for dnsmgr_lookup"); 11749 } 11750 } 11751 11752 if (r->call) { /* We have a registration */ 11753 if (!auth) { 11754 ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname); 11755 return 0; 11756 } else { 11757 p = dialog_ref(r->call, "getting a copy of the r->call dialog in transmit_register"); 11758 make_our_tag(p->tag, sizeof(p->tag)); /* create a new local tag for every register attempt */ 11759 ast_string_field_set(p, theirtag, NULL); /* forget their old tag, so we don't match tags when getting response */ 11760 } 11761 } else { 11762 /* Build callid for registration if we haven't registered before */ 11763 if (!r->callid_valid) { 11764 build_callid_registry(r, internip.sin_addr, default_fromdomain); 11765 r->callid_valid = TRUE; 11766 } 11767 /* Allocate SIP dialog for registration */ 11768 if (!(p = sip_alloc( r->callid, NULL, 0, SIP_REGISTER, NULL))) { 11769 ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n"); 11770 return 0; 11771 } 11772 11773 if (p->do_history) 11774 append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname); 11775 11776 /* Use port number specified if no SRV record was found */ 11777 if (!r->us.sin_port && r->portno) 11778 r->us.sin_port = htons(r->portno); 11779 11780 /* Find address to hostname */ 11781 if (create_addr(p, S_OR(r->peername, r->hostname), &r->us, 0)) { 11782 /* we have what we hope is a temporary network error, 11783 * probably DNS. We need to reschedule a registration try */ 11784 dialog_unlink_all(p, TRUE, TRUE); 11785 p = dialog_unref(p, "unref dialog after unlink_all"); 11786 if (r->timeout > -1) { 11787 AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r, 11788 registry_unref(_data, "del for REPLACE of registry ptr"), 11789 registry_unref(r, "object ptr dec when SCHED_REPLACE add failed"), 11790 registry_addref(r,"add for REPLACE registry ptr")); 11791 ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout); 11792 } else { 11793 r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, registry_addref(r, "add for REPLACE registry ptr")); 11794 ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout); 11795 } 11796 r->regattempts++; 11797 return 0; 11798 } 11799 11800 /* Copy back Call-ID in case create_addr changed it */ 11801 ast_string_field_set(r, callid, p->callid); 11802 if (!r->dnsmgr && r->portno) { 11803 p->sa.sin_port = htons(r->portno); 11804 p->recv.sin_port = htons(r->portno); 11805 } else { /* Set registry port to the port set from the peer definition/srv or default */ 11806 r->portno = ntohs(p->sa.sin_port); 11807 } 11808 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Registration is outgoing call */ 11809 r->call = dialog_ref(p, "copying dialog into registry r->call"); /* Save pointer to SIP dialog */ 11810 p->registry = registry_addref(r, "transmit_register: addref to p->registry in transmit_register"); /* Add pointer to registry in packet */ 11811 if (!ast_strlen_zero(r->secret)) { /* Secret (password) */ 11812 ast_string_field_set(p, peersecret, r->secret); 11813 } 11814 if (!ast_strlen_zero(r->md5secret)) 11815 ast_string_field_set(p, peermd5secret, r->md5secret); 11816 /* User name in this realm 11817 - if authuser is set, use that, otherwise use username */ 11818 if (!ast_strlen_zero(r->authuser)) { 11819 ast_string_field_set(p, peername, r->authuser); 11820 ast_string_field_set(p, authname, r->authuser); 11821 } else if (!ast_strlen_zero(r->username)) { 11822 ast_string_field_set(p, peername, r->username); 11823 ast_string_field_set(p, authname, r->username); 11824 ast_string_field_set(p, fromuser, r->username); 11825 } 11826 if (!ast_strlen_zero(r->username)) 11827 ast_string_field_set(p, username, r->username); 11828 /* Save extension in packet */ 11829 if (!ast_strlen_zero(r->callback)) 11830 ast_string_field_set(p, exten, r->callback); 11831 11832 /* Set transport and port so the correct contact is built */ 11833 set_socket_transport(&p->socket, r->transport); 11834 if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) { 11835 p->socket.port = sip_tcp_desc.local_address.sin_port; 11836 } 11837 11838 /* 11839 check which address we should use in our contact header 11840 based on whether the remote host is on the external or 11841 internal network so we can register through nat 11842 */ 11843 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 11844 build_contact(p); 11845 } 11846 11847 /* set up a timeout */ 11848 if (auth == NULL) { 11849 if (r->timeout > -1) 11850 ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout); 11851 AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r, 11852 registry_unref(_data,"reg ptr unrefed from del in SCHED_REPLACE"), 11853 registry_unref(r,"reg ptr unrefed from add failure in SCHED_REPLACE"), 11854 registry_addref(r,"reg ptr reffed from add in SCHED_REPLACE")); 11855 ast_debug(1, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout); 11856 } 11857 11858 if ((fromdomain = strchr(r->username, '@'))) { 11859 /* the domain name is just behind '@' */ 11860 fromdomain++ ; 11861 /* We have a domain in the username for registration */ 11862 snprintf(from, sizeof(from), "<sip:%s>;tag=%s", r->username, p->tag); 11863 if (!ast_strlen_zero(p->theirtag)) 11864 snprintf(to, sizeof(to), "<sip:%s>;tag=%s", r->username, p->theirtag); 11865 else 11866 snprintf(to, sizeof(to), "<sip:%s>", r->username); 11867 11868 /* If the registration username contains '@', then the domain should be used as 11869 the equivalent of "fromdomain" for the registration */ 11870 if (ast_strlen_zero(p->fromdomain)) { 11871 ast_string_field_set(p, fromdomain, fromdomain); 11872 } 11873 } else { 11874 snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->tag); 11875 if (!ast_strlen_zero(p->theirtag)) 11876 snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, p->tohost, p->theirtag); 11877 else 11878 snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, p->tohost); 11879 } 11880 11881 /* Fromdomain is what we are registering to, regardless of actual 11882 host name from SRV */ 11883 if (!ast_strlen_zero(p->fromdomain)) { 11884 domainport = strrchr(p->fromdomain, ':'); 11885 if (domainport) { 11886 *domainport++ = '\0'; /* trim off domainport from p->fromdomain */ 11887 if (ast_strlen_zero(domainport)) 11888 domainport = NULL; 11889 } 11890 if (domainport) { 11891 if (atoi(domainport) != STANDARD_SIP_PORT) 11892 snprintf(addr, sizeof(addr), "sip:%s:%s", p->fromdomain, domainport); 11893 else 11894 snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain); 11895 } else { 11896 if (r->portno && r->portno != STANDARD_SIP_PORT) 11897 snprintf(addr, sizeof(addr), "sip:%s:%d", p->fromdomain, r->portno); 11898 else 11899 snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain); 11900 } 11901 } else { 11902 if (r->portno && r->portno != STANDARD_SIP_PORT) 11903 snprintf(addr, sizeof(addr), "sip:%s:%d", r->hostname, r->portno); 11904 else 11905 snprintf(addr, sizeof(addr), "sip:%s", r->hostname); 11906 } 11907 ast_string_field_set(p, uri, addr); 11908 11909 p->branch ^= ast_random(); 11910 11911 init_req(&req, sipmethod, addr); 11912 11913 /* Add to CSEQ */ 11914 snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_methods[sipmethod].text); 11915 p->ocseq = r->ocseq; 11916 11917 build_via(p); 11918 add_header(&req, "Via", p->via); 11919 add_header(&req, "Max-Forwards", DEFAULT_MAX_FORWARDS); 11920 add_header(&req, "From", from); 11921 add_header(&req, "To", to); 11922 add_header(&req, "Call-ID", p->callid); 11923 add_header(&req, "CSeq", tmp); 11924 if (!ast_strlen_zero(global_useragent)) 11925 add_header(&req, "User-Agent", global_useragent); 11926 11927 11928 if (auth) /* Add auth header */ 11929 add_header(&req, authheader, auth); 11930 else if (!ast_strlen_zero(r->nonce)) { 11931 char digest[1024]; 11932 11933 /* We have auth data to reuse, build a digest header. 11934 * Note, this is not always useful because some parties do not 11935 * like nonces to be reused (for good reasons!) so they will 11936 * challenge us anyways. 11937 */ 11938 if (sipdebug) 11939 ast_debug(1, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname); 11940 ast_string_field_set(p, realm, r->realm); 11941 ast_string_field_set(p, nonce, r->nonce); 11942 ast_string_field_set(p, domain, r->domain); 11943 ast_string_field_set(p, opaque, r->opaque); 11944 ast_string_field_set(p, qop, r->qop); 11945 p->noncecount = ++r->noncecount; 11946 11947 memset(digest, 0, sizeof(digest)); 11948 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) 11949 add_header(&req, "Authorization", digest); 11950 else 11951 ast_log(LOG_NOTICE, "No authorization available for authentication of registration to %s@%s\n", r->username, r->hostname); 11952 11953 } 11954 11955 snprintf(tmp, sizeof(tmp), "%d", r->expiry); 11956 add_header(&req, "Expires", tmp); 11957 add_header(&req, "Contact", p->our_contact); 11958 11959 initialize_initreq(p, &req); 11960 if (sip_debug_test_pvt(p)) { 11961 ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 11962 } 11963 r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT; 11964 r->regattempts++; /* Another attempt */ 11965 ast_debug(4, "REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname); 11966 res = send_request(p, &req, XMIT_CRITICAL, p->ocseq); 11967 dialog_unref(p, "p is finished here at the end of transmit_register"); 11968 return res; 11969 }
| static int transmit_reinvite_with_sdp | ( | struct sip_pvt * | p, | |
| int | t38version, | |||
| int | oldsdp | |||
| ) | [static] |
Transmit reinvite with SDP.
If oldsdp is TRUE then the SDP version number is not incremented. This is needed for Session-Timers so we can send a re-invite to refresh the SIP session without modifying the media session.
Definition at line 10666 of file chan_sip.c.
References add_header(), add_sdp(), add_supported_header(), ALLOWED_METHODS, append_history, ast_set_flag, ast_test_flag, sip_pvt::do_history, FALSE, sip_pvt::flags, initialize_initreq(), sip_pvt::lastinvite, sip_pvt::ocseq, sip_pvt::offered_media, reqprep(), send_request(), SIP_INVITE, SIP_OUTGOING, SIP_REINVITE_UPDATE, SIP_UPDATE, TRUE, and XMIT_CRITICAL.
Referenced by check_pendings(), handle_response_invite(), interpret_t38_parameters(), proc_session_timer(), sip_sendhtml(), sip_set_rtp_peer(), and sip_set_udptl_peer().
10667 { 10668 struct sip_request req; 10669 10670 reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ? SIP_UPDATE : SIP_INVITE, 0, 1); 10671 10672 add_header(&req, "Allow", ALLOWED_METHODS); 10673 add_supported_header(p, &req); 10674 if (sipdebug) { 10675 if (oldsdp == TRUE) 10676 add_header(&req, "X-asterisk-Info", "SIP re-invite (Session-Timers)"); 10677 else 10678 add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)"); 10679 } 10680 10681 if (p->do_history) 10682 append_history(p, "ReInv", "Re-invite sent"); 10683 memset(p->offered_media, 0, sizeof(p->offered_media)); 10684 10685 if (t38version) 10686 add_sdp(&req, p, oldsdp, FALSE, TRUE); 10687 else 10688 add_sdp(&req, p, oldsdp, TRUE, FALSE); 10689 10690 /* Use this as the basis */ 10691 initialize_initreq(p, &req); 10692 p->lastinvite = p->ocseq; 10693 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Change direction of this dialog */ 10694 10695 return send_request(p, &req, XMIT_CRITICAL, p->ocseq); 10696 }
| static int transmit_request | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | inc, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry).
Definition at line 12091 of file chan_sip.c.
References add_header(), sip_pvt::answered_elsewhere, INV_CONFIRMED, sip_pvt::invitestate, sip_pvt::ocseq, reqprep(), send_request(), SIP_ACK, and SIP_CANCEL.
Referenced by check_pendings(), handle_response(), handle_response_invite(), and sip_hangup().
12092 { 12093 struct sip_request resp; 12094 12095 if (sipmethod == SIP_ACK) 12096 p->invitestate = INV_CONFIRMED; 12097 12098 reqprep(&resp, p, sipmethod, seqno, newbranch); 12099 if (sipmethod == SIP_CANCEL && p->answered_elsewhere) 12100 add_header(&resp, "Reason", "SIP;cause=200;text=\"Call completed elsewhere\""); 12101 12102 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 12103 }
| static int transmit_request_with_auth | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | seqno, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit SIP request, auth added.
Definition at line 12121 of file chan_sip.c.
References add_header(), ast_cause2str(), ast_log(), ast_strlen_zero(), auth_headers(), sip_invite_param::auth_type, buf, build_reply_digest(), sip_pvt::callid, dummy(), sip_pvt::hangupcause, LOG_WARNING, sip_pvt::ocseq, sip_pvt::options, PROXY_AUTH, sip_pvt::realm, reqprep(), send_request(), and SIP_BYE.
Referenced by __sip_autodestruct(), check_pendings(), and sip_hangup().
12122 { 12123 struct sip_request resp; 12124 12125 reqprep(&resp, p, sipmethod, seqno, newbranch); 12126 if (!ast_strlen_zero(p->realm)) { 12127 char digest[1024]; 12128 12129 memset(digest, 0, sizeof(digest)); 12130 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) { 12131 char *dummy, *response; 12132 enum sip_auth_type code = p->options ? p->options->auth_type : PROXY_AUTH; /* XXX force 407 if unknown */ 12133 auth_headers(code, &dummy, &response); 12134 add_header(&resp, response, digest); 12135 } else 12136 ast_log(LOG_WARNING, "No authentication available for call %s\n", p->callid); 12137 } 12138 /* If we are hanging up and know a cause for that, send it in clear text to make 12139 debugging easier. */ 12140 if (sipmethod == SIP_BYE) { 12141 char buf[10]; 12142 12143 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause)); 12144 snprintf(buf, sizeof(buf), "%d", p->hangupcause); 12145 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 12146 } 12147 12148 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 12149 }
| static int transmit_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Transmit response, no retransmits.
Definition at line 9839 of file chan_sip.c.
References __transmit_response(), and XMIT_UNRELIABLE.
Referenced by handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_do(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_refer(), handle_request_subscribe(), local_attended_transfer(), receive_message(), register_verify(), send_provisional_keepalive_full(), sip_indicate(), sip_park_thread(), sip_sendhtml(), transmit_fake_auth_response(), and transmit_provisional_response().
09840 { 09841 return __transmit_response(p, msg, req, XMIT_UNRELIABLE); 09842 }
| static int transmit_response_reliable | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK.
Definition at line 9872 of file chan_sip.c.
References __transmit_response(), sip_request::ignore, XMIT_CRITICAL, and XMIT_UNRELIABLE.
Referenced by handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_subscribe(), interpret_t38_parameters(), sip_hangup(), sip_indicate(), sip_sipredirect(), and sip_t38_abort().
09873 { 09874 return __transmit_response(p, msg, req, req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL); 09875 }
| static int transmit_response_using_temp | ( | ast_string_field | callid, | |
| struct sockaddr_in * | sin, | |||
| int | useglobal_nat, | |||
| const int | intended_method, | |||
| const struct sip_request * | req, | |||
| const char * | msg | |||
| ) | [static] |
Transmit response, no retransmits, using a temporary pvt structure.
Definition at line 9787 of file chan_sip.c.
References __transmit_response(), ast_copy_flags, ast_log(), ast_random(), ast_sip_ouraddrfor(), ast_string_field_init, ast_string_field_set, ast_test_flag, ast_threadstorage_get(), sip_pvt::branch, build_via(), copy_socket_data(), do_setnat(), sip_pvt::flags, sip_pvt::fromdomain, INITIAL_CSEQ, internip, LOG_ERROR, make_our_tag(), sip_pvt::method, sip_pvt::ocseq, sip_pvt::ourip, sip_pvt::recv, sip_pvt::sa, SIP_NAT, SIP_NAT_ROUTE, sip_request::socket, sip_pvt::socket, sip_pvt::tag, ts_temp_pvt, and XMIT_UNRELIABLE.
Referenced by find_call().
09788 { 09789 struct sip_pvt *p = NULL; 09790 09791 if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) { 09792 ast_log(LOG_ERROR, "Failed to get temporary pvt\n"); 09793 return -1; 09794 } 09795 09796 /* XXX the structure may be dirty from previous usage. 09797 * Here we should state clearly how we should reinitialize it 09798 * before using it. 09799 * E.g. certainly the threadstorage should be left alone, 09800 * but other thihngs such as flags etc. maybe need cleanup ? 09801 */ 09802 09803 /* Initialize the bare minimum */ 09804 p->method = intended_method; 09805 09806 if (!sin) 09807 p->ourip = internip; 09808 else { 09809 p->sa = *sin; 09810 ast_sip_ouraddrfor(&p->sa.sin_addr, &p->ourip, p); 09811 } 09812 09813 p->branch = ast_random(); 09814 make_our_tag(p->tag, sizeof(p->tag)); 09815 p->ocseq = INITIAL_CSEQ; 09816 09817 if (useglobal_nat && sin) { 09818 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT); 09819 p->recv = *sin; 09820 do_setnat(p, ast_test_flag(&p->flags[0], SIP_NAT) & SIP_NAT_ROUTE); 09821 } 09822 09823 ast_string_field_set(p, fromdomain, default_fromdomain); 09824 build_via(p); 09825 ast_string_field_set(p, callid, callid); 09826 09827 copy_socket_data(&p->socket, &req->socket); 09828 09829 /* Use this temporary pvt structure to send the message */ 09830 __transmit_response(p, msg, req, XMIT_UNRELIABLE); 09831 09832 /* Free the string fields, but not the pool space */ 09833 ast_string_field_init(p, 0); 09834 09835 return 0; 09836 }
| static int transmit_response_with_allow | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Append Accept header, content length before transmitting response.
Definition at line 9899 of file chan_sip.c.
References add_header(), respprep(), and send_response().
Referenced by handle_incoming(), and handle_request_options().
09900 { 09901 struct sip_request resp; 09902 respprep(&resp, p, msg, req); 09903 add_header(&resp, "Accept", "application/sdp"); 09904 return send_response(p, &resp, reliable, 0); 09905 }
| static int transmit_response_with_auth | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| const char * | rand, | |||
| enum xmittype | reliable, | |||
| const char * | header, | |||
| int | stale | |||
| ) | [static] |
Respond with authorization request.
Definition at line 9908 of file chan_sip.c.
References add_header(), append_history, ast_log(), get_header(), LOG_WARNING, sip_pvt::noncecount, sip_settings::realm, respprep(), send_response(), sip_cfg, and sip_pvt::username.
Referenced by check_auth(), and transmit_fake_auth_response().
09909 { 09910 struct sip_request resp; 09911 char tmp[512]; 09912 int seqno = 0; 09913 09914 if (reliable && (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1)) { 09915 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 09916 return -1; 09917 } 09918 /* Stale means that they sent us correct authentication, but 09919 based it on an old challenge (nonce) */ 09920 snprintf(tmp, sizeof(tmp), "Digest algorithm=MD5, realm=\"%s\", nonce=\"%s\"%s", sip_cfg.realm, randdata, stale ? ", stale=true" : ""); 09921 respprep(&resp, p, msg, req); 09922 add_header(&resp, header, tmp); 09923 append_history(p, "AuthChal", "Auth challenge sent for %s - nc %d", p->username, p->noncecount); 09924 return send_response(p, &resp, reliable, seqno); 09925 }
| static int transmit_response_with_date | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Append date and content length before transmitting response.
Definition at line 9890 of file chan_sip.c.
References append_date(), respprep(), send_response(), and XMIT_UNRELIABLE.
Referenced by handle_response_subscribe(), and register_verify().
09891 { 09892 struct sip_request resp; 09893 respprep(&resp, p, msg, req); 09894 append_date(&resp); 09895 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 09896 }
| static int transmit_response_with_minse | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| int | minse_int | |||
| ) | [static] |
Transmit 422 response with Min-SE header (Session-Timers).
Definition at line 9855 of file chan_sip.c.
References add_header(), append_date(), respprep(), send_response(), and XMIT_UNRELIABLE.
Referenced by handle_request_invite().
09856 { 09857 struct sip_request resp; 09858 char minse_str[20]; 09859 09860 respprep(&resp, p, msg, req); 09861 append_date(&resp); 09862 09863 snprintf(minse_str, sizeof(minse_str), "%d", minse_int); 09864 add_header(&resp, "Min-SE", minse_str); 09865 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 09866 }
| static int transmit_response_with_sdp | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| int | oldsdp | |||
| ) | [static] |
Used for 200 OK and 183 early media.
Definition at line 10583 of file chan_sip.c.
References add_sdp(), ast_debug, ast_log(), ast_rtp_codec_setpref(), ast_test_flag, sip_pvt::autoframing, sip_pvt::callid, FALSE, sip_pvt::flags, get_header(), LOG_ERROR, LOG_WARNING, sip_pvt::pendinginvite, sip_pvt::prefs, respprep(), sip_pvt::rtp, send_response(), SIP_OUTGOING, t38properties::state, sip_pvt::t38, T38_ENABLED, TRUE, and try_suggested_sip_codec().
Referenced by handle_invite_replaces(), handle_request_invite(), send_provisional_keepalive_full(), sip_answer(), and transmit_provisional_response().
10584 { 10585 struct sip_request resp; 10586 int seqno; 10587 if (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1) { 10588 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 10589 return -1; 10590 } 10591 respprep(&resp, p, msg, req); 10592 if (p->rtp) { 10593 if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 10594 ast_debug(1, "Setting framing from config on incoming call\n"); 10595 ast_rtp_codec_setpref(p->rtp, &p->prefs); 10596 } 10597 try_suggested_sip_codec(p); 10598 if (p->t38.state == T38_ENABLED) { 10599 add_sdp(&resp, p, oldsdp, TRUE, TRUE); 10600 } else { 10601 add_sdp(&resp, p, oldsdp, TRUE, FALSE); 10602 } 10603 } else 10604 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid); 10605 if (reliable && !p->pendinginvite) 10606 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 10607 return send_response(p, &resp, reliable, seqno); 10608 }
| static int transmit_response_with_t38_sdp | ( | struct sip_pvt * | p, | |
| char * | msg, | |||
| struct sip_request * | req, | |||
| int | retrans | |||
| ) | [static] |
Used for 200 OK and 183 early media.
Definition at line 10533 of file chan_sip.c.
References add_sdp(), ast_log(), sip_pvt::callid, get_header(), LOG_ERROR, LOG_WARNING, sip_pvt::pendinginvite, respprep(), send_response(), and sip_pvt::udptl.
Referenced by handle_request_invite(), and interpret_t38_parameters().
10534 { 10535 struct sip_request resp; 10536 int seqno; 10537 10538 if (sscanf(get_header(req, "CSeq"), "%30d ", &seqno) != 1) { 10539 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 10540 return -1; 10541 } 10542 respprep(&resp, p, msg, req); 10543 if (p->udptl) { 10544 add_sdp(&resp, p, 0, 0, 1); 10545 } else 10546 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->callid); 10547 if (retrans && !p->pendinginvite) 10548 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 10549 return send_response(p, &resp, retrans, seqno); 10550 }
| static int transmit_response_with_unsupported | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| const char * | unsupported | |||
| ) | [static] |
Transmit response, no retransmits.
Definition at line 9845 of file chan_sip.c.
References add_header(), append_date(), respprep(), send_response(), and XMIT_UNRELIABLE.
Referenced by handle_request_invite().
09846 { 09847 struct sip_request resp; 09848 respprep(&resp, p, msg, req); 09849 append_date(&resp); 09850 add_header(&resp, "Unsupported", unsupported); 09851 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 09852 }
| static int transmit_state_notify | ( | struct sip_pvt * | p, | |
| int | state, | |||
| int | full, | |||
| int | timeout | |||
| ) | [static] |
Used in the SUBSCRIBE notification subsystem (RFC3265).
Definition at line 11210 of file chan_sip.c.
References add_content(), add_header(), ast_channel_search_locked(), ast_channel_unlock, ast_copy_string(), AST_DEVICE_UNAVAILABLE, AST_EXTENSION_BUSY, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_REMOVED, AST_EXTENSION_RINGING, AST_EXTENSION_UNAVAILABLE, ast_get_hint(), ast_log(), AST_MAX_EXTENSION, ast_str_alloca, ast_str_append(), ast_strdupa, ast_strlen_zero(), sip_pvt::callid, ast_channel::cid, ast_callerid::cid_name, ast_callerid::cid_num, sip_pvt::context, CPIM_PIDF_XML, DIALOG_INFO_XML, sip_pvt::dialogver, cfsubscription_types::event, sip_pvt::expiry, sip_pvt::exten, find_calling_channel(), find_subscription_type(), sip_pvt::fromdomain, get_header(), get_in_brackets(), sip_pvt::initreq, LOG_WARNING, cfsubscription_types::mediatype, NONE, sip_settings::notifycid, sip_settings::notifyringing, sip_pvt::ocseq, sip_settings::pedanticsipchecking, sip_pvt::pendinginvite, PIDF_XML, remove_uri_parameters(), reqprep(), send_request(), sip_cfg, SIP_NOTIFY, strsep(), sip_pvt::subscribed, sip_pvt::tag, sip_pvt::theirtag, XMIT_RELIABLE, and XPIDF_XML.
Referenced by __sip_autodestruct(), cb_extensionstate(), and handle_request_subscribe().
11211 { 11212 struct ast_str *tmp = ast_str_alloca(4000); 11213 char from[256], to[256]; 11214 char *c, *mfrom, *mto; 11215 struct sip_request req; 11216 char hint[AST_MAX_EXTENSION]; 11217 char *statestring = "terminated"; 11218 const struct cfsubscription_types *subscriptiontype; 11219 enum state { NOTIFY_OPEN, NOTIFY_INUSE, NOTIFY_CLOSED } local_state = NOTIFY_OPEN; 11220 char *pidfstate = "--"; 11221 char *pidfnote= "Ready"; 11222 11223 memset(from, 0, sizeof(from)); 11224 memset(to, 0, sizeof(to)); 11225 11226 switch (state) { 11227 case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE): 11228 statestring = (sip_cfg.notifyringing) ? "early" : "confirmed"; 11229 local_state = NOTIFY_INUSE; 11230 pidfstate = "busy"; 11231 pidfnote = "Ringing"; 11232 break; 11233 case AST_EXTENSION_RINGING: 11234 statestring = "early"; 11235 local_state = NOTIFY_INUSE; 11236 pidfstate = "busy"; 11237 pidfnote = "Ringing"; 11238 break; 11239 case AST_EXTENSION_INUSE: 11240 statestring = "confirmed"; 11241 local_state = NOTIFY_INUSE; 11242 pidfstate = "busy"; 11243 pidfnote = "On the phone"; 11244 break; 11245 case AST_EXTENSION_BUSY: 11246 statestring = "confirmed"; 11247 local_state = NOTIFY_CLOSED; 11248 pidfstate = "busy"; 11249 pidfnote = "On the phone"; 11250 break; 11251 case AST_EXTENSION_UNAVAILABLE: 11252 statestring = "terminated"; 11253 local_state = NOTIFY_CLOSED; 11254 pidfstate = "away"; 11255 pidfnote = "Unavailable"; 11256 break; 11257 case AST_EXTENSION_ONHOLD: 11258 statestring = "confirmed"; 11259 local_state = NOTIFY_CLOSED; 11260 pidfstate = "busy"; 11261 pidfnote = "On hold"; 11262 break; 11263 case AST_EXTENSION_NOT_INUSE: 11264 default: 11265 /* Default setting */ 11266 break; 11267 } 11268 11269 subscriptiontype = find_subscription_type(p->subscribed); 11270 11271 /* Check which device/devices we are watching and if they are registered */ 11272 if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, p->exten)) { 11273 char *hint2 = hint, *individual_hint = NULL; 11274 int hint_count = 0, unavailable_count = 0; 11275 11276 while ((individual_hint = strsep(&hint2, "&"))) { 11277 hint_count++; 11278 11279 if (ast_device_state(individual_hint) == AST_DEVICE_UNAVAILABLE) 11280 unavailable_count++; 11281 } 11282 11283 /* If none of the hinted devices are registered, we will 11284 * override notification and show no availability. 11285 */ 11286 if (hint_count > 0 && hint_count == unavailable_count) { 11287 local_state = NOTIFY_CLOSED; 11288 pidfstate = "away"; 11289 pidfnote = "Not online"; 11290 } 11291 } 11292 11293 ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from)); 11294 c = get_in_brackets(from); 11295 if (strncasecmp(c, "sip:", 4) && strncasecmp(c, "sips:", 5)) { 11296 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 11297 return -1; 11298 } 11299 11300 mfrom = remove_uri_parameters(c); 11301 11302 ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); 11303 c = get_in_brackets(to); 11304 if (strncasecmp(c, "sip:", 4) && strncasecmp(c, "sips:", 5)) { 11305 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 11306 return -1; 11307 } 11308 mto = remove_uri_parameters(c); 11309 11310 reqprep(&req, p, SIP_NOTIFY, 0, 1); 11311 11312 11313 add_header(&req, "Event", subscriptiontype->event); 11314 add_header(&req, "Content-Type", subscriptiontype->mediatype); 11315 switch(state) { 11316 case AST_EXTENSION_DEACTIVATED: 11317 if (timeout) 11318 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 11319 else { 11320 add_header(&req, "Subscription-State", "terminated;reason=probation"); 11321 add_header(&req, "Retry-After", "60"); 11322 } 11323 break; 11324 case AST_EXTENSION_REMOVED: 11325 add_header(&req, "Subscription-State", "terminated;reason=noresource"); 11326 break; 11327 default: 11328 if (p->expiry) 11329 add_header(&req, "Subscription-State", "active"); 11330 else /* Expired */ 11331 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 11332 } 11333 switch (p->subscribed) { 11334 case XPIDF_XML: 11335 case CPIM_PIDF_XML: 11336 ast_str_append(&tmp, 0, 11337 "<?xml version=\"1.0\"?>\n" 11338 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n" 11339 "<presence>\n"); 11340 ast_str_append(&tmp, 0, "<presentity uri=\"%s;method=SUBSCRIBE\" />\n", mfrom); 11341 ast_str_append(&tmp, 0, "<atom id=\"%s\">\n", p->exten); 11342 ast_str_append(&tmp, 0, "<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", mto); 11343 ast_str_append(&tmp, 0, "<status status=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "open" : (local_state == NOTIFY_INUSE) ? "inuse" : "closed"); 11344 ast_str_append(&tmp, 0, "<msnsubstatus substatus=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "online" : (local_state == NOTIFY_INUSE) ? "onthephone" : "offline"); 11345 ast_str_append(&tmp, 0, "</address>\n</atom>\n</presence>\n"); 11346 break; 11347 case PIDF_XML: /* Eyebeam supports this format */ 11348 ast_str_append(&tmp, 0, 11349 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" 11350 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nxmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\nentity=\"%s\">\n", mfrom); 11351 ast_str_append(&tmp, 0, "<pp:person><status>\n"); 11352 if (pidfstate[0] != '-') 11353 ast_str_append(&tmp, 0, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate); 11354 ast_str_append(&tmp, 0, "</status></pp:person>\n"); 11355 ast_str_append(&tmp, 0, "<note>%s</note>\n", pidfnote); /* Note */ 11356 ast_str_append(&tmp, 0, "<tuple id=\"%s\">\n", p->exten); /* Tuple start */ 11357 ast_str_append(&tmp, 0, "<contact priority=\"1\">%s</contact>\n", mto); 11358 if (pidfstate[0] == 'b') /* Busy? Still open ... */ 11359 ast_str_append(&tmp, 0, "<status><basic>open</basic></status>\n"); 11360 else 11361 ast_str_append(&tmp, 0, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed"); 11362 ast_str_append(&tmp, 0, "</tuple>\n</presence>\n"); 11363 break; 11364 case DIALOG_INFO_XML: /* SNOM subscribes in this format */ 11365 ast_str_append(&tmp, 0, "<?xml version=\"1.0\"?>\n"); 11366 ast_str_append(&tmp, 0, "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"%d\" state=\"%s\" entity=\"%s\">\n", p->dialogver++, full ? "full" : "partial", mto); 11367 if ((state & AST_EXTENSION_RINGING) && sip_cfg.notifyringing) { 11368 const char *local_display = p->exten; 11369 char *local_target = mto; 11370 11371 /* There are some limitations to how this works. The primary one is that the 11372 callee must be dialing the same extension that is being monitored. Simply dialing 11373 the hint'd device is not sufficient. */ 11374 if (sip_cfg.notifycid) { 11375 struct ast_channel *caller = ast_channel_search_locked(find_calling_channel, p); 11376 11377 if (caller) { 11378 int need = strlen(caller->cid.cid_num) + strlen(p->fromdomain) + sizeof("sip:@"); 11379 local_target = alloca(need); 11380 snprintf(local_target, need, "sip:%s@%s", caller->cid.cid_num, p->fromdomain); 11381 if (!(ast_strlen_zero(caller->cid.cid_name))) { 11382 local_display = ast_strdupa(caller->cid.cid_name); 11383 } 11384 ast_channel_unlock(caller); 11385 caller = NULL; 11386 } 11387 /* We create a fake call-id which the phone will send back in an INVITE 11388 * Replaces header which we can grab and do some magic with. */ 11389 if (sip_cfg.pedanticsipchecking) { 11390 ast_str_append(&tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"recipient\">\n", 11391 p->exten, p->callid, p->theirtag, p->tag); 11392 } else { 11393 ast_str_append(&tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" direction=\"recipient\">\n", 11394 p->exten, p->callid); 11395 } 11396 ast_str_append(&tmp, 0, 11397 "<remote>\n" 11398 /* See the limitations of this above. Luckily the phone seems to still be 11399 happy when these values are not correct. */ 11400 "<identity display=\"%s\">%s</identity>\n" 11401 "<target uri=\"%s\"/>\n" 11402 "</remote>\n" 11403 "<local>\n" 11404 "<identity>%s</identity>\n" 11405 "<target uri=\"%s\"/>\n" 11406 "</local>\n", 11407 local_display, local_target, local_target, mto, mto); 11408 } else { 11409 ast_str_append(&tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n", p->exten); 11410 } 11411 } else { 11412 ast_str_append(&tmp, 0, "<dialog id=\"%s\">\n", p->exten); 11413 } 11414 ast_str_append(&tmp, 0, "<state>%s</state>\n", statestring); 11415 if (state == AST_EXTENSION_ONHOLD) { 11416 ast_str_append(&tmp, 0, "<local>\n<target uri=\"%s\">\n" 11417 "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n" 11418 "</target>\n</local>\n", mto); 11419 } 11420 ast_str_append(&tmp, 0, "</dialog>\n</dialog-info>\n"); 11421 break; 11422 case NONE: 11423 default: 11424 break; 11425 } 11426 11427 add_content(&req, tmp->str); 11428 11429 p->pendinginvite = p->ocseq; /* Remember that we have a pending NOTIFY in order not to confuse the NOTIFY subsystem */ 11430 11431 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 11432 }
| static void try_suggested_sip_codec | ( | struct sip_pvt * | p | ) | [static] |
Try setting codec suggested by the SIP_CODEC channel variable.
Definition at line 6237 of file chan_sip.c.
References ast_getformatbyname(), ast_log(), sip_pvt::capability, sip_pvt::jointcapability, LOG_NOTICE, sip_pvt::owner, and pbx_builtin_getvar_helper().
Referenced by sip_answer(), and transmit_response_with_sdp().
06238 { 06239 int fmt; 06240 const char *codec; 06241 06242 codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"); 06243 if (!codec) 06244 return; 06245 06246 fmt = ast_getformatbyname(codec); 06247 if (fmt) { 06248 ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); 06249 if (p->jointcapability & fmt) { 06250 p->jointcapability &= fmt; 06251 p->capability &= fmt; 06252 } else 06253 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n"); 06254 } else 06255 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec); 06256 return; 06257 }
| static void unlink_marked_peers_from_tables | ( | void | ) | [static] |
Definition at line 3113 of file chan_sip.c.
References ao2_t_callback, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, and peer_is_marked().
Referenced by sip_do_reload(), and sip_prune_realtime().
03114 { 03115 ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, NULL, 03116 "initiating callback to remove marked peers"); 03117 ao2_t_callback(peers_by_ip, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, peer_is_marked, NULL, 03118 "initiating callback to remove marked peers"); 03119 }
| static void unlink_peer_from_tables | ( | struct sip_peer * | peer | ) | [static] |
Definition at line 3122 of file chan_sip.c.
References sip_peer::addr, and ao2_t_unlink.
Referenced by expire_register().
03123 { 03124 ao2_t_unlink(peers, peer, "ao2_unlink of peer from peers table"); 03125 if (peer->addr.sin_addr.s_addr) { 03126 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table"); 03127 } 03128 }
| static int unload_module | ( | void | ) | [static] |
PBX unload module API.
Definition at line 26126 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ARRAY_LEN, ast_channel_unregister(), ast_cli_unregister_multiple(), ast_context_destroy(), ast_context_find(), ast_custom_function_unregister(), ast_free, ast_free_ha(), ast_manager_unregister(), ast_mutex_lock(), ast_mutex_unlock(), AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_proto_unregister(), ast_sched_dump(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_tcptls_server_stop(), ast_udptl_proto_unregister(), ast_unload_realtime(), ast_unregister_application(), ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, clear_realm_authentication(), clear_sip_domains(), default_tls_cfg, dialog_unlink_all(), ast_tcptls_session_args::master, monlock, sip_pvt::owner, regl, sched_context_destroy(), sip_registry_destroy(), sip_subscribe_mwi_destroy(), sip_threadinfo::stop, submwil, thread, sip_threadinfo::threadid, and TRUE.
26127 { 26128 struct sip_pvt *p; 26129 struct sip_threadinfo *th; 26130 struct ast_context *con; 26131 struct ao2_iterator i; 26132 26133 ast_sched_dump(sched); 26134 26135 /* First, take us out of the channel type list */ 26136 ast_channel_unregister(&sip_tech); 26137 26138 /* Unregister dial plan functions */ 26139 ast_custom_function_unregister(&sipchaninfo_function); 26140 ast_custom_function_unregister(&sippeer_function); 26141 ast_custom_function_unregister(&sip_header_function); 26142 ast_custom_function_unregister(&checksipdomain_function); 26143 26144 /* Unregister dial plan applications */ 26145 ast_unregister_application(app_dtmfmode); 26146 ast_unregister_application(app_sipaddheader); 26147 ast_unregister_application(app_sipremoveheader); 26148 26149 /* Unregister CLI commands */ 26150 ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip)); 26151 26152 /* Disconnect from the RTP subsystem */ 26153 ast_rtp_proto_unregister(&sip_rtp); 26154 26155 /* Disconnect from UDPTL */ 26156 ast_udptl_proto_unregister(&sip_udptl); 26157 26158 /* Unregister AMI actions */ 26159 ast_manager_unregister("SIPpeers"); 26160 ast_manager_unregister("SIPshowpeer"); 26161 ast_manager_unregister("SIPqualifypeer"); 26162 ast_manager_unregister("SIPshowregistry"); 26163 ast_manager_unregister("SIPnotify"); 26164 26165 /* Kill TCP/TLS server threads */ 26166 if (sip_tcp_desc.master) 26167 ast_tcptls_server_stop(&sip_tcp_desc); 26168 if (sip_tls_desc.master) 26169 ast_tcptls_server_stop(&sip_tls_desc); 26170 26171 /* Kill all existing TCP/TLS threads */ 26172 i = ao2_iterator_init(threadt, 0); 26173 while ((th = ao2_t_iterator_next(&i, "iterate through tcp threads for 'sip show tcp'"))) { 26174 pthread_t thread = th->threadid; 26175 th->stop = 1; 26176 pthread_kill(thread, SIGURG); 26177 pthread_join(thread, NULL); 26178 ao2_t_ref(th, -1, "decrement ref from iterator"); 26179 } 26180 ao2_iterator_destroy(&i); 26181 26182 /* Hangup all dialogs if they have an owner */ 26183 i = ao2_iterator_init(dialogs, 0); 26184 while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 26185 if (p->owner) 26186 ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); 26187 ao2_t_ref(p, -1, "toss dialog ptr from iterator_next"); 26188 } 26189 ao2_iterator_destroy(&i); 26190 26191 ast_mutex_lock(&monlock); 26192 if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { 26193 pthread_cancel(monitor_thread); 26194 pthread_kill(monitor_thread, SIGURG); 26195 pthread_join(monitor_thread, NULL); 26196 } 26197 monitor_thread = AST_PTHREADT_STOP; 26198 ast_mutex_unlock(&monlock); 26199 26200 /* Destroy all the dialogs and free their memory */ 26201 i = ao2_iterator_init(dialogs, 0); 26202 while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 26203 dialog_unlink_all(p, TRUE, TRUE); 26204 ao2_t_ref(p, -1, "throw away iterator result"); 26205 } 26206 ao2_iterator_destroy(&i); 26207 26208 /* Free memory for local network address mask */ 26209 ast_free_ha(localaddr); 26210 26211 clear_realm_authentication(authl); 26212 26213 26214 if (default_tls_cfg.certfile) 26215 ast_free(default_tls_cfg.certfile); 26216 if (default_tls_cfg.cipher) 26217 ast_free(default_tls_cfg.cipher); 26218 if (default_tls_cfg.cafile) 26219 ast_free(default_tls_cfg.cafile); 26220 if (default_tls_cfg.capath) 26221 ast_free(default_tls_cfg.capath); 26222 26223 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 26224 ASTOBJ_CONTAINER_DESTROY(®l); 26225 ASTOBJ_CONTAINER_DESTROYALL(&submwil, sip_subscribe_mwi_destroy); 26226 ASTOBJ_CONTAINER_DESTROY(&submwil); 26227 26228 ao2_t_ref(peers, -1, "unref the peers table"); 26229 ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table"); 26230 ao2_t_ref(dialogs, -1, "unref the dialogs table"); 26231 ao2_t_ref(threadt, -1, "unref the thread table"); 26232 26233 clear_sip_domains(); 26234 ast_free_ha(global_contact_ha); 26235 close(sipsock); 26236 sched_context_destroy(sched); 26237 con = ast_context_find(used_context); 26238 if (con) 26239 ast_context_destroy(con, "SIP"); 26240 ast_unload_realtime("sipregs"); 26241 ast_unload_realtime("sippeers"); 26242 26243 return 0; 26244 }
| static void* unref_peer | ( | struct sip_peer * | peer, | |
| char * | tag | |||
| ) | [static] |
helper functions to unreference various types of objects. By handling them this way, we don't have to declare the destructor on each call, which removes the chance of errors.
Definition at line 3135 of file chan_sip.c.
References ao2_t_ref.
Referenced by __sip_destroy(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), build_peer(), check_peer_ok(), complete_sip_peer(), complete_sip_registered_peer(), complete_sip_user(), create_addr(), expire_register(), find_peer(), function_sippeer(), handle_request_subscribe(), handle_response_peerpoke(), parse_register_contact(), realtime_peer(), reg_source_db(), register_verify(), reload_config(), sip_devicestate(), sip_do_debug_peer(), sip_peer_hold(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_poke_peer_s(), sip_prune_realtime(), sip_show_inuse(), sip_show_user(), sip_show_users(), sip_unregister(), st_get_mode(), st_get_refresher(), st_get_se(), transmit_register(), and update_call_counter().
03136 { 03137 ao2_t_ref(peer, -1, tag); 03138 return NULL; 03139 }
| static int update_call_counter | ( | struct sip_pvt * | fup, | |
| int | event | |||
| ) | [static] |
update_call_counter: Handle call_limit for SIP devices Setting a call-limit will cause calls above the limit not to be accepted.
Remember that for a type=friend, there's one limit for the user and another for the peer, not a combined call limit. This will cause unexpected behaviour in subscriptions, since a "friend" is *two* devices in Asterisk, not one.
Thought: For realtime, we should probably update storage with inuse counter...
Definition at line 5708 of file chan_sip.c.
References ao2_lock(), ao2_unlock(), ast_clear_flag, ast_copy_string(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), ast_set_flag, ast_strlen_zero(), ast_test_flag, sip_peer::call_limit, DEC_CALL_LIMIT, DEC_CALL_RINGING, FALSE, find_peer(), FINDALLDEVICES, sip_pvt::flags, INC_CALL_LIMIT, INC_CALL_RINGING, sip_peer::inRinging, sip_peer::inUse, inuse, LOG_ERROR, LOG_NOTICE, sip_peer::name, name, sip_settings::notifyhold, sip_pvt::outgoing_call, sip_pvt::peername, SIP_CALL_LIMIT, sip_cfg, SIP_INC_COUNT, SIP_INC_RINGING, SIP_PAGE2_CALL_ONHOLD, sip_peer_hold(), sip_pvt_lock, sip_pvt_unlock, TRUE, unref_peer(), and sip_pvt::username.
Referenced by __sip_destroy(), handle_request_cancel(), handle_request_invite(), handle_response_invite(), sip_call(), and sip_hangup().
05709 { 05710 char name[256]; 05711 int *inuse = NULL, *call_limit = NULL, *inringing = NULL; 05712 int outgoing = fup->outgoing_call; 05713 struct sip_peer *p = NULL; 05714 05715 ast_debug(3, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming"); 05716 05717 05718 /* Test if we need to check call limits, in order to avoid 05719 realtime lookups if we do not need it */ 05720 if (!ast_test_flag(&fup->flags[0], SIP_CALL_LIMIT) && !ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD)) 05721 return 0; 05722 05723 ast_copy_string(name, fup->username, sizeof(name)); 05724 05725 /* Check the list of devices */ 05726 if ((p = find_peer(ast_strlen_zero(fup->peername) ? name : fup->peername, NULL, TRUE, FINDALLDEVICES, FALSE, 0))) { 05727 inuse = &p->inUse; 05728 call_limit = &p->call_limit; 05729 inringing = &p->inRinging; 05730 ast_copy_string(name, fup->peername, sizeof(name)); 05731 } 05732 if (!p) { 05733 ast_debug(2, "%s is not a local device, no call limit\n", name); 05734 return 0; 05735 } 05736 05737 switch(event) { 05738 /* incoming and outgoing affects the inUse counter */ 05739 case DEC_CALL_LIMIT: 05740 /* Decrement inuse count if applicable */ 05741 if (inuse) { 05742 sip_pvt_lock(fup); 05743 ao2_lock(p); 05744 if (*inuse > 0) { 05745 if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { 05746 (*inuse)--; 05747 ast_clear_flag(&fup->flags[0], SIP_INC_COUNT); 05748 } 05749 } else { 05750 *inuse = 0; 05751 } 05752 ao2_unlock(p); 05753 sip_pvt_unlock(fup); 05754 } 05755 05756 /* Decrement ringing count if applicable */ 05757 if (inringing) { 05758 sip_pvt_lock(fup); 05759 ao2_lock(p); 05760 if (*inringing > 0) { 05761 if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 05762 (*inringing)--; 05763 ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); 05764 } 05765 } else { 05766 *inringing = 0; 05767 } 05768 ao2_unlock(p); 05769 sip_pvt_unlock(fup); 05770 } 05771 05772 /* Decrement onhold count if applicable */ 05773 sip_pvt_lock(fup); 05774 ao2_lock(p); 05775 if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && sip_cfg.notifyhold) { 05776 ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD); 05777 ao2_unlock(p); 05778 sip_pvt_unlock(fup); 05779 sip_peer_hold(fup, FALSE); 05780 } else { 05781 ao2_unlock(p); 05782 sip_pvt_unlock(fup); 05783 } 05784 if (sipdebug) 05785 ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", "peer", name, *call_limit); 05786 break; 05787 05788 case INC_CALL_RINGING: 05789 case INC_CALL_LIMIT: 05790 /* If call limit is active and we have reached the limit, reject the call */ 05791 if (*call_limit > 0 ) { 05792 if (*inuse >= *call_limit) { 05793 ast_log(LOG_NOTICE, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", "peer", name, *call_limit); 05794 unref_peer(p, "update_call_counter: unref peer p, call limit exceeded"); 05795 return -1; 05796 } 05797 } 05798 if (inringing && (event == INC_CALL_RINGING)) { 05799 sip_pvt_lock(fup); 05800 ao2_lock(p); 05801 if (!ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 05802 (*inringing)++; 05803 ast_set_flag(&fup->flags[0], SIP_INC_RINGING); 05804 } 05805 ao2_unlock(p); 05806 sip_pvt_unlock(fup); 05807 } 05808 if (inuse) { 05809 sip_pvt_lock(fup); 05810 ao2_lock(p); 05811 if (!ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { 05812 (*inuse)++; 05813 ast_set_flag(&fup->flags[0], SIP_INC_COUNT); 05814 } 05815 ao2_unlock(p); 05816 sip_pvt_unlock(fup); 05817 } 05818 if (sipdebug) { 05819 ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", "peer", name, *inuse, *call_limit); 05820 } 05821 break; 05822 05823 case DEC_CALL_RINGING: 05824 if (inringing) { 05825 sip_pvt_lock(fup); 05826 ao2_lock(p); 05827 if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 05828 if (*inringing > 0) { 05829 (*inringing)--; 05830 } 05831 ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); 05832 } 05833 ao2_unlock(p); 05834 sip_pvt_unlock(fup); 05835 } 05836 break; 05837 05838 default: 05839 ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event); 05840 } 05841 05842 if (p) { 05843 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->name); 05844 unref_peer(p, "update_call_counter: unref_peer from call counter"); 05845 } 05846 return 0; 05847 }
| static void update_peer | ( | struct sip_peer * | p, | |
| int | expire | |||
| ) | [static] |
Update peer data in database (if used).
Definition at line 4761 of file chan_sip.c.
References sip_peer::addr, ast_test_flag, sip_peer::deprecated_username, sip_peer::flags, sip_peer::fullcontact, sip_peer::is_realtime, sip_peer::lastms, sip_peer::name, sip_settings::peer_rtupdate, realtime_update_peer(), sip_cfg, SIP_PAGE2_RTCACHEFRIENDS, sip_peer::useragent, and sip_peer::username.
Referenced by register_verify().
04762 { 04763 int rtcachefriends = ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS); 04764 if (sip_cfg.peer_rtupdate && 04765 (p->is_realtime || rtcachefriends)) { 04766 realtime_update_peer(p->name, &p->addr, p->username, rtcachefriends ? p->fullcontact : NULL, p->useragent, expire, p->deprecated_username, p->lastms); 04767 } 04768 }
| static void update_provisional_keepalive | ( | struct sip_pvt * | pvt, | |
| int | with_sdp | |||
| ) | [static] |
Definition at line 4248 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL_UNREF, dialog_ref(), dialog_unref(), PROVIS_KEEPALIVE_TIMEOUT, sip_pvt::provisional_keepalive_sched_id, send_provisional_keepalive(), and send_provisional_keepalive_with_sdp().
Referenced by transmit_provisional_response().
04249 { 04250 AST_SCHED_DEL_UNREF(sched, pvt->provisional_keepalive_sched_id, dialog_unref(pvt, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 04251 04252 pvt->provisional_keepalive_sched_id = ast_sched_add(sched, PROVIS_KEEPALIVE_TIMEOUT, 04253 with_sdp ? send_provisional_keepalive_with_sdp : send_provisional_keepalive, dialog_ref(pvt, "Increment refcount to pass dialog pointer to sched callback")); 04254 }
struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_DEFAULT , .description = "Session Initiation Protocol (SIP)" , .key = "This paragraph is copyright (c) 2006 by Digium, Inc. \In order for your module to load, it must return this \key via a function called \"key\". Any code which \includes this paragraph must be licensed under the GNU \General Public License version 2 or later (at your \option). In addition to Digium's general reservations \of rights, Digium expressly reserves the right to \allow other parties to license this paragraph under \different terms. Any use of Digium, Inc. trademarks or \logos (including \"Asterisk\" or \"Digium\") without \express written permission of Digium, Inc. is prohibited.\n" , .buildopt_sum = AST_BUILDOPT_SUM, .load = load_module, .unload = unload_module, .reload = reload, } [static] |
Definition at line 26250 of file chan_sip.c.
int apeerobjs = 0 [static] |
Autocreated peer objects
Definition at line 1130 of file chan_sip.c.
char* app_dtmfmode = "SIPDtmfMode" [static] |
Definition at line 25668 of file chan_sip.c.
char* app_sipaddheader = "SIPAddHeader" [static] |
Definition at line 25669 of file chan_sip.c.
char* app_sipremoveheader = "SIPRemoveHeader" [static] |
Definition at line 25670 of file chan_sip.c.
struct ast_module_info* ast_module_info = &__mod_info [static] |
Definition at line 26250 of file chan_sip.c.
struct sockaddr_in bindaddr [static] |
UDP: The address we bind to
Definition at line 2171 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), create_addr(), create_addr_from_peer(), handle_request_invite(), reload_config(), sip_alloc(), sip_show_settings(), and sipsock_read().
unsigned int chan_idx [static] |
Definition at line 851 of file chan_sip.c.
struct ast_threadstorage check_auth_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_check_auth_buf , .custom_init = NULL , } [static] |
Definition at line 12739 of file chan_sip.c.
Referenced by check_auth(), and transmit_fake_auth_response().
struct ast_custom_function checksipdomain_function [static] |
Initial value:
{
.name = "CHECKSIPDOMAIN",
.read = func_check_sipdomain,
}
Definition at line 17473 of file chan_sip.c.
struct ast_cli_entry cli_sip[] [static] |
const char config[] = "sip.conf" [static] |
Main configuration file
Definition at line 566 of file chan_sip.c.
struct sockaddr_in debugaddr [static] |
Definition at line 2216 of file chan_sip.c.
Referenced by sip_debug_test_addr(), sip_do_debug(), sip_do_debug_ip(), and sip_do_debug_peer().
char default_callerid[AST_MAX_EXTENSION] [static] |
Definition at line 1017 of file chan_sip.c.
int default_expiry = DEFAULT_DEFAULT_EXPIRY [static] |
Definition at line 519 of file chan_sip.c.
char default_fromdomain[AST_MAX_EXTENSION] [static] |
Definition at line 1018 of file chan_sip.c.
struct ast_jb_conf default_jbconf [static] |
Global jitterbuffer configuration - by default, jb is disabled.
Definition at line 556 of file chan_sip.c.
char default_language[MAX_LANGUAGE] [static] |
Definition at line 1016 of file chan_sip.c.
int default_maxcallbitrate [static] |
Maximum bitrate for call
Definition at line 1026 of file chan_sip.c.
char default_mohinterpret[MAX_MUSICCLASS] [static] |
Global setting for moh class to use when put on hold
Definition at line 1022 of file chan_sip.c.
char default_mohsuggest[MAX_MUSICCLASS] [static] |
Global setting for moh class to suggest when putting a bridged channel on hold
Definition at line 1023 of file chan_sip.c.
char default_notifymime[AST_MAX_EXTENSION] [static] |
Definition at line 1019 of file chan_sip.c.
char default_parkinglot[AST_MAX_CONTEXT] [static] |
Parkinglot
Definition at line 1025 of file chan_sip.c.
struct ast_codec_pref default_prefs [static] |
Default codec prefs
Definition at line 1027 of file chan_sip.c.
Referenced by reload_config(), set_peer_defaults(), sip_alloc(), sip_show_settings(), and temp_peer().
unsigned int default_primary_transport [static] |
Default primary Transport (enum sip_transport) for outbound connections to devices
Definition at line 1029 of file chan_sip.c.
int default_qualify [static] |
Default Qualify= setting
Definition at line 1020 of file chan_sip.c.
struct ast_tls_config default_tls_cfg [static] |
Default TLS connection configuration.
Definition at line 2692 of file chan_sip.c.
Referenced by reload_config(), sip_prepare_socket(), sip_show_settings(), and unload_module().
unsigned int default_transports [static] |
Default Transports (enum sip_transport) that are acceptable
Definition at line 1028 of file chan_sip.c.
char default_vmexten[AST_MAX_EXTENSION] [static] |
Definition at line 1021 of file chan_sip.c.
| struct ao2_container* dialogs |
Here we implement the container for dialogs (sip_pvt), defining generic wrapper functions to ease the transition from the current implementation (a single linked list) to a different container. In addition to a reference to the container, we need functions to lock/unlock the container and individual items, and functions to add/remove references to the individual items.
Definition at line 1727 of file chan_sip.c.
mapping between dtmf flags and strings
Definition at line 15114 of file chan_sip.c.
Referenced by conf_run(), handle_link_data(), handle_remote_data(), and send_dtmf().
int dumphistory [static] |
Dump history to verbose before destroying SIP dialog
Definition at line 1096 of file chan_sip.c.
time_t externexpire [static] |
Expiration counter for re-resolving external host name in dynamic DNS
Definition at line 2202 of file chan_sip.c.
char externhost[MAXHOSTNAMELEN] [static] |
External host name
Definition at line 2201 of file chan_sip.c.
struct sockaddr_in externip [static] |
our external IP address/port for SIP sessions. externip.sin_addr is only set when we know we might be behind a NAT, and this is done using a variety of (mutually exclusive) ways from the config file:
+ with "externip = host[:port]" we specify the address/port explicitly. The address is looked up only once when (re)loading the config file;
+ with "externhost = host[:port]" we do a similar thing, but the hostname is stored in externhost, and the hostname->IP mapping is refreshed every 'externrefresh' seconds;
+ with "stunaddr = host[:port]" we run queries every externrefresh seconds to the specified server, and store the result in externip.
Other variables (externhost, externexpire, externrefresh) are used to support the above functions. External IP address if we are behind NAT
Definition at line 2199 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), reload_config(), and sip_show_settings().
int externrefresh = 10 [static] |
Definition at line 2203 of file chan_sip.c.
struct _map_x_s faxecmodes[] [static] |
Definition at line 15546 of file chan_sip.c.
int global_authfailureevents [static] |
Whether we send authentication failure manager events or not. Default no.
Definition at line 1101 of file chan_sip.c.
int global_autoframing [static] |
Turn autoframing on or off.
Definition at line 1105 of file chan_sip.c.
int global_callcounter [static] |
Enable call counters for all devices. This is currently enabled by setting the peer call-limit to INT_MAX. When we remove the call-limit from the code, we can make it with just a boolean flag in the device structure
Definition at line 1084 of file chan_sip.c.
int global_capability = AST_FORMAT_ULAW | AST_FORMAT_ALAW | AST_FORMAT_GSM | AST_FORMAT_H263 [static] |
struct ast_ha* global_contact_ha = NULL [static] |
Global list of addresses dynamic peers are not allowed to use.
Definition at line 1123 of file chan_sip.c.
unsigned int global_cos_audio [static] |
802.1p class of service for audio RTP packets
Definition at line 1092 of file chan_sip.c.
unsigned int global_cos_sip [static] |
802.1p class of service for SIP packets
Definition at line 1091 of file chan_sip.c.
unsigned int global_cos_text [static] |
802.1p class of service for text RTP packets
Definition at line 1094 of file chan_sip.c.
unsigned int global_cos_video [static] |
802.1p class of service for video RTP packets
Definition at line 1093 of file chan_sip.c.
int global_dynamic_exclude_static = 0 [static] |
Exclude static peers from contact registrations
Definition at line 1119 of file chan_sip.c.
struct ast_flags global_flags[2] = {{0}} [static] |
global SIP_ flags
Definition at line 1134 of file chan_sip.c.
struct ast_jb_conf global_jbconf [static] |
Global jitterbuffer configuration
Definition at line 564 of file chan_sip.c.
Referenced by reload_config(), sip_get_rtp_peer(), sip_new(), and sip_show_settings().
int global_match_auth_username [static] |
Match auth username if available instead of From: Default off.
Definition at line 1073 of file chan_sip.c.
int global_max_se [static] |
Highest threshold for session refresh interval
Definition at line 1117 of file chan_sip.c.
int global_min_se [static] |
Lowest threshold for session refresh interval
Definition at line 1116 of file chan_sip.c.
int global_prematuremediafilter [static] |
Enable/disable premature frames in a call (causing 183 early media)
Definition at line 1076 of file chan_sip.c.
int global_qualify_gap [static] |
Time between our group of peer pokes
Definition at line 1107 of file chan_sip.c.
int global_qualify_peers [static] |
Number of peers to poke at a given time
Definition at line 1108 of file chan_sip.c.
int global_qualifyfreq [static] |
Qualify frequency
Definition at line 1106 of file chan_sip.c.
int global_reg_timeout [static] |
Definition at line 1081 of file chan_sip.c.
int global_regattempts_max [static] |
Registration attempts before giving up
Definition at line 1082 of file chan_sip.c.
char global_regcontext[AST_MAX_CONTEXT] [static] |
Context for auto-extensions
Definition at line 1097 of file chan_sip.c.
static int global_relaxdtmf [static] |
Relax DTMF
Definition at line 1075 of file chan_sip.c.
int global_rtpholdtimeout [static] |
Time out call if no RTP during hold
Definition at line 1079 of file chan_sip.c.
int global_rtpkeepalive [static] |
Send RTP keepalives
Definition at line 1080 of file chan_sip.c.
int global_rtptimeout [static] |
Time out call if no RTP
Definition at line 1078 of file chan_sip.c.
char global_sdpowner[AST_MAX_EXTENSION] [static] |
SDP owner name for the SIP channel
Definition at line 1100 of file chan_sip.c.
char global_sdpsession[AST_MAX_EXTENSION] [static] |
SDP session name for the SIP channel
Definition at line 1099 of file chan_sip.c.
int global_shrinkcallerid [static] |
enable or disable shrinking of caller id
Definition at line 1083 of file chan_sip.c.
enum st_mode global_st_mode [static] |
Mode of operation for Session-Timers
Definition at line 1114 of file chan_sip.c.
enum st_refresher global_st_refresher [static] |
Session-Timer refresher
Definition at line 1115 of file chan_sip.c.
int global_t1 [static] |
T1 time
Definition at line 1102 of file chan_sip.c.
int global_t1min [static] |
T1 roundtrip time minimum
Definition at line 1103 of file chan_sip.c.
int global_t38_maxdatagram [static] |
global T.38 FaxMaxDatagram override
Definition at line 1135 of file chan_sip.c.
int global_timer_b [static] |
Timer B - RFC 3261 Section 17.1.1.2
Definition at line 1104 of file chan_sip.c.
unsigned int global_tos_audio [static] |
IP type of service for audio RTP packets
Definition at line 1088 of file chan_sip.c.
unsigned int global_tos_sip [static] |
IP type of service for SIP packets
Definition at line 1087 of file chan_sip.c.
unsigned int global_tos_text [static] |
IP type of service for text RTP packets
Definition at line 1090 of file chan_sip.c.
unsigned int global_tos_video [static] |
IP type of service for video RTP packets
Definition at line 1089 of file chan_sip.c.
char global_useragent[AST_MAX_EXTENSION] [static] |
Useragent for the SIP channel
Definition at line 1098 of file chan_sip.c.
const int HASH_DIALOG_SIZE = 563 [static] |
Definition at line 2005 of file chan_sip.c.
const int HASH_PEER_SIZE = 563 [static] |
Size of peer hash table, prime number preferred!
Definition at line 2004 of file chan_sip.c.
struct _map_x_s insecurestr[] [static] |
Definition at line 15135 of file chan_sip.c.
struct sockaddr_in internip [static] |
our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suitable address from one of the interfaces, and the same port number we bind to. It is used as the default address/port in SIP messages, and as the default address (but not port) in SDP messages.
Definition at line 2179 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), reload_config(), sip_alloc(), transmit_register(), and transmit_response_using_temp().
struct invstate2stringtable invitestate2string[] [static] |
Readable descriptions of device states.
Referenced by show_chanstats_cb().
struct io_context* io [static] |
The IO context
Definition at line 1156 of file chan_sip.c.
List of local networks We store "localnet" addresses from the config file into an access list, marked as 'DENY', so the call to ast_apply_ha() will return AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local' (i.e. presumably public) addresses.
List of local networks, on the same side of NAT as this Asterisk
Definition at line 2212 of file chan_sip.c.
char mandescr_show_peer[] [static] |
Initial value:
"Description: Show one SIP peer with details on current status.\n" "Variables: \n" " Peer: <name> The peer name you want to check.\n" " ActionID: <id> Optional action ID for this AMI transaction.\n"
Definition at line 15429 of file chan_sip.c.
char mandescr_show_peers[] [static] |
Definition at line 14824 of file chan_sip.c.
char mandescr_show_registry[] [static] |
char mandescr_sipnotify[] [static] |
Definition at line 11592 of file chan_sip.c.
int max_expiry = DEFAULT_MAX_EXPIRY [static] |
Maximum accepted registration time
Definition at line 518 of file chan_sip.c.
int min_expiry = DEFAULT_MIN_EXPIRY [static] |
Minimum accepted registration time
Definition at line 517 of file chan_sip.c.
pthread_t monitor_thread = AST_PTHREADT_NULL [static] |
This is the thread for the monitor which checks for input on the channels which are not currently in use.
Definition at line 1150 of file chan_sip.c.
ast_mutex_t monlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.
Definition at line 1144 of file chan_sip.c.
Referenced by do_monitor(), restart_monitor(), and unload_module().
int mwi_expiry = DEFAULT_MWI_EXPIRY [static] |
Definition at line 520 of file chan_sip.c.
Definition at line 14559 of file chan_sip.c.
ast_mutex_t netlock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
const char notify_config[] = "sip_notify.conf" [static] |
Configuration file for sending Notify with CLI commands to reconfigure or reboot phones
Definition at line 567 of file chan_sip.c.
struct ast_config* notify_types = NULL [static] |
The list of manual NOTIFY types we know how to send
Definition at line 2218 of file chan_sip.c.
int ourport_tcp [static] |
The port used for TCP connections
Definition at line 2214 of file chan_sip.c.
int ourport_tls [static] |
The port used for TCP/TLS connections
Definition at line 2215 of file chan_sip.c.
| struct ao2_container* peers |
| struct ao2_container* peers_by_ip |
Definition at line 2011 of file chan_sip.c.
int recordhistory [static] |
Record SIP history. Off by default
Definition at line 1095 of file chan_sip.c.
struct _map_x_s referstatusstrings[] [static] |
Definition at line 1470 of file chan_sip.c.
struct ast_register_list regl [static] |
The register list: Other SIP proxies we register with and place calls to.
Referenced by load_module(), manager_show_registry(), reload_config(), sip_register(), sip_send_all_registers(), sip_show_objects(), sip_show_registry(), and unload_module().
int regobjs = 0 [static] |
Registry objects
Definition at line 1131 of file chan_sip.c.
struct _map_x_s regstatestrings[] [static] |
Definition at line 11601 of file chan_sip.c.
int rpeerobjs = 0 [static] |
Realtime peers
Definition at line 1129 of file chan_sip.c.
struct sched_context* sched [static] |
The scheduling context
Definition at line 1155 of file chan_sip.c.
struct sip_settings sip_cfg [static] |
Definition at line 1071 of file chan_sip.c.
Referenced by __get_header(), __sip_subscribe_mwi_do(), add_header(), ast_sip_ouraddrfor(), build_peer(), change_hold_state(), check_auth(), check_user_full(), create_addr(), destroy_association(), do_magic_pickup(), find_call(), find_call_cb(), find_calling_channel(), get_also_info(), get_destination(), get_refer_info(), get_sip_pvt_byid_locked(), handle_incoming(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_options(), handle_request_refer(), handle_request_subscribe(), handle_response_invite(), handle_response_peerpoke(), initreqprep(), obproxy_get(), proxy_update(), realtime_peer(), realtime_update_peer(), ref_proxy(), register_verify(), reload_config(), set_destination(), set_peer_defaults(), sip_alloc(), sip_new(), sip_poke_noanswer(), sip_request_call(), sip_set_rtp_peer(), sip_show_settings(), transmit_register(), transmit_response_with_auth(), transmit_state_notify(), update_call_counter(), and update_peer().
struct ast_custom_function sip_header_function [static] |
Initial value:
{
.name = "SIP_HEADER",
.read = func_header_read,
}
Definition at line 17454 of file chan_sip.c.
struct cfsip_methods sip_methods[] [static] |
The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type.
Referenced by __sip_autodestruct(), __sip_destroy(), __sip_pretend_ack(), __sip_semi_ack(), build_reply_digest(), check_auth(), dialog_needdestroy(), do_proxy_auth(), find_call(), find_call_cb(), find_sip_method(), get_destination(), handle_incoming(), handle_request_bye(), handle_request_invite(), handle_request_register(), handle_request_subscribe(), handle_response(), init_req(), initialize_initreq(), initreqprep(), method_match(), reqprep(), retrans_pkt(), send_request(), send_response(), sip_alloc(), sip_scheddestroy(), and transmit_register().
struct cfsip_options sip_options[] [static] |
List of well-known SIP options. If we get this in a require, we should check the list and answer accordingly.
Referenced by _sip_show_peer(), parse_sip_options(), and sip_show_channel().
ast_mutex_t sip_reload_lock = ((ast_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP ) [static] |
int sip_reloading = FALSE [static] |
Flag for avoiding multiple reloads at the same time
Definition at line 1152 of file chan_sip.c.
enum channelreloadreason sip_reloadreason [static] |
Reason for last reload/load of configuration
Definition at line 1153 of file chan_sip.c.
struct ast_rtp_protocol sip_rtp [static] |
Interface structure with callbacks used to connect to RTP module.
Definition at line 2747 of file chan_sip.c.
struct ast_tcptls_session_args sip_tcp_desc [static] |
struct ast_channel_tech sip_tech [static] |
Definition of this channel for PBX channel registration.
Definition at line 2651 of file chan_sip.c.
struct ast_channel_tech sip_tech_info [static] |
This version of the sip channel tech has no send_digit_begin callback so that the core knows that the channel does not want DTMF BEGIN frames. The struct is initialized just before registering the channel driver, and is for use with channels using SIP INFO DTMF.
Definition at line 2685 of file chan_sip.c.
Referenced by load_module(), and sip_new().
struct ast_tls_config sip_tls_cfg [static] |
struct ast_tcptls_session_args sip_tls_desc [static] |
struct ast_udptl_protocol sip_udptl [static] |
Initial value:
{
type: "SIP",
get_udptl_info: sip_get_udptl_peer,
set_udptl_peer: sip_set_udptl_peer,
}
Definition at line 3260 of file chan_sip.c.
struct ast_custom_function sipchaninfo_function [static] |
Initial value:
{
.name = "SIPCHANINFO",
.read = function_sipchaninfo_read,
}
Definition at line 17634 of file chan_sip.c.
enum sip_debug_e sipdebug [static] |
Definition at line 1424 of file chan_sip.c.
int sipdebug_text [static] |
extra debugging for 'text' related events. At the moment this is set together with sip_debug_console.
Definition at line 1430 of file chan_sip.c.
struct ast_custom_function sippeer_function [static] |
Initial value:
{
.name = "SIPPEER",
.read = function_sippeer,
}
Definition at line 17568 of file chan_sip.c.
int sipsock = -1 [static] |
Main socket for UDP SIP communication.
sipsock is shared between the SIP manager thread (which handles reload requests), the udp io handler (sipsock_read()) and the user routines that issue udp writes (using __sip_xmit()). The socket is -1 only when opening fails (this is a permanent condition), or when we are handling a reload() that changes its address (this is a transient situation during which we might have a harmless race, see below). Because the conditions for the race to be possible are extremely rare, we don't want to pay the cost of locking on every I/O. Rather, we remember that when the race may occur, communication is bound to fail anyways, so we just live with this event and let the protocol handle this above us.
Definition at line 2169 of file chan_sip.c.
int* sipsock_read_id [static] |
ID of IO entry for sipsock FD
Definition at line 1157 of file chan_sip.c.
int speerobjs = 0 [static] |
Static peers
Definition at line 1128 of file chan_sip.c.
Report Peer status in character string.
Definition at line 14599 of file chan_sip.c.
struct _map_x_s strefreshers[] [static] |
Definition at line 14617 of file chan_sip.c.
struct sockaddr_in stunaddr [static] |
stun server address
Definition at line 2204 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), reload_config(), and sip_show_settings().
struct ast_subscription_mwi_list submwil [static] |
The MWI subscription list.
Referenced by load_module(), sip_send_all_mwi_subscriptions(), sip_show_mwi(), sip_subscribe_mwi(), and unload_module().
struct cfsubscription_types subscription_types[] [static] |
Subscription types that we support. We support
Referenced by find_subscription_type(), and subscription_type2str().
struct ao2_container* threadt [static] |
Definition at line 2007 of file chan_sip.c.
struct ast_threadstorage ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ts_temp_pvt , .custom_init = temp_pvt_init , } [static] |
char used_context[AST_MAX_CONTEXT] [static] |
name of automatically created context for unloading
Definition at line 1137 of file chan_sip.c.
1.5.9