Asterisk - The Open Source Telephony Project  GIT-master-a24979a
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
 arguments used for Request/Response to matching More...
 
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 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...
 
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 globally 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)
 Handle SIP response in NOTIFY transaction We've sent a NOTIFY, now handle responses to it. More...
 
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)
 Handle SIP response in REFER transaction We've sent a REFER, now handle responses to it. More...
 
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)
 Handle SIP response in SUBSCRIBE transaction. More...
 
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)
 Match a incoming Request/Response to a dialog. More...
 
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 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)
 
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)
 Remove URI parameters at end of URI, not in username part though. More...
 
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)
 Determine what, if any, CC has been offered and queue a CC frame if possible. More...
 
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_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)
 
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)
 Unlink all marked peers from ao2 containers. More...
 
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 = AST_BUILDOPT_SUM, .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 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 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 apeerobjs = 0
 
static int rpeerobjs = 0
 
static int speerobjs = 0
 

DefaultSettings

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

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

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 Config_sip

********** 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)

Append to SIP dialog history.

Return values
0always

Definition at line 2413 of file chan_sip.c.

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

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

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

◆ find_call

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

Definition at line 1247 of file chan_sip.c.

◆ FORMAT [1/8]

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

Definition at line 22166 of file chan_sip.c.

◆ FORMAT [2/8]

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

Definition at line 22166 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 22166 of file chan_sip.c.

◆ FORMAT [4/8]

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

Definition at line 22166 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 22166 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 22166 of file chan_sip.c.

◆ FORMAT [7/8]

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

Definition at line 22166 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 22166 of file chan_sip.c.

◆ FORMAT2 [1/5]

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

Definition at line 22165 of file chan_sip.c.

◆ FORMAT2 [2/5]

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

Definition at line 22165 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 22165 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 22165 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 22165 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 22164 of file chan_sip.c.

◆ FORMAT4

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

Definition at line 22163 of file chan_sip.c.

◆ peer_in_destruction

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

Definition at line 1344 of file chan_sip.c.

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

◆ REMOVE_MAILBOX_WITH_LOCKED_PEER

#define REMOVE_MAILBOX_WITH_LOCKED_PEER (   __peer)

Definition at line 5294 of file chan_sip.c.

◆ 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
static struct sip_settings sip_cfg
Definition: chan_sip.c:815
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
int pedanticsipchecking
Definition: sip.h:753
const struct ast_flags ast_uri_sip_user
Definition: main/utils.c:721

Definition at line 819 of file chan_sip.c.

◆ sip_pvt_lock

#define sip_pvt_lock (   x)    ao2_lock(x)

Definition at line 1051 of file chan_sip.c.

◆ sip_pvt_trylock

#define sip_pvt_trylock (   x)    ao2_trylock(x)

Definition at line 1052 of file chan_sip.c.

◆ sip_pvt_unlock

#define sip_pvt_unlock (   x)    ao2_unlock(x)

Definition at line 1053 of file chan_sip.c.

◆ SIP_TRANSPORT_STR_BUFSIZE

#define SIP_TRANSPORT_STR_BUFSIZE   128

Size of the SIP transport buffer.

Definition at line 1083 of file chan_sip.c.

◆ SIPHEADER

#define SIPHEADER   256

◆ UNLINK

#define UNLINK (   element,
  head,
  prev 
)

some list management macros.

Definition at line 1164 of file chan_sip.c.

Enumeration Type Documentation

◆ match_req_res

Enumerator
SIP_REQ_MATCH 
SIP_REQ_NOT_MATCH 
SIP_REQ_LOOP_DETECTED 
SIP_REQ_FORKED 

Definition at line 9176 of file chan_sip.c.

9176  {
9177  SIP_REQ_MATCH,
9179  SIP_REQ_LOOP_DETECTED, /* multiple incoming requests with same call-id but different branch parameters have been detected */
9180  SIP_REQ_FORKED, /* An outgoing request has been forked as result of receiving two differing 200ok responses. */
9181 };
@ SIP_REQ_FORKED
Definition: chan_sip.c:9180
@ SIP_REQ_MATCH
Definition: chan_sip.c:9177
@ SIP_REQ_LOOP_DETECTED
Definition: chan_sip.c:9179
@ SIP_REQ_NOT_MATCH
Definition: chan_sip.c:9178

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

2768  {
2769  /*!
2770  * The message has an error in it with
2771  * regards to its Content-Length header
2772  */
2774  /*!
2775  * The message is incomplete
2776  */
2778  /*!
2779  * The data contains a complete message
2780  * plus a fragment of another.
2781  */
2783  /*!
2784  * The message is complete
2785  */
2787 };
@ MESSAGE_FRAGMENT_COMPLETE
Definition: chan_sip.c:2782
@ MESSAGE_COMPLETE
Definition: chan_sip.c:2786
@ MESSAGE_INVALID
Definition: chan_sip.c:2773
@ MESSAGE_FRAGMENT
Definition: chan_sip.c:2777

◆ peer_unlink_flag_t

Enumerator
SIP_PEERS_MARKED 
SIP_PEERS_ALL 

Definition at line 3234 of file chan_sip.c.

3234  {
3236  SIP_PEERS_ALL,
peer_unlink_flag_t
Definition: chan_sip.c:3234
@ SIP_PEERS_ALL
Definition: chan_sip.c:3236
@ SIP_PEERS_MARKED
Definition: chan_sip.c:3235

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

7854  {
7860  SIP_UDPTL_FD,
7861 };
@ SIP_UDPTL_FD
Definition: chan_sip.c:7860
@ SIP_VIDEO_RTCP_FD
Definition: chan_sip.c:7858
@ SIP_VIDEO_RTP_FD
Definition: chan_sip.c:7857
@ SIP_TEXT_RTP_FD
Definition: chan_sip.c:7859
@ SIP_AUDIO_RTP_FD
Definition: chan_sip.c:7855
@ SIP_AUDIO_RTCP_FD
Definition: chan_sip.c:7856

Function Documentation

◆ __cleanup_registration()

static int __cleanup_registration ( const void *  data)
static

Definition at line 32477 of file chan_sip.c.

32478 {
32479  struct sip_registry *reg = (struct sip_registry *) data;
32480 
32481  ao2_lock(reg);
32482 
32483  if (reg->call) {
32484  ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname);
32485  /* This will also remove references to the registry */
32486  dialog_unlink_all(reg->call);
32487  reg->call = dialog_unref(reg->call, "remove iterator->call from registry traversal");
32488  }
32489 
32491  ao2_t_ref(reg, -1, "Stop scheduled reregister timeout"));
32493  ao2_t_ref(reg, -1, "Stop scheduled register timeout"));
32494 
32495  if (reg->dnsmgr) {
32496  ast_dnsmgr_release(reg->dnsmgr);
32497  reg->dnsmgr = NULL;
32498  ao2_t_ref(reg, -1, "reg ptr unref from dnsmgr");
32499  }
32500 
32501  ao2_unlock(reg);
32502 
32503  ao2_t_ref(reg, -1, "cleanup_registration action");
32504  return 0;
32505 }
#define ao2_t_ref(o, delta, tag)
Definition: astobj2.h:460
#define ao2_unlock(a)
Definition: astobj2.h:729
#define ao2_lock(a)
Definition: astobj2.h:717
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:3377
#define dialog_unref(dialog, tag)
Definition: dialog.h:33
void ast_dnsmgr_release(struct ast_dnsmgr_entry *entry)
Free a DNS manager entry.
Definition: dnsmgr.c:136
#define ast_debug(level,...)
Log a DEBUG message.
#define NULL
Definition: resample.c:96
#define AST_SCHED_DEL_UNREF(sched, id, refcall)
schedule task to get deleted and call unref function
Definition: sched.h:82
Definition: sched.c:76
Registrations with other SIP proxies.
Definition: sip.h:1395
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1428
int expire
Definition: sip.h:1417
int timeout
Definition: sip.h:1421
const ast_string_field username
Definition: sip.h:1413
struct sip_pvt * call
Definition: sip.h:1423
const ast_string_field hostname
Definition: sip.h:1413

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().

◆ __dialog_unlink_sched_items()

static int __dialog_unlink_sched_items ( const void *  data)
static

Definition at line 3361 of file chan_sip.c.

3362 {
3363  struct sip_pvt *dialog = (void *) data;
3364 
3366  dialog_unref(dialog, "Stop scheduled items for unlink action");
3367  return 0;
3368 }
static void do_dialog_unlink_sched_items(struct sip_pvt *dialog)
Definition: chan_sip.c:3318
Structure used for each SIP dialog, ie. a call, a registration, a subscribe. Created and initialized ...
Definition: sip.h:1004

References dialog_unref, and do_dialog_unlink_sched_items().

Referenced by dialog_unlink_all().

◆ __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 9480 of file chan_sip.c.

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

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(), sip_via::branch, sip_pvt::callid, CAN_CREATE_DIALOG, CAN_CREATE_DIALOG_UNSUPPORTED_METHOD, dialog_find_multiple(), dialog_ref, dialog_unref, dialogs, make_ari_stubs::file, forked_invite_init(), free_via(), gettag(), sip_request::has_to_tag, match_req_to_dialog(), sip_request::method, sip_pvt::method, NULL, OBJ_MULTIPLE, OBJ_POINTER, parse_via(), sip_settings::pedanticsipchecking, REQ_OFFSET_TO_STR, sip_via::sent_by, 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, and transmit_response_using_temp().

◆ __get_header()

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

Definition at line 8575 of file chan_sip.c.

8576 {
8577  /*
8578  * Technically you can place arbitrary whitespace both before and after the ':' in
8579  * a header, although RFC3261 clearly says you shouldn't before, and place just
8580  * one afterwards. If you shouldn't do it, what absolute idiot decided it was
8581  * a good idea to say you can do it, and if you can do it, why in the hell would.
8582  * you say you shouldn't.
8583  */
8584  const char *sname = find_alias(name, NULL);
8585  int x, len = strlen(name), slen = (sname ? 1 : 0);
8586  for (x = *start; x < req->headers; x++) {
8587  const char *header = REQ_OFFSET_TO_STR(req, header[x]);
8588  int smatch = 0, match = !strncasecmp(header, name, len);
8589  if (slen) {
8590  smatch = !strncasecmp(header, sname, slen);
8591  }
8592  if (match || smatch) {
8593  /* skip name */
8594  const char *r = header + (match ? len : slen );
8595  /* HCOLON has optional SP/HTAB; skip past those */
8596  while (*r == ' ' || *r == '\t') {
8597  ++r;
8598  }
8599  if (*r == ':') {
8600  *start = x+1;
8601  return ast_skip_blanks(r+1);
8602  }
8603  }
8604  }
8605 
8606  /* Don't return NULL, so sip_get_header is always a valid pointer */
8607  return "";
8608 }
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:2312
static const char * find_alias(const char *name, const char *_default)
Find compressed SIP alias.
Definition: chan_sip.c:8547
static const char name[]
Definition: format_mp3.c:68
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
int headers
Definition: sip.h:831

References ast_skip_blanks(), find_alias(), sip_request::headers, len(), match(), name, 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(), reply_digest(), and sip_get_header().

◆ __init_sip_content_buf()

static void __init_sip_content_buf ( void  )
static

Definition at line 8620 of file chan_sip.c.

8624 {

◆ __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 1080 of file chan_sip.c.

1164 { \

◆ __init_ts_temp_pvt()

static void __init_ts_temp_pvt ( void  )
static

A per-thread temporary pvt structure.

Definition at line 1077 of file chan_sip.c.

1164 { \

◆ __reg_module()

static void __reg_module ( void  )
static

Definition at line 35946 of file chan_sip.c.

◆ __sched_check_pendings()

static int __sched_check_pendings ( const void *  data)
static

Definition at line 23799 of file chan_sip.c.

23800 {
23801  struct sip_pvt *pvt = (void *) data;
23802  struct ast_channel *owner;
23803 
23804  owner = sip_pvt_lock_full(pvt);
23805  check_pendings(pvt);
23806  if (owner) {
23807  ast_channel_unlock(owner);
23808  ast_channel_unref(owner);
23809  }
23810  sip_pvt_unlock(pvt);
23811 
23812  dialog_unref(pvt, "Check pending actions action");
23813  return 0;
23814 }
static void check_pendings(struct sip_pvt *p)
Check pending actions on SIP call.
Definition: chan_sip.c:23749
static struct ast_channel * sip_pvt_lock_full(struct sip_pvt *pvt)
Definition: chan_sip.c:9411
#define ast_channel_unref(c)
Decrease channel reference count.
Definition: channel.h:2958
#define ast_channel_unlock(chan)
Definition: channel.h:2923
Main Channel structure associated with a channel.

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

Referenced by sched_check_pendings().

◆ __set_address_from_contact()

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

Definition at line 16904 of file chan_sip.c.

16905 {
16906  char *hostport, *transport;
16907  char contact_buf[256];
16908  char *contact;
16909 
16910  /* Work on a copy */
16911  ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf));
16912  contact = contact_buf;
16913 
16914  /*
16915  * We have only the part in <brackets> here so we just need to parse a SIP URI.
16916  *
16917  * Note: The outbound proxy could be using UDP between the proxy and Asterisk.
16918  * We still need to be able to send to the remote agent through the proxy.
16919  */
16920 
16921  if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &hostport,
16922  &transport)) {
16923  ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact);
16924  }
16925 
16926  /* XXX This could block for a long time XXX */
16927  /* We should only do this if it's a name, not an IP */
16928  /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records
16929  to find transport, port address and hostname. If there's a port number, we have to
16930  assume that the hostport part is a host name and only look for an A/AAAA record in DNS.
16931  */
16932 
16933  /* If we took in an invalid URI, hostport may not have been initialized */
16934  /* ast_sockaddr_resolve requires an initialized hostport string. */
16935  if (ast_strlen_zero(hostport)) {
16936  ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire hostport\n");
16937  return -1;
16938  }
16939 
16940  if (ast_sockaddr_resolve_first_transport(addr, hostport, 0, get_transport_str2enum(transport))) {
16941  ast_log(LOG_WARNING, "Invalid host name in Contact: (can't "
16942  "resolve in DNS) : '%s'\n", hostport);
16943  return -1;
16944  }
16945 
16946  /* set port */
16947  if (!ast_sockaddr_port(addr)) {
16948  ast_sockaddr_set_port(addr,
16949  (get_transport_str2enum(transport) ==
16951  !strncasecmp(fullcontact, "sips", 4)) ?
16953  }
16954 
16955  return 0;
16956 }
#define ast_log
Definition: astobj2.c:42
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:3668
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:16892
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:34497
#define LOG_WARNING
#define ast_sockaddr_port(addr)
Get the port number of a socket address.
Definition: netsock2.h:517
@ AST_TRANSPORT_TLS
Definition: netsock2.h:62
#define ast_sockaddr_set_port(addr, port)
Sets the port number of a socket address.
Definition: netsock2.h:532
#define STANDARD_SIP_PORT
Standard SIP unsecure port for UDP and TCP from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:169
#define STANDARD_TLS_PORT
Standard SIP TLS port from RFC 3261. DO NOT CHANGE THIS.
Definition: sip.h:171
void ast_copy_string(char *dst, const char *src, size_t size)
Size-limited null-terminating string copy.
Definition: strings.h:406

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(), parse_register_contact(), sip_poke_peer(), and sip_request_call().

◆ __shutdown_mwi_subscription()

static int __shutdown_mwi_subscription ( const void *  data)
static

Definition at line 14947 of file chan_sip.c.

14948 {
14949  struct sip_subscription_mwi *mwi = (void *) data;
14950 
14952  ao2_t_ref(mwi, -1, "Stop scheduled mwi resub"));
14953 
14954  if (mwi->dnsmgr) {
14955  ast_dnsmgr_release(mwi->dnsmgr);
14956  mwi->dnsmgr = NULL;
14957  ao2_t_ref(mwi, -1, "dnsmgr release");
14958  }
14959 
14960  ao2_t_ref(mwi, -1, "Shutdown MWI subscription action");
14961  return 0;
14962 }
Definition of an MWI subscription to another server.
Definition: sip.h:1453
struct ast_dnsmgr_entry * dnsmgr
Definition: sip.h:1466

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().

◆ __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 4581 of file chan_sip.c.

4582 {
4583  struct sip_pkt *cur, *prev = NULL;
4584  const char *msg = "Not Found"; /* used only for debugging */
4585  int res = FALSE;
4586 
4587  /* If we have an outbound proxy for this dialog, then delete it now since
4588  the rest of the requests in this dialog needs to follow the routing.
4589  If obforcing is set, we will keep the outbound proxy during the whole
4590  dialog, regardless of what the SIP rfc says
4591  */
4592  if (p->outboundproxy && !p->outboundproxy->force) {
4593  ref_proxy(p, NULL);
4594  }
4595 
4596  for (cur = p->packets; cur; prev = cur, cur = cur->next) {
4597  if (cur->seqno != seqno || cur->is_resp != resp) {
4598  continue;
4599  }
4600  if (cur->is_resp || cur->method == sipmethod) {
4601  res = TRUE;
4602  msg = "Found";
4603  if (!resp && (seqno == p->pendinginvite)) {
4604  ast_debug(1, "Acked pending invite %u\n", p->pendinginvite);
4605  p->pendinginvite = 0;
4606  }
4607  if (cur->retransid > -1) {
4608  if (sipdebug)
4609  ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid);
4610  }
4611 
4612  /* Unlink and destroy the packet object. */
4613  UNLINK(cur, p->packets, prev);
4614  stop_retrans_pkt(cur);
4615  ao2_t_ref(cur, -1, "Packet retransmission list");
4616  break;
4617  }
4618  }
4619  ast_debug(1, "Stopping retransmission on '%s' of %s %u: Match %s\n",
4620  p->callid, resp ? "Response" : "Request", seqno, msg);
4621  return res;
4622 }
#define TRUE
Definition: app_minivm.c:524
#define FALSE
Definition: app_minivm.c:527
#define UNLINK(element, head, prev)
Definition: chan_sip.c:1164
static void stop_retrans_pkt(struct sip_pkt *pkt)
Definition: chan_sip.c:4261
static enum sip_debug_e sipdebug
Definition: chan_sip.c:923
static void ref_proxy(struct sip_pvt *pvt, struct sip_proxy *proxy)
Definition: chan_sip.c:3303
sipmethod
SIP Request methods known by Asterisk.
Definition: sip.h:609
sip packet - raw format for outbound packets that are sent or scheduled for transmission Packets are ...
Definition: sip.h:1230
char is_resp
Definition: sip.h:1235
int retransid
Definition: sip.h:1239
uint32_t seqno
Definition: sip.h:1234
int method
Definition: sip.h:1233
struct sip_pkt * next
Definition: sip.h:1231
int force
Definition: sip.h:724
struct sip_pkt * packets
Definition: sip.h:1176
struct sip_proxy * outboundproxy
Definition: sip.h:1111
uint32_t pendinginvite
Definition: sip.h:1146

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().

◆ __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 8953 of file chan_sip.c.

8956 {
8957  struct sip_pvt *p;
8958 
8959  p = __ao2_alloc(sizeof(*p), sip_pvt_dtor,
8960  AO2_ALLOC_OPT_LOCK_MUTEX, "allocate a dialog(pvt) struct",
8961  file, line, func);
8962  if (!p) {
8963  return NULL;
8964  }
8965 
8966  if (ast_string_field_init(p, 512)) {
8967  ao2_t_ref(p, -1, "failed to string_field_init, drop p");
8968  return NULL;
8969  }
8970 
8971  if (!(p->cc_params = ast_cc_config_params_init())) {
8972  ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p");
8973  return NULL;
8974  }
8975 
8976  if (logger_callid) {
8978  }
8979 
8985 
8986  if (!p->caps|| !p->jointcaps || !p->peercaps || !p->redircaps || !p->prefcaps) {
8987  ao2_cleanup(p->caps);
8988  ao2_cleanup(p->jointcaps);
8989  ao2_cleanup(p->peercaps);
8990  ao2_cleanup(p->redircaps);
8991  ao2_cleanup(p->prefcaps);
8992  ao2_t_ref(p, -1, "Yuck, couldn't allocate format capabilities. Get rid o' p");
8993  return NULL;
8994  }
8995 
8996 
8997  /* If this dialog is created as a result of a request or response, lets store
8998  * some information about it in the dialog. */
8999  if (req) {
9000  struct sip_via *via;
9001  const char *cseq = sip_get_header(req, "Cseq");
9002  uint32_t seqno;
9003 
9004  /* get branch parameter from initial Request that started this dialog */
9005  via = parse_via(sip_get_header(req, "Via"));
9006  if (via) {
9007  /* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise
9008  * it is not useful to us to have it */
9009  if (!ast_strlen_zero(via->branch) && !strncasecmp(via->branch, "z9hG4bK", 7)) {
9010  ast_string_field_set(p, initviabranch, via->branch);
9011  ast_string_field_set(p, initviasentby, via->sent_by);
9012  }
9013  free_via(via);
9014  }
9015 
9016  /* Store initial incoming cseq. An error in sscanf here is ignored. There is no approperiate
9017  * except not storing the number. CSeq validation must take place before dialog creation in find_call */
9018  if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) {
9019  p->init_icseq = seqno;
9020  }
9021  /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */
9023  } else {
9025  }
9026 
9027  p->socket.fd = -1;
9028  p->method = intended_method;
9029  p->initid = -1;
9030  p->waitid = -1;
9031  p->reinviteid = -1;
9032  p->autokillid = -1;
9033  p->request_queue_sched_id = -1;
9035  p->t38id = -1;
9036  p->subscribed = NONE;
9037  p->stateid = -1;
9038  p->sessionversion_remote = -1;
9039  p->session_modify = TRUE;
9040  p->stimer = NULL;
9041  ast_copy_string(p->zone, default_zone, sizeof(p->zone));
9043 
9044  if (intended_method != SIP_OPTIONS) { /* Peerpoke has it's own system */
9045  p->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */
9046  p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */
9047  }
9048 
9049  if (!addr) {
9050  p->ourip = internip;
9051  } else {
9052  ast_sockaddr_copy(&p->sa, addr);
9053  ast_sip_ouraddrfor(&p->sa, &p->ourip, p);
9054  }
9055 
9056  /* Copy global flags to this PVT at setup. */
9060 
9062 
9063  p->branch = ast_random();
9064  make_our_tag(p);
9065  p->ocseq = INITIAL_CSEQ;
9066  p->allowed_methods = UINT_MAX;
9067 
9068  if (sip_methods[intended_method].need_rtp) {
9071  }
9072 
9073  if (useglobal_nat && addr) {
9074  /* Setup NAT structure according to global settings if we have an address */
9075  ast_sockaddr_copy(&p->recv, addr);
9076  check_via(p, req);
9077  do_setnat(p);
9078  }
9079 
9080  if (p->method != SIP_REGISTER) {
9081  ast_string_field_set(p, fromdomain, default_fromdomain);
9083  }
9084  build_via(p);
9085  if (!callid)
9086  build_callid_pvt(p);
9087  else
9088  ast_string_field_set(p, callid, callid);
9089  /* Assign default music on hold class */
9094  if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) ||
9095  (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) {
9097  }
9101 
9104 
9105  /* Add to active dialog list */
9106 
9107  ao2_t_link(dialogs, p, "link pvt into dialogs table");
9108 
9109  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");
9110  return p;
9111 }
@ AO2_ALLOC_OPT_LOCK_MUTEX
Definition: astobj2.h:363
#define ao2_cleanup(obj)
Definition: astobj2.h:1934
#define ao2_t_link(container, obj, tag)
Definition: astobj2.h:1534
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:768
#define ast_cc_config_params_init()
Allocate and initialize an ast_cc_config_params structure.
Definition: ccss.h:135
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:120
static char mohinterpret[MAX_MUSICCLASS]
Definition: chan_alsa.c:123
static char mohsuggest[MAX_MUSICCLASS]
Definition: chan_iax2.c:427
static char parkinglot[AST_MAX_CONTEXT]
Definition: chan_mgcp.c:166
static void sip_pvt_callid_set(struct sip_pvt *pvt, ast_callid callid)
Definition: chan_sip.c:8944
static void make_our_tag(struct sip_pvt *pvt)
Make our SIP dialog tag.
Definition: chan_sip.c:8919
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:3876
static char default_mohsuggest[MAX_MUSICCLASS]
Definition: chan_sip.c:806
static unsigned int global_autoframing
Definition: chan_sip.c:856
static char default_engine[256]
Definition: chan_sip.c:809
static unsigned int recordhistory
Definition: chan_sip.c:847
static char default_parkinglot[AST_MAX_CONTEXT]
Definition: chan_sip.c:808
static int global_t1
Definition: chan_sip.c:853
static char default_zone[MAX_TONEZONE_COUNTRY]
Definition: chan_sip.c:811
static void sip_pvt_dtor(void *vdoomed)
ao2 destructor for SIP dialog structure
Definition: chan_sip.c:6686
static int default_fromdomainport
Definition: chan_sip.c:800
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:19176
static char default_mohinterpret[MAX_MUSICCLASS]
Definition: chan_sip.c:805
static int global_timer_b
Definition: chan_sip.c:855
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:1121
static void set_socket_transport(struct sip_socket *socket, int transport)
Definition: chan_sip.c:16641
static int default_maxcallbitrate
Definition: chan_sip.c:810
static void build_via(struct sip_pvt *p)
Build a Via header for a request.
Definition: chan_sip.c:3857
static void do_setnat(struct sip_pvt *p)
Set nat mode on the various data sockets.
Definition: chan_sip.c:5873
static struct ast_flags global_flags[3]
Definition: chan_sip.c:891
static char default_fromdomain[AST_MAX_EXTENSION]
Definition: chan_sip.c:799
static void build_callid_pvt(struct sip_pvt *pvt)
Build SIP Call-ID value for a non-REGISTER transaction.
Definition: chan_sip.c:8842
@ AST_MEDIA_TYPE_UNKNOWN
Definition: codec.h:31
@ AST_FORMAT_CAP_FLAG_DEFAULT
Definition: format_cap.h:38
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
#define ast_format_cap_alloc(flags)
Allocate a new ast_format_cap structure.
Definition: format_cap.h:49
#define AST_LIST_HEAD_INIT_NOLOCK(head)
Initializes a list head structure.
Definition: linkedlists.h:681
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:167
@ AST_TRANSPORT_UDP
Definition: netsock2.h:60
#define AST_RTP_DTMF
Definition: rtp_engine.h:266
#define SIP_DTMF_RFC2833
Definition: sip.h:271
#define SIP_PAGE3_FLAGS_TO_COPY
Definition: sip.h:393
#define SIP_DTMF
Definition: sip.h:270
@ NONE
Definition: sip.h:471
#define SIP_DTMF_AUTO
Definition: sip.h:274
#define SIP_PAGE2_FLAGS_TO_COPY
Definition: sip.h:372
#define SIP_FLAGS_TO_COPY
Flags to copy from peer/user to dialog.
Definition: sip.h:308
@ SIP_OPTIONS
Definition: sip.h:613
#define INITIAL_CSEQ
Definition: sip.h:110
#define ast_string_field_init(x, size)
Initialize a field pool and fields.
Definition: stringfields.h:359
unsigned int allowed_methods
Definition: sip.h:1195
unsigned short session_modify
Definition: sip.h:1086
char zone[MAX_TONEZONE_COUNTRY]
Definition: sip.h:1115
unsigned short do_history
Definition: sip.h:1077
int maxforwards
Definition: sip.h:1064
struct ast_format_cap * peercaps
Definition: sip.h:1100
uint32_t init_icseq
Definition: sip.h:1068
struct sip_pvt::@165 offered_media
struct ast_flags flags[3]
Definition: sip.h:1074
int fromdomainport
Definition: sip.h:1219
enum transfermodes allowtransfer
Definition: sip.h:1136
int noncodeccapability
Definition: sip.h:1103
struct ast_format_cap * redircaps
Definition: sip.h:1101
int provisional_keepalive_sched_id
Definition: sip.h:1108
int timer_b
Definition: sip.h:1095
int64_t sessionversion_remote
Definition: sip.h:1122
int reinviteid
Definition: sip.h:1156
struct ast_format_cap * prefcaps
Definition: sip.h:1102
struct ast_sockaddr recv
Definition: sip.h:1134
int waitid
Definition: sip.h:1155
struct ast_format_cap * caps
Definition: sip.h:1098
int stateid
Definition: sip.h:1161
uint32_t ocseq
Definition: sip.h:1066
struct ast_rtp_instance * rtp
Definition: sip.h:1173
struct ast_format_cap * jointcaps
Definition: sip.h:1099
int request_queue_sched_id
Definition: sip.h:1107
unsigned short autoframing
Definition: sip.h:1088
int maxcallbitrate
Definition: sip.h:1105
struct ast_sockaddr sa
Definition: sip.h:1124
long branch
Definition: sip.h:1120
int t38id
Definition: sip.h:1158
enum subscriptiontype subscribed
Definition: sip.h:1160
struct sip_socket socket
Definition: sip.h:1065
struct ast_cc_config_params * cc_params
Definition: sip.h:1217
int timer_t1
Definition: sip.h:1094
struct ast_sockaddr ourip
Definition: sip.h:1135
int autokillid
Definition: sip.h:1157
struct sip_st_dlg * stimer
Definition: sip.h:1183
struct sip_pvt::request_queue request_queue
int initid
Definition: sip.h:1154
struct sip_socket socket
Definition: sip.h:845
enum transfermodes allowtransfer
Definition: sip.h:773
struct ast_format_cap * caps
Global list of addresses dynamic peers are not allowed to use.
Definition: sip.h:784
char default_context[AST_MAX_CONTEXT]
Definition: sip.h:779
int default_max_forwards
Definition: sip.h:786
enum ast_transport type
Definition: sip.h:797
int fd
Definition: sip.h:798
#define ast_test_flag(p, flag)
Definition: utils.h:63
long int ast_random(void)
Definition: main/utils.c:2210
#define ast_copy_flags(dest, src, flagz)
Definition: utils.h:84

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, dialogs, sip_pvt::do_history, do_setnat(), sip_socket::fd, make_ari_stubs::file, sip_pvt::flags, free_via(), sip_pvt::fromdomainport, global_autoframing, global_flags, 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.

◆ __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 4380 of file chan_sip.c.

4381 {
4382  struct sip_pvt *p = (struct sip_pvt *)data;
4383  struct ast_channel *owner;
4384 
4385  /* If this is a subscription, tell the phone that we got a timeout */
4387  struct state_notify_data data = { 0, };
4388 
4390 
4391  transmit_state_notify(p, &data, 1, TRUE); /* Send last notification */
4392  p->subscribed = NONE;
4393  append_history(p, "Subscribestatus", "timeout");
4394  ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>");
4395  return 10000; /* Reschedule this destruction so that we know that it's gone */
4396  }
4397 
4398  /* If there are packets still waiting for delivery, delay the destruction */
4399  if (p->packets) {
4400  if (!p->needdestroy) {
4401  char method_str[31];
4402 
4403  ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>");
4404  append_history(p, "ReliableXmit", "timeout");
4405  if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) {
4406  if (p->ongoing_reinvite || method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) {
4407  pvt_set_needdestroy(p, "autodestruct");
4408  }
4409  }
4410  return 10000;
4411  } else {
4412  /* They've had their chance to respond. Time to bail */
4413  __sip_pretend_ack(p);
4414  }
4415  }
4416 
4417  /*
4418  * Lock both the pvt and the channel safely so that we can queue up a frame.
4419  */
4420  owner = sip_pvt_lock_full(p);
4421  if (owner) {
4423  "Autodestruct on dialog '%s' with owner %s in place (Method: %s). Rescheduling destruction for 10000 ms\n",
4424  p->callid, ast_channel_name(owner), sip_methods[p->method].text);
4426  ast_channel_unlock(owner);
4427  ast_channel_unref(owner);
4428  sip_pvt_unlock(p);
4429  return 10000;
4430  }
4431 
4432  /* Reset schedule ID */
4433  p->autokillid = -1;
4434 
4435  if (p->refer && !p->alreadygone) {
4436  ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid);
4437  stop_media_flows(p);
4439  append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid);
4441  sip_pvt_unlock(p);
4442  } else {
4443  append_history(p, "AutoDestroy", "%s", p->callid);
4444  ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid);
4445  sip_pvt_unlock(p);
4446  dialog_unlink_all(p); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */
4447  }
4448 
4449  dialog_unref(p, "autokillid complete");
4450 
4451  return 0;
4452 }
#define AST_CAUSE_PROTOCOL_ERROR
Definition: causes.h:145
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:15489
#define append_history(p, event, fmt, args...)
Append to SIP dialog history.
Definition: chan_sip.c:2413
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:16576
void sip_scheddestroy(struct sip_pvt *p, int ms)
Schedule destruction of SIP dialog.
Definition: chan_sip.c:4560
static void pvt_set_needdestroy(struct sip_pvt *pvt, const char *reason)
Definition: chan_sip.c:3439
static void stop_media_flows(struct sip_pvt *p)
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition: chan_sip.c:25168
void __sip_pretend_ack(struct sip_pvt *p)
Pretend to ack all packets called with p locked.
Definition: chan_sip.c:4626
static int method_match(enum sipmethod id, const char *name)
returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'....
Definition: chan_sip.c:3594
const char * ast_channel_name(const struct ast_channel *chan)
int ast_queue_hangup_with_cause(struct ast_channel *chan, int cause)
Queue a hangup frame with hangupcause set.
Definition: channel.c:1160
@ AST_EXTENSION_DEACTIVATED
Definition: pbx.h:63
#define DEFAULT_TRANS_TIMEOUT
Definition: sip.h:100
@ CALL_COMPLETION
Definition: sip.h:477
@ MWI_NOTIFICATION
Definition: sip.h:476
@ XMIT_RELIABLE
Definition: sip.h:457
@ SIP_CANCEL
Definition: sip.h:624
char lastmsg[256]
Definition: sip.h:1144
unsigned short alreadygone
Definition: sip.h:1078
struct sip_refer * refer
Definition: sip.h:1159
unsigned short needdestroy
Definition: sip.h:1079
unsigned int ongoing_reinvite
Definition: sip.h:1143

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().

◆ __sip_cancel_destroy()

static int __sip_cancel_destroy ( const void *  data)
static

Definition at line 4464 of file chan_sip.c.

4465 {
4466  struct sip_pvt *pvt = (void *) data;
4467 
4468  sip_pvt_lock(pvt);
4469  do_cancel_destroy(pvt);
4470  sip_pvt_unlock(pvt);
4471  dialog_unref(pvt, "Cancel destroy action");
4472  return 0;
4473 }
static void do_cancel_destroy(struct sip_pvt *pvt)
Definition: chan_sip.c:4454

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

Referenced by sip_cancel_destroy().

◆ __sip_do_register()

static int __sip_do_register ( struct sip_registry r)
static

Register with SIP proxy.

Returns
see __sip_xmit

Definition at line 15921 of file chan_sip.c.

15922 {
15923  int res;
15924 
15926  return res;
15927 }
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:16118

References NULL, SIP_REGISTER, and transmit_register().

Referenced by sip_reregister().

◆ __sip_pretend_ack()

void __sip_pretend_ack ( struct sip_pvt p)

Pretend to ack all packets called with p locked.

Definition at line 4626 of file chan_sip.c.

4627 {
4628  struct sip_pkt *cur = NULL;
4629 
4630  while (p->packets) {
4631  int method;
4632  if (cur == p->packets) {
4633  ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text);
4634  return;
4635  }
4636  cur = p->packets;
4637  method = (cur->method) ? cur->method : find_sip_method(ast_str_buffer(cur->data));
4638  __sip_ack(p, cur->seqno, cur->is_resp, method);
4639  }
4640 }
static int find_sip_method(const char *msg)
find_sip_method: Find SIP method from header
Definition: chan_sip.c:3604
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:4581
const char * method
Definition: res_pjsip.c:1130
char * ast_str_buffer(const struct ast_str *buf)
Returns the string buffer within the ast_str buf.
Definition: strings.h:739
struct ast_str * data
Definition: sip.h:1245

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().

◆ __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 4270 of file chan_sip.c.

4287 {
4288  struct sip_pkt *pkt = NULL;
4289  int siptimer_a = DEFAULT_RETRANS;
4290  int xmitres = 0;
4291  unsigned respid;
4292 
4293  if (sipmethod == SIP_INVITE) {
4294  /* Note this is a pending invite */
4295  p->pendinginvite = seqno;
4296  }
4297 
4299  if (!pkt) {
4300  return AST_FAILURE;
4301  }
4302  /* copy data, add a terminator and save length */
4304  if (!pkt->data) {
4305  ao2_t_ref(pkt, -1, "Failed to initialize");
4306  return AST_FAILURE;
4307  }
4308  ast_str_set(&pkt->data, 0, "%s%s", ast_str_buffer(data), "\0");
4309  /* copy other parameters from the caller */
4310  pkt->method = sipmethod;
4311  pkt->seqno = seqno;
4312  pkt->is_resp = resp;
4313  pkt->is_fatal = fatal;
4314  pkt->owner = dialog_ref(p, "__sip_reliable_xmit: setting pkt->owner");
4315 
4316  /* The retransmission list owns a pkt ref */
4317  pkt->next = p->packets;
4318  p->packets = pkt; /* Add it to the queue */
4319 
4320  if (resp) {
4321  /* Parse out the response code */
4322  if (sscanf(ast_str_buffer(pkt->data), "SIP/2.0 %30u", &respid) == 1) {
4323  pkt->response_code = respid;
4324  }
4325  }
4326  pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */
4327  if (pkt->timer_t1) {
4328  siptimer_a = pkt->timer_t1;
4329  }
4330 
4331  pkt->time_sent = ast_tvnow(); /* time packet was sent */
4332  pkt->retrans_stop_time = 64 * (pkt->timer_t1 ? pkt->timer_t1 : DEFAULT_TIMER_T1); /* time in ms after pkt->time_sent to stop retransmission */
4333 
4334  if (!(p->socket.type & AST_TRANSPORT_UDP)) {
4335  /* TCP does not need retransmits as that's built in, but with
4336  * retrans_stop set, we must give it the full timer_H treatment */
4337  pkt->retrans_stop = 1;
4338  siptimer_a = pkt->retrans_stop_time;
4339  }
4340 
4341  /* Schedule retransmission */
4342  ao2_t_ref(pkt, +1, "Schedule packet retransmission");
4343  pkt->retransid = ast_sched_add_variable(sched, siptimer_a, retrans_pkt, pkt, 1);
4344  if (pkt->retransid < 0) {
4345  ao2_t_ref(pkt, -1, "Failed to schedule packet retransmission");
4346  }
4347 
4348  if (sipdebug) {
4349  ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid);
4350  }
4351 
4352  xmitres = __sip_xmit(pkt->owner, pkt->data); /* Send packet */
4353 
4354  if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */
4355  append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)");
4356  ast_log(LOG_ERROR, "Serious Network Trouble; __sip_xmit returns error for pkt data\n");
4357 
4358  /* Unlink and destroy the packet object. */
4359  p->packets = pkt->next;
4360  stop_retrans_pkt(pkt);
4361  ao2_t_ref(pkt, -1, "Packet retransmission list");
4362  return AST_FAILURE;
4363  } else {
4364  /* This is odd, but since the retrans timer starts at 500ms and the do_monitor thread
4365  * only wakes up every 1000ms by default, we have to poke the thread here to make
4366  * sure it successfully detects this must be retransmitted in less time than
4367  * it usually sleeps for. Otherwise it might not retransmit this packet for 1000ms. */
4369  pthread_kill(monitor_thread, SIGURG);
4370  }
4371  return AST_SUCCESS;
4372  }
4373 }
@ AO2_ALLOC_OPT_LOCK_NOLOCK
Definition: astobj2.h:367
#define ao2_alloc_options(data_size, destructor_fn, options)
Definition: astobj2.h:404
#define DEFAULT_RETRANS
Definition: chan_mgcp.c:129
static void sip_pkt_dtor(void *vdoomed)
Definition: chan_sip.c:4270
static int __sip_xmit(struct sip_pvt *p, struct ast_str *data)
Definition: chan_sip.c:3811
static int retrans_pkt(const void *data)
Retransmit SIP message if no answer.
Definition: chan_sip.c:4051
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:910
#define LOG_ERROR
#define AST_PTHREADT_NULL
Definition: lock.h:66
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:526
#define DEFAULT_TIMER_T1
Definition: sip.h:96
#define XMIT_ERROR
Definition: sip.h:58
@ AST_SUCCESS
Definition: sip.h:418
@ AST_FAILURE
Definition: sip.h:419
#define ast_str_create(init_len)
Create a malloc'ed dynamic length string.
Definition: strings.h:640
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:1091
size_t ast_str_strlen(const struct ast_str *buf)
Returns the current length of the string stored within buf.
Definition: strings.h:711
int64_t retrans_stop_time
Definition: sip.h:1243
int retrans_stop
Definition: sip.h:1244
struct timeval time_sent
Definition: sip.h:1242
char is_fatal
Definition: sip.h:1236
struct sip_pvt * owner
Definition: sip.h:1238
int response_code
Definition: sip.h:1237
int timer_t1
Definition: sip.h:1241
struct timeval ast_tvnow(void)
Returns current timeval. Meant to replace calls to gettimeofday().
Definition: time.h:157

References ast_free, sip_pkt::data, dialog_unref, and sip_pkt::owner.

Referenced by send_request(), and send_response().

◆ __sip_scheddestroy()

static int __sip_scheddestroy ( const void *  data)
static

Definition at line 4495 of file chan_sip.c.

4496 {
4497  struct sip_scheddestroy_data *sched_data = (void *) data;
4498  struct sip_pvt *pvt = sched_data->pvt;
4499  int ms = sched_data->ms;
4500 
4501  ast_free(sched_data);
4502 
4503  sip_pvt_lock(pvt);
4504  do_cancel_destroy(pvt);
4505 
4506  if (pvt->do_history) {
4507  append_history(pvt, "SchedDestroy", "%d ms", ms);
4508  }
4509 
4510  dialog_ref(pvt, "Schedule autokillid");
4512  if (pvt->autokillid < 0) {
4513  /* Uh Oh. Expect bad behavior. */
4514  dialog_unref(pvt, "Failed to schedule autokillid");
4515  }
4516 
4517  if (pvt->stimer) {
4518  stop_session_timer(pvt);
4519  }
4520  sip_pvt_unlock(pvt);
4521  dialog_unref(pvt, "Destroy action");
4522  return 0;
4523 }
#define ast_free(a)
Definition: astmm.h:180
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-...
Definition: chan_sip.c:4380
static void stop_session_timer(struct sip_pvt *p)
Session-Timers: Stop session timer.
Definition: chan_sip.c:30235
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.
Definition: sched.c:567
struct sip_pvt * pvt
Definition: chan_sip.c:4490

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().

◆ __sip_semi_ack()

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)

Definition at line 4643 of file chan_sip.c.

4644 {
4645  struct sip_pkt *cur;
4646  int res = FALSE;
4647 
4648  for (cur = p->packets; cur; cur = cur->next) {
4649  if (cur->seqno == seqno && cur->is_resp == resp &&
4650  (cur->is_resp || method_match(sipmethod, ast_str_buffer(cur->data)))) {
4651  /* this is our baby */
4652  if (cur->retransid > -1) {
4653  if (sipdebug)
4654  ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text);
4655  }
4656  stop_retrans_pkt(cur);
4657  res = TRUE;
4658  break;
4659  }
4660  }
4661  ast_debug(1, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %u: %s\n", p->callid, resp ? "Response" : "Request", seqno, res == -1 ? "Not Found" : "Found");
4662  return res;
4663 }

References ast_debug, ast_str_buffer(), sip_pvt::callid, sip_pkt::data, FALSE, sip_pkt::is_resp, method_match(), sip_pkt::next, sip_pvt::packets, sip_pkt::retransid, sip_pkt::seqno, sip_methods, sipdebug, stop_retrans_pkt(), cfsip_methods::text, and TRUE.

Referenced by handle_response(), and sip_hangup().

◆ __sip_subscribe_mwi_do()

static int __sip_subscribe_mwi_do ( struct sip_subscription_mwi mwi)
static

Actually setup an MWI subscription or resubscribe.

Definition at line 15087 of file chan_sip.c.

15088 {
15089  /* If we have no DNS manager let's do a lookup */
15090  if (!mwi->dnsmgr) {
15091  char transport[MAXHOSTNAMELEN];
15092  snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport));
15093 
15094  mwi->us.ss.ss_family = get_address_family_filter(mwi->transport); /* Filter address family */
15095  ao2_t_ref(mwi, +1, "dnsmgr reference to mwi");
15096  ast_dnsmgr_lookup_cb(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_mwi, mwi);
15097  if (!mwi->dnsmgr) {
15098  ao2_t_ref(mwi, -1, "dnsmgr disabled, remove reference");
15099  }
15100  }
15101 
15102  /* If we already have a subscription up simply send a resubscription */
15103  if (mwi->call) {
15104  transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0, NULL);
15105  return 0;
15106  }
15107 
15108  /* Create a dialog that we will use for the subscription */
15109  if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL, 0))) {
15110  return -1;
15111  }
15112 
15113  ref_proxy(mwi->call, obproxy_get(mwi->call, NULL));
15114 
15115  if (!ast_sockaddr_port(&mwi->us) && mwi->portno) {
15116  ast_sockaddr_set_port(&mwi->us, mwi->portno);
15117  }
15118 
15119  /* Setup the destination of our subscription */
15120  if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0)) {
15121  dialog_unlink_all(mwi->call);
15122  mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all");
15123  return 0;
15124  }
15125 
15126  mwi->call->expiry = mwi_expiry;
15127 
15128  if (!mwi->dnsmgr && mwi->portno) {
15129  ast_sockaddr_set_port(&mwi->call->sa, mwi->portno);
15130  ast_sockaddr_set_port(&mwi->call->recv, mwi->portno);
15131  } else {
15132  mwi->portno = ast_sockaddr_port(&mwi->call->sa);
15133  }
15134 
15135  /* Set various other information */
15136  if (!ast_strlen_zero(mwi->authuser)) {
15137  ast_string_field_set(mwi->call, peername, mwi->authuser);
15138  ast_string_field_set(mwi->call, authname, mwi->authuser);
15139  ast_string_field_set(mwi->call, fromuser, mwi->authuser);
15140  } else {
15141  ast_string_field_set(mwi->call, peername, mwi->username);
15142  ast_string_field_set(mwi->call, authname, mwi->username);
15143  ast_string_field_set(mwi->call, fromuser, mwi->username);
15144  }
15145  ast_string_field_set(mwi->call, username, mwi->username);
15146  if (!ast_strlen_zero(mwi->secret)) {
15147  ast_string_field_set(mwi->call, peersecret, mwi->secret);
15148  }
15149  set_socket_transport(&mwi->call->socket, mwi->transport);
15150  ast_sip_ouraddrfor(&mwi->call->sa, &mwi->call->ourip, mwi->call);
15151  build_via(mwi->call);
15152 
15153  /* Change the dialog callid. */
15154  change_callid_pvt(mwi->call, NULL);
15155 
15156  ast_set_flag(&mwi->call->flags[0], SIP_OUTGOING);
15157 
15158  /* Associate the call with us */
15159  mwi->call->mwi = ao2_t_bump(mwi, "Reference mwi from it's call");
15160 
15162 
15163  /* Actually send the packet */
15164  transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2, NULL);
15165 
15166  return 0;
15167 }
#define ao2_t_bump(obj, tag)
Definition: astobj2.h:483
static const char * get_srv_service(enum ast_transport t)
Return service string for srv dns query.
Definition: chan_sip.c:3771
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 TR...
Definition: chan_sip.c:6330
static const char * get_srv_protocol(enum ast_transport t)
Return protocol string for srv dns query.
Definition: chan_sip.c:3753
static int get_address_family_filter(unsigned int transport)
Helper for dns resolution to filter by address family.
Definition: chan_sip.c:29579
static void change_callid_pvt(struct sip_pvt *pvt, const char *callid)
Definition: chan_sip.c:8871
static void on_dns_update_mwi(struct ast_sockaddr *old, struct ast_sockaddr *new, void *data)
Definition: chan_sip.c:15070
static int mwi_expiry
Definition: chan_sip.c:678
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.
Definition: chan_sip.c:14767
static struct sip_proxy * obproxy_get(struct sip_pvt *dialog, struct sip_peer *peer)
Get default outbound proxy or global proxy.
Definition: chan_sip.c:3559
int ast_dnsmgr_lookup_cb(const char *name, struct ast_sockaddr *result, struct ast_dnsmgr_entry **dnsmgr, const char *service, dns_update_func func, void *data)
Allocate and initialize a DNS manager entry, with update callback.
Definition: dnsmgr.c:196
#define MAXHOSTNAMELEN
Definition: network.h:69
#define SIP_OUTGOING
Definition: sip.h:252
@ SIP_SUBSCRIBE
Definition: sip.h:620
struct sockaddr_storage ss
Definition: netsock2.h:98
int expiry
Definition: sip.h:1117
struct sip_subscription_mwi * mwi
Definition: sip.h:1191
int srvlookup
Definition: sip.h:755
const ast_string_field authuser
Definition: sip.h:1460
enum ast_transport transport
Definition: sip.h:1461
const ast_string_field username
Definition: sip.h:1460
struct sip_pvt * call
Definition: sip.h:1465
struct ast_sockaddr us
Definition: sip.h:1467
const ast_string_field secret
Definition: sip.h:1460
</