Asterisk - The Open Source Telephony Project  18.5.0
Data Structures | Macros | Enumerations | Functions | Variables
chan_sip.c File Reference

Implementation of Session Initiation Protocol. More...

#include "asterisk.h"
#include <signal.h>
#include <regex.h>
#include <inttypes.h>
#include "asterisk/network.h"
#include "asterisk/paths.h"
#include "asterisk/lock.h"
#include "asterisk/config.h"
#include "asterisk/module.h"
#include "asterisk/pbx.h"
#include "asterisk/sched.h"
#include "asterisk/io.h"
#include "asterisk/rtp_engine.h"
#include "asterisk/udptl.h"
#include "asterisk/acl.h"
#include "asterisk/manager.h"
#include "asterisk/callerid.h"
#include "asterisk/cli.h"
#include "asterisk/musiconhold.h"
#include "asterisk/dsp.h"
#include "asterisk/pickup.h"
#include "asterisk/parking.h"
#include "asterisk/srv.h"
#include "asterisk/astdb.h"
#include "asterisk/causes.h"
#include "asterisk/utils.h"
#include "asterisk/file.h"
#include "asterisk/astobj2.h"
#include "asterisk/dnsmgr.h"
#include "asterisk/devicestate.h"
#include "asterisk/netsock2.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/aoc.h"
#include "asterisk/message.h"
#include "sip/include/sip.h"
#include "sip/include/globals.h"
#include "sip/include/config_parser.h"
#include "sip/include/reqresp_parser.h"
#include "sip/include/sip_utils.h"
#include "asterisk/sdp_srtp.h"
#include "asterisk/ccss.h"
#include "asterisk/xml.h"
#include "sip/include/dialog.h"
#include "sip/include/dialplan_functions.h"
#include "sip/include/security_events.h"
#include "sip/include/route.h"
#include "asterisk/sip_api.h"
#include "asterisk/mwi.h"
#include "asterisk/bridge.h"
#include "asterisk/stasis.h"
#include "asterisk/stasis_endpoints.h"
#include "asterisk/stasis_system.h"
#include "asterisk/stasis_channels.h"
#include "asterisk/features_config.h"
#include "asterisk/http_websocket.h"
#include "asterisk/format_cache.h"
#include "asterisk/linkedlists.h"

Go to the source code of this file.

Data Structures

struct  blind_transfer_cb_data
 
struct  cfalias
 Structure for conversion between compressed SIP and "normal" SIP headers. 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  cfsubscription_types
 Subscription types that we support. We support. More...
 
struct  domain_list
 
struct  epa_static_data_list
 
struct  event_state_compositor
 The Event State Compositors. More...
 
struct  invstate2stringtable
 Readable descriptions of device states. More...
 
struct  match_req_args
 
struct  mwi_subscription_data
 
struct  reregister_data
 
struct  show_peers_context
 Used in the sip_show_peers functions to pass parameters. More...
 
struct  sip_history_head
 
struct  sip_reasons
 Diversion header reasons. More...
 
struct  sip_scheddestroy_data
 
struct  state_notify_data
 

Macros

#define append_history(p, event, fmt, args...)   append_history_full(p, "%-15s " fmt, event, ## args)
 Append to SIP dialog history. More...
 
#define BOGUS_PEER_MD5SECRET   "intentionally_invalid_md5_string"
 We can recognize the bogus peer by this invalid MD5 hash. More...
 
#define check_request_transport(peer, tmpl)
 generic function for determining if a correct transport is being used to contact a peer More...
 
#define CHECK_RESULTS(in, expected_res, expected_start, expected_len)
 
#define CONTAINER_UNLINK(container, obj, tag)
 Unlink the given object from the container and return TRUE if it was in the container. More...
 
#define find_call(req, addr, intended_method)   __find_call(req, addr, intended_method, __FILE__, __LINE__, __PRETTY_FUNCTION__)
 
#define FORMAT   "%-25.25s %-15.15s %-15.15s \n"
 
#define FORMAT   "%-47.47s %-9.9s %-6.6s\n"
 
#define FORMAT   "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"
 
#define FORMAT   "%-40.40s %-20.20s %-16.16s\n"
 
#define FORMAT   "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n"
 
#define FORMAT   "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n"
 
#define FORMAT   "%-30.30s %-12.12s %-10.10s %-10.10s\n"
 
#define FORMAT   "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n"
 
#define FORMAT2   "%-25.25s %-15.15s %-15.15s \n"
 
#define FORMAT2   "%-47.47s %9.9s %6.6s\n"
 
#define FORMAT2   "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n"
 
#define FORMAT2   "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"
 
#define FORMAT2   "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\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 peer_in_destruction(peer)   (ao2_ref(peer, 0) == 0)
 
#define PEERS_FORMAT2   "%-25.25s %-39.39s %-3.3s %-10.10s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"
 
#define REMOVE_MAILBOX_WITH_LOCKED_PEER(__peer)
 
#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_TRANSPORT_STR_BUFSIZE   128
 Size of the SIP transport buffer. More...
 
#define SIPHEADER   256
 
#define UNLINK(element, head, prev)
 

Enumerations

enum  match_req_res { SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, SIP_REQ_LOOP_DETECTED, SIP_REQ_FORKED }
 
enum  message_integrity { MESSAGE_INVALID, MESSAGE_FRAGMENT, MESSAGE_FRAGMENT_COMPLETE, MESSAGE_COMPLETE }
 Indication of a TCP message's integrity. More...
 
enum  peer_unlink_flag_t { SIP_PEERS_MARKED, SIP_PEERS_ALL }
 
enum  sip_media_fds {
  SIP_AUDIO_RTP_FD, SIP_AUDIO_RTCP_FD, SIP_VIDEO_RTP_FD, SIP_VIDEO_RTCP_FD,
  SIP_TEXT_RTP_FD, SIP_UDPTL_FD
}
 

Functions

static int __cleanup_registration (const void *data)
 
static int __dialog_unlink_sched_items (const void *data)
 
static struct sip_pvt__find_call (struct sip_request *req, struct ast_sockaddr *addr, const int intended_method, const char *file, int line, const char *func)
 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_request_do More...
 
static const char * __get_header (const struct sip_request *req, const char *name, int *start)
 
static void __init_sip_content_buf (void)
 
static void __init_sip_transport_str_buf (void)
 A per-thread buffer for transport to string conversion. More...
 
static void __init_ts_temp_pvt (void)
 A per-thread temporary pvt structure. More...
 
static void __reg_module (void)
 
static int __sched_check_pendings (const void *data)
 
static int __set_address_from_contact (const char *fullcontact, struct ast_sockaddr *addr, int tcp)
 
static int __shutdown_mwi_subscription (const void *data)
 
int __sip_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acknowledges receipt of a packet and stops retransmission called with p locked. More...
 
struct sip_pvt__sip_alloc (ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, struct sip_request *req, ast_callid logger_callid, const char *file, int line, const char *func)
 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. More...
 
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(). More...
 
static int __sip_cancel_destroy (const void *data)
 
static int __sip_do_register (struct sip_registry *r)
 Register with SIP proxy. More...
 
void __sip_pretend_ack (struct sip_pvt *p)
 Pretend to ack all packets called with p locked. More...
 
static int __sip_reliable_xmit (struct sip_pvt *p, uint32_t seqno, int resp, struct ast_str *data, int fatal, int sipmethod)
 
static int __sip_scheddestroy (const void *data)
 
int __sip_semi_ack (struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
 Acks receipt of packet, keep it around (used for provisional responses) More...
 
static int __sip_subscribe_mwi_do (struct sip_subscription_mwi *mwi)
 Actually setup an MWI subscription or resubscribe. More...
 
static int __sip_xmit (struct sip_pvt *p, struct ast_str *data)
 
static int __start_mwi_subscription (const void *data)
 
static int __start_register_timeout (const void *data)
 
static int __start_reregister_timeout (const void *data)
 
static int __start_session_timer (const void *data)
 
static int __start_t38_abort_timer (const void *data)
 
static int __stop_provisional_keepalive (const void *data)
 
static int __stop_register_timeout (const void *data)
 
static int __stop_reinvite_retry (const void *data)
 
static int __stop_reinviteid (const void *data)
 
static int __stop_retrans_pkt (const void *data)
 
static int __stop_session_timer (const void *data)
 
static int __stop_t38_abort_timer (const void *data)
 
static int __transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable)
 Base transmit response function. More...
 
static void __unreg_module (void)
 
static int __update_provisional_keepalive (const void *data)
 
static int __update_provisional_keepalive_full (struct sip_pvt *pvt, int with_sdp)
 
static int __update_provisional_keepalive_with_sdp (const void *data)
 
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. More...
 
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) More...
 
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. More...
 
static struct sip_peer_sip_show_peers_one (int fd, struct mansession *s, struct show_peers_context *cont, struct sip_peer *peer)
 Emit informations for one peer during sip show peers command. More...
 
static void * _sip_tcp_helper_thread (struct ast_tcptls_session_instance *tcptls_session)
 SIP TCP thread management function This function reads from the socket, parses the packet into a request. More...
 
static void acl_change_event_stasis_unsubscribe (void)
 
static void acl_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void acl_change_stasis_subscribe (void)
 
static void add_blank (struct sip_request *req)
 add a blank line if no body More...
 
static void add_cc_call_info_to_response (struct sip_pvt *p, struct sip_request *resp)
 
static void add_codec_to_sdp (const struct sip_pvt *p, struct ast_format *format, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size, int *max_packet_size)
 Add codec offer to SDP offer/answer body in INVITE or 200 OK. More...
 
static int add_content (struct sip_request *req, const char *line)
 Add content (not header) to SIP message. More...
 
static void add_date (struct sip_request *req)
 Add date header to SIP message. More...
 
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. More...
 
static void add_diversion (struct sip_request *req, struct sip_pvt *pvt)
 Add "Diversion" header to outgoing message. More...
 
static void add_dtls_to_sdp (struct ast_rtp_instance *instance, struct ast_str **a_buf)
 Add DTLS attributes to SDP. More...
 
static void add_expires (struct sip_request *req, int expires)
 Add Expires header to SIP message. More...
 
static int add_header (struct sip_request *req, const char *var, const char *value)
 Add header to SIP message. More...
 
static void add_ice_to_sdp (struct ast_rtp_instance *instance, struct ast_str **a_buf)
 Add ICE attributes to SDP. More...
 
static int add_max_forwards (struct sip_pvt *dialog, struct sip_request *req)
 Add 'Max-Forwards' header to SIP message. More...
 
static void add_msg_header (struct sip_pvt *pvt, const char *hdr_name, const char *hdr_value)
 
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. More...
 
static void add_peer_mailboxes (struct sip_peer *peer, const char *value)
 
static void add_peer_mwi_subs (struct sip_peer *peer)
 
static void add_realm_authentication (struct sip_auth_container **credentials, const char *configuration, int lineno)
 
static void add_required_respheader (struct sip_request *req)
 
static void add_route (struct sip_request *req, struct sip_route *route, int skip)
 Add route header into request per learned route. More...
 
static int add_rpid (struct sip_request *req, struct sip_pvt *p)
 Add Remote-Party-ID header to SIP message. More...
 
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. More...
 
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. More...
 
static int add_supported (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. More...
 
static void add_tcodec_to_sdp (const struct sip_pvt *p, struct ast_format *format, 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. More...
 
static int add_text (struct sip_request *req, struct sip_pvt *p)
 Add text body to SIP message. More...
 
static struct ast_variableadd_var (const char *buf, struct ast_variable *list)
 implement the setvar config line More...
 
static void add_vcodec_to_sdp (const struct sip_pvt *p, struct ast_format *format, 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. More...
 
static int add_vidupdate (struct sip_request *req)
 add XML encoded media control with update More...
 
static int allow_notify_user_presence (struct sip_pvt *p)
 
static const char * allowoverlap2str (int mode)
 Convert AllowOverlap setting to printable string. More...
 
static AO2_GLOBAL_OBJ_STATIC (g_bogus_peer)
 A bogus peer, to be used when authentication should fail. More...
 
static void append_history_full (struct sip_pvt *p, const char *fmt,...)
 Append to SIP dialog history with arg list. More...
 
static void append_history_va (struct sip_pvt *p, const char *fmt, va_list ap)
 Append to SIP dialog history with arg list. More...
 
struct ast_moduleAST_MODULE_SELF_SYM (void)
 
static void ast_sip_ouraddrfor (const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
 NAT fix - decide which IP address to use for Asterisk server? More...
 
static int ast_sockaddr_resolve_first (struct ast_sockaddr *addr, const char *name, int flag)
 Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr. More...
 
static int ast_sockaddr_resolve_first_transport (struct ast_sockaddr *addr, const char *name, int flag, unsigned int transport)
 Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr. More...
 
 AST_TEST_DEFINE (test_sip_mwi_subscribe_parse)
 
 AST_TEST_DEFINE (test_tcp_message_fragmentation)
 
 AST_TEST_DEFINE (get_in_brackets_const_test)
 
static int auto_congest (const void *arg)
 Scheduled congestion on a call. Only called by the scheduler, must return the reference when done. More...
 
static const char * autocreatepeer2str (enum autocreatepeer_mode r)
 
static void blind_transfer_cb (struct ast_channel *chan, struct transfer_channel_data *user_data_wrapper, enum ast_transfer_type transfer_type)
 
static int block_msg_header (const char *header_name)
 
static void build_callid_pvt (struct sip_pvt *pvt)
 Build SIP Call-ID value for a non-REGISTER transaction. More...
 
static void build_callid_registry (struct sip_registry *reg, const struct ast_sockaddr *ourip, const char *fromdomain)
 Build SIP Call-ID value for a REGISTER transaction. More...
 
static void build_contact (struct sip_pvt *p, struct sip_request *req, int incoming)
 Build contact header. More...
 
static void build_localtag_registry (struct sip_registry *reg)
 Build SIP From tag value for REGISTER. More...
 
static void build_nonce (struct sip_pvt *p, int forceupdate)
 builds the sip_pvt's nonce field which is used for the authentication 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. More...
 
static int build_path (struct sip_pvt *p, struct sip_peer *peer, struct sip_request *req, const char *pathbuf)
 Build route list from Path header RFC 3327 requires that the Path header contains SIP URIs with lr paramter. Thus, we do not care about strict routing SIP routers. More...
 
static struct sip_peerbuild_peer (const char *name, struct ast_variable *v_head, struct ast_variable *alt, int realtime, int devstate_only)
 Build peer from configuration (file or realtime static/dynamic) More...
 
static int build_reply_digest (struct sip_pvt *p, int method, char *digest, int digest_len)
 Build reply digest. More...
 
static void build_route (struct sip_pvt *p, struct sip_request *req, int backwards, int resp)
 Build route list from Record-Route header. More...
 
static void build_via (struct sip_pvt *p)
 Build a Via header for a request. More...
 
static int cb_extensionstate (const char *context, const char *exten, struct ast_state_cb_info *info, void *data)
 Callback for the devicestate notification (SUBSCRIBE) support subsystem. More...
 
static void cb_extensionstate_destroy (int id, void *data)
 
static void cc_epa_destructor (void *data)
 
static int cc_esc_publish_handler (struct sip_pvt *pvt, struct sip_request *req, struct event_state_compositor *esc, struct sip_esc_entry *esc_entry)
 
static void cc_handle_publish_error (struct sip_pvt *pvt, const int resp, struct sip_request *req, struct sip_epa_entry *epa_entry)
 
static void change_callid_pvt (struct sip_pvt *pvt, const char *callid)
 
static void change_hold_state (struct sip_pvt *dialog, struct sip_request *req, int holdstate, int sendonly)
 Change hold state for a call. More...
 
static void change_redirecting_information (struct sip_pvt *p, struct sip_request *req, struct ast_party_redirecting *redirecting, struct ast_set_party_redirecting *update_redirecting, int set_call_forward)
 update redirecting information for a channel based on headers More...
 
static void change_t38_state (struct sip_pvt *p, int state)
 Change the T38 state on a SIP dialog. More...
 
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, const char *uri, enum xmittype reliable)
 Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set) More...
 
static void check_for_nat (const struct ast_sockaddr *addr, struct sip_pvt *p)
 Check and see if the requesting UA is likely to be behind a NAT. More...
 
static enum message_integrity check_message_integrity (struct ast_str **request, struct ast_str **overflow)
 Check that a message received over TCP is a full message. More...
 
static enum check_auth_result check_peer_ok (struct sip_pvt *p, char *of, struct sip_request *req, int sipmethod, struct ast_sockaddr *addr, struct sip_peer **authpeer, enum xmittype reliable, char *calleridname, char *uri2)
 Validate device authentication. More...
 
static void check_pendings (struct sip_pvt *p)
 Check pending actions on SIP call. More...
 
static int 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 More...
 
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 More...
 
static int check_user (struct sip_pvt *p, struct sip_request *req, int sipmethod, const char *uri, enum xmittype reliable, struct ast_sockaddr *addr)
 Find user If we get a match, this will add a reference pointer to the user object, that needs to be unreferenced. More...
 
static enum check_auth_result check_user_full (struct sip_pvt *p, struct sip_request *req, int sipmethod, const char *uri, enum xmittype reliable, struct ast_sockaddr *addr, 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. More...
 
static void check_via (struct sip_pvt *p, const struct sip_request *req)
 check Via: header for hostname, port and rport request/answer More...
 
static void cleanup_all_regs (void)
 
static int cleanup_registration (void *obj, void *arg, int flags)
 
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. More...
 
static void clear_peer_mailboxes (struct sip_peer *peer)
 
static void clear_sip_domains (void)
 Clear our domain list (at reload) More...
 
static char * complete_sip_notify (const char *line, const char *word, int pos, int state)
 Support routine for 'sip notify' CLI. More...
 
static char * complete_sip_peer (const char *word, int state, int flags2)
 Do completion on peer name. More...
 
static char * complete_sip_registered_peer (const char *word, int state, int flags2)
 Do completion on registered peer name. More...
 
static char * complete_sip_show_history (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show history' CLI. More...
 
static char * complete_sip_show_peer (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show peer' CLI. More...
 
static char * complete_sip_show_user (const char *line, const char *word, int pos, int state)
 Support routine for 'sip show user' CLI. More...
 
static char * complete_sip_unregister (const char *line, const char *word, int pos, int state)
 Support routine for 'sip unregister' CLI. More...
 
static char * complete_sip_user (const char *word, int state)
 Do completion on user name. More...
 
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. More...
 
static void configure_rtcp (struct sip_pvt *p, struct ast_rtp_instance *instance, int which, int remote_rtcp_mux)
 
static int construct_pidf_body (enum sip_cc_publish_state state, char *pidf_body, size_t size, const char *presentity)
 
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. More...
 
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. More...
 
static void copy_request (struct sip_request *dst, const struct sip_request *src)
 copy SIP request (mostly used to save request for responses) More...
 
static void copy_socket_data (struct sip_socket *to_sock, const struct sip_socket *from_sock)
 
static struct ast_variablecopy_vars (struct ast_variable *src)
 duplicate a list of channel variables, More...
 
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. More...
 
static int create_addr (struct sip_pvt *dialog, const char *opeer, struct ast_sockaddr *addr, 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 More...
 
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. More...
 
static struct sip_epa_entrycreate_epa_entry (const char *const event_package, const char *const destination)
 
static struct sip_esc_entrycreate_esc_entry (struct event_state_compositor *esc, struct sip_request *req, const int expires)
 
static void create_new_sip_etag (struct sip_esc_entry *esc_entry, int is_linked)
 
static char * crypto_get_attrib (struct ast_sdp_srtp *srtp, int dtls_enabled, int default_taglen_32)
 
static int default_sip_port (enum ast_transport type)
 The default sip port for the given transport. More...
 
static void deinit_req (struct sip_request *req)
 Deinitialize SIP response/request. More...
 
static void deprecation_notice (void)
 
static void destroy_association (struct sip_peer *peer)
 Remove registration data from realtime database or AST/DB when registration expires. More...
 
static void destroy_escs (void)
 
static void destroy_mailbox (struct sip_mailbox *mailbox)
 
static void destroy_msg_headers (struct sip_pvt *pvt)
 
static void destroy_realm_authentication (void *obj)
 
static int determine_firstline_parts (struct sip_request *req)
 Parse first line of incoming SIP request. More...
 
static enum sip_publish_type determine_sip_publish_type (struct sip_request *req, const char *const event, const char *const etag, const char *const expires, int *expires_int)
 
static int dialog_checkrtp_cb (void *dialogobj, void *arg, int flags)
 Check RTP Timeout on dialogs. More...
 
static void dialog_clean_rtp (struct sip_pvt *p)
 
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_find_multiple (void *obj, void *arg, int flags)
 
static int dialog_hash_cb (const void *obj, const int flags)
 
static int dialog_initialize_dtls_srtp (const struct sip_pvt *dialog, struct ast_rtp_instance *rtp, struct ast_sdp_srtp **srtp)
 Initialize DTLS-SRTP support on an RTP instance. More...
 
static int dialog_initialize_rtp (struct sip_pvt *dialog)
 Initialize RTP portion of a dialog. More...
 
static int dialog_needdestroy (void *dialogobj, void *arg, int flags)
 Match dialogs that need to be destroyed. More...
 
void dialog_unlink_all (struct sip_pvt *dialog)
 Unlink a dialog from the dialogs container, as well as any other places that it may be currently stored. More...
 
static void disable_dsp_detect (struct sip_pvt *p)
 
static void display_nat_warning (const char *cat, int reason, struct ast_flags *flags)
 
static void do_cancel_destroy (struct sip_pvt *pvt)
 
static void do_dialog_unlink_sched_items (struct sip_pvt *dialog)
 
static int do_magic_pickup (struct ast_channel *channel, const char *extension, const char *context)
 
static int do_message_auth (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void * do_monitor (void *data)
 The SIP monitoring thread. More...
 
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. More...
 
static int do_register_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code)
 Authenticate for outbound registration. More...
 
static void do_setnat (struct sip_pvt *p)
 Set nat mode on the various data sockets. More...
 
static void do_stop_session_timer (struct sip_pvt *pvt)
 
static const char * domain_mode_to_text (const enum domain_mode mode)
 Print domain mode to cli. More...
 
static const char * dtmfmode2str (int mode)
 Convert DTMF mode to printable string. More...
 
static void enable_dsp_detect (struct sip_pvt *p)
 
static int esc_cmp_fn (void *obj, void *arg, int flags)
 
static void esc_entry_destructor (void *obj)
 
static int esc_hash_fn (const void *obj, const int flags)
 
static int expire_register (const void *data)
 Expire registration of SIP peer. More...
 
static int extensionstate_update (const char *context, const char *exten, struct state_notify_data *data, struct sip_pvt *p, int force)
 Callback for the devicestate notification (SUBSCRIBE) support subsystem. More...
 
static void extract_host_from_hostport (char **hostport)
 Terminate a host:port at the ':'. More...
 
static void extract_transferrer_headers (const char *prefix, struct ast_channel *peer, const struct sip_request *req)
 
static void extract_uri (struct sip_pvt *p, struct sip_request *req)
 Check Contact: URI of SIP message. More...
 
static const char * faxec2str (int faxec)
 
static int finalize_content (struct sip_request *req)
 Add 'Content-Length' header and content to SIP message. More...
 
static const char * find_alias (const char *name, const char *_default)
 Find compressed SIP alias. More...
 
static int find_by_callid_helper (void *obj, void *arg, int flags)
 
static int find_by_name (void *obj, void *arg, void *data, int flags)
 
static int find_by_notify_uri_helper (void *obj, void *arg, int flags)
 
static int find_by_subscribe_uri_helper (void *obj, void *arg, int flags)
 
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. More...
 
static const char * find_full_alias (const char *name, const char *_default)
 Find full SIP alias. More...
 
static struct sip_authfind_realm_authentication (struct sip_auth_container *credentials, const char *realm)
 
static struct ast_channelfind_ringing_channel (struct ao2_container *device_state_info, struct sip_pvt *p)
 
static int find_sdp (struct sip_request *req)
 Determine whether a SIP message contains an SDP in its body. More...
 
static struct ast_cc_agentfind_sip_cc_agent_by_notify_uri (const char *const uri)
 
static struct ast_cc_agentfind_sip_cc_agent_by_original_callid (struct sip_pvt *pvt)
 
static struct ast_cc_agentfind_sip_cc_agent_by_subscribe_uri (const char *const uri)
 
static int find_sip_method (const char *msg)
 find_sip_method: Find SIP method from header More...
 
static int find_sip_monitor_instance_by_subscription_pvt (void *obj, void *arg, int flags)
 
static int find_sip_monitor_instance_by_suspension_entry (void *obj, void *arg, int flags)
 
static const struct epa_static_datafind_static_data (const char *const event_package)
 
static const struct cfsubscription_typesfind_subscription_type (enum subscriptiontype subtype)
 Find subscription type in array. More...
 
static void forked_invite_init (struct sip_request *req, const char *new_theirtag, struct sip_pvt *original, struct ast_sockaddr *addr)
 This function creates a dialog to handle a forked request. This dialog exists only to properly terminiate the forked request immediately. More...
 
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. More...
 
static int func_header_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len)
 Read SIP header (dialplan function) More...
 
static int func_headers_read2 (struct ast_channel *chan, const char *function, char *data, struct ast_str **buf, ssize_t maxlen)
 Read unique list of SIP headers (dialplan function) More...
 
static int function_sippeer (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len)
 ${SIPPEER()} Dialplan function - reads peer data More...
 
static char * generate_random_string (char *buf, size_t size)
 Generate 32 byte random string for callid's etc. More...
 
static char * generate_uri (struct sip_pvt *pvt, char *buf, size_t size)
 
static int get_address_family_filter (unsigned int transport)
 Helper for dns resolution to filter by address family. More...
 
static int get_also_info (struct sip_pvt *p, struct sip_request *oreq)
 Call transfer support (old way, deprecated by the IETF) More...
 
static int get_cached_mwi (struct sip_peer *peer, int *new, int *old)
 Get cached MWI info. More...
 
static char * get_content (struct sip_request *req)
 Get message body content. More...
 
static char * get_content_line (struct sip_request *req, char *name, char delimiter)
 Get a specific line from the message content. More...
 
static enum sip_get_dest_result get_destination (struct sip_pvt *p, struct sip_request *oreq, int *cc_recall_core_id)
 Find out who the call is for. More...
 
static int get_domain (const char *str, char *domain, int len)
 Extract domain from SIP To/From header. More...
 
static struct event_state_compositorget_esc (const char *const event_package)
 
static struct sip_esc_entryget_esc_entry (const char *entity_tag, struct event_state_compositor *esc)
 
static struct ast_variableget_insecure_variable_from_config (struct ast_config *config)
 
static struct ast_variableget_insecure_variable_from_sippeers (const char *column, const char *value)
 
static struct ast_variableget_insecure_variable_from_sipregs (const char *column, const char *value, struct ast_variable **var)
 
static const char * get_name_from_variable (const struct ast_variable *var)
 
static void get_our_media_address (struct sip_pvt *p, int needvideo, int needtext, struct ast_sockaddr *addr, struct ast_sockaddr *vaddr, struct ast_sockaddr *taddr, struct ast_sockaddr *dest, struct ast_sockaddr *vdest, struct ast_sockaddr *tdest)
 Set all IP media addresses for this call. More...
 
static int get_pai (struct sip_pvt *p, struct sip_request *req)
 Parse the parts of the P-Asserted-Identity header on an incoming packet. Returns 1 if a valid header is found and it is different from the current caller id. More...
 
static int get_rdnis (struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason_code, char **reason_str)
 Get referring dnis. More...
 
static void get_realm (struct sip_pvt *p, const struct sip_request *req)
 Choose realm based on From header and then To header or use globaly configured realm. Realm from From/To header should be listed among served domains in config file: domain=... More...
 
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. More...
 
static int get_rpid (struct sip_pvt *p, struct sip_request *oreq)
 Get name, number and presentation from remote party id header, returns true if a valid header was found and it was different from the current caller id. More...
 
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. More...
 
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. More...
 
static int get_sip_pvt_from_replaces (const char *callid, const char *totag, const char *fromtag, struct sip_pvt **out_pvt, struct ast_channel **out_chan)
 Find a companion dialog based on Replaces information. More...
 
static const char * get_srv_protocol (enum ast_transport t)
 Return protocol string for srv dns query. More...
 
static const char * get_srv_service (enum ast_transport t)
 Return service string for srv dns query. More...
 
static const char * get_transport_list (unsigned int transports)
 Return configuration of transports for a device. More...
 
static const char * get_transport_pvt (struct sip_pvt *p)
 Return transport of dialog. More...
 
static int get_transport_str2enum (const char *transport)
 Return int representing a bit field of transport types found in const char *transport. More...
 
static const char * gettag (const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
 Get tag from packet. More...
 
static int handle_cc_notify (struct sip_pvt *pvt, struct sip_request *req)
 
static int handle_cc_subscribe (struct sip_pvt *p, struct sip_request *req)
 
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. More...
 
static int handle_incoming (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, int *recount, int *nounlock)
 Handle incoming SIP requests (methods) More...
 
static int handle_invite_replaces (struct sip_pvt *p, struct sip_request *req, int *nounlock, struct sip_pvt *replaces_pvt, struct ast_channel *replaces_chan)
 Handle the transfer part of INVITE with a replaces: header,. More...
 
static int handle_request_bye (struct sip_pvt *p, struct sip_request *req)
 Handle incoming BYE request. More...
 
static int handle_request_cancel (struct sip_pvt *p, struct sip_request *req)
 Handle incoming CANCEL request. More...
 
static int handle_request_do (struct sip_request *req, struct ast_sockaddr *addr)
 Handle incoming SIP message - request or response. More...
 
static void handle_request_info (struct sip_pvt *p, struct sip_request *req)
 Receive SIP INFO Message. More...
 
static int handle_request_invite (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, int *recount, const char *e, int *nounlock)
 Handle incoming INVITE request. More...
 
static int handle_request_invite_st (struct sip_pvt *p, struct sip_request *req, int reinvite)
 
static int handle_request_message (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming MESSAGE request. More...
 
static int handle_request_notify (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e)
 Handle incoming notifications. More...
 
static int handle_request_options (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming OPTIONS request An OPTIONS request should be answered like an INVITE from the same UA, including SDP. More...
 
static int handle_request_publish (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const uint32_t seqno, const char *uri)
 
static int handle_request_refer (struct sip_pvt *p, struct sip_request *req, uint32_t seqno, int *nounlock)
 
static int handle_request_register (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Handle incoming REGISTER request. More...
 
static int handle_request_subscribe (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e)
 Handle incoming SUBSCRIBE request. More...
 
static int handle_request_update (struct sip_pvt *p, struct sip_request *req)
 bare-bones support for SIP UPDATE More...
 
static void handle_response (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response in dialogue. More...
 
static void handle_response_info (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_invite (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle SIP response to INVITE dialogue. More...
 
static void handle_response_message (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_notify (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_peerpoke (struct sip_pvt *p, int resp, struct sip_request *req)
 Handle qualification responses (OPTIONS) More...
 
static void handle_response_publish (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_refer (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static int handle_response_register (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle responses on REGISTER to services. More...
 
static void handle_response_subscribe (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 
static void handle_response_update (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno)
 Handle authentication challenge for SIP UPDATE. More...
 
static int handle_sip_publish_initial (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const int expires)
 
static int handle_sip_publish_modify (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag, const int expires)
 
static int handle_sip_publish_refresh (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag, const int expires)
 
static int handle_sip_publish_remove (struct sip_pvt *p, struct sip_request *req, struct event_state_compositor *esc, const char *const etag)
 
static int handle_t38_options (struct ast_flags *flags, struct ast_flags *mask, struct ast_variable *v, unsigned int *maxdatagram)
 Handle T.38 configuration options common to users and peers. More...
 
const char * hangup_cause2sip (int cause)
 Convert Asterisk hangup causes to SIP codes. More...
 
int hangup_sip2cause (int cause)
 Convert SIP hangup causes to Asterisk hangup causes. More...
 
static int has_media_level_attribute (int start, struct sip_request *req, const char *attr)
 
static int has_media_stream (struct sip_pvt *p, enum media_type m)
 Check the media stream list to see if the given type already exists. More...
 
static int init_req (struct sip_request *req, int sipmethod, const char *recip)
 Initialize SIP request. More...
 
static int init_resp (struct sip_request *resp, const char *msg)
 Initialize SIP response, based on SIP request. More...
 
static int initialize_escs (void)
 
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. More...
 
static int initialize_udptl (struct sip_pvt *p)
 
static void initreqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, const char *const explicit_uri)
 Initiate new SIP request to peer/user. More...
 
static const char * insecure2str (int mode)
 Convert Insecure setting to printable string. More...
 
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. More...
 
static int is_method_allowed (unsigned int *allowed_methods, enum sipmethod method)
 Check if method is allowed for a device or a dialog. More...
 
static int load_module (void)
 Load the module. More...
 
static int local_attended_transfer (struct sip_pvt *transferer, struct ast_channel *transferer_chan, uint32_t seqno, int *nounlock)
 Find all call legs and bridge transferee with target called from handle_request_refer. More...
 
static void lws2sws (struct ast_str *data)
 Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled. More...
 
static void make_our_tag (struct sip_pvt *pvt)
 Make our SIP dialog tag. More...
 
static int manager_show_registry (struct mansession *s, const struct message *m)
 Show SIP registrations in the manager API. More...
 
static int manager_sip_peer_status (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API. More...
 
static int manager_sip_qualify_peer (struct mansession *s, const struct message *m)
 Qualify SIP peers in the manager API. More...
 
static int manager_sip_show_peer (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API. More...
 
static int manager_sip_show_peers (struct mansession *s, const struct message *m)
 Show SIP peers in the manager API. More...
 
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. More...
 
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 More...
 
static void mark_method_allowed (unsigned int *allowed_methods, enum sipmethod method)
 
static void mark_method_unallowed (unsigned int *allowed_methods, enum sipmethod method)
 
static void mark_parsed_methods (unsigned int *methods, char *methods_str)
 
static int match_and_cleanup_peer_sched (void *peerobj, void *arg, int flags)
 
static enum match_req_res match_req_to_dialog (struct sip_pvt *sip_pvt_ptr, struct match_req_args *arg)
 
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 More...
 
static int mock_tcp_loop (char *fragments[], size_t num_fragments, struct ast_str **overflow, char **messages, int *num_messages, struct ast_test *test)
 Imitation TCP reception loop. More...
 
static void mwi_event_cb (void *userdata, struct stasis_subscription *sub, struct stasis_message *msg)
 Receive MWI events that we have subscribed to. More...
 
static int network_change_sched_cb (const void *data)
 
static void network_change_stasis_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 
static void network_change_stasis_subscribe (void)
 
static void network_change_stasis_unsubscribe (void)
 
static struct sip_proxyobproxy_get (struct sip_pvt *dialog, struct sip_peer *peer)
 Get default outbound proxy or global proxy. More...
 
static void offered_media_list_destroy (struct sip_pvt *p)
 Destroy SDP media offer list. More...
 
static void on_dns_update_mwi (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static void on_dns_update_peer (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static void on_dns_update_registry (struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
 
static unsigned int parse_allowed_methods (struct sip_request *req)
 parse the Allow header to see what methods the endpoint we are communicating with allows. More...
 
static void parse_copy (struct sip_request *dst, const struct sip_request *src)
 Copy SIP request, parse it. More...
 
static int parse_minse (const char *p_hdrval, int *const p_interval)
 Session-Timers: Function for parsing Min-SE header. More...
 
static void parse_moved_contact (struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward)
 Parse 302 Moved temporalily response. More...
 
static int parse_ok_contact (struct sip_pvt *pvt, struct sip_request *req)
 Save contact header for 200 OK on INVITE. More...
 
static void parse_oli (struct sip_request *req, struct ast_channel *chan)
 Check for the presence of OLI tag(s) in the From header and set on the channel. More...
 
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) More...
 
static int parse_request (struct sip_request *req)
 Parse a SIP message. More...
 
static int parse_session_expires (const char *p_hdrval, int *const p_interval, enum st_refresher_param *const p_ref)
 Session-Timers: Function for parsing Session-Expires header. More...
 
static int parse_uri_legacy_check (char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport)
 parse uri in a way that allows semicolon stripping if legacy mode is enabled More...
 
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_full (void *obj, void *arg, void *data, int flags)
 
static int peer_iphash_cb (const void *obj, const int flags)
 
static void peer_mailboxes_to_str (struct ast_str **mailbox_str, struct sip_peer *peer)
 list peer mailboxes to CLI More...
 
static int peer_markall_autopeers_func (void *device, void *arg, int flags)
 
static int peer_markall_func (void *device, void *arg, int flags)
 
static void peer_sched_cleanup (struct sip_peer *peer)
 
static int peer_status (struct sip_peer *peer, char *status, int statuslen)
 
int peercomparefunc (const void *a, const void *b)
 
static int pidf_validate_presence (struct ast_xml_doc *doc)
 
static int pidf_validate_tuple (struct ast_xml_node *tuple_node)
 
unsigned 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. More...
 
static void print_group (int fd, ast_group_t group, int crlf)
 Print call group and pickup group. More...
 
static void print_named_groups (int fd, struct ast_namedgroups *group, int crlf)
 Print named call groups and pickup groups. More...
 
static void proc_422_rsp (struct sip_pvt *p, struct sip_request *rsp)
 Handle 422 response to INVITE with session-timer requested. More...
 
static int proc_session_timer (const void *vp)
 Session-Timers: Process session refresh timeout event. More...
 
static int process_crypto (struct sip_pvt *p, struct ast_rtp_instance *rtp, struct ast_sdp_srtp **srtp, const char *a)
 
static int process_sdp (struct sip_pvt *p, struct sip_request *req, int t38action, int is_offer)
 Process SIP SDP offer, select formats and activate media 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(). More...
 
static int process_sdp_a_audio (const char *a, struct sip_pvt *p, struct ast_rtp_codecs *newaudiortp, int *last_rtpmap_codec)
 
static int process_sdp_a_dtls (const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance)
 
static int process_sdp_a_ice (const char *a, struct sip_pvt *p, struct ast_rtp_instance *instance, int rtcp_mux)
 
static int process_sdp_a_image (const char *a, struct sip_pvt *p)
 
static int process_sdp_a_rtcp_mux (const char *a, struct sip_pvt *p, int *requested)
 
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_codecs *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_codecs *newvideortp, int *last_rtpmap_codec)
 
static int process_sdp_c (const char *c, struct ast_sockaddr *addr)
 
static int process_sdp_o (const char *o, struct sip_pvt *p)
 
static int process_via (struct sip_pvt *p, const struct sip_request *req)
 Process the Via header according to RFC 3261 section 18.2.2. More...
 
static struct sip_proxyproxy_from_config (const char *proxy, int sipconf_lineno, struct sip_proxy *dest)
 Parse proxy string and return an ao2_alloc'd proxy. If dest is non-NULL, no allocation is performed and dest is used instead. On error NULL is returned. More...
 
static int proxy_update (struct sip_proxy *proxy)
 
static int publish_expire (const void *data)
 
static void publish_qualify_peer_done (const char *id, const char *peer)
 
static void pvt_set_needdestroy (struct sip_pvt *pvt, const char *reason)
 
static int read_raw_content_length (const char *message)
 Get the content length from an unparsed SIP message. More...
 
static struct sip_peerrealtime_peer (const char *newpeername, struct ast_sockaddr *addr, char *callbackexten, int devstate_only, int which_objects)
 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. More...
 
static int realtime_peer_by_addr (const char **name, struct ast_sockaddr *addr, const char *ipaddr, const char *callbackexten, struct ast_variable **var, struct ast_variable **varregs)
 
static int realtime_peer_by_name (const char *const *name, struct ast_sockaddr *addr, const char *ipaddr, struct ast_variable **var, struct ast_variable **varregs)
 
static struct ast_variablerealtime_peer_get_sippeer_helper (const char **name, struct ast_variable **varregs)
 
static void realtime_update_peer (const char *peername, struct ast_sockaddr *addr, const char *defaultuser, const char *fullcontact, const char *useragent, int expirey, unsigned short deprecated_username, int lastms, const char *path)
 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. More...
 
static void receive_message (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, const char *e)
 Receive SIP MESSAGE method messages. More...
 
static void ref_proxy (struct sip_pvt *pvt, struct sip_proxy *proxy)
 maintain proper refcounts for a sip_pvt's outboundproxy More...
 
static const char * referstatus2str (enum referstatus rstatus)
 Convert transfer status to string. More...
 
static void reg_source_db (struct sip_peer *peer)
 Get registration details from Asterisk DB. More...
 
static void register_peer_exten (struct sip_peer *peer, int onoff)
 Automatically add peer extension to dial plan. More...
 
static int register_realtime_peers_with_callbackextens (void)
 
static enum check_auth_result register_verify (struct sip_pvt *p, struct ast_sockaddr *addr, struct sip_request *req, const char *uri)
 Verify registration of user. More...
 
static int registry_cmp_cb (void *obj, void *arg, int flags)
 
static int registry_hash_cb (const void *obj, const int flags)
 
static const char * regstate2str (enum sipregistrystate regstate)
 Convert registration state status to string. More...
 
static int reinvite_timeout (const void *data)
 
static int reload (void)
 Part of Asterisk module interface. More...
 
static int reload_config (enum channelreloadreason reason)
 Re-read SIP.conf config file. More...
 
static char * remove_uri_parameters (char *uri)
 
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 More...
 
static int reqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, uint32_t seqno, int newbranch)
 Initialize a SIP request message (not the initial one in a dialog) More...
 
static int resp_needs_contact (const char *msg, enum sipmethod method)
 Test if this response needs a contact header. More...
 
static int respprep (struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Prepare SIP response packet. More...
 
static int restart_monitor (void)
 Start the channel monitor thread. More...
 
static void restart_session_timer (struct sip_pvt *p)
 Session-Timers: Restart session timer. More...
 
static int retrans_pkt (const void *data)
 Retransmit SIP message if no answer. More...
 
static void sched_check_pendings (struct sip_pvt *pvt)
 
static void send_check_user_failure_response (struct sip_pvt *p, struct sip_request *req, int res, enum xmittype reliable)
 
static void send_manager_peer_status (struct mansession *s, struct sip_peer *peer, const char *idText)
 
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, uint32_t seqno)
 
static int send_response (struct sip_pvt *p, struct sip_request *req, enum xmittype reliable, uint32_t seqno)
 Transmit response on SIP request. More...
 
static void send_session_timeout (struct ast_channel *chan, const char *source)
 Sends a session timeout channel blob used to produce SessionTimeout AMI messages. More...
 
static enum ast_cc_service_type service_string_to_service_type (const char *const service_string)
 
static struct ast_manager_event_blobsession_timeout_to_ami (struct stasis_message *msg)
 
static int set_address_from_contact (struct sip_pvt *pvt)
 Change the other partys IP address based on given contact. More...
 
static void set_destination (struct sip_pvt *p, const char *uri)
 Set destination from SIP URI. More...
 
static void set_ice_components (struct sip_pvt *p, struct ast_rtp_instance *instance, int remote_rtcp_mux)
 
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. More...
 
static int set_message_vars_from_req (struct ast_msg *msg, struct sip_request *req)
 
static void set_peer_defaults (struct sip_peer *peer)
 Set peer defaults before configuring specific configurations. More...
 
static void set_peer_nat (const struct sip_pvt *p, struct sip_peer *peer)
 Set the peers nat flags if they are using auto_* settings. More...
 
static unsigned int set_pvt_allowed_methods (struct sip_pvt *pvt, struct sip_request *req)
 
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. More...
 
static int show_channels_cb (struct sip_pvt *cur, struct __show_chan_arg *arg)
 callback for show channel|subscription More...
 
static int show_chanstats_cb (struct sip_pvt *cur, struct __show_chan_arg *arg)
 Callback for show_chanstats. More...
 
static void shutdown_mwi_subscription (struct sip_subscription_mwi *mwi)
 
static int sip_addheader (struct ast_channel *chan, const char *data)
 Add a SIP header to an outbound INVITE. More...
 
static int sip_allow_anyrtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance, const char *rtptype)
 
static int sip_allow_rtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance)
 
static int sip_allow_vrtp_remote (struct ast_channel *chan1, struct ast_rtp_instance *instance)
 
static void sip_alreadygone (struct sip_pvt *dialog)
 Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging. More...
 
static int sip_answer (struct ast_channel *ast)
 sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface More...
 
void sip_auth_headers (enum sip_auth_type code, char **header, char **respheader)
 return the request and response header for a 401 or 407 code More...
 
static int sip_call (struct ast_channel *ast, const char *dest, int timeout)
 Initiate SIP call from PBX used from the dial() application. More...
 
void sip_cancel_destroy (struct sip_pvt *pvt)
 Cancel destruction of SIP dialog. More...
 
static void sip_cc_agent_destructor (struct ast_cc_agent *agent)
 
static int sip_cc_agent_init (struct ast_cc_agent *agent, struct ast_channel *chan)
 
static int sip_cc_agent_recall (struct ast_cc_agent *agent)
 
static void sip_cc_agent_respond (struct ast_cc_agent *agent, enum ast_cc_agent_response_reason reason)
 
static int sip_cc_agent_start_monitoring (struct ast_cc_agent *agent)
 
static int sip_cc_agent_start_offer_timer (struct ast_cc_agent *agent)
 
static int sip_cc_agent_status_request (struct ast_cc_agent *agent)
 
static int sip_cc_agent_stop_offer_timer (struct ast_cc_agent *agent)
 
static int sip_cc_monitor_cancel_available_timer (struct ast_cc_monitor *monitor, int *sched_id)
 
static void sip_cc_monitor_destructor (void *private_data)
 
static int sip_cc_monitor_request_cc (struct ast_cc_monitor *monitor, int *available_timer_id)
 
static int sip_cc_monitor_suspend (struct ast_cc_monitor *monitor)
 
static int sip_cc_monitor_unsuspend (struct ast_cc_monitor *monitor)
 
static int sip_check_authtimeout (time_t start)
 Check if the authtimeout has expired. More...
 
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. More...
 
static int sip_debug_test_addr (const struct ast_sockaddr *addr)
 See if we pass debug IP filter. More...
 
static int sip_debug_test_pvt (struct sip_pvt *p)
 Test PVT for debugging output. More...
 
static void sip_destroy_peer (struct sip_peer *peer)
 Destroy peer object from memory. More...
 
static void sip_destroy_peer_fn (void *peer)
 
static int sip_devicestate (const char *data)
 Part of PBX channel interface. More...
 
void sip_digest_parser (char *c, struct digestkeys *keys)
 Takes the digest response and parses it. More...
 
static char * sip_do_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Turn on SIP debugging (CLI command) More...
 
static char * sip_do_debug_ip (int fd, const char *arg)
 Enable SIP Debugging for a single IP. More...
 
static char * sip_do_debug_peer (int fd, const char *arg)
 Turn on SIP debugging for a given peer. More...
 
static int sip_do_reload (enum channelreloadreason reason)
 Reload module. More...
 
static int sip_dtmfmode (struct ast_channel *chan, const char *data)
 Set the DTMFmode for an outbound SIP call (application) More...
 
static void sip_dump_history (struct sip_pvt *dialog)
 Dump SIP history to debug log file at end of lifespan for SIP dialog. More...
 
static int sip_epa_register (const struct epa_static_data *static_data)
 
static void sip_epa_unregister_all (void)
 
struct sip_peersip_find_peer (const char *peer, struct ast_sockaddr *addr, int realtime, int which_objects, int devstate_only, int transport)
 Locate device by name or ip address. More...
 
static struct sip_peersip_find_peer_by_ip_and_exten (struct ast_sockaddr *addr, char *callbackexten, int transport)
 
static struct sip_peersip_find_peer_full (const char *peer, struct ast_sockaddr *addr, char *callbackexten, int realtime, int which_objects, int devstate_only, int transport)
 
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 More...
 
static const char * sip_get_callid (struct ast_channel *chan)
 Deliver SIP call ID for the call. More...
 
static int sip_get_cc_information (struct sip_request *req, char *subscribe_uri, size_t size, enum ast_cc_service_type *service)
 
static void sip_get_codec (struct ast_channel *chan, struct ast_format_cap *result)
 
const char * sip_get_header (const struct sip_request *req, const char *name)
 Get header from SIP request. More...
 
static enum ast_rtp_glue_result sip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
const char * sip_get_transport (enum ast_transport t)
 Return transport as string. More...
 
static enum ast_rtp_glue_result sip_get_trtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
static enum ast_rtp_glue_result sip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance)
 
static void sip_handle_cc (struct sip_pvt *pvt, struct sip_request *req, enum ast_cc_service_type service)
 
static int sip_hangup (struct ast_channel *ast)
 sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup More...
 
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. More...
 
static int sip_is_token (const char *str)
 
static int sip_is_xml_parsable (void)
 
static void sip_keepalive_all_peers (void)
 Send a keepalive to all known peers. More...
 
static int sip_monitor_instance_cmp_fn (void *obj, void *arg, int flags)
 
static void sip_monitor_instance_destructor (void *data)
 
static int sip_monitor_instance_hash_fn (const void *obj, const int flags)
 
static struct sip_monitor_instancesip_monitor_instance_init (int core_id, const char *const subscribe_uri, const char *const peername, const char *const device_name)
 
static int sip_msg_send (const struct ast_msg *msg, const char *to, const char *from)
 
static const char * sip_nat_mode (const struct sip_pvt *p)
 Display SIP nat mode. More...
 
static struct ast_channelsip_new (struct sip_pvt *i, int state, const char *title, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, ast_callid callid)
 Initiate a call in the SIP channel. More...
 
static int sip_notify_alloc (struct sip_pvt *p)
 Allocate SIP refer structure. More...
 
static int sip_offer_timer_expire (const void *data)
 
static void sip_peer_hold (struct sip_pvt *p, int hold)
 Change onhold state of a peer using a pvt structure. More...
 
static int sip_pickup (struct ast_channel *chan)
 Pickup a call using the subsystem in features.c This is executed in a separate thread. More...
 
static void * sip_pickup_thread (void *stuff)
 SIP pickup support function Starts in a new thread, then pickup the call. More...
 
static int sip_pidf_validate (struct sip_request *req, struct ast_xml_doc **pidf_doc)
 Makes sure that body is properly formatted PIDF. More...
 
static void sip_pkt_dtor (void *vdoomed)
 
static void sip_poke_all_peers (void)
 Send a poke to all known peers. More...
 
static int sip_poke_noanswer (const void *data)
 React to lack of answer to Qualify poke. More...
 
static int sip_poke_peer (struct sip_peer *peer, int force)
 Check availability of peer, also keep NAT open. More...
 
static int sip_poke_peer_now (const void *data)
 
static int sip_poke_peer_s (const void *data)
 Poke peer (send qualify to check if peer is alive and well) More...
 
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) More...
 
static void sip_publish_registry (const char *username, const char *domain, const char *status)
 
static void sip_pvt_callid_set (struct sip_pvt *pvt, ast_callid callid)
 
static void sip_pvt_dtor (void *vdoomed)
 ao2 destructor for SIP dialog structure More...
 
static struct ast_channelsip_pvt_lock_full (struct sip_pvt *pvt)
 
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. More...
 
static int sip_queryoption (struct ast_channel *chan, int option, void *data, int *datalen)
 Query an option on a SIP dialog. More...
 
static void sip_queue_hangup_cause (struct sip_pvt *p, int cause)
 
static struct ast_framesip_read (struct ast_channel *ast)
 Read SIP RTP from channel. More...
 
static const struct ast_sockaddrsip_real_dst (const struct sip_pvt *p)
 The real destination address for a write. More...
 
static const char * sip_reason_code_to_str (struct ast_party_redirecting_reason *reason)
 
static int sip_refer_alloc (struct sip_pvt *p)
 Allocate SIP refer structure. More...
 
static void sip_refer_destroy (struct sip_pvt *p)
 Destroy SIP refer structure. More...
 
static int sip_reg_timeout (const void *data)
 Registration request timeout, register again. More...
 
static int sip_register (const char *value, int lineno)
 create sip_registry object from register=> line in sip.conf and link into reg container More...
 
static void sip_register_tests (void)
 SIP test registration. More...
 
static void sip_registry_destroy (void *obj)
 Destroy registry object Objects created with the register= statement in static configuration. More...
 
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. More...
 
static char * sip_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Force reload of module from cli. More...
 
static int sip_removeheader (struct ast_channel *chan, const char *data)
 Remove SIP headers added previously with SipAddHeader application. More...
 
static struct ast_channelsip_request_call (const char *type, struct ast_format_cap *cap, const struct ast_assigned_ids *assignedids, const struct ast_channel *requestor, const char *dest, int *cause)
 PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here. More...
 
static int sip_reregister (const void *data)
 Update registration with SIP Proxy. More...
 
static struct ast_framesip_rtp_read (struct ast_channel *ast, struct sip_pvt *p, int *faxdetect)
 Read RTP from network. More...
 
static const char * sip_sanitized_host (const char *host)
 
void sip_scheddestroy (struct sip_pvt *p, int ms)
 Schedule destruction of SIP dialog. More...
 
void sip_scheddestroy_final (struct sip_pvt *p, int ms)
 Schedule final destruction of SIP dialog. More...
 
static int sip_scheddestroy_full (struct sip_pvt *p, int ms)
 
static void sip_send_all_mwi_subscriptions (void)
 Send all MWI subscriptions. More...
 
static void sip_send_all_registers (void)
 Send all known registrations. More...
 
static int sip_send_keepalive (const void *data)
 Send keep alive packet to peer. More...
 
static int sip_send_mwi_to_peer (struct sip_peer *peer, int cache_only)
 Send message waiting indication to alert peer that they've got voicemail. More...
 
static int sip_sendcustominfo (struct ast_channel *chan, const char *data)
 Send a custom INFO message via AST_CONTROL_CUSTOM indication. More...
 
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. More...
 
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! More...
 
static int sip_sendtext (struct ast_channel *ast, const char *text)
 
static void sip_set_default_format_capabilities (struct ast_format_cap *cap)
 
static char * sip_set_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Enable/Disable SIP History logging (CLI) More...
 
static void sip_set_owner (struct sip_pvt *p, struct ast_channel *chan)
 Set the owning channel on the sip_pvt object. More...
 
static void sip_set_redirstr (struct sip_pvt *p, char *reason)
 Translate referring cause. More...
 
static int sip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, const struct ast_format_cap *cap, int nat_active)
 
static int sip_setoption (struct ast_channel *chan, int option, void *data, int datalen)
 Set an option on a SIP dialog. More...
 
static char * sip_show_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show details of one active dialog. More...
 
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. More...
 
static char * sip_show_channelstats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 SIP show channelstats CLI (main function) More...
 
static char * sip_show_domains (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI command to list local domains. More...
 
static char * sip_show_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show history details of one dialog. More...
 
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. More...
 
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) More...
 
static char * sip_show_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show one peer in detail. More...
 
static char * sip_show_peers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI Show Peers command. More...
 
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. More...
 
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. More...
 
static char * sip_show_tcp (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show active TCP connections. More...
 
static char * sip_show_user (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 Show one user in detail. More...
 
static char * sip_show_users (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)
 CLI Command 'SIP Show Users'. More...
 
static int sip_sipredirect (struct sip_pvt *p, const char *dest)
 Transfer call before connect with a 302 redirect. More...
 
static struct sip_st_dlgsip_st_alloc (struct sip_pvt *const p)
 Allocate Session-Timers struct w/in dialog. More...
 
static int sip_standard_port (enum ast_transport type, int port)
 Returns the port to use for this socket. More...
 
static int sip_subscribe_mwi (const char *value, int lineno)
 Parse mwi=> line in sip.conf and add to list. More...
 
static void sip_subscribe_mwi_destroy (void *data)
 Destroy MWI subscription object. More...
 
static int sip_subscribe_mwi_do (const void *data)
 Send a subscription or resubscription for MWI. More...
 
static int sip_t38_abort (const void *data)
 Called to deny a T38 reinvite if the core does not respond to our request. More...
 
static struct ast_tcptls_session_instancesip_tcp_locate (struct ast_sockaddr *s)
 Find thread for TCP/TLS session (based on IP/Port. More...
 
static void * sip_tcp_worker_fn (void *data)
 SIP TCP connection handler. More...
 
static void sip_tcptls_client_args_destructor (void *obj)
 
static int sip_tcptls_read (struct sip_request *req, struct ast_tcptls_session_instance *tcptls_session, int authenticated, time_t start)
 Read SIP request or response from a TCP/TLS connection. More...
 
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 More...
 
static struct sip_threadinfosip_threadinfo_create (struct ast_tcptls_session_instance *tcptls_session, int transport)
 creates a sip_threadinfo object and links it into the threadt table. More...
 
static void sip_threadinfo_destructor (void *obj)
 
static int sip_transfer (struct ast_channel *ast, const char *dest)
 Transfer SIP call. More...
 
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. More...
 
static void sip_unregister_tests (void)
 SIP test registration. More...
 
static void sip_websocket_callback (struct ast_websocket *session, struct ast_variable *parameters, struct ast_variable *headers)
 SIP WebSocket connection handler. More...
 
static int sip_write (struct ast_channel *ast, struct ast_frame *frame)
 Send frame to media channel (rtp) More...
 
static int sipinfo_send (struct ast_channel *chan, struct ast_variable *headers, const char *content_type, const char *content, const char *useragent_filter)
 
static int sipsock_read (int *id, int fd, short events, void *ignore)
 Read data from SIP UDP socket. More...
 
static int sockaddr_is_null_or_any (const struct ast_sockaddr *addr)
 
static enum st_mode st_get_mode (struct sip_pvt *p, int no_cached)
 Get the session-timer mode. More...
 
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. More...
 
static int st_get_se (struct sip_pvt *p, int max)
 Get Max or Min SE (session timer expiry) More...
 
static void start_ice (struct ast_rtp_instance *instance, int offer)
 Start ICE negotiation on an RTP instance. More...
 
static void start_mwi_subscription (struct sip_subscription_mwi *mwi, int ms)
 
static void start_register_timeout (struct sip_registry *reg)
 
static void start_reregister_timeout (struct sip_registry *reg, int ms)
 
static void start_session_timer (struct sip_pvt *pvt)
 Session-Timers: Start session timer. More...
 
static void start_t38_abort_timer (struct sip_pvt *pvt)
 
static void startup_event_cb (void *data, struct stasis_subscription *sub, struct stasis_message *message)
 Event callback which indicates we're fully booted. More...
 
 STASIS_MESSAGE_TYPE_DEFN_LOCAL (session_timeout_type,.to_ami=session_timeout_to_ami,)
 
static void state_notify_build_xml (struct state_notify_data *data, int full, const char *exten, const char *context, struct ast_str **tmp, struct sip_pvt *p, int subscribed, const char *mfrom, const char *mto)
 Builds XML portion of NOTIFY messages for presence or dialog updates. More...
 
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. More...
 
static void stop_provisional_keepalive (struct sip_pvt *pvt)
 
static void stop_register_timeout (struct sip_registry *reg)
 
static void stop_reinvite_retry (struct sip_pvt *pvt)
 
static void stop_reinviteid (struct sip_pvt *pvt)
 
static void stop_retrans_pkt (struct sip_pkt *pkt)
 
static void stop_session_timer (struct sip_pvt *pvt)
 Session-Timers: Stop session timer. More...
 
static void stop_t38_abort_timer (struct sip_pvt *pvt)
 
static int str2dtmfmode (const char *str)
 maps a string to dtmfmode, returns -1 on error More...
 
static enum st_mode str2stmode (const char *s)
 
static enum st_refresher_param str2strefresherparam (const char *s)
 
static const char * strefresher2str (enum st_refresher r)
 
static const char * strefresherparam2str (enum st_refresher_param r)
 
static const char * subscription_type2str (enum subscriptiontype subtype)
 Show subscription type in string format. More...
 
static unsigned int t38_get_rate (enum ast_control_t38_rate rate)
 Get Max T.38 Transmission rate from T38 capabilities. More...
 
static void tcptls_packet_destructor (void *obj)
 
static struct sip_peertemp_peer (const char *name)
 Create temporary peer (used in autocreatepeer mode) More...
 
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. More...
 
static int transmit_cc_notify (struct ast_cc_agent *agent, struct sip_pvt *subscription, enum sip_cc_notify_state state)
 
static void transmit_fake_auth_response (struct sip_pvt *p, 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. More...
 
static int transmit_info_with_aoc (struct sip_pvt *p, struct ast_aoc_decoded *decoded)
 Send SIP INFO advice of charge message. More...
 
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. More...
 
static int transmit_info_with_vidupdate (struct sip_pvt *p)
 Send SIP INFO with video update request. More...
 
static int transmit_invite (struct sip_pvt *p, int sipmethod, int sdp, int init, const char *const explicit_uri)
 Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it. More...
 
static int transmit_message (struct sip_pvt *p, int init, int auth)
 Transmit with SIP MESSAGE method. More...
 
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) More...
 
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) More...
 
static int transmit_provisional_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp)
 
static int transmit_publish (struct sip_epa_entry *epa_entry, enum sip_publish_type publish_type, const char *const explicit_uri)
 
static int transmit_refer (struct sip_pvt *p, const char *dest)
 Transmit SIP REFER message (initiated by the transfer() dialplan application. More...
 
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()) More...
 
static int transmit_reinvite_with_sdp (struct sip_pvt *p, int t38version, int oldsdp)
 Transmit reinvite with SDP. More...
 
static int transmit_request (struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
 Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry) More...
 
static int transmit_request_with_auth (struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
 Transmit SIP request, auth added. More...
 
static int transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Transmit response, no retransmits. More...
 
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. More...
 
static int transmit_response_using_temp (ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
 Transmit response, no retransmits, using a temporary pvt structure. More...
 
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. More...
 
static int transmit_response_with_auth (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *nonce, enum xmittype reliable, const char *header, int stale)
 Respond with authorization request. More...
 
static int transmit_response_with_date (struct sip_pvt *p, const char *msg, const struct sip_request *req)
 Add date before transmitting response. More...
 
static int transmit_response_with_minexpires (struct sip_pvt *p, const char *msg, const struct sip_request *req, int minexpires)
 Append Min-Expires header, content length before transmitting response. More...
 
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) More...
 
static int transmit_response_with_retry_after (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *seconds)
 Append Retry-After header field when transmitting response. More...
 
static int transmit_response_with_sdp (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable, int oldsdp, int rpid)
 Used for 200 OK and 183 early media. More...
 
static int transmit_response_with_sip_etag (struct sip_pvt *p, const char *msg, const struct sip_request *req, struct sip_esc_entry *esc_entry, int need_new_etag)
 
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. More...
 
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. More...
 
static int transmit_state_notify (struct sip_pvt *p, struct state_notify_data *data, int full, int timeout)
 Used in the SUBSCRIBE notification subsystem (RFC3265) More...
 
static const char * trust_id_outbound2str (int mode)
 
static void try_suggested_sip_codec (struct sip_pvt *p)
 Try setting the codecs suggested by the SIP_CODEC channel variable. More...
 
static int uac_sips_contact (struct sip_request *req)
 Determine if, as a UAC, we need to use a SIPS Contact. More...
 
static int uas_sips_contact (struct sip_request *req)
 Determine if, as a UAS, we need to use a SIPS Contact. More...
 
static void unlink_all_peers_from_tables (void)
 
static void unlink_marked_peers_from_tables (void)
 
static void unlink_peers_from_tables (peer_unlink_flag_t flag)
 
static int unload_module (void)
 PBX unload module API. More...
 
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. More...
 
static void update_connectedline (struct sip_pvt *p, const void *data, size_t datalen)
 Notify peer that the connected line has changed. More...
 
static void update_peer (struct sip_peer *p, int expire)
 Update peer data in database (if used) More...
 
static void update_peer_lastmsgssent (struct sip_peer *peer, int value, int locked)
 
static void update_provisional_keepalive (struct sip_pvt *pvt, int with_sdp)
 
static void update_redirecting (struct sip_pvt *p, const void *data, size_t datalen)
 Send a provisional response indicating that a call was redirected. More...
 
static int use_reason_header (struct sip_pvt *pvt, struct sip_request *req)
 Parses SIP reason header according to RFC3326 and sets channel's hangupcause if configured so and header present. More...
 

Variables

static struct ast_module_info __mod_info = { .name = AST_MODULE, .flags = AST_MODFLAG_LOAD_ORDER , .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 = "30ef0c93b36035ec78c9cfd712d36d9b" , .support_level = AST_MODULE_SUPPORT_DEPRECATED, .load = load_module, .unload = unload_module, .reload = reload, .load_pri = AST_MODPRI_CHANNEL_DRIVER, .requires = "ccss,dnsmgr,udptl", .optional_modules = "res_crypto,res_http_websocket", }
 
static struct stasis_subscriptionacl_change_sub
 
static const struct cfalias aliases []
 
static const struct _map_x_s allowoverlapstr []
 
static char * app_dtmfmode = "SIPDtmfMode"
 
static char * app_sipaddheader = "SIPAddHeader"
 
static char * app_sipremoveheader = "SIPRemoveHeader"
 
static char * app_sipsendcustominfo = "SIPSendCustomINFO"
 
static const struct ast_module_infoast_module_info = &__mod_info
 
static struct sip_auth_containerauthl = NULL
 Authentication container for realm authentication. More...
 
static ast_mutex_t authl_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 Global authentication container protection while adjusting the references. More...
 
static int authlimit = DEFAULT_AUTHLIMIT
 
static int authtimeout = DEFAULT_AUTHTIMEOUT
 
static struct _map_x_s autopeermodes []
 
struct ast_sockaddr bindaddr
 
static int can_parse_xml
 
static const struct epa_static_data cc_epa_static_data
 
static const struct sip_esc_publish_callbacks cc_esc_publish_callbacks
 
static const struct ast_sip_api_tech chan_sip_api_provider
 
static struct ast_custom_function checksipdomain_function
 
static struct ast_cli_entry cli_sip []
 SIP Cli commands definition. More...
 
static const char config [] = "sip.conf"
 
static struct ast_sockaddr debugaddr
 
static struct ast_rtp_dtls_cfg default_dtls_cfg
 Default DTLS connection configuration. More...
 
static int default_expiry = DEFAULT_DEFAULT_EXPIRY
 
static struct ast_jb_conf default_jbconf
 Global jitterbuffer configuration - by default, jb is disabled. More...
 
static const int DEFAULT_PUBLISH_EXPIRES = 3600
 
static struct ast_tls_config default_tls_cfg
 Default TLS connection configuration. More...
 
static struct ao2_containerdialogs
 
struct ao2_containerdialogs_needdestroy
 
struct ao2_containerdialogs_rtpcheck
 
static struct domain_list domain_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static const struct _map_x_s dtmfstr []
 mapping between dtmf flags and strings More...
 
struct epa_static_data_list epa_static_data_list = { .first = NULL, .last = NULL, .lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} } , }
 
static int esc_etag_counter
 
static const int ESC_MAX_BUCKETS = 37
 
static struct event_state_compositor event_state_compositors []
 
static struct ast_sockaddr externaddr
 our external IP address/port for SIP sessions. externaddr.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: More...
 
static time_t externexpire
 
static char externhost [MAXHOSTNAMELEN]
 
static int externrefresh = 10
 
static uint16_t externtcpport
 
static uint16_t externtlsport
 
static struct _map_x_s faxecmodes []
 
static struct ast_flags global_flags [3] = {{0}}
 
static struct ast_jb_conf global_jbconf
 
static unsigned int global_t38_maxdatagram
 
static const int HASH_DIALOG_SIZE = 563
 
static const int HASH_PEER_SIZE = 563
 
static const int HASH_REGISTRY_SIZE = 563
 
static const struct _map_x_s insecurestr []
 
static struct ast_sockaddr 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. More...
 
static const struct invstate2stringtable invitestate2string []
 
static struct io_contextio
 
static struct ast_halocaladdr
 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. More...
 
static int log_level = -1
 
static int max_expiry = DEFAULT_MAX_EXPIRY
 
static int max_subexpiry = DEFAULT_MAX_EXPIRY
 
static struct ast_sockaddr media_address
 
static int min_expiry = DEFAULT_MIN_EXPIRY
 
static int min_subexpiry = DEFAULT_MIN_EXPIRY
 
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. More...
 
static ast_mutex_t monlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. More...
 
static int mwi_expiry = DEFAULT_MWI_EXPIRY
 
static ast_mutex_t netlock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static int network_change_sched_id = -1
 
static struct stasis_subscriptionnetwork_change_sub
 
static const char notify_config [] = "sip_notify.conf"
 
static struct ast_confignotify_types = NULL
 
static int ourport_tcp
 
static int ourport_tls
 
static struct ao2_containerpeers
 The peer list: Users, Peers and Friends. More...
 
static struct ao2_containerpeers_by_ip
 
static const struct _map_x_s referstatusstrings []
 
static struct ao2_containerregistry_list
 The register list: Other SIP proxies we register with and receive calls from. More...
 
static const struct _map_x_s regstatestrings []
 
static struct ast_sockaddr rtpbindaddr
 
struct ast_sched_contextsched
 
static struct ast_cc_agent_callbacks sip_cc_agent_callbacks
 
static struct ast_cc_monitor_callbacks sip_cc_monitor_callbacks
 
struct {
   enum sip_cc_notify_state   state
 
   const char *   state_string
 
sip_cc_notify_state_map []
 
struct {
   enum ast_cc_service_type   service
 
   const char *   service_string
 
sip_cc_service_map []
 
static struct ast_threadstorage sip_content_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sip_content_buf , .custom_init = NULL , }
 
static struct ast_custom_function sip_header_function
 
static struct ast_custom_function sip_headers_function
 
static const struct cfsip_methods sip_methods []
 
struct ao2_containersip_monitor_instances
 
static const struct ast_msg_tech sip_msg_tech
 
static const struct sip_reasons sip_reason_table []
 
static ast_mutex_t sip_reload_lock = { PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP , NULL, {1, 0} }
 
static int sip_reloading = FALSE
 
static enum channelreloadreason sip_reloadreason
 
static struct ast_rtp_glue sip_rtp_glue
 
static struct ast_tcptls_session_args sip_tcp_desc
 The TCP server definition. More...
 
struct ast_channel_tech sip_tech
 Definition of this channel for PBX channel registration. More...
 
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. More...
 
static struct ast_tls_config sip_tls_cfg
 Working TLS connection configuration. More...
 
static struct ast_tcptls_session_args sip_tls_desc
 The TCP/TLS server definition. More...
 
static struct ast_threadstorage sip_transport_str_buf = { .once = PTHREAD_ONCE_INIT , .key_init = __init_sip_transport_str_buf , .custom_init = NULL , }
 
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. More...
 
static struct ast_custom_function sippeer_function
 Structure to declare a dialplan function: SIPPEER. More...
 
static int sipsock = -1
 Main socket for UDP SIP communication. More...
 
static int * sipsock_read_id
 
static const struct _map_x_s stmodes []
 Report Peer status in character string. More...
 
static const struct _map_x_s strefresher_params []
 
static const struct _map_x_s strefreshers []
 
static struct ao2_containersubscription_mwi_list
 The MWI subscription list. More...
 
static const struct cfsubscription_types subscription_types []
 
static struct ao2_containerthreadt
 The table of TCP threads. More...
 
static const struct _map_x_s trust_id_outboundstr []
 
static struct ast_threadstorage ts_temp_pvt = { .once = PTHREAD_ONCE_INIT , .key_init = __init_ts_temp_pvt , .custom_init = temp_pvt_init , }
 
static int unauth_sessions = 0
 
static char used_context [AST_MAX_CONTEXT]
 
Object counters @{
Bug:
These counters are not handled in a thread-safe way ast_atomic_fetchadd_int() should be used to modify these values.
static int speerobjs = 0
 
static int rpeerobjs = 0
 
static int apeerobjs = 0
 

DefaultSettings

Default setttings are used as a channel setting and as a default when configuring devices

#define SIP_PEDANTIC_DECODE(str)
 
static char default_language [MAX_LANGUAGE]
 
static char default_callerid [AST_MAX_EXTENSION]
 
static char default_mwi_from [80]
 
static char default_fromdomain [AST_MAX_EXTENSION]
 
static int default_fromdomainport
 
static char default_notifymime [AST_MAX_EXTENSION]
 
static char default_vmexten [AST_MAX_EXTENSION]
 
static int default_qualify
 
static int default_keepalive
 
static char default_mohinterpret [MAX_MUSICCLASS]
 
static char default_mohsuggest [MAX_MUSICCLASS]
 
static char default_parkinglot [AST_MAX_CONTEXT]
 
static char default_engine [256]
 
static int default_maxcallbitrate
 
static char default_zone [MAX_TONEZONE_COUNTRY]
 
static unsigned int default_transports
 
static unsigned int default_primary_transport
 
static struct sip_settings sip_cfg
 
static unsigned int chan_idx
 
static int global_match_auth_username
 
static int global_relaxdtmf
 
static int global_prematuremediafilter
 
static int global_rtptimeout
 
static int global_rtpholdtimeout
 
static int global_rtpkeepalive
 
static int global_reg_timeout
 
static int global_regattempts_max
 
static int global_reg_retry_403
 
static int global_shrinkcallerid
 
static int global_callcounter
 
static unsigned int global_tos_sip
 
static unsigned int global_tos_audio
 
static unsigned int global_tos_video
 
static unsigned int global_tos_text
 
static unsigned int global_cos_sip
 
static unsigned int global_cos_audio
 
static unsigned int global_cos_video
 
static unsigned int global_cos_text
 
static unsigned int recordhistory
 
static unsigned int dumphistory
 
static char global_useragent [AST_MAX_EXTENSION]
 
static char global_sdpsession [AST_MAX_EXTENSION]
 
static char global_sdpowner [AST_MAX_EXTENSION]
 
static int global_authfailureevents
 
static int global_t1
 
static int global_t1min
 
static int global_timer_b
 
static unsigned int global_autoframing
 
static int global_qualifyfreq
 
static int global_qualify_gap
 
static int global_qualify_peers
 
static enum st_mode global_st_mode
 
static enum st_refresher_param global_st_refresher
 
static int global_min_se
 
static int global_max_se
 
static int global_store_sip_cause
 
static int global_dynamic_exclude_static = 0
 
static unsigned char global_refer_addheaders
 

Detailed Description

Implementation of Session Initiation Protocol.

Author
Mark Spencer marks.nosp@m.ter@.nosp@m.digiu.nosp@m.m.co.nosp@m.m

See Also:

Implementation of RFC 3261 - without S/MIME, and experimental TCP and TLS support Configuration file sip.conf

********** IMPORTANT *

Note
TCP/TLS support is EXPERIMENTAL and WILL CHANGE. This applies to configuration settings, dialplan commands and dialplans apps/functions See SIP TCP and TLS support

******** General TODO:s

Todo:

Better support of forking

VIA branch tag transaction checking

Transaction support

******** Wishlist: Improvements

Overview of the handling of SIP sessions
The SIP channel handles several types of SIP sessions, or dialogs, not all of them being "telephone calls".
  • Incoming calls that will be sent to the PBX core
  • Outgoing calls, generated by the PBX
  • SIP subscriptions and notifications of states and voicemail messages
  • SIP registrations, both inbound and outbound
  • SIP peer management (peerpoke, OPTIONS)
  • SIP text messages

In the SIP channel, there's a list of active SIP dialogs, which includes all of these when they are active. "sip show channels" in the CLI will show most of these, excluding subscriptions which are shown by "sip show subscriptions"

incoming packets
Incoming packets are received in the monitoring thread, then handled by sipsock_read() for udp only. In tcp, packets are read by the tcp_helper thread. sipsock_read() function parses the packet and matches an existing dialog or starts a new SIP dialog.

sipsock_read sends the packet to handle_incoming(), that parses a bit more. If it is a response to an outbound request, the packet is sent to handle_response(). If it is a request, handle_incoming() sends it to one of a list of functions depending on the request type - INVITE, OPTIONS, REFER, BYE, CANCEL etc sipsock_read locks the ast_channel if it exists (an active call) and unlocks it after we have processed the SIP message.

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

Outbound calls
Outbound calls are set up by the PBX through the sip_request_call() function. After that, they are activated by sip_call().
Hanging up
The PBX issues a hangup on both incoming and outgoing calls through the sip_hangup() function

Definition in file chan_sip.c.

Macro Definition Documentation

◆ append_history

#define append_history (   p,
  event,
  fmt,
  args... 
)    append_history_full(p, "%-15s " fmt, event, ## args)

◆ BOGUS_PEER_MD5SECRET

#define BOGUS_PEER_MD5SECRET   "intentionally_invalid_md5_string"

We can recognize the bogus peer by this invalid MD5 hash.

Definition at line 1058 of file chan_sip.c.

Referenced by check_auth(), load_module(), and sip_reload().

◆ check_request_transport

#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 2498 of file chan_sip.c.

Referenced by create_addr_from_peer(), and register_verify().

◆ CHECK_RESULTS

#define CHECK_RESULTS (   in,
  expected_res,
  expected_start,
  expected_len 
)

Referenced by AST_TEST_DEFINE().

◆ CONTAINER_UNLINK

#define CONTAINER_UNLINK (   container,
  obj,
  tag 
)

Unlink the given object from the container and return TRUE if it was in the container.

Definition at line 8838 of file chan_sip.c.

Referenced by change_callid_pvt().

◆ find_call

#define find_call (   req,
  addr,
  intended_method 
)    __find_call(req, addr, intended_method, __FILE__, __LINE__, __PRETTY_FUNCTION__)

Definition at line 1240 of file chan_sip.c.

Referenced by handle_request_do().

◆ FORMAT [1/8]

#define FORMAT   "%-25.25s %-15.15s %-15.15s \n"

◆ FORMAT [2/8]

#define FORMAT   "%-47.47s %-9.9s %-6.6s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [3/8]

#define FORMAT   "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [4/8]

#define FORMAT   "%-40.40s %-20.20s %-16.16s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [5/8]

#define FORMAT   "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [6/8]

#define FORMAT   "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [7/8]

#define FORMAT   "%-30.30s %-12.12s %-10.10s %-10.10s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT [8/8]

#define FORMAT   "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n"

Definition at line 22152 of file chan_sip.c.

◆ FORMAT2 [1/5]

#define FORMAT2   "%-25.25s %-15.15s %-15.15s \n"

◆ FORMAT2 [2/5]

#define FORMAT2   "%-47.47s %9.9s %6.6s\n"

Definition at line 22151 of file chan_sip.c.

◆ FORMAT2 [3/5]

#define FORMAT2   "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n"

Definition at line 22151 of file chan_sip.c.

◆ FORMAT2 [4/5]

#define FORMAT2   "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n"

Definition at line 22151 of file chan_sip.c.

◆ FORMAT2 [5/5]

#define FORMAT2   "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n"

Definition at line 22151 of file chan_sip.c.

◆ FORMAT3

#define FORMAT3   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n"

Definition at line 22150 of file chan_sip.c.

Referenced by sip_show_channels().

◆ FORMAT4

#define FORMAT4   "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n"

Definition at line 22149 of file chan_sip.c.

Referenced by show_channels_cb().

◆ peer_in_destruction

#define peer_in_destruction (   peer)    (ao2_ref(peer, 0) == 0)

Definition at line 1337 of file chan_sip.c.

Referenced by mwi_event_cb().

◆ PEERS_FORMAT2

#define PEERS_FORMAT2   "%-25.25s %-39.39s %-3.3s %-10.10s %-10.10s %-3.3s %-8s %-11s %-32.32s %s\n"

Definition at line 20280 of file chan_sip.c.

Referenced by _sip_show_peers(), and _sip_show_peers_one().

◆ REMOVE_MAILBOX_WITH_LOCKED_PEER

#define REMOVE_MAILBOX_WITH_LOCKED_PEER (   __peer)

Definition at line 5283 of file chan_sip.c.

Referenced by clear_peer_mailboxes().

◆ SIP_PEDANTIC_DECODE

#define SIP_PEDANTIC_DECODE (   str)
Value:
ast_uri_decode(str, ast_uri_sip_user); \
} \
const char * str
Definition: app_jack.c:147
#define ast_strlen_zero(foo)
Definition: strings.h:52
int pedanticsipchecking
Definition: sip.h:756
static struct sip_settings sip_cfg
Definition: chan_sip.c:809
const struct ast_flags ast_uri_sip_user
Definition: main/utils.c:575

Definition at line 813 of file chan_sip.c.

Referenced by check_user_full(), get_also_info(), get_destination(), get_refer_info(), register_verify(), and sip_msg_send().

◆ sip_pvt_lock

#define sip_pvt_lock (   x)    ao2_lock(x)

◆ sip_pvt_trylock

#define sip_pvt_trylock (   x)    ao2_trylock(x)

Definition at line 1045 of file chan_sip.c.

Referenced by dialog_checkrtp_cb(), dialog_needdestroy(), and forked_invite_init().

◆ sip_pvt_unlock

#define sip_pvt_unlock (   x)    ao2_unlock(x)

Definition at line 1046 of file chan_sip.c.

Referenced by __find_call(), __sched_check_pendings(), __sip_autodestruct(), __sip_cancel_destroy(), __sip_scheddestroy(), __update_provisional_keepalive_full(), auto_congest(), complete_sipch(), dialog_checkrtp_cb(), dialog_needdestroy(), dialog_unlink_all(), do_dialog_unlink_sched_items(), extensionstate_update(), forked_invite_init(), get_refer_info(), get_sip_pvt_from_replaces(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_refer(), handle_request_subscribe(), local_attended_transfer(), parse_register_contact(), proc_session_timer(), register_verify(), reinvite_timeout(), retrans_pkt(), send_provisional_keepalive_full(), show_channels_cb(), show_chanstats_cb(), sip_allow_anyrtp_remote(), sip_answer(), sip_call(), sip_cc_agent_destructor(), sip_cc_agent_init(), sip_cc_agent_recall(), sip_cc_agent_respond(), sip_cc_monitor_request_cc(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_monitor_instance_destructor(), sip_msg_send(), sip_new(), sip_pvt_lock_full(), sip_queryoption(), sip_queue_hangup_cause(), sip_read(), sip_reg_timeout(), sip_reinvite_retry(), sip_request_call(), sip_send_mwi_to_peer(), sip_senddigit_begin(), sip_senddigit_end(), sip_sendtext(), sip_set_rtp_peer(), sip_setoption(), sip_show_channel(), sip_show_history(), sip_t38_abort(), sip_transfer(), sip_write(), sipinfo_send(), transmit_publish(), and update_call_counter().

◆ SIP_TRANSPORT_STR_BUFSIZE

#define SIP_TRANSPORT_STR_BUFSIZE   128

Size of the SIP transport buffer.

Definition at line 1076 of file chan_sip.c.

Referenced by get_transport_list().

◆ SIPHEADER

#define SIPHEADER   256

Referenced by initreqprep().

◆ UNLINK

#define UNLINK (   element,
  head,
  prev 
)

some list management macros.

Definition at line 1157 of file chan_sip.c.

Referenced by __sip_ack(), handle_request_cancel(), and retrans_pkt().

Enumeration Type Documentation

◆ match_req_res

Enumerator
SIP_REQ_MATCH 
SIP_REQ_NOT_MATCH 
SIP_REQ_LOOP_DETECTED 
SIP_REQ_FORKED 

Definition at line 9165 of file chan_sip.c.

9165  {
9166  SIP_REQ_MATCH,
9168  SIP_REQ_LOOP_DETECTED, /* multiple incoming requests with same call-id but different branch parameters have been detected */
9169  SIP_REQ_FORKED, /* An outgoing request has been forked as result of receiving two differing 200ok responses. */
9170 };

◆ message_integrity

Indication of a TCP message's integrity.

Enumerator
MESSAGE_INVALID 

The message has an error in it with regards to its Content-Length header

MESSAGE_FRAGMENT 

The message is incomplete

MESSAGE_FRAGMENT_COMPLETE 

The data contains a complete message plus a fragment of another.

MESSAGE_COMPLETE 

The message is complete

Definition at line 2761 of file chan_sip.c.

2761  {
2762  /*!
2763  * The message has an error in it with
2764  * regards to its Content-Length header
2765  */
2767  /*!
2768  * The message is incomplete
2769  */
2771  /*!
2772  * The data contains a complete message
2773  * plus a fragment of another.
2774  */
2776  /*!
2777  * The message is complete
2778  */
2780 };

◆ peer_unlink_flag_t

Enumerator
SIP_PEERS_MARKED 
SIP_PEERS_ALL 

Definition at line 3225 of file chan_sip.c.

3225  {
3227  SIP_PEERS_ALL,
peer_unlink_flag_t
Definition: chan_sip.c:3225

◆ sip_media_fds

Enumerator
SIP_AUDIO_RTP_FD 
SIP_AUDIO_RTCP_FD 
SIP_VIDEO_RTP_FD 
SIP_VIDEO_RTCP_FD 
SIP_TEXT_RTP_FD 
SIP_UDPTL_FD 

Definition at line 7841 of file chan_sip.c.

Function Documentation

◆ __cleanup_registration()

static int __cleanup_registration ( const void *  data)
static

Definition at line 32459 of file chan_sip.c.

References ao2_lock, ao2_t_ref, ao2_unlock, ast_debug, ast_dnsmgr_release(), AST_SCHED_DEL_UNREF, sip_registry::call, dialog_unlink_all(), dialog_unref, sip_registry::dnsmgr, sip_registry::expire, sip_registry::hostname, NULL, sip_registry::timeout, and sip_registry::username.

Referenced by cleanup_registration().

32460 {
32461  struct sip_registry *reg = (struct sip_registry *) data;
32462 
32463  ao2_lock(reg);
32464 
32465  if (reg->call) {
32466  ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
32467  /* This will also remove references to the registry */
32468  dialog_unlink_all(reg->call);
32469  reg->call = dialog_unref(reg->call, "remove iterator->call from registry traversal");
32470  }
32471 
32473  ao2_t_ref(reg, -1, "Stop scheduled reregister timeout"));
32475  ao2_t_ref(reg, -1, "Stop scheduled register timeout"));
32476 
32477  if (reg->dnsmgr) {
32478  ast_dnsmgr_release(reg->dnsmgr);
32479  reg->dnsmgr = NULL;
32480  ao2_t_ref(reg, -1, "reg ptr unref from dnsmgr");
32481  }
32482 
32483  ao2_unlock(reg);
32484 
32485  ao2_t_ref(reg, -1, "cleanup_registration action");
32486  return 0;
32487 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
const ast_string_field hostname
Definition: sip.h:1414
int expire
Definition: sip.h:1418
const ast_string_field username
Definition: sip.h:1414
struct sip_pvt * call
Definition: sip.h:1424
Definition: sched.c:76
Registrations with other SIP proxies.
Definition: sip.h:1396
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:80
#define ao2_unlock(a)
Definition: astobj2.h:730
#define NULL
Definition: resample.c:96
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1429
void dialog_unlink_all(struct sip_pvt *dialog)
Unlink a dialog from the dialogs container, as well as any other places that it may be currently stor...
Definition: chan_sip.c:3367
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
#define ao2_lock(a)
Definition: astobj2.h:718
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
int timeout
Definition: sip.h:1422

◆ __dialog_unlink_sched_items()

static int __dialog_unlink_sched_items ( const void *  data)
static

Definition at line 3351 of file chan_sip.c.

References dialog_unref, and do_dialog_unlink_sched_items().

Referenced by dialog_unlink_all().

3352 {
3353  struct sip_pvt *dialog = (void *) data;
3354 
3356  dialog_unref(dialog, "Stop scheduled items for unlink action");
3357  return 0;
3358 }
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
static void do_dialog_unlink_sched_items(struct sip_pvt *dialog)
Definition: chan_sip.c:3308

◆ __find_call()

static struct sip_pvt * __find_call ( struct sip_request req,
struct ast_sockaddr addr,
const int  intended_method,
const char *  file,
int  line,
const char *  func 
)
static

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_request_do

Definition at line 9469 of file chan_sip.c.

References __ao2_callback(), __ao2_find(), __ao2_ref(), ao2_iterator_destroy(), ao2_iterator_next, args, ast_create_callid(), ast_debug, ast_skip_blanks(), ast_string_field_set, ast_strlen_zero, match_req_args::authentication_present, sip_via::branch, sip_pvt::callid, match_req_args::callid, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, dialog_find_multiple(), dialog_ref, dialog_unref, forked_invite_init(), free_via(), match_req_args::fromtag, gettag(), sip_request::has_to_tag, match_req_to_dialog(), sip_request::method, sip_pvt::method, match_req_args::method, NULL, OBJ_MULTIPLE, OBJ_POINTER, parse_via(), sip_settings::pedanticsipchecking, REQ_OFFSET_TO_STR, match_req_args::respid, match_req_args::ruri, sip_via::sent_by, match_req_args::seqno, SIP_ACK, sip_alloc, SIP_BYE, sip_cfg, sip_get_header(), SIP_INFO, SIP_INVITE, sip_methods, sip_pvt_lock, sip_pvt_unlock, SIP_REGISTER, SIP_REQ_FORKED, SIP_REQ_LOOP_DETECTED, SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, SIP_RESPONSE, cfsip_methods::text, sip_pvt::theirtag, match_req_args::totag, transmit_response_using_temp(), match_req_args::viabranch, and match_req_args::viasentby.

9471 {
9472  char totag[128];
9473  char fromtag[128];
9474  const char *callid = sip_get_header(req, "Call-ID");
9475  const char *from = sip_get_header(req, "From");
9476  const char *to = sip_get_header(req, "To");
9477  const char *cseq = sip_get_header(req, "Cseq");
9478  struct sip_pvt *sip_pvt_ptr;
9479  uint32_t seqno;
9480  /* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */
9481  /* sip_get_header always returns non-NULL so we must use ast_strlen_zero() */
9482  if (ast_strlen_zero(callid) || ast_strlen_zero(to) ||
9483  ast_strlen_zero(from) || ast_strlen_zero(cseq) ||
9484  (sscanf(cseq, "%30u", &seqno) != 1)) {
9485 
9486  /* RFC 3261 section 24.4.1. Send a 400 Bad Request if the request is malformed. */
9487  if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) {
9488  transmit_response_using_temp(callid, addr, 1, intended_method,
9489  req, "400 Bad Request");
9490  }
9491  return NULL; /* Invalid packet */
9492  }
9493 
9495  /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy
9496  we need more to identify a branch - so we have to check branch, from
9497  and to tags to identify a call leg.
9498  For Asterisk to behave correctly, you need to turn on pedanticsipchecking
9499  in sip.conf
9500  */
9501  if (gettag(req, "To", totag, sizeof(totag)))
9502  req->has_to_tag = 1; /* Used in handle_request/response */
9503  gettag(req, "From", fromtag, sizeof(fromtag));
9504 
9505  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);
9506 
9507  /* All messages must always have From: tag */
9508  if (ast_strlen_zero(fromtag)) {
9509  ast_debug(5, "%s request has no from tag, dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from );
9510  return NULL;
9511  }
9512  /* reject requests that must always have a To: tag */
9513  if (ast_strlen_zero(totag) && (req->method == SIP_ACK || req->method == SIP_BYE || req->method == SIP_INFO )) {
9514  if (req->method != SIP_ACK) {
9515  transmit_response_using_temp(callid, addr, 1, intended_method, req, "481 Call leg/transaction does not exist");
9516  }
9517  ast_debug(5, "%s must have a to tag. dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from );
9518  return NULL;
9519  }
9520  }
9521 
9522  /* match on callid only for REGISTERs */
9523  if (!sip_cfg.pedanticsipchecking || req->method == SIP_REGISTER) {
9524  struct sip_pvt tmp_dialog = {
9525  .callid = callid,
9526  };
9527  sip_pvt_ptr = __ao2_find(dialogs, &tmp_dialog, OBJ_POINTER,
9528  "find_call in dialogs", file, line, func);
9529  if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */
9530  /* Found the call */
9531  return sip_pvt_ptr;
9532  }
9533  } else { /* in pedantic mode! -- do the fancy search */
9534  struct sip_pvt tmp_dialog = {
9535  .callid = callid,
9536  };
9537  /* if a Outbound forked Request is detected, this pvt will point
9538  * to the dialog the Request is forking off of. */
9539  struct sip_pvt *fork_pvt = NULL;
9540  struct match_req_args args = { 0, };
9541  int found;
9542  struct ao2_iterator *iterator = __ao2_callback(dialogs,
9545  &tmp_dialog,
9546  "pedantic ao2_find in dialogs",
9547  file, line, func);
9548  struct sip_via *via = NULL;
9549 
9550  args.method = req->method;
9551  args.callid = NULL; /* we already matched this. */
9552  args.totag = totag;
9553  args.fromtag = fromtag;
9554  args.seqno = seqno;
9555  /* get via header information. */
9556  args.ruri = REQ_OFFSET_TO_STR(req, rlpart2);
9557  via = parse_via(sip_get_header(req, "Via"));
9558  if (via) {
9559  args.viasentby = via->sent_by;
9560  args.viabranch = via->branch;
9561  }
9562  /* determine if this is a Request with authentication credentials. */
9563  if (!ast_strlen_zero(sip_get_header(req, "Authorization")) ||
9564  !ast_strlen_zero(sip_get_header(req, "Proxy-Authorization"))) {
9565  args.authentication_present = 1;
9566  }
9567  /* if it is a response, get the response code */
9568  if (req->method == SIP_RESPONSE) {
9569  const char* e = ast_skip_blanks(REQ_OFFSET_TO_STR(req, rlpart2));
9570  int respid;
9571  if (!ast_strlen_zero(e) && (sscanf(e, "%30d", &respid) == 1)) {
9572  args.respid = respid;
9573  }
9574  }
9575 
9576  /* Iterate a list of dialogs already matched by Call-id */
9577  while (iterator && (sip_pvt_ptr = ao2_iterator_next(iterator))) {
9578  sip_pvt_lock(sip_pvt_ptr);
9579  found = match_req_to_dialog(sip_pvt_ptr, &args);
9580  sip_pvt_unlock(sip_pvt_ptr);
9581 
9582  switch (found) {
9583  case SIP_REQ_MATCH:
9584  sip_pvt_lock(sip_pvt_ptr);
9585  if (args.method != SIP_RESPONSE && args.authentication_present
9586  && strcmp(args.fromtag, sip_pvt_ptr->theirtag)) {
9587  /* If we have a request that uses athentication and the fromtag is
9588  * different from that in the original call dialog, update the
9589  * fromtag in the saved call dialog */
9590  ast_string_field_set(sip_pvt_ptr, theirtag, args.fromtag);
9591  }
9592  sip_pvt_unlock(sip_pvt_ptr);
9593  ao2_iterator_destroy(iterator);
9594  dialog_unref(fork_pvt, "unref fork_pvt");
9595  free_via(via);
9596  return sip_pvt_ptr; /* return pvt with ref */
9597  case SIP_REQ_LOOP_DETECTED:
9598  /* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork.
9599  * RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */
9600  transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)");
9601  __ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search.",
9602  file, line, func);
9603  ao2_iterator_destroy(iterator);
9604  dialog_unref(fork_pvt, "unref fork_pvt");
9605  free_via(via);
9606  return NULL;
9607  case SIP_REQ_FORKED:
9608  dialog_unref(fork_pvt, "throwing way pvt to fork off of.");
9609  fork_pvt = dialog_ref(sip_pvt_ptr, "this pvt has a forked request, save this off to copy information into new dialog\n");
9610  /* fall through */
9611  case SIP_REQ_NOT_MATCH:
9612  default:
9613  __ao2_ref(sip_pvt_ptr, -1, "pvt did not match incoming SIP msg, unref from search",
9614  file, line, func);
9615  break;
9616  }
9617  }
9618  if (iterator) {
9619  ao2_iterator_destroy(iterator);
9620  }
9621 
9622  /* Handle any possible forked requests. This must be done only after transaction matching is complete. */
9623  if (fork_pvt) {
9624  /* XXX right now we only support handling forked INVITE Requests. Any other
9625  * forked request type must be added here. */
9626  if (fork_pvt->method == SIP_INVITE) {
9627  forked_invite_init(req, args.totag, fork_pvt, addr);
9628  dialog_unref(fork_pvt, "throwing way old forked pvt");
9629  free_via(via);
9630  return NULL;
9631  }
9632  fork_pvt = dialog_unref(fork_pvt, "throwing way pvt to fork off of");
9633  }
9634 
9635  free_via(via);
9636  } /* end of pedantic mode Request/Reponse to Dialog matching */
9637 
9638  /* See if the method is capable of creating a dialog */
9639  if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) {
9640  struct sip_pvt *p = NULL;
9642 
9643  if (intended_method == SIP_INVITE) {
9644  logger_callid = ast_create_callid();
9645  }
9646 
9647  /* Ok, time to create a new SIP dialog object, a pvt */
9648  if (!(p = sip_alloc(callid, addr, 1, intended_method, req, logger_callid))) {
9649  /* We have a memory or file/socket error (can't allocate RTP sockets or something) so we're not
9650  getting a dialog from sip_alloc.
9651 
9652  Without a dialog we can't retransmit and handle ACKs and all that, but at least
9653  send an error message.
9654 
9655  Sorry, we apologize for the inconvienience
9656  */
9657  transmit_response_using_temp(callid, addr, 1, intended_method, req, "500 Server internal error");
9658  ast_debug(4, "Failed allocating SIP dialog, sending 500 Server internal error and giving up\n");
9659  }
9660  return p; /* can be NULL */
9661  } else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) {
9662  /* A method we do not support, let's take it on the volley */
9663  transmit_response_using_temp(callid, addr, 1, intended_method, req, "501 Method Not Implemented");
9664  ast_debug(2, "Got a request with unsupported SIP method.\n");
9665  } else if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) {
9666  /* This is a request outside of a dialog that we don't know about */
9667  transmit_response_using_temp(callid, addr, 1, intended_method, req, "481 Call leg/transaction does not exist");
9668  ast_debug(2, "That's odd... Got a request in unknown dialog. Callid %s\n", callid ? callid : "<unknown>");
9669  }
9670  /* We do not respond to responses for dialogs that we don't know about, we just drop
9671  the session quickly */
9672  if (intended_method == SIP_RESPONSE)
9673  ast_debug(2, "That's odd... Got a response on a call we don't know about. Callid %s\n", callid ? callid : "<unknown>");
9674 
9675  return NULL;
9676 }
static struct ao2_container * dialogs
Definition: chan_sip.c:1043
const char * sip_get_header(const struct sip_request *req, const char *name)
Get header from SIP request.
Definition: chan_sip.c:8600
Definition: sip.h:626
ast_callid logger_callid
Definition: sip.h:1008
void free_via(struct sip_via *v)
const char * viabranch
Definition: chan_sip.c:9158
const char * ruri
Definition: chan_sip.c:9157
void * __ao2_find(struct ao2_container *c, const void *arg, enum search_flags flags, const char *tag, const char *file, int line, const char *func)
Definition: sip.h:619
static const struct cfsip_methods sip_methods[]
const char * viasentby
Definition: chan_sip.c:9159
#define OBJ_POINTER
Definition: astobj2.h:1154
static const char * gettag(const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize)
Get tag from packet.
Definition: chan_sip.c:25654
void ao2_iterator_destroy(struct ao2_iterator *iter)
Destroy a container iterator.
const ast_string_field from
Definition: sip.h:1063
unsigned int ast_callid
Definition: logger.h:87
static int dialog_find_multiple(void *obj, void *arg, int flags)
Definition: chan_sip.c:34633
void * __ao2_callback(struct ao2_container *c, enum search_flags flags, ao2_callback_fn *cb_fn, void *arg, const char *tag, const char *file, int line, const char *func)
const char * args
Definition: sip.h:621
#define NULL
Definition: resample.c:96
const char * fromtag
Definition: chan_sip.c:9150
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define sip_pvt_lock(x)
Definition: chan_sip.c:1044
Structure to store Via information.
Definition: sip.h:874
int __ao2_ref(void *o, int delta, const char *tag, const char *file, int line, const char *func)
Definition: astobj2.c:498
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
int authentication_present
Definition: chan_sip.c:9162
const char * branch
Definition: sip.h:878
const char * totag
Definition: chan_sip.c:9149
#define sip_alloc(callid, addr, useglobal_nat, intended_method, req, logger_callid)
Definition: dialog.h:39
const ast_string_field theirtag
Definition: sip.h:1063
char * via
Definition: sip.h:875
int pedanticsipchecking
Definition: sip.h:756
static enum match_req_res match_req_to_dialog(struct sip_pvt *sip_pvt_ptr, struct match_req_args *arg)
Definition: chan_sip.c:9177
const ast_string_field callid
Definition: sip.h:1063
ast_callid ast_create_callid(void)
factory function to create a new uniquely identifying callid.
Definition: logger.c:1957
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
int method
Definition: sip.h:1009
int method
Definition: sip.h:833
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
#define ao2_iterator_next(iter)
Definition: astobj2.h:1933
static struct sip_settings sip_cfg
Definition: chan_sip.c:809
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
#define REQ_OFFSET_TO_STR(req, offset)
Definition: sip.h:858
char *const text
Definition: chan_sip.c:737
const char * sent_by
Definition: sip.h:877
uint32_t seqno
Definition: chan_sip.c:9151
const char * callid
Definition: chan_sip.c:9148
When we need to walk through a container, we use an ao2_iterator to keep track of the current positio...
Definition: astobj2.h:1841
struct sip_via * parse_via(const char *header)
Parse a Via header.
char has_to_tag
Definition: sip.h:838
static void forked_invite_init(struct sip_request *req, const char *new_theirtag, struct sip_pvt *original, struct ast_sockaddr *addr)
This function creates a dialog to handle a forked request. This dialog exists only to properly termin...
Definition: chan_sip.c:9333
static int transmit_response_using_temp(ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, const struct sip_request *req, const char *msg)
Transmit response, no retransmits, using a temporary pvt structure.
Definition: chan_sip.c:12601
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ __get_header()

static const char * __get_header ( const struct sip_request req,
const char *  name,
int *  start 
)
static

Definition at line 8562 of file chan_sip.c.

References ast_skip_blanks(), find_alias(), sip_request::headers, len(), match(), NULL, and REQ_OFFSET_TO_STR.

Referenced by build_path(), build_route(), copy_all_header(), copy_via_headers(), func_header_read(), handle_incoming(), handle_request_invite(), handle_request_subscribe(), handle_response_register(), parse_register_contact(), reply_digest(), and sip_get_header().

8563 {
8564  /*
8565  * Technically you can place arbitrary whitespace both before and after the ':' in
8566  * a header, although RFC3261 clearly says you shouldn't before, and place just
8567  * one afterwards. If you shouldn't do it, what absolute idiot decided it was
8568  * a good idea to say you can do it, and if you can do it, why in the hell would.
8569  * you say you shouldn't.
8570  */
8571  const char *sname = find_alias(name, NULL);
8572  int x, len = strlen(name), slen = (sname ? 1 : 0);
8573  for (x = *start; x < req->headers; x++) {
8574  const char *header = REQ_OFFSET_TO_STR(req, header[x]);
8575  int smatch = 0, match = !strncasecmp(header, name, len);
8576  if (slen) {
8577  smatch = !strncasecmp(header, sname, slen);
8578  }
8579  if (match || smatch) {
8580  /* skip name */
8581  const char *r = header + (match ? len : slen );
8582  /* HCOLON has optional SP/HTAB; skip past those */
8583  while (*r == ' ' || *r == '\t') {
8584  ++r;
8585  }
8586  if (*r == ':') {
8587  *start = x+1;
8588  return ast_skip_blanks(r+1);
8589  }
8590  }
8591  }
8592 
8593  /* Don't return NULL, so sip_get_header is always a valid pointer */
8594  return "";
8595 }
static const char * find_alias(const char *name, const char *_default)
Find compressed SIP alias.
Definition: chan_sip.c:8534
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
#define NULL
Definition: resample.c:96
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
char * ast_skip_blanks(const char *str)
Gets a pointer to the first non-whitespace character in a string.
Definition: strings.h:157
int headers
Definition: sip.h:832
static const char name[]
Definition: cdr_mysql.c:74
#define REQ_OFFSET_TO_STR(req, offset)
Definition: sip.h:858

◆ __init_sip_content_buf()

static void __init_sip_content_buf ( void  )
static

Definition at line 8607 of file chan_sip.c.

8611 {

◆ __init_sip_transport_str_buf()

static void __init_sip_transport_str_buf ( void  )
static

A per-thread buffer for transport to string conversion.

Definition at line 1073 of file chan_sip.c.

1157 { \

◆ __init_ts_temp_pvt()

static void __init_ts_temp_pvt ( void  )
static

A per-thread temporary pvt structure.

Definition at line 1070 of file chan_sip.c.

1157 { \

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 35928 of file chan_sip.c.

◆ __sched_check_pendings()

static int __sched_check_pendings ( const void *  data)
static

Definition at line 23785 of file chan_sip.c.

References ast_channel_unlock, ast_channel_unref, check_pendings(), dialog_unref, sip_pvt_lock_full(), and sip_pvt_unlock.

Referenced by sched_check_pendings().

23786 {
23787  struct sip_pvt *pvt = (void *) data;
23788  struct ast_channel *owner;
23789 
23790  owner = sip_pvt_lock_full(pvt);
23791  check_pendings(pvt);
23792  if (owner) {
23793  ast_channel_unlock(owner);
23794  ast_channel_unref(owner);
23795  }
23796  sip_pvt_unlock(pvt);
23797 
23798  dialog_unref(pvt, "Check pending actions action");
23799  return 0;
23800 }
Main Channel structure associated with a channel.
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
static struct ast_channel * sip_pvt_lock_full(struct sip_pvt *pvt)
Definition: chan_sip.c:9400
#define ast_channel_unlock(chan)
Definition: channel.h:2946
static void check_pendings(struct sip_pvt *p)
Check pending actions on SIP call.
Definition: chan_sip.c:23735

◆ __set_address_from_contact()

static int __set_address_from_contact ( const char *  fullcontact,
struct ast_sockaddr addr,
int  tcp 
)
static

Definition at line 16892 of file chan_sip.c.

References ast_copy_string(), ast_log, ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_strlen_zero, AST_TRANSPORT_TLS, get_transport_str2enum(), LOG_WARNING, NULL, parse_uri_legacy_check(), STANDARD_SIP_PORT, and STANDARD_TLS_PORT.

Referenced by build_peer(), create_addr_from_peer(), dialog_initialize_rtp(), set_address_from_contact(), sip_poke_peer(), and sip_request_call().

16893 {
16894  char *hostport, *transport;
16895  char contact_buf[256];
16896  char *contact;
16897 
16898  /* Work on a copy */
16899  ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf));
16900  contact = contact_buf;
16901 
16902  /*
16903  * We have only the part in <brackets> here so we just need to parse a SIP URI.
16904  *
16905  * Note: The outbound proxy could be using UDP between the proxy and Asterisk.
16906  * We still need to be able to send to the remote agent through the proxy.
16907  */
16908 
16909  if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &hostport,
16910  &transport)) {
16911  ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
16912  }
16913 
16914  /* XXX This could block for a long time XXX */
16915  /* We should only do this if it's a name, not an IP */
16916  /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records
16917  to find transport, port address and hostname. If there's a port number, we have to
16918  assume that the hostport part is a host name and only look for an A/AAAA record in DNS.
16919  */
16920 
16921  /* If we took in an invalid URI, hostport may not have been initialized */
16922  /* ast_sockaddr_resolve requires an initialized hostport string. */
16923  if (ast_strlen_zero(hostport)) {
16924  ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire hostport\n");
16925  return -1;
16926  }
16927 
16928  if (ast_sockaddr_resolve_first_transport(addr, hostport, 0, get_transport_str2enum(transport))) {
16929  ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
16930  "resolve in DNS) : '%s'\n", hostport);
16931  return -1;
16932  }
16933 
16934  /* set port */
16935  if (!ast_sockaddr_port(addr)) {
16936  ast_sockaddr_set_port(addr,
16937  (get_transport_str2enum(transport) ==
16939  !strncasecmp(fullcontact, "sips", 4)) ?
16941  }
16942 
16943  return 0;
16944 }
#define LOG_WARNING
Definition: logger.h:274
#define NULL
Definition: resample.c:96
#define ast_strlen_zero(foo)
Definition: strings.h:52
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:521
#define ast_log
Definition: astobj2.c:42
#define STANDARD_TLS_PORT
Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:178
#define STANDARD_SIP_PORT
Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:176
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:537
static int get_transport_str2enum(const char *transport)
Return int representing a bit field of transport types found in const char *transport.
Definition: chan_sip.c:3658
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static int ast_sockaddr_resolve_first_transport(struct ast_sockaddr *addr, const char *name, int flag, unsigned int transport)
Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr. ...
Definition: chan_sip.c:34479
static int parse_uri_legacy_check(char *uri, const char *scheme, char **user, char **pass, char **hostport, char **transport)
parse uri in a way that allows semicolon stripping if legacy mode is enabled
Definition: chan_sip.c:16880

◆ __shutdown_mwi_subscription()

static int __shutdown_mwi_subscription ( const void *  data)
static

Definition at line 14935 of file chan_sip.c.

References ao2_t_ref, ast_dnsmgr_release(), AST_SCHED_DEL_UNREF, sip_subscription_mwi::dnsmgr, NULL, and sip_subscription_mwi::resub.

Referenced by shutdown_mwi_subscription().

14936 {
14937  struct sip_subscription_mwi *mwi = (void *) data;
14938 
14940  ao2_t_ref(mwi, -1, "Stop scheduled mwi resub"));
14941 
14942  if (mwi->dnsmgr) {
14943  ast_dnsmgr_release(mwi->dnsmgr);
14944  mwi->dnsmgr = NULL;
14945  ao2_t_ref(mwi, -1, "dnsmgr release");
14946  }
14947 
14948  ao2_t_ref(mwi, -1, "Shutdown MWI subscription action");
14949  return 0;
14950 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
Definition: sched.c:76
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:80
#define NULL
Definition: resample.c:96
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
Definition of an MWI subscription to another server.
Definition: sip.h:1454
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1467

◆ __sip_ack()

int __sip_ack ( struct sip_pvt p,
uint32_t  seqno,
int  resp,
int  sipmethod 
)

Acknowledges receipt of a packet and stops retransmission called with p locked.

Definition at line 4570 of file chan_sip.c.

References ao2_t_ref, ast_debug, sip_pvt::callid, FALSE, sip_proxy::force, sip_pkt::is_resp, sip_pkt::method, sip_pkt::next, NULL, sip_pvt::outboundproxy, sip_pvt::packets, sip_pvt::pendinginvite, ref_proxy(), sip_pkt::retransid, sip_pkt::seqno, sipdebug, stop_retrans_pkt(), TRUE, and UNLINK.

Referenced by __sip_pretend_ack(), handle_incoming(), handle_request_invite(), handle_request_publish(), and handle_response().

4571 {
4572  struct sip_pkt *cur, *prev = NULL;
4573  const char *msg = "Not Found"; /* used only for debugging */
4574  int res = FALSE;
4575 
4576  /* If we have an outbound proxy for this dialog, then delete it now since
4577  the rest of the requests in this dialog needs to follow the routing.
4578  If obforcing is set, we will keep the outbound proxy during the whole
4579  dialog, regardless of what the SIP rfc says
4580  */
4581  if (p->outboundproxy && !p->outboundproxy->force) {
4582  ref_proxy(p, NULL);
4583  }
4584 
4585  for (cur = p->packets; cur; prev = cur, cur = cur->next) {
4586  if (cur->seqno != seqno || cur->is_resp != resp) {
4587  continue;
4588  }
4589  if (cur->is_resp || cur->method == sipmethod) {
4590  res = TRUE;
4591  msg = "Found";
4592  if (!resp && (seqno == p->pendinginvite)) {
4593  ast_debug(1, "Acked pending invite %u\n", p->pendinginvite);
4594  p->pendinginvite = 0;
4595  }
4596  if (cur->retransid > -1) {
4597  if (sipdebug)
4598  ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
4599  }
4600 
4601  /* Unlink and destroy the packet object. */
4602  UNLINK(cur, p->packets, prev);
4603  stop_retrans_pkt(cur);
4604  ao2_t_ref(cur, -1, "Packet retransmission list");
4605  break;
4606  }
4607  }
4608  ast_debug(1, "Stopping retransmission on '%s' of %s %u: Match %s\n",
4609  p->callid, resp ? "Response" : "Request", seqno, msg);
4610  return res;
4611 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1231
int force
Definition: sip.h:727
#define FALSE
Definition: app_minivm.c:521
int method
Definition: sip.h:1234
static void stop_retrans_pkt(struct sip_pkt *pkt)
Definition: chan_sip.c:4251
uint32_t pendinginvite
Definition: sip.h:1147
uint32_t seqno
Definition: sip.h:1235
int retransid
Definition: sip.h:1240
#define NULL
Definition: resample.c:96
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
sipmethod
SIP Request methods known by Asterisk.
Definition: sip.h:612
const ast_string_field callid
Definition: sip.h:1063
char is_resp
Definition: sip.h:1236
static enum sip_debug_e sipdebug
Definition: chan_sip.c:916
struct sip_pkt * next
Definition: sip.h:1232
struct sip_pkt * packets
Definition: sip.h:1177
static void ref_proxy(struct sip_pvt *pvt, struct sip_proxy *proxy)
maintain proper refcounts for a sip_pvt&#39;s outboundproxy
Definition: chan_sip.c:3293
#define UNLINK(element, head, prev)
Definition: chan_sip.c:1157
#define TRUE
Definition: app_minivm.c:518
struct sip_proxy * outboundproxy
Definition: sip.h:1112

◆ __sip_alloc()

struct sip_pvt* __sip_alloc ( ast_string_field  callid,
struct ast_sockaddr addr,
int  useglobal_nat,
const int  intended_method,
struct sip_request req,
ast_callid  logger_callid,
const char *  file,
int  line,
const char *  func 
)

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 8942 of file chan_sip.c.

References __ao2_alloc(), sip_pvt::allowed_methods, sip_settings::allowtransfer, sip_pvt::allowtransfer, AO2_ALLOC_OPT_LOCK_MUTEX, ao2_cleanup, ao2_t_link, ao2_t_ref, ast_cc_config_params_init, ast_copy_flags, ast_copy_string(), ast_debug, ast_format_cap_alloc, ast_format_cap_append_from_cap(), AST_FORMAT_CAP_FLAG_DEFAULT, AST_LIST_HEAD_INIT_NOLOCK, AST_MEDIA_TYPE_UNKNOWN, ast_random(), AST_RTP_DTMF, ast_sip_ouraddrfor(), ast_sockaddr_copy(), ast_string_field_init, ast_string_field_set, ast_strlen_zero, ast_test_flag, AST_TRANSPORT_UDP, sip_pvt::autoframing, sip_pvt::autokillid, sip_via::branch, sip_pvt::branch, build_callid_pvt(), build_via(), sip_pvt::callid, sip_settings::caps, sip_pvt::caps, sip_pvt::cc_params, check_via(), context, sip_settings::default_context, default_engine, default_fromdomain, default_fromdomainport, sip_settings::default_max_forwards, default_maxcallbitrate, default_mohinterpret, default_mohsuggest, default_parkinglot, default_zone, sip_pvt::do_history, do_setnat(), sip_socket::fd, sip_pvt::flags, free_via(), sip_pvt::fromdomainport, global_autoframing, global_t1, global_timer_b, sip_pvt::init_icseq, INITIAL_CSEQ, sip_pvt::initid, internip, sip_pvt::jointcaps, make_our_tag(), sip_pvt::maxcallbitrate, sip_pvt::maxforwards, sip_pvt::method, mohinterpret, mohsuggest, sip_pvt::noncodeccapability, NONE, NULL, sip_pvt::ocseq, sip_pvt::offered_media, sip_pvt::ourip, parkinglot, parse_via(), sip_pvt::peercaps, sip_pvt::prefcaps, sip_pvt::provisional_keepalive_sched_id, recordhistory, sip_pvt::recv, sip_pvt::redircaps, sip_pvt::reinviteid, sip_pvt::request_queue, sip_pvt::request_queue_sched_id, sip_pvt::rtp, sip_pvt::sa, sip_via::sent_by, sip_pvt::session_modify, sip_pvt::sessionversion_remote, set_socket_transport(), sip_cfg, SIP_DTMF, SIP_DTMF_AUTO, SIP_DTMF_RFC2833, SIP_FLAGS_TO_COPY, sip_get_header(), sip_methods, SIP_OPTIONS, SIP_PAGE2_FLAGS_TO_COPY, SIP_PAGE3_FLAGS_TO_COPY, sip_pvt_callid_set(), sip_pvt_dtor(), SIP_REGISTER, sip_request::socket, sip_pvt::socket, sip_pvt::stateid, sip_pvt::stimer, sip_pvt::subscribed, sip_pvt::t38id, cfsip_methods::text, sip_pvt::timer_b, sip_pvt::timer_t1, TRUE, sip_socket::type, sip_pvt::waitid, and sip_pvt::zone.

8945 {
8946  struct sip_pvt *p;
8947 
8948  p = __ao2_alloc(sizeof(*p), sip_pvt_dtor,
8949  AO2_ALLOC_OPT_LOCK_MUTEX, "allocate a dialog(pvt) struct",
8950  file, line, func);
8951  if (!p) {
8952  return NULL;
8953  }
8954 
8955  if (ast_string_field_init(p, 512)) {
8956  ao2_t_ref(p, -1, "failed to string_field_init, drop p");
8957  return NULL;
8958  }
8959 
8960  if (!(p->cc_params = ast_cc_config_params_init())) {
8961  ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");
8962  return NULL;
8963  }
8964 
8965  if (logger_callid) {
8967  }
8968 
8974 
8975  if (!p->caps|| !p->jointcaps || !p->peercaps || !p->redircaps || !p->prefcaps) {
8976  ao2_cleanup(p->caps);
8977  ao2_cleanup(p->jointcaps);
8978  ao2_cleanup(p->peercaps);
8979  ao2_cleanup(p->redircaps);
8980  ao2_cleanup(p->prefcaps);
8981  ao2_t_ref(p, -1, "Yuck, couldn't allocate format capabilities. Get rid o' p");
8982  return NULL;
8983  }
8984 
8985 
8986  /* If this dialog is created as a result of a request or response, lets store
8987  * some information about it in the dialog. */
8988  if (req) {
8989  struct sip_via *via;
8990  const char *cseq = sip_get_header(req, "Cseq");
8991  uint32_t seqno;
8992 
8993  /* get branch parameter from initial Request that started this dialog */
8994  via = parse_via(sip_get_header(req, "Via"));
8995  if (via) {
8996  /* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise
8997  * it is not useful to us to have it */
8998  if (!ast_strlen_zero(via->branch) && !strncasecmp(via->branch, "z9hG4bK", 7)) {
8999  ast_string_field_set(p, initviabranch, via->branch);
9000  ast_string_field_set(p, initviasentby, via->sent_by);
9001  }
9002  free_via(via);
9003  }
9004 
9005  /* Store initial incoming cseq. An error in sscanf here is ignored. There is no approperiate
9006  * except not storing the number. CSeq validation must take place before dialog creation in find_call */
9007  if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) {
9008  p->init_icseq = seqno;
9009  }
9010  /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */
9012  } else {
9014  }
9015 
9016  p->socket.fd = -1;
9017  p->method = intended_method;
9018  p->initid = -1;
9019  p->waitid = -1;
9020  p->reinviteid = -1;
9021  p->autokillid = -1;
9022  p->request_queue_sched_id = -1;
9024  p->t38id = -1;
9025  p->subscribed = NONE;
9026  p->stateid = -1;
9027  p->sessionversion_remote = -1;
9028  p->session_modify = TRUE;
9029  p->stimer = NULL;
9030  ast_copy_string(p->zone, default_zone, sizeof(p->zone));
9032 
9033  if (intended_method != SIP_OPTIONS) { /* Peerpoke has it's own system */
9034  p->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
9035  p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
9036  }
9037 
9038  if (!addr) {
9039  p->ourip = internip;
9040  } else {
9041  ast_sockaddr_copy(&p->sa, addr);
9042  ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
9043  }
9044 
9045  /* Copy global flags to this PVT at setup. */
9049 
9051 
9052  p->branch = ast_random();
9053  make_our_tag(p);
9054  p->ocseq = INITIAL_CSEQ;
9055  p->allowed_methods = UINT_MAX;
9056 
9057  if (sip_methods[intended_method].need_rtp) {
9060  }
9061 
9062  if (useglobal_nat && addr) {
9063  /* Setup NAT structure according to global settings if we have an address */
9064  ast_sockaddr_copy(&p->recv, addr);
9065  check_via(p, req);
9066  do_setnat(p);
9067  }
9068 
9069  if (p->method != SIP_REGISTER) {
9070  ast_string_field_set(p, fromdomain, default_fromdomain);
9072  }
9073  build_via(p);
9074  if (!callid)
9075  build_callid_pvt(p);
9076  else
9077  ast_string_field_set(p, callid, callid);
9078  /* Assign default music on hold class */
9083  if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
9084  (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
9086  }
9090 
9093 
9094  /* Add to active dialog list */
9095 
9096  ao2_t_link(dialogs, p, "link pvt into dialogs table");
9097 
9098  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");
9099  return p;
9100 }
static struct ao2_container * dialogs
Definition: chan_sip.c:1043
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
const char * sip_get_header(const struct sip_request *req, const char *name)
Get header from SIP request.
Definition: chan_sip.c:8600
ast_callid logger_callid
Definition: sip.h:1008
struct ast_format_cap * peercaps
Definition: sip.h:1101
struct ast_cc_config_params * cc_params
Definition: sip.h:1218
static char mohinterpret[MAX_MUSICCLASS]
Definition: chan_alsa.c:119
uint32_t init_icseq
Definition: sip.h:1069
struct ast_format_cap * prefcaps
Definition: sip.h:1103
enum subscriptiontype subscribed
Definition: sip.h:1161
int fromdomainport
Definition: sip.h:1220
unsigned int allowed_methods
Definition: sip.h:1196
void free_via(struct sip_via *v)
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:163
int64_t sessionversion_remote
Definition: sip.h:1123
static void build_via(struct sip_pvt *p)
Build a Via header for a request.
Definition: chan_sip.c:3847
int maxcallbitrate
Definition: sip.h:1106
#define ast_test_flag(p, flag)
Definition: utils.h:63
static const struct cfsip_methods sip_methods[]
static void ast_sockaddr_copy(struct ast_sockaddr *dst, const struct ast_sockaddr *src)
Copies the data from one ast_sockaddr to another.
Definition: netsock2.h:171
#define NONE
Definition: misdn_config.c:45
int autokillid
Definition: sip.h:1158
int reinviteid
Definition: sip.h:1157
static void check_via(struct sip_pvt *p, const struct sip_request *req)
check Via: header for hostname, port and rport request/answer
Definition: chan_sip.c:19164
struct ast_sockaddr recv
Definition: sip.h:1135
int initid
Definition: sip.h:1155
struct sip_socket socket
Definition: sip.h:1066
#define SIP_DTMF_RFC2833
Definition: sip.h:276
void * __ao2_alloc(size_t data_size, ao2_destructor_fn destructor_fn, unsigned int options, const char *tag, const char *file, int line, const char *func) attribute_warn_unused_result
Definition: astobj2.c:765
struct ast_sockaddr ourip
Definition: sip.h:1136
#define ao2_t_link(container, obj, tag)
Add an object to a container.
Definition: astobj2.h:1547
static struct ast_sockaddr internip
our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suit...
Definition: chan_sip.c:1114
struct ast_format_cap * jointcaps
Definition: sip.h:1100
static char default_fromdomain[AST_MAX_EXTENSION]
Definition: chan_sip.c:793
static void ast_sip_ouraddrfor(const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p)
NAT fix - decide which IP address to use for Asterisk server?
Definition: chan_sip.c:3866
struct ast_flags flags[3]
Definition: sip.h:1075
#define ast_copy_flags(dest, src, flagz)
Definition: utils.h:84
#define NULL
Definition: resample.c:96
int provisional_keepalive_sched_id
Definition: sip.h:1109
static int default_maxcallbitrate
Definition: chan_sip.c:804
#define ast_cc_config_params_init()
Allocate and initialize an ast_cc_config_params structure.
Definition: ccss.h:135
int fd
Definition: sip.h:799
int request_queue_sched_id
Definition: sip.h:1108
static void make_our_tag(struct sip_pvt *pvt)
Make our SIP dialog tag.
Definition: chan_sip.c:8908
enum transfermodes allowtransfer
Definition: sip.h:776
#define ast_strlen_zero(foo)
Definition: strings.h:52
Structure to store Via information.
Definition: sip.h:874
char zone[MAX_TONEZONE_COUNTRY]
Definition: sip.h:1116
struct ast_sockaddr sa
Definition: sip.h:1125
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
static void sip_pvt_callid_set(struct sip_pvt *pvt, ast_callid callid)
Definition: chan_sip.c:8933
int noncodeccapability
Definition: sip.h:1104
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:353
struct ast_format_cap * caps
Definition: sip.h:1099
static char default_zone[MAX_TONEZONE_COUNTRY]
Definition: chan_sip.c:805
static char mohsuggest[MAX_MUSICCLASS]
Definition: chan_iax2.c:430
long branch
Definition: sip.h:1121
const char * branch
Definition: sip.h:878
long int ast_random(void)
Definition: main/utils.c:2064
#define SIP_PAGE3_FLAGS_TO_COPY
Definition: sip.h:396
unsigned short autoframing
Definition: sip.h:1089
int maxforwards
Definition: sip.h:1065
char * via
Definition: sip.h:875
int default_max_forwards
Definition: sip.h:789
#define ast_format_cap_alloc(flags)
Definition: format_cap.h:52
#define SIP_PAGE2_FLAGS_TO_COPY
Definition: sip.h:375
int waitid
Definition: sip.h:1156
const ast_string_field callid
Definition: sip.h:1063
static unsigned int recordhistory
Definition: chan_sip.c:841
struct ast_format_cap * redircaps
Definition: sip.h:1102
struct sip_st_dlg * stimer
Definition: sip.h:1184
static char default_parkinglot[AST_MAX_CONTEXT]
Definition: chan_sip.c:802
int method
Definition: sip.h:1009
static struct ast_flags global_flags[3]
Definition: chan_sip.c:884
int timer_b
Definition: sip.h:1096
uint32_t ocseq
Definition: sip.h:1067
static struct sip_settings sip_cfg
Definition: chan_sip.c:809
static char default_mohsuggest[MAX_MUSICCLASS]
Definition: chan_sip.c:800
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
static int global_timer_b
Definition: chan_sip.c:849
int stateid
Definition: sip.h:1162
#define SIP_FLAGS_TO_COPY
Flags to copy from peer/user to dialog.
Definition: sip.h:313
unsigned short do_history
Definition: sip.h:1078
int timer_t1
Definition: sip.h:1095
static unsigned int global_autoframing
Definition: chan_sip.c:850
#define INITIAL_CSEQ
Definition: sip.h:117
struct ast_rtp_instance * rtp
Definition: sip.h:1174
static char default_engine[256]
Definition: chan_sip.c:803
struct ast_format_cap * caps
Global list of addresses dynamic peers are not allowed to use.
Definition: sip.h:787
static void build_callid_pvt(struct sip_pvt *pvt)
Build SIP Call-ID value for a non-REGISTER transaction.
Definition: chan_sip.c:8829
static void do_setnat(struct sip_pvt *p)
Set nat mode on the various data sockets.
Definition: chan_sip.c:5862
char *const text
Definition: chan_sip.c:737
const char * sent_by
Definition: sip.h:877
struct sip_pvt::request_queue request_queue
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:680
enum transfermodes allowtransfer
Definition: sip.h:1137
#define SIP_DTMF
Definition: sip.h:275
#define ao2_cleanup(obj)
Definition: astobj2.h:1958
enum ast_transport type
Definition: sip.h:798
static char default_mohinterpret[MAX_MUSICCLASS]
Definition: chan_sip.c:799
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:401
static int default_fromdomainport
Definition: chan_sip.c:794
#define TRUE
Definition: app_minivm.c:518
static int global_t1
Definition: chan_sip.c:847
unsigned short session_modify
Definition: sip.h:1087
struct sip_via * parse_via(const char *header)
Parse a Via header.
struct sip_socket socket
Definition: sip.h:846
int ast_format_cap_append_from_cap(struct ast_format_cap *dst, const struct ast_format_cap *src, enum ast_media_type type)
Append the formats of provided type in src to dst.
Definition: format_cap.c:269
static void set_socket_transport(struct sip_socket *socket, int transport)
Definition: chan_sip.c:16629
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:116
struct sip_pvt::@174 offered_media
#define AST_RTP_DTMF
Definition: rtp_engine.h:266
char default_context[AST_MAX_CONTEXT]
Definition: sip.h:782
static void sip_pvt_dtor(void *vdoomed)
ao2 destructor for SIP dialog structure
Definition: chan_sip.c:6673
#define SIP_DTMF_AUTO
Definition: sip.h:279
int t38id
Definition: sip.h:1159
#define ast_string_field_set(x, field, data)
Set a field to a simple string value.
Definition: stringfields.h:514

◆ __sip_autodestruct()

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 4369 of file chan_sip.c.

References __sip_pretend_ack(), sip_pvt::alreadygone, append_history, AST_CAUSE_PROTOCOL_ERROR, ast_channel_name(), ast_channel_unlock, ast_channel_unref, ast_debug, AST_EXTENSION_DEACTIVATED, ast_log, ast_queue_hangup_with_cause(), sip_pvt::autokillid, CALL_COMPLETION, sip_pvt::callid, DEFAULT_TRANS_TIMEOUT, dialog_unlink_all(), dialog_unref, sip_pvt::lastmsg, LOG_WARNING, sip_pvt::method, method_match(), MWI_NOTIFICATION, sip_pvt::needdestroy, NONE, sip_pvt::ongoing_reinvite, sip_pvt::packets, pvt_set_needdestroy(), sip_pvt::refer, SIP_BYE, SIP_CANCEL, sip_methods, sip_pvt_lock_full(), sip_pvt_unlock, sip_scheddestroy(), state_notify_data::state, stop_media_flows(), 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().

4370 {
4371  struct sip_pvt *p = (struct sip_pvt *)data;
4372  struct ast_channel *owner;
4373 
4374  /* If this is a subscription, tell the phone that we got a timeout */
4376  struct state_notify_data data = { 0, };
4377 
4379 
4380  transmit_state_notify(p, &data, 1, TRUE); /* Send last notification */
4381  p->subscribed = NONE;
4382  append_history(p, "Subscribestatus", "timeout");
4383  ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>");
4384  return 10000; /* Reschedule this destruction so that we know that it's gone */
4385  }
4386 
4387  /* If there are packets still waiting for delivery, delay the destruction */
4388  if (p->packets) {
4389  if (!p->needdestroy) {
4390  char method_str[31];
4391 
4392  ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
4393  append_history(p, "ReliableXmit", "timeout");
4394  if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) {
4395  if (p->ongoing_reinvite || method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) {
4396  pvt_set_needdestroy(p, "autodestruct");
4397  }
4398  }
4399  return 10000;
4400  } else {
4401  /* They've had their chance to respond. Time to bail */
4402  __sip_pretend_ack(p);
4403  }
4404  }
4405 
4406  /*
4407  * Lock both the pvt and the channel safely so that we can queue up a frame.
4408  */
4409  owner = sip_pvt_lock_full(p);
4410  if (owner) {
4412  "Autodestruct on dialog '%s' with owner %s in place (Method: %s). Rescheduling destruction for 10000 ms\n",
4413  p->callid, ast_channel_name(owner), sip_methods[p->method].text);
4415  ast_channel_unlock(owner);
4416  ast_channel_unref(owner);
4417  sip_pvt_unlock(p);
4418  return 10000;
4419  }
4420 
4421  /* Reset schedule ID */
4422  p->autokillid = -1;
4423 
4424  if (p->refer && !p->alreadygone) {
4425  ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid);
4426  stop_media_flows(p);
4428  append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid);
4430  sip_pvt_unlock(p);
4431  } else {
4432  append_history(p, "AutoDestroy", "%s", p->callid);
4433  ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid);
4434  sip_pvt_unlock(p);
4435  dialog_unlink_all(p); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */
4436  }
4437 
4438  dialog_unref(p, "autokillid complete");
4439 
4440  return 0;
4441 }
static int transmit_request_with_auth(struct sip_pvt *p, int sipmethod, uint32_t seqno, enum xmittype reliable, int newbranch)
Transmit SIP request, auth added.
Definition: chan_sip.c:16564
#define AST_CAUSE_PROTOCOL_ERROR
Definition: causes.h:144
Main Channel structure associated with a channel.
enum subscriptiontype subscribed
Definition: sip.h:1161
void __sip_pretend_ack(struct sip_pvt *p)
Pretend to ack all packets called with p locked.
Definition: chan_sip.c:4615
char lastmsg[256]
Definition: sip.h:1145
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2981
static const struct cfsip_methods sip_methods[]
#define NONE
Definition: misdn_config.c:45
int autokillid
Definition: sip.h:1158
#define LOG_WARNING
Definition: logger.h:274
#define DEFAULT_TRANS_TIMEOUT
Definition: sip.h:107
unsigned short needdestroy
Definition: sip.h:1080
static int method_match(enum sipmethod id, const char *name)
returns true if &#39;name&#39; (with optional trailing whitespace) matches the sip method &#39;id&#39;...
Definition: chan_sip.c:3584
unsigned int ongoing_reinvite
Definition: sip.h:1144
Definition: sip.h:621
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1166
void dialog_unlink_all(struct sip_pvt *dialog)
Unlink a dialog from the dialogs container, as well as any other places that it may be currently stor...
Definition: chan_sip.c:3367
unsigned short alreadygone
Definition: sip.h:1079
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
const ast_string_field callid
Definition: sip.h:1063
static void pvt_set_needdestroy(struct sip_pvt *pvt, const char *reason)
Definition: chan_sip.c:3429
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
int method
Definition: sip.h:1009
static void stop_media_flows(struct sip_pvt *p)
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition: chan_sip.c:25156
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
static struct ast_channel * sip_pvt_lock_full(struct sip_pvt *pvt)
Definition: chan_sip.c:9400
#define ast_channel_unlock(chan)
Definition: channel.h:2946
struct sip_pkt * packets
Definition: sip.h:1177
char *const text
Definition: chan_sip.c:737
struct sip_refer * refer
Definition: sip.h:1160
static int transmit_state_notify(struct sip_pvt *p, struct state_notify_data *data, int full, int timeout)
Used in the SUBSCRIBE notification subsystem (RFC3265)
Definition: chan_sip.c:15477
const char * ast_channel_name(const struct ast_channel *chan)
#define TRUE
Definition: app_minivm.c:518
#define append_history(p, event, fmt, args...)
Append to SIP dialog history.
Definition: chan_sip.c:2406
void sip_scheddestroy(struct sip_pvt *p, int ms)
Schedule destruction of SIP dialog.
Definition: chan_sip.c:4549

◆ __sip_cancel_destroy()

static int __sip_cancel_destroy ( const void *  data)
static

Definition at line 4453 of file chan_sip.c.

References dialog_unref, do_cancel_destroy(), sip_pvt_lock, and sip_pvt_unlock.

Referenced by sip_cancel_destroy().

4454 {
4455  struct sip_pvt *pvt = (void *) data;
4456 
4457  sip_pvt_lock(pvt);
4458  do_cancel_destroy(pvt);
4459  sip_pvt_unlock(pvt);
4460  dialog_unref(pvt, "Cancel destroy action");
4461  return 0;
4462 }
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
#define sip_pvt_lock(x)
Definition: chan_sip.c:1044
static void do_cancel_destroy(struct sip_pvt *pvt)
Definition: chan_sip.c:4443
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005

◆ __sip_do_register()

static int __sip_do_register ( struct sip_registry r)
static

Register with SIP proxy.

Returns
see __sip_xmit

Definition at line 15909 of file chan_sip.c.

References NULL, SIP_REGISTER, and transmit_register().

Referenced by sip_reregister().

15910 {
15911  int res;
15912 
15914  return res;
15915 }
#define NULL
Definition: resample.c:96
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()) ...
Definition: chan_sip.c:16106

◆ __sip_pretend_ack()

void __sip_pretend_ack ( struct sip_pvt p)

Pretend to ack all packets called with p locked.

Definition at line 4615 of file chan_sip.c.

References __sip_ack(), ast_log, ast_str_buffer(), sip_pkt::data, find_sip_method(), sip_pkt::is_resp, LOG_WARNING, sip_pkt::method, method, NULL, 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().

4616 {
4617  struct sip_pkt *cur = NULL;
4618 
4619  while (p->packets) {
4620  int method;
4621  if (cur == p->packets) {
4622  ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text);
4623  return;
4624  }
4625  cur = p->packets;
4626  method = (cur->method) ? cur->method : find_sip_method(ast_str_buffer(cur->data));
4627  __sip_ack(p, cur->seqno, cur->is_resp, method);
4628  }
4629 }
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1231
int method
Definition: sip.h:1234
static const struct cfsip_methods sip_methods[]
#define LOG_WARNING
Definition: logger.h:274
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
uint32_t seqno
Definition: sip.h:1235
#define NULL
Definition: resample.c:96
int __sip_ack(struct sip_pvt *p, uint32_t seqno, int resp, int sipmethod)
Acknowledges receipt of a packet and stops retransmission called with p locked.
Definition: chan_sip.c:4570
#define ast_log
Definition: astobj2.c:42
const char * method
Definition: res_pjsip.c:4335
struct ast_str * data
Definition: sip.h:1246
char is_resp
Definition: sip.h:1236
struct sip_pkt * packets
Definition: sip.h:1177
static int find_sip_method(const char *msg)
find_sip_method: Find SIP method from header
Definition: chan_sip.c:3594
char *const text
Definition: chan_sip.c:737

◆ __sip_reliable_xmit()

static enum sip_result __sip_reliable_xmit ( struct sip_pvt p,
uint32_t  seqno,
int  resp,
struct ast_str data,
int  fatal,
int  sipmethod 
)
static

Definition at line 4275 of file chan_sip.c.

References __sip_xmit(), AO2_ALLOC_OPT_LOCK_NOLOCK, ao2_alloc_options, ao2_t_ref, append_history, ast_debug, AST_FAILURE, ast_log, AST_PTHREADT_NULL, ast_sched_add_variable(), ast_str_buffer(), ast_str_create, ast_str_set(), ast_str_strlen(), AST_SUCCESS, AST_TRANSPORT_UDP, ast_tvnow(), sip_pkt::data, DEFAULT_RETRANS, DEFAULT_TIMER_T1, dialog_ref, sip_pkt::is_fatal, sip_pkt::is_resp, LOG_ERROR, sip_pkt::method, monitor_thread, sip_pkt::next, NULL, sip_pkt::owner, sip_pvt::packets, sip_pvt::pendinginvite, sip_pkt::response_code, retrans_pkt(), sip_pkt::retrans_stop, sip_pkt::retrans_stop_time, sip_pkt::retransid, sip_pkt::seqno, SIP_INVITE, sip_pkt_dtor(), sipdebug, sip_pvt::socket, stop_retrans_pkt(), sip_pkt::time_sent, sip_pvt::timer_t1, sip_pkt::timer_t1, sip_socket::type, and XMIT_ERROR.

Referenced by send_request(), and send_response().

4276 {
4277  struct sip_pkt *pkt = NULL;
4278  int siptimer_a = DEFAULT_RETRANS;
4279  int xmitres = 0;
4280  unsigned respid;
4281 
4282  if (sipmethod == SIP_INVITE) {
4283  /* Note this is a pending invite */
4284  p->pendinginvite = seqno;
4285  }
4286 
4288  if (!pkt) {
4289  return AST_FAILURE;
4290  }
4291  /* copy data, add a terminator and save length */
4292  pkt->data = ast_str_create(ast_str_strlen(data));
4293  if (!pkt->data) {
4294  ao2_t_ref(pkt, -1, "Failed to initialize");
4295  return AST_FAILURE;
4296  }
4297  ast_str_set(&pkt->data, 0, "%s%s", ast_str_buffer(data), "\0");
4298  /* copy other parameters from the caller */
4299  pkt->method = sipmethod;
4300  pkt->seqno = seqno;
4301  pkt->is_resp = resp;
4302  pkt->is_fatal = fatal;
4303  pkt->owner = dialog_ref(p, "__sip_reliable_xmit: setting pkt->owner");
4304 
4305  /* The retransmission list owns a pkt ref */
4306  pkt->next = p->packets;
4307  p->packets = pkt; /* Add it to the queue */
4308 
4309  if (resp) {
4310  /* Parse out the response code */
4311  if (sscanf(ast_str_buffer(pkt->data), "SIP/2.0 %30u", &respid) == 1) {
4312  pkt->response_code = respid;
4313  }
4314  }
4315  pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */
4316  if (pkt->timer_t1) {
4317  siptimer_a = pkt->timer_t1;
4318  }
4319 
4320  pkt->time_sent = ast_tvnow(); /* time packet was sent */
4321  pkt->retrans_stop_time = 64 * (pkt->timer_t1 ? pkt->timer_t1 : DEFAULT_TIMER_T1); /* time in ms after pkt->time_sent to stop retransmission */
4322 
4323  if (!(p->socket.type & AST_TRANSPORT_UDP)) {
4324  /* TCP does not need retransmits as that's built in, but with
4325  * retrans_stop set, we must give it the full timer_H treatment */
4326  pkt->retrans_stop = 1;
4327  siptimer_a = pkt->retrans_stop_time;
4328  }
4329 
4330  /* Schedule retransmission */
4331  ao2_t_ref(pkt, +1, "Schedule packet retransmission");
4332  pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
4333  if (pkt->retransid < 0) {
4334  ao2_t_ref(pkt, -1, "Failed to schedule packet retransmission");
4335  }
4336 
4337  if (sipdebug) {
4338  ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid);
4339  }
4340 
4341  xmitres = __sip_xmit(pkt->owner, pkt->data); /* Send packet */
4342 
4343  if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */
4344  append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
4345  ast_log(LOG_ERROR, "Serious Network Trouble; __sip_xmit returns error for pkt data\n");
4346 
4347  /* Unlink and destroy the packet object. */
4348  p->packets = pkt->next;
4349  stop_retrans_pkt(pkt);
4350  ao2_t_ref(pkt, -1, "Packet retransmission list");
4351  return AST_FAILURE;
4352  } else {
4353  /* This is odd, but since the retrans timer starts at 500ms and the do_monitor thread
4354  * only wakes up every 1000ms by default, we have to poke the thread here to make
4355  * sure it successfully detects this must be retransmitted in less time than
4356  * it usually sleeps for. Otherwise it might not retransmit this packet for 1000ms. */
4358  pthread_kill(monitor_thread, SIGURG);
4359  }
4360  return AST_SUCCESS;
4361  }
4362 }
#define ao2_t_ref(o, delta, tag)
Reference/unreference an object and return the old refcount.
Definition: astobj2.h:463
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1231
struct sip_pvt * owner
Definition: sip.h:1239
int method
Definition: sip.h:1234
static void stop_retrans_pkt(struct sip_pkt *pkt)
Definition: chan_sip.c:4251
int response_code
Definition: sip.h:1238
uint32_t pendinginvite
Definition: sip.h:1147
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:714
struct sip_socket socket
Definition: sip.h:1066
uint32_t seqno
Definition: sip.h:1235
int retransid
Definition: sip.h:1240
Definition: sched.c:76
int ast_sched_add_variable(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data, int variable) attribute_warn_unused_result
Adds a scheduled event with rescheduling support.
Definition: sched.c:524
int timer_t1
Definition: sip.h:1242
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:150
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:406
#define NULL
Definition: resample.c:96
static int retrans_pkt(const void *data)
Retransmit SIP message if no answer.
Definition: chan_sip.c:4041
int ast_str_set(struct ast_str **buf, ssize_t max_len, const char *fmt,...)
Set a dynamic string using variable arguments.
Definition: strings.h:1065
#define ast_debug(level,...)
Log a DEBUG message.
Definition: logger.h:452
#define ast_log
Definition: astobj2.c:42
#define AST_PTHREADT_NULL
Definition: lock.h:66
static int __sip_xmit(struct sip_pvt *p, struct ast_str *data)
Definition: chan_sip.c:3801
sipmethod
SIP Request methods known by Asterisk.
Definition: sip.h:612
static void sip_pkt_dtor(void *vdoomed)
Definition: chan_sip.c:4260
struct ast_str * data
Definition: sip.h:1246
int64_t retrans_stop_time
Definition: sip.h:1244
#define XMIT_ERROR
Definition: sip.h:58
#define LOG_ERROR
Definition: logger.h:285
#define DEFAULT_RETRANS
Definition: chan_mgcp.c:126
char is_resp
Definition: sip.h:1236
int retrans_stop
Definition: sip.h:1245
struct timeval time_sent
Definition: sip.h:1243
static enum sip_debug_e sipdebug
Definition: chan_sip.c:916
struct sip_pkt * next
Definition: sip.h:1232
int timer_t1
Definition: sip.h:1095
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
struct sip_pkt * packets
Definition: sip.h:1177
#define DEFAULT_TIMER_T1
Definition: sip.h:101
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:688
enum ast_transport type
Definition: sip.h:798
#define append_history(p, event, fmt, args...)
Append to SIP dialog history.
Definition: chan_sip.c:2406
char is_fatal
Definition: sip.h:1237
static pthread_t monitor_thread
This is the thread for the monitor which checks for input on the channels which are not currently in ...
Definition: chan_sip.c:903
#define ast_str_create(init_len)
Create a malloc&#39;ed dynamic length string.
Definition: strings.h:620

◆ __sip_scheddestroy()

static int __sip_scheddestroy ( const void *  data)
static

Definition at line 4484 of file chan_sip.c.

References __sip_autodestruct(), append_history, ast_free, ast_sched_add(), sip_pvt::autokillid, dialog_ref, dialog_unref, do_cancel_destroy(), sip_pvt::do_history, sip_scheddestroy_data::ms, sip_scheddestroy_data::pvt, sip_pvt_lock, sip_pvt_unlock, sip_pvt::stimer, and stop_session_timer().

Referenced by sip_scheddestroy_full().

4485 {
4486  struct sip_scheddestroy_data *sched_data = (void *) data;
4487  struct sip_pvt *pvt = sched_data->pvt;
4488  int ms = sched_data->ms;
4489 
4490  ast_free(sched_data);
4491 
4492  sip_pvt_lock(pvt);
4493  do_cancel_destroy(pvt);
4494 
4495  if (pvt->do_history) {
4496  append_history(pvt, "SchedDestroy", "%d ms", ms);
4497  }
4498 
4499  dialog_ref(pvt, "Schedule autokillid");
4501  if (pvt->autokillid < 0) {
4502  /* Uh Oh. Expect bad behavior. */
4503  dialog_unref(pvt, "Failed to schedule autokillid");
4504  }
4505 
4506  if (pvt->stimer) {
4507  stop_session_timer(pvt);
4508  }
4509  sip_pvt_unlock(pvt);
4510  dialog_unref(pvt, "Destroy action");
4511  return 0;
4512 }
int autokillid
Definition: sip.h:1158
Definition: sched.c:76
#define sip_pvt_unlock(x)
Definition: chan_sip.c:1046
#define sip_pvt_lock(x)
Definition: chan_sip.c:1044
static void stop_session_timer(struct sip_pvt *p)
Session-Timers: Stop session timer.
Definition: chan_sip.c:30213
static void do_cancel_destroy(struct sip_pvt *pvt)
Definition: chan_sip.c:4443
struct sip_st_dlg * stimer
Definition: sip.h:1184
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1005
#define ast_free(a)
Definition: astmm.h:182
unsigned short do_history
Definition: sip.h:1078
#define dialog_ref(dialog, tag)
when we create or delete references, make sure to use these functions so we keep track of the refcoun...
Definition: dialog.h:32
int ast_sched_add(struct ast_sched_context *con, int when, ast_sched_cb callback, const void *data) attribute_warn_unused_result
Adds a scheduled event.