Implementation of Session Initiation Protocol. More...
#include "asterisk.h"#include <signal.h>#include <sys/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/features.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/monitor.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/event.h"#include "asterisk/cel.h"#include "asterisk/data.h"#include "asterisk/aoc.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 "sip/include/srtp.h"#include "sip/include/sdp_crypto.h"#include "asterisk/ccss.h"#include "asterisk/xml.h"#include "sip/include/dialog.h"#include "sip/include/dialplan_functions.h"Go to the source code of this file.
Data Structures | |
| struct | ast_register_list |
| The register list: Other SIP proxies we register with and receive calls from. More... | |
| struct | ast_subscription_mwi_list |
| The MWI subscription list. More... | |
| struct | cfsip_methods |
| The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type. More... | |
| struct | cfsubscription_types |
Subscription types that we support. We support
| |
| struct | event_state_compositor |
| The Event State Compositors. More... | |
| struct | invstate2stringtable |
| Readable descriptions of device states. More... | |
| struct | match_req_args |
| struct | sip_reasons |
| Diversion header reasons. More... | |
Defines | |
| #define | SIP_PEDANTIC_DECODE(str) |
Variables | |
| static int | authlimit = DEFAULT_AUTHLIMIT |
| static int | authtimeout = DEFAULT_AUTHTIMEOUT |
| static int | can_parse_xml |
| static unsigned int | chan_idx |
| static const char | config [] = "sip.conf" |
| static int | default_expiry = DEFAULT_DEFAULT_EXPIRY |
| static struct ast_jb_conf | default_jbconf |
| Global jitterbuffer configuration - by default, jb is disabled. | |
| 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 struct ast_jb_conf | global_jbconf |
| static int | global_match_auth_username |
| static int | global_max_se |
| static int | global_min_se |
| static int | global_prematuremediafilter |
| static int | global_qualify_gap |
| static int | global_qualify_peers |
| static int | global_qualifyfreq |
| static int | global_reg_timeout |
| static int | global_regattempts_max |
| static int | global_relaxdtmf |
| static int | global_rtpholdtimeout |
| static int | global_rtpkeepalive |
| static int | global_rtptimeout |
| static char | global_sdpowner [AST_MAX_EXTENSION] |
| static char | global_sdpsession [AST_MAX_EXTENSION] |
| static int | global_shrinkcallerid |
| static enum st_mode | global_st_mode |
| static enum st_refresher | global_st_refresher |
| static int | global_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 struct invstate2stringtable | invitestate2string [] |
| Readable descriptions of device states. | |
| static int | max_expiry = DEFAULT_MAX_EXPIRY |
| static int | min_expiry = DEFAULT_MIN_EXPIRY |
| static int | mwi_expiry = DEFAULT_MWI_EXPIRY |
| static const char | notify_config [] = "sip_notify.conf" |
| static unsigned int | recordhistory |
| static struct sip_settings | sip_cfg |
| static struct cfsip_methods | sip_methods [] |
| The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type. | |
| static struct sip_reasons | sip_reason_table [] |
| Diversion header reasons. | |
| static struct cfsubscription_types | subscription_types [] |
Subscription types that we support. We support
| |
| static int | unauth_sessions = 0 |
DefaultSettings | |
| static char | default_callerid [AST_MAX_EXTENSION] |
| static char | default_engine [256] |
| static char | default_fromdomain [AST_MAX_EXTENSION] |
| static int | default_fromdomainport |
| 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 struct ast_codec_pref | default_prefs |
| static unsigned int | default_primary_transport |
| static int | default_qualify |
| static unsigned int | default_transports |
| static char | default_vmexten [AST_MAX_EXTENSION] |
Object counters @{ | |
| |
| #define | append_history(p, event, fmt, args...) append_history_full(p, "%-15s " fmt, event, ## args) |
| Append to SIP dialog history. | |
| #define | CHECK_AUTH_BUF_INITLEN 256 |
| #define | check_request_transport(peer, tmpl) |
| generic function for determining if a correct transport is being used to contact a peer | |
| #define | CONTAINER_UNLINK(container, obj, tag) |
| Unlink the given object from the container and return TRUE if it was in the container. | |
| #define | DATA_EXPORT_SIP_PEER(MEMBER) |
| #define | FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n" |
| #define | FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" |
| #define | FORMAT "%-15.15s %-11.11s %-8.8s %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf %-10.10u%-1.1s %-10.10u (%5.2f%%) %-6.4lf\n" |
| #define | FORMAT "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" |
| #define | FORMAT "%-40.40s %-20.20s %-16.16s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
| #define | FORMAT "%-47.47s %-9.9s %-6.6s\n" |
| #define | FORMAT "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n" |
| #define | FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" |
| #define | FORMAT2 "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" |
| #define | FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-10s %s\n" |
| #define | FORMAT2 "%-47.47s %9.9s %6.6s\n" |
| #define | FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
| #define | FORMAT3 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n" |
| #define | FORMAT4 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n" |
| #define | sip_pvt_lock(x) ao2_lock(x) |
| #define | sip_pvt_trylock(x) ao2_trylock(x) |
| #define | sip_pvt_unlock(x) ao2_unlock(x) |
| #define | UNLINK(element, head, prev) |
| enum | match_req_res { SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, SIP_REQ_LOOP_DETECTED } |
| enum | peer_unlink_flag_t { SIP_PEERS_MARKED, SIP_PEERS_ALL } |
| static struct _map_x_s | allowoverlapstr [] |
| static int | apeerobjs = 0 |
| static char * | app_dtmfmode = "SIPDtmfMode" |
| static char * | app_sipaddheader = "SIPAddHeader" |
| static char * | app_sipremoveheader = "SIPRemoveHeader" |
| static struct sip_auth_container * | authl = NULL |
| Authentication container for realm authentication. | |
| struct ast_sockaddr | bindaddr |
| static struct epa_static_data | cc_epa_static_data |
| static struct ast_custom_function | checksipdomain_function |
| static struct ast_cli_entry | cli_sip [] |
| SIP Cli commands definition. | |
| static struct ast_sockaddr | debugaddr |
| static const int | DEFAULT_PUBLISH_EXPIRES = 3600 |
| static struct ast_tls_config | default_tls_cfg |
| Default TLS connection configuration. | |
| static struct ao2_container * | dialogs |
| Here we implement the container for dialogs (sip_pvt), defining generic wrapper functions to ease the transition from the current implementation (a single linked list) to a different container. In addition to a reference to the container, we need functions to lock/unlock the container and individual items, and functions to add/remove references to the individual items. | |
| struct ao2_container * | dialogs_to_destroy |
| static struct _map_x_s | dtmfstr [] |
| mapping between dtmf flags and strings | |
| static int | esc_etag_counter |
| static const int | ESC_MAX_BUCKETS = 37 |
| static struct event_state_compositor | event_state_compositors [] |
| The 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: | |
| 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 int | global_t38_maxdatagram |
| static const int | HASH_DIALOG_SIZE = 563 |
| static const int | HASH_PEER_SIZE = 563 |
| static 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. | |
| static struct io_context * | io |
| static struct ast_ha * | localaddr |
| List of local networks We store "localnet" addresses from the config file into an access list, marked as 'DENY', so the call to ast_apply_ha() will return AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local' (i.e. presumably public) addresses. | |
| static struct ast_sockaddr | media_address |
| static pthread_t | monitor_thread = AST_PTHREADT_NULL |
| This is the thread for the monitor which checks for input on the channels which are not currently in use. | |
| static int | network_change_event_sched_id = -1 |
| static struct ast_event_sub * | network_change_event_subscription |
| static struct ast_config * | notify_types = NULL |
| static int | ourport_tcp |
| static int | ourport_tls |
| static struct ao2_container * | peers |
| The peer list: Users, Peers and Friends. | |
| static struct ao2_container * | peers_by_ip |
| static struct ast_data_handler | peers_data_provider |
| static struct _map_x_s | referstatusstrings [] |
| static struct ast_register_list | regl |
| The register list: Other SIP proxies we register with and receive calls from. | |
| static int | regobjs = 0 |
| static struct _map_x_s | regstatestrings [] |
| static int | rpeerobjs = 0 |
| struct sched_context * | sched |
| 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_data_entry | sip_data_providers [] |
| static struct ast_custom_function | sip_header_function |
| struct ao2_container * | sip_monitor_instances |
| 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. | |
| struct ast_channel_tech | sip_tech |
| Definition of this channel for PBX channel registration. | |
| struct ast_channel_tech | sip_tech_info |
| This version of the sip channel tech has no send_digit_begin callback so that the core knows that the channel does not want DTMF BEGIN frames. The struct is initialized just before registering the channel driver, and is for use with channels using SIP INFO DTMF. | |
| static struct ast_tls_config | sip_tls_cfg |
| Working TLS connection configuration. | |
| static struct ast_tcptls_session_args | sip_tls_desc |
| The TCP/TLS server definition. | |
| static struct ast_udptl_protocol | sip_udptl |
| Interface structure with callbacks used to connect to UDPTL module. | |
| static struct ast_custom_function | sipchaninfo_function |
| Structure to declare a dialplan function: SIPCHANINFO. | |
| static enum sip_debug_e | sipdebug |
| static int | sipdebug_text |
| extra debugging for 'text' related events. At the moment this is set together with sip_debug_console. | |
| static struct ast_custom_function | sippeer_function |
| Structure to declare a dialplan function: SIPPEER. | |
| static int | sipsock = -1 |
| Main socket for UDP SIP communication. | |
| static int * | sipsock_read_id |
| static int | speerobjs = 0 |
| static struct _map_x_s | stmodes [] |
| Report Peer status in character string. | |
| static struct _map_x_s | strefreshers [] |
| static struct ast_subscription_mwi_list | submwil |
| The MWI subscription list. | |
| static struct ao2_container * | threadt |
| The table of TCP threads. | |
| static char | used_context [AST_MAX_CONTEXT] |
| static const char * | __get_header (const struct sip_request *req, const char *name, int *start) |
| static int | __set_address_from_contact (const char *fullcontact, struct ast_sockaddr *addr, int tcp) |
| 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. | |
| 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(). | |
| void | __sip_destroy (struct sip_pvt *p, int lockowner, int lockdialoglist) |
| Execute destruction of SIP dialog structure, release memory. | |
| static int | __sip_do_register (struct sip_registry *r) |
| Register with SIP proxy. | |
| void | __sip_pretend_ack (struct sip_pvt *p) |
| Pretend to ack all packets called with p locked. | |
| static int | __sip_reliable_xmit (struct sip_pvt *p, uint32_t seqno, int resp, struct ast_str *data, int fatal, int sipmethod) |
| 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). | |
| static int | __sip_subscribe_mwi_do (struct sip_subscription_mwi *mwi) |
| Actually setup an MWI subscription or resubscribe. | |
| static int | __sip_xmit (struct sip_pvt *p, struct ast_str *data) |
| static int | __transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Base transmit response function. | |
| static char * | _sip_qualify_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Send qualify message to peer from cli or manager. Mostly for debugging. | |
| static char * | _sip_show_peer (int type, int fd, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Show one peer in detail (main function). | |
| static char * | _sip_show_peers (int fd, int *total, struct mansession *s, const struct message *m, int argc, const char *argv[]) |
| Execute sip show peers command. | |
| static void * | _sip_tcp_helper_thread (struct ast_tcptls_session_instance *tcptls_session) |
| SIP TCP thread management function This function reads from the socket, parses the packet into a request. | |
| static void | add_blank (struct sip_request *req) |
| add a blank line if no body | |
| 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, format_t codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_content (struct sip_request *req, const char *line) |
| Add content (not header) to SIP message. | |
| static int | add_digit (struct sip_request *req, char digit, unsigned int duration, int mode) |
| Add DTMF INFO tone to sip message Mode = 0 for application/dtmf-relay (Cisco) 1 for application/dtmf. | |
| static void | add_diversion_header (struct sip_request *req, struct sip_pvt *pvt) |
| Add "Diversion" header to outgoing message. | |
| static int | add_header (struct sip_request *req, const char *var, const char *value) |
| Add header to SIP message. | |
| static int | add_header_max_forwards (struct sip_pvt *dialog, struct sip_request *req) |
| Add 'Max-Forwards' header to SIP message. | |
| static void | add_noncodec_to_sdp (const struct sip_pvt *p, int format, struct ast_str **m_buf, struct ast_str **a_buf, int debug) |
| Add RFC 2833 DTMF offer to SDP. | |
| static void | add_peer_mailboxes (struct sip_peer *peer, const char *value) |
| static void | add_peer_mwi_subs (struct sip_peer *peer) |
| static void | add_realm_authentication (struct sip_auth_container **credentials, const char *configuration, int lineno) |
| static void | add_route (struct sip_request *req, struct sip_route *route) |
| Add route header into request per learned route. | |
| static int | add_rpid (struct sip_request *req, struct sip_pvt *p) |
| Add Remote-Party-ID header to SIP message. | |
| static enum sip_result | add_sdp (struct sip_request *resp, struct sip_pvt *p, int oldsdp, int add_audio, int add_t38) |
| Add Session Description Protocol message. | |
| static int | add_sip_domain (const char *domain, const enum domain_mode mode, const char *context) |
| Add SIP domain to list of domains we are responsible for. | |
| static int | add_supported_header (struct sip_pvt *pvt, struct sip_request *req) |
| Add "Supported" header to sip message. Since some options may be disabled in the config, the sip_pvt must be inspected to determine what is supported for this dialog. | |
| static void | add_tcodec_to_sdp (const struct sip_pvt *p, int codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add text codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_text (struct sip_request *req, const char *text) |
| Add text body to SIP message. | |
| static struct ast_variable * | add_var (const char *buf, struct ast_variable *list) |
| implement the setvar config line | |
| static void | add_vcodec_to_sdp (const struct sip_pvt *p, format_t codec, struct ast_str **m_buf, struct ast_str **a_buf, int debug, int *min_packet_size) |
| Add video codec offer to SDP offer/answer body in INVITE or 200 OK. | |
| static int | add_vidupdate (struct sip_request *req) |
| add XML encoded media control with update | |
| static int | addr_is_multicast (const struct ast_sockaddr *addr) |
| Check if an ip is an multicast IP. addr the address to check. | |
| static const char * | allowoverlap2str (int mode) |
| Convert AllowOverlap setting to printable string. | |
| static void | append_date (struct sip_request *req) |
| Append date to SIP message. | |
| static void | append_history_full (struct sip_pvt *p, const char *fmt,...) |
| Append to SIP dialog history with arg list. | |
| static void | append_history_va (struct sip_pvt *p, const char *fmt, va_list ap) |
| Append to SIP dialog history with arg list. | |
| static int | apply_directmedia_ha (struct sip_pvt *p1, struct sip_pvt *p2, const char *op) |
| AST_DATA_STRUCTURE (sip_peer, DATA_EXPORT_SIP_PEER) | |
| AST_LIST_HEAD_NOLOCK (sip_history_head, sip_history) | |
| AST_LIST_HEAD_STATIC (epa_static_data_list, epa_backend) | |
| static | AST_LIST_HEAD_STATIC (domain_list, domain) |
| AST_MODULE_INFO (ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER,"Session Initiation Protocol (SIP)",.load=load_module,.unload=unload_module,.reload=reload,.load_pri=AST_MODPRI_CHANNEL_DRIVER,.nonoptreq="res_crypto,chan_local",) | |
| AST_MUTEX_DEFINE_STATIC (authl_lock) | |
| Global authentication container protection while adjusting the references. | |
| AST_MUTEX_DEFINE_STATIC (sip_reload_lock) | |
| AST_MUTEX_DEFINE_STATIC (monlock) | |
| Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical. | |
| AST_MUTEX_DEFINE_STATIC (netlock) | |
| static void | ast_quiet_chan (struct ast_channel *chan) |
| Turn off generator data XXX Does this function belong in the SIP channel? | |
| static void | ast_sip_ouraddrfor (const struct ast_sockaddr *them, struct ast_sockaddr *us, struct sip_pvt *p) |
| NAT fix - decide which IP address to use for Asterisk server? | |
| 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. | |
| static int | ast_sockaddr_resolve_first_af (struct ast_sockaddr *addr, const char *name, int flag, int family) |
| Return the first entry from ast_sockaddr_resolve filtered by address family. | |
| 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. | |
| AST_THREADSTORAGE (check_auth_buf) | |
| AST_THREADSTORAGE_CUSTOM (ts_temp_pvt, temp_pvt_init, temp_pvt_cleanup) | |
| A per-thread temporary pvt structure. | |
| static int | attempt_transfer (struct sip_dual *transferer, struct sip_dual *target) |
| Attempt transfer of SIP call This fix for attended transfers on a local PBX. | |
| static void | auth_headers (enum sip_auth_type code, char **header, char **respheader) |
| return the request and response header for a 401 or 407 code | |
| static int | auto_congest (const void *arg) |
| Scheduled congestion on a call. Only called by the scheduler, must return the reference when done. | |
| static void | build_callid_pvt (struct sip_pvt *pvt) |
| Build SIP Call-ID value for a non-REGISTER transaction. | |
| static void | build_callid_registry (struct sip_registry *reg, const struct ast_sockaddr *ourip, const char *fromdomain) |
| Build SIP Call-ID value for a REGISTER transaction. | |
| static void | build_contact (struct sip_pvt *p) |
| Build contact header - the contact header we send out. | |
| static struct sip_peer * | build_peer (const char *name, struct ast_variable *v, struct ast_variable *alt, int realtime, int devstate_only) |
| Build peer from configuration (file or realtime static/dynamic). | |
| static int | build_reply_digest (struct sip_pvt *p, int method, char *digest, int digest_len) |
| Build reply digest. | |
| static void | build_route (struct sip_pvt *p, struct sip_request *req, int backwards, int resp) |
| Build route list from Record-Route header. | |
| static void | build_via (struct sip_pvt *p) |
| Build a Via header for a request. | |
| static int | cb_extensionstate (char *context, char *exten, int state, void *data) |
| Callback for the devicestate notification (SUBSCRIBE) support subsystem. | |
| static void | cb_extensionstate_destroy (int id, void *data) |
| static void | cc_epa_destructor (void *data) |
| 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. | |
| 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 | |
| static void | change_t38_state (struct sip_pvt *p, int state) |
| Change the T38 state on a SIP dialog. | |
| static enum check_auth_result | check_auth (struct sip_pvt *p, struct sip_request *req, const char *username, const char *secret, const char *md5secret, int sipmethod, const char *uri, enum xmittype reliable, int ignore) |
| Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set). | |
| static enum check_auth_result | check_peer_ok (struct sip_pvt *p, char *of, struct sip_request *req, int sipmethod, struct ast_sockaddr *addr, struct sip_peer **authpeer, enum xmittype reliable, char *calleridname, char *uri2) |
| Validate device authentication. | |
| static void | check_pendings (struct sip_pvt *p) |
| Check pending actions on SIP call. | |
| static void | check_rtp_timeout (struct sip_pvt *dialog, time_t t) |
| helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked | |
| static int | check_sip_domain (const char *domain, char *context, size_t len) |
| check_sip_domain: Check if domain part of uri is local to our server | |
| static int | check_user (struct sip_pvt *p, struct sip_request *req, int sipmethod, 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 in ASTOBJ, that needs to be unreferenced. | |
| static enum check_auth_result | check_user_full (struct sip_pvt *p, struct sip_request *req, int sipmethod, 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. | |
| static void | check_via (struct sip_pvt *p, struct sip_request *req) |
| check Via: header for hostname, port and rport request/answer | |
| static attribute_unused void | check_via_response (struct sip_pvt *p, struct sip_request *req) |
| check received= and rport= in a SIP response. If we get a response with received= and/or rport= in the Via: line, use them as 'p->ourip' (see RFC 3581 for rport, and RFC 3261 for received). Using these two fields SIP can produce the correct address and port in the SIP headers without the need for STUN. The address part is also reused for the media sessions. Note that ast_sip_ouraddrfor() still rewrites p->ourip if you specify externaddr/seternaddr/. | |
| static void | cleanup_all_regs (void) |
| static void | cleanup_stale_contexts (char *new, char *old) |
| Destroy disused contexts between reloads Only used in reload_config so the code for regcontext doesn't get ugly. | |
| static void | clear_peer_mailboxes (struct sip_peer *peer) |
| static void | clear_sip_domains (void) |
| Clear our domain list (at reload). | |
| static char * | complete_sip_peer (const char *word, int state, int flags2) |
| Do completion on peer name. | |
| static char * | complete_sip_registered_peer (const char *word, int state, int flags2) |
| Do completion on registered peer name. | |
| static char * | complete_sip_show_history (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show history' CLI. | |
| static char * | complete_sip_show_peer (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show peer' CLI. | |
| static char * | complete_sip_show_user (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show user' CLI. | |
| static char * | complete_sip_unregister (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip unregister' CLI. | |
| static char * | complete_sip_user (const char *word, int state) |
| Do completion on user name. | |
| static char * | complete_sipch (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip show channel' and 'sip show history' CLI This is in charge of generating all strings that match a prefix in the given position. As many functions of this kind, each invokation has O(state) time complexity so be careful in using it. | |
| static char * | complete_sipnotify (const char *line, const char *word, int pos, int state) |
| Support routine for 'sip notify' CLI. | |
| static int | 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. | |
| static int | copy_header (struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy one header field from one request to another. | |
| static void | copy_request (struct sip_request *dst, const struct sip_request *src) |
| copy SIP request (mostly used to save request for responses) | |
| static void | copy_socket_data (struct sip_socket *to_sock, const struct sip_socket *from_sock) |
| static struct ast_variable * | copy_vars (struct ast_variable *src) |
| duplicate a list of channel variables, | |
| static int | copy_via_headers (struct sip_pvt *p, struct sip_request *req, const struct sip_request *orig, const char *field) |
| Copy SIP VIA Headers from the request to the response. | |
| static int | create_addr (struct sip_pvt *dialog, const char *opeer, struct ast_sockaddr *addr, int newdialog, struct ast_sockaddr *remote_address) |
| create address structure from device name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success | |
| static int | create_addr_from_peer (struct sip_pvt *dialog, struct sip_peer *peer) |
| Create address structure from peer reference. This function copies data from peer to the dialog, so we don't have to look up the peer again from memory or database during the life time of the dialog. | |
| static struct sip_epa_entry * | create_epa_entry (const char *const event_package, const char *const destination) |
| static struct sip_esc_entry * | create_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 int | default_sip_port (enum sip_transport type) |
| The default sip port for the given transport. | |
| static void | deinit_req (struct sip_request *req) |
| Deinitialize SIP response/request. | |
| static void | destroy_association (struct sip_peer *peer) |
| Remove registration data from realtime database or AST/DB when registration expires. | |
| static void | destroy_escs (void) |
| static void | destroy_mailbox (struct sip_mailbox *mailbox) |
| static void | destroy_realm_authentication (void *obj) |
| static int | determine_firstline_parts (struct sip_request *req) |
| Parse first line of incoming SIP request. | |
| 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_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_rtp (struct sip_pvt *dialog) |
| Initialize RTP portion of a dialog. | |
| static int | dialog_needdestroy (void *dialogobj, void *arg, int flags) |
| Match dialogs that need to be destroyed. | |
| struct sip_pvt * | dialog_ref_debug (struct sip_pvt *p, char *tag, char *file, int line, const char *func) |
| 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. | |
| static int | dialog_unlink_callback (void *obj, void *arg, int flags) |
| struct sip_pvt * | dialog_unref_debug (struct sip_pvt *p, char *tag, char *file, int line, const char *func) |
| static void | disable_dsp_detect (struct sip_pvt *p) |
| static void | display_nat_warning (const char *cat, int reason, struct ast_flags *flags) |
| static int | do_magic_pickup (struct ast_channel *channel, const char *extension, const char *context) |
| static void * | do_monitor (void *data) |
| The SIP monitoring thread. | |
| static int | do_proxy_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code, int sipmethod, int init) |
| Add authentication on outbound SIP packet. | |
| static int | do_register_auth (struct sip_pvt *p, struct sip_request *req, enum sip_auth_type code) |
| Authenticate for outbound registration. | |
| static void | do_setnat (struct sip_pvt *p) |
| Set nat mode on the various data sockets. | |
| static const char * | domain_mode_to_text (const enum domain_mode mode) |
| Print domain mode to cli. | |
| static const char * | dtmfmode2str (int mode) |
| Convert DTMF mode to printable string. | |
| static 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. | |
| static void | extract_host_from_hostport (char **hostport) |
| Terminate a host:port at the ':'. | |
| static void | extract_uri (struct sip_pvt *p, struct sip_request *req) |
| Check Contact: URI of SIP message. | |
| static const char * | faxec2str (int faxec) |
| static int | finalize_content (struct sip_request *req) |
| Add 'Content-Length' header and content to SIP message. | |
| static const char * | find_alias (const char *name, const char *_default) |
| Find compressed SIP alias. | |
| static int | find_by_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) |
| static struct sip_pvt * | find_call (struct sip_request *req, struct ast_sockaddr *addr, const int intended_method) |
| find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_request_do | |
| static int | find_calling_channel (void *obj, void *arg, void *data, int flags) |
| Find the channel that is causing the RINGING update. | |
| const char * | find_closing_quote (const char *start, const char *lim) |
| Locate closing quote in a string, skipping escaped quotes. optionally with a limit on the search. start must be past the first quote. | |
| static struct sip_peer * | find_peer (const char *peer, struct ast_sockaddr *addr, int realtime, int which_objects, int devstate_only, int transport) |
| Locate device by name or ip address. | |
| static struct sip_auth * | find_realm_authentication (struct sip_auth_container *credentials, const char *realm) |
| static int | find_sdp (struct sip_request *req) |
| Determine whether a SIP message contains an SDP in its body. | |
| static struct ast_cc_agent * | find_sip_cc_agent_by_notify_uri (const char *const uri) |
| static struct ast_cc_agent * | find_sip_cc_agent_by_original_callid (struct sip_pvt *pvt) |
| static struct ast_cc_agent * | find_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 | |
| 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 struct epa_static_data * | find_static_data (const char *const event_package) |
| static struct cfsubscription_types * | find_subscription_type (enum subscriptiontype subtype) |
| Find subscription type in array. | |
| static void | free_old_route (struct sip_route *route) |
| Remove route from route list. | |
| static int | func_check_sipdomain (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| Dial plan function to check if domain is local. | |
| static int | func_header_read (struct ast_channel *chan, const char *function, char *data, char *buf, size_t len) |
| Read SIP header (dialplan function). | |
| static int | function_sipchaninfo_read (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| ${SIPCHANINFO()} Dialplan function - reads sip channel data | |
| static int | function_sippeer (struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) |
| ${SIPPEER()} Dialplan function - reads peer data | |
| static char * | generate_random_string (char *buf, size_t size) |
| Generate 32 byte random string for callid's etc. | |
| static 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. | |
| static int | get_also_info (struct sip_pvt *p, struct sip_request *oreq) |
| Call transfer support (old way, deprecated by the IETF). | |
| static char * | get_body (struct sip_request *req, char *name, char delimiter) |
| Get a specific line from the message body. | |
| static char * | get_body_by_line (const char *line, const char *name, int nameLen, char delimiter) |
| Reads one line of SIP message body. | |
| static int | get_cached_mwi (struct sip_peer *peer, int *new, int *old) |
| Get cached MWI info. | |
| static void | get_crypto_attrib (struct sip_srtp *srtp, const char **a_crypto) |
| 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. | |
| static int | get_domain (const char *str, char *domain, int len) |
| Extract domain from SIP To/From header. | |
| static struct event_state_compositor * | get_esc (const char *const event_package) |
| static struct sip_esc_entry * | get_esc_entry (const char *entity_tag, struct event_state_compositor *esc) |
| static const char * | get_header (const struct sip_request *req, const char *name) |
| Get header from SIP request. | |
| static struct ast_variable * | get_insecure_variable_from_config (struct ast_config *config) |
| static struct ast_variable * | get_insecure_variable_from_sippeers (const char *column, const char *value) |
| static struct ast_variable * | get_insecure_variable_from_sipregs (const char *column, const char *value, struct ast_variable **var) |
| static int | get_ip_and_port_from_sdp (struct sip_request *req, const enum media_type media, struct ast_sockaddr *addr) |
| static int | get_msg_text (char *buf, int len, struct sip_request *req) |
| Get message body from a SIP request. | |
| 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. | |
| 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. | |
| static int | get_rdnis (struct sip_pvt *p, struct sip_request *oreq, char **name, char **number, int *reason) |
| Get referring dnis. | |
| static void | get_realm (struct sip_pvt *p, const struct sip_request *req) |
| Choose realm based on From header and then To header or use globaly configured realm. Realm from From/To header should be listed among served domains in config file: domain=... | |
| static int | get_refer_info (struct sip_pvt *transferer, struct sip_request *outgoing_req) |
| Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure. | |
| static int | get_rpid (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. | |
| static const char * | get_sdp_iterate (int *start, struct sip_request *req, const char *name) |
| Lookup 'name' in the SDP starting at the 'start' line. Returns the matching line, and 'start' is updated with the next line number. | |
| static char | get_sdp_line (int *start, int stop, struct sip_request *req, const char **value) |
| Fetches the next valid SDP line between the 'start' line (inclusive) and the 'stop' line (exclusive). Returns the type ('a', 'c', ...) and matching line in reference 'start' is updated with the next line number. | |
| static struct sip_pvt * | get_sip_pvt_byid_locked (const char *callid, const char *totag, const char *fromtag) |
| Lock dialog lock and find matching pvt lock. | |
| static const char * | get_srv_protocol (enum sip_transport t) |
| Return protocol string for srv dns query. | |
| static const char * | get_srv_service (enum sip_transport t) |
| Return service string for srv dns query. | |
| static const char * | get_transport (enum sip_transport t) |
| Return transport as string. | |
| static const char * | get_transport_list (unsigned int transports) |
| Return configuration of transports for a device. | |
| static const char * | get_transport_pvt (struct sip_pvt *p) |
| Return transport of dialog. | |
| static int | get_transport_str2enum (const char *transport) |
| Return int representing a bit field of transport types found in const char *transport. | |
| static const char * | gettag (const struct sip_request *req, const char *header, char *tagbuf, int tagbufsize) |
| Get tag from packet. | |
| static int | handle_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. | |
| 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). | |
| static int | handle_invite_replaces (struct sip_pvt *p, struct sip_request *req, int debug, uint32_t seqno, struct ast_sockaddr *addr, int *nounlock) |
| Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer. Used only once. XXX 'ignore' is unused. | |
| static int | handle_request_bye (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming BYE request. | |
| static int | handle_request_cancel (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming CANCEL request. | |
| static int | handle_request_do (struct sip_request *req, struct ast_sockaddr *addr) |
| Handle incoming SIP message - request or response. | |
| static void | handle_request_info (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP INFO Message. | |
| static int | handle_request_invite (struct sip_pvt *p, struct sip_request *req, int debug, uint32_t seqno, struct ast_sockaddr *addr, int *recount, const char *e, int *nounlock) |
| Handle incoming INVITE request. | |
| static int | handle_request_message (struct sip_pvt *p, struct sip_request *req) |
| Handle incoming MESSAGE request. | |
| static int | handle_request_notify (struct sip_pvt *p, struct sip_request *req, struct ast_sockaddr *addr, uint32_t seqno, const char *e) |
| Handle incoming notifications. | |
| 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. | |
| 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, int debug, 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. | |
| 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. | |
| static int | handle_request_update (struct sip_pvt *p, struct sip_request *req) |
| bare-bones support for SIP UPDATE | |
| 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. | |
| 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. | |
| static void | handle_response_message (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| static void | handle_response_notify (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| static void | handle_response_peerpoke (struct sip_pvt *p, int resp, struct sip_request *req) |
| Handle qualification responses (OPTIONS). | |
| static void | handle_response_publish (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| static void | handle_response_refer (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| static int | handle_response_register (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| Handle responses on REGISTER to services. | |
| static void | handle_response_subscribe (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| static void | handle_response_update (struct sip_pvt *p, int resp, const char *rest, struct sip_request *req, uint32_t seqno) |
| Handle authentication challenge for SIP UPDATE. | |
| 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, int *maxdatagram) |
| Handle T.38 configuration options common to users and peers. | |
| const char * | hangup_cause2sip (int cause) |
| Convert Asterisk hangup causes to SIP codes. | |
| int | hangup_sip2cause (int cause) |
| Convert SIP hangup causes to Asterisk hangup causes. | |
| static int | init_req (struct sip_request *req, int sipmethod, const char *recip) |
| Initialize SIP request. | |
| static int | init_resp (struct sip_request *resp, const char *msg) |
| Initialize SIP response, based on SIP request. | |
| static 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. | |
| 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. | |
| static const char * | insecure2str (int mode) |
| Convert Insecure setting to printable string. | |
| static int | interpret_t38_parameters (struct sip_pvt *p, const struct ast_control_t38_parameters *parameters) |
| Helper function which updates T.38 capability information and triggers a reinvite. | |
| static int | is_method_allowed (unsigned int *allowed_methods, enum sipmethod method) |
| Check if method is allowed for a device or a dialog. | |
| static void | list_route (struct sip_route *route) |
| List all routes - mostly for debugging. | |
| static int | load_module (void) |
| PBX load module - initialization. | |
| static int | local_attended_transfer (struct sip_pvt *transferer, struct sip_dual *current, struct sip_request *req, uint32_t seqno, int *nounlock) |
| Find all call legs and bridge transferee with target called from handle_request_refer. | |
| static void | lws2sws (struct ast_str *data) |
| Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled. | |
| static void | make_our_tag (struct sip_pvt *pvt) |
| Make our SIP dialog tag. | |
| static int | manager_show_registry (struct mansession *s, const struct message *m) |
| Show SIP registrations in the manager API. | |
| static int | manager_sip_qualify_peer (struct mansession *s, const struct message *m) |
| Qualify SIP peers in the manager API. | |
| static int | manager_sip_show_peer (struct mansession *s, const struct message *m) |
| Show SIP peers in the manager API. | |
| static int | manager_sip_show_peers (struct mansession *s, const struct message *m) |
| Show SIP peers in the manager API. | |
| static int | manager_sipnotify (struct mansession *s, const struct message *m) |
| static int | map_s_x (const struct _map_x_s *table, const char *s, int errorvalue) |
| map from a string to an integer value, case insensitive. If no match is found, return errorvalue. | |
| static const char * | map_x_s (const struct _map_x_s *table, int x, const char *errorstring) |
| map from an integer value to a string. If no match is found, return errorstring | |
| static void | mark_method_allowed (unsigned int *allowed_methods, enum sipmethod method) |
| static void | mark_method_unallowed (unsigned int *allowed_methods, enum sipmethod method) |
| static void | mark_parsed_methods (unsigned int *methods, char *methods_str) |
| static int | match_and_cleanup_peer_sched (void *peerobj, void *arg, int flags) |
| static enum match_req_res | match_req_to_dialog (struct sip_pvt *sip_pvt_ptr, struct match_req_args *arg) |
| static int | method_match (enum sipmethod id, const char *name) |
| returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'. Strictly speaking, SIP methods are case SENSITIVE, but we do a case-insensitive comparison to be more tolerant. following Jon Postel's rule: Be gentle in what you accept, strict with what you send | |
| static void | mwi_event_cb (const struct ast_event *event, void *userdata) |
| Receive MWI events that we have subscribed to. | |
| static void | network_change_event_cb (const struct ast_event *, void *) |
| static int | network_change_event_sched_cb (const void *data) |
| static void | network_change_event_subscribe (void) |
| static void | network_change_event_unsubscribe (void) |
| static struct sip_proxy * | obproxy_get (struct sip_pvt *dialog, struct sip_peer *peer) |
| Get default outbound proxy or global proxy. | |
| 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. | |
| static void | parse_copy (struct sip_request *dst, const struct sip_request *src) |
| Copy SIP request, parse it. | |
| static int | parse_minse (const char *p_hdrval, int *const p_interval) |
| Session-Timers: Function for parsing Min-SE header. | |
| static void | parse_moved_contact (struct sip_pvt *p, struct sip_request *req, char **name, char **number, int set_call_forward) |
| Parse 302 Moved temporalily response. | |
| static int | parse_ok_contact (struct sip_pvt *pvt, struct sip_request *req) |
| Save contact header for 200 OK on INVITE. | |
| static enum parse_register_result | parse_register_contact (struct sip_pvt *pvt, struct sip_peer *peer, struct sip_request *req) |
| Parse contact header and save registration (peer registration). | |
| static int | parse_request (struct sip_request *req) |
| Parse a SIP message. | |
| static int | parse_session_expires (const char *p_hdrval, int *const p_interval, enum st_refresher *const p_ref) |
| Session-Timers: Function for parsing Session-Expires header. | |
| static 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 | |
| static int | peer_cmp_cb (void *obj, void *arg, int flags) |
| static int | peer_dump_func (void *userobj, void *arg, int flags) |
| static int | peer_hash_cb (const void *obj, const int flags) |
| static int | peer_ipcmp_cb (void *obj, void *arg, int flags) |
| static int | peer_iphash_cb (const void *obj, const int flags) |
| static void | peer_mailboxes_to_str (struct ast_str **mailbox_str, struct sip_peer *peer) |
| list peer mailboxes to CLI | |
| static int | peer_markall_func (void *device, void *arg, int flags) |
| static 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 | peers_data_provider_get (const struct ast_data_search *search, struct ast_data *data_root) |
| 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. | |
| static void | print_codec_to_cli (int fd, struct ast_codec_pref *pref) |
| Print codec list from preference to CLI/manager. | |
| static void | print_group (int fd, ast_group_t group, int crlf) |
| Print call group and pickup group. | |
| static void | proc_422_rsp (struct sip_pvt *p, struct sip_request *rsp) |
| Handle 422 response to INVITE with session-timer requested. | |
| static int | proc_session_timer (const void *vp) |
| Session-Timers: Process session refresh timeout event. | |
| static int | process_crypto (struct sip_pvt *p, struct ast_rtp_instance *rtp, struct sip_srtp **srtp, const char *a) |
| static int | process_sdp (struct sip_pvt *p, struct sip_request *req, int t38action) |
| 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(). | |
| 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_image (const char *a, struct sip_pvt *p) |
| static int | process_sdp_a_sendonly (const char *a, int *sendonly) |
| static int | process_sdp_a_text (const char *a, struct sip_pvt *p, struct ast_rtp_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. | |
| static int | proxy_update (struct sip_proxy *proxy) |
| static int | publish_expire (const void *data) |
| static void | pvt_set_needdestroy (struct sip_pvt *pvt, const char *reason) |
| static struct sip_peer * | realtime_peer (const char *newpeername, struct ast_sockaddr *addr, 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. | |
| static int | realtime_peer_by_addr (const char **name, struct ast_sockaddr *addr, const char *ipaddr, 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_variable * | realtime_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) |
| Update peer object in realtime storage If the Asterisk system name is set in asterisk.conf, we will use that name and store that in the "regserver" field in the sippeers table to facilitate multi-server setups. | |
| static void | receive_message (struct sip_pvt *p, struct sip_request *req) |
| Receive SIP MESSAGE method messages. | |
| static struct sip_peer * | ref_peer (struct sip_peer *peer, char *tag) |
| static void | ref_proxy (struct sip_pvt *pvt, struct sip_proxy *proxy) |
| maintain proper refcounts for a sip_pvt's outboundproxy | |
| static const char * | referstatus2str (enum referstatus rstatus) |
| Convert transfer status to string. | |
| static void | reg_source_db (struct sip_peer *peer) |
| Get registration details from Asterisk DB. | |
| static void | register_peer_exten (struct sip_peer *peer, int onoff) |
| Automatically add peer extension to dial plan. | |
| static enum check_auth_result | register_verify (struct sip_pvt *p, struct ast_sockaddr *addr, struct sip_request *req, const char *uri) |
Verify registration of user
| |
| static struct sip_registry * | registry_addref (struct sip_registry *reg, char *tag) |
| Add object reference to SIP registry. | |
| static void * | registry_unref (struct sip_registry *reg, char *tag) |
| static const char * | regstate2str (enum sipregistrystate regstate) |
| Convert registration state status to string. | |
| static int | reinvite_timeout (const void *data) |
| static int | reload (void) |
| Part of Asterisk module interface. | |
| static int | reload_config (enum channelreloadreason reason) |
| Re-read SIP.conf config file. | |
| static char * | remove_uri_parameters (char *uri) |
| static int | reply_digest (struct sip_pvt *p, struct sip_request *req, char *header, int sipmethod, char *digest, int digest_len) |
| reply to authentication for outbound registrations | |
| static int | reqprep (struct sip_request *req, struct sip_pvt *p, int sipmethod, uint32_t seqno, int newbranch) |
| Initialize a SIP request message (not the initial one in a dialog). | |
| static int | resp_needs_contact (const char *msg, enum sipmethod method) |
| Test if this response needs a contact header. | |
| static int | respprep (struct sip_request *resp, struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Prepare SIP response packet. | |
| static int | restart_monitor (void) |
| Start the channel monitor thread. | |
| static void | restart_session_timer (struct sip_pvt *p) |
| Session-Timers: Restart session timer. | |
| static int | retrans_pkt (const void *data) |
| Retransmit SIP message if no answer (Called from scheduler). | |
| static int | 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. | |
| static enum ast_cc_service_type | service_string_to_service_type (const char *const service_string) |
| static int | set_address_from_contact (struct sip_pvt *pvt) |
| Change the other partys IP address based on given contact. | |
| static void | set_destination (struct sip_pvt *p, char *uri) |
| Set destination from SIP URI. | |
| static void | set_insecure_flags (struct ast_flags *flags, const char *value, int lineno) |
| Parse insecure= setting in sip.conf and set flags according to setting. | |
| static void | set_nonce_randdata (struct sip_pvt *p, int forceupdate) |
| builds the sip_pvt's randdata field which is used for the nonce challenge. When forceupdate is not set, the nonce is only updated if the current one is stale. In this case, a stalenonce is one which has already received a response, if a nonce has not received a response it is not always necessary or beneficial to create a new one. | |
| static void | set_peer_defaults (struct sip_peer *peer) |
| Set peer defaults before configuring specific configurations. | |
| static 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. | |
| static int | setup_srtp (struct sip_srtp **srtp) |
| static int | show_channels_cb (void *__cur, void *__arg, int flags) |
| callback for show channel|subscription | |
| static int | show_chanstats_cb (void *__cur, void *__arg, int flags) |
| Callback for show_chanstats. | |
| static int | sip_addheader (struct ast_channel *chan, const char *data) |
| Add a SIP header to an outbound INVITE. | |
| struct sip_pvt * | sip_alloc (ast_string_field callid, struct ast_sockaddr *addr, int useglobal_nat, const int intended_method, struct sip_request *req) |
| Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference. | |
| static void | sip_alreadygone (struct sip_pvt *dialog) |
| Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging. | |
| static int | sip_answer (struct ast_channel *ast) |
| sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface | |
| static int | sip_call (struct ast_channel *ast, char *dest, int timeout) |
| Initiate SIP call from PBX used from the dial() application. | |
| int | sip_cancel_destroy (struct sip_pvt *p) |
| Cancel destruction of SIP dialog. Be careful as this also absorbs the reference - if you call it from within the scheduler, this might be the last reference. | |
| static 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. | |
| static char * | sip_cli_notify (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Cli command to send SIP notify to peer. | |
| static int | sip_debug_test_addr (const struct ast_sockaddr *addr) |
| See if we pass debug IP filter. | |
| static int | sip_debug_test_pvt (struct sip_pvt *p) |
| Test PVT for debugging output. | |
| struct sip_pvt * | sip_destroy (struct sip_pvt *p) |
| Destroy SIP call structure. Make it return NULL so the caller can do things like foo = sip_destroy(foo); and reduce the chance of bugs due to dangling pointers. | |
| static void | sip_destroy_fn (void *p) |
| static void | sip_destroy_peer (struct sip_peer *peer) |
| Destroy peer object from memory. | |
| static void | sip_destroy_peer_fn (void *peer) |
| static int | sip_devicestate (void *data) |
| Part of PBX channel interface. | |
| static char * | sip_do_debug (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Turn on SIP debugging (CLI command). | |
| static char * | sip_do_debug_ip (int fd, const char *arg) |
| Enable SIP Debugging for a single IP. | |
| static char * | sip_do_debug_peer (int fd, const char *arg) |
| Turn on SIP debugging for a given peer. | |
| static int | sip_do_reload (enum channelreloadreason reason) |
| Reload module. | |
| static int | sip_dtmfmode (struct ast_channel *chan, const char *data) |
| Set the DTMFmode for an outbound SIP call (application). | |
| static void | sip_dump_history (struct sip_pvt *dialog) |
| Dump SIP history to debug log file at end of lifespan for SIP dialog. | |
| static int | sip_epa_register (const struct epa_static_data *static_data) |
| static void | sip_epa_unregister_all (void) |
| static int | sip_fixup (struct ast_channel *oldchan, struct ast_channel *newchan) |
| sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links | |
| static const char * | sip_get_callid (struct ast_channel *chan) |
| Deliver SIP call ID for the call. | |
| static int | sip_get_cc_information (struct sip_request *req, char *subscribe_uri, size_t size, enum ast_cc_service_type *service) |
| static format_t | sip_get_codec (struct ast_channel *chan) |
| static enum ast_rtp_glue_result | sip_get_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance) |
| static enum ast_rtp_glue_result | sip_get_trtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance) |
| static struct ast_udptl * | sip_get_udptl_peer (struct ast_channel *chan) |
| static enum ast_rtp_glue_result | sip_get_vrtp_peer (struct ast_channel *chan, struct ast_rtp_instance **instance) |
| static void | sip_handle_cc (struct sip_pvt *pvt, struct sip_request *req, enum ast_cc_service_type service) |
| static int | sip_hangup (struct ast_channel *ast) |
| sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup | |
| static int | sip_indicate (struct ast_channel *ast, int condition, const void *data, size_t datalen) |
| Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc. | |
| static int | sip_is_xml_parsable (void) |
| 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_instance * | sip_monitor_instance_init (int core_id, const char *const subscribe_uri, const char *const peername, const char *const device_name) |
| static const char * | sip_nat_mode (const struct sip_pvt *p) |
| Display SIP nat mode. | |
| static struct ast_channel * | sip_new (struct sip_pvt *i, int state, const char *title, const char *linkedid) |
| Initiate a call in the SIP channel. | |
| static int | sip_notify_allocate (struct sip_pvt *p) |
| Allocate SIP refer structure. | |
| static int | sip_offer_timer_expire (const void *data) |
| static int | sip_park (struct ast_channel *chan1, struct ast_channel *chan2, struct sip_request *req, uint32_t seqno, const char *park_exten, const char *park_context) |
| static void * | sip_park_thread (void *stuff) |
| Park SIP call support function Starts in a new thread, then parks the call XXX Should we add a wait period after streaming audio and before hangup?? Sometimes the audio can't be heard before hangup. | |
| static void | sip_peer_hold (struct sip_pvt *p, int hold) |
| Change onhold state of a peer using a pvt structure. | |
| static int | sip_pickup (struct ast_channel *chan) |
| Pickup a call using the subsystem in features.c This is executed in a separate thread. | |
| static void * | sip_pickup_thread (void *stuff) |
| SIP pickup support function Starts in a new thread, then pickup the call. | |
| static void | sip_poke_all_peers (void) |
| Send a poke to all known peers. | |
| static int | sip_poke_noanswer (const void *data) |
| React to lack of answer to Qualify poke. | |
| static int | sip_poke_peer (struct sip_peer *peer, int force) |
| Check availability of peer, also keep NAT open. | |
| static int | sip_poke_peer_s (const void *data) |
| Poke peer (send qualify to check if peer is alive and well). | |
| static int | sip_prepare_socket (struct sip_pvt *p) |
| static char * | sip_prune_realtime (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Remove temporary realtime objects from memory (CLI). | |
| static struct ast_channel * | sip_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. | |
| static int | sip_queryoption (struct ast_channel *chan, int option, void *data, int *datalen) |
| Query an option on a SIP dialog. | |
| static void | sip_queue_hangup_cause (struct sip_pvt *p, int cause) |
| static struct ast_frame * | sip_read (struct ast_channel *ast) |
| Read SIP RTP from channel. | |
| static struct ast_sockaddr * | sip_real_dst (const struct sip_pvt *p) |
| The real destination address for a write. | |
| static const char * | sip_reason_code_to_str (enum AST_REDIRECTING_REASON code) |
| static enum AST_REDIRECTING_REASON | sip_reason_str_to_code (const char *text) |
| static int | sip_refer_allocate (struct sip_pvt *p) |
| Allocate SIP refer structure. | |
| static int | sip_reg_timeout (const void *data) |
| Registration timeout, register again Registered as a timeout handler during transmit_register(), to retransmit the packet if a reply does not come back. This is called by the scheduler so the event is not pending anymore when we are called. | |
| static int | sip_register (const char *value, int lineno) |
| create sip_registry object from register=> line in sip.conf and link into reg container | |
| static void | sip_register_tests (void) |
| SIP test registration. | |
| static void | sip_registry_destroy (struct sip_registry *reg) |
| Destroy registry object Objects created with the register= statement in static configuration. | |
| static int | sip_reinvite_retry (const void *data) |
| Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. Called from the scheduler. | |
| static char * | sip_reload (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Force reload of module from cli. | |
| static int | sip_removeheader (struct ast_channel *chan, const char *data) |
| Remove SIP headers added previously with SipAddHeader application. | |
| static struct ast_channel * | sip_request_call (const char *type, format_t format, const struct ast_channel *requestor, void *data, int *cause) |
| PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here. | |
| static int | sip_reregister (const void *data) |
| Update registration with SIP Proxy. Called from the scheduler when the previous registration expires, so we don't have to cancel the pending event. We assume the reference so the sip_registry is valid, since it is stored in the scheduled event anyways. | |
| static struct ast_frame * | sip_rtp_read (struct ast_channel *ast, struct sip_pvt *p, int *faxdetect) |
| Read RTP from network. | |
| static const char * | sip_sanitized_host (const char *host) |
| void | sip_scheddestroy (struct sip_pvt *p, int ms) |
| Schedule destruction of SIP dialog. | |
| void | sip_scheddestroy_final (struct sip_pvt *p, int ms) |
| Schedule final destruction of SIP dialog. This can not be canceled. This function is used to keep a dialog around for a period of time in order to properly respond to any retransmits. | |
| static void | sip_send_all_mwi_subscriptions (void) |
| Send all MWI subscriptions. | |
| static void | sip_send_all_registers (void) |
| Send all known registrations. | |
| static int | sip_send_mwi_to_peer (struct sip_peer *peer, int cache_only) |
| Send message waiting indication to alert peer that they've got voicemail. | |
| static int | sip_senddigit_begin (struct ast_channel *ast, char digit) |
| static int | sip_senddigit_end (struct ast_channel *ast, char digit, unsigned int duration) |
| Send DTMF character on SIP channel within one call, we're able to transmit in many methods simultaneously. | |
| static int | sip_sendhtml (struct ast_channel *chan, int subclass, const char *data, int datalen) |
| Send message with Access-URL header, if this is an HTML URL only! | |
| static int | sip_sendtext (struct ast_channel *ast, const char *text) |
| static char * | sip_set_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Enable/Disable SIP History logging (CLI). | |
| static void | sip_set_redirstr (struct sip_pvt *p, char *reason) |
| Translate referring cause. | |
| static int | sip_set_rtp_peer (struct ast_channel *chan, struct ast_rtp_instance *instance, struct ast_rtp_instance *vinstance, struct ast_rtp_instance *tinstance, format_t codecs, int nat_active) |
| static int | sip_set_udptl_peer (struct ast_channel *chan, struct ast_udptl *udptl) |
| static int | sip_setoption (struct ast_channel *chan, int option, void *data, int datalen) |
| Set an option on a SIP dialog. | |
| static char * | sip_show_channel (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show details of one active dialog. | |
| static char * | sip_show_channels (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI for show channels or subscriptions. This is a new-style CLI handler so a single function contains the prototype for the function, the 'generator' to produce multiple entries in case it is required, and the actual handler for the command. | |
| static char * | sip_show_channelstats (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| SIP show channelstats CLI (main function). | |
| static char * | sip_show_domains (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI command to list local domains. | |
| static char * | sip_show_history (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show history details of one dialog. | |
| static char * | sip_show_inuse (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Command to show calls within limits set by call_limit. | |
| static char * | sip_show_mwi (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | sip_show_objects (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| List all allocated SIP Objects (realtime or static). | |
| static char * | sip_show_peer (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show one peer in detail. | |
| static char * | sip_show_peers (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Show Peers command. | |
| static char * | sip_show_registry (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show SIP Registry (registrations with other SIP proxies. | |
| static char * | sip_show_sched (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| static char * | sip_show_settings (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| List global settings for the SIP channel. | |
| static char * | sip_show_tcp (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show active TCP connections. | |
| static char * | sip_show_user (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Show one user in detail. | |
| static char * | sip_show_users (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| CLI Command 'SIP Show Users'. | |
| static int | sip_sipredirect (struct sip_pvt *p, const char *dest) |
| Transfer call before connect with a 302 redirect. | |
| static struct sip_st_dlg * | sip_st_alloc (struct sip_pvt *const p) |
| Allocate Session-Timers struct w/in dialog. | |
| static int | sip_standard_port (enum sip_transport type, int port) |
| Returns the port to use for this socket. | |
| static int | sip_subscribe_mwi (const char *value, int lineno) |
| Parse mwi=> line in sip.conf and add to list. | |
| static void | sip_subscribe_mwi_destroy (struct sip_subscription_mwi *mwi) |
| Destroy MWI subscription object. | |
| static int | sip_subscribe_mwi_do (const void *data) |
| Send a subscription or resubscription for MWI. | |
| static int | sip_t38_abort (const void *data) |
| Called to deny a T38 reinvite if the core does not respond to our request. | |
| static struct ast_tcptls_session_instance * | sip_tcp_locate (struct ast_sockaddr *s) |
| Find thread for TCP/TLS session (based on IP/Port. | |
| static void * | sip_tcp_worker_fn (void *data) |
| SIP TCP connection handler. | |
| static void | sip_tcptls_client_args_destructor (void *obj) |
| static int | sip_tcptls_write (struct ast_tcptls_session_instance *tcptls_session, const void *buf, size_t len) |
| used to indicate to a tcptls thread that data is ready to be written | |
| static struct sip_threadinfo * | sip_threadinfo_create (struct ast_tcptls_session_instance *tcptls_session, int transport) |
| creates a sip_threadinfo object and links it into the threadt table. | |
| static void | sip_threadinfo_destructor (void *obj) |
| static int | sip_transfer (struct ast_channel *ast, const char *dest) |
| Transfer SIP call. | |
| static char * | sip_unregister (struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) |
| Unregister (force expiration) a SIP peer in the registry via CLI. | |
| static void | sip_unregister_tests (void) |
| SIP test registration. | |
| static int | sip_write (struct ast_channel *ast, struct ast_frame *frame) |
| Send frame to media channel (rtp). | |
| static int | sipsock_read (int *id, int fd, short events, void *ignore) |
| Read data from SIP UDP socket. | |
| static 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. | |
| static enum st_refresher | st_get_refresher (struct sip_pvt *p) |
| Get the entity (UAC or UAS) that's acting as the session-timer refresher. | |
| static int | st_get_se (struct sip_pvt *p, int max) |
| Get Max or Min SE (session timer expiry). | |
| static void | start_session_timer (struct sip_pvt *p) |
| Session-Timers: Start session timer. | |
| static void | state_notify_build_xml (int state, 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. | |
| static const char * | stmode2str (enum st_mode m) |
| static void | stop_media_flows (struct sip_pvt *p) |
| Immediately stop RTP, VRTP and UDPTL as applicable. | |
| static void | stop_session_timer (struct sip_pvt *p) |
| Session-Timers: Stop session timer. | |
| static int | str2dtmfmode (const char *str) |
| maps a string to dtmfmode, returns -1 on error | |
| static enum st_mode | str2stmode (const char *s) |
| static enum st_refresher | str2strefresher (const char *s) |
| static const char * | strefresher2str (enum st_refresher r) |
| static const char * | subscription_type2str (enum subscriptiontype subtype) |
| Show subscription type in string format. | |
| static unsigned int | t38_get_rate (enum ast_control_t38_rate rate) |
| Get Max T.38 Transmission rate from T38 capabilities. | |
| static void | tcptls_packet_destructor (void *obj) |
| static struct sip_peer * | temp_peer (const char *name) |
| Create temporary peer (used in autocreatepeer mode). | |
| static void | temp_pvt_cleanup (void *) |
| static int | temp_pvt_init (void *) |
| static char * | terminate_uri (char *uri) |
| static int | threadinfo_locate_cb (void *obj, void *arg, int flags) |
| static int | threadt_cmp_cb (void *obj, void *arg, int flags) |
| static int | threadt_hash_cb (const void *obj, const int flags) |
| static char * | transfermode2str (enum transfermodes mode) |
| Convert transfer mode to text string. | |
| static 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, int sipmethod, struct sip_request *req, enum xmittype reliable) |
| Send a fake 401 Unauthorized response when the administrator wants to hide the names of local devices from fishers. | |
| static int | transmit_info_with_aoc (struct sip_pvt *p, struct ast_aoc_decoded *decoded) |
| Send SIP INFO advice of charge message. | |
| static int | transmit_info_with_digit (struct sip_pvt *p, const char digit, unsigned int duration) |
| Send SIP INFO dtmf message, see Cisco documentation on cisco.com. | |
| static int | transmit_info_with_vidupdate (struct sip_pvt *p) |
| Send SIP INFO with video update request. | |
| static int | transmit_invite (struct sip_pvt *p, int sipmethod, int sdp, int init, const char *const explicit_uri) |
| Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it. | |
| static int | transmit_message_with_text (struct sip_pvt *p, const char *text) |
| Transmit text with SIP MESSAGE method. | |
| static int | transmit_notify_with_mwi (struct sip_pvt *p, int newmsgs, int oldmsgs, const char *vmexten) |
| Notify user of messages waiting in voicemail (RFC3842). | |
| static int | transmit_notify_with_sipfrag (struct sip_pvt *p, int cseq, char *message, int terminate) |
| Notify a transferring party of the status of transfer (RFC3515). | |
| static int | transmit_provisional_response (struct sip_pvt *p, const char *msg, const struct sip_request *req, int with_sdp) |
| static int | transmit_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. | |
| static int | transmit_register (struct sip_registry *r, int sipmethod, const char *auth, const char *authheader) |
| Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister()). | |
| static int | transmit_reinvite_with_sdp (struct sip_pvt *p, int t38version, int oldsdp) |
| Transmit reinvite with SDP. | |
| static int | transmit_request (struct sip_pvt *p, int sipmethod, 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). | |
| 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. | |
| static int | transmit_response (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, no retransmits. | |
| static int | transmit_response_reliable (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK. | |
| static int | transmit_response_using_temp (ast_string_field callid, struct 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. | |
| static int | transmit_response_with_allow (struct sip_pvt *p, const char *msg, const struct sip_request *req, enum xmittype reliable) |
| Append Accept header, content length before transmitting response. | |
| static int | transmit_response_with_auth (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *randdata, enum xmittype reliable, const char *header, int stale) |
| Respond with authorization request. | |
| static int | transmit_response_with_date (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Append date and content length before transmitting response. | |
| static int | transmit_response_with_minexpires (struct sip_pvt *p, const char *msg, const struct sip_request *req) |
| Append Min-Expires header, content length before transmitting response. | |
| static int | transmit_response_with_minse (struct sip_pvt *p, const char *msg, const struct sip_request *req, int minse_int) |
| Transmit 422 response with Min-SE header (Session-Timers). | |
| static int | transmit_response_with_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. | |
| 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. | |
| 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. | |
| static int | transmit_response_with_unsupported (struct sip_pvt *p, const char *msg, const struct sip_request *req, const char *unsupported) |
| Transmit response, no retransmits. | |
| static int | transmit_state_notify (struct sip_pvt *p, int state, int full, int timeout) |
| Used in the SUBSCRIBE notification subsystem (RFC3265). | |
| static void | try_suggested_sip_codec (struct sip_pvt *p) |
| Try setting codec suggested by the SIP_CODEC channel variable. | |
| static void | unlink_all_peers_from_tables (void) |
| static void | unlink_marked_peers_from_tables (void) |
| static void | unlink_peer_from_tables (struct sip_peer *peer) |
| static void | unlink_peers_from_tables (peer_unlink_flag_t flag) |
| static int | unload_module (void) |
| PBX unload module API. | |
| static void * | unref_peer (struct sip_peer *peer, char *tag) |
| static int | update_call_counter (struct sip_pvt *fup, int event) |
| update_call_counter: Handle call_limit for SIP devices Setting a call-limit will cause calls above the limit not to be accepted. | |
| static void | update_connectedline (struct sip_pvt *p, const void *data, size_t datalen) |
| Notify peer that the connected line has changed. | |
| static void | update_peer (struct sip_peer *p, int expire) |
| Update peer data in database (if used). | |
| 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. | |
Implementation of Session Initiation Protocol.
See Also:
Implementation of RFC 3261 - without S/MIME, and experimental TCP and TLS support Configuration file sip.conf
********** IMPORTANT *
******** General TODO:s
Better support of forking
VIA branch tag transaction checking
Transaction support
******** Wishlist: Improvements
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"
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
Definition in file chan_sip.c.
| #define append_history | ( | p, | |||
| event, | |||||
| fmt, | |||||
| args... | ) | append_history_full(p, "%-15s " fmt, event, ## args) |
Append to SIP dialog history.
Definition at line 2221 of file chan_sip.c.
Referenced by __sip_autodestruct(), __sip_reliable_xmit(), auto_congest(), build_reply_digest(), cb_extensionstate(), change_hold_state(), check_auth(), do_register_auth(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_invite(), local_attended_transfer(), obproxy_get(), pvt_set_needdestroy(), retrans_pkt(), send_request(), send_response(), sip_cancel_destroy(), sip_fixup(), sip_hangup(), sip_new(), sip_park_thread(), sip_reregister(), sip_scheddestroy(), sip_set_rtp_peer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_response_with_auth(), and update_connectedline().
| #define CHECK_AUTH_BUF_INITLEN 256 |
Definition at line 14378 of file chan_sip.c.
Referenced by check_auth(), and transmit_fake_auth_response().
| #define check_request_transport | ( | peer, | |||
| tmpl | ) |
generic function for determining if a correct transport is being used to contact a peer
this is done as a macro so that the "tmpl" var can be passed either a sip_request or a sip_peer
Definition at line 2304 of file chan_sip.c.
Referenced by create_addr_from_peer(), and register_verify().
| #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 7585 of file chan_sip.c.
Referenced by change_callid_pvt().
| #define DATA_EXPORT_SIP_PEER | ( | MEMBER | ) |
Definition at line 30417 of file chan_sip.c.
| #define FORMAT "%-15.15s %-15.15s %-15.15s %-15.15s %-3.3s %-3.3s %-15.15s %-10.10s %-10.10s\n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" |
Definition at line 18412 of file chan_sip.c.
| #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 18412 of file chan_sip.c.
| #define FORMAT "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT "%-40.40s %-20.20s %-16.16s\n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT "%-47.47s %-9.9s %-6.6s\n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT "%-25.25s %-15.15s %-15.15s \n" |
Definition at line 18412 of file chan_sip.c.
| #define FORMAT2 "%-15.15s %-15.15s %-15.15s %-15.15s %-7.7s %-15.15s %-10.10s %-10.10s\n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT2 "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-10s %s\n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT2 "%-47.47s %9.9s %6.6s\n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" |
Definition at line 18411 of file chan_sip.c.
| #define FORMAT3 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6s\n" |
Definition at line 18410 of file chan_sip.c.
Referenced by sip_show_channels().
| #define FORMAT4 "%-15.15s %-15.15s %-15.15s %-15.15s %-13.13s %-15.15s %-10.10s %-6.6d\n" |
Definition at line 18409 of file chan_sip.c.
Referenced by show_channels_cb().
| #define SIP_PEDANTIC_DECODE | ( | str | ) |
if (sip_cfg.pedanticsipchecking && !ast_strlen_zero(str)) { \ ast_uri_decode(str); \ } \
Definition at line 702 of file chan_sip.c.
Referenced by check_user_full(), get_also_info(), get_destination(), get_refer_info(), and register_verify().
| #define sip_pvt_lock | ( | x | ) | ao2_lock(x) |
Definition at line 1102 of file chan_sip.c.
Referenced by __sip_ack(), __sip_autodestruct(), auto_congest(), cb_extensionstate(), complete_sipch(), get_sip_pvt_byid_locked(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_invite(), handle_request_refer(), local_attended_transfer(), proc_session_timer(), retrans_pkt(), sip_answer(), sip_call(), sip_cc_agent_destructor(), sip_cc_agent_init(), sip_cc_agent_recall(), sip_cc_agent_respond(), sip_cc_monitor_request_cc(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_monitor_instance_destructor(), sip_new(), sip_pvt_lock_full(), sip_queryoption(), sip_read(), sip_reg_timeout(), sip_reinvite_retry(), sip_request_call(), sip_send_mwi_to_peer(), sip_senddigit_begin(), sip_senddigit_end(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_setoption(), sip_show_channel(), sip_show_history(), sip_t38_abort(), sip_transfer(), sip_write(), transmit_publish(), and update_call_counter().
| #define sip_pvt_trylock | ( | x | ) | ao2_trylock(x) |
Definition at line 1103 of file chan_sip.c.
Referenced by dialog_needdestroy(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), and sip_hangup().
| #define sip_pvt_unlock | ( | x | ) | ao2_unlock(x) |
Definition at line 1104 of file chan_sip.c.
Referenced by __sip_ack(), __sip_autodestruct(), auto_congest(), cb_extensionstate(), complete_sipch(), dialog_needdestroy(), dialog_unlink_all(), get_sip_pvt_byid_locked(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_refer(), local_attended_transfer(), proc_session_timer(), retrans_pkt(), send_provisional_keepalive_full(), sip_answer(), sip_call(), sip_cc_agent_destructor(), sip_cc_agent_init(), sip_cc_agent_recall(), sip_cc_agent_respond(), sip_cc_monitor_request_cc(), sip_dtmfmode(), sip_fixup(), sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), sip_get_vrtp_peer(), sip_hangup(), sip_indicate(), sip_monitor_instance_destructor(), sip_new(), sip_pvt_lock_full(), sip_queryoption(), sip_queue_hangup_cause(), sip_read(), sip_reg_timeout(), sip_reinvite_retry(), sip_request_call(), sip_send_mwi_to_peer(), sip_senddigit_begin(), sip_senddigit_end(), sip_set_rtp_peer(), sip_set_udptl_peer(), sip_setoption(), sip_show_channel(), sip_show_history(), sip_t38_abort(), sip_transfer(), sip_write(), transmit_publish(), and update_call_counter().
| #define UNLINK | ( | element, | |||
| head, | |||||
| prev | ) |
some list management macros.
Definition at line 1202 of file chan_sip.c.
Referenced by __sip_ack(), handle_request_cancel(), and retrans_pkt().
| enum match_req_res |
Definition at line 7871 of file chan_sip.c.
07871 { 07872 SIP_REQ_MATCH, 07873 SIP_REQ_NOT_MATCH, 07874 SIP_REQ_LOOP_DETECTED, 07875 };
| enum peer_unlink_flag_t |
Definition at line 2868 of file chan_sip.c.
02868 { 02869 SIP_PEERS_MARKED, 02870 SIP_PEERS_ALL, 02871 } peer_unlink_flag_t;
| static const char * __get_header | ( | const struct sip_request * | req, | |
| const char * | name, | |||
| int * | start | |||
| ) | [static] |
Definition at line 7353 of file chan_sip.c.
References ast_skip_blanks(), find_alias(), len(), match(), and sip_cfg.
Referenced by build_route(), copy_all_header(), copy_via_headers(), func_header_read(), get_header(), handle_incoming(), handle_request_subscribe(), handle_response_register(), and parse_register_contact().
07354 { 07355 /* 07356 * Technically you can place arbitrary whitespace both before and after the ':' in 07357 * a header, although RFC3261 clearly says you shouldn't before, and place just 07358 * one afterwards. If you shouldn't do it, what absolute idiot decided it was 07359 * a good idea to say you can do it, and if you can do it, why in the hell would. 07360 * you say you shouldn't. 07361 * Anyways, pedanticsipchecking controls whether we allow spaces before ':', 07362 * and we always allow spaces after that for compatibility. 07363 */ 07364 const char *sname = find_alias(name, NULL); 07365 int x, len = strlen(name), slen = (sname ? 1 : 0); 07366 for (x = *start; x < req->headers; x++) { 07367 const char *header = REQ_OFFSET_TO_STR(req, header[x]); 07368 int smatch = 0, match = !strncasecmp(header, name, len); 07369 if (slen) { 07370 smatch = !strncasecmp(header, sname, slen); 07371 } 07372 if (match || smatch) { 07373 /* skip name */ 07374 const char *r = header + (match ? len : slen ); 07375 if (sip_cfg.pedanticsipchecking) { 07376 r = ast_skip_blanks(r); 07377 } 07378 07379 if (*r == ':') { 07380 *start = x+1; 07381 return ast_skip_blanks(r+1); 07382 } 07383 } 07384 } 07385 07386 /* Don't return NULL, so get_header is always a valid pointer */ 07387 return ""; 07388 }
| static int __set_address_from_contact | ( | const char * | fullcontact, | |
| struct ast_sockaddr * | addr, | |||
| int | tcp | |||
| ) | [static] |
Definition at line 13954 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_strlen_zero(), get_transport_str2enum(), LOG_WARNING, and parse_uri_legacy_check().
Referenced by build_peer(), and set_address_from_contact().
13955 { 13956 char *hostport, *transport; 13957 char contact_buf[256]; 13958 char *contact; 13959 13960 /* Work on a copy */ 13961 ast_copy_string(contact_buf, fullcontact, sizeof(contact_buf)); 13962 contact = contact_buf; 13963 13964 /* 13965 * We have only the part in <brackets> here so we just need to parse a SIP URI. 13966 * 13967 * Note: The outbound proxy could be using UDP between the proxy and Asterisk. 13968 * We still need to be able to send to the remote agent through the proxy. 13969 */ 13970 13971 if (parse_uri_legacy_check(contact, "sip:,sips:", &contact, NULL, &hostport, 13972 &transport)) { 13973 ast_log(LOG_WARNING, "Invalid contact uri %s (missing sip: or sips:), attempting to use anyway\n", fullcontact); 13974 } 13975 13976 /* XXX This could block for a long time XXX */ 13977 /* We should only do this if it's a name, not an IP */ 13978 /* \todo - if there's no PORT number in contact - we are required to check NAPTR/SRV records 13979 to find transport, port address and hostname. If there's a port number, we have to 13980 assume that the hostport part is a host name and only look for an A/AAAA record in DNS. 13981 */ 13982 13983 /* If we took in an invalid URI, hostport may not have been initialized */ 13984 /* ast_sockaddr_resolve requires an initialized hostport string. */ 13985 if (ast_strlen_zero(hostport)) { 13986 ast_log(LOG_WARNING, "Invalid URI: parse_uri failed to acquire hostport\n"); 13987 return -1; 13988 } 13989 13990 if (ast_sockaddr_resolve_first_transport(addr, hostport, 0, get_transport_str2enum(transport))) { 13991 ast_log(LOG_WARNING, "Invalid host name in Contact: (can't " 13992 "resolve in DNS) : '%s'\n", hostport); 13993 return -1; 13994 } 13995 13996 /* set port */ 13997 if (!ast_sockaddr_port(addr)) { 13998 ast_sockaddr_set_port(addr, 13999 (get_transport_str2enum(transport) == 14000 SIP_TRANSPORT_TLS || 14001 !strncasecmp(fullcontact, "sips", 4)) ? 14002 STANDARD_TLS_PORT : STANDARD_SIP_PORT); 14003 } 14004 14005 return 0; 14006 }
| 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 3969 of file chan_sip.c.
References ast_debug, ast_free, ast_sched_del(), FALSE, ref_proxy(), sip_pvt_lock, sip_pvt_unlock, TRUE, and UNLINK.
Referenced by __sip_pretend_ack(), handle_incoming(), handle_request_invite(), handle_request_publish(), and handle_response().
03970 { 03971 struct sip_pkt *cur, *prev = NULL; 03972 const char *msg = "Not Found"; /* used only for debugging */ 03973 int res = FALSE; 03974 03975 /* If we have an outbound proxy for this dialog, then delete it now since 03976 the rest of the requests in this dialog needs to follow the routing. 03977 If obforcing is set, we will keep the outbound proxy during the whole 03978 dialog, regardless of what the SIP rfc says 03979 */ 03980 if (p->outboundproxy && !p->outboundproxy->force){ 03981 ref_proxy(p, NULL); 03982 } 03983 03984 for (cur = p->packets; cur; prev = cur, cur = cur->next) { 03985 if (cur->seqno != seqno || cur->is_resp != resp) { 03986 continue; 03987 } 03988 if (cur->is_resp || cur->method == sipmethod) { 03989 res = TRUE; 03990 msg = "Found"; 03991 if (!resp && (seqno == p->pendinginvite)) { 03992 ast_debug(1, "Acked pending invite %u\n", p->pendinginvite); 03993 p->pendinginvite = 0; 03994 } 03995 if (cur->retransid > -1) { 03996 if (sipdebug) 03997 ast_debug(4, "** SIP TIMER: Cancelling retransmit of packet (reply received) Retransid #%d\n", cur->retransid); 03998 } 03999 /* This odd section is designed to thwart a 04000 * race condition in the packet scheduler. There are 04001 * two conditions under which deleting the packet from the 04002 * scheduler can fail. 04003 * 04004 * 1. The packet has been removed from the scheduler because retransmission 04005 * is being attempted. The problem is that if the packet is currently attempting 04006 * retransmission and we are at this point in the code, then that MUST mean 04007 * that retrans_pkt is waiting on p's lock. Therefore we will relinquish the 04008 * lock temporarily to allow retransmission. 04009 * 04010 * 2. The packet has reached its maximum number of retransmissions and has 04011 * been permanently removed from the packet scheduler. If this is the case, then 04012 * the packet's retransid will be set to -1. The atomicity of the setting and checking 04013 * of the retransid to -1 is ensured since in both cases p's lock is held. 04014 */ 04015 while (cur->retransid > -1 && ast_sched_del(sched, cur->retransid)) { 04016 sip_pvt_unlock(p); 04017 usleep(1); 04018 sip_pvt_lock(p); 04019 } 04020 UNLINK(cur, p->packets, prev); 04021 dialog_unref(cur->owner, "unref pkt cur->owner dialog from sip ack before freeing pkt"); 04022 if (cur->data) { 04023 ast_free(cur->data); 04024 } 04025 ast_free(cur); 04026 break; 04027 } 04028 } 04029 ast_debug(1, "Stopping retransmission on '%s' of %s %u: Match %s\n", 04030 p->callid, resp ? "Response" : "Request", seqno, msg); 04031 return res; 04032 }
| 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 3832 of file chan_sip.c.
References __sip_pretend_ack(), append_history, AST_CAUSE_PROTOCOL_ERROR, ast_channel_unlock, ast_channel_unref, ast_debug, AST_EXTENSION_DEACTIVATED, ast_log(), ast_queue_hangup_with_cause(), dialog_unlink_all(), LOG_WARNING, method_match(), NONE, pvt_set_needdestroy(), sip_methods, sip_pvt_lock, sip_pvt_lock_full(), sip_pvt_unlock, sip_scheddestroy(), stop_media_flows(), cfsip_methods::text, transmit_request_with_auth(), transmit_state_notify(), and TRUE.
Referenced by sip_scheddestroy(), and sip_show_sched().
03833 { 03834 struct sip_pvt *p = (struct sip_pvt *)data; 03835 struct ast_channel *owner; 03836 03837 /* If this is a subscription, tell the phone that we got a timeout */ 03838 if (p->subscribed && p->subscribed != MWI_NOTIFICATION && p->subscribed != CALL_COMPLETION) { 03839 transmit_state_notify(p, AST_EXTENSION_DEACTIVATED, 1, TRUE); /* Send last notification */ 03840 p->subscribed = NONE; 03841 append_history(p, "Subscribestatus", "timeout"); 03842 ast_debug(3, "Re-scheduled destruction of SIP subscription %s\n", p->callid ? p->callid : "<unknown>"); 03843 return 10000; /* Reschedule this destruction so that we know that it's gone */ 03844 } 03845 03846 /* If there are packets still waiting for delivery, delay the destruction */ 03847 if (p->packets) { 03848 if (!p->needdestroy) { 03849 char method_str[31]; 03850 ast_debug(3, "Re-scheduled destruction of SIP call %s\n", p->callid ? p->callid : "<unknown>"); 03851 append_history(p, "ReliableXmit", "timeout"); 03852 if (sscanf(p->lastmsg, "Tx: %30s", method_str) == 1 || sscanf(p->lastmsg, "Rx: %30s", method_str) == 1) { 03853 if (p->ongoing_reinvite || method_match(SIP_CANCEL, method_str) || method_match(SIP_BYE, method_str)) { 03854 pvt_set_needdestroy(p, "autodestruct"); 03855 } 03856 } 03857 return 10000; 03858 } else { 03859 /* They've had their chance to respond. Time to bail */ 03860 __sip_pretend_ack(p); 03861 } 03862 } 03863 03864 /* Reset schedule ID */ 03865 p->autokillid = -1; 03866 03867 /* 03868 * Lock both the pvt and the channel safely so that we can queue up a frame. 03869 */ 03870 owner = sip_pvt_lock_full(p); 03871 if (owner) { 03872 ast_log(LOG_WARNING, "Autodestruct on dialog '%s' with owner in place (Method: %s). Rescheduling destruction for 10000 ms\n", p->callid, sip_methods[p->method].text); 03873 ast_queue_hangup_with_cause(owner, AST_CAUSE_PROTOCOL_ERROR); 03874 ast_channel_unlock(owner); 03875 ast_channel_unref(owner); 03876 sip_pvt_unlock(p); 03877 return 10000; 03878 } else if (p->refer && !p->alreadygone) { 03879 ast_debug(3, "Finally hanging up channel after transfer: %s\n", p->callid); 03880 stop_media_flows(p); 03881 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 03882 append_history(p, "ReferBYE", "Sending BYE on transferer call leg %s", p->callid); 03883 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 03884 } else { 03885 append_history(p, "AutoDestroy", "%s", p->callid); 03886 ast_debug(3, "Auto destroying SIP dialog '%s'\n", p->callid); 03887 sip_pvt_unlock(p); 03888 dialog_unlink_all(p); /* once it's unlinked and unrefd everywhere, it'll be freed automagically */ 03889 sip_pvt_lock(p); 03890 /* dialog_unref(p, "unref dialog-- no other matching conditions"); -- unlink all now should finish off the dialog's references and free it. */ 03891 /* sip_destroy(p); */ /* Go ahead and destroy dialog. All attempts to recover is done */ 03892 /* sip_destroy also absorbs the reference */ 03893 } 03894 03895 sip_pvt_unlock(p); 03896 03897 dialog_unref(p, "The ref to a dialog passed to this sched callback is going out of scope; unref it."); 03898 03899 return 0; 03900 }
| void __sip_destroy | ( | struct sip_pvt * | p, | |
| int | lockowner, | |||
| int | lockdialoglist | |||
| ) |
Execute destruction of SIP dialog structure, release memory.
Definition at line 5737 of file chan_sip.c.
References ao2_ref, ao2_t_ref, ast_cc_config_params_destroy(), ast_channel_lock, ast_channel_unlock, ast_debug, ast_free, ast_free_ha(), AST_LIST_REMOVE_HEAD, ast_rtp_instance_destroy(), AST_SOFTHANGUP_DEV, ast_string_field_free_memory, ast_test_flag, ast_udptl_destroy(), ast_variables_destroy(), ast_verbose, deinit_req(), free_old_route(), registry_unref(), sip_debug_test_pvt(), sip_dump_history(), sip_methods, sip_srtp_destroy(), stop_session_timer(), cfsip_methods::text, unref_peer(), and update_call_counter().
Referenced by sip_destroy().
05738 { 05739 struct sip_request *req; 05740 05741 /* Destroy Session-Timers if allocated */ 05742 if (p->stimer) { 05743 p->stimer->quit_flag = 1; 05744 stop_session_timer(p); 05745 ast_free(p->stimer); 05746 p->stimer = NULL; 05747 } 05748 05749 if (sip_debug_test_pvt(p)) 05750 ast_verbose("Really destroying SIP dialog '%s' Method: %s\n", p->callid, sip_methods[p->method].text); 05751 05752 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 05753 update_call_counter(p, DEC_CALL_LIMIT); 05754 ast_debug(2, "This call did not properly clean up call limits. Call ID %s\n", p->callid); 05755 } 05756 05757 /* Unlink us from the owner if we have one */ 05758 if (p->owner) { 05759 if (lockowner) 05760 ast_channel_lock(p->owner); 05761 ast_debug(1, "Detaching from %s\n", p->owner->name); 05762 p->owner->tech_pvt = NULL; 05763 /* Make sure that the channel knows its backend is going away */ 05764 p->owner->_softhangup |= AST_SOFTHANGUP_DEV; 05765 if (lockowner) 05766 ast_channel_unlock(p->owner); 05767 /* Give the channel a chance to react before deallocation */ 05768 usleep(1); 05769 } 05770 05771 /* Remove link from peer to subscription of MWI */ 05772 if (p->relatedpeer && p->relatedpeer->mwipvt) 05773 p->relatedpeer->mwipvt = dialog_unref(p->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt"); 05774 if (p->relatedpeer && p->relatedpeer->call == p) 05775 p->relatedpeer->call = dialog_unref(p->relatedpeer->call, "unset the relatedpeer->call field in tandem with relatedpeer field itself"); 05776 05777 if (p->relatedpeer) 05778 p->relatedpeer = unref_peer(p->relatedpeer,"unsetting a dialog relatedpeer field in sip_destroy"); 05779 05780 if (p->registry) { 05781 if (p->registry->call == p) 05782 p->registry->call = dialog_unref(p->registry->call, "nulling out the registry's call dialog field in unlink_all"); 05783 p->registry = registry_unref(p->registry, "delete p->registry"); 05784 } 05785 05786 if (p->mwi) { 05787 p->mwi->call = NULL; 05788 } 05789 05790 if (dumphistory) 05791 sip_dump_history(p); 05792 05793 if (p->options) 05794 ast_free(p->options); 05795 05796 if (p->notify) { 05797 ast_variables_destroy(p->notify->headers); 05798 ast_free(p->notify->content); 05799 ast_free(p->notify); 05800 } 05801 if (p->rtp) { 05802 ast_rtp_instance_destroy(p->rtp); 05803 } 05804 if (p->vrtp) { 05805 ast_rtp_instance_destroy(p->vrtp); 05806 } 05807 if (p->trtp) { 05808 ast_rtp_instance_destroy(p->trtp); 05809 } 05810 if (p->udptl) 05811 ast_udptl_destroy(p->udptl); 05812 if (p->refer) { 05813 if (p->refer->refer_call) { 05814 p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); 05815 } 05816 ast_free(p->refer); 05817 } 05818 if (p->route) { 05819 free_old_route(p->route); 05820 p->route = NULL; 05821 } 05822 deinit_req(&p->initreq); 05823 05824 /* Clear history */ 05825 if (p->history) { 05826 struct sip_history *hist; 05827 while ( (hist = AST_LIST_REMOVE_HEAD(p->history, list)) ) { 05828 ast_free(hist); 05829 p->history_entries--; 05830 } 05831 ast_free(p->history); 05832 p->history = NULL; 05833 } 05834 05835 while ((req = AST_LIST_REMOVE_HEAD(&p->request_queue, next))) { 05836 ast_free(req); 05837 } 05838 05839 if (p->chanvars) { 05840 ast_variables_destroy(p->chanvars); 05841 p->chanvars = NULL; 05842 } 05843 05844 if (p->srtp) { 05845 sip_srtp_destroy(p->srtp); 05846 p->srtp = NULL; 05847 } 05848 05849 if (p->vsrtp) { 05850 sip_srtp_destroy(p->vsrtp); 05851 p->vsrtp = NULL; 05852 } 05853 05854 if (p->tsrtp) { 05855 sip_srtp_destroy(p->tsrtp); 05856 p->tsrtp = NULL; 05857 } 05858 05859 if (p->directmediaha) { 05860 ast_free_ha(p->directmediaha); 05861 p->directmediaha = NULL; 05862 } 05863 05864 ast_string_field_free_memory(p); 05865 05866 ast_cc_config_params_destroy(p->cc_params); 05867 05868 if (p->epa_entry) { 05869 ao2_ref(p->epa_entry, -1); 05870 p->epa_entry = NULL; 05871 } 05872 05873 if (p->socket.tcptls_session) { 05874 ao2_ref(p->socket.tcptls_session, -1); 05875 p->socket.tcptls_session = NULL; 05876 } 05877 05878 if (p->peerauth) { 05879 ao2_t_ref(p->peerauth, -1, "Removing active peer authentication"); 05880 p->peerauth = NULL; 05881 } 05882 }
| static int __sip_do_register | ( | struct sip_registry * | r | ) | [static] |
Register with SIP proxy.
Definition at line 13164 of file chan_sip.c.
References transmit_register().
Referenced by sip_reregister().
13165 { 13166 int res; 13167 13168 res = transmit_register(r, SIP_REGISTER, NULL, NULL); 13169 return res; 13170 }
| void __sip_pretend_ack | ( | struct sip_pvt * | p | ) |
Pretend to ack all packets called with p locked.
Definition at line 4036 of file chan_sip.c.
References __sip_ack(), ast_log(), find_sip_method(), LOG_WARNING, sip_methods, and cfsip_methods::text.
Referenced by __sip_autodestruct(), handle_request_bye(), handle_request_cancel(), and sip_reg_timeout().
04037 { 04038 struct sip_pkt *cur = NULL; 04039 04040 while (p->packets) { 04041 int method; 04042 if (cur == p->packets) { 04043 ast_log(LOG_WARNING, "Have a packet that doesn't want to give up! %s\n", sip_methods[cur->method].text); 04044 return; 04045 } 04046 cur = p->packets; 04047 method = (cur->method) ? cur->method : find_sip_method(cur->data->str); 04048 __sip_ack(p, cur->seqno, cur->is_resp, method); 04049 } 04050 }
| 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 3741 of file chan_sip.c.
References __sip_xmit(), append_history, ast_calloc, ast_debug, ast_free, ast_log(), AST_PTHREADT_NULL, AST_SCHED_DEL, AST_SCHED_REPLACE_VARIABLE, ast_str_buffer(), ast_str_create(), ast_str_set(), ast_str_strlen(), ast_tvnow(), DEFAULT_RETRANS, LOG_ERROR, and retrans_pkt().
Referenced by send_request(), and send_response().
03742 { 03743 struct sip_pkt *pkt = NULL; 03744 int siptimer_a = DEFAULT_RETRANS; 03745 int xmitres = 0; 03746 int respid; 03747 03748 if (sipmethod == SIP_INVITE) { 03749 /* Note this is a pending invite */ 03750 p->pendinginvite = seqno; 03751 } 03752 03753 /* If the transport is something reliable (TCP or TLS) then don't really send this reliably */ 03754 /* I removed the code from retrans_pkt that does the same thing so it doesn't get loaded into the scheduler */ 03755 /*! \todo According to the RFC some packets need to be retransmitted even if its TCP, so this needs to get revisited */ 03756 if (!(p->socket.type & SIP_TRANSPORT_UDP)) { 03757 xmitres = __sip_xmit(p, data); /* Send packet */ 03758 if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ 03759 append_history(p, "XmitErr", "%s", fatal ? "(Critical)" : "(Non-critical)"); 03760 return AST_FAILURE; 03761 } else { 03762 return AST_SUCCESS; 03763 } 03764 } 03765 03766 if (!(pkt = ast_calloc(1, sizeof(*pkt)))) { 03767 return AST_FAILURE; 03768 } 03769 /* copy data, add a terminator and save length */ 03770 if (!(pkt->data = ast_str_create(ast_str_strlen(data)))) { 03771 ast_free(pkt); 03772 return AST_FAILURE; 03773 } 03774 ast_str_set(&pkt->data, 0, "%s%s", data->str, "\0"); 03775 /* copy other parameters from the caller */ 03776 pkt->method = sipmethod; 03777 pkt->seqno = seqno; 03778 pkt->is_resp = resp; 03779 pkt->is_fatal = fatal; 03780 pkt->owner = dialog_ref(p, "__sip_reliable_xmit: setting pkt->owner"); 03781 pkt->next = p->packets; 03782 p->packets = pkt; /* Add it to the queue */ 03783 if (resp) { 03784 /* Parse out the response code */ 03785 if (sscanf(ast_str_buffer(pkt->data), "SIP/2.0 %30u", &respid) == 1) { 03786 pkt->response_code = respid; 03787 } 03788 } 03789 pkt->timer_t1 = p->timer_t1; /* Set SIP timer T1 */ 03790 pkt->retransid = -1; 03791 if (pkt->timer_t1) { 03792 siptimer_a = pkt->timer_t1; 03793 } 03794 03795 pkt->time_sent = ast_tvnow(); /* time packet was sent */ 03796 pkt->retrans_stop_time = 64 * (pkt->timer_t1 ? pkt->timer_t1 : DEFAULT_TIMER_T1); /* time in ms after pkt->time_sent to stop retransmission */ 03797 03798 /* Schedule retransmission */ 03799 AST_SCHED_REPLACE_VARIABLE(pkt->retransid, sched, siptimer_a, retrans_pkt, pkt, 1); 03800 if (sipdebug) { 03801 ast_debug(4, "*** SIP TIMER: Initializing retransmit timer on packet: Id #%d\n", pkt->retransid); 03802 } 03803 03804 xmitres = __sip_xmit(pkt->owner, pkt->data); /* Send packet */ 03805 03806 if (xmitres == XMIT_ERROR) { /* Serious network trouble, no need to try again */ 03807 append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03808 ast_log(LOG_ERROR, "Serious Network Trouble; __sip_xmit returns error for pkt data\n"); 03809 AST_SCHED_DEL(sched, pkt->retransid); 03810 p->packets = pkt->next; 03811 pkt->owner = dialog_unref(pkt->owner,"pkt is being freed, its dialog ref is dead now"); 03812 ast_free(pkt->data); 03813 ast_free(pkt); 03814 return AST_FAILURE; 03815 } else { 03816 /* This is odd, but since the retrans timer starts at 500ms and the do_monitor thread 03817 * only wakes up every 1000ms by default, we have to poke the thread here to make 03818 * sure it successfully detects this must be retransmitted in less time than 03819 * it usually sleeps for. Otherwise it might not retransmit this packet for 1000ms. */ 03820 if (monitor_thread != AST_PTHREADT_NULL) { 03821 pthread_kill(monitor_thread, SIGURG); 03822 } 03823 return AST_SUCCESS; 03824 } 03825 }
| 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 4053 of file chan_sip.c.
References ast_debug, AST_SCHED_DEL, FALSE, method_match(), sip_methods, cfsip_methods::text, and TRUE.
Referenced by handle_response(), and sip_hangup().
04054 { 04055 struct sip_pkt *cur; 04056 int res = FALSE; 04057 04058 for (cur = p->packets; cur; cur = cur->next) { 04059 if (cur->seqno == seqno && cur->is_resp == resp && 04060 (cur->is_resp || method_match(sipmethod, cur->data->str))) { 04061 /* this is our baby */ 04062 if (cur->retransid > -1) { 04063 if (sipdebug) 04064 ast_debug(4, "*** SIP TIMER: Cancelling retransmission #%d - %s (got response)\n", cur->retransid, sip_methods[sipmethod].text); 04065 } 04066 AST_SCHED_DEL(sched, cur->retransid); 04067 res = TRUE; 04068 break; 04069 } 04070 } 04071 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"); 04072 return res; 04073 }
| static int __sip_subscribe_mwi_do | ( | struct sip_subscription_mwi * | mwi | ) | [static] |
Actually setup an MWI subscription or resubscribe.
Definition at line 12475 of file chan_sip.c.
References ast_dnsmgr_lookup_cb(), ast_set_flag, ast_sip_ouraddrfor(), ast_sockaddr_port, ast_sockaddr_set_port, ast_string_field_set, ast_strlen_zero(), ASTOBJ_REF, ASTOBJ_UNREF, build_contact(), build_via(), change_callid_pvt(), create_addr(), dialog_unlink_all(), get_address_family_filter(), get_srv_protocol(), get_srv_service(), MAXHOSTNAMELEN, obproxy_get(), on_dns_update_mwi(), ref_proxy(), set_socket_transport(), sip_alloc(), sip_cfg, sip_subscribe_mwi_destroy(), and transmit_invite().
Referenced by sip_subscribe_mwi_do().
12476 { 12477 /* If we have no DNS manager let's do a lookup */ 12478 if (!mwi->dnsmgr) { 12479 char transport[MAXHOSTNAMELEN]; 12480 struct sip_subscription_mwi *saved; 12481 snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(mwi->transport), get_srv_protocol(mwi->transport)); 12482 12483 mwi->us.ss.ss_family = get_address_family_filter(mwi->transport); /* Filter address family */ 12484 saved = ASTOBJ_REF(mwi); 12485 ast_dnsmgr_lookup_cb(mwi->hostname, &mwi->us, &mwi->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_mwi, saved); 12486 if (!mwi->dnsmgr) { 12487 ASTOBJ_UNREF(saved, sip_subscribe_mwi_destroy); /* dnsmgr disabled, remove reference */ 12488 } 12489 } 12490 12491 /* If we already have a subscription up simply send a resubscription */ 12492 if (mwi->call) { 12493 transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 0, NULL); 12494 return 0; 12495 } 12496 12497 /* Create a dialog that we will use for the subscription */ 12498 if (!(mwi->call = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) { 12499 return -1; 12500 } 12501 12502 ref_proxy(mwi->call, obproxy_get(mwi->call, NULL)); 12503 12504 if (!ast_sockaddr_port(&mwi->us) && mwi->portno) { 12505 ast_sockaddr_set_port(&mwi->us, mwi->portno); 12506 } 12507 12508 /* Setup the destination of our subscription */ 12509 if (create_addr(mwi->call, mwi->hostname, &mwi->us, 0, NULL)) { 12510 dialog_unlink_all(mwi->call); 12511 mwi->call = dialog_unref(mwi->call, "unref dialog after unlink_all"); 12512 return 0; 12513 } 12514 12515 mwi->call->expiry = mwi_expiry; 12516 12517 if (!mwi->dnsmgr && mwi->portno) { 12518 ast_sockaddr_set_port(&mwi->call->sa, mwi->portno); 12519 ast_sockaddr_set_port(&mwi->call->recv, mwi->portno); 12520 } else { 12521 mwi->portno = ast_sockaddr_port(&mwi->call->sa); 12522 } 12523 12524 /* Set various other information */ 12525 if (!ast_strlen_zero(mwi->authuser)) { 12526 ast_string_field_set(mwi->call, peername, mwi->authuser); 12527 ast_string_field_set(mwi->call, authname, mwi->authuser); 12528 ast_string_field_set(mwi->call, fromuser, mwi->authuser); 12529 } else { 12530 ast_string_field_set(mwi->call, peername, mwi->username); 12531 ast_string_field_set(mwi->call, authname, mwi->username); 12532 ast_string_field_set(mwi->call, fromuser, mwi->username); 12533 } 12534 ast_string_field_set(mwi->call, username, mwi->username); 12535 if (!ast_strlen_zero(mwi->secret)) { 12536 ast_string_field_set(mwi->call, peersecret, mwi->secret); 12537 } 12538 set_socket_transport(&mwi->call->socket, mwi->transport); 12539 mwi->call->socket.port = htons(mwi->portno); 12540 ast_sip_ouraddrfor(&mwi->call->sa, &mwi->call->ourip, mwi->call); 12541 build_contact(mwi->call); 12542 build_via(mwi->call); 12543 12544 /* Change the dialog callid. */ 12545 change_callid_pvt(mwi->call, NULL); 12546 12547 ast_set_flag(&mwi->call->flags[0], SIP_OUTGOING); 12548 12549 /* Associate the call with us */ 12550 mwi->call->mwi = ASTOBJ_REF(mwi); 12551 12552 mwi->call->subscribed = MWI_NOTIFICATION; 12553 12554 /* Actually send the packet */ 12555 transmit_invite(mwi->call, SIP_SUBSCRIBE, 0, 2, NULL); 12556 12557 return 0; 12558 }
| static int __sip_xmit | ( | struct sip_pvt * | p, | |
| struct ast_str * | data | |||
| ) | [static] |
Definition at line 3341 of file chan_sip.c.
References ast_debug, ast_log(), ast_sendto(), ast_sockaddr_stringify(), ast_str_strlen(), errno, get_transport_pvt(), LOG_WARNING, sip_prepare_socket(), sip_real_dst(), and sip_tcptls_write().
Referenced by __sip_reliable_xmit(), retrans_pkt(), send_request(), and send_response().
03342 { 03343 int res = 0; 03344 const struct ast_sockaddr *dst = sip_real_dst(p); 03345 03346 ast_debug(2, "Trying to put '%.11s' onto %s socket destined for %s\n", data->str, get_transport_pvt(p), ast_sockaddr_stringify(dst)); 03347 03348 if (sip_prepare_socket(p) < 0) { 03349 return XMIT_ERROR; 03350 } 03351 03352 if (p->socket.type == SIP_TRANSPORT_UDP) { 03353 res = ast_sendto(p->socket.fd, data->str, ast_str_strlen(data), 0, dst); 03354 } else if (p->socket.tcptls_session) { 03355 res = sip_tcptls_write(p->socket.tcptls_session, data->str, ast_str_strlen(data)); 03356 } else { 03357 ast_debug(2, "Socket type is TCP but no tcptls_session is present to write to\n"); 03358 return XMIT_ERROR; 03359 } 03360 03361 if (res == -1) { 03362 switch (errno) { 03363 case EBADF: /* Bad file descriptor - seems like this is generated when the host exist, but doesn't accept the UDP packet */ 03364 case EHOSTUNREACH: /* Host can't be reached */ 03365 case ENETDOWN: /* Interface down */ 03366 case ENETUNREACH: /* Network failure */ 03367 case ECONNREFUSED: /* ICMP port unreachable */ 03368 res = XMIT_ERROR; /* Don't bother with trying to transmit again */ 03369 } 03370 } 03371 if (res != ast_str_strlen(data)) { 03372 ast_log(LOG_WARNING, "sip_xmit of %p (len %zu) to %s returned %d: %s\n", data, ast_str_strlen(data), ast_sockaddr_stringify(dst), res, strerror(errno)); 03373 } 03374 03375 return res; 03376 }
| static int __transmit_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Base transmit response function.
Definition at line 10499 of file chan_sip.c.
References add_cc_call_info_to_response(), add_diversion_header(), add_header(), add_rpid(), ast_cause2str(), ast_clear_flag, ast_log(), ast_test_flag, get_header(), hangup_sip2cause(), LOG_WARNING, respprep(), and send_response().
Referenced by transmit_response(), transmit_response_reliable(), and transmit_response_using_temp().
10500 { 10501 struct sip_request resp; 10502 uint32_t seqno = 0; 10503 10504 if (reliable && (sscanf(get_header(req, "CSeq"), "%30u ", &seqno) != 1)) { 10505 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 10506 return -1; 10507 } 10508 respprep(&resp, p, msg, req); 10509 10510 if (ast_test_flag(&p->flags[0], SIP_SENDRPID) 10511 && ast_test_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND) 10512 && (!strncmp(msg, "180", 3) || !strncmp(msg, "183", 3))) { 10513 ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND); 10514 add_rpid(&resp, p); 10515 } 10516 if (ast_test_flag(&p->flags[0], SIP_OFFER_CC)) { 10517 add_cc_call_info_to_response(p, &resp); 10518 } 10519 10520 /* If we are sending a 302 Redirect we can add a diversion header if the redirect information is set */ 10521 if (!strncmp(msg, "302", 3)) { 10522 add_diversion_header(&resp, p); 10523 } 10524 10525 /* If we are cancelling an incoming invite for some reason, add information 10526 about the reason why we are doing this in clear text */ 10527 if (p->method == SIP_INVITE && msg[0] != '1') { 10528 char buf[20]; 10529 10530 if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON)) { 10531 int hangupcause = 0; 10532 10533 if (p->owner && p->owner->hangupcause) { 10534 hangupcause = p->owner->hangupcause; 10535 } else if (p->hangupcause) { 10536 hangupcause = p->hangupcause; 10537 } else { 10538 int respcode; 10539 if (sscanf(msg, "%30d ", &respcode)) 10540 hangupcause = hangup_sip2cause(respcode); 10541 } 10542 10543 if (hangupcause) { 10544 sprintf(buf, "Q.850;cause=%i", hangupcause & 0x7f); 10545 add_header(&resp, "Reason", buf); 10546 } 10547 } 10548 10549 if (p->owner && p->owner->hangupcause) { 10550 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->owner->hangupcause)); 10551 snprintf(buf, sizeof(buf), "%d", p->owner->hangupcause); 10552 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 10553 } 10554 } 10555 return send_response(p, &resp, reliable, seqno); 10556 }
| static char * _sip_qualify_peer | ( | int | type, | |
| int | fd, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Send qualify message to peer from cli or manager. Mostly for debugging.
Definition at line 17418 of file chan_sip.c.
References ast_cli(), astman_send_error(), CLI_SHOWUSAGE, CLI_SUCCESS, FALSE, find_peer(), sip_poke_peer(), TRUE, and unref_peer().
Referenced by manager_sip_qualify_peer(), and sip_qualify_peer().
17419 { 17420 struct sip_peer *peer; 17421 int load_realtime; 17422 17423 if (argc < 4) 17424 return CLI_SHOWUSAGE; 17425 17426 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 17427 if ((peer = find_peer(argv[3], NULL, load_realtime, FINDPEERS, FALSE, 0))) { 17428 sip_poke_peer(peer, 1); 17429 unref_peer(peer, "qualify: done with peer"); 17430 } else if (type == 0) { 17431 ast_cli(fd, "Peer '%s' not found\n", argv[3]); 17432 } else { 17433 astman_send_error(s, m, "Peer not found"); 17434 } 17435 return CLI_SUCCESS; 17436 }
| static char * _sip_show_peer | ( | int | type, | |
| int | fd, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Show one peer in detail (main function).
Definition at line 17503 of file chan_sip.c.
References allowoverlap2str(), ao2_lock, ao2_t_ref, ao2_unlock, ARRAY_LEN, ast_callerid_merge(), ast_cdr_flags2str(), ast_check_realtime(), ast_cli(), AST_CLI_YESNO, ast_codec_pref_index(), ast_describe_caller_presentation(), ast_getformatname(), ast_getformatname_multiple(), AST_LIST_TRAVERSE, ast_print_group(), ast_sched_when(), ast_sockaddr_port, ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_str_alloca, ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), astman_send_error(), CLI_SHOWUSAGE, CLI_SUCCESS, dtmfmode2str(), FALSE, faxec2str(), find_peer(), get_transport(), get_transport_list(), insecure2str(), ast_variable::name, ast_variable::next, peer_mailboxes_to_str(), peer_status(), print_codec_to_cli(), print_group(), S_OR, sip_cfg, status, stmode2str(), strefresher2str(), text, transfermode2str(), TRUE, unref_peer(), and ast_variable::value.
Referenced by manager_sip_show_peer(), and sip_show_peer().
17504 { 17505 char status[30] = ""; 17506 char cbuf[256]; 17507 struct sip_peer *peer; 17508 char codec_buf[512]; 17509 struct ast_codec_pref *pref; 17510 struct ast_variable *v; 17511 int x = 0, load_realtime; 17512 format_t codec = 0; 17513 int realtimepeers; 17514 17515 realtimepeers = ast_check_realtime("sippeers"); 17516 17517 if (argc < 4) 17518 return CLI_SHOWUSAGE; 17519 17520 load_realtime = (argc == 5 && !strcmp(argv[4], "load")) ? TRUE : FALSE; 17521 peer = find_peer(argv[3], NULL, load_realtime, FINDPEERS, FALSE, 0); 17522 17523 if (s) { /* Manager */ 17524 if (peer) { 17525 const char *id = astman_get_header(m, "ActionID"); 17526 17527 astman_append(s, "Response: Success\r\n"); 17528 if (!ast_strlen_zero(id)) 17529 astman_append(s, "ActionID: %s\r\n", id); 17530 } else { 17531 snprintf (cbuf, sizeof(cbuf), "Peer %s not found.", argv[3]); 17532 astman_send_error(s, m, cbuf); 17533 return CLI_SUCCESS; 17534 } 17535 } 17536 if (peer && type==0 ) { /* Normal listing */ 17537 struct ast_str *mailbox_str = ast_str_alloca(512); 17538 struct sip_auth_container *credentials; 17539 17540 ao2_lock(peer); 17541 credentials = peer->auth; 17542 if (credentials) { 17543 ao2_t_ref(credentials, +1, "Ref peer auth for show"); 17544 } 17545 ao2_unlock(peer); 17546 17547 ast_cli(fd, "\n\n"); 17548 ast_cli(fd, " * Name : %s\n", peer->name); 17549 if (realtimepeers) { /* Realtime is enabled */ 17550 ast_cli(fd, " Realtime peer: %s\n", peer->is_realtime ? "Yes, cached" : "No"); 17551 } 17552 ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>"); 17553 ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>"); 17554 ast_cli(fd, " Remote Secret: %s\n", ast_strlen_zero(peer->remotesecret)?"<Not set>":"<Set>"); 17555 if (credentials) { 17556 struct sip_auth *auth; 17557 17558 AST_LIST_TRAVERSE(&credentials->list, auth, node) { 17559 ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s %s\n", 17560 auth->realm, 17561 auth->username, 17562 !ast_strlen_zero(auth->secret) 17563 ? "<Secret set>" 17564 : (!ast_strlen_zero(auth->md5secret) 17565 ? "<MD5secret set>" : "<Not set>")); 17566 } 17567 ao2_t_ref(credentials, -1, "Unref peer auth for show"); 17568 } 17569 ast_cli(fd, " Context : %s\n", peer->context); 17570 ast_cli(fd, " Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") ); 17571 ast_cli(fd, " Language : %s\n", peer->language); 17572 if (!ast_strlen_zero(peer->accountcode)) 17573 ast_cli(fd, " Accountcode : %s\n", peer->accountcode); 17574 ast_cli(fd, " AMA flags : %s\n", ast_cdr_flags2str(peer->amaflags)); 17575 ast_cli(fd, " Transfer mode: %s\n", transfermode2str(peer->allowtransfer)); 17576 ast_cli(fd, " CallingPres : %s\n", ast_describe_caller_presentation(peer->callingpres)); 17577 if (!ast_strlen_zero(peer->fromuser)) 17578 ast_cli(fd, " FromUser : %s\n", peer->fromuser); 17579 if (!ast_strlen_zero(peer->fromdomain)) 17580 ast_cli(fd, " FromDomain : %s Port %d\n", peer->fromdomain, (peer->fromdomainport) ? peer->fromdomainport : STANDARD_SIP_PORT); 17581 ast_cli(fd, " Callgroup : "); 17582 print_group(fd, peer->callgroup, 0); 17583 ast_cli(fd, " Pickupgroup : "); 17584 print_group(fd, peer->pickupgroup, 0); 17585 peer_mailboxes_to_str(&mailbox_str, peer); 17586 ast_cli(fd, " MOH Suggest : %s\n", peer->mohsuggest); 17587 ast_cli(fd, " Mailbox : %s\n", mailbox_str->str); 17588 ast_cli(fd, " VM Extension : %s\n", peer->vmexten); 17589 ast_cli(fd, " LastMsgsSent : %d/%d\n", (peer->lastmsgssent & 0x7fff0000) >> 16, peer->lastmsgssent & 0xffff); 17590 ast_cli(fd, " Call limit : %d\n", peer->call_limit); 17591 ast_cli(fd, " Max forwards : %d\n", peer->maxforwards); 17592 if (peer->busy_level) 17593 ast_cli(fd, " Busy level : %d\n", peer->busy_level); 17594 ast_cli(fd, " Dynamic : %s\n", AST_CLI_YESNO(peer->host_dynamic)); 17595 ast_cli(fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "<unspecified>")); 17596 ast_cli(fd, " MaxCallBR : %d kbps\n", peer->maxcallbitrate); 17597 ast_cli(fd, " Expire : %ld\n", ast_sched_when(sched, peer->expire)); 17598 ast_cli(fd, " Insecure : %s\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE))); 17599 ast_cli(fd, " Force rport : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT))); 17600 ast_cli(fd, " ACL : %s\n", AST_CLI_YESNO(peer->ha != NULL)); 17601 ast_cli(fd, " DirectMedACL : %s\n", AST_CLI_YESNO(peer->directmediaha != NULL)); 17602 ast_cli(fd, " T.38 support : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 17603 ast_cli(fd, " T.38 EC mode : %s\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 17604 ast_cli(fd, " T.38 MaxDtgrm: %d\n", peer->t38_maxdatagram); 17605 ast_cli(fd, " DirectMedia : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA))); 17606 ast_cli(fd, " PromiscRedir : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR))); 17607 ast_cli(fd, " User=Phone : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_USEREQPHONE))); 17608 ast_cli(fd, " Video Support: %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) || ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS))); 17609 ast_cli(fd, " Text Support : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT))); 17610 ast_cli(fd, " Ign SDP ver : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_IGNORESDPVERSION))); 17611 ast_cli(fd, " Trust RPID : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_TRUSTRPID))); 17612 ast_cli(fd, " Send RPID : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[0], SIP_SENDRPID))); 17613 ast_cli(fd, " Subscriptions: %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); 17614 ast_cli(fd, " Overlap dial : %s\n", allowoverlap2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWOVERLAP))); 17615 if (peer->outboundproxy) 17616 ast_cli(fd, " Outb. proxy : %s %s\n", ast_strlen_zero(peer->outboundproxy->name) ? "<not set>" : peer->outboundproxy->name, 17617 peer->outboundproxy->force ? "(forced)" : ""); 17618 17619 /* - is enumerated */ 17620 ast_cli(fd, " DTMFmode : %s\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 17621 ast_cli(fd, " Timer T1 : %d\n", peer->timer_t1); 17622 ast_cli(fd, " Timer B : %d\n", peer->timer_b); 17623 ast_cli(fd, " ToHost : %s\n", peer->tohost); 17624 ast_cli(fd, " Addr->IP : %s\n", ast_sockaddr_stringify(&peer->addr)); 17625 ast_cli(fd, " Defaddr->IP : %s\n", ast_sockaddr_stringify(&peer->defaddr)); 17626 ast_cli(fd, " Prim.Transp. : %s\n", get_transport(peer->socket.type)); 17627 ast_cli(fd, " Allowed.Trsp : %s\n", get_transport_list(peer->transports)); 17628 if (!ast_strlen_zero(sip_cfg.regcontext)) 17629 ast_cli(fd, " Reg. exten : %s\n", peer->regexten); 17630 ast_cli(fd, " Def. Username: %s\n", peer->username); 17631 ast_cli(fd, " SIP Options : "); 17632 if (peer->sipoptions) { 17633 int lastoption = -1; 17634 for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { 17635 if (sip_options[x].id != lastoption) { 17636 if (peer->sipoptions & sip_options[x].id) 17637 ast_cli(fd, "%s ", sip_options[x].text); 17638 lastoption = x; 17639 } 17640 } 17641 } else 17642 ast_cli(fd, "(none)"); 17643 17644 ast_cli(fd, "\n"); 17645 ast_cli(fd, " Codecs : "); 17646 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 17647 ast_cli(fd, "%s\n", codec_buf); 17648 ast_cli(fd, " Codec Order : ("); 17649 print_codec_to_cli(fd, &peer->prefs); 17650 ast_cli(fd, ")\n"); 17651 17652 ast_cli(fd, " Auto-Framing : %s \n", AST_CLI_YESNO(peer->autoframing)); 17653 ast_cli(fd, " Status : "); 17654 peer_status(peer, status, sizeof(status)); 17655 ast_cli(fd, "%s\n", status); 17656 ast_cli(fd, " Useragent : %s\n", peer->useragent); 17657 ast_cli(fd, " Reg. Contact : %s\n", peer->fullcontact); 17658 ast_cli(fd, " Qualify Freq : %d ms\n", peer->qualifyfreq); 17659 if (peer->chanvars) { 17660 ast_cli(fd, " Variables :\n"); 17661 for (v = peer->chanvars ; v ; v = v->next) 17662 ast_cli(fd, " %s = %s\n", v->name, v->value); 17663 } 17664 17665 ast_cli(fd, " Sess-Timers : %s\n", stmode2str(peer->stimer.st_mode_oper)); 17666 ast_cli(fd, " Sess-Refresh : %s\n", strefresher2str(peer->stimer.st_ref)); 17667 ast_cli(fd, " Sess-Expires : %d secs\n", peer->stimer.st_max_se); 17668 ast_cli(fd, " Min-Sess : %d secs\n", peer->stimer.st_min_se); 17669 ast_cli(fd, " RTP Engine : %s\n", peer->engine); 17670 ast_cli(fd, " Parkinglot : %s\n", peer->parkinglot); 17671 ast_cli(fd, " Use Reason : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON))); 17672 ast_cli(fd, " Encryption : %s\n", AST_CLI_YESNO(ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP))); 17673 ast_cli(fd, "\n"); 17674 peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer ptr"); 17675 } else if (peer && type == 1) { /* manager listing */ 17676 char buffer[256]; 17677 struct ast_str *mailbox_str = ast_str_alloca(512); 17678 astman_append(s, "Channeltype: SIP\r\n"); 17679 astman_append(s, "ObjectName: %s\r\n", peer->name); 17680 astman_append(s, "ChanObjectType: peer\r\n"); 17681 astman_append(s, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y"); 17682 astman_append(s, "RemoteSecretExist: %s\r\n", ast_strlen_zero(peer->remotesecret)?"N":"Y"); 17683 astman_append(s, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y"); 17684 astman_append(s, "Context: %s\r\n", peer->context); 17685 astman_append(s, "Language: %s\r\n", peer->language); 17686 if (!ast_strlen_zero(peer->accountcode)) 17687 astman_append(s, "Accountcode: %s\r\n", peer->accountcode); 17688 astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags)); 17689 astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres)); 17690 if (!ast_strlen_zero(peer->fromuser)) 17691 astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser); 17692 if (!ast_strlen_zero(peer->fromdomain)) 17693 astman_append(s, "SIP-FromDomain: %s\r\nSip-FromDomain-Port: %d\r\n", peer->fromdomain, (peer->fromdomainport) ? peer->fromdomainport : STANDARD_SIP_PORT); 17694 astman_append(s, "Callgroup: "); 17695 astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->callgroup)); 17696 astman_append(s, "Pickupgroup: "); 17697 astman_append(s, "%s\r\n", ast_print_group(buffer, sizeof(buffer), peer->pickupgroup)); 17698 astman_append(s, "MOHSuggest: %s\r\n", peer->mohsuggest); 17699 peer_mailboxes_to_str(&mailbox_str, peer); 17700 astman_append(s, "VoiceMailbox: %s\r\n", mailbox_str->str); 17701 astman_append(s, "TransferMode: %s\r\n", transfermode2str(peer->allowtransfer)); 17702 astman_append(s, "LastMsgsSent: %d\r\n", peer->lastmsgssent); 17703 astman_append(s, "Maxforwards: %d\r\n", peer->maxforwards); 17704 astman_append(s, "Call-limit: %d\r\n", peer->call_limit); 17705 astman_append(s, "Busy-level: %d\r\n", peer->busy_level); 17706 astman_append(s, "MaxCallBR: %d kbps\r\n", peer->maxcallbitrate); 17707 astman_append(s, "Dynamic: %s\r\n", peer->host_dynamic?"Y":"N"); 17708 astman_append(s, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, "")); 17709 astman_append(s, "RegExpire: %ld seconds\r\n", ast_sched_when(sched, peer->expire)); 17710 astman_append(s, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(&peer->flags[0], SIP_INSECURE))); 17711 astman_append(s, "SIP-Forcerport: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT)?"Y":"N")); 17712 astman_append(s, "ACL: %s\r\n", (peer->ha?"Y":"N")); 17713 astman_append(s, "SIP-CanReinvite: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)?"Y":"N")); 17714 astman_append(s, "SIP-DirectMedia: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_DIRECT_MEDIA)?"Y":"N")); 17715 astman_append(s, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_PROMISCREDIR)?"Y":"N")); 17716 astman_append(s, "SIP-UserPhone: %s\r\n", (ast_test_flag(&peer->flags[0], SIP_USEREQPHONE)?"Y":"N")); 17717 astman_append(s, "SIP-VideoSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT)?"Y":"N")); 17718 astman_append(s, "SIP-TextSupport: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT)?"Y":"N")); 17719 astman_append(s, "SIP-T.38Support: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT)?"Y":"N")); 17720 astman_append(s, "SIP-T.38EC: %s\r\n", faxec2str(ast_test_flag(&peer->flags[1], SIP_PAGE2_T38SUPPORT))); 17721 astman_append(s, "SIP-T.38MaxDtgrm: %d\r\n", peer->t38_maxdatagram); 17722 astman_append(s, "SIP-Sess-Timers: %s\r\n", stmode2str(peer->stimer.st_mode_oper)); 17723 astman_append(s, "SIP-Sess-Refresh: %s\r\n", strefresher2str(peer->stimer.st_ref)); 17724 astman_append(s, "SIP-Sess-Expires: %d\r\n", peer->stimer.st_max_se); 17725 astman_append(s, "SIP-Sess-Min: %d\r\n", peer->stimer.st_min_se); 17726 astman_append(s, "SIP-RTP-Engine: %s\r\n", peer->engine); 17727 astman_append(s, "SIP-Encryption: %s\r\n", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP) ? "Y" : "N"); 17728 17729 /* - is enumerated */ 17730 astman_append(s, "SIP-DTMFmode: %s\r\n", dtmfmode2str(ast_test_flag(&peer->flags[0], SIP_DTMF))); 17731 astman_append(s, "ToHost: %s\r\n", peer->tohost); 17732 astman_append(s, "Address-IP: %s\r\nAddress-Port: %d\r\n", ast_sockaddr_stringify_addr(&peer->addr), ast_sockaddr_port(&peer->addr)); 17733 astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_sockaddr_stringify_addr(&peer->defaddr), ast_sockaddr_port(&peer->defaddr)); 17734 astman_append(s, "Default-Username: %s\r\n", peer->username); 17735 if (!ast_strlen_zero(sip_cfg.regcontext)) 17736 astman_append(s, "RegExtension: %s\r\n", peer->regexten); 17737 astman_append(s, "Codecs: "); 17738 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability); 17739 astman_append(s, "%s\r\n", codec_buf); 17740 astman_append(s, "CodecOrder: "); 17741 pref = &peer->prefs; 17742 for(x = 0; x < 64 ; x++) { 17743 codec = ast_codec_pref_index(pref, x); 17744 if (!codec) 17745 break; 17746 astman_append(s, "%s", ast_getformatname(codec)); 17747 if (x < 63 && ast_codec_pref_index(pref, x+1)) 17748 astman_append(s, ","); 17749 } 17750 17751 astman_append(s, "\r\n"); 17752 astman_append(s, "Status: "); 17753 peer_status(peer, status, sizeof(status)); 17754 astman_append(s, "%s\r\n", status); 17755 astman_append(s, "SIP-Useragent: %s\r\n", peer->useragent); 17756 astman_append(s, "Reg-Contact: %s\r\n", peer->fullcontact); 17757 astman_append(s, "QualifyFreq: %d ms\r\n", peer->qualifyfreq); 17758 astman_append(s, "Parkinglot: %s\r\n", peer->parkinglot); 17759 if (peer->chanvars) { 17760 for (v = peer->chanvars ; v ; v = v->next) { 17761 astman_append(s, "ChanVariable: %s=%s\r\n", v->name, v->value); 17762 } 17763 } 17764 astman_append(s, "SIP-Use-Reason-Header: %s\r\n", (ast_test_flag(&peer->flags[1], SIP_PAGE2_Q850_REASON)) ? "Y" : "N"); 17765 17766 peer = unref_peer(peer, "sip_show_peer: unref_peer: done with peer"); 17767 17768 } else { 17769 ast_cli(fd, "Peer %s not found.\n", argv[3]); 17770 ast_cli(fd, "\n"); 17771 } 17772 17773 return CLI_SUCCESS; 17774 }
| static char * _sip_show_peers | ( | int | fd, | |
| int * | total, | |||
| struct mansession * | s, | |||
| const struct message * | m, | |||
| int | argc, | |||
| const char * | argv[] | |||
| ) | [static] |
Execute sip show peers command.
Definition at line 16759 of file chan_sip.c.
References ao2_callback, ao2_container_count(), ao2_iterator_destroy(), ao2_lock, ao2_t_iterator_next, ao2_unlock, ast_calloc, ast_check_realtime(), ast_cli(), ast_copy_string(), ast_free, ast_log(), AST_LOG_ERROR, ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), ast_strdupa, ast_strlen_zero(), ast_test_flag, astman_append(), astman_get_header(), CLI_FAILURE, CLI_SHOWUSAGE, CLI_SUCCESS, FALSE, FORMAT2, id, name, OBJ_MULTIPLE, peer_status(), peercomparefunc(), status, TRUE, and unref_peer().
Referenced by manager_sip_show_peers(), and sip_show_peers().
16760 { 16761 regex_t regexbuf; 16762 int havepattern = FALSE; 16763 struct sip_peer *peer; 16764 struct ao2_iterator* it_peers; 16765 16766 /* the last argument is left-aligned, so we don't need a size anyways */ 16767 #define FORMAT2 "%-25.25s %-39.39s %-3.3s %-10.10s %-3.3s %-8s %-10s %s\n" 16768 16769 char name[256]; 16770 int total_peers = 0; 16771 int peers_mon_online = 0; 16772 int peers_mon_offline = 0; 16773 int peers_unmon_offline = 0; 16774 int peers_unmon_online = 0; 16775 const char *id; 16776 char idtext[256] = ""; 16777 int realtimepeers; 16778 struct sip_peer **peerarray; 16779 int k; 16780 16781 realtimepeers = ast_check_realtime("sippeers"); 16782 16783 if (s) { /* Manager - get ActionID */ 16784 id = astman_get_header(m, "ActionID"); 16785 if (!ast_strlen_zero(id)) 16786 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 16787 } 16788 16789 switch (argc) { 16790 case 5: 16791 if (!strcasecmp(argv[3], "like")) { 16792 if (regcomp(®exbuf, argv[4], REG_EXTENDED | REG_NOSUB)) 16793 return CLI_SHOWUSAGE; 16794 havepattern = TRUE; 16795 } else 16796 return CLI_SHOWUSAGE; 16797 case 3: 16798 break; 16799 default: 16800 return CLI_SHOWUSAGE; 16801 } 16802 16803 if (!s) { 16804 /* Normal list */ 16805 ast_cli(fd, FORMAT2, "Name/username", "Host", "Dyn", "Forcerport", "ACL", "Port", "Status", (realtimepeers ? "Realtime" : "")); 16806 } 16807 16808 ao2_lock(peers); 16809 if (!(it_peers = ao2_callback(peers, OBJ_MULTIPLE, NULL, NULL))) { 16810 ast_log(AST_LOG_ERROR, "Unable to create iterator for peers container for sip show peers\n"); 16811 ao2_unlock(peers); 16812 return CLI_FAILURE; 16813 } 16814 if (!(peerarray = ast_calloc(sizeof(struct sip_peer *), ao2_container_count(peers)))) { 16815 ast_log(AST_LOG_ERROR, "Unable to allocate peer array for sip show peers\n"); 16816 ao2_iterator_destroy(it_peers); 16817 ao2_unlock(peers); 16818 return CLI_FAILURE; 16819 } 16820 ao2_unlock(peers); 16821 16822 while ((peer = ao2_t_iterator_next(it_peers, "iterate thru peers table"))) { 16823 ao2_lock(peer); 16824 16825 if (!(peer->type & SIP_TYPE_PEER)) { 16826 ao2_unlock(peer); 16827 unref_peer(peer, "unref peer because it's actually a user"); 16828 continue; 16829 } 16830 16831 if (havepattern && regexec(®exbuf, peer->name, 0, NULL, 0)) { 16832 ao2_unlock(peer); 16833 unref_peer(peer, "toss iterator peer ptr before continue"); 16834 continue; 16835 } 16836 16837 peerarray[total_peers++] = peer; 16838 ao2_unlock(peer); 16839 } 16840 ao2_iterator_destroy(it_peers); 16841 16842 qsort(peerarray, total_peers, sizeof(struct sip_peer *), peercomparefunc); 16843 16844 for(k=0; k < total_peers; k++) { 16845 char status[20] = ""; 16846 char srch[2000]; 16847 char pstatus; 16848 16849 /* 16850 * tmp_port and tmp_host store copies of ast_sockaddr_stringify strings since the 16851 * string pointers for that function aren't valid between subsequent calls to 16852 * ast_sockaddr_stringify functions 16853 */ 16854 char *tmp_port; 16855 char *tmp_host; 16856 16857 peer = peerarray[k]; 16858 16859 tmp_port = ast_sockaddr_isnull(&peer->addr) ? 16860 "0" : ast_strdupa(ast_sockaddr_stringify_port(&peer->addr)); 16861 16862 tmp_host = ast_sockaddr_isnull(&peer->addr) ? 16863 "(Unspecified)" : ast_strdupa(ast_sockaddr_stringify_addr(&peer->addr)); 16864 16865 ao2_lock(peer); 16866 if (havepattern && regexec(®exbuf, peer->name, 0, NULL, 0)) { 16867 ao2_unlock(peer); 16868 peer = peerarray[k] = unref_peer(peer, "toss iterator peer ptr before continue"); 16869 continue; 16870 } 16871 16872 if (!ast_strlen_zero(peer->username) && !s) 16873 snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username); 16874 else 16875 ast_copy_string(name, peer->name, sizeof(name)); 16876 16877 pstatus = peer_status(peer, status, sizeof(status)); 16878 if (pstatus == 1) 16879 peers_mon_online++; 16880 else if (pstatus == 0) 16881 peers_mon_offline++; 16882 else { 16883 if (ast_sockaddr_isnull(&peer->addr) || 16884 !ast_sockaddr_port(&peer->addr)) { 16885 peers_unmon_offline++; 16886 } else { 16887 peers_unmon_online++; 16888 } 16889 } 16890 16891 snprintf(srch, sizeof(srch), FORMAT2, name, 16892 tmp_host, 16893 peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ 16894 ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */ 16895 peer->ha ? " A " : " ", /* permit/deny */ 16896 tmp_port, status, 16897 realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); 16898 16899 if (!s) {/* Normal CLI list */ 16900 ast_cli(fd, FORMAT2, name, 16901 tmp_host, 16902 peer->host_dynamic ? " D " : " ", /* Dynamic or not? */ 16903 ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? " N " : " ", /* NAT=yes? */ 16904 peer->ha ? " A " : " ", /* permit/deny */ 16905 tmp_port, status, 16906 realtimepeers ? (peer->is_realtime ? "Cached RT":"") : ""); 16907 } else { /* Manager format */ 16908 /* The names here need to be the same as other channels */ 16909 astman_append(s, 16910 "Event: PeerEntry\r\n%s" 16911 "Channeltype: SIP\r\n" 16912 "ObjectName: %s\r\n" 16913 "ChanObjectType: peer\r\n" /* "peer" or "user" */ 16914 "IPaddress: %s\r\n" 16915 "IPport: %s\r\n" 16916 "Dynamic: %s\r\n" 16917 "Forcerport: %s\r\n" 16918 "VideoSupport: %s\r\n" 16919 "TextSupport: %s\r\n" 16920 "ACL: %s\r\n" 16921 "Status: %s\r\n" 16922 "RealtimeDevice: %s\r\n\r\n", 16923 idtext, 16924 peer->name, 16925 ast_sockaddr_isnull(&peer->addr) ? "-none-" : tmp_host, 16926 ast_sockaddr_isnull(&peer->addr) ? "0" : tmp_port, 16927 peer->host_dynamic ? "yes" : "no", /* Dynamic or not? */ 16928 ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) ? "yes" : "no", /* NAT=yes? */ 16929 ast_test_flag(&peer->flags[1], SIP_PAGE2_VIDEOSUPPORT) ? "yes" : "no", /* VIDEOSUPPORT=yes? */ 16930 ast_test_flag(&peer->flags[1], SIP_PAGE2_TEXTSUPPORT) ? "yes" : "no", /* TEXTSUPPORT=yes? */ 16931 peer->ha ? "yes" : "no", /* permit/deny */ 16932 status, 16933 realtimepeers ? (peer->is_realtime ? "yes":"no") : "no"); 16934 } 16935 ao2_unlock(peer); 16936 peer = peerarray[k] = unref_peer(peer, "toss iterator peer ptr"); 16937 } 16938 16939 if (!s) 16940 ast_cli(fd, "%d sip peers [Monitored: %d online, %d offline Unmonitored: %d online, %d offline]\n", 16941 total_peers, peers_mon_online, peers_mon_offline, peers_unmon_online, peers_unmon_offline); 16942 16943 if (havepattern) 16944 regfree(®exbuf); 16945 16946 if (total) 16947 *total = total_peers; 16948 16949 ast_free(peerarray); 16950 16951 return CLI_SUCCESS; 16952 #undef FORMAT2 16953 }
| static void * _sip_tcp_helper_thread | ( | struct ast_tcptls_session_instance * | tcptls_session | ) | [static] |
SIP TCP thread management function This function reads from the socket, parses the packet into a request.
Definition at line 2504 of file chan_sip.c.
References ao2_lock, ao2_ref, ao2_t_find, ao2_t_ref, ao2_t_unlink, ao2_unlock, ast_atomic_fetchadd_int(), ast_debug, AST_LIST_REMOVE_HEAD, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_poll, ast_str_append(), ast_str_buffer(), ast_str_create(), ast_str_reset(), ast_str_strlen(), ast_tcptls_client_start(), ast_tcptls_close_session_file(), ast_tcptls_server_write(), ast_wait_for_input(), cleanup(), ast_tcptls_session_instance::client, copy_request(), deinit_req(), errno, ast_tcptls_session_instance::f, ast_tcptls_session_instance::fd, get_header(), handle_request_do(), ast_tcptls_session_instance::lock, LOG_ERROR, LOG_WARNING, MIN, OBJ_POINTER, ast_tcptls_session_instance::parent, parse_request(), ast_tcptls_session_instance::remote_address, set_socket_transport(), sip_check_authtimeout(), sip_threadinfo_create(), and ast_tcptls_session_instance::ssl.
Referenced by sip_tcp_worker_fn().
02505 { 02506 int res, cl, timeout = -1, authenticated = 0, flags, after_poll = 0, need_poll = 1; 02507 time_t start; 02508 struct sip_request req = { 0, } , reqcpy = { 0, }; 02509 struct sip_threadinfo *me = NULL; 02510 char buf[1024] = ""; 02511 struct pollfd fds[2] = { { 0 }, { 0 }, }; 02512 struct ast_tcptls_session_args *ca = NULL; 02513 02514 /* If this is a server session, then the connection has already been 02515 * setup. Check if the authlimit has been reached and if not create the 02516 * threadinfo object so we can access this thread for writing. 02517 * 02518 * if this is a client connection more work must be done. 02519 * 1. We own the parent session args for a client connection. This pointer needs 02520 * to be held on to so we can decrement it's ref count on thread destruction. 02521 * 2. The threadinfo object was created before this thread was launched, however 02522 * it must be found within the threadt table. 02523 * 3. Last, the tcptls_session must be started. 02524 */ 02525 if (!tcptls_session->client) { 02526 if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= authlimit) { 02527 /* unauth_sessions is decremented in the cleanup code */ 02528 goto cleanup; 02529 } 02530 02531 if ((flags = fcntl(tcptls_session->fd, F_GETFL)) == -1) { 02532 ast_log(LOG_ERROR, "error setting socket to non blocking mode, fcntl() failed: %s\n", strerror(errno)); 02533 goto cleanup; 02534 } 02535 02536 flags |= O_NONBLOCK; 02537 if (fcntl(tcptls_session->fd, F_SETFL, flags) == -1) { 02538 ast_log(LOG_ERROR, "error setting socket to non blocking mode, fcntl() failed: %s\n", strerror(errno)); 02539 goto cleanup; 02540 } 02541 02542 if (!(me = sip_threadinfo_create(tcptls_session, tcptls_session->ssl ? SIP_TRANSPORT_TLS : SIP_TRANSPORT_TCP))) { 02543 goto cleanup; 02544 } 02545 ao2_t_ref(me, +1, "Adding threadinfo ref for tcp_helper_thread"); 02546 } else { 02547 struct sip_threadinfo tmp = { 02548 .tcptls_session = tcptls_session, 02549 }; 02550 02551 if ((!(ca = tcptls_session->parent)) || 02552 (!(me = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread"))) || 02553 (!(tcptls_session = ast_tcptls_client_start(tcptls_session)))) { 02554 goto cleanup; 02555 } 02556 } 02557 02558 flags = 1; 02559 if (setsockopt(tcptls_session->fd, SOL_SOCKET, SO_KEEPALIVE, &flags, sizeof(flags))) { 02560 ast_log(LOG_ERROR, "error enabling TCP keep-alives on sip socket: %s\n", strerror(errno)); 02561 goto cleanup; 02562 } 02563 02564 me->threadid = pthread_self(); 02565 ast_debug(2, "Starting thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP"); 02566 02567 /* set up pollfd to watch for reads on both the socket and the alert_pipe */ 02568 fds[0].fd = tcptls_session->fd; 02569 fds[1].fd = me->alert_pipe[0]; 02570 fds[0].events = fds[1].events = POLLIN | POLLPRI; 02571 02572 if (!(req.data = ast_str_create(SIP_MIN_PACKET))) { 02573 goto cleanup; 02574 } 02575 if (!(reqcpy.data = ast_str_create(SIP_MIN_PACKET))) { 02576 goto cleanup; 02577 } 02578 02579 if(time(&start) == -1) { 02580 ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno)); 02581 goto cleanup; 02582 } 02583 02584 for (;;) { 02585 struct ast_str *str_save; 02586 02587 if (!tcptls_session->client && req.authenticated && !authenticated) { 02588 authenticated = 1; 02589 ast_atomic_fetchadd_int(&unauth_sessions, -1); 02590 } 02591 02592 /* calculate the timeout for unauthenticated server sessions */ 02593 if (!tcptls_session->client && !authenticated ) { 02594 if ((timeout = sip_check_authtimeout(start)) < 0) { 02595 goto cleanup; 02596 } 02597 02598 if (timeout == 0) { 02599 ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP"); 02600 goto cleanup; 02601 } 02602 } else { 02603 timeout = -1; 02604 } 02605 02606 res = ast_poll(fds, 2, timeout); /* polls for both socket and alert_pipe */ 02607 if (res < 0) { 02608 ast_debug(2, "SIP %s server :: ast_wait_for_input returned %d\n", tcptls_session->ssl ? "SSL": "TCP", res); 02609 goto cleanup; 02610 } else if (res == 0) { 02611 /* timeout */ 02612 ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP"); 02613 goto cleanup; 02614 } 02615 02616 /* handle the socket event, check for both reads from the socket fd, 02617 * and writes from alert_pipe fd */ 02618 if (fds[0].revents) { /* there is data on the socket to be read */ 02619 after_poll = 1; 02620 02621 fds[0].revents = 0; 02622 02623 /* clear request structure */ 02624 str_save = req.data; 02625 memset(&req, 0, sizeof(req)); 02626 req.data = str_save; 02627 ast_str_reset(req.data); 02628 02629 str_save = reqcpy.data; 02630 memset(&reqcpy, 0, sizeof(reqcpy)); 02631 reqcpy.data = str_save; 02632 ast_str_reset(reqcpy.data); 02633 02634 memset(buf, 0, sizeof(buf)); 02635 02636 if (tcptls_session->ssl) { 02637 set_socket_transport(&req.socket, SIP_TRANSPORT_TLS); 02638 req.socket.port = htons(ourport_tls); 02639 } else { 02640 set_socket_transport(&req.socket, SIP_TRANSPORT_TCP); 02641 req.socket.port = htons(ourport_tcp); 02642 } 02643 req.socket.fd = tcptls_session->fd; 02644 02645 /* Read in headers one line at a time */ 02646 while (ast_str_strlen(req.data) < 4 || strncmp(REQ_OFFSET_TO_STR(&req, data->used - 4), "\r\n\r\n", 4)) { 02647 if (!tcptls_session->client && !authenticated ) { 02648 if ((timeout = sip_check_authtimeout(start)) < 0) { 02649 goto cleanup; 02650 } 02651 02652 if (timeout == 0) { 02653 ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP"); 02654 goto cleanup; 02655 } 02656 } else { 02657 timeout = -1; 02658 } 02659 02660 /* special polling behavior is required for TLS 02661 * sockets because of the buffering done in the 02662 * TLS layer */ 02663 if (!tcptls_session->ssl || need_poll) { 02664 need_poll = 0; 02665 after_poll = 1; 02666 res = ast_wait_for_input(tcptls_session->fd, timeout); 02667 if (res < 0) { 02668 ast_debug(2, "SIP TCP server :: ast_wait_for_input returned %d\n", res); 02669 goto cleanup; 02670 } else if (res == 0) { 02671 /* timeout */ 02672 ast_debug(2, "SIP TCP server timed out\n"); 02673 goto cleanup; 02674 } 02675 } 02676 02677 ast_mutex_lock(&tcptls_session->lock); 02678 if (!fgets(buf, sizeof(buf), tcptls_session->f)) { 02679 ast_mutex_unlock(&tcptls_session->lock); 02680 if (after_poll) { 02681 goto cleanup; 02682 } else { 02683 need_poll = 1; 02684 continue; 02685 } 02686 } 02687 ast_mutex_unlock(&tcptls_session->lock); 02688 after_poll = 0; 02689 if (me->stop) { 02690 goto cleanup; 02691 } 02692 ast_str_append(&req.data, 0, "%s", buf); 02693 } 02694 copy_request(&reqcpy, &req); 02695 parse_request(&reqcpy); 02696 /* In order to know how much to read, we need the content-length header */ 02697 if (sscanf(get_header(&reqcpy, "Content-Length"), "%30d", &cl)) { 02698 while (cl > 0) { 02699 size_t bytes_read; 02700 if (!tcptls_session->client && !authenticated ) { 02701 if ((timeout = sip_check_authtimeout(start)) < 0) { 02702 goto cleanup; 02703 } 02704 02705 if (timeout == 0) { 02706 ast_debug(2, "SIP %s server timed out\n", tcptls_session->ssl ? "SSL": "TCP"); 02707 goto cleanup; 02708 } 02709 } else { 02710 timeout = -1; 02711 } 02712 02713 if (!tcptls_session->ssl || need_poll) { 02714 need_poll = 0; 02715 after_poll = 1; 02716 res = ast_wait_for_input(tcptls_session->fd, timeout); 02717 if (res < 0) { 02718 ast_debug(2, "SIP TCP server :: ast_wait_for_input returned %d\n", res); 02719 goto cleanup; 02720 } else if (res == 0) { 02721 /* timeout */ 02722 ast_debug(2, "SIP TCP server timed out\n"); 02723 goto cleanup; 02724 } 02725 } 02726 02727 ast_mutex_lock(&tcptls_session->lock); 02728 if (!(bytes_read = fread(buf, 1, MIN(sizeof(buf) - 1, cl), tcptls_session->f))) { 02729 ast_mutex_unlock(&tcptls_session->lock); 02730 if (after_poll) { 02731 goto cleanup; 02732 } else { 02733 need_poll = 1; 02734 continue; 02735 } 02736 } 02737 buf[bytes_read] = '\0'; 02738 ast_mutex_unlock(&tcptls_session->lock); 02739 after_poll = 0; 02740 if (me->stop) { 02741 goto cleanup; 02742 } 02743 cl -= strlen(buf); 02744 ast_str_append(&req.data, 0, "%s", buf); 02745 } 02746 } 02747 /*! \todo XXX If there's no Content-Length or if the content-length and what 02748 we receive is not the same - we should generate an error */ 02749 02750 req.socket.tcptls_session = tcptls_session; 02751 handle_request_do(&req, &tcptls_session->remote_address); 02752 } 02753 02754 if (fds[1].revents) { /* alert_pipe indicates there is data in the send queue to be sent */ 02755 enum sip_tcptls_alert alert; 02756 struct tcptls_packet *packet; 02757 02758 fds[1].revents = 0; 02759 02760 if (read(me->alert_pipe[0], &alert, sizeof(alert)) == -1) { 02761 ast_log(LOG_ERROR, "read() failed: %s\n", strerror(errno)); 02762 continue; 02763 } 02764 02765 switch (alert) { 02766 case TCPTLS_ALERT_STOP: 02767 goto cleanup; 02768 case TCPTLS_ALERT_DATA: 02769 ao2_lock(me); 02770 if (!(packet = AST_LIST_REMOVE_HEAD(&me->packet_q, entry))) { 02771 ast_log(LOG_WARNING, "TCPTLS thread alert_pipe indicated packet should be sent, but frame_q is empty\n"); 02772 } 02773 ao2_unlock(me); 02774 02775 if (packet) { 02776 if (ast_tcptls_server_write(tcptls_session, ast_str_buffer(packet->data), packet->len) == -1) { 02777 ast_log(LOG_WARNING, "Failure to write to tcp/tls socket\n"); 02778 } 02779 ao2_t_ref(packet, -1, "tcptls packet sent, this is no longer needed"); 02780 } 02781 break; 02782 default: 02783 ast_log(LOG_ERROR, "Unknown tcptls thread alert '%d'\n", alert); 02784 } 02785 } 02786 } 02787 02788 ast_debug(2, "Shutting down thread for %s server\n", tcptls_session->ssl ? "SSL" : "TCP"); 02789 02790 cleanup: 02791 if (tcptls_session && !tcptls_session->client && !authenticated) { 02792 ast_atomic_fetchadd_int(&unauth_sessions, -1); 02793 } 02794 02795 if (me) { 02796 ao2_t_unlink(threadt, me, "Removing tcptls helper thread, thread is closing"); 02797 ao2_t_ref(me, -1, "Removing tcp_helper_threads threadinfo ref"); 02798 } 02799 deinit_req(&reqcpy); 02800 deinit_req(&req); 02801 02802 /* if client, we own the parent session arguments and must decrement ref */ 02803 if (ca) { 02804 ao2_t_ref(ca, -1, "closing tcptls thread, getting rid of client tcptls_session arguments"); 02805 } 02806 02807 if (tcptls_session) { 02808 ast_mutex_lock(&tcptls_session->lock); 02809 ast_tcptls_close_session_file(tcptls_session); 02810 tcptls_session->parent = NULL; 02811 ast_mutex_unlock(&tcptls_session->lock); 02812 02813 ao2_ref(tcptls_session, -1); 02814 tcptls_session = NULL; 02815 } 02816 return NULL; 02817 }
| static void add_blank | ( | struct sip_request * | req | ) | [static] |
add a blank line if no body
Definition at line 4084 of file chan_sip.c.
References ast_str_append().
Referenced by send_request(), and send_response().
04085 { 04086 if (!req->lines) { 04087 /* Add extra empty return. add_header() reserves 4 bytes so cannot be truncated */ 04088 ast_str_append(&req->data, 0, "\r\n"); 04089 } 04090 }
| static void add_cc_call_info_to_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | resp | |||
| ) | [static] |
Definition at line 11762 of file chan_sip.c.
References add_header(), ao2_ref, ast_copy_string(), ast_log(), ast_str_alloca, ast_str_buffer(), ast_str_set(), ast_strlen_zero(), find_sip_cc_agent_by_original_callid(), generate_uri(), LOG_WARNING, and ast_cc_agent::private_data.
Referenced by __transmit_response(), and transmit_response_with_sdp().
11763 { 11764 char uri[SIPBUFSIZE]; 11765 struct ast_str *header = ast_str_alloca(SIPBUFSIZE); 11766 struct ast_cc_agent *agent = find_sip_cc_agent_by_original_callid(p); 11767 struct sip_cc_agent_pvt *agent_pvt; 11768 11769 if (!agent) { 11770 /* Um, what? How could the SIP_OFFER_CC flag be set but there not be an 11771 * agent? Oh well, we'll just warn and return without adding the header. 11772 */ 11773 ast_log(LOG_WARNING, "Can't find SIP CC agent for call '%s' even though OFFER_CC flag was set?\n", p->callid); 11774 return; 11775 } 11776 11777 agent_pvt = agent->private_data; 11778 11779 if (!ast_strlen_zero(agent_pvt->subscribe_uri)) { 11780 ast_copy_string(uri, agent_pvt->subscribe_uri, sizeof(uri)); 11781 } else { 11782 generate_uri(p, uri, sizeof(uri)); 11783 ast_copy_string(agent_pvt->subscribe_uri, uri, sizeof(agent_pvt->subscribe_uri)); 11784 } 11785 /* XXX Hardcode "NR" as the m reason for now. This should perhaps be changed 11786 * to be more accurate. This parameter has no bearing on the actual operation 11787 * of the feature; it's just there for informational purposes. 11788 */ 11789 ast_str_set(&header, 0, "<%s>;purpose=call-completion;m=%s", uri, "NR"); 11790 add_header(resp, "Call-Info", ast_str_buffer(header)); 11791 ao2_ref(agent, -1); 11792 }
| static void add_codec_to_sdp | ( | const struct sip_pvt * | p, | |
| format_t | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 11012 of file chan_sip.c.
References ast_codec_pref_getsize(), AST_FORMAT_G719, AST_FORMAT_G723_1, AST_FORMAT_G729A, AST_FORMAT_ILBC, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, ast_getformatname(), ast_rtp_codecs_payload_code(), ast_rtp_instance_get_codecs(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), AST_RTP_OPT_G726_NONSTANDARD, ast_str_append(), ast_test_flag, ast_verbose, ast_format_list::cur_ms, and ast_rtp_codecs::pref.
Referenced by add_sdp().
11015 { 11016 int rtp_code; 11017 struct ast_format_list fmt; 11018 11019 11020 if (debug) 11021 ast_verbose("Adding codec 0x%" PRIx64 " (%s) to SDP\n", codec, ast_getformatname(codec)); 11022 if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 1, codec)) == -1) 11023 return; 11024 11025 if (p->rtp) { 11026 struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref; 11027 fmt = ast_codec_pref_getsize(pref, codec); 11028 } else /* I don't see how you couldn't have p->rtp, but good to check for and error out if not there like earlier code */ 11029 return; 11030 ast_str_append(m_buf, 0, " %d", rtp_code); 11031 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 11032 ast_rtp_lookup_mime_subtype2(1, codec, 11033 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0), 11034 ast_rtp_lookup_sample_rate2(1, codec)); 11035 11036 switch (codec) { 11037 case AST_FORMAT_G729A: 11038 /* Indicate that we don't support VAD (G.729 annex B) */ 11039 ast_str_append(a_buf, 0, "a=fmtp:%d annexb=no\r\n", rtp_code); 11040 break; 11041 case AST_FORMAT_G723_1: 11042 /* Indicate that we don't support VAD (G.723.1 annex A) */ 11043 ast_str_append(a_buf, 0, "a=fmtp:%d annexa=no\r\n", rtp_code); 11044 break; 11045 case AST_FORMAT_ILBC: 11046 /* Add information about us using only 20/30 ms packetization */ 11047 ast_str_append(a_buf, 0, "a=fmtp:%d mode=%d\r\n", rtp_code, fmt.cur_ms); 11048 break; 11049 case AST_FORMAT_SIREN7: 11050 /* Indicate that we only expect 32Kbps */ 11051 ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=32000\r\n", rtp_code); 11052 break; 11053 case AST_FORMAT_SIREN14: 11054 /* Indicate that we only expect 48Kbps */ 11055 ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=48000\r\n", rtp_code); 11056 break; 11057 case AST_FORMAT_G719: 11058 /* Indicate that we only expect 64Kbps */ 11059 ast_str_append(a_buf, 0, "a=fmtp:%d bitrate=64000\r\n", rtp_code); 11060 break; 11061 } 11062 11063 if (fmt.cur_ms && (fmt.cur_ms < *min_packet_size)) 11064 *min_packet_size = fmt.cur_ms; 11065 11066 /* Our first codec packetization processed cannot be zero */ 11067 if ((*min_packet_size)==0 && fmt.cur_ms) 11068 *min_packet_size = fmt.cur_ms; 11069 }
| static int add_content | ( | struct sip_request * | req, | |
| const char * | line | |||
| ) | [static] |
Add content (not header) to SIP message.
Definition at line 9945 of file chan_sip.c.
References ast_log(), ast_str_append(), and LOG_WARNING.
Referenced by add_digit(), add_sdp(), add_text(), add_vidupdate(), transmit_cc_notify(), transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), and transmit_state_notify().
09946 { 09947 if (req->lines) { 09948 ast_log(LOG_WARNING, "Can't add more content when the content has been finalized\n"); 09949 return -1; 09950 } 09951 09952 ast_str_append(&req->content, 0, "%s", line); 09953 return 0; 09954 }
| static int add_digit | ( | struct sip_request * | req, | |
| char | digit, | |||
| unsigned int | duration, | |||
| int | mode | |||
| ) | [static] |
Add DTMF INFO tone to sip message Mode = 0 for application/dtmf-relay (Cisco) 1 for application/dtmf.
Definition at line 10870 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_info_with_digit().
10871 { 10872 char tmp[256]; 10873 int event; 10874 if (mode) { 10875 /* Application/dtmf short version used by some implementations */ 10876 if ('0' <= digit && digit <= '9') { 10877 event = digit - '0'; 10878 } else if (digit == '*') { 10879 event = 10; 10880 } else if (digit == '#') { 10881 event = 11; 10882 } else if ('A' <= digit && digit <= 'D') { 10883 event = 12 + digit - 'A'; 10884 } else if ('a' <= digit && digit <= 'd') { 10885 event = 12 + digit - 'a'; 10886 } else { 10887 /* Unknown digit */ 10888 event = 0; 10889 } 10890 snprintf(tmp, sizeof(tmp), "%d\r\n", event); 10891 add_header(req, "Content-Type", "application/dtmf"); 10892 add_content(req, tmp); 10893 } else { 10894 /* Application/dtmf-relay as documented by Cisco */ 10895 snprintf(tmp, sizeof(tmp), "Signal=%c\r\nDuration=%u\r\n", digit, duration); 10896 add_header(req, "Content-Type", "application/dtmf-relay"); 10897 add_content(req, tmp); 10898 } 10899 return 0; 10900 }
| static void add_diversion_header | ( | struct sip_request * | req, | |
| struct sip_pvt * | pvt | |||
| ) | [static] |
Add "Diversion" header to outgoing message.
We need to add a Diversion header if the owner channel of this dialog has redirecting information associated with it.
| req | The request/response to which we will add the header | |
| pvt | The sip_pvt which represents the call-leg |
Definition at line 12148 of file chan_sip.c.
References add_header(), ast_sockaddr_stringify_host_remote(), ast_strlen_zero(), and sip_reason_code_to_str().
Referenced by __transmit_response(), transmit_invite(), and update_redirecting().
12149 { 12150 const char *diverting_number; 12151 const char *diverting_name; 12152 const char *reason; 12153 char header_text[256]; 12154 12155 if (!pvt->owner) { 12156 return; 12157 } 12158 12159 diverting_number = pvt->owner->redirecting.from.number.str; 12160 if (!pvt->owner->redirecting.from.number.valid 12161 || ast_strlen_zero(diverting_number)) { 12162 return; 12163 } 12164 12165 reason = sip_reason_code_to_str(pvt->owner->redirecting.reason); 12166 12167 /* We at least have a number to place in the Diversion header, which is enough */ 12168 diverting_name = pvt->owner->redirecting.from.name.str; 12169 if (!pvt->owner->redirecting.from.name.valid 12170 || ast_strlen_zero(diverting_name)) { 12171 snprintf(header_text, sizeof(header_text), "<sip:%s@%s>;reason=%s", diverting_number, 12172 ast_sockaddr_stringify_host_remote(&pvt->ourip), reason); 12173 } else { 12174 snprintf(header_text, sizeof(header_text), "\"%s\" <sip:%s@%s>;reason=%s", 12175 diverting_name, diverting_number, 12176 ast_sockaddr_stringify_host_remote(&pvt->ourip), reason); 12177 } 12178 12179 add_header(req, "Diversion", header_text); 12180 }
| static int add_header | ( | struct sip_request * | req, | |
| const char * | var, | |||
| const char * | value | |||
| ) | [static] |
Add header to SIP message.
Definition at line 9887 of file chan_sip.c.
References ast_log(), ast_str_append(), ast_str_strlen(), find_alias(), LOG_WARNING, and sip_cfg.
Referenced by __transmit_response(), add_cc_call_info_to_response(), add_digit(), add_diversion_header(), add_header_max_forwards(), add_route(), add_rpid(), add_sdp(), add_supported_header(), add_text(), add_vidupdate(), append_date(), copy_all_header(), copy_header(), copy_via_headers(), finalize_content(), initreqprep(), reqprep(), respprep(), transmit_cc_notify(), transmit_info_with_aoc(), transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_minexpires(), transmit_response_with_minse(), transmit_response_with_retry_after(), transmit_response_with_sip_etag(), transmit_response_with_unsupported(), transmit_state_notify(), and update_connectedline().
09888 { 09889 if (req->headers == SIP_MAX_HEADERS) { 09890 ast_log(LOG_WARNING, "Out of SIP header space\n"); 09891 return -1; 09892 } 09893 09894 if (req->lines) { 09895 ast_log(LOG_WARNING, "Can't add more headers when lines have been added\n"); 09896 return -1; 09897 } 09898 09899 if (sip_cfg.compactheaders) { 09900 var = find_alias(var, var); 09901 } 09902 09903 ast_str_append(&req->data, 0, "%s: %s\r\n", var, value); 09904 req->header[req->headers] = ast_str_strlen(req->data); 09905 09906 req->headers++; 09907 09908 return 0; 09909 }
| static int add_header_max_forwards | ( | struct sip_pvt * | dialog, | |
| struct sip_request * | req | |||
| ) | [static] |
Add 'Max-Forwards' header to SIP message.
Definition at line 9915 of file chan_sip.c.
References add_header().
Referenced by initreqprep(), reqprep(), and transmit_register().
09916 { 09917 char clen[10]; 09918 09919 snprintf(clen, sizeof(clen), "%d", dialog->maxforwards); 09920 09921 return add_header(req, "Max-Forwards", clen); 09922 }
| static void add_noncodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | format, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug | |||
| ) | [static] |
Add RFC 2833 DTMF offer to SDP.
Definition at line 11150 of file chan_sip.c.
References ast_rtp_codecs_payload_code(), AST_RTP_DTMF, ast_rtp_instance_get_codecs(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_append(), and ast_verbose.
Referenced by add_sdp().
11153 { 11154 int rtp_code; 11155 11156 if (debug) 11157 ast_verbose("Adding non-codec 0x%x (%s) to SDP\n", format, ast_rtp_lookup_mime_subtype2(0, format, 0)); 11158 if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->rtp), 0, format)) == -1) 11159 return; 11160 11161 ast_str_append(m_buf, 0, " %d", rtp_code); 11162 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 11163 ast_rtp_lookup_mime_subtype2(0, format, 0), 11164 ast_rtp_lookup_sample_rate2(0, format)); 11165 if (format == AST_RTP_DTMF) /* Indicate we support DTMF and FLASH... */ 11166 ast_str_append(a_buf, 0, "a=fmtp:%d 0-16\r\n", rtp_code); 11167 }
| static void add_peer_mailboxes | ( | struct sip_peer * | peer, | |
| const char * | value | |||
| ) | [static] |
Definition at line 27335 of file chan_sip.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_TRAVERSE, ast_strdupa, ast_strip(), ast_strlen_zero(), context, mailbox, mbox(), and S_OR.
Referenced by build_peer().
27336 { 27337 char *next, *mbox, *context; 27338 27339 next = ast_strdupa(value); 27340 27341 while ((mbox = context = strsep(&next, ","))) { 27342 struct sip_mailbox *mailbox; 27343 int duplicate = 0; 27344 /* remove leading/trailing whitespace from mailbox string */ 27345 mbox = ast_strip(mbox); 27346 strsep(&context, "@"); 27347 27348 if (ast_strlen_zero(mbox)) { 27349 continue; 27350 } 27351 27352 /* Check whether the mailbox is already in the list */ 27353 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 27354 if (!strcmp(mailbox->mailbox, mbox) && !strcmp(S_OR(mailbox->context, ""), S_OR(context, ""))) { 27355 duplicate = 1; 27356 break; 27357 } 27358 } 27359 if (duplicate) { 27360 continue; 27361 } 27362 27363 if (!(mailbox = ast_calloc(1, sizeof(*mailbox) + strlen(mbox) + strlen(S_OR(context, ""))))) { 27364 continue; 27365 } 27366 27367 if (!ast_strlen_zero(context)) { 27368 mailbox->context = mailbox->mailbox + strlen(mbox) + 1; 27369 strcpy(mailbox->context, context); /* SAFE */ 27370 } 27371 strcpy(mailbox->mailbox, mbox); /* SAFE */ 27372 27373 AST_LIST_INSERT_TAIL(&peer->mailboxes, mailbox, entry); 27374 } 27375 }
| static void add_peer_mwi_subs | ( | struct sip_peer * | peer | ) | [static] |
Definition at line 24608 of file chan_sip.c.
References AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, ast_event_subscribe(), ast_event_unsubscribe(), AST_LIST_TRAVERSE, mailbox, mwi_event_cb(), and S_OR.
Referenced by build_peer(), and handle_request_subscribe().
24609 { 24610 struct sip_mailbox *mailbox; 24611 24612 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 24613 if (mailbox->event_sub) { 24614 ast_event_unsubscribe(mailbox->event_sub); 24615 } 24616 24617 mailbox->event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, "SIP mbox event", peer, 24618 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox, 24619 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"), 24620 AST_EVENT_IE_END); 24621 } 24622 }
| static void add_realm_authentication | ( | struct sip_auth_container ** | credentials, | |
| const char * | configuration, | |||
| int | lineno | |||
| ) | [static] |
Definition at line 27139 of file chan_sip.c.
References ao2_t_alloc, ast_calloc, ast_copy_string(), ast_debug, AST_LIST_INSERT_TAIL, ast_log(), ast_strdupa, ast_strlen_zero(), ast_verb, destroy_realm_authentication(), LOG_WARNING, and secret.
Referenced by build_peer(), and reload_config().
27140 { 27141 char *authcopy; 27142 char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL; 27143 struct sip_auth *auth; 27144 27145 if (ast_strlen_zero(configuration)) { 27146 /* Nothing to add */ 27147 return; 27148 } 27149 27150 ast_debug(1, "Auth config :: %s\n", configuration); 27151 27152 authcopy = ast_strdupa(configuration); 27153 username = authcopy; 27154 27155 /* split user[:secret] and relm */ 27156 realm = strrchr(username, '@'); 27157 if (realm) 27158 *realm++ = '\0'; 27159 if (ast_strlen_zero(username) || ast_strlen_zero(realm)) { 27160 ast_log(LOG_WARNING, "Format for authentication entry is user[:secret]@realm at line %d\n", lineno); 27161 return; 27162 } 27163 27164 /* parse username at ':' for secret, or '#" for md5secret */ 27165 if ((secret = strchr(username, ':'))) { 27166 *secret++ = '\0'; 27167 } else if ((md5secret = strchr(username, '#'))) { 27168 *md5secret++ = '\0'; 27169 } 27170 27171 /* Create the continer if needed. */ 27172 if (!*credentials) { 27173 *credentials = ao2_t_alloc(sizeof(**credentials), destroy_realm_authentication, 27174 "Create realm auth container."); 27175 if (!*credentials) { 27176 /* Failed to create the credentials container. */ 27177 return; 27178 } 27179 } 27180 27181 /* Create the authentication credential entry. */ 27182 auth = ast_calloc(1, sizeof(*auth)); 27183 if (!auth) { 27184 return; 27185 } 27186 ast_copy_string(auth->realm, realm, sizeof(auth->realm)); 27187 ast_copy_string(auth->username, username, sizeof(auth->username)); 27188 if (secret) 27189 ast_copy_string(auth->secret, secret, sizeof(auth->secret)); 27190 if (md5secret) 27191 ast_copy_string(auth->md5secret, md5secret, sizeof(auth->md5secret)); 27192 27193 /* Add credential to container list. */ 27194 AST_LIST_INSERT_TAIL(&(*credentials)->list, auth, node); 27195 27196 ast_verb(3, "Added authentication for realm %s\n", realm); 27197 }
| static void add_route | ( | struct sip_request * | req, | |
| struct sip_route * | route | |||
| ) | [static] |
Add route header into request per learned route.
Definition at line 10056 of file chan_sip.c.
References add_header(), and ast_copy_string().
Referenced by initreqprep(), and reqprep().
10057 { 10058 char r[SIPBUFSIZE*2], *p; 10059 int n, rem = sizeof(r); 10060 10061 if (!route) 10062 return; 10063 10064 p = r; 10065 for (;route ; route = route->next) { 10066 n = strlen(route->hop); 10067 if (rem < n+3) /* we need room for ",<route>" */ 10068 break; 10069 if (p != r) { /* add a separator after fist route */ 10070 *p++ = ','; 10071 --rem; 10072 } 10073 *p++ = '<'; 10074 ast_copy_string(p, route->hop, rem); /* cannot fail */ 10075 p += n; 10076 *p++ = '>'; 10077 rem -= (n+2); 10078 } 10079 *p = '\0'; 10080 add_header(req, "Route", r); 10081 }
| static int add_rpid | ( | struct sip_request * | req, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Add Remote-Party-ID header to SIP message.
Definition at line 10906 of file chan_sip.c.
References add_header(), ast_party_id_presentation(), AST_PRES_ALLOWED, AST_PRES_ALLOWED_NETWORK_NUMBER, AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN, AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRES_NUMBER_NOT_AVAILABLE, AST_PRES_PROHIB_NETWORK_NUMBER, AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN, AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, AST_PRES_RESTRICTION, ast_sockaddr_stringify_host_remote(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), ast_strlen_zero(), ast_test_flag, ast_uri_encode(), and S_OR.
Referenced by __transmit_response(), transmit_invite(), transmit_reinvite_with_sdp(), transmit_response_with_sdp(), and update_connectedline().
10907 { 10908 struct ast_str *tmp = ast_str_alloca(256); 10909 char tmp2[256]; 10910 char *lid_num = NULL; 10911 char *lid_name = NULL; 10912 int lid_pres; 10913 const char *fromdomain; 10914 const char *privacy = NULL; 10915 const char *screen = NULL; 10916 const char *anonymous_string = "\"Anonymous\" <sip:anonymous@anonymous.invalid>"; 10917 10918 if (!ast_test_flag(&p->flags[0], SIP_SENDRPID)) { 10919 return 0; 10920 } 10921 10922 if (p->owner && p->owner->connected.id.number.valid 10923 && p->owner->connected.id.number.str) { 10924 lid_num = p->owner->connected.id.number.str; 10925 } 10926 if (p->owner && p->owner->connected.id.name.valid 10927 && p->owner->connected.id.name.str) { 10928 lid_name = p->owner->connected.id.name.str; 10929 } 10930 lid_pres = (p->owner) ? ast_party_id_presentation(&p->owner->connected.id) : AST_PRES_NUMBER_NOT_AVAILABLE; 10931 10932 if (ast_strlen_zero(lid_num)) 10933 return 0; 10934 if (ast_strlen_zero(lid_name)) 10935 lid_name = lid_num; 10936 fromdomain = S_OR(p->fromdomain, ast_sockaddr_stringify_host_remote(&p->ourip)); 10937 10938 lid_num = ast_uri_encode(lid_num, tmp2, sizeof(tmp2), 0); 10939 10940 if (ast_test_flag(&p->flags[0], SIP_SENDRPID_PAI)) { 10941 if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 10942 ast_str_set(&tmp, -1, "%s", anonymous_string); 10943 } else { 10944 ast_str_set(&tmp, -1, "\"%s\" <sip:%s@%s>", lid_name, lid_num, fromdomain); 10945 } 10946 add_header(req, "P-Asserted-Identity", ast_str_buffer(tmp)); 10947 } else { 10948 ast_str_set(&tmp, -1, "\"%s\" <sip:%s@%s>;party=%s", lid_name, lid_num, fromdomain, ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "calling" : "called"); 10949 10950 switch (lid_pres) { 10951 case AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED: 10952 case AST_PRES_ALLOWED_USER_NUMBER_FAILED_SCREEN: 10953 privacy = "off"; 10954 screen = "no"; 10955 break; 10956 case AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN: 10957 case AST_PRES_ALLOWED_NETWORK_NUMBER: 10958 privacy = "off"; 10959 screen = "yes"; 10960 break; 10961 case AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED: 10962 case AST_PRES_PROHIB_USER_NUMBER_FAILED_SCREEN: 10963 privacy = "full"; 10964 screen = "no"; 10965 break; 10966 case AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN: 10967 case AST_PRES_PROHIB_NETWORK_NUMBER: 10968 privacy = "full"; 10969 screen = "yes"; 10970 break; 10971 case AST_PRES_NUMBER_NOT_AVAILABLE: 10972 break; 10973 default: 10974 if ((lid_pres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 10975 privacy = "full"; 10976 } 10977 else 10978 privacy = "off"; 10979 screen = "no"; 10980 break; 10981 } 10982 10983 if (!ast_strlen_zero(privacy) && !ast_strlen_zero(screen)) { 10984 ast_str_append(&tmp, -1, ";privacy=%s;screen=%s", privacy, screen); 10985 } 10986 10987 add_header(req, "Remote-Party-ID", ast_str_buffer(tmp)); 10988 } 10989 return 0; 10990 }
| static enum sip_result add_sdp | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p, | |||
| int | oldsdp, | |||
| int | add_audio, | |||
| int | add_t38 | |||
| ) | [static] |
Add Session Description Protocol message.
If oldsdp is TRUE, then the SDP version number is not incremented. This mechanism is used in Session-Timers where RE-INVITEs are used for refreshing SIP sessions without modifying the media session in any way.
Definition at line 11288 of file chan_sip.c.
References add_codec_to_sdp(), add_content(), add_header(), add_noncodec_to_sdp(), add_tcodec_to_sdp(), add_vcodec_to_sdp(), ast_codec_pref_index(), ast_debug, AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_getformatname_multiple(), ast_internal_timing_enabled(), ast_log(), ast_random(), AST_RTP_MAX, ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_is_ipv4_mapped(), ast_sockaddr_is_ipv6(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_addr_remote(), ast_sockaddr_stringify_port(), ast_str_alloca, ast_str_append(), ast_strlen_zero(), AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_test_flag, ast_udptl_get_error_correction_scheme(), ast_udptl_get_local_max_datagram(), ast_udptl_get_us(), ast_verbose, capability, FALSE, get_crypto_attrib(), get_our_media_address(), LOG_WARNING, sip_debug_test_pvt(), t38_get_rate(), TRUE, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, UDPTL_ERROR_CORRECTION_REDUNDANCY, and version.
Referenced by transmit_invite(), transmit_reinvite_with_sdp(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and update_connectedline().
11289 { 11290 format_t alreadysent = 0; 11291 int doing_directmedia = FALSE; 11292 11293 struct ast_sockaddr addr = { {0,} }; 11294 struct ast_sockaddr vaddr = { {0,} }; 11295 struct ast_sockaddr taddr = { {0,} }; 11296 struct ast_sockaddr udptladdr = { {0,} }; 11297 struct ast_sockaddr dest = { {0,} }; 11298 struct ast_sockaddr vdest = { {0,} }; 11299 struct ast_sockaddr tdest = { {0,} }; 11300 struct ast_sockaddr udptldest = { {0,} }; 11301 11302 /* SDP fields */ 11303 char *version = "v=0\r\n"; /* Protocol version */ 11304 char subject[256]; /* Subject of the session */ 11305 char owner[256]; /* Session owner/creator */ 11306 char connection[256]; /* Connection data */ 11307 char *session_time = "t=0 0\r\n"; /* Time the session is active */ 11308 char bandwidth[256] = ""; /* Max bitrate */ 11309 char *hold = ""; 11310 struct ast_str *m_audio = ast_str_alloca(256); /* Media declaration line for audio */ 11311 struct ast_str *m_video = ast_str_alloca(256); /* Media declaration line for video */ 11312 struct ast_str *m_text = ast_str_alloca(256); /* Media declaration line for text */ 11313 struct ast_str *m_modem = ast_str_alloca(256); /* Media declaration line for modem */ 11314 struct ast_str *a_audio = ast_str_alloca(1024); /* Attributes for audio */ 11315 struct ast_str *a_video = ast_str_alloca(1024); /* Attributes for video */ 11316 struct ast_str *a_text = ast_str_alloca(1024); /* Attributes for text */ 11317 struct ast_str *a_modem = ast_str_alloca(1024); /* Attributes for modem */ 11318 const char *a_crypto = NULL; 11319 const char *v_a_crypto = NULL; 11320 const char *t_a_crypto = NULL; 11321 11322 format_t x; 11323 format_t capability = 0; 11324 int needaudio = FALSE; 11325 int needvideo = FALSE; 11326 int needtext = FALSE; 11327 int debug = sip_debug_test_pvt(p); 11328 int min_audio_packet_size = 0; 11329 int min_video_packet_size = 0; 11330 int min_text_packet_size = 0; 11331 11332 char codecbuf[SIPBUFSIZE]; 11333 char buf[SIPBUFSIZE]; 11334 char dummy_answer[256]; 11335 11336 /* Set the SDP session name */ 11337 snprintf(subject, sizeof(subject), "s=%s\r\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession); 11338 11339 if (!p->rtp) { 11340 ast_log(LOG_WARNING, "No way to add SDP without an RTP structure\n"); 11341 return AST_FAILURE; 11342 } 11343 /* XXX We should not change properties in the SIP dialog until 11344 we have acceptance of the offer if this is a re-invite */ 11345 11346 /* Set RTP Session ID and version */ 11347 if (!p->sessionid) { 11348 p->sessionid = (int)ast_random(); 11349 p->sessionversion = p->sessionid; 11350 } else { 11351 if (oldsdp == FALSE) 11352 p->sessionversion++; 11353 } 11354 11355 if (add_audio) { 11356 doing_directmedia = (!ast_sockaddr_isnull(&p->redirip) && p->redircodecs) ? TRUE : FALSE; 11357 /* Check if we need video in this call */ 11358 if ((p->jointcapability & AST_FORMAT_VIDEO_MASK) && !p->novideo) { 11359 if (doing_directmedia && !(p->jointcapability & AST_FORMAT_VIDEO_MASK & p->redircodecs)) { 11360 ast_debug(2, "This call needs video offers, but caller probably did not offer it!\n"); 11361 } else if (p->vrtp) { 11362 needvideo = TRUE; 11363 ast_debug(2, "This call needs video offers!\n"); 11364 } else { 11365 ast_debug(2, "This call needs video offers, but there's no video support enabled!\n"); 11366 } 11367 } 11368 /* Check if we need text in this call */ 11369 if ((p->jointcapability & AST_FORMAT_TEXT_MASK) && !p->notext) { 11370 if (sipdebug_text) 11371 ast_verbose("We think we can do text\n"); 11372 if (p->trtp) { 11373 if (sipdebug_text) { 11374 ast_verbose("And we have a text rtp object\n"); 11375 } 11376 needtext = TRUE; 11377 ast_debug(2, "This call needs text offers! \n"); 11378 } else { 11379 ast_debug(2, "This call needs text offers, but there's no text support enabled ! \n"); 11380 } 11381 } 11382 } 11383 11384 get_our_media_address(p, needvideo, needtext, &addr, &vaddr, &taddr, &dest, &vdest, &tdest); 11385 11386 snprintf(owner, sizeof(owner), "o=%s %d %d IN %s %s\r\n", 11387 ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner, 11388 p->sessionid, p->sessionversion, 11389 (ast_sockaddr_is_ipv6(&dest) && !ast_sockaddr_is_ipv4_mapped(&dest)) ? 11390 "IP6" : "IP4", 11391 ast_sockaddr_stringify_addr_remote(&dest)); 11392 11393 snprintf(connection, sizeof(connection), "c=IN %s %s\r\n", 11394 (ast_sockaddr_is_ipv6(&dest) && !ast_sockaddr_is_ipv4_mapped(&dest)) ? 11395 "IP6" : "IP4", 11396 ast_sockaddr_stringify_addr_remote(&dest)); 11397 11398 if (add_audio) { 11399 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_ONEDIR) { 11400 hold = "a=recvonly\r\n"; 11401 doing_directmedia = FALSE; 11402 } else if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) == SIP_PAGE2_CALL_ONHOLD_INACTIVE) { 11403 hold = "a=inactive\r\n"; 11404 doing_directmedia = FALSE; 11405 } else { 11406 hold = "a=sendrecv\r\n"; 11407 } 11408 11409 capability = p->jointcapability; 11410 11411 /* XXX note, Video and Text are negated - 'true' means 'no' */ 11412 ast_debug(1, "** Our capability: %s Video flag: %s Text flag: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability), 11413 p->novideo ? "True" : "False", p->notext ? "True" : "False"); 11414 ast_debug(1, "** Our prefcodec: %s \n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), p->prefcodec)); 11415 11416 if (doing_directmedia) { 11417 capability &= p->redircodecs; 11418 ast_debug(1, "** Our native-bridge filtered capablity: %s\n", ast_getformatname_multiple(codecbuf, sizeof(codecbuf), capability)); 11419 } 11420 11421 /* Check if we need audio */ 11422 if (capability & AST_FORMAT_AUDIO_MASK) 11423 needaudio = TRUE; 11424 11425 if (debug) { 11426 ast_verbose("Audio is at %s\n", ast_sockaddr_stringify_port(&addr)); 11427 } 11428 11429 /* Ok, we need video. Let's add what we need for video and set codecs. 11430 Video is handled differently than audio since we can not transcode. */ 11431 if (needvideo) { 11432 get_crypto_attrib(p->vsrtp, &v_a_crypto); 11433 ast_str_append(&m_video, 0, "m=video %d RTP/%s", ast_sockaddr_port(&vdest), 11434 v_a_crypto ? "SAVP" : "AVP"); 11435 11436 /* Build max bitrate string */ 11437 if (p->maxcallbitrate) 11438 snprintf(bandwidth, sizeof(bandwidth), "b=CT:%d\r\n", p->maxcallbitrate); 11439 if (debug) { 11440 ast_verbose("Video is at %s\n", ast_sockaddr_stringify(&vdest)); 11441 } 11442 } 11443 11444 /* Ok, we need text. Let's add what we need for text and set codecs. 11445 Text is handled differently than audio since we can not transcode. */ 11446 if (needtext) { 11447 if (sipdebug_text) 11448 ast_verbose("Lets set up the text sdp\n"); 11449 get_crypto_attrib(p->tsrtp, &t_a_crypto); 11450 ast_str_append(&m_text, 0, "m=text %d RTP/%s", ast_sockaddr_port(&tdest), 11451 t_a_crypto ? "SAVP" : "AVP"); 11452 if (debug) { /* XXX should I use tdest below ? */ 11453 ast_verbose("Text is at %s\n", ast_sockaddr_stringify(&taddr)); 11454 } 11455 } 11456 11457 /* Start building generic SDP headers */ 11458 11459 /* We break with the "recommendation" and send our IP, in order that our 11460 peer doesn't have to ast_gethostbyname() us */ 11461 11462 get_crypto_attrib(p->srtp, &a_crypto); 11463 ast_str_append(&m_audio, 0, "m=audio %d RTP/%s", ast_sockaddr_port(&dest), 11464 a_crypto ? "SAVP" : "AVP"); 11465 11466 /* Now, start adding audio codecs. These are added in this order: 11467 - First what was requested by the calling channel 11468 - Then preferences in order from sip.conf device config for this peer/user 11469 - Then other codecs in capabilities, including video 11470 */ 11471 11472 /* Prefer the audio codec we were requested to use, first, no matter what 11473 Note that p->prefcodec can include video codecs, so mask them out 11474 */ 11475 if (capability & p->prefcodec) { 11476 format_t codec = p->prefcodec & AST_FORMAT_AUDIO_MASK; 11477 11478 add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size); 11479 alreadysent |= codec; 11480 } 11481 11482 /* Start by sending our preferred audio/video codecs */ 11483 for (x = 0; x < 64; x++) { 11484 format_t codec; 11485 11486 if (!(codec = ast_codec_pref_index(&p->prefs, x))) 11487 break; 11488 11489 if (!(capability & codec)) 11490 continue; 11491 11492 if (alreadysent & codec) 11493 continue; 11494 11495 add_codec_to_sdp(p, codec, &m_audio, &a_audio, debug, &min_audio_packet_size); 11496 alreadysent |= codec; 11497 } 11498 11499 /* Now send any other common audio and video codecs, and non-codec formats: */ 11500 for (x = 1ULL; x <= (needtext ? AST_FORMAT_TEXT_MASK : (needvideo ? AST_FORMAT_VIDEO_MASK : AST_FORMAT_AUDIO_MASK)); x <<= 1) { 11501 if (!(capability & x)) /* Codec not requested */ 11502 continue; 11503 11504 if (alreadysent & x) /* Already added to SDP */ 11505 continue; 11506 11507 if (x & AST_FORMAT_AUDIO_MASK) 11508 add_codec_to_sdp(p, x, &m_audio, &a_audio, debug, &min_audio_packet_size); 11509 else if (x & AST_FORMAT_VIDEO_MASK) 11510 add_vcodec_to_sdp(p, x, &m_video, &a_video, debug, &min_video_packet_size); 11511 else if (x & AST_FORMAT_TEXT_MASK) 11512 add_tcodec_to_sdp(p, x, &m_text, &a_text, debug, &min_text_packet_size); 11513 } 11514 11515 /* Now add DTMF RFC2833 telephony-event as a codec */ 11516 for (x = 1LL; x <= AST_RTP_MAX; x <<= 1) { 11517 if (!(p->jointnoncodeccapability & x)) 11518 continue; 11519 11520 add_noncodec_to_sdp(p, x, &m_audio, &a_audio, debug); 11521 } 11522 11523 ast_debug(3, "-- Done with adding codecs to SDP\n"); 11524 11525 if (!p->owner || !ast_internal_timing_enabled(p->owner)) 11526 ast_str_append(&a_audio, 0, "a=silenceSupp:off - - - -\r\n"); 11527 11528 if (min_audio_packet_size) 11529 ast_str_append(&a_audio, 0, "a=ptime:%d\r\n", min_audio_packet_size); 11530 11531 /* XXX don't think you can have ptime for video */ 11532 if (min_video_packet_size) 11533 ast_str_append(&a_video, 0, "a=ptime:%d\r\n", min_video_packet_size); 11534 11535 /* XXX don't think you can have ptime for text */ 11536 if (min_text_packet_size) 11537 ast_str_append(&a_text, 0, "a=ptime:%d\r\n", min_text_packet_size); 11538 11539 if (m_audio->len - m_audio->used < 2 || m_video->len - m_video->used < 2 || 11540 m_text->len - m_text->used < 2 || a_text->len - a_text->used < 2 || 11541 a_audio->len - a_audio->used < 2 || a_video->len - a_video->used < 2) 11542 ast_log(LOG_WARNING, "SIP SDP may be truncated due to undersized buffer!!\n"); 11543 } 11544 11545 if (add_t38) { 11546 /* Our T.38 end is */ 11547 ast_udptl_get_us(p->udptl, &udptladdr); 11548 11549 /* Determine T.38 UDPTL destination */ 11550 if (!ast_sockaddr_isnull(&p->udptlredirip)) { 11551 ast_sockaddr_copy(&udptldest, &p->udptlredirip); 11552 } else { 11553 ast_sockaddr_copy(&udptldest, &p->ourip); 11554 ast_sockaddr_set_port(&udptldest, ast_sockaddr_port(&udptladdr)); 11555 } 11556 11557 if (debug) { 11558 ast_debug(1, "T.38 UDPTL is at %s port %d\n", ast_sockaddr_stringify_addr(&p->ourip), ast_sockaddr_port(&udptladdr)); 11559 } 11560 11561 /* We break with the "recommendation" and send our IP, in order that our 11562 peer doesn't have to ast_gethostbyname() us */ 11563 11564 ast_str_append(&m_modem, 0, "m=image %d udptl t38\r\n", ast_sockaddr_port(&udptldest)); 11565 11566 if (!ast_sockaddr_cmp(&udptldest, &dest)) { 11567 ast_str_append(&m_modem, 0, "c=IN %s %s\r\n", 11568 (ast_sockaddr_is_ipv6(&dest) && !ast_sockaddr_is_ipv4_mapped(&dest)) ? 11569 "IP6" : "IP4", ast_sockaddr_stringify_addr_remote(&udptldest)); 11570 } 11571 11572 ast_str_append(&a_modem, 0, "a=T38FaxVersion:%d\r\n", p->t38.our_parms.version); 11573 ast_str_append(&a_modem, 0, "a=T38MaxBitRate:%d\r\n", t38_get_rate(p->t38.our_parms.rate)); 11574 if (p->t38.our_parms.fill_bit_removal) { 11575 ast_str_append(&a_modem, 0, "a=T38FaxFillBitRemoval\r\n"); 11576 } 11577 if (p->t38.our_parms.transcoding_mmr) { 11578 ast_str_append(&a_modem, 0, "a=T38FaxTranscodingMMR\r\n"); 11579 } 11580 if (p->t38.our_parms.transcoding_jbig) { 11581 ast_str_append(&a_modem, 0, "a=T38FaxTranscodingJBIG\r\n"); 11582 } 11583 switch (p->t38.our_parms.rate_management) { 11584 case AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF: 11585 ast_str_append(&a_modem, 0, "a=T38FaxRateManagement:transferredTCF\r\n"); 11586 break; 11587 case AST_T38_RATE_MANAGEMENT_LOCAL_TCF: 11588 ast_str_append(&a_modem, 0, "a=T38FaxRateManagement:localTCF\r\n"); 11589 break; 11590 } 11591 ast_str_append(&a_modem, 0, "a=T38FaxMaxDatagram:%u\r\n", ast_udptl_get_local_max_datagram(p->udptl)); 11592 switch (ast_udptl_get_error_correction_scheme(p->udptl)) { 11593 case UDPTL_ERROR_CORRECTION_NONE: 11594 break; 11595 case UDPTL_ERROR_CORRECTION_FEC: 11596 ast_str_append(&a_modem, 0, "a=T38FaxUdpEC:t38UDPFEC\r\n"); 11597 break; 11598 case UDPTL_ERROR_CORRECTION_REDUNDANCY: 11599 ast_str_append(&a_modem, 0, "a=T38FaxUdpEC:t38UDPRedundancy\r\n"); 11600 break; 11601 } 11602 } 11603 11604 if (needaudio) 11605 ast_str_append(&m_audio, 0, "\r\n"); 11606 if (needvideo) 11607 ast_str_append(&m_video, 0, "\r\n"); 11608 if (needtext) 11609 ast_str_append(&m_text, 0, "\r\n"); 11610 11611 add_header(resp, "Content-Type", "application/sdp"); 11612 add_content(resp, version); 11613 add_content(resp, owner); 11614 add_content(resp, subject); 11615 add_content(resp, connection); 11616 /* only if video response is appropriate */ 11617 if (needvideo) { 11618 add_content(resp, bandwidth); 11619 } 11620 add_content(resp, session_time); 11621 /* if this is a response to an invite, order our offers properly */ 11622 if (p->offered_media[SDP_AUDIO].order_offered || 11623 p->offered_media[SDP_VIDEO].order_offered || 11624 p->offered_media[SDP_TEXT].order_offered || 11625 p->offered_media[SDP_IMAGE].order_offered) { 11626 int i; 11627 /* we have up to 3 streams as limited by process_sdp */ 11628 for (i = 1; i <= 3; i++) { 11629 if (p->offered_media[SDP_AUDIO].order_offered == i) { 11630 if (needaudio) { 11631 add_content(resp, m_audio->str); 11632 add_content(resp, a_audio->str); 11633 add_content(resp, hold); 11634 if (a_crypto) { 11635 add_content(resp, a_crypto); 11636 } 11637 } else { 11638 snprintf(dummy_answer, sizeof(dummy_answer), "m=audio 0 RTP/AVP %s\r\n", p->offered_media[SDP_AUDIO].codecs); 11639 add_content(resp, dummy_answer); 11640 } 11641 } else if (p->offered_media[SDP_VIDEO].order_offered == i) { 11642 if (needvideo) { /* only if video response is appropriate */ 11643 add_content(resp, m_video->str); 11644 add_content(resp, a_video->str); 11645 add_content(resp, hold); /* Repeat hold for the video stream */ 11646 if (v_a_crypto) { 11647 add_content(resp, v_a_crypto); 11648 } 11649 } else { 11650 snprintf(dummy_answer, sizeof(dummy_answer), "m=video 0 RTP/AVP %s\r\n", p->offered_media[SDP_VIDEO].codecs); 11651 add_content(resp, dummy_answer); 11652 } 11653 } else if (p->offered_media[SDP_TEXT].order_offered == i) { 11654 if (needtext) { /* only if text response is appropriate */ 11655 add_content(resp, m_text->str); 11656 add_content(resp, a_text->str); 11657 add_content(resp, hold); /* Repeat hold for the text stream */ 11658 if (t_a_crypto) { 11659 add_content(resp, t_a_crypto); 11660 } 11661 } else { 11662 snprintf(dummy_answer, sizeof(dummy_answer), "m=text 0 RTP/AVP %s\r\n", p->offered_media[SDP_TEXT].codecs); 11663 add_content(resp, dummy_answer); 11664 } 11665 } else if (p->offered_media[SDP_IMAGE].order_offered == i) { 11666 if (add_t38) { 11667 add_content(resp, m_modem->str); 11668 add_content(resp, a_modem->str); 11669 } else { 11670 add_content(resp, "m=image 0 udptl t38\r\n"); 11671 } 11672 } 11673 } 11674 } else { 11675 /* generate new SDP from scratch, no offers */ 11676 if (needaudio) { 11677 add_content(resp, m_audio->str); 11678 add_content(resp, a_audio->str); 11679 add_content(resp, hold); 11680 if (a_crypto) { 11681 add_content(resp, a_crypto); 11682 } 11683 } 11684 if (needvideo) { /* only if video response is appropriate */ 11685 add_content(resp, m_video->str); 11686 add_content(resp, a_video->str); 11687 add_content(resp, hold); /* Repeat hold for the video stream */ 11688 if (v_a_crypto) { 11689 add_content(resp, v_a_crypto); 11690 } 11691 } 11692 if (needtext) { /* only if text response is appropriate */ 11693 add_content(resp, m_text->str); 11694 add_content(resp, a_text->str); 11695 add_content(resp, hold); /* Repeat hold for the text stream */ 11696 if (t_a_crypto) { 11697 add_content(resp, t_a_crypto); 11698 } 11699 } 11700 if (add_t38) { 11701 add_content(resp, m_modem->str); 11702 add_content(resp, a_modem->str); 11703 } 11704 } 11705 11706 /* Update lastrtprx when we send our SDP */ 11707 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 11708 11709 ast_debug(3, "Done building SDP. Settling with this capability: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, capability)); 11710 11711 return AST_SUCCESS; 11712 }
| static int add_sip_domain | ( | const char * | domain, | |
| const enum domain_mode | mode, | |||
| const char * | context | |||
| ) | [static] |
Add SIP domain to list of domains we are responsible for.
Definition at line 27048 of file chan_sip.c.
References ast_calloc, ast_copy_string(), ast_debug, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, AST_LIST_UNLOCK, ast_log(), ast_strlen_zero(), and LOG_WARNING.
Referenced by reload_config().
27049 { 27050 struct domain *d; 27051 27052 if (ast_strlen_zero(domain)) { 27053 ast_log(LOG_WARNING, "Zero length domain.\n"); 27054 return 1; 27055 } 27056 27057 if (!(d = ast_calloc(1, sizeof(*d)))) 27058 return 0; 27059 27060 ast_copy_string(d->domain, domain, sizeof(d->domain)); 27061 27062 if (!ast_strlen_zero(context)) 27063 ast_copy_string(d->context, context, sizeof(d->context)); 27064 27065 d->mode = mode; 27066 27067 AST_LIST_LOCK(&domain_list); 27068 AST_LIST_INSERT_TAIL(&domain_list, d, list); 27069 AST_LIST_UNLOCK(&domain_list); 27070 27071 if (sipdebug) 27072 ast_debug(1, "Added local SIP domain '%s'\n", domain); 27073 27074 return 1; 27075 }
| static int add_supported_header | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
Add "Supported" header to sip message. Since some options may be disabled in the config, the sip_pvt must be inspected to determine what is supported for this dialog.
Definition at line 9875 of file chan_sip.c.
References add_header(), and st_get_mode().
Referenced by respprep(), transmit_invite(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), and update_connectedline().
09876 { 09877 int res; 09878 if (st_get_mode(pvt, 0) != SESSION_TIMER_MODE_REFUSE) { 09879 res = add_header(req, "Supported", "replaces, timer"); 09880 } else { 09881 res = add_header(req, "Supported", "replaces"); 09882 } 09883 return res; 09884 }
| static void add_tcodec_to_sdp | ( | const struct sip_pvt * | p, | |
| int | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add text codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 11096 of file chan_sip.c.
References AST_FORMAT_T140, AST_FORMAT_T140RED, ast_getformatname(), ast_rtp_codecs_payload_code(), ast_rtp_instance_get_codecs(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_append(), and ast_verbose.
Referenced by add_sdp().
11099 { 11100 int rtp_code; 11101 11102 if (!p->trtp) 11103 return; 11104 11105 if (debug) 11106 ast_verbose("Adding text codec 0x%x (%s) to SDP\n", codec, ast_getformatname(codec)); 11107 11108 if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, codec)) == -1) 11109 return; 11110 11111 ast_str_append(m_buf, 0, " %d", rtp_code); 11112 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 11113 ast_rtp_lookup_mime_subtype2(1, codec, 0), 11114 ast_rtp_lookup_sample_rate2(1, codec)); 11115 /* Add fmtp code here */ 11116 11117 if (codec == AST_FORMAT_T140RED) { 11118 int t140code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->trtp), 1, AST_FORMAT_T140); 11119 ast_str_append(a_buf, 0, "a=fmtp:%d %d/%d/%d\r\n", rtp_code, 11120 t140code, 11121 t140code, 11122 t140code); 11123 11124 } 11125 }
| static int add_text | ( | struct sip_request * | req, | |
| const char * | text | |||
| ) | [static] |
Add text body to SIP message.
Definition at line 10858 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_message_with_text().
10859 { 10860 /* XXX Convert \n's to \r\n's XXX */ 10861 add_header(req, "Content-Type", "text/plain;charset=UTF-8"); 10862 add_content(req, text); 10863 return 0; 10864 }
| static struct ast_variable* add_var | ( | const char * | buf, | |
| struct ast_variable * | list | |||
| ) | [static, read] |
implement the setvar config line
Definition at line 27228 of file chan_sip.c.
References ast_strdupa, ast_variable_new(), and ast_variable::next.
Referenced by build_peer().
27229 { 27230 struct ast_variable *tmpvar = NULL; 27231 char *varname = ast_strdupa(buf), *varval = NULL; 27232 27233 if ((varval = strchr(varname, '='))) { 27234 *varval++ = '\0'; 27235 if ((tmpvar = ast_variable_new(varname, varval, ""))) { 27236 tmpvar->next = list; 27237 list = tmpvar; 27238 } 27239 } 27240 return list; 27241 }
| static void add_vcodec_to_sdp | ( | const struct sip_pvt * | p, | |
| format_t | codec, | |||
| struct ast_str ** | m_buf, | |||
| struct ast_str ** | a_buf, | |||
| int | debug, | |||
| int * | min_packet_size | |||
| ) | [static] |
Add video codec offer to SDP offer/answer body in INVITE or 200 OK.
Definition at line 11073 of file chan_sip.c.
References ast_getformatname(), ast_rtp_codecs_payload_code(), ast_rtp_instance_get_codecs(), ast_rtp_lookup_mime_subtype2(), ast_rtp_lookup_sample_rate2(), ast_str_append(), and ast_verbose.
Referenced by add_sdp().
11076 { 11077 int rtp_code; 11078 11079 if (!p->vrtp) 11080 return; 11081 11082 if (debug) 11083 ast_verbose("Adding video codec 0x%" PRIx64 " (%s) to SDP\n", codec, ast_getformatname(codec)); 11084 11085 if ((rtp_code = ast_rtp_codecs_payload_code(ast_rtp_instance_get_codecs(p->vrtp), 1, codec)) == -1) 11086 return; 11087 11088 ast_str_append(m_buf, 0, " %d", rtp_code); 11089 ast_str_append(a_buf, 0, "a=rtpmap:%d %s/%d\r\n", rtp_code, 11090 ast_rtp_lookup_mime_subtype2(1, codec, 0), 11091 ast_rtp_lookup_sample_rate2(1, codec)); 11092 /* Add fmtp code here */ 11093 }
| static int add_vidupdate | ( | struct sip_request * | req | ) | [static] |
add XML encoded media control with update
Definition at line 10994 of file chan_sip.c.
References add_content(), and add_header().
Referenced by transmit_info_with_vidupdate().
10995 { 10996 const char *xml_is_a_huge_waste_of_space = 10997 "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n" 10998 " <media_control>\r\n" 10999 " <vc_primitive>\r\n" 11000 " <to_encoder>\r\n" 11001 " <picture_fast_update>\r\n" 11002 " </picture_fast_update>\r\n" 11003 " </to_encoder>\r\n" 11004 " </vc_primitive>\r\n" 11005 " </media_control>\r\n"; 11006 add_header(req, "Content-Type", "application/media_control+xml"); 11007 add_content(req, xml_is_a_huge_waste_of_space); 11008 return 0; 11009 }
| static int addr_is_multicast | ( | const struct ast_sockaddr * | addr | ) | [static] |
Check if an ip is an multicast IP. addr the address to check.
This function checks if an address is in the 224.0.0.0/4 network block.
Definition at line 7806 of file chan_sip.c.
References ast_sockaddr_ipv4().
Referenced by process_via().
07807 { 07808 return ((ast_sockaddr_ipv4(addr) & 0xf0000000) == 0xe0000000); 07809 }
| static const char * allowoverlap2str | ( | int | mode | ) | [static] |
Convert AllowOverlap setting to printable string.
Definition at line 17057 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), and sip_show_settings().
17058 { 17059 return map_x_s(allowoverlapstr, mode, "<error>"); 17060 }
| static void append_date | ( | struct sip_request * | req | ) | [static] |
Append date to SIP message.
Definition at line 10681 of file chan_sip.c.
References add_header().
Referenced by transmit_invite(), transmit_response_with_date(), transmit_response_with_minse(), and transmit_response_with_unsupported().
10682 { 10683 char tmpdat[256]; 10684 struct tm tm; 10685 time_t t = time(NULL); 10686 10687 gmtime_r(&t, &tm); 10688 strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T GMT", &tm); 10689 add_header(req, "Date", tmpdat); 10690 }
| static void append_history_full | ( | struct sip_pvt * | p, | |
| const char * | fmt, | |||
| ... | ||||
| ) | [static] |
Append to SIP dialog history with arg list.
Definition at line 3530 of file chan_sip.c.
References append_history_va().
03531 { 03532 va_list ap; 03533 03534 if (!p) { 03535 return; 03536 } 03537 03538 if (!p->do_history && !recordhistory && !dumphistory) { 03539 return; 03540 } 03541 03542 va_start(ap, fmt); 03543 append_history_va(p, fmt, ap); 03544 va_end(ap); 03545 03546 return; 03547 }
| static void append_history_va | ( | struct sip_pvt * | p, | |
| const char * | fmt, | |||
| va_list | ap | |||
| ) | [static] |
Append to SIP dialog history with arg list.
Definition at line 3502 of file chan_sip.c.
References ast_calloc, ast_free, AST_LIST_INSERT_TAIL, and AST_LIST_REMOVE_HEAD.
Referenced by append_history_full().
03503 { 03504 char buf[80], *c = buf; /* max history length */ 03505 struct sip_history *hist; 03506 int l; 03507 03508 vsnprintf(buf, sizeof(buf), fmt, ap); 03509 strsep(&c, "\r\n"); /* Trim up everything after \r or \n */ 03510 l = strlen(buf) + 1; 03511 if (!(hist = ast_calloc(1, sizeof(*hist) + l))) { 03512 return; 03513 } 03514 if (!p->history && !(p->history = ast_calloc(1, sizeof(*p->history)))) { 03515 ast_free(hist); 03516 return; 03517 } 03518 memcpy(hist->event, buf, l); 03519 if (p->history_entries == MAX_HISTORY_ENTRIES) { 03520 struct sip_history *oldest; 03521 oldest = AST_LIST_REMOVE_HEAD(p->history, list); 03522 p->history_entries--; 03523 ast_free(oldest); 03524 } 03525 AST_LIST_INSERT_TAIL(p->history, hist, list); 03526 p->history_entries++; 03527 }
| static int apply_directmedia_ha | ( | struct sip_pvt * | p1, | |
| struct sip_pvt * | p2, | |||
| const char * | op | |||
| ) | [static] |
Definition at line 29204 of file chan_sip.c.
References ast_apply_ha(), ast_debug, ast_rtp_instance_get_local_address(), ast_rtp_instance_get_remote_address(), AST_SENSE_ALLOW, AST_SENSE_DENY, ast_sockaddr_stringify(), and ast_strdupa.
Referenced by sip_get_rtp_peer(), sip_get_trtp_peer(), sip_get_udptl_peer(), and sip_get_vrtp_peer().
29205 { 29206 struct ast_sockaddr us = { { 0, }, }, them = { { 0, }, }; 29207 int res = AST_SENSE_ALLOW; 29208 29209 ast_rtp_instance_get_remote_address(p1->rtp, &them); 29210 ast_rtp_instance_get_local_address(p1->rtp, &us); 29211 29212 /* If p2 is a guest call, there will be no peer. If there is no peer, there 29213 * is no directmediaha, so go ahead and allow it */ 29214 if (!p2->relatedpeer) { 29215 return res; 29216 } 29217 29218 if ((res = ast_apply_ha(p2->relatedpeer->directmediaha, &them)) == AST_SENSE_DENY) { 29219 const char *us_addr = ast_strdupa(ast_sockaddr_stringify(&us)); 29220 const char *them_addr = ast_strdupa(ast_sockaddr_stringify(&them)); 29221 29222 ast_debug(3, "Reinvite %s to %s denied by directmedia ACL on %s\n", 29223 op, them_addr, us_addr); 29224 } 29225 29226 return res; 29227 }
| AST_DATA_STRUCTURE | ( | sip_peer | , | |
| DATA_EXPORT_SIP_PEER | ||||
| ) |
| AST_LIST_HEAD_NOLOCK | ( | sip_history_head | , | |
| sip_history | ||||
| ) |
history list, entry in sip_pvt
| AST_LIST_HEAD_STATIC | ( | epa_static_data_list | , | |
| epa_backend | ||||
| ) |
| static AST_LIST_HEAD_STATIC | ( | domain_list | , | |
| domain | ||||
| ) | [static] |
The SIP domain list
| AST_MODULE_INFO | ( | ASTERISK_GPL_KEY | , | |
| AST_MODFLAG_LOAD_ORDER | , | |||
| "Session Initiation Protocol (SIP)" | , | |||
| . | load = load_module, |
|||
| . | unload = unload_module, |
|||
| . | reload = reload, |
|||
| . | load_pri = AST_MODPRI_CHANNEL_DRIVER, |
|||
| . | nonoptreq = "res_crypto,chan_local" | |||
| ) |
| AST_MUTEX_DEFINE_STATIC | ( | authl_lock | ) |
Global authentication container protection while adjusting the references.
| AST_MUTEX_DEFINE_STATIC | ( | sip_reload_lock | ) |
| AST_MUTEX_DEFINE_STATIC | ( | monlock | ) |
Protect the monitoring thread, so only one process can kill or start it, and not when it's doing something critical.
| AST_MUTEX_DEFINE_STATIC | ( | netlock | ) |
| static void ast_quiet_chan | ( | struct ast_channel * | chan | ) | [static] |
Turn off generator data XXX Does this function belong in the SIP channel?
Definition at line 21694 of file chan_sip.c.
References ast_channel::_state, ast_deactivate_generator(), AST_FLAG_MOH, ast_moh_stop(), AST_STATE_UP, ast_test_flag, and ast_channel::generatordata.
Referenced by attempt_transfer(), and handle_invite_replaces().
21695 { 21696 if (chan && chan->_state == AST_STATE_UP) { 21697 if (ast_test_flag(chan, AST_FLAG_MOH)) 21698 ast_moh_stop(chan); 21699 else if (chan->generatordata) 21700 ast_deactivate_generator(chan); 21701 } 21702 }
| static void ast_sip_ouraddrfor | ( | const struct ast_sockaddr * | them, | |
| struct ast_sockaddr * | us, | |||
| struct sip_pvt * | p | |||
| ) | [static] |
NAT fix - decide which IP address to use for Asterisk server?
Using the localaddr structure built up with localnet statements in sip.conf apply it to their address to see if we need to substitute our externaddr or can get away with our internal bindaddr 'us' is always overwritten.
Definition at line 3398 of file chan_sip.c.
References ast_apply_ha(), ast_debug, ast_log(), ast_ouraddrfor(), AST_SENSE_ALLOW, ast_sockaddr_copy(), ast_sockaddr_is_any(), ast_sockaddr_is_ipv6(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_resolve_first(), ast_sockaddr_set_port, ast_sockaddr_stringify(), bindaddr, externaddr, get_transport(), internip, ast_tcptls_session_args::local_address, LOG_NOTICE, LOG_WARNING, and sip_cfg.
Referenced by __sip_subscribe_mwi_do(), sip_alloc(), sip_cc_monitor_request_cc(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_publish(), transmit_register(), and transmit_response_using_temp().
03399 { 03400 struct ast_sockaddr theirs; 03401 03402 /* Set want_remap to non-zero if we want to remap 'us' to an externally 03403 * reachable IP address and port. This is done if: 03404 * 1. we have a localaddr list (containing 'internal' addresses marked 03405 * as 'deny', so ast_apply_ha() will return AST_SENSE_DENY on them, 03406 * and AST_SENSE_ALLOW on 'external' ones); 03407 * 2. externaddr is set, so we know what to use as the 03408 * externally visible address; 03409 * 3. the remote address, 'them', is external; 03410 * 4. the address returned by ast_ouraddrfor() is 'internal' (AST_SENSE_DENY 03411 * when passed to ast_apply_ha() so it does need to be remapped. 03412 * This fourth condition is checked later. 03413 */ 03414 int want_remap = 0; 03415 03416 ast_sockaddr_copy(us, &internip); /* starting guess for the internal address */ 03417 /* now ask the system what would it use to talk to 'them' */ 03418 ast_ouraddrfor(them, us); 03419 ast_sockaddr_copy(&theirs, them); 03420 03421 if (ast_sockaddr_is_ipv6(&theirs)) { 03422 if (localaddr && !ast_sockaddr_isnull(&externaddr) && !ast_sockaddr_is_any(&bindaddr)) { 03423 ast_log(LOG_WARNING, "Address remapping activated in sip.conf " 03424 "but we're using IPv6, which doesn't need it. Please " 03425 "remove \"localnet\" and/or \"externaddr\" settings.\n"); 03426 } 03427 } else { 03428 want_remap = localaddr && 03429 !ast_sockaddr_isnull(&externaddr) && 03430 ast_apply_ha(localaddr, &theirs) == AST_SENSE_ALLOW ; 03431 } 03432 03433 if (want_remap && 03434 (!sip_cfg.matchexternaddrlocally || !ast_apply_ha(localaddr, us)) ) { 03435 /* if we used externhost, see if it is time to refresh the info */ 03436 if (externexpire && time(NULL) >= externexpire) { 03437 if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) { 03438 ast_log(LOG_NOTICE, "Warning: Re-lookup of '%s' failed!\n", externhost); 03439 } 03440 externexpire = time(NULL) + externrefresh; 03441 } 03442 if (!ast_sockaddr_isnull(&externaddr)) { 03443 ast_sockaddr_copy(us, &externaddr); 03444 switch (p->socket.type) { 03445 case SIP_TRANSPORT_TCP: 03446 if (!externtcpport && ast_sockaddr_port(&externaddr)) { 03447 /* for consistency, default to the externaddr port */ 03448 externtcpport = ast_sockaddr_port(&externaddr); 03449 } 03450 ast_sockaddr_set_port(us, externtcpport); 03451 break; 03452 case SIP_TRANSPORT_TLS: 03453 ast_sockaddr_set_port(us, externtlsport); 03454 break; 03455 case SIP_TRANSPORT_UDP: 03456 if (!ast_sockaddr_port(&externaddr)) { 03457 ast_sockaddr_set_port(us, ast_sockaddr_port(&bindaddr)); 03458 } 03459 break; 03460 default: 03461 break; 03462 } 03463 } 03464 ast_debug(1, "Target address %s is not local, substituting externaddr\n", 03465 ast_sockaddr_stringify(them)); 03466 } else { 03467 /* no remapping, but we bind to a specific address, so use it. */ 03468 switch (p->socket.type) { 03469 case SIP_TRANSPORT_TCP: 03470 if (!ast_sockaddr_is_any(&sip_tcp_desc.local_address)) { 03471 ast_sockaddr_copy(us, 03472 &sip_tcp_desc.local_address); 03473 } else { 03474 ast_sockaddr_set_port(us, 03475 ast_sockaddr_port(&sip_tcp_desc.local_address)); 03476 } 03477 break; 03478 case SIP_TRANSPORT_TLS: 03479 if (!ast_sockaddr_is_any(&sip_tls_desc.local_address)) { 03480 ast_sockaddr_copy(us, 03481 &sip_tls_desc.local_address); 03482 } else { 03483 ast_sockaddr_set_port(us, 03484 ast_sockaddr_port(&sip_tls_desc.local_address)); 03485 } 03486 break; 03487 case SIP_TRANSPORT_UDP: 03488 /* fall through on purpose */ 03489 default: 03490 if (!ast_sockaddr_is_any(&bindaddr)) { 03491 ast_sockaddr_copy(us, &bindaddr); 03492 } 03493 if (!ast_sockaddr_port(us)) { 03494 ast_sockaddr_set_port(us, ast_sockaddr_port(&bindaddr)); 03495 } 03496 } 03497 } 03498 ast_debug(3, "Setting SIP_TRANSPORT_%s with address %s\n", get_transport(p->socket.type), ast_sockaddr_stringify(us)); 03499 }
| static int ast_sockaddr_resolve_first | ( | struct ast_sockaddr * | addr, | |
| const char * | name, | |||
| int | flag | |||
| ) | [static] |
Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr.
Using this function probably means you have a faulty design.
Definition at line 30004 of file chan_sip.c.
References ast_sockaddr_resolve_first_af(), and get_address_family_filter().
Referenced by ast_sip_ouraddrfor(), check_via(), and reload_config().
30006 { 30007 return ast_sockaddr_resolve_first_af(addr, name, flag, get_address_family_filter(SIP_TRANSPORT_UDP)); 30008 }
| static int ast_sockaddr_resolve_first_af | ( | struct ast_sockaddr * | addr, | |
| const char * | name, | |||
| int | flag, | |||
| int | family | |||
| ) | [static] |
Return the first entry from ast_sockaddr_resolve filtered by address family.
Using this function probably means you have a faulty design.
Definition at line 29980 of file chan_sip.c.
References ast_debug, ast_free, ast_sockaddr_copy(), and ast_sockaddr_resolve().
Referenced by ast_sockaddr_resolve_first(), ast_sockaddr_resolve_first_transport(), get_ip_and_port_from_sdp(), process_sdp_c(), and sip_do_debug_ip().
29982 { 29983 struct ast_sockaddr *addrs; 29984 int addrs_cnt; 29985 29986 addrs_cnt = ast_sockaddr_resolve(&addrs, name, flag, family); 29987 if (addrs_cnt <= 0) { 29988 return 1; 29989 } 29990 if (addrs_cnt > 1) { 29991 ast_debug(1, "Multiple addresses, using the first one only\n"); 29992 } 29993 29994 ast_sockaddr_copy(addr, &addrs[0]); 29995 29996 ast_free(addrs); 29997 return 0; 29998 }
| static int ast_sockaddr_resolve_first_transport | ( | struct ast_sockaddr * | addr, | |
| const char * | name, | |||
| int | flag, | |||
| unsigned int | transport | |||
| ) | [static] |
Return the first entry from ast_sockaddr_resolve filtered by family of binddaddr.
Using this function probably means you have a faulty design.
Definition at line 30014 of file chan_sip.c.
References ast_sockaddr_resolve_first_af(), and get_address_family_filter().
Referenced by __set_address_from_contact(), create_addr(), parse_register_contact(), process_via(), set_destination(), and sip_request_call().
30016 { 30017 return ast_sockaddr_resolve_first_af(addr, name, flag, get_address_family_filter(transport)); 30018 }
| AST_THREADSTORAGE | ( | check_auth_buf | ) |
| AST_THREADSTORAGE_CUSTOM | ( | ts_temp_pvt | , | |
| temp_pvt_init | , | |||
| temp_pvt_cleanup | ||||
| ) |
A per-thread temporary pvt structure.
| static int attempt_transfer | ( | struct sip_dual * | transferer, | |
| struct sip_dual * | target | |||
| ) | [static] |
Attempt transfer of SIP call This fix for attended transfers on a local PBX.
Definition at line 21706 of file chan_sip.c.
References ast_channel_masquerade(), ast_debug, ast_log(), ast_quiet_chan(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), ast_state2str(), LOG_NOTICE, and LOG_WARNING.
Referenced by local_attended_transfer().
21707 { 21708 int res = 0; 21709 struct ast_channel *peera = NULL, 21710 *peerb = NULL, 21711 *peerc = NULL, 21712 *peerd = NULL; 21713 21714 21715 /* We will try to connect the transferee with the target and hangup 21716 all channels to the transferer */ 21717 ast_debug(4, "Sip transfer:--------------------\n"); 21718 if (transferer->chan1) 21719 ast_debug(4, "-- Transferer to PBX channel: %s State %s\n", transferer->chan1->name, ast_state2str(transferer->chan1->_state)); 21720 else 21721 ast_debug(4, "-- No transferer first channel - odd??? \n"); 21722 if (target->chan1) 21723 ast_debug(4, "-- Transferer to PBX second channel (target): %s State %s\n", target->chan1->name, ast_state2str(target->chan1->_state)); 21724 else 21725 ast_debug(4, "-- No target first channel ---\n"); 21726 if (transferer->chan2) 21727 ast_debug(4, "-- Bridged call to transferee: %s State %s\n", transferer->chan2->name, ast_state2str(transferer->chan2->_state)); 21728 else 21729 ast_debug(4, "-- No bridged call to transferee\n"); 21730 if (target->chan2) 21731 ast_debug(4, "-- Bridged call to transfer target: %s State %s\n", target->chan2 ? target->chan2->name : "<none>", target->chan2 ? ast_state2str(target->chan2->_state) : "(none)"); 21732 else 21733 ast_debug(4, "-- No target second channel ---\n"); 21734 ast_debug(4, "-- END Sip transfer:--------------------\n"); 21735 if (transferer->chan2) { /* We have a bridge on the transferer's channel */ 21736 peera = transferer->chan1; /* Transferer - PBX -> transferee channel * the one we hangup */ 21737 peerb = target->chan1; /* Transferer - PBX -> target channel - This will get lost in masq */ 21738 peerc = transferer->chan2; /* Asterisk to Transferee */ 21739 peerd = target->chan2; /* Asterisk to Target */ 21740 ast_debug(3, "SIP transfer: Four channels to handle\n"); 21741 } else if (target->chan2) { /* Transferer has no bridge (IVR), but transferee */ 21742 peera = target->chan1; /* Transferer to PBX -> target channel */ 21743 peerb = transferer->chan1; /* Transferer to IVR*/ 21744 peerc = target->chan2; /* Asterisk to Target */ 21745 peerd = transferer->chan2; /* Nothing */ 21746 ast_debug(3, "SIP transfer: Three channels to handle\n"); 21747 } 21748 21749 if (peera && peerb && peerc && (peerb != peerc)) { 21750 ast_quiet_chan(peera); /* Stop generators */ 21751 ast_quiet_chan(peerb); 21752 ast_quiet_chan(peerc); 21753 if (peerd) 21754 ast_quiet_chan(peerd); 21755 21756 ast_debug(4, "SIP transfer: trying to masquerade %s into %s\n", peerc->name, peerb->name); 21757 if (ast_channel_masquerade(peerb, peerc)) { 21758 ast_log(LOG_WARNING, "Failed to masquerade %s into %s\n", peerb->name, peerc->name); 21759 res = -1; 21760 } else 21761 ast_debug(4, "SIP transfer: Succeeded to masquerade channels.\n"); 21762 return res; 21763 } else { 21764 ast_log(LOG_NOTICE, "SIP Transfer attempted with no appropriate bridged calls to transfer\n"); 21765 if (transferer->chan1) 21766 ast_softhangup_nolock(transferer->chan1, AST_SOFTHANGUP_DEV); 21767 if (target->chan1) 21768 ast_softhangup_nolock(target->chan1, AST_SOFTHANGUP_DEV); 21769 return -1; 21770 } 21771 return 0; 21772 }
| static void auth_headers | ( | enum sip_auth_type | code, | |
| char ** | header, | |||
| char ** | respheader | |||
| ) | [static] |
return the request and response header for a 401 or 407 code
Definition at line 13696 of file chan_sip.c.
References ast_verbose.
Referenced by check_auth(), do_proxy_auth(), do_register_auth(), and transmit_request_with_auth().
13697 { 13698 if (code == WWW_AUTH) { /* 401 */ 13699 *header = "WWW-Authenticate"; 13700 *respheader = "Authorization"; 13701 } else if (code == PROXY_AUTH) { /* 407 */ 13702 *header = "Proxy-Authenticate"; 13703 *respheader = "Proxy-Authorization"; 13704 } else { 13705 ast_verbose("-- wrong response code %d\n", code); 13706 *header = *respheader = "Invalid"; 13707 } 13708 }
| static int auto_congest | ( | const void * | arg | ) | [static] |
Scheduled congestion on a call. Only called by the scheduler, must return the reference when done.
Definition at line 5509 of file chan_sip.c.
References append_history, ast_channel_trylock, ast_channel_unlock, AST_CONTROL_CONGESTION, ast_queue_control(), sip_pvt_lock, sip_pvt_unlock, and sip_scheddestroy().
Referenced by sip_call(), and sip_show_sched().
05510 { 05511 struct sip_pvt *p = (struct sip_pvt *)arg; 05512 05513 sip_pvt_lock(p); 05514 p->initid = -1; /* event gone, will not be rescheduled */ 05515 if (p->owner) { 05516 /* XXX fails on possible deadlock */ 05517 if (!ast_channel_trylock(p->owner)) { 05518 append_history(p, "Cong", "Auto-congesting (timer)"); 05519 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 05520 ast_channel_unlock(p->owner); 05521 } 05522 05523 /* Give the channel a chance to act before we proceed with destruction */ 05524 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 05525 } 05526 sip_pvt_unlock(p); 05527 dialog_unref(p, "unreffing arg passed into auto_congest callback (p->initid)"); 05528 return 0; 05529 }
| static void build_callid_pvt | ( | struct sip_pvt * | pvt | ) | [static] |
Build SIP Call-ID value for a non-REGISTER transaction.
Definition at line 7576 of file chan_sip.c.
References ast_sockaddr_stringify_remote(), ast_string_field_build, generate_random_string(), and S_OR.
Referenced by change_callid_pvt(), and sip_alloc().
07577 { 07578 char buf[33]; 07579 const char *host = S_OR(pvt->fromdomain, ast_sockaddr_stringify_remote(&pvt->ourip)); 07580 07581 ast_string_field_build(pvt, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 07582 }
| static void build_callid_registry | ( | struct sip_registry * | reg, | |
| const struct ast_sockaddr * | ourip, | |||
| const char * | fromdomain | |||
| ) | [static] |
Build SIP Call-ID value for a REGISTER transaction.
Definition at line 7626 of file chan_sip.c.
References ast_sockaddr_stringify_host_remote(), ast_string_field_build, generate_random_string(), and S_OR.
Referenced by transmit_register().
07627 { 07628 char buf[33]; 07629 07630 const char *host = S_OR(fromdomain, ast_sockaddr_stringify_host_remote(ourip)); 07631 07632 ast_string_field_build(reg, callid, "%s@%s", generate_random_string(buf, sizeof(buf)), host); 07633 }
| static void build_contact | ( | struct sip_pvt * | p | ) | [static] |
Build contact header - the contact header we send out.
Definition at line 11956 of file chan_sip.c.
References ast_sockaddr_stringify_remote(), ast_string_field_build, ast_strlen_zero(), ast_uri_encode(), and get_transport().
Referenced by __sip_subscribe_mwi_do(), check_user_full(), handle_request_invite(), handle_request_options(), handle_request_subscribe(), initreqprep(), register_verify(), and transmit_register().
11957 { 11958 char tmp[SIPBUFSIZE]; 11959 char *user = ast_uri_encode(p->exten, tmp, sizeof(tmp), 0); 11960 11961 if (p->socket.type == SIP_TRANSPORT_UDP) { 11962 ast_string_field_build(p, our_contact, "<sip:%s%s%s>", user, 11963 ast_strlen_zero(user) ? "" : "@", ast_sockaddr_stringify_remote(&p->ourip)); 11964 } else { 11965 ast_string_field_build(p, our_contact, "<sip:%s%s%s;transport=%s>", user, 11966 ast_strlen_zero(user) ? "" : "@", ast_sockaddr_stringify_remote(&p->ourip), 11967 get_transport(p->socket.type)); 11968 } 11969 }
| static struct sip_peer * build_peer | ( | const char * | name, | |
| struct ast_variable * | v, | |||
| struct ast_variable * | alt, | |||
| int | realtime, | |||
| int | devstate_only | |||
| ) | [static, read] |
Build peer from configuration (file or realtime static/dynamic).
< The first transport listed should be default outbound
Definition at line 27378 of file chan_sip.c.
References __set_address_from_contact(), accountcode, add_peer_mailboxes(), add_peer_mwi_subs(), add_realm_authentication(), add_var(), ao2_alloc, ao2_lock, ao2_t_alloc, ao2_t_find, ao2_t_ref, ao2_t_unlink, ao2_unlock, asprintf, ast_append_ha(), ast_atomic_fetchadd_int(), ast_callerid_split(), AST_CC_AGENT_NATIVE, AST_CC_AGENT_NEVER, ast_cc_config_params_init, ast_cc_is_config_param(), ast_cc_set_param(), ast_cdr_amaflags2int(), ast_copy_flags, ast_copy_string(), ast_debug, ast_dnsmgr_lookup_cb(), ast_dnsmgr_refresh(), ast_free, ast_free_ha(), ast_get_cc_agent_policy(), ast_get_group(), ast_get_ip(), ast_get_time_t(), AST_LIST_EMPTY, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_log(), ast_parse_allow_disallow(), ast_parse_caller_presentation(), AST_SCHED_DEL_UNREF, ast_set2_flag, ast_set_cc_agent_policy(), ast_set_flag, ast_skip_blanks(), ast_sockaddr_isnull(), ast_sockaddr_parse(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_setnull(), ast_sockaddr_stringify_addr(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_reset(), ast_str_set(), ast_str_strlen(), ast_strdupa, ast_string_field_init, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_true(), ast_variables_destroy(), cid_name, cid_num, context, DEFAULT_MAXMS, destroy_association(), destroy_mailbox(), ast_tls_config::enabled, errno, FALSE, ast_flags::flags, format, get_address_family_filter(), get_srv_protocol(), get_srv_service(), handle_common_options(), handle_t38_options(), language, ast_variable::lineno, LOG_ERROR, LOG_NOTICE, LOG_WARNING, mailbox, mark_parsed_methods(), MAXHOSTNAMELEN, mohinterpret, mohsuggest, ast_variable::name, ast_variable::next, OBJ_POINTER, OBJ_UNLINK, on_dns_update_peer(), parkinglot, PARSE_PORT_FORBID, port_str2int(), proxy_update(), ref_peer(), reg_source_db(), secret, set_peer_defaults(), set_socket_transport(), sip_cfg, sip_destroy_peer_fn(), sip_parse_host(), sip_poke_peer(), sip_register(), sip_send_mwi_to_peer(), srvlookup, str2stmode(), str2strefresher(), TRUE, unref_peer(), and ast_variable::value.
Referenced by realtime_peer(), and reload_config().
27379 { 27380 struct sip_peer *peer = NULL; 27381 struct ast_ha *oldha = NULL; 27382 struct ast_ha *olddirectmediaha = NULL; 27383 int found = 0; 27384 int firstpass = 1; 27385 uint16_t port = 0; 27386 int format = 0; /* Ama flags */ 27387 int timerb_set = 0, timert1_set = 0; 27388 time_t regseconds = 0; 27389 struct ast_flags peerflags[3] = {{(0)}}; 27390 struct ast_flags mask[3] = {{(0)}}; 27391 char callback[256] = ""; 27392 struct sip_peer tmp_peer; 27393 const char *srvlookup = NULL; 27394 static int deprecation_warning = 1; 27395 int alt_fullcontact = alt ? 1 : 0, headercount = 0; 27396 struct ast_str *fullcontact = ast_str_alloca(512); 27397 27398 if (!realtime || ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 27399 /* Note we do NOT use find_peer here, to avoid realtime recursion */ 27400 /* We also use a case-sensitive comparison (unlike find_peer) so 27401 that case changes made to the peer name will be properly handled 27402 during reload 27403 */ 27404 ast_copy_string(tmp_peer.name, name, sizeof(tmp_peer.name)); 27405 peer = ao2_t_find(peers, &tmp_peer, OBJ_POINTER | OBJ_UNLINK, "find and unlink peer from peers table"); 27406 } 27407 27408 if (peer) { 27409 /* Already in the list, remove it and it will be added back (or FREE'd) */ 27410 found++; 27411 /* we've unlinked the peer from the peers container but not unlinked from the peers_by_ip container yet 27412 this leads to a wrong refcounter and the peer object is never destroyed */ 27413 if (!ast_sockaddr_isnull(&peer->addr)) { 27414 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink peer from peers_by_ip table"); 27415 } 27416 if (!(peer->the_mark)) 27417 firstpass = 0; 27418 } else { 27419 if (!(peer = ao2_t_alloc(sizeof(*peer), sip_destroy_peer_fn, "allocate a peer struct"))) 27420 return NULL; 27421 27422 if (ast_string_field_init(peer, 512)) { 27423 ao2_t_ref(peer, -1, "failed to string_field_init, drop peer"); 27424 return NULL; 27425 } 27426 27427 if (!(peer->cc_params = ast_cc_config_params_init())) { 27428 ao2_t_ref(peer, -1, "failed to allocate cc_params for peer"); 27429 return NULL; 27430 } 27431 27432 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 27433 ast_atomic_fetchadd_int(&rpeerobjs, 1); 27434 ast_debug(3, "-REALTIME- peer built. Name: %s. Peer objects: %d\n", name, rpeerobjs); 27435 } else 27436 ast_atomic_fetchadd_int(&speerobjs, 1); 27437 } 27438 27439 /* Note that our peer HAS had its reference count increased */ 27440 if (firstpass) { 27441 peer->lastmsgssent = -1; 27442 oldha = peer->ha; 27443 peer->ha = NULL; 27444 olddirectmediaha = peer->directmediaha; 27445 peer->directmediaha = NULL; 27446 set_peer_defaults(peer); /* Set peer defaults */ 27447 peer->type = 0; 27448 } 27449 27450 /* in case the case of the peer name has changed, update the name */ 27451 ast_copy_string(peer->name, name, sizeof(peer->name)); 27452 27453 /* If we have channel variables, remove them (reload) */ 27454 if (peer->chanvars) { 27455 ast_variables_destroy(peer->chanvars); 27456 peer->chanvars = NULL; 27457 /* XXX should unregister ? */ 27458 } 27459 27460 if (found) 27461 peer->portinuri = 0; 27462 27463 /* If we have realm authentication information, remove them (reload) */ 27464 ao2_lock(peer); 27465 if (peer->auth) { 27466 ao2_t_ref(peer->auth, -1, "Removing old peer authentication"); 27467 peer->auth = NULL; 27468 } 27469 ao2_unlock(peer); 27470 27471 /* clear the transport information. We will detect if a default value is required after parsing the config */ 27472 peer->default_outbound_transport = 0; 27473 peer->transports = 0; 27474 27475 if (!devstate_only) { 27476 struct sip_mailbox *mailbox; 27477 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 27478 mailbox->delme = 1; 27479 } 27480 } 27481 27482 for (; v || ((v = alt) && !(alt=NULL)); v = v->next) { 27483 if (!devstate_only) { 27484 if (handle_common_options(&peerflags[0], &mask[0], v)) { 27485 continue; 27486 } 27487 if (handle_t38_options(&peerflags[0], &mask[0], v, &peer->t38_maxdatagram)) { 27488 continue; 27489 } 27490 if (!strcasecmp(v->name, "transport")) { 27491 char *val = ast_strdupa(v->value); 27492 char *trans; 27493 27494 peer->transports = peer->default_outbound_transport = 0; 27495 while ((trans = strsep(&val, ","))) { 27496 trans = ast_skip_blanks(trans); 27497 27498 if (!strncasecmp(trans, "udp", 3)) { 27499 peer->transports |= SIP_TRANSPORT_UDP; 27500 } else if (sip_cfg.tcp_enabled && !strncasecmp(trans, "tcp", 3)) { 27501 peer->transports |= SIP_TRANSPORT_TCP; 27502 } else if (default_tls_cfg.enabled && !strncasecmp(trans, "tls", 3)) { 27503 peer->transports |= SIP_TRANSPORT_TLS; 27504 } else if (!strncasecmp(trans, "tcp", 3) || !strncasecmp(trans, "tls", 3)) { 27505 ast_log(LOG_WARNING, "'%.3s' is not a valid transport type when %.3senable=no. If no other is specified, the defaults from general will be used.\n", trans, trans); 27506 } else { 27507 ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, the defaults from general will be used.\n", trans); 27508 } 27509 27510 if (!peer->default_outbound_transport) { /*!< The first transport listed should be default outbound */ 27511 peer->default_outbound_transport = peer->transports; 27512 } 27513 } 27514 } else if (realtime && !strcasecmp(v->name, "regseconds")) { 27515 ast_get_time_t(v->value, ®seconds, 0, NULL); 27516 } else if (realtime && !strcasecmp(v->name, "name")) { 27517 ast_copy_string(peer->name, v->value, sizeof(peer->name)); 27518 } else if (realtime && !strcasecmp(v->name, "useragent")) { 27519 ast_string_field_set(peer, useragent, v->value); 27520 } else if (!strcasecmp(v->name, "type")) { 27521 if (!strcasecmp(v->value, "peer")) { 27522 peer->type |= SIP_TYPE_PEER; 27523 } else if (!strcasecmp(v->value, "user")) { 27524 peer->type |= SIP_TYPE_USER; 27525 } else if (!strcasecmp(v->value, "friend")) { 27526 peer->type = SIP_TYPE_USER | SIP_TYPE_PEER; 27527 } 27528 } else if (!strcasecmp(v->name, "remotesecret")) { 27529 ast_string_field_set(peer, remotesecret, v->value); 27530 } else if (!strcasecmp(v->name, "secret")) { 27531 ast_string_field_set(peer, secret, v->value); 27532 } else if (!strcasecmp(v->name, "md5secret")) { 27533 ast_string_field_set(peer, md5secret, v->value); 27534 } else if (!strcasecmp(v->name, "auth")) { 27535 add_realm_authentication(&peer->auth, v->value, v->lineno); 27536 } else if (!strcasecmp(v->name, "callerid")) { 27537 char cid_name[80] = { '\0' }, cid_num[80] = { '\0' }; 27538 27539 ast_callerid_split(v->value, cid_name, sizeof(cid_name), cid_num, sizeof(cid_num)); 27540 ast_string_field_set(peer, cid_name, cid_name); 27541 ast_string_field_set(peer, cid_num, cid_num); 27542 } else if (!strcasecmp(v->name, "mwi_from")) { 27543 ast_string_field_set(peer, mwi_from, v->value); 27544 } else if (!strcasecmp(v->name, "fullname")) { 27545 ast_string_field_set(peer, cid_name, v->value); 27546 } else if (!strcasecmp(v->name, "trunkname")) { 27547 /* This is actually for a trunk, so we don't want to override callerid */ 27548 ast_string_field_set(peer, cid_name, ""); 27549 } else if (!strcasecmp(v->name, "cid_number")) { 27550 ast_string_field_set(peer, cid_num, v->value); 27551 } else if (!strcasecmp(v->name, "cid_tag")) { 27552 ast_string_field_set(peer, cid_tag, v->value); 27553 } else if (!strcasecmp(v->name, "context")) { 27554 ast_string_field_set(peer, context, v->value); 27555 ast_set_flag(&peer->flags[1], SIP_PAGE2_HAVEPEERCONTEXT); 27556 } else if (!strcasecmp(v->name, "subscribecontext")) { 27557 ast_string_field_set(peer, subscribecontext, v->value); 27558 } else if (!strcasecmp(v->name, "fromdomain")) { 27559 char *fromdomainport; 27560 ast_string_field_set(peer, fromdomain, v->value); 27561 if ((fromdomainport = strchr(peer->fromdomain, ':'))) { 27562 *fromdomainport++ = '\0'; 27563 if (!(peer->fromdomainport = port_str2int(fromdomainport, 0))) { 27564 ast_log(LOG_NOTICE, "'%s' is not a valid port number for fromdomain.\n",fromdomainport); 27565 } 27566 } else { 27567 peer->fromdomainport = STANDARD_SIP_PORT; 27568 } 27569 } else if (!strcasecmp(v->name, "usereqphone")) { 27570 ast_set2_flag(&peer->flags[0], ast_true(v->value), SIP_USEREQPHONE); 27571 } else if (!strcasecmp(v->name, "fromuser")) { 27572 ast_string_field_set(peer, fromuser, v->value); 27573 } else if (!strcasecmp(v->name, "outboundproxy")) { 27574 char *host, *proxyname, *sep; 27575 27576 if (ast_strlen_zero(v->value)) { 27577 ast_log(LOG_WARNING, "no value given for outbound proxy on line %d of sip.conf\n", v->lineno); 27578 continue; 27579 } 27580 27581 if (!peer->outboundproxy) { 27582 peer->outboundproxy = ao2_alloc(sizeof(*peer->outboundproxy), NULL); 27583 if (!peer->outboundproxy) { 27584 ast_log(LOG_WARNING, "Unable to allocate config storage for outboundproxy\n"); 27585 continue; 27586 } 27587 } 27588 27589 host = ast_strdupa(v->value); 27590 if (!host) { 27591 ast_log(LOG_WARNING, "Unable to allocate stack space for parsing outboundproxy\n"); 27592 continue; 27593 } 27594 27595 host = ast_skip_blanks(host); 27596 sep = strchr(host, ','); 27597 if (sep) { 27598 *sep++ = '\0'; 27599 peer->outboundproxy->force = !strncasecmp(ast_skip_blanks(sep), "force", 5); 27600 } else { 27601 peer->outboundproxy->force = FALSE; 27602 } 27603 27604 sip_parse_host(host, v->lineno, &proxyname, 27605 &peer->outboundproxy->port, 27606 &peer->outboundproxy->transport); 27607 27608 if (ast_strlen_zero(proxyname)) { 27609 ast_log(LOG_WARNING, "you must specify a name for the outboundproxy on line %d of sip.conf\n", v->lineno); 27610 sip_cfg.outboundproxy.name[0] = '\0'; 27611 continue; 27612 } 27613 27614 ast_copy_string(peer->outboundproxy->name, proxyname, sizeof(peer->outboundproxy->name)); 27615 27616 proxy_update(peer->outboundproxy); 27617 } else if (!strcasecmp(v->name, "host")) { 27618 if (!strcasecmp(v->value, "dynamic")) { 27619 /* They'll register with us */ 27620 if (!found || !peer->host_dynamic) { 27621 /* Initialize stuff if this is a new peer, or if it used to 27622 * not be dynamic before the reload. */ 27623 ast_sockaddr_setnull(&peer->addr); 27624 } 27625 peer->host_dynamic = TRUE; 27626 } else { 27627 /* Non-dynamic. Make sure we become that way if we're not */ 27628 AST_SCHED_DEL_UNREF(sched, peer->expire, 27629 unref_peer(peer, "removing register expire ref")); 27630 peer->host_dynamic = FALSE; 27631 srvlookup = v->value; 27632 } 27633 } else if (!strcasecmp(v->name, "defaultip")) { 27634 if (!ast_strlen_zero(v->value) && ast_get_ip(&peer->defaddr, v->value)) { 27635 unref_peer(peer, "unref_peer: from build_peer defaultip"); 27636 return NULL; 27637 } 27638 } else if (!strcasecmp(v->name, "permit") || !strcasecmp(v->name, "deny")) { 27639 int ha_error = 0; 27640 if (!ast_strlen_zero(v->value)) { 27641 peer->ha = ast_append_ha(v->name, v->value, peer->ha, &ha_error); 27642 } 27643 if (ha_error) { 27644 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 27645 } 27646 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 27647 int ha_error = 0; 27648 if (!ast_strlen_zero(v->value)) { 27649 peer->contactha = ast_append_ha(v->name + 7, v->value, peer->contactha, &ha_error); 27650 } 27651 if (ha_error) { 27652 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 27653 } 27654 } else if (!strcasecmp(v->name, "directmediapermit") || !strcasecmp(v->name, "directmediadeny")) { 27655 int ha_error = 0; 27656 peer->directmediaha = ast_append_ha(v->name + 11, v->value, peer->directmediaha, &ha_error); 27657 if (ha_error) { 27658 ast_log(LOG_ERROR, "Bad directmedia ACL entry in configuration line %d : %s\n", v->lineno, v->value); 27659 } 27660 } else if (!strcasecmp(v->name, "port")) { 27661 peer->portinuri = 1; 27662 if (!(port = port_str2int(v->value, 0))) { 27663 if (realtime) { 27664 /* If stored as integer, could be 0 for some DBs (notably MySQL) */ 27665 peer->portinuri = 0; 27666 } else { 27667 ast_log(LOG_WARNING, "Invalid peer port configuration at line %d : %s\n", v->lineno, v->value); 27668 } 27669 } 27670 } else if (!strcasecmp(v->name, "callingpres")) { 27671 peer->callingpres = ast_parse_caller_presentation(v->value); 27672 if (peer->callingpres == -1) { 27673 peer->callingpres = atoi(v->value); 27674 } 27675 } else if (!strcasecmp(v->name, "username") || !strcmp(v->name, "defaultuser")) { /* "username" is deprecated */ 27676 ast_string_field_set(peer, username, v->value); 27677 if (!strcasecmp(v->name, "username")) { 27678 if (deprecation_warning) { 27679 ast_log(LOG_NOTICE, "The 'username' field for sip peers has been deprecated in favor of the term 'defaultuser'\n"); 27680 deprecation_warning = 0; 27681 } 27682 peer->deprecated_username = 1; 27683 } 27684 } else if (!strcasecmp(v->name, "language")) { 27685 ast_string_field_set(peer, language, v->value); 27686 } else if (!strcasecmp(v->name, "regexten")) { 27687 ast_string_field_set(peer, regexten, v->value); 27688 } else if (!strcasecmp(v->name, "callbackextension")) { 27689 ast_copy_string(callback, v->value, sizeof(callback)); 27690 } else if (!strcasecmp(v->name, "amaflags")) { 27691 format = ast_cdr_amaflags2int(v->value); 27692 if (format < 0) { 27693 ast_log(LOG_WARNING, "Invalid AMA Flags for peer: %s at line %d\n", v->value, v->lineno); 27694 } else { 27695 peer->amaflags = format; 27696 } 27697 } else if (!strcasecmp(v->name, "maxforwards")) { 27698 if (sscanf(v->value, "%30d", &peer->maxforwards) != 1 27699 || peer->maxforwards < 1 || 255 < peer->maxforwards) { 27700 ast_log(LOG_WARNING, "'%s' is not a valid maxforwards value at line %d. Using default.\n", v->value, v->lineno); 27701 peer->maxforwards = sip_cfg.default_max_forwards; 27702 } 27703 } else if (!strcasecmp(v->name, "accountcode")) { 27704 ast_string_field_set(peer, accountcode, v->value); 27705 } else if (!strcasecmp(v->name, "mohinterpret")) { 27706 ast_string_field_set(peer, mohinterpret, v->value); 27707 } else if (!strcasecmp(v->name, "mohsuggest")) { 27708 ast_string_field_set(peer, mohsuggest, v->value); 27709 } else if (!strcasecmp(v->name, "parkinglot")) { 27710 ast_string_field_set(peer, parkinglot, v->value); 27711 } else if (!strcasecmp(v->name, "rtp_engine")) { 27712 ast_string_field_set(peer, engine, v->value); 27713 } else if (!strcasecmp(v->name, "mailbox")) { 27714 add_peer_mailboxes(peer, v->value); 27715 } else if (!strcasecmp(v->name, "hasvoicemail")) { 27716 /* People expect that if 'hasvoicemail' is set, that the mailbox will 27717 * be also set, even if not explicitly specified. */ 27718 if (ast_true(v->value) && AST_LIST_EMPTY(&peer->mailboxes)) { 27719 add_peer_mailboxes(peer, name); 27720 } 27721 } else if (!strcasecmp(v->name, "subscribemwi")) { 27722 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_SUBSCRIBEMWIONLY); 27723 } else if (!strcasecmp(v->name, "vmexten")) { 27724 ast_string_field_set(peer, vmexten, v->value); 27725 } else if (!strcasecmp(v->name, "callgroup")) { 27726 peer->callgroup = ast_get_group(v->value); 27727 } else if (!strcasecmp(v->name, "allowtransfer")) { 27728 peer->allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 27729 } else if (!strcasecmp(v->name, "pickupgroup")) { 27730 peer->pickupgroup = ast_get_group(v->value); 27731 } else if (!strcasecmp(v->name, "allow")) { 27732 int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, TRUE); 27733 if (error) { 27734 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 27735 } 27736 } else if (!strcasecmp(v->name, "disallow")) { 27737 int error = ast_parse_allow_disallow(&peer->prefs, &peer->capability, v->value, FALSE); 27738 if (error) { 27739 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 27740 } 27741 } else if (!strcasecmp(v->name, "preferred_codec_only")) { 27742 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_PREFERRED_CODEC); 27743 } else if (!strcasecmp(v->name, "autoframing")) { 27744 peer->autoframing = ast_true(v->value); 27745 } else if (!strcasecmp(v->name, "rtptimeout")) { 27746 if ((sscanf(v->value, "%30d", &peer->rtptimeout) != 1) || (peer->rtptimeout < 0)) { 27747 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 27748 peer->rtptimeout = global_rtptimeout; 27749 } 27750 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 27751 if ((sscanf(v->value, "%30d", &peer->rtpholdtimeout) != 1) || (peer->rtpholdtimeout < 0)) { 27752 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 27753 peer->rtpholdtimeout = global_rtpholdtimeout; 27754 } 27755 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 27756 if ((sscanf(v->value, "%30d", &peer->rtpkeepalive) != 1) || (peer->rtpkeepalive < 0)) { 27757 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 27758 peer->rtpkeepalive = global_rtpkeepalive; 27759 } 27760 } else if (!strcasecmp(v->name, "timert1")) { 27761 if ((sscanf(v->value, "%30d", &peer->timer_t1) != 1) || (peer->timer_t1 < 200) || (peer->timer_t1 < global_t1min)) { 27762 ast_log(LOG_WARNING, "'%s' is not a valid T1 time at line %d. Using default.\n", v->value, v->lineno); 27763 peer->timer_t1 = global_t1min; 27764 } 27765 timert1_set = 1; 27766 } else if (!strcasecmp(v->name, "timerb")) { 27767 if ((sscanf(v->value, "%30d", &peer->timer_b) != 1) || (peer->timer_b < 200)) { 27768 ast_log(LOG_WARNING, "'%s' is not a valid Timer B time at line %d. Using default.\n", v->value, v->lineno); 27769 peer->timer_b = global_timer_b; 27770 } 27771 timerb_set = 1; 27772 } else if (!strcasecmp(v->name, "setvar")) { 27773 peer->chanvars = add_var(v->value, peer->chanvars); 27774 } else if (!strcasecmp(v->name, "header")) { 27775 char tmp[4096]; 27776 snprintf(tmp, sizeof(tmp), "__SIPADDHEADERpre%2d=%s", ++headercount, v->value); 27777 peer->chanvars = add_var(tmp, peer->chanvars); 27778 } else if (!strcasecmp(v->name, "qualifyfreq")) { 27779 int i; 27780 if (sscanf(v->value, "%30d", &i) == 1) { 27781 peer->qualifyfreq = i * 1000; 27782 } else { 27783 ast_log(LOG_WARNING, "Invalid qualifyfreq number '%s' at line %d of %s\n", v->value, v->lineno, config); 27784 peer->qualifyfreq = global_qualifyfreq; 27785 } 27786 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 27787 peer->maxcallbitrate = atoi(v->value); 27788 if (peer->maxcallbitrate < 0) { 27789 peer->maxcallbitrate = default_maxcallbitrate; 27790 } 27791 } else if (!strcasecmp(v->name, "session-timers")) { 27792 int i = (int) str2stmode(v->value); 27793 if (i < 0) { 27794 ast_log(LOG_WARNING, "Invalid session-timers '%s' at line %d of %s\n", v->value, v->lineno, config); 27795 peer->stimer.st_mode_oper = global_st_mode; 27796 } else { 27797 peer->stimer.st_mode_oper = i; 27798 } 27799 } else if (!strcasecmp(v->name, "session-expires")) { 27800 if (sscanf(v->value, "%30d", &peer->stimer.st_max_se) != 1) { 27801 ast_log(LOG_WARNING, "Invalid session-expires '%s' at line %d of %s\n", v->value, v->lineno, config); 27802 peer->stimer.st_max_se = global_max_se; 27803 } 27804 } else if (!strcasecmp(v->name, "session-minse")) { 27805 if (sscanf(v->value, "%30d", &peer->stimer.st_min_se) != 1) { 27806 ast_log(LOG_WARNING, "Invalid session-minse '%s' at line %d of %s\n", v->value, v->lineno, config); 27807 peer->stimer.st_min_se = global_min_se; 27808 } 27809 if (peer->stimer.st_min_se < 90) { 27810 ast_log(LOG_WARNING, "session-minse '%s' at line %d of %s is not allowed to be < 90 secs\n", v->value, v->lineno, config); 27811 peer->stimer.st_min_se = global_min_se; 27812 } 27813 } else if (!strcasecmp(v->name, "session-refresher")) { 27814 int i = (int) str2strefresher(v->value); 27815 if (i < 0) { 27816 ast_log(LOG_WARNING, "Invalid session-refresher '%s' at line %d of %s\n", v->value, v->lineno, config); 27817 peer->stimer.st_ref = global_st_refresher; 27818 } else { 27819 peer->stimer.st_ref = i; 27820 } 27821 } else if (!strcasecmp(v->name, "disallowed_methods")) { 27822 char *disallow = ast_strdupa(v->value); 27823 mark_parsed_methods(&peer->disallowed_methods, disallow); 27824 } else if (!strcasecmp(v->name, "unsolicited_mailbox")) { 27825 ast_string_field_set(peer, unsolicited_mailbox, v->value); 27826 } else if (!strcasecmp(v->name, "use_q850_reason")) { 27827 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON); 27828 } else if (!strcasecmp(v->name, "encryption")) { 27829 ast_set2_flag(&peer->flags[1], ast_true(v->value), SIP_PAGE2_USE_SRTP); 27830 } else if (!strcasecmp(v->name, "snom_aoc_enabled")) { 27831 ast_set2_flag(&peer->flags[2], ast_true(v->value), SIP_PAGE3_SNOM_AOC); 27832 } 27833 } 27834 27835 /* These apply to devstate lookups */ 27836 if (realtime && !strcasecmp(v->name, "lastms")) { 27837 sscanf(v->value, "%30d", &peer->lastms); 27838 } else if (realtime && !strcasecmp(v->name, "ipaddr") && !ast_strlen_zero(v->value) ) { 27839 ast_sockaddr_parse(&peer->addr, v->value, PARSE_PORT_FORBID); 27840 } else if (realtime && !strcasecmp(v->name, "fullcontact")) { 27841 if (alt_fullcontact && !alt) { 27842 /* Reset, because the alternate also has a fullcontact and we 27843 * do NOT want the field value to be doubled. It might be 27844 * tempting to skip this, but the first table might not have 27845 * fullcontact and since we're here, we know that the alternate 27846 * absolutely does. */ 27847 alt_fullcontact = 0; 27848 ast_str_reset(fullcontact); 27849 } 27850 /* Reconstruct field, because realtime separates our value at the ';' */ 27851 if (fullcontact->used > 0) { 27852 ast_str_append(&fullcontact, 0, ";%s", v->value); 27853 } else { 27854 ast_str_set(&fullcontact, 0, "%s", v->value); 27855 } 27856 } else if (!strcasecmp(v->name, "qualify")) { 27857 if (!strcasecmp(v->value, "no")) { 27858 peer->maxms = 0; 27859 } else if (!strcasecmp(v->value, "yes")) { 27860 peer->maxms = default_qualify ? default_qualify : DEFAULT_MAXMS; 27861 } else if (sscanf(v->value, "%30d", &peer->maxms) != 1) { 27862 ast_log(LOG_WARNING, "Qualification of peer '%s' should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", peer->name, v->lineno); 27863 peer->maxms = 0; 27864 } 27865 if (realtime && !ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->maxms > 0) { 27866 /* This would otherwise cause a network storm, where the 27867 * qualify response refreshes the peer from the database, 27868 * which in turn causes another qualify to be sent, ad 27869 * infinitum. */ 27870 ast_log(LOG_WARNING, "Qualify is incompatible with dynamic uncached realtime. Please either turn rtcachefriends on or turn qualify off on peer '%s'\n", peer->name); 27871 peer->maxms = 0; 27872 } 27873 } else if (!strcasecmp(v->name, "callcounter")) { 27874 peer->call_limit = ast_true(v->value) ? INT_MAX : 0; 27875 } else if (!strcasecmp(v->name, "call-limit")) { 27876 peer->call_limit = atoi(v->value); 27877 if (peer->call_limit < 0) { 27878 peer->call_limit = 0; 27879 } 27880 } else if (!strcasecmp(v->name, "busylevel")) { 27881 peer->busy_level = atoi(v->value); 27882 if (peer->busy_level < 0) { 27883 peer->busy_level = 0; 27884 } 27885 } else if (ast_cc_is_config_param(v->name)) { 27886 ast_cc_set_param(peer->cc_params, v->name, v->value); 27887 } 27888 } 27889 27890 if (!devstate_only) { 27891 struct sip_mailbox *mailbox; 27892 AST_LIST_TRAVERSE_SAFE_BEGIN(&peer->mailboxes, mailbox, entry) { 27893 if (mailbox->delme) { 27894 AST_LIST_REMOVE_CURRENT(entry); 27895 destroy_mailbox(mailbox); 27896 } 27897 } 27898 AST_LIST_TRAVERSE_SAFE_END; 27899 } 27900 27901 if (!can_parse_xml && (ast_get_cc_agent_policy(peer->cc_params) == AST_CC_AGENT_NATIVE)) { 27902 ast_log(LOG_WARNING, "Peer %s has a cc_agent_policy of 'native' but required libxml2 dependency is not installed. Changing policy to 'never'\n", peer->name); 27903 ast_set_cc_agent_policy(peer->cc_params, AST_CC_AGENT_NEVER); 27904 } 27905 27906 /* Note that Timer B is dependent upon T1 and MUST NOT be lower 27907 * than T1 * 64, according to RFC 3261, Section 17.1.1.2 */ 27908 if (peer->timer_b < peer->timer_t1 * 64) { 27909 if (timerb_set && timert1_set) { 27910 ast_log(LOG_WARNING, "Timer B has been set lower than recommended for peer %s (%d < 64 * Timer-T1=%d)\n", peer->name, peer->timer_b, peer->timer_t1); 27911 } else if (timerb_set) { 27912 if ((peer->timer_t1 = peer->timer_b / 64) < global_t1min) { 27913 ast_log(LOG_WARNING, "Timer B has been set lower than recommended (%d < 64 * timert1=%d). (RFC 3261, 17.1.1.2)\n", peer->timer_b, peer->timer_t1); 27914 peer->timer_t1 = global_t1min; 27915 peer->timer_b = peer->timer_t1 * 64; 27916 } 27917 peer->timer_t1 = peer->timer_b / 64; 27918 } else { 27919 peer->timer_b = peer->timer_t1 * 64; 27920 } 27921 } 27922 27923 if (!peer->default_outbound_transport) { 27924 /* Set default set of transports */ 27925 peer->transports = default_transports; 27926 /* Set default primary transport */ 27927 peer->default_outbound_transport = default_primary_transport; 27928 } 27929 27930 /* The default transport type set during build_peer should only replace the socket.type when... 27931 * 1. Registration is not present and the socket.type and default transport types are different. 27932 * 2. The socket.type is not an acceptable transport type after rebuilding peer. 27933 * 3. The socket.type is not set yet. */ 27934 if (((peer->socket.type != peer->default_outbound_transport) && (peer->expire == -1)) || 27935 !(peer->socket.type & peer->transports) || !(peer->socket.type)) { 27936 27937 set_socket_transport(&peer->socket, peer->default_outbound_transport); 27938 } 27939 27940 if (ast_str_strlen(fullcontact)) { 27941 ast_string_field_set(peer, fullcontact, ast_str_buffer(fullcontact)); 27942 peer->rt_fromcontact = TRUE; 27943 /* We have a hostname in the fullcontact, but if we don't have an 27944 * address listed on the entry (or if it's 'dynamic'), then we need to 27945 * parse the entry to obtain the IP address, so a dynamic host can be 27946 * contacted immediately after reload (as opposed to waiting for it to 27947 * register once again). But if we have an address for this peer and NAT was 27948 * specified, use that address instead. */ 27949 /* XXX May need to revisit the final argument; does the realtime DB store whether 27950 * the original contact was over TLS or not? XXX */ 27951 if (!ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) || ast_sockaddr_isnull(&peer->addr)) { 27952 __set_address_from_contact(fullcontact->str, &peer->addr, 0); 27953 } 27954 } 27955 27956 if (srvlookup && peer->dnsmgr == NULL) { 27957 char transport[MAXHOSTNAMELEN]; 27958 char _srvlookup[MAXHOSTNAMELEN]; 27959 char *params; 27960 27961 ast_copy_string(_srvlookup, srvlookup, sizeof(_srvlookup)); 27962 if ((params = strchr(_srvlookup, ';'))) { 27963 *params++ = '\0'; 27964 } 27965 27966 snprintf(transport, sizeof(transport), "_%s._%s", get_srv_service(peer->socket.type), get_srv_protocol(peer->socket.type)); 27967 27968 peer->addr.ss.ss_family = get_address_family_filter(peer->socket.type); /* Filter address family */ 27969 if (ast_dnsmgr_lookup_cb(_srvlookup, &peer->addr, &peer->dnsmgr, sip_cfg.srvlookup && !peer->portinuri ? transport : NULL, 27970 on_dns_update_peer, ref_peer(peer, "Store peer on dnsmgr"))) { 27971 ast_log(LOG_ERROR, "srvlookup failed for host: %s, on peer %s, removing peer\n", _srvlookup, peer->name); 27972 unref_peer(peer, "dnsmgr lookup failed, getting rid of peer dnsmgr ref"); 27973 unref_peer(peer, "getting rid of a peer pointer"); 27974 return NULL; 27975 } 27976 if (!peer->dnsmgr) { 27977 /* dnsmgr refresh disabeld, release reference */ 27978 unref_peer(peer, "dnsmgr disabled, unref peer"); 27979 } 27980 27981 ast_string_field_set(peer, tohost, srvlookup); 27982 27983 if (global_dynamic_exclude_static && !ast_sockaddr_isnull(&peer->addr)) { 27984 int ha_error = 0; 27985 sip_cfg.contact_ha = ast_append_ha("deny", ast_sockaddr_stringify_addr(&peer->addr), 27986 sip_cfg.contact_ha, &ha_error); 27987 if (ha_error) { 27988 ast_log(LOG_ERROR, "Bad or unresolved host/IP entry in configuration for peer %s, cannot add to contact ACL\n", peer->name); 27989 } 27990 } 27991 } else if (peer->dnsmgr && !peer->host_dynamic) { 27992 /* force a refresh here on reload if dnsmgr already exists and host is set. */ 27993 ast_dnsmgr_refresh(peer->dnsmgr); 27994 } 27995 27996 if (port && !realtime && peer->host_dynamic) { 27997 ast_sockaddr_set_port(&peer->defaddr, port); 27998 } else if (port) { 27999 ast_sockaddr_set_port(&peer->addr, port); 28000 } 28001 28002 if (ast_sockaddr_port(&peer->addr) == 0) { 28003 ast_sockaddr_set_port(&peer->addr, 28004 (peer->socket.type & SIP_TRANSPORT_TLS) ? 28005 STANDARD_TLS_PORT : STANDARD_SIP_PORT); 28006 } 28007 if (ast_sockaddr_port(&peer->defaddr) == 0) { 28008 ast_sockaddr_set_port(&peer->defaddr, 28009 (peer->socket.type & SIP_TRANSPORT_TLS) ? 28010 STANDARD_TLS_PORT : STANDARD_SIP_PORT); 28011 } 28012 if (!peer->socket.port) { 28013 peer->socket.port = htons(((peer->socket.type & SIP_TRANSPORT_TLS) ? STANDARD_TLS_PORT : STANDARD_SIP_PORT)); 28014 } 28015 28016 if (!sip_cfg.ignore_regexpire && peer->host_dynamic && realtime) { 28017 time_t nowtime = time(NULL); 28018 28019 if ((nowtime - regseconds) > 0) { 28020 destroy_association(peer); 28021 memset(&peer->addr, 0, sizeof(peer->addr)); 28022 peer->lastms = -1; 28023 ast_debug(1, "Bah, we're expired (%d/%d/%d)!\n", (int)(nowtime - regseconds), (int)regseconds, (int)nowtime); 28024 } 28025 } 28026 28027 /* Startup regular pokes */ 28028 if (!devstate_only && realtime && peer->lastms > 0) { 28029 ref_peer(peer, "schedule qualify"); 28030 sip_poke_peer(peer, 0); 28031 } 28032 28033 ast_copy_flags(&peer->flags[0], &peerflags[0], mask[0].flags); 28034 ast_copy_flags(&peer->flags[1], &peerflags[1], mask[1].flags); 28035 ast_copy_flags(&peer->flags[2], &peerflags[2], mask[2].flags); 28036 if (ast_test_flag(&peer->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { 28037 sip_cfg.allowsubscribe = TRUE; /* No global ban any more */ 28038 } 28039 /* If read-only RT backend, then refresh from local DB cache */ 28040 if (peer->host_dynamic && (!peer->is_realtime || !sip_cfg.peer_rtupdate)) { 28041 reg_source_db(peer); 28042 } 28043 28044 /* If they didn't request that MWI is sent *only* on subscribe, go ahead and 28045 * subscribe to it now. */ 28046 if (!devstate_only && !ast_test_flag(&peer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY) && 28047 !AST_LIST_EMPTY(&peer->mailboxes)) { 28048 add_peer_mwi_subs(peer); 28049 /* Send MWI from the event cache only. This is so we can send initial 28050 * MWI if app_voicemail got loaded before chan_sip. If it is the other 28051 * way, then we will get events when app_voicemail gets loaded. */ 28052 sip_send_mwi_to_peer(peer, 1); 28053 } 28054 28055 peer->the_mark = 0; 28056 28057 ast_free_ha(oldha); 28058 ast_free_ha(olddirectmediaha); 28059 if (!ast_strlen_zero(callback)) { /* build string from peer info */ 28060 char *reg_string; 28061 if (asprintf(®_string, "%s?%s:%s@%s/%s", peer->name, peer->username, !ast_strlen_zero(peer->remotesecret) ? peer->remotesecret : peer->secret, peer->tohost, callback) < 0) { 28062 ast_log(LOG_WARNING, "asprintf() failed: %s\n", strerror(errno)); 28063 } else if (reg_string) { 28064 sip_register(reg_string, 0); /* XXX TODO: count in registry_count */ 28065 ast_free(reg_string); 28066 } 28067 } 28068 return peer; 28069 }
| static int build_reply_digest | ( | struct sip_pvt * | p, | |
| int | method, | |||
| char * | digest, | |||
| int | digest_len | |||
| ) | [static] |
Build reply digest.
Definition at line 19329 of file chan_sip.c.
References ao2_lock, ao2_t_ref, ao2_unlock, append_history, ast_copy_string(), ast_debug, ast_md5_hash(), ast_mutex_lock, ast_mutex_unlock, ast_random(), ast_sockaddr_stringify_host_remote(), ast_strlen_zero(), find_realm_authentication(), secret, sip_methods, and text.
Referenced by reply_digest(), transmit_register(), and transmit_request_with_auth().
19330 { 19331 char a1[256]; 19332 char a2[256]; 19333 char a1_hash[256]; 19334 char a2_hash[256]; 19335 char resp[256]; 19336 char resp_hash[256]; 19337 char uri[256]; 19338 char opaque[256] = ""; 19339 char cnonce[80]; 19340 const char *username; 19341 const char *secret; 19342 const char *md5secret; 19343 struct sip_auth *auth; /* Realm authentication credential */ 19344 struct sip_auth_container *credentials; 19345 19346 if (!ast_strlen_zero(p->domain)) 19347 snprintf(uri, sizeof(uri), "%s:%s", p->socket.type == SIP_TRANSPORT_TLS ? "sips" : "sip", p->domain); 19348 else if (!ast_strlen_zero(p->uri)) 19349 ast_copy_string(uri, p->uri, sizeof(uri)); 19350 else 19351 snprintf(uri, sizeof(uri), "%s:%s@%s", p->socket.type == SIP_TRANSPORT_TLS ? "sips" : "sip", p->username, ast_sockaddr_stringify_host_remote(&p->sa)); 19352 19353 snprintf(cnonce, sizeof(cnonce), "%08lx", ast_random()); 19354 19355 /* Check if we have peer credentials */ 19356 ao2_lock(p); 19357 credentials = p->peerauth; 19358 if (credentials) { 19359 ao2_t_ref(credentials, +1, "Ref peer auth for digest"); 19360 } 19361 ao2_unlock(p); 19362 auth = find_realm_authentication(credentials, p->realm); 19363 if (!auth) { 19364 /* If not, check global credentials */ 19365 if (credentials) { 19366 ao2_t_ref(credentials, -1, "Unref peer auth for digest"); 19367 } 19368 ast_mutex_lock(&authl_lock); 19369 credentials = authl; 19370 if (credentials) { 19371 ao2_t_ref(credentials, +1, "Ref global auth for digest"); 19372 } 19373 ast_mutex_unlock(&authl_lock); 19374 auth = find_realm_authentication(credentials, p->realm); 19375 } 19376 19377 if (auth) { 19378 ast_debug(3, "use realm [%s] from peer [%s][%s]\n", auth->username, p->peername, p->username); 19379 username = auth->username; 19380 secret = auth->secret; 19381 md5secret = auth->md5secret; 19382 if (sipdebug) 19383 ast_debug(1, "Using realm %s authentication for call %s\n", p->realm, p->callid); 19384 } else { 19385 /* No authentication, use peer or register= config */ 19386 username = p->authname; 19387 secret = p->relatedpeer 19388 && !ast_strlen_zero(p->relatedpeer->remotesecret) 19389 ? p->relatedpeer->remotesecret : p->peersecret; 19390 md5secret = p->peermd5secret; 19391 } 19392 if (ast_strlen_zero(username)) { 19393 /* We have no authentication */ 19394 if (credentials) { 19395 ao2_t_ref(credentials, -1, "Unref auth for digest"); 19396 } 19397 return -1; 19398 } 19399 19400 /* Calculate SIP digest response */ 19401 snprintf(a1, sizeof(a1), "%s:%s:%s", username, p->realm, secret); 19402 snprintf(a2, sizeof(a2), "%s:%s", sip_methods[method].text, uri); 19403 if (!ast_strlen_zero(md5secret)) 19404 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 19405 else 19406 ast_md5_hash(a1_hash, a1); 19407 ast_md5_hash(a2_hash, a2); 19408 19409 p->noncecount++; 19410 if (!ast_strlen_zero(p->qop)) 19411 snprintf(resp, sizeof(resp), "%s:%s:%08x:%s:%s:%s", a1_hash, p->nonce, p->noncecount, cnonce, "auth", a2_hash); 19412 else 19413 snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, p->nonce, a2_hash); 19414 ast_md5_hash(resp_hash, resp); 19415 19416 /* only include the opaque string if it's set */ 19417 if (!ast_strlen_zero(p->opaque)) { 19418 snprintf(opaque, sizeof(opaque), ", opaque=\"%s\"", p->opaque); 19419 } 19420 19421 /* XXX We hard code our qop to "auth" for now. XXX */ 19422 if (!ast_strlen_zero(p->qop)) 19423 snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\"%s, qop=auth, cnonce=\"%s\", nc=%08x", username, p->realm, uri, p->nonce, resp_hash, opaque, cnonce, p->noncecount); 19424 else 19425 snprintf(digest, digest_len, "Digest username=\"%s\", realm=\"%s\", algorithm=MD5, uri=\"%s\", nonce=\"%s\", response=\"%s\"%s", username, p->realm, uri, p->nonce, resp_hash, opaque); 19426 19427 append_history(p, "AuthResp", "Auth response sent for %s in realm %s - nc %d", username, p->realm, p->noncecount); 19428 19429 if (credentials) { 19430 ao2_t_ref(credentials, -1, "Unref auth for digest"); 19431 } 19432 return 0; 19433 }
| static void build_route | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | backwards, | |||
| int | resp | |||
| ) | [static] |
Build route list from Record-Route header.
| resp | the SIP response code or 0 for a request |
Definition at line 14256 of file chan_sip.c.
References __get_header(), ast_copy_string(), ast_debug, ast_malloc, ast_strdupa, ast_strlen_zero(), free_old_route(), get_header(), get_in_brackets(), len(), list_route(), and sip_debug_test_pvt().
Referenced by handle_request_invite(), handle_request_subscribe(), and handle_response_invite().
14257 { 14258 struct sip_route *thishop, *head, *tail; 14259 int start = 0; 14260 int len; 14261 const char *rr, *c; 14262 14263 /* Once a persistent route is set, don't fool with it */ 14264 if (p->route && p->route_persistent) { 14265 ast_debug(1, "build_route: Retaining previous route: <%s>\n", p->route->hop); 14266 return; 14267 } 14268 14269 if (p->route) { 14270 free_old_route(p->route); 14271 p->route = NULL; 14272 } 14273 14274 /* We only want to create the route set the first time this is called except 14275 it is called from a provisional response.*/ 14276 if ((resp < 100) || (resp > 199)) { 14277 p->route_persistent = 1; 14278 } 14279 14280 /* Build a tailq, then assign it to p->route when done. 14281 * If backwards, we add entries from the head so they end up 14282 * in reverse order. However, we do need to maintain a correct 14283 * tail pointer because the contact is always at the end. 14284 */ 14285 head = NULL; 14286 tail = head; 14287 /* 1st we pass through all the hops in any Record-Route headers */ 14288 for (;;) { 14289 /* Each Record-Route header */ 14290 char rr_copy[256]; 14291 char *rr_copy_ptr; 14292 char *rr_iter; 14293 rr = __get_header(req, "Record-Route", &start); 14294 if (*rr == '\0') { 14295 break; 14296 } 14297 ast_copy_string(rr_copy, rr, sizeof(rr_copy)); 14298 rr_copy_ptr = rr_copy; 14299 while ((rr_iter = strsep(&rr_copy_ptr, ","))) { /* Each route entry */ 14300 char *uri = get_in_brackets(rr_iter); 14301 len = strlen(uri) + 1; 14302 /* Make a struct route */ 14303 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 14304 /* ast_calloc is not needed because all fields are initialized in this block */ 14305 ast_copy_string(thishop->hop, uri, len); 14306 ast_debug(2, "build_route: Record-Route hop: <%s>\n", thishop->hop); 14307 /* Link in */ 14308 if (backwards) { 14309 /* Link in at head so they end up in reverse order */ 14310 thishop->next = head; 14311 head = thishop; 14312 /* If this was the first then it'll be the tail */ 14313 if (!tail) { 14314 tail = thishop; 14315 } 14316 } else { 14317 thishop->next = NULL; 14318 /* Link in at the end */ 14319 if (tail) { 14320 tail->next = thishop; 14321 } else { 14322 head = thishop; 14323 } 14324 tail = thishop; 14325 } 14326 } 14327 } 14328 } 14329 14330 /* Only append the contact if we are dealing with a strict router */ 14331 if (!head || (!ast_strlen_zero(head->hop) && strstr(head->hop, ";lr") == NULL) ) { 14332 /* 2nd append the Contact: if there is one */ 14333 /* Can be multiple Contact headers, comma separated values - we just take the first */ 14334 char *contact = ast_strdupa(get_header(req, "Contact")); 14335 if (!ast_strlen_zero(contact)) { 14336 ast_debug(2, "build_route: Contact hop: %s\n", contact); 14337 /* Look for <: delimited address */ 14338 c = get_in_brackets(contact); 14339 len = strlen(c) + 1; 14340 if ((thishop = ast_malloc(sizeof(*thishop) + len))) { 14341 /* ast_calloc is not needed because all fields are initialized in this block */ 14342 ast_copy_string(thishop->hop, c, len); 14343 thishop->next = NULL; 14344 /* Goes at the end */ 14345 if (tail) { 14346 tail->next = thishop; 14347 } else { 14348 head = thishop; 14349 } 14350 } 14351 } 14352 } 14353 14354 /* Store as new route */ 14355 p->route = head; 14356 14357 /* For debugging dump what we ended up with */ 14358 if (sip_debug_test_pvt(p)) { 14359 list_route(p->route); 14360 } 14361 }
| static void build_via | ( | struct sip_pvt * | p | ) | [static] |
Build a Via header for a request.
Definition at line 3379 of file chan_sip.c.
References ast_sockaddr_stringify_remote(), ast_test_flag, and get_transport_pvt().
Referenced by __sip_subscribe_mwi_do(), reqprep(), sip_alloc(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_invite(), transmit_register(), and transmit_response_using_temp().
03380 { 03381 /* Work around buggy UNIDEN UIP200 firmware */ 03382 const char *rport = (ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT) || ast_test_flag(&p->flags[0], SIP_NAT_RPORT_PRESENT)) ? ";rport" : ""; 03383 03384 /* z9hG4bK is a magic cookie. See RFC 3261 section 8.1.1.7 */ 03385 snprintf(p->via, sizeof(p->via), "SIP/2.0/%s %s;branch=z9hG4bK%08x%s", 03386 get_transport_pvt(p), 03387 ast_sockaddr_stringify_remote(&p->ourip), 03388 (int) p->branch, rport); 03389 }
| static int cb_extensionstate | ( | char * | context, | |
| char * | exten, | |||
| int | state, | |||
| void * | data | |||
| ) | [static] |
Callback for the devicestate notification (SUBSCRIBE) support subsystem.
Definition at line 14634 of file chan_sip.c.
References append_history, AST_EXTENSION_DEACTIVATED, AST_EXTENSION_REMOVED, ast_extension_state2str(), ast_set_flag, ast_test_flag, ast_verb, FALSE, NONE, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), and transmit_state_notify().
Referenced by dialog_unlink_all(), handle_request_subscribe(), and handle_response_notify().
14635 { 14636 struct sip_pvt *p = data; 14637 14638 sip_pvt_lock(p); 14639 14640 switch(state) { 14641 case AST_EXTENSION_DEACTIVATED: /* Retry after a while */ 14642 case AST_EXTENSION_REMOVED: /* Extension is gone */ 14643 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); /* Delete subscription in 32 secs */ 14644 ast_verb(2, "Extension state: Watcher for hint %s %s. Notify User %s\n", exten, state == AST_EXTENSION_DEACTIVATED ? "deactivated" : "removed", p->username); 14645 p->subscribed = NONE; 14646 append_history(p, "Subscribestatus", "%s", state == AST_EXTENSION_REMOVED ? "HintRemoved" : "Deactivated"); 14647 break; 14648 default: /* Tell user */ 14649 p->laststate = state; 14650 break; 14651 } 14652 if (p->subscribed != NONE) { /* Only send state NOTIFY if we know the format */ 14653 if (!p->pendinginvite) { 14654 transmit_state_notify(p, state, 1, FALSE); 14655 } else { 14656 /* We already have a NOTIFY sent that is not answered. Queue the state up. 14657 if many state changes happen meanwhile, we will only send a notification of the last one */ 14658 ast_set_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 14659 } 14660 } 14661 ast_verb(2, "Extension Changed %s[%s] new state %s for Notify User %s %s\n", exten, context, ast_extension_state2str(state), p->username, 14662 ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE) ? "(queued)" : ""); 14663 14664 sip_pvt_unlock(p); 14665 14666 return 0; 14667 }
| static void cb_extensionstate_destroy | ( | int | id, | |
| void * | data | |||
| ) | [static] |
Definition at line 14624 of file chan_sip.c.
Referenced by handle_request_subscribe().
| static void cc_epa_destructor | ( | void * | data | ) | [static] |
Definition at line 891 of file chan_sip.c.
References ast_free.
00892 { 00893 struct sip_epa_entry *epa_entry = data; 00894 struct cc_epa_entry *cc_entry = epa_entry->instance_data; 00895 ast_free(cc_entry); 00896 }
| static void cc_handle_publish_error | ( | struct sip_pvt * | pvt, | |
| const int | resp, | |||
| struct sip_request * | req, | |||
| struct sip_epa_entry * | epa_entry | |||
| ) | [static] |
Definition at line 19952 of file chan_sip.c.
References ao2_callback, ao2_ref, ast_cc_monitor_failed(), ast_log(), ast_strlen_zero(), FALSE, find_sip_monitor_instance_by_suspension_entry(), get_header(), LOG_WARNING, and transmit_invite().
19953 { 19954 struct cc_epa_entry *cc_entry = epa_entry->instance_data; 19955 struct sip_monitor_instance *monitor_instance = ao2_callback(sip_monitor_instances, 0, 19956 find_sip_monitor_instance_by_suspension_entry, epa_entry); 19957 const char *min_expires; 19958 19959 if (!monitor_instance) { 19960 ast_log(LOG_WARNING, "Can't find monitor_instance corresponding to epa_entry %p.\n", epa_entry); 19961 return; 19962 } 19963 19964 if (resp != 423) { 19965 ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name, 19966 "Received error response to our PUBLISH"); 19967 ao2_ref(monitor_instance, -1); 19968 return; 19969 } 19970 19971 /* Allrighty, the other end doesn't like our Expires value. They think it's 19972 * too small, so let's see if they've provided a more sensible value. If they 19973 * haven't, then we'll just double our Expires value and see if they like that 19974 * instead. 19975 * 19976 * XXX Ideally this logic could be placed into its own function so that SUBSCRIBE, 19977 * PUBLISH, and REGISTER could all benefit from the same shared code. 19978 */ 19979 min_expires = get_header(req, "Min-Expires"); 19980 if (ast_strlen_zero(min_expires)) { 19981 pvt->expiry *= 2; 19982 if (pvt->expiry < 0) { 19983 /* You dork! You overflowed! */ 19984 ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name, 19985 "PUBLISH expiry overflowed"); 19986 ao2_ref(monitor_instance, -1); 19987 return; 19988 } 19989 } else if (sscanf(min_expires, "%d", &pvt->expiry) != 1) { 19990 ast_cc_monitor_failed(cc_entry->core_id, monitor_instance->device_name, 19991 "Min-Expires has non-numeric value"); 19992 ao2_ref(monitor_instance, -1); 19993 return; 19994 } 19995 /* At this point, we have most certainly changed pvt->expiry, so try transmitting 19996 * again 19997 */ 19998 transmit_invite(pvt, SIP_PUBLISH, FALSE, 0, NULL); 19999 ao2_ref(monitor_instance, -1); 20000 }
| static void change_callid_pvt | ( | struct sip_pvt * | pvt, | |
| const char * | callid | |||
| ) | [static] |
Definition at line 7607 of file chan_sip.c.
References ao2_lock, ao2_t_link, ao2_unlock, ast_string_field_set, build_callid_pvt(), and CONTAINER_UNLINK.
Referenced by __sip_subscribe_mwi_do(), create_addr_from_peer(), sip_poke_peer(), sip_request_call(), and sip_send_mwi_to_peer().
07608 { 07609 int in_dialog_container; 07610 07611 ao2_lock(dialogs); 07612 in_dialog_container = CONTAINER_UNLINK(dialogs, pvt, 07613 "About to change the callid -- remove the old name"); 07614 if (callid) { 07615 ast_string_field_set(pvt, callid, callid); 07616 } else { 07617 build_callid_pvt(pvt); 07618 } 07619 if (in_dialog_container) { 07620 ao2_t_link(dialogs, pvt, "New dialog callid -- inserted back into table"); 07621 } 07622 ao2_unlock(dialogs); 07623 }
| static void change_hold_state | ( | struct sip_pvt * | dialog, | |
| struct sip_request * | req, | |||
| int | holdstate, | |||
| int | sendonly | |||
| ) | [static] |
Change hold state for a call.
Definition at line 8682 of file chan_sip.c.
References append_history, ast_clear_flag, ast_set_flag, ast_test_flag, EVENT_FLAG_CALL, manager_event, sip_cfg, and sip_peer_hold().
Referenced by handle_request_invite(), and process_sdp().
08683 { 08684 if (sip_cfg.notifyhold && (!holdstate || !ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD))) 08685 sip_peer_hold(dialog, holdstate); 08686 if (sip_cfg.callevents) 08687 manager_event(EVENT_FLAG_CALL, "Hold", 08688 "Status: %s\r\n" 08689 "Channel: %s\r\n" 08690 "Uniqueid: %s\r\n", 08691 holdstate ? "On" : "Off", 08692 dialog->owner->name, 08693 dialog->owner->uniqueid); 08694 append_history(dialog, holdstate ? "Hold" : "Unhold", "%s", req->data->str); 08695 if (!holdstate) { /* Put off remote hold */ 08696 ast_clear_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD); /* Clear both flags */ 08697 return; 08698 } 08699 /* No address for RTP, we're on hold */ 08700 08701 /* Ensure hold flags are cleared so that overlapping flags do not conflict */ 08702 ast_clear_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD); 08703 08704 if (sendonly == 1) /* One directional hold (sendonly/recvonly) */ 08705 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ONEDIR); 08706 else if (sendonly == 2) /* Inactive stream */ 08707 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_INACTIVE); 08708 else 08709 ast_set_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD_ACTIVE); 08710 return; 08711 }
| 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 | |||
| ) | [static] |
update redirecting information for a channel based on headers
Definition at line 19681 of file chan_sip.c.
References ast_debug, ast_free, AST_REDIRECTING_REASON_UNCONDITIONAL, ast_strdup, ast_strlen_zero(), ast_party_redirecting::from, ast_set_party_redirecting::from, get_header(), get_name_and_number(), get_rdnis(), ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, parse_moved_contact(), ast_party_redirecting::reason, ast_party_name::str, ast_party_number::str, ast_party_id::tag, ast_set_party_redirecting::to, ast_party_redirecting::to, ast_party_name::valid, and ast_party_number::valid.
Referenced by handle_request_invite(), handle_response(), and handle_response_invite().
19684 { 19685 char *redirecting_from_name = NULL; 19686 char *redirecting_from_number = NULL; 19687 char *redirecting_to_name = NULL; 19688 char *redirecting_to_number = NULL; 19689 int reason = AST_REDIRECTING_REASON_UNCONDITIONAL; 19690 int is_response = req->method == SIP_RESPONSE; 19691 int res = 0; 19692 19693 res = get_rdnis(p, req, &redirecting_from_name, &redirecting_from_number, &reason); 19694 if (res == -1) { 19695 if (is_response) { 19696 get_name_and_number(get_header(req, "TO"), &redirecting_from_name, &redirecting_from_number); 19697 } else { 19698 return; 19699 } 19700 } 19701 19702 /* At this point, all redirecting "from" info should be filled in appropriately 19703 * on to the "to" info 19704 */ 19705 19706 if (is_response) { 19707 parse_moved_contact(p, req, &redirecting_to_name, &redirecting_to_number, set_call_forward); 19708 } else { 19709 get_name_and_number(get_header(req, "TO"), &redirecting_to_name, &redirecting_to_number); 19710 } 19711 19712 if (!ast_strlen_zero(redirecting_from_number)) { 19713 ast_debug(3, "Got redirecting from number %s\n", redirecting_from_number); 19714 update_redirecting->from.number = 1; 19715 redirecting->from.number.valid = 1; 19716 ast_free(redirecting->from.number.str); 19717 redirecting->from.number.str = redirecting_from_number; 19718 } 19719 if (!ast_strlen_zero(redirecting_from_name)) { 19720 ast_debug(3, "Got redirecting from name %s\n", redirecting_from_name); 19721 update_redirecting->from.name = 1; 19722 redirecting->from.name.valid = 1; 19723 ast_free(redirecting->from.name.str); 19724 redirecting->from.name.str = redirecting_from_name; 19725 } 19726 if (!ast_strlen_zero(p->cid_tag)) { 19727 ast_free(redirecting->from.tag); 19728 redirecting->from.tag = ast_strdup(p->cid_tag); 19729 ast_free(redirecting->to.tag); 19730 redirecting->to.tag = ast_strdup(p->cid_tag); 19731 } 19732 if (!ast_strlen_zero(redirecting_to_number)) { 19733 ast_debug(3, "Got redirecting to number %s\n", redirecting_to_number); 19734 update_redirecting->to.number = 1; 19735 redirecting->to.number.valid = 1; 19736 ast_free(redirecting->to.number.str); 19737 redirecting->to.number.str = redirecting_to_number; 19738 } 19739 if (!ast_strlen_zero(redirecting_to_name)) { 19740 ast_debug(3, "Got redirecting to name %s\n", redirecting_from_number); 19741 update_redirecting->to.name = 1; 19742 redirecting->to.name.valid = 1; 19743 ast_free(redirecting->to.name.str); 19744 redirecting->to.name.str = redirecting_to_name; 19745 } 19746 redirecting->reason = reason; 19747 }
| static void change_t38_state | ( | struct sip_pvt * | p, | |
| int | state | |||
| ) | [static] |
Change the T38 state on a SIP dialog.
Definition at line 5111 of file chan_sip.c.
References AST_CONTROL_T38_PARAMETERS, ast_debug, ast_queue_control_data(), AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_TERMINATED, ast_udptl_get_far_max_ifp(), ast_udptl_set_tag(), ast_control_t38_parameters::max_ifp, and ast_control_t38_parameters::request_response.
Referenced by handle_response_invite(), interpret_t38_parameters(), process_sdp(), and sip_t38_abort().
05112 { 05113 int old = p->t38.state; 05114 struct ast_channel *chan = p->owner; 05115 struct ast_control_t38_parameters parameters = { .request_response = 0 }; 05116 05117 /* Don't bother changing if we are already in the state wanted */ 05118 if (old == state) 05119 return; 05120 05121 p->t38.state = state; 05122 ast_debug(2, "T38 state changed to %d on channel %s\n", p->t38.state, chan ? chan->name : "<none>"); 05123 05124 /* If no channel was provided we can't send off a control frame */ 05125 if (!chan) 05126 return; 05127 05128 /* Given the state requested and old state determine what control frame we want to queue up */ 05129 switch (state) { 05130 case T38_PEER_REINVITE: 05131 parameters = p->t38.their_parms; 05132 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 05133 parameters.request_response = AST_T38_REQUEST_NEGOTIATE; 05134 ast_udptl_set_tag(p->udptl, "%s", chan->name); 05135 break; 05136 case T38_ENABLED: 05137 parameters = p->t38.their_parms; 05138 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 05139 parameters.request_response = AST_T38_NEGOTIATED; 05140 ast_udptl_set_tag(p->udptl, "%s", chan->name); 05141 break; 05142 case T38_DISABLED: 05143 if (old == T38_ENABLED) { 05144 parameters.request_response = AST_T38_TERMINATED; 05145 } else if (old == T38_LOCAL_REINVITE) { 05146 parameters.request_response = AST_T38_REFUSED; 05147 } 05148 break; 05149 case T38_LOCAL_REINVITE: 05150 /* wait until we get a peer response before responding to local reinvite */ 05151 break; 05152 } 05153 05154 /* Woot we got a message, create a control frame and send it on! */ 05155 if (parameters.request_response) 05156 ast_queue_control_data(chan, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters)); 05157 }
| 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, | |||
| int | ignore | |||
| ) | [static] |
Check user authorization from peer definition Some actions, like REGISTER and INVITEs from peers require authentication (if peer have secret set).
XXX
XXX
Definition at line 14385 of file chan_sip.c.
References append_history, ast_copy_string(), AST_DYNSTR_BUILD_FAILED, ast_log(), ast_md5_hash(), ast_skip_blanks(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero(), auth_headers(), CHECK_AUTH_BUF_INITLEN, FALSE, get_header(), LOG_NOTICE, LOG_WARNING, S_OR, set_nonce_randdata(), sip_methods, sip_scheddestroy(), text, transmit_response_with_auth(), and TRUE.
Referenced by check_peer_ok(), and register_verify().
14388 { 14389 const char *response; 14390 char *reqheader, *respheader; 14391 const char *authtoken; 14392 char a1_hash[256]; 14393 char resp_hash[256]=""; 14394 char *c; 14395 int wrongnonce = FALSE; 14396 int good_response; 14397 const char *usednonce = p->randdata; 14398 struct ast_str *buf; 14399 int res; 14400 14401 /* table of recognised keywords, and their value in the digest */ 14402 enum keys { K_RESP, K_URI, K_USER, K_NONCE, K_LAST }; 14403 struct x { 14404 const char *key; 14405 const char *s; 14406 } *i, keys[] = { 14407 [K_RESP] = { "response=", "" }, 14408 [K_URI] = { "uri=", "" }, 14409 [K_USER] = { "username=", "" }, 14410 [K_NONCE] = { "nonce=", "" }, 14411 [K_LAST] = { NULL, NULL} 14412 }; 14413 14414 /* Always OK if no secret */ 14415 if (ast_strlen_zero(secret) && ast_strlen_zero(md5secret)) 14416 return AUTH_SUCCESSFUL; 14417 14418 /* Always auth with WWW-auth since we're NOT a proxy */ 14419 /* Using proxy-auth in a B2BUA may block proxy authorization in the same transaction */ 14420 response = "401 Unauthorized"; 14421 14422 /* 14423 * Note the apparent swap of arguments below, compared to other 14424 * usages of auth_headers(). 14425 */ 14426 auth_headers(WWW_AUTH, &respheader, &reqheader); 14427 14428 authtoken = get_header(req, reqheader); 14429 if (ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) { 14430 /* This is a retransmitted invite/register/etc, don't reconstruct authentication 14431 information */ 14432 if (!reliable) { 14433 /* Resend message if this was NOT a reliable delivery. Otherwise the 14434 retransmission should get it */ 14435 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 14436 /* Schedule auto destroy in 32 seconds (according to RFC 3261) */ 14437 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14438 } 14439 return AUTH_CHALLENGE_SENT; 14440 } else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) { 14441 /* We have no auth, so issue challenge and request authentication */ 14442 set_nonce_randdata(p, 1); /* Create nonce for challenge */ 14443 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 14444 /* Schedule auto destroy in 32 seconds */ 14445 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14446 return AUTH_CHALLENGE_SENT; 14447 } 14448 14449 /* --- We have auth, so check it */ 14450 14451 /* Whoever came up with the authentication section of SIP can suck my %&#$&* for not putting 14452 an example in the spec of just what it is you're doing a hash on. */ 14453 14454 if (!(buf = ast_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) { 14455 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 14456 } 14457 14458 /* Make a copy of the response and parse it */ 14459 res = ast_str_set(&buf, 0, "%s", authtoken); 14460 14461 if (res == AST_DYNSTR_BUILD_FAILED) { 14462 return AUTH_SECRET_FAILED; /*! XXX \todo need a better return code here */ 14463 } 14464 14465 c = buf->str; 14466 14467 while(c && *(c = ast_skip_blanks(c)) ) { /* lookup for keys */ 14468 for (i = keys; i->key != NULL; i++) { 14469 const char *separator = ","; /* default */ 14470 14471 if (strncasecmp(c, i->key, strlen(i->key)) != 0) { 14472 continue; 14473 } 14474 /* Found. Skip keyword, take text in quotes or up to the separator. */ 14475 c += strlen(i->key); 14476 if (*c == '"') { /* in quotes. Skip first and look for last */ 14477 c++; 14478 separator = "\""; 14479 } 14480 i->s = c; 14481 strsep(&c, separator); 14482 break; 14483 } 14484 if (i->key == NULL) { /* not found, jump after space or comma */ 14485 strsep(&c, " ,"); 14486 } 14487 } 14488 14489 /* Verify that digest username matches the username we auth as */ 14490 if (strcmp(username, keys[K_USER].s)) { 14491 ast_log(LOG_WARNING, "username mismatch, have <%s>, digest has <%s>\n", 14492 username, keys[K_USER].s); 14493 /* Oops, we're trying something here */ 14494 return AUTH_USERNAME_MISMATCH; 14495 } 14496 14497 /* Verify nonce from request matches our nonce, and the nonce has not already been responded to. 14498 * If this check fails, send 401 with new nonce */ 14499 if (strcasecmp(p->randdata, keys[K_NONCE].s) || p->stalenonce) { /* XXX it was 'n'casecmp ? */ 14500 wrongnonce = TRUE; 14501 usednonce = keys[K_NONCE].s; 14502 } else { 14503 p->stalenonce = 1; /* now, since the nonce has a response, mark it as stale so it can't be sent or responded to again */ 14504 } 14505 14506 if (!ast_strlen_zero(md5secret)) { 14507 ast_copy_string(a1_hash, md5secret, sizeof(a1_hash)); 14508 } else { 14509 char a1[256]; 14510 14511 snprintf(a1, sizeof(a1), "%s:%s:%s", username, p->realm, secret); 14512 ast_md5_hash(a1_hash, a1); 14513 } 14514 14515 /* compute the expected response to compare with what we received */ 14516 { 14517 char a2[256]; 14518 char a2_hash[256]; 14519 char resp[256]; 14520 14521 snprintf(a2, sizeof(a2), "%s:%s", sip_methods[sipmethod].text, 14522 S_OR(keys[K_URI].s, uri)); 14523 ast_md5_hash(a2_hash, a2); 14524 snprintf(resp, sizeof(resp), "%s:%s:%s", a1_hash, usednonce, a2_hash); 14525 ast_md5_hash(resp_hash, resp); 14526 } 14527 14528 good_response = keys[K_RESP].s && 14529 !strncasecmp(keys[K_RESP].s, resp_hash, strlen(resp_hash)); 14530 if (wrongnonce) { 14531 if (good_response) { 14532 if (sipdebug) 14533 ast_log(LOG_NOTICE, "Correct auth, but based on stale nonce received from '%s'\n", get_header(req, "From")); 14534 /* We got working auth token, based on stale nonce . */ 14535 set_nonce_randdata(p, 0); 14536 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, TRUE); 14537 } else { 14538 /* Everything was wrong, so give the device one more try with a new challenge */ 14539 if (!req->ignore) { 14540 if (sipdebug) { 14541 ast_log(LOG_NOTICE, "Bad authentication received from '%s'\n", get_header(req, "To")); 14542 } 14543 set_nonce_randdata(p, 1); 14544 } else { 14545 if (sipdebug) { 14546 ast_log(LOG_NOTICE, "Duplicate authentication received from '%s'\n", get_header(req, "To")); 14547 } 14548 } 14549 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE); 14550 } 14551 14552 /* Schedule auto destroy in 32 seconds */ 14553 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14554 return AUTH_CHALLENGE_SENT; 14555 } 14556 if (good_response) { 14557 append_history(p, "AuthOK", "Auth challenge successful for %s", username); 14558 return AUTH_SUCCESSFUL; 14559 } 14560 14561 /* Ok, we have a bad username/secret pair */ 14562 /* Tell the UAS not to re-send this authentication data, because 14563 it will continue to fail 14564 */ 14565 14566 return AUTH_SECRET_FAILED; 14567 }
| 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 | |||
| ) | [static] |
Validate device authentication.
Definition at line 16004 of file chan_sip.c.
References accountcode, ao2_t_ref, ast_apply_ha(), ast_cc_copy_config_params(), ast_copy_flags, ast_debug, ast_is_shrinkable_phonenumber(), ast_rtp_codecs_packetization_set(), AST_RTP_DTMF, ast_rtp_instance_get_codecs(), ast_set_flag, ast_shrink_phone_number(), ast_sockaddr_stringify(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_variables_destroy(), ast_verbose, check_auth(), cid_name, cid_num, context, copy_vars(), dialog_initialize_rtp(), do_setnat(), FALSE, find_peer(), get_rpid(), language, mohinterpret, mohsuggest, parkinglot, set_pvt_allowed_methods(), set_t38_capabilities(), sip_debug_test_addr(), TRUE, and unref_peer().
Referenced by check_user_full().
16008 { 16009 enum check_auth_result res; 16010 int debug = sip_debug_test_addr(addr); 16011 struct sip_peer *peer; 16012 16013 if (sipmethod == SIP_SUBSCRIBE) { 16014 /* For subscribes, match on device name only; for other methods, 16015 * match on IP address-port of the incoming request. 16016 */ 16017 peer = find_peer(of, NULL, TRUE, FINDALLDEVICES, FALSE, 0); 16018 } else { 16019 /* First find devices based on username (avoid all type=peer's) */ 16020 peer = find_peer(of, NULL, TRUE, FINDUSERS, FALSE, 0); 16021 16022 /* Then find devices based on IP */ 16023 if (!peer) { 16024 peer = find_peer(NULL, &p->recv, TRUE, FINDPEERS, FALSE, p->socket.type); 16025 } 16026 } 16027 16028 if (!peer) { 16029 if (debug) { 16030 ast_verbose("No matching peer for '%s' from '%s'\n", 16031 of, ast_sockaddr_stringify(&p->recv)); 16032 } 16033 return AUTH_DONT_KNOW; 16034 } 16035 16036 if (!ast_apply_ha(peer->ha, addr)) { 16037 ast_debug(2, "Found peer '%s' for '%s', but fails host access\n", peer->name, of); 16038 unref_peer(peer, "unref_peer: check_peer_ok: from find_peer call, early return of AUTH_ACL_FAILED"); 16039 return AUTH_ACL_FAILED; 16040 } 16041 if (debug) 16042 ast_verbose("Found peer '%s' for '%s' from %s\n", 16043 peer->name, of, ast_sockaddr_stringify(&p->recv)); 16044 16045 /* XXX what about p->prefs = peer->prefs; ? */ 16046 /* Set Frame packetization */ 16047 if (p->rtp) { 16048 ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &peer->prefs); 16049 p->autoframing = peer->autoframing; 16050 } 16051 16052 /* Take the peer */ 16053 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 16054 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 16055 ast_copy_flags(&p->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY); 16056 16057 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) && p->udptl) { 16058 p->t38_maxdatagram = peer->t38_maxdatagram; 16059 set_t38_capabilities(p); 16060 } 16061 16062 /* Copy SIP extensions profile to peer */ 16063 /* XXX is this correct before a successful auth ? */ 16064 if (p->sipoptions) 16065 peer->sipoptions = p->sipoptions; 16066 16067 do_setnat(p); 16068 16069 ast_string_field_set(p, peersecret, peer->secret); 16070 ast_string_field_set(p, peermd5secret, peer->md5secret); 16071 ast_string_field_set(p, subscribecontext, peer->subscribecontext); 16072 ast_string_field_set(p, mohinterpret, peer->mohinterpret); 16073 ast_string_field_set(p, mohsuggest, peer->mohsuggest); 16074 if (!ast_strlen_zero(peer->parkinglot)) { 16075 ast_string_field_set(p, parkinglot, peer->parkinglot); 16076 } 16077 ast_string_field_set(p, engine, peer->engine); 16078 p->disallowed_methods = peer->disallowed_methods; 16079 set_pvt_allowed_methods(p, req); 16080 ast_cc_copy_config_params(p->cc_params, peer->cc_params); 16081 if (peer->callingpres) /* Peer calling pres setting will override RPID */ 16082 p->callingpres = peer->callingpres; 16083 if (peer->maxms && peer->lastms) 16084 p->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 16085 else 16086 p->timer_t1 = peer->timer_t1; 16087 16088 /* Set timer B to control transaction timeouts */ 16089 if (peer->timer_b) 16090 p->timer_b = peer->timer_b; 16091 else 16092 p->timer_b = 64 * p->timer_t1; 16093 16094 p->allowtransfer = peer->allowtransfer; 16095 16096 if (ast_test_flag(&peer->flags[0], SIP_INSECURE_INVITE)) { 16097 /* Pretend there is no required authentication */ 16098 ast_string_field_set(p, peersecret, NULL); 16099 ast_string_field_set(p, peermd5secret, NULL); 16100 } 16101 if (!(res = check_auth(p, req, peer->name, p->peersecret, p->peermd5secret, sipmethod, uri2, reliable, req->ignore))) { 16102 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 16103 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 16104 ast_copy_flags(&p->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY); 16105 /* If we have a call limit, set flag */ 16106 if (peer->call_limit) 16107 ast_set_flag(&p->flags[0], SIP_CALL_LIMIT); 16108 ast_string_field_set(p, peername, peer->name); 16109 ast_string_field_set(p, authname, peer->name); 16110 16111 if (sipmethod == SIP_INVITE) { 16112 /* destroy old channel vars and copy in new ones. */ 16113 ast_variables_destroy(p->chanvars); 16114 p->chanvars = copy_vars(peer->chanvars); 16115 } 16116 16117 if (authpeer) { 16118 ao2_t_ref(peer, 1, "copy pointer into (*authpeer)"); 16119 (*authpeer) = peer; /* Add a ref to the object here, to keep it in memory a bit longer if it is realtime */ 16120 } 16121 16122 if (!ast_strlen_zero(peer->username)) { 16123 ast_string_field_set(p, username, peer->username); 16124 /* Use the default username for authentication on outbound calls */ 16125 /* XXX this takes the name from the caller... can we override ? */ 16126 ast_string_field_set(p, authname, peer->username); 16127 } 16128 if (!get_rpid(p, req)) { 16129 if (!ast_strlen_zero(peer->cid_num)) { 16130 char *tmp = ast_strdupa(peer->cid_num); 16131 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) 16132 ast_shrink_phone_number(tmp); 16133 ast_string_field_set(p, cid_num, tmp); 16134 } 16135 if (!ast_strlen_zero(peer->cid_name)) 16136 ast_string_field_set(p, cid_name, peer->cid_name); 16137 if (peer->callingpres) 16138 p->callingpres = peer->callingpres; 16139 } 16140 if (!ast_strlen_zero(peer->cid_tag)) { 16141 ast_string_field_set(p, cid_tag, peer->cid_tag); 16142 } 16143 ast_string_field_set(p, fullcontact, peer->fullcontact); 16144 16145 if (!ast_strlen_zero(peer->context)) { 16146 ast_string_field_set(p, context, peer->context); 16147 } 16148 if (!ast_strlen_zero(peer->mwi_from)) { 16149 ast_string_field_set(p, mwi_from, peer->mwi_from); 16150 } 16151 16152 ast_string_field_set(p, peersecret, peer->secret); 16153 ast_string_field_set(p, peermd5secret, peer->md5secret); 16154 ast_string_field_set(p, language, peer->language); 16155 ast_string_field_set(p, accountcode, peer->accountcode); 16156 p->amaflags = peer->amaflags; 16157 p->callgroup = peer->callgroup; 16158 p->pickupgroup = peer->pickupgroup; 16159 p->capability = peer->capability; 16160 p->prefs = peer->prefs; 16161 p->jointcapability = peer->capability; 16162 if (peer->maxforwards > 0) { 16163 p->maxforwards = peer->maxforwards; 16164 } 16165 if (p->peercapability) 16166 p->jointcapability &= p->peercapability; 16167 p->maxcallbitrate = peer->maxcallbitrate; 16168 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 16169 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 16170 p->noncodeccapability |= AST_RTP_DTMF; 16171 else 16172 p->noncodeccapability &= ~AST_RTP_DTMF; 16173 p->jointnoncodeccapability = p->noncodeccapability; 16174 p->rtptimeout = peer->rtptimeout; 16175 p->rtpholdtimeout = peer->rtpholdtimeout; 16176 p->rtpkeepalive = peer->rtpkeepalive; 16177 if (!dialog_initialize_rtp(p)) { 16178 if (p->rtp) { 16179 ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &peer->prefs); 16180 p->autoframing = peer->autoframing; 16181 } 16182 } else { 16183 res = AUTH_RTP_FAILED; 16184 } 16185 } 16186 unref_peer(peer, "check_peer_ok: unref_peer: tossing temp ptr to peer from find_peer"); 16187 return res; 16188 }
| static void check_pendings | ( | struct sip_pvt * | p | ) | [static] |
Check pending actions on SIP call.
Definition at line 19867 of file chan_sip.c.
References ast_clear_flag, ast_debug, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), ast_test_flag, FALSE, sip_scheddestroy(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), and TRUE.
Referenced by handle_incoming(), handle_response_invite(), reinvite_timeout(), and sip_reinvite_retry().
19868 { 19869 if (ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 19870 if (p->reinviteid > -1) { 19871 /* Outstanding p->reinviteid timeout, so wait... */ 19872 return; 19873 } else if (p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA) { 19874 /* if we can't BYE, then this is really a pending CANCEL */ 19875 p->invitestate = INV_CANCELLED; 19876 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 19877 /* If the cancel occurred on an initial invite, cancel the pending BYE */ 19878 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { 19879 ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); 19880 } 19881 /* Actually don't destroy us yet, wait for the 487 on our original 19882 INVITE, but do set an autodestruct just in case we never get it. */ 19883 } else { 19884 /* We have a pending outbound invite, don't send something 19885 * new in-transaction, unless it is a pending reinvite, then 19886 * by the time we are called here, we should probably just hang up. */ 19887 if (p->pendinginvite && !p->ongoing_reinvite) 19888 return; 19889 19890 if (p->owner) { 19891 ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV); 19892 } 19893 /* Perhaps there is an SD change INVITE outstanding */ 19894 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, TRUE); 19895 ast_clear_flag(&p->flags[0], SIP_PENDINGBYE); 19896 } 19897 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 19898 } else if (ast_test_flag(&p->flags[0], SIP_NEEDREINVITE)) { 19899 /* if we can't REINVITE, hold it for later */ 19900 if (p->pendinginvite || p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA || p->waitid > 0) { 19901 ast_debug(2, "NOT Sending pending reinvite (yet) on '%s'\n", p->callid); 19902 } else { 19903 ast_debug(2, "Sending pending reinvite on '%s'\n", p->callid); 19904 /* Didn't get to reinvite yet, so do it now */ 19905 transmit_reinvite_with_sdp(p, (p->t38.state == T38_LOCAL_REINVITE ? TRUE : FALSE), FALSE); 19906 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 19907 } 19908 } 19909 }
| static void check_rtp_timeout | ( | struct sip_pvt * | dialog, | |
| time_t | t | |||
| ) | [static] |
helper function for the monitoring thread -- seems to be called with the assumption that the dialog is locked
Do we need to move the lastrtptx to the RTP structure to have one for audio and one for video? It really does belong to the RTP structure.
Definition at line 25880 of file chan_sip.c.
References ast_channel_trylock, ast_channel_unlock, ast_log(), ast_rtp_instance_get_hold_timeout(), ast_rtp_instance_get_keepalive(), ast_rtp_instance_get_timeout(), ast_rtp_instance_sendcng(), ast_rtp_instance_set_hold_timeout(), ast_rtp_instance_set_timeout(), ast_sockaddr_isnull(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, ast_test_flag, and LOG_NOTICE.
Referenced by dialog_needdestroy().
25881 { 25882 /* If we have no RTP or no active owner, no need to check timers */ 25883 if (!dialog->rtp || !dialog->owner) 25884 return; 25885 /* If the call is not in UP state or redirected outside Asterisk, no need to check timers */ 25886 25887 if (dialog->owner->_state != AST_STATE_UP || !ast_sockaddr_isnull(&dialog->redirip)) 25888 return; 25889 25890 /* If the call is involved in a T38 fax session do not check RTP timeout */ 25891 if (dialog->t38.state == T38_ENABLED) 25892 return; 25893 25894 /* If we have no timers set, return now */ 25895 if (!ast_rtp_instance_get_keepalive(dialog->rtp) && !ast_rtp_instance_get_timeout(dialog->rtp) && !ast_rtp_instance_get_hold_timeout(dialog->rtp)) { 25896 return; 25897 } 25898 25899 /* Check AUDIO RTP keepalives */ 25900 if (dialog->lastrtptx && ast_rtp_instance_get_keepalive(dialog->rtp) && 25901 (t > dialog->lastrtptx + ast_rtp_instance_get_keepalive(dialog->rtp))) { 25902 /* Need to send an empty RTP packet */ 25903 dialog->lastrtptx = time(NULL); 25904 ast_rtp_instance_sendcng(dialog->rtp, 0); 25905 } 25906 25907 /*! \todo Check video RTP keepalives 25908 25909 Do we need to move the lastrtptx to the RTP structure to have one for audio and one 25910 for video? It really does belong to the RTP structure. 25911 */ 25912 25913 /* Check AUDIO RTP timers */ 25914 if (dialog->lastrtprx && (ast_rtp_instance_get_timeout(dialog->rtp) || ast_rtp_instance_get_hold_timeout(dialog->rtp)) && (t > dialog->lastrtprx + ast_rtp_instance_get_timeout(dialog->rtp))) { 25915 if (!ast_test_flag(&dialog->flags[1], SIP_PAGE2_CALL_ONHOLD) || (ast_rtp_instance_get_hold_timeout(dialog->rtp) && (t > dialog->lastrtprx + ast_rtp_instance_get_hold_timeout(dialog->rtp)))) { 25916 /* Needs a hangup */ 25917 if (ast_rtp_instance_get_timeout(dialog->rtp)) { 25918 if (!dialog->owner || ast_channel_trylock(dialog->owner)) { 25919 /* 25920 * Don't block, just try again later. 25921 * If there was no owner, the call is dead already. 25922 */ 25923 return; 25924 } 25925 ast_log(LOG_NOTICE, "Disconnecting call '%s' for lack of RTP activity in %ld seconds\n", 25926 dialog->owner->name, (long) (t - dialog->lastrtprx)); 25927 /* Issue a softhangup */ 25928 ast_softhangup_nolock(dialog->owner, AST_SOFTHANGUP_DEV); 25929 ast_channel_unlock(dialog->owner); 25930 /* forget the timeouts for this call, since a hangup 25931 has already been requested and we don't want to 25932 repeatedly request hangups 25933 */ 25934 ast_rtp_instance_set_timeout(dialog->rtp, 0); 25935 ast_rtp_instance_set_hold_timeout(dialog->rtp, 0); 25936 if (dialog->vrtp) { 25937 ast_rtp_instance_set_timeout(dialog->vrtp, 0); 25938 ast_rtp_instance_set_hold_timeout(dialog->vrtp, 0); 25939 } 25940 } 25941 } 25942 } 25943 }
| static int check_sip_domain | ( | const char * | domain, | |
| char * | context, | |||
| size_t | len | |||
| ) | [static] |
check_sip_domain: Check if domain part of uri is local to our server
Definition at line 27078 of file chan_sip.c.
References ast_copy_string(), AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, and ast_strlen_zero().
Referenced by func_check_sipdomain(), get_destination(), get_realm(), handle_request_refer(), and register_verify().
27079 { 27080 struct domain *d; 27081 int result = 0; 27082 27083 AST_LIST_LOCK(&domain_list); 27084 AST_LIST_TRAVERSE(&domain_list, d, list) { 27085 if (strcasecmp(d->domain, domain)) { 27086 continue; 27087 } 27088 27089 if (len && !ast_strlen_zero(d->context)) 27090 ast_copy_string(context, d->context, len); 27091 27092 result = 1; 27093 break; 27094 } 27095 AST_LIST_UNLOCK(&domain_list); 27096 27097 return result; 27098 }
| static int check_user | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | sipmethod, | |||
| const char * | uri, | |||
| enum xmittype | reliable, | |||
| struct ast_sockaddr * | addr | |||
| ) | [static] |
Find user If we get a match, this will add a reference pointer to the user object in ASTOBJ, that needs to be unreferenced.
Definition at line 16328 of file chan_sip.c.
References check_user_full().
Referenced by handle_request_options(), and handle_request_publish().
16329 { 16330 return check_user_full(p, req, sipmethod, uri, reliable, addr, NULL); 16331 }
| 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 | |||
| ) | [static] |
Check if matching user or peer is defined Match user on From: user name and peer on IP/port This is used on first invite (not re-invites) and subscribe requests.
Definition at line 16196 of file chan_sip.c.
References ast_copy_string(), ast_is_shrinkable_phonenumber(), ast_log(), ast_set_flag, ast_shrink_phone_number(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, build_contact(), check_peer_ok(), cid_name, cid_num, dialog_initialize_rtp(), exten, extract_host_from_hostport(), get_calleridname(), get_header(), get_in_brackets(), get_rpid(), LOG_ERROR, LOG_NOTICE, name, parse_uri_legacy_check(), sip_cfg, SIP_PEDANTIC_DECODE, and terminate_uri().
Referenced by check_user(), handle_request_invite(), and handle_request_subscribe().
16199 { 16200 char from[256] = "", *of, *name, *unused_password, *domain; 16201 enum check_auth_result res = AUTH_DONT_KNOW; 16202 char calleridname[50]; 16203 char *uri2 = ast_strdupa(uri); 16204 16205 terminate_uri(uri2); /* trim extra stuff */ 16206 16207 ast_copy_string(from, get_header(req, "From"), sizeof(from)); 16208 /* XXX here tries to map the username for invite things */ 16209 16210 /* strip the display-name portion off the beginning of the FROM header. */ 16211 if (!(of = (char *) get_calleridname(from, calleridname, sizeof(calleridname)))) { 16212 ast_log(LOG_ERROR, "FROM header can not be parsed \n"); 16213 return res; 16214 } 16215 16216 if (calleridname[0]) { 16217 ast_string_field_set(p, cid_name, calleridname); 16218 } 16219 16220 if (ast_strlen_zero(p->exten)) { 16221 char *t = uri2; 16222 if (!strncasecmp(t, "sip:", 4)) 16223 t+= 4; 16224 else if (!strncasecmp(t, "sips:", 5)) 16225 t += 5; 16226 ast_string_field_set(p, exten, t); 16227 t = strchr(p->exten, '@'); 16228 if (t) 16229 *t = '\0'; 16230 16231 if (ast_strlen_zero(p->our_contact)) 16232 build_contact(p); 16233 } 16234 16235 of = get_in_brackets(of); 16236 16237 /* save the URI part of the From header */ 16238 ast_string_field_set(p, from, of); 16239 16240 if (parse_uri_legacy_check(of, "sip:,sips:", &name, &unused_password, &domain, NULL)) { 16241 ast_log(LOG_NOTICE, "From address missing 'sip:', using it anyway\n"); 16242 } 16243 16244 SIP_PEDANTIC_DECODE(name); 16245 SIP_PEDANTIC_DECODE(domain); 16246 16247 extract_host_from_hostport(&domain); 16248 16249 if (ast_strlen_zero(domain)) { 16250 /* <sip:name@[EMPTY]>, never good */ 16251 ast_log(LOG_ERROR, "Empty domain name in FROM header\n"); 16252 return res; 16253 } 16254 16255 if (ast_strlen_zero(name)) { 16256 /* <sip:[EMPTY][@]hostport>. Asterisk 1.4 and 1.6 have always 16257 * treated that as a username, so we continue the tradition: 16258 * uri is now <sip:host@hostport>. */ 16259 name = domain; 16260 } else { 16261 /* Non-empty name, try to get caller id from it */ 16262 char *tmp = ast_strdupa(name); 16263 /* We need to be able to handle from-headers looking like 16264 <sip:8164444422;phone-context=+1@1.2.3.4:5060;user=phone;tag=SDadkoa01-gK0c3bdb43> 16265 */ 16266 tmp = strsep(&tmp, ";"); 16267 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(tmp)) { 16268 ast_shrink_phone_number(tmp); 16269 } 16270 ast_string_field_set(p, cid_num, tmp); 16271 } 16272 16273 if (global_match_auth_username) { 16274 /* 16275 * XXX This is experimental code to grab the search key from the 16276 * Auth header's username instead of the 'From' name, if available. 16277 * Do not enable this block unless you understand the side effects (if any!) 16278 * Note, the search for "username" should be done in a more robust way. 16279 * Note2, at the moment we check both fields, though maybe we should 16280 * pick one or another depending on the request ? XXX 16281 */ 16282 const char *hdr = get_header(req, "Authorization"); 16283 if (ast_strlen_zero(hdr)) { 16284 hdr = get_header(req, "Proxy-Authorization"); 16285 } 16286 16287 if (!ast_strlen_zero(hdr) && (hdr = strstr(hdr, "username=\""))) { 16288 ast_copy_string(from, hdr + strlen("username=\""), sizeof(from)); 16289 name = from; 16290 name = strsep(&name, "\""); 16291 } 16292 } 16293 16294 res = check_peer_ok(p, name, req, sipmethod, addr, 16295 authpeer, reliable, calleridname, uri2); 16296 if (res != AUTH_DONT_KNOW) { 16297 return res; 16298 } 16299 16300 /* Finally, apply the guest policy */ 16301 if (sip_cfg.allowguest) { 16302 /* Ignore check_return warning from Coverity for get_rpid below. */ 16303 get_rpid(p, req); 16304 p->rtptimeout = global_rtptimeout; 16305 p->rtpholdtimeout = global_rtpholdtimeout; 16306 p->rtpkeepalive = global_rtpkeepalive; 16307 if (!dialog_initialize_rtp(p)) { 16308 res = AUTH_SUCCESSFUL; 16309 } else { 16310 res = AUTH_RTP_FAILED; 16311 } 16312 } else if (sip_cfg.alwaysauthreject) { 16313 res = AUTH_FAKE_AUTH; /* reject with fake authorization request */ 16314 } else { 16315 res = AUTH_SECRET_FAILED; /* we don't want any guests, authentication will fail */ 16316 } 16317 16318 if (ast_test_flag(&p->flags[1], SIP_PAGE2_RPORT_PRESENT)) { 16319 ast_set_flag(&p->flags[0], SIP_NAT_RPORT_PRESENT); 16320 } 16321 16322 return res; 16323 }
| static void check_via | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
check Via: header for hostname, port and rport request/answer
Definition at line 15941 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_set_flag, ast_skip_blanks(), ast_sockaddr_port, ast_sockaddr_resolve_first(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_verbose, get_header(), LOG_WARNING, sip_debug_test_pvt(), sip_nat_mode(), and sip_real_dst().
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_register(), and handle_request_subscribe().
15942 { 15943 char via[512]; 15944 char *c, *maddr; 15945 struct ast_sockaddr tmp = { { 0, } }; 15946 uint16_t port; 15947 15948 ast_copy_string(via, get_header(req, "Via"), sizeof(via)); 15949 15950 /* Work on the leftmost value of the topmost Via header */ 15951 c = strchr(via, ','); 15952 if (c) 15953 *c = '\0'; 15954 15955 /* Check for rport */ 15956 c = strstr(via, ";rport"); 15957 if (c && (c[6] != '=')) { /* rport query, not answer */ 15958 ast_set_flag(&p->flags[1], SIP_PAGE2_RPORT_PRESENT); 15959 ast_set_flag(&p->flags[0], SIP_NAT_RPORT_PRESENT); 15960 } 15961 15962 /* Check for maddr */ 15963 maddr = strstr(via, "maddr="); 15964 if (maddr) { 15965 maddr += 6; 15966 c = maddr + strspn(maddr, "abcdefghijklmnopqrstuvwxyz" 15967 "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-.:[]"); 15968 *c = '\0'; 15969 } 15970 15971 c = strchr(via, ';'); 15972 if (c) 15973 *c = '\0'; 15974 15975 c = strchr(via, ' '); 15976 if (c) { 15977 *c = '\0'; 15978 c = ast_skip_blanks(c+1); 15979 if (strcasecmp(via, "SIP/2.0/UDP") && strcasecmp(via, "SIP/2.0/TCP") && strcasecmp(via, "SIP/2.0/TLS")) { 15980 ast_log(LOG_WARNING, "Don't know how to respond via '%s'\n", via); 15981 return; 15982 } 15983 15984 if (maddr && ast_sockaddr_resolve_first(&p->sa, maddr, 0)) { 15985 p->sa = p->recv; 15986 } 15987 15988 if (ast_sockaddr_resolve_first(&tmp, c, 0)) { 15989 ast_log(LOG_WARNING, "Could not resolve socket address for '%s'\n", c); 15990 } 15991 port = ast_sockaddr_port(&tmp); 15992 ast_sockaddr_set_port(&p->sa, 15993 port != 0 ? port : STANDARD_SIP_PORT); 15994 15995 if (sip_debug_test_pvt(p)) { 15996 ast_verbose("Sending to %s (%s)\n", 15997 ast_sockaddr_stringify(sip_real_dst(p)), 15998 sip_nat_mode(p)); 15999 } 16000 } 16001 }
| static attribute_unused void check_via_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
check received= and rport= in a SIP response. If we get a response with received= and/or rport= in the Via: line, use them as 'p->ourip' (see RFC 3581 for rport, and RFC 3261 for received). Using these two fields SIP can produce the correct address and port in the SIP headers without the need for STUN. The address part is also reused for the media sessions. Note that ast_sip_ouraddrfor() still rewrites p->ourip if you specify externaddr/seternaddr/.
Definition at line 15911 of file chan_sip.c.
References ast_copy_string(), ast_parse_arg(), ast_sockaddr_set_port, get_header(), and PARSE_ADDR.
15912 { 15913 char via[256]; 15914 char *cur, *opts; 15915 15916 ast_copy_string(via, get_header(req, "Via"), sizeof(via)); 15917 15918 /* Work on the leftmost value of the topmost Via header */ 15919 opts = strchr(via, ','); 15920 if (opts) 15921 *opts = '\0'; 15922 15923 /* parse all relevant options */ 15924 opts = strchr(via, ';'); 15925 if (!opts) 15926 return; /* no options to parse */ 15927 *opts++ = '\0'; 15928 while ( (cur = strsep(&opts, ";")) ) { 15929 if (!strncmp(cur, "rport=", 6)) { 15930 int port = strtol(cur+6, NULL, 10); 15931 /* XXX add error checking */ 15932 ast_sockaddr_set_port(&p->ourip, port); 15933 } else if (!strncmp(cur, "received=", 9)) { 15934 if (ast_parse_arg(cur + 9, PARSE_ADDR, &p->ourip)) 15935 ; /* XXX add error checking */ 15936 } 15937 } 15938 }
| static void cleanup_all_regs | ( | void | ) | [static] |
Definition at line 28090 of file chan_sip.c.
References ast_debug, ast_dnsmgr_release(), AST_SCHED_DEL_UNREF, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, dialog_unlink_all(), registry_unref(), and regl.
Referenced by reload_config(), and unload_module().
28091 { 28092 /* First, destroy all outstanding registry calls */ 28093 /* This is needed, since otherwise active registry entries will not be destroyed */ 28094 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { /* regl is locked */ 28095 ASTOBJ_WRLOCK(iterator); /* now regl is locked, and the object is also locked */ 28096 if (iterator->call) { 28097 ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", iterator->username, iterator->hostname); 28098 /* This will also remove references to the registry */ 28099 dialog_unlink_all(iterator->call); 28100 iterator->call = dialog_unref(iterator->call, "remove iterator->call from registry traversal"); 28101 } 28102 if (iterator->expire > -1) { 28103 AST_SCHED_DEL_UNREF(sched, iterator->expire, registry_unref(iterator, "reg ptr unref from reload config")); 28104 } 28105 if (iterator->timeout > -1) { 28106 AST_SCHED_DEL_UNREF(sched, iterator->timeout, registry_unref(iterator, "reg ptr unref from reload config")); 28107 } 28108 if (iterator->dnsmgr) { 28109 ast_dnsmgr_release(iterator->dnsmgr); 28110 iterator->dnsmgr = NULL; 28111 registry_unref(iterator, "reg ptr unref from dnsmgr"); 28112 } 28113 ASTOBJ_UNLOCK(iterator); 28114 } while(0)); 28115 }
| static void cleanup_stale_contexts | ( | char * | new, | |
| char * | old | |||
| ) | [static] |
Destroy disused contexts between reloads Only used in reload_config so the code for regcontext doesn't get ugly.
Definition at line 17065 of file chan_sip.c.
References ast_context_destroy(), ast_context_find(), ast_copy_string(), and AST_MAX_CONTEXT.
Referenced by reload_config().
17066 { 17067 char *oldcontext, *newcontext, *stalecontext, *stringp, newlist[AST_MAX_CONTEXT]; 17068 17069 while ((oldcontext = strsep(&old, "&"))) { 17070 stalecontext = '\0'; 17071 ast_copy_string(newlist, new, sizeof(newlist)); 17072 stringp = newlist; 17073 while ((newcontext = strsep(&stringp, "&"))) { 17074 if (!strcmp(newcontext, oldcontext)) { 17075 /* This is not the context you're looking for */ 17076 stalecontext = '\0'; 17077 break; 17078 } else if (strcmp(newcontext, oldcontext)) { 17079 stalecontext = oldcontext; 17080 } 17081 17082 } 17083 if (stalecontext) 17084 ast_context_destroy(ast_context_find(stalecontext), "SIP"); 17085 } 17086 }
| static void clear_peer_mailboxes | ( | struct sip_peer * | peer | ) | [static] |
Destroy all peer-related mailbox subscriptions
Definition at line 4596 of file chan_sip.c.
References AST_LIST_REMOVE_HEAD, destroy_mailbox(), and mailbox.
Referenced by set_peer_defaults(), and sip_destroy_peer().
04597 { 04598 struct sip_mailbox *mailbox; 04599 04600 while ((mailbox = AST_LIST_REMOVE_HEAD(&peer->mailboxes, entry))) 04601 destroy_mailbox(mailbox); 04602 }
| static void clear_sip_domains | ( | void | ) | [static] |
Clear our domain list (at reload).
Definition at line 27101 of file chan_sip.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, and AST_LIST_UNLOCK.
Referenced by reload_config(), and unload_module().
27102 { 27103 struct domain *d; 27104 27105 AST_LIST_LOCK(&domain_list); 27106 while ((d = AST_LIST_REMOVE_HEAD(&domain_list, list))) 27107 ast_free(d); 27108 AST_LIST_UNLOCK(&domain_list); 27109 }
| static char * complete_sip_peer | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on peer name.
Definition at line 18535 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, ast_test_flag, and unref_peer().
Referenced by complete_sip_show_peer(), complete_sipnotify(), sip_do_debug(), and sip_prune_realtime().
18536 { 18537 char *result = NULL; 18538 int wordlen = strlen(word); 18539 int which = 0; 18540 struct ao2_iterator i = ao2_iterator_init(peers, 0); 18541 struct sip_peer *peer; 18542 18543 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 18544 /* locking of the object is not required because only the name and flags are being compared */ 18545 if (!strncasecmp(word, peer->name, wordlen) && 18546 (!flags2 || ast_test_flag(&peer->flags[1], flags2)) && 18547 ++which > state) 18548 result = ast_strdup(peer->name); 18549 unref_peer(peer, "toss iterator peer ptr before break"); 18550 if (result) { 18551 break; 18552 } 18553 } 18554 ao2_iterator_destroy(&i); 18555 return result; 18556 }
| static char * complete_sip_registered_peer | ( | const char * | word, | |
| int | state, | |||
| int | flags2 | |||
| ) | [static] |
Do completion on registered peer name.
Definition at line 18559 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, ast_test_flag, and unref_peer().
Referenced by complete_sip_unregister().
18560 { 18561 char *result = NULL; 18562 int wordlen = strlen(word); 18563 int which = 0; 18564 struct ao2_iterator i; 18565 struct sip_peer *peer; 18566 18567 i = ao2_iterator_init(peers, 0); 18568 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 18569 if (!strncasecmp(word, peer->name, wordlen) && 18570 (!flags2 || ast_test_flag(&peer->flags[1], flags2)) && 18571 ++which > state && peer->expire > 0) 18572 result = ast_strdup(peer->name); 18573 if (result) { 18574 unref_peer(peer, "toss iterator peer ptr before break"); 18575 break; 18576 } 18577 unref_peer(peer, "toss iterator peer ptr"); 18578 } 18579 ao2_iterator_destroy(&i); 18580 return result; 18581 }
| static char * complete_sip_show_history | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show history' CLI.
Definition at line 18584 of file chan_sip.c.
References complete_sipch().
Referenced by sip_show_history().
18585 { 18586 if (pos == 3) 18587 return complete_sipch(line, word, pos, state); 18588 18589 return NULL; 18590 }
| static char * complete_sip_show_peer | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show peer' CLI.
Definition at line 18593 of file chan_sip.c.
References complete_sip_peer().
Referenced by sip_qualify_peer(), and sip_show_peer().
18594 { 18595 if (pos == 3) { 18596 return complete_sip_peer(word, state, 0); 18597 } 18598 18599 return NULL; 18600 }
| static char* complete_sip_show_user | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show user' CLI.
Definition at line 17807 of file chan_sip.c.
References complete_sip_user().
Referenced by sip_show_user().
17808 { 17809 if (pos == 3) 17810 return complete_sip_user(word, state); 17811 17812 return NULL; 17813 }
| static char * complete_sip_unregister | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip unregister' CLI.
Definition at line 18603 of file chan_sip.c.
References complete_sip_registered_peer().
Referenced by sip_unregister().
18604 { 18605 if (pos == 2) 18606 return complete_sip_registered_peer(word, state, 0); 18607 18608 return NULL; 18609 }
| static char* complete_sip_user | ( | const char * | word, | |
| int | state | |||
| ) | [static] |
Do completion on user name.
Definition at line 17777 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_iterator_next, ao2_unlock, ast_strdup, and unref_peer().
Referenced by complete_sip_show_user().
17778 { 17779 char *result = NULL; 17780 int wordlen = strlen(word); 17781 int which = 0; 17782 struct ao2_iterator user_iter; 17783 struct sip_peer *user; 17784 17785 user_iter = ao2_iterator_init(peers, 0); 17786 while ((user = ao2_t_iterator_next(&user_iter, "iterate thru peers table"))) { 17787 ao2_lock(user); 17788 if (!(user->type & SIP_TYPE_USER)) { 17789 ao2_unlock(user); 17790 unref_peer(user, "complete sip user"); 17791 continue; 17792 } 17793 /* locking of the object is not required because only the name and flags are being compared */ 17794 if (!strncasecmp(word, user->name, wordlen) && ++which > state) { 17795 result = ast_strdup(user->name); 17796 } 17797 ao2_unlock(user); 17798 unref_peer(user, "complete sip user"); 17799 if (result) { 17800 break; 17801 } 17802 } 17803 ao2_iterator_destroy(&user_iter); 17804 return result; 17805 }
| static char* complete_sipch | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip show channel' and 'sip show history' CLI This is in charge of generating all strings that match a prefix in the given position. As many functions of this kind, each invokation has O(state) time complexity so be careful in using it.
Definition at line 18505 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ast_strdup, sip_pvt_lock, and sip_pvt_unlock.
Referenced by complete_sip_show_history(), and sip_show_channel().
18506 { 18507 int which=0; 18508 struct sip_pvt *cur; 18509 char *c = NULL; 18510 int wordlen = strlen(word); 18511 struct ao2_iterator i; 18512 18513 if (pos != 3) { 18514 return NULL; 18515 } 18516 18517 i = ao2_iterator_init(dialogs, 0); 18518 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 18519 sip_pvt_lock(cur); 18520 if (!strncasecmp(word, cur->callid, wordlen) && ++which > state) { 18521 c = ast_strdup(cur->callid); 18522 sip_pvt_unlock(cur); 18523 dialog_unref(cur, "drop ref in iterator loop break"); 18524 break; 18525 } 18526 sip_pvt_unlock(cur); 18527 dialog_unref(cur, "drop ref in iterator loop"); 18528 } 18529 ao2_iterator_destroy(&i); 18530 return c; 18531 }
| static char * complete_sipnotify | ( | const char * | line, | |
| const char * | word, | |||
| int | pos, | |||
| int | state | |||
| ) | [static] |
Support routine for 'sip notify' CLI.
Definition at line 18612 of file chan_sip.c.
References ast_category_browse(), ast_strdup, and complete_sip_peer().
Referenced by sip_cli_notify().
18613 { 18614 char *c = NULL; 18615 18616 if (pos == 2) { 18617 int which = 0; 18618 char *cat = NULL; 18619 int wordlen = strlen(word); 18620 18621 /* do completion for notify type */ 18622 18623 if (!notify_types) 18624 return NULL; 18625 18626 while ( (cat = ast_category_browse(notify_types, cat)) ) { 18627 if (!strncasecmp(word, cat, wordlen) && ++which > state) { 18628 c = ast_strdup(cat); 18629 break; 18630 } 18631 } 18632 return c; 18633 } 18634 18635 if (pos > 2) 18636 return complete_sip_peer(word, state, 0); 18637 18638 return NULL; 18639 }
| static int construct_pidf_body | ( | enum sip_cc_publish_state | state, | |
| char * | pidf_body, | |||
| size_t | size, | |||
| const char * | presentity | |||
| ) | [static] |
Definition at line 1952 of file chan_sip.c.
References ast_copy_string(), ast_str_alloca, ast_str_append(), ast_str_buffer(), and generate_random_string().
Referenced by handle_cc_notify(), sip_cc_monitor_suspend(), and sip_cc_monitor_unsuspend().
01953 { 01954 struct ast_str *body = ast_str_alloca(size); 01955 char tuple_id[32]; 01956 01957 generate_random_string(tuple_id, sizeof(tuple_id)); 01958 01959 /* We'll make this a bare-bones pidf body. In state_notify_build_xml, the PIDF 01960 * body gets a lot more extra junk that isn't necessary, so we'll leave it out here. 01961 */ 01962 ast_str_append(&body, 0, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"); 01963 /* XXX The entity attribute is currently set to the peer name associated with the 01964 * dialog. This is because we currently only call this function for call-completion 01965 * PUBLISH bodies. In such cases, the entity is completely disregarded. For other 01966 * event packages, it may be crucial to have a proper URI as the presentity so this 01967 * should be revisited as support is expanded. 01968 */ 01969 ast_str_append(&body, 0, "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" entity=\"%s\">\n", presentity); 01970 ast_str_append(&body, 0, "<tuple id=\"%s\">\n", tuple_id); 01971 ast_str_append(&body, 0, "<status><basic>%s</basic></status>\n", state == CC_OPEN ? "open" : "closed"); 01972 ast_str_append(&body, 0, "</tuple>\n"); 01973 ast_str_append(&body, 0, "</presence>\n"); 01974 ast_copy_string(pidf_body, ast_str_buffer(body), size); 01975 return 0; 01976 }
| static int copy_all_header | ( | struct sip_request * | req, | |
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy all headers from one request to another.
Definition at line 9968 of file chan_sip.c.
References __get_header(), add_header(), and ast_strlen_zero().
Referenced by respprep().
09969 { 09970 int start = 0; 09971 int copied = 0; 09972 for (;;) { 09973 const char *tmp = __get_header(orig, field, &start); 09974 09975 if (ast_strlen_zero(tmp)) 09976 break; 09977 /* Add what we're responding to */ 09978 add_header(req, field, tmp); 09979 copied++; 09980 } 09981 return copied ? 0 : -1; 09982 }
| static int copy_header | ( | struct sip_request * | req, | |
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy one header field from one request to another.
Definition at line 9957 of file chan_sip.c.
References add_header(), ast_log(), ast_strlen_zero(), get_header(), and LOG_NOTICE.
Referenced by reqprep(), and respprep().
09958 { 09959 const char *tmp = get_header(orig, field); 09960 09961 if (!ast_strlen_zero(tmp)) /* Add what we're responding to */ 09962 return add_header(req, field, tmp); 09963 ast_log(LOG_NOTICE, "No field '%s' present to copy\n", field); 09964 return -1; 09965 }
| static void copy_request | ( | struct sip_request * | dst, | |
| const struct sip_request * | src | |||
| ) | [static] |
copy SIP request (mostly used to save request for responses)
Definition at line 11735 of file chan_sip.c.
References ast_str_copy_string(), ast_str_create(), and ast_str_strlen().
Referenced by _sip_tcp_helper_thread(), handle_request_bye(), handle_request_invite(), handle_request_options(), handle_request_register(), handle_request_subscribe(), initialize_initreq(), parse_copy(), and sip_park().
11736 { 11737 /* XXX this function can encounter memory allocation errors, perhaps it 11738 * should return a value */ 11739 11740 struct ast_str *duplicate = dst->data; 11741 struct ast_str *duplicate_content = dst->content; 11742 11743 /* copy the entire request then restore the original data and content 11744 * members from the dst request */ 11745 memcpy(dst, src, sizeof(*dst)); 11746 dst->data = duplicate; 11747 dst->content = duplicate_content; 11748 11749 /* copy the data into the dst request */ 11750 if (!dst->data && !(dst->data = ast_str_create(ast_str_strlen(src->data) + 1))) 11751 return; 11752 ast_str_copy_string(&dst->data, src->data); 11753 11754 /* copy the content into the dst request (if it exists) */ 11755 if (src->content) { 11756 if (!dst->content && !(dst->content = ast_str_create(ast_str_strlen(src->content) + 1))) 11757 return; 11758 ast_str_copy_string(&dst->content, src->content); 11759 } 11760 }
| static void copy_socket_data | ( | struct sip_socket * | to_sock, | |
| const struct sip_socket * | from_sock | |||
| ) | [static] |
Definition at line 5173 of file chan_sip.c.
References ao2_ref.
Referenced by create_addr_from_peer(), handle_request_do(), parse_register_contact(), sip_poke_peer(), and transmit_response_using_temp().
| static struct ast_variable * copy_vars | ( | struct ast_variable * | src | ) | [static, read] |
duplicate a list of channel variables,
Definition at line 2331 of file chan_sip.c.
References ast_variable_new(), and ast_variable::next.
Referenced by check_peer_ok(), and create_addr_from_peer().
02332 { 02333 struct ast_variable *res = NULL, *tmp, *v = NULL; 02334 02335 for (v = src ; v ; v = v->next) { 02336 if ((tmp = ast_variable_new(v->name, v->value, v->file))) { 02337 tmp->next = res; 02338 res = tmp; 02339 } 02340 } 02341 return res; 02342 }
| static int copy_via_headers | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| const struct sip_request * | orig, | |||
| const char * | field | |||
| ) | [static] |
Copy SIP VIA Headers from the request to the response.
We always add ;received=<ip address> to the topmost via header.
Definition at line 9992 of file chan_sip.c.
References __get_header(), add_header(), ast_copy_string(), ast_log(), ast_sockaddr_port, ast_sockaddr_stringify_addr_remote(), ast_strlen_zero(), ast_test_flag, and LOG_NOTICE.
Referenced by respprep().
09993 { 09994 int copied = 0; 09995 int start = 0; 09996 09997 for (;;) { 09998 char new[512]; 09999 const char *oh = __get_header(orig, field, &start); 10000 10001 if (ast_strlen_zero(oh)) 10002 break; 10003 10004 if (!copied) { /* Only check for empty rport in topmost via header */ 10005 char leftmost[512], *others, *rport; 10006 10007 /* Only work on leftmost value */ 10008 ast_copy_string(leftmost, oh, sizeof(leftmost)); 10009 others = strchr(leftmost, ','); 10010 if (others) 10011 *others++ = '\0'; 10012 10013 /* Find ;rport; (empty request) */ 10014 rport = strstr(leftmost, ";rport"); 10015 if (rport && *(rport+6) == '=') 10016 rport = NULL; /* We already have a parameter to rport */ 10017 10018 if (((ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT)) || (rport && ast_test_flag(&p->flags[0], SIP_NAT_RPORT_PRESENT)))) { 10019 /* We need to add received port - rport */ 10020 char *end; 10021 10022 rport = strstr(leftmost, ";rport"); 10023 10024 if (rport) { 10025 end = strchr(rport + 1, ';'); 10026 if (end) 10027 memmove(rport, end, strlen(end) + 1); 10028 else 10029 *rport = '\0'; 10030 } 10031 10032 /* Add rport to first VIA header if requested */ 10033 snprintf(new, sizeof(new), "%s;received=%s;rport=%d%s%s", 10034 leftmost, ast_sockaddr_stringify_addr_remote(&p->recv), 10035 ast_sockaddr_port(&p->recv), 10036 others ? "," : "", others ? others : ""); 10037 } else { 10038 /* We should *always* add a received to the topmost via */ 10039 snprintf(new, sizeof(new), "%s;received=%s%s%s", 10040 leftmost, ast_sockaddr_stringify_addr_remote(&p->recv), 10041 others ? "," : "", others ? others : ""); 10042 } 10043 oh = new; /* the header to copy */ 10044 } /* else add the following via headers untouched */ 10045 add_header(req, field, oh); 10046 copied++; 10047 } 10048 if (!copied) { 10049 ast_log(LOG_NOTICE, "No header field '%s' present to copy\n", field); 10050 return -1; 10051 } 10052 return 0; 10053 }
| static int create_addr | ( | struct sip_pvt * | dialog, | |
| const char * | opeer, | |||
| struct ast_sockaddr * | addr, | |||
| int | newdialog, | |||
| struct ast_sockaddr * | remote_address | |||
| ) | [static] |
create address structure from device name Or, if peer not found, find it in the global DNS returns TRUE (-1) on failure, FALSE on success
Definition at line 5401 of file chan_sip.c.
References AST_APP_ARG, ast_check_digits(), AST_DECLARE_APP_ARGS, ast_get_srv(), ast_log(), AST_NONSTANDARD_RAW_ARGS, ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_strdupa, ast_string_field_set, bindaddr, create_addr_from_peer(), default_sip_port(), dialog_initialize_rtp(), FALSE, find_peer(), get_srv_protocol(), get_srv_service(), LOG_WARNING, MAXHOSTNAMELEN, obproxy_get(), ref_peer(), ref_proxy(), service, set_socket_transport(), sip_cfg, TRUE, and unref_peer().
Referenced by __sip_subscribe_mwi_do(), manager_sipnotify(), sip_cc_monitor_request_cc(), sip_cli_notify(), sip_request_call(), transmit_publish(), and transmit_register().
05402 { 05403 struct sip_peer *peer; 05404 char *peername, *peername2, *hostn; 05405 char host[MAXHOSTNAMELEN]; 05406 char service[MAXHOSTNAMELEN]; 05407 int srv_ret = 0; 05408 int tportno; 05409 05410 AST_DECLARE_APP_ARGS(hostport, 05411 AST_APP_ARG(host); 05412 AST_APP_ARG(port); 05413 ); 05414 05415 peername = ast_strdupa(opeer); 05416 peername2 = ast_strdupa(opeer); 05417 AST_NONSTANDARD_RAW_ARGS(hostport, peername2, ':'); 05418 05419 if (hostport.port) 05420 dialog->portinuri = 1; 05421 05422 dialog->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */ 05423 dialog->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */ 05424 peer = find_peer(peername, NULL, TRUE, FINDPEERS, FALSE, 0); 05425 05426 if (peer) { 05427 int res; 05428 if (newdialog) { 05429 set_socket_transport(&dialog->socket, 0); 05430 } 05431 res = create_addr_from_peer(dialog, peer); 05432 if (!ast_sockaddr_isnull(remote_address)) { 05433 ast_sockaddr_copy(&dialog->sa, remote_address); 05434 } 05435 dialog->relatedpeer = ref_peer(peer, "create_addr: setting dialog's relatedpeer pointer"); 05436 unref_peer(peer, "create_addr: unref peer from find_peer hashtab lookup"); 05437 return res; 05438 } else if (ast_check_digits(peername)) { 05439 /* Although an IPv4 hostname *could* be represented as a 32-bit integer, it is uncommon and 05440 * it makes dialing SIP/${EXTEN} for a peer that isn't defined resolve to an IP that is 05441 * almost certainly not intended. It is much better to just reject purely numeric hostnames */ 05442 ast_log(LOG_WARNING, "Purely numeric hostname (%s), and not a peer--rejecting!\n", peername); 05443 return -1; 05444 } else { 05445 dialog->rtptimeout = global_rtptimeout; 05446 dialog->rtpholdtimeout = global_rtpholdtimeout; 05447 dialog->rtpkeepalive = global_rtpkeepalive; 05448 if (dialog_initialize_rtp(dialog)) { 05449 return -1; 05450 } 05451 } 05452 05453 ast_string_field_set(dialog, tohost, hostport.host); 05454 dialog->allowed_methods &= ~sip_cfg.disallowed_methods; 05455 05456 /* Get the outbound proxy information */ 05457 ref_proxy(dialog, obproxy_get(dialog, NULL)); 05458 05459 if (addr) { 05460 /* This address should be updated using dnsmgr */ 05461 ast_sockaddr_copy(&dialog->sa, addr); 05462 } else { 05463 05464 /* Let's see if we can find the host in DNS. First try DNS SRV records, 05465 then hostname lookup */ 05466 /*! \todo Fix this function. When we ask for SRV, we should check all transports 05467 In the future, we should first check NAPTR to find out transport preference 05468 */ 05469 hostn = peername; 05470 /* Section 4.2 of RFC 3263 specifies that if a port number is specified, then 05471 * an A record lookup should be used instead of SRV. 05472 */ 05473 if (!hostport.port && sip_cfg.srvlookup) { 05474 snprintf(service, sizeof(service), "_%s._%s.%s", 05475 get_srv_service(dialog->socket.type), 05476 get_srv_protocol(dialog->socket.type), peername); 05477 if ((srv_ret = ast_get_srv(NULL, host, sizeof(host), &tportno, 05478 service)) > 0) { 05479 hostn = host; 05480 } 05481 } 05482 05483 if (ast_sockaddr_resolve_first_transport(&dialog->sa, hostn, 0, dialog->socket.type ? dialog->socket.type : SIP_TRANSPORT_UDP)) { 05484 ast_log(LOG_WARNING, "No such host: %s\n", peername); 05485 return -1; 05486 } 05487 05488 if (srv_ret > 0) { 05489 ast_sockaddr_set_port(&dialog->sa, tportno); 05490 } 05491 } 05492 05493 if (!dialog->socket.type) 05494 set_socket_transport(&dialog->socket, SIP_TRANSPORT_UDP); 05495 if (!dialog->socket.port) { 05496 dialog->socket.port = htons(ast_sockaddr_port(&bindaddr)); 05497 } 05498 05499 if (!ast_sockaddr_port(&dialog->sa)) { 05500 ast_sockaddr_set_port(&dialog->sa, default_sip_port(dialog->socket.type)); 05501 } 05502 ast_sockaddr_copy(&dialog->recv, &dialog->sa); 05503 return 0; 05504 }
| static int create_addr_from_peer | ( | struct sip_pvt * | dialog, | |
| struct sip_peer * | peer | |||
| ) | [static] |
Create address structure from peer reference. This function copies data from peer to the dialog, so we don't have to look up the peer again from memory or database during the life time of the dialog.
Definition at line 5247 of file chan_sip.c.
References accountcode, ao2_lock, ao2_t_ref, ao2_unlock, ast_cc_copy_config_params(), ast_copy_flags, ast_duplicate_ha_list(), ast_rtp_codecs_packetization_set(), AST_RTP_DTMF, ast_rtp_instance_get_codecs(), ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_set_flag, ast_sockaddr_isnull(), ast_sockaddr_stringify_host_remote(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, change_callid_pvt(), check_request_transport, cid_name, cid_num, context, copy_socket_data(), copy_vars(), dialog_initialize_rtp(), language, mohinterpret, mohsuggest, obproxy_get(), parkinglot, and ref_proxy().
Referenced by create_addr(), and sip_send_mwi_to_peer().
05248 { 05249 struct sip_auth_container *credentials; 05250 05251 /* this checks that the dialog is contacting the peer on a valid 05252 * transport type based on the peers transport configuration, 05253 * otherwise, this function bails out */ 05254 if (dialog->socket.type && check_request_transport(peer, dialog)) 05255 return -1; 05256 copy_socket_data(&dialog->socket, &peer->socket); 05257 05258 if (!(ast_sockaddr_isnull(&peer->addr) && ast_sockaddr_isnull(&peer->defaddr)) && 05259 (!peer->maxms || ((peer->lastms >= 0) && (peer->lastms <= peer->maxms)))) { 05260 dialog->sa = ast_sockaddr_isnull(&peer->addr) ? peer->defaddr : peer->addr; 05261 dialog->recv = dialog->sa; 05262 } else 05263 return -1; 05264 05265 /* XXX TODO: get flags directly from peer only as they are needed using dialog->relatedpeer */ 05266 ast_copy_flags(&dialog->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 05267 ast_copy_flags(&dialog->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 05268 ast_copy_flags(&dialog->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY); 05269 dialog->capability = peer->capability; 05270 dialog->prefs = peer->prefs; 05271 dialog->amaflags = peer->amaflags; 05272 05273 ast_string_field_set(dialog, engine, peer->engine); 05274 05275 dialog->rtptimeout = peer->rtptimeout; 05276 dialog->rtpholdtimeout = peer->rtpholdtimeout; 05277 dialog->rtpkeepalive = peer->rtpkeepalive; 05278 if (dialog_initialize_rtp(dialog)) { 05279 return -1; 05280 } 05281 05282 if (dialog->rtp) { /* Audio */ 05283 ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 05284 ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 05285 /* Set Frame packetization */ 05286 ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(dialog->rtp), dialog->rtp, &dialog->prefs); 05287 dialog->autoframing = peer->autoframing; 05288 } 05289 05290 /* XXX TODO: get fields directly from peer only as they are needed using dialog->relatedpeer */ 05291 ast_string_field_set(dialog, peername, peer->name); 05292 ast_string_field_set(dialog, authname, peer->username); 05293 ast_string_field_set(dialog, username, peer->username); 05294 ast_string_field_set(dialog, peersecret, peer->secret); 05295 ast_string_field_set(dialog, peermd5secret, peer->md5secret); 05296 ast_string_field_set(dialog, mohsuggest, peer->mohsuggest); 05297 ast_string_field_set(dialog, mohinterpret, peer->mohinterpret); 05298 ast_string_field_set(dialog, tohost, peer->tohost); 05299 ast_string_field_set(dialog, fullcontact, peer->fullcontact); 05300 ast_string_field_set(dialog, accountcode, peer->accountcode); 05301 ast_string_field_set(dialog, context, peer->context); 05302 ast_string_field_set(dialog, cid_num, peer->cid_num); 05303 ast_string_field_set(dialog, cid_name, peer->cid_name); 05304 ast_string_field_set(dialog, cid_tag, peer->cid_tag); 05305 ast_string_field_set(dialog, mwi_from, peer->mwi_from); 05306 if (!ast_strlen_zero(peer->parkinglot)) { 05307 ast_string_field_set(dialog, parkinglot, peer->parkinglot); 05308 } 05309 ast_string_field_set(dialog, engine, peer->engine); 05310 ref_proxy(dialog, obproxy_get(dialog, peer)); 05311 dialog->callgroup = peer->callgroup; 05312 dialog->pickupgroup = peer->pickupgroup; 05313 dialog->allowtransfer = peer->allowtransfer; 05314 dialog->jointnoncodeccapability = dialog->noncodeccapability; 05315 05316 /* Update dialog authorization credentials */ 05317 ao2_lock(peer); 05318 credentials = peer->auth; 05319 if (credentials) { 05320 ao2_t_ref(credentials, +1, "Ref peer auth for dialog"); 05321 } 05322 ao2_unlock(peer); 05323 ao2_lock(dialog); 05324 if (dialog->peerauth) { 05325 ao2_t_ref(dialog->peerauth, -1, "Unref old dialog peer auth"); 05326 } 05327 dialog->peerauth = credentials; 05328 ao2_unlock(dialog); 05329 05330 dialog->maxcallbitrate = peer->maxcallbitrate; 05331 dialog->disallowed_methods = peer->disallowed_methods; 05332 ast_cc_copy_config_params(dialog->cc_params, peer->cc_params); 05333 if (ast_strlen_zero(dialog->tohost)) 05334 ast_string_field_set(dialog, tohost, ast_sockaddr_stringify_host_remote(&dialog->sa)); 05335 if (!ast_strlen_zero(peer->fromdomain)) { 05336 ast_string_field_set(dialog, fromdomain, peer->fromdomain); 05337 if (!dialog->initreq.headers) { 05338 char *new_callid; 05339 char *tmpcall = ast_strdupa(dialog->callid); 05340 /* this sure looks to me like we are going to change the callid on this dialog!! */ 05341 new_callid = strchr(tmpcall, '@'); 05342 if (new_callid) { 05343 int callid_size; 05344 05345 *new_callid = '\0'; 05346 05347 /* Change the dialog callid. */ 05348 callid_size = strlen(tmpcall) + strlen(peer->fromdomain) + 2; 05349 new_callid = alloca(callid_size); 05350 snprintf(new_callid, callid_size, "%s@%s", tmpcall, peer->fromdomain); 05351 change_callid_pvt(dialog, new_callid); 05352 } 05353 } 05354 } 05355 if (!ast_strlen_zero(peer->fromuser)) 05356 ast_string_field_set(dialog, fromuser, peer->fromuser); 05357 if (!ast_strlen_zero(peer->language)) 05358 ast_string_field_set(dialog, language, peer->language); 05359 /* Set timer T1 to RTT for this peer (if known by qualify=) */ 05360 /* Minimum is settable or default to 100 ms */ 05361 /* If there is a maxms and lastms from a qualify use that over a manual T1 05362 value. Otherwise, use the peer's T1 value. */ 05363 if (peer->maxms && peer->lastms) 05364 dialog->timer_t1 = peer->lastms < global_t1min ? global_t1min : peer->lastms; 05365 else 05366 dialog->timer_t1 = peer->timer_t1; 05367 05368 /* Set timer B to control transaction timeouts, the peer setting is the default and overrides 05369 the known timer */ 05370 if (peer->timer_b) 05371 dialog->timer_b = peer->timer_b; 05372 else 05373 dialog->timer_b = 64 * dialog->timer_t1; 05374 05375 if ((ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 05376 (ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) 05377 dialog->noncodeccapability |= AST_RTP_DTMF; 05378 else 05379 dialog->noncodeccapability &= ~AST_RTP_DTMF; 05380 dialog->directmediaha = ast_duplicate_ha_list(peer->directmediaha); 05381 if (peer->call_limit) 05382 ast_set_flag(&dialog->flags[0], SIP_CALL_LIMIT); 05383 if (!dialog->portinuri) 05384 dialog->portinuri = peer->portinuri; 05385 dialog->chanvars = copy_vars(peer->chanvars); 05386 if (peer->fromdomainport) 05387 dialog->fromdomainport = peer->fromdomainport; 05388 05389 return 0; 05390 }
| static struct sip_epa_entry* create_epa_entry | ( | const char *const | event_package, | |
| const char *const | destination | |||
| ) | [static, read] |
Definition at line 919 of file chan_sip.c.
References ao2_t_alloc, ast_copy_string(), and find_static_data().
Referenced by sip_cc_monitor_suspend().
00920 { 00921 struct sip_epa_entry *epa_entry; 00922 const struct epa_static_data *static_data; 00923 00924 if (!(static_data = find_static_data(event_package))) { 00925 return NULL; 00926 } 00927 00928 if (!(epa_entry = ao2_t_alloc(sizeof(*epa_entry), static_data->destructor, "Allocate new EPA entry"))) { 00929 return NULL; 00930 } 00931 00932 epa_entry->static_data = static_data; 00933 ast_copy_string(epa_entry->destination, destination, sizeof(epa_entry->destination)); 00934 return epa_entry; 00935 }
| static struct sip_esc_entry* create_esc_entry | ( | struct event_state_compositor * | esc, | |
| struct sip_request * | req, | |||
| const int | expires | |||
| ) | [static, read] |
Definition at line 1045 of file chan_sip.c.
References ao2_alloc, ao2_ref, ast_sched_add(), create_new_sip_etag(), esc_entry_destructor(), event_state_compositor::name, and publish_expire().
Referenced by handle_sip_publish_initial().
01046 { 01047 struct sip_esc_entry *esc_entry; 01048 int expires_ms; 01049 01050 if (!(esc_entry = ao2_alloc(sizeof(*esc_entry), esc_entry_destructor))) { 01051 return NULL; 01052 } 01053 01054 esc_entry->event = esc->name; 01055 01056 expires_ms = expires * 1000; 01057 /* Bump refcount for scheduler */ 01058 ao2_ref(esc_entry, +1); 01059 esc_entry->sched_id = ast_sched_add(sched, expires_ms, publish_expire, esc_entry); 01060 01061 /* Note: This links the esc_entry into the ESC properly */ 01062 create_new_sip_etag(esc_entry, 0); 01063 01064 return esc_entry; 01065 }
| static void create_new_sip_etag | ( | struct sip_esc_entry * | esc_entry, | |
| int | is_linked | |||
| ) | [static] |
Definition at line 1032 of file chan_sip.c.
References ao2_link, ao2_unlink, ast_assert, ast_atomic_fetchadd_int(), event_state_compositor::compositor, and get_esc().
Referenced by create_esc_entry(), and transmit_response_with_sip_etag().
01033 { 01034 int new_etag = ast_atomic_fetchadd_int(&esc_etag_counter, +1); 01035 struct event_state_compositor *esc = get_esc(esc_entry->event); 01036 01037 ast_assert(esc != NULL); 01038 if (is_linked) { 01039 ao2_unlink(esc->compositor, esc_entry); 01040 } 01041 snprintf(esc_entry->entity_tag, sizeof(esc_entry->entity_tag), "%d", new_etag); 01042 ao2_link(esc->compositor, esc_entry); 01043 }
| static int default_sip_port | ( | enum sip_transport | type | ) | [inline, static] |
The default sip port for the given transport.
Definition at line 5393 of file chan_sip.c.
Referenced by create_addr(), on_dns_update_peer(), and parse_register_contact().
05394 { 05395 return type == SIP_TRANSPORT_TLS ? STANDARD_TLS_PORT : STANDARD_SIP_PORT; 05396 }
| static void deinit_req | ( | struct sip_request * | req | ) | [static] |
Deinitialize SIP response/request.
Definition at line 10209 of file chan_sip.c.
References ast_free.
Referenced by __sip_destroy(), _sip_tcp_helper_thread(), send_request(), send_response(), sip_park(), sip_park_thread(), and sipsock_read().
| static void destroy_association | ( | struct sip_peer * | peer | ) | [static] |
Remove registration data from realtime database or AST/DB when registration expires.
Definition at line 13748 of file chan_sip.c.
References ast_check_realtime(), ast_db_del(), ast_update_realtime(), SENTINEL, and sip_cfg.
Referenced by build_peer(), and expire_register().
13749 { 13750 int realtimeregs = ast_check_realtime("sipregs"); 13751 char *tablename = (realtimeregs) ? "sipregs" : "sippeers"; 13752 13753 if (!sip_cfg.ignore_regexpire) { 13754 if (peer->rt_fromcontact && sip_cfg.peer_rtupdate) { 13755 ast_update_realtime(tablename, "name", peer->name, "fullcontact", "", "ipaddr", "", "port", "", "regseconds", "0", "regserver", "", "useragent", "", "lastms", "0", SENTINEL); 13756 } else { 13757 ast_db_del("SIP/Registry", peer->name); 13758 ast_db_del("SIP/PeerMethods", peer->name); 13759 } 13760 } 13761 }
| static void destroy_escs | ( | void | ) | [static] |
Definition at line 1079 of file chan_sip.c.
References ao2_ref, ARRAY_LEN, and event_state_compositors.
Referenced by unload_module().
01080 { 01081 int i; 01082 for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) { 01083 ao2_ref(event_state_compositors[i].compositor, -1); 01084 } 01085 }
| static void destroy_mailbox | ( | struct sip_mailbox * | mailbox | ) | [static] |
Destroy mailbox subscriptions
Definition at line 4588 of file chan_sip.c.
References ast_event_unsubscribe(), and ast_free.
Referenced by build_peer(), and clear_peer_mailboxes().
04589 { 04590 if (mailbox->event_sub) 04591 ast_event_unsubscribe(mailbox->event_sub); 04592 ast_free(mailbox); 04593 }
| static void destroy_realm_authentication | ( | void * | obj | ) | [static] |
Definition at line 27119 of file chan_sip.c.
References ast_free, and AST_LIST_REMOVE_HEAD.
Referenced by add_realm_authentication().
27120 { 27121 struct sip_auth_container *credentials = obj; 27122 struct sip_auth *auth; 27123 27124 while ((auth = AST_LIST_REMOVE_HEAD(&credentials->list, node))) { 27125 ast_free(auth); 27126 } 27127 }
| static int determine_firstline_parts | ( | struct sip_request * | req | ) | [static] |
Parse first line of incoming SIP request.
Definition at line 11832 of file chan_sip.c.
References ast_debug, ast_skip_blanks(), ast_skip_nonblanks(), and ast_trim_blanks().
Referenced by parse_request().
11833 { 11834 char *e = ast_skip_blanks(req->data->str); /* there shouldn't be any */ 11835 char *local_rlPart1; 11836 11837 if (!*e) 11838 return -1; 11839 req->rlPart1 = e - req->data->str; /* method or protocol */ 11840 local_rlPart1 = e; 11841 e = ast_skip_nonblanks(e); 11842 if (*e) 11843 *e++ = '\0'; 11844 /* Get URI or status code */ 11845 e = ast_skip_blanks(e); 11846 if ( !*e ) 11847 return -1; 11848 ast_trim_blanks(e); 11849 11850 if (!strcasecmp(local_rlPart1, "SIP/2.0") ) { /* We have a response */ 11851 if (strlen(e) < 3) /* status code is 3 digits */ 11852 return -1; 11853 req->rlPart2 = e - req->data->str; 11854 } else { /* We have a request */ 11855 if ( *e == '<' ) { /* XXX the spec says it must not be in <> ! */ 11856 ast_debug(3, "Oops. Bogus uri in <> %s\n", e); 11857 e++; 11858 if (!*e) 11859 return -1; 11860 } 11861 req->rlPart2 = e - req->data->str; /* URI */ 11862 e = ast_skip_nonblanks(e); 11863 if (*e) 11864 *e++ = '\0'; 11865 e = ast_skip_blanks(e); 11866 if (strcasecmp(e, "SIP/2.0") ) { 11867 ast_debug(3, "Skipping packet - Bad request protocol %s\n", e); 11868 return -1; 11869 } 11870 } 11871 return 1; 11872 }
| 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] |
Definition at line 24095 of file chan_sip.c.
References ast_assert, and ast_strlen_zero().
Referenced by handle_request_publish().
24096 { 24097 int etag_present = !ast_strlen_zero(etag); 24098 int body_present = req->lines > 0; 24099 24100 ast_assert(expires_int != NULL); 24101 24102 if (ast_strlen_zero(expires)) { 24103 /* Section 6, item 4, second bullet point of RFC 3903 says to 24104 * use a locally-configured default expiration if none is provided 24105 * in the request 24106 */ 24107 *expires_int = DEFAULT_PUBLISH_EXPIRES; 24108 } else if (sscanf(expires, "%30d", expires_int) != 1) { 24109 return SIP_PUBLISH_UNKNOWN; 24110 } 24111 24112 if (*expires_int == 0) { 24113 return SIP_PUBLISH_REMOVE; 24114 } else if (!etag_present && body_present) { 24115 return SIP_PUBLISH_INITIAL; 24116 } else if (etag_present && !body_present) { 24117 return SIP_PUBLISH_REFRESH; 24118 } else if (etag_present && body_present) { 24119 return SIP_PUBLISH_MODIFY; 24120 } 24121 24122 return SIP_PUBLISH_UNKNOWN; 24123 }
| static int dialog_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 30144 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by load_module().
| static int dialog_dump_func | ( | void * | userobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 16966 of file chan_sip.c.
References ao2_t_ref, ast_cli(), and ast_cli_args::fd.
Referenced by sip_show_objects().
16967 { 16968 struct sip_pvt *pvt = userobj; 16969 int refc = ao2_t_ref(userobj, 0, ""); 16970 struct ast_cli_args *a = (struct ast_cli_args *) arg; 16971 16972 ast_cli(a->fd, "name: %s\ntype: dialog\nobjflags: %d\nrefcount: %d\n\n", 16973 pvt->callid, 0, refc); 16974 return 0; 16975 }
| static int dialog_find_multiple | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 30134 of file chan_sip.c.
References CMP_MATCH.
Referenced by find_call().
30135 { 30136 struct sip_pvt *pvt = obj, *pvt2 = arg; 30137 30138 return !strcasecmp(pvt->callid, pvt2->callid) ? CMP_MATCH : 0; 30139 }
| static int dialog_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 30124 of file chan_sip.c.
References ast_str_case_hash().
Referenced by load_module().
30125 { 30126 const struct sip_pvt *pvt = obj; 30127 30128 return ast_str_case_hash(pvt->callid); 30129 }
| static int dialog_initialize_rtp | ( | struct sip_pvt * | dialog | ) | [static] |
Initialize RTP portion of a dialog.
Definition at line 5190 of file chan_sip.c.
References AST_FORMAT_VIDEO_MASK, ast_rtp_instance_new(), ast_rtp_instance_set_hold_timeout(), ast_rtp_instance_set_keepalive(), ast_rtp_instance_set_prop(), ast_rtp_instance_set_qos(), ast_rtp_instance_set_timeout(), AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, AST_RTP_PROPERTY_RTCP, ast_sockaddr_copy(), ast_test_flag, bindaddr, do_setnat(), cfsip_methods::need_rtp, and sip_methods.
Referenced by check_peer_ok(), check_user_full(), create_addr(), and create_addr_from_peer().
05191 { 05192 struct ast_sockaddr bindaddr_tmp; 05193 05194 if (!sip_methods[dialog->method].need_rtp) { 05195 return 0; 05196 } 05197 05198 ast_sockaddr_copy(&bindaddr_tmp, &bindaddr); 05199 if (!(dialog->rtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) { 05200 return -1; 05201 } 05202 05203 if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS) || 05204 (ast_test_flag(&dialog->flags[1], SIP_PAGE2_VIDEOSUPPORT) && (dialog->capability & AST_FORMAT_VIDEO_MASK))) { 05205 if (!(dialog->vrtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) { 05206 return -1; 05207 } 05208 ast_rtp_instance_set_timeout(dialog->vrtp, dialog->rtptimeout); 05209 ast_rtp_instance_set_hold_timeout(dialog->vrtp, dialog->rtpholdtimeout); 05210 ast_rtp_instance_set_keepalive(dialog->vrtp, dialog->rtpkeepalive); 05211 05212 ast_rtp_instance_set_prop(dialog->vrtp, AST_RTP_PROPERTY_RTCP, 1); 05213 } 05214 05215 if (ast_test_flag(&dialog->flags[1], SIP_PAGE2_TEXTSUPPORT)) { 05216 if (!(dialog->trtp = ast_rtp_instance_new(dialog->engine, sched, &bindaddr_tmp, NULL))) { 05217 return -1; 05218 } 05219 /* Do not timeout text as its not constant*/ 05220 ast_rtp_instance_set_keepalive(dialog->trtp, dialog->rtpkeepalive); 05221 05222 ast_rtp_instance_set_prop(dialog->trtp, AST_RTP_PROPERTY_RTCP, 1); 05223 } 05224 05225 ast_rtp_instance_set_timeout(dialog->rtp, dialog->rtptimeout); 05226 ast_rtp_instance_set_hold_timeout(dialog->rtp, dialog->rtpholdtimeout); 05227 ast_rtp_instance_set_keepalive(dialog->rtp, dialog->rtpkeepalive); 05228 05229 ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_RTCP, 1); 05230 ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&dialog->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 05231 ast_rtp_instance_set_prop(dialog->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&dialog->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 05232 05233 ast_rtp_instance_set_qos(dialog->rtp, global_tos_audio, global_cos_audio, "SIP RTP"); 05234 05235 do_setnat(dialog); 05236 05237 return 0; 05238 }
| static int dialog_needdestroy | ( | void * | dialogobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Match dialogs that need to be destroyed.
This is used with ao2_callback to unlink/delete all dialogs that are marked needdestroy.
Definition at line 17098 of file chan_sip.c.
References ao2_t_link, ast_debug, ast_rtp_instance_get_bridged(), check_rtp_timeout(), sip_methods, sip_pvt_trylock, sip_pvt_unlock, and cfsip_methods::text.
Referenced by do_monitor().
17099 { 17100 struct sip_pvt *dialog = dialogobj; 17101 time_t *t = arg; 17102 17103 if (sip_pvt_trylock(dialog)) { 17104 /* Don't block the monitor thread. This function is called often enough 17105 * that we can wait for the next time around. */ 17106 return 0; 17107 } 17108 17109 /* Check RTP timeouts and kill calls if we have a timeout set and do not get RTP */ 17110 check_rtp_timeout(dialog, *t); 17111 17112 /* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */ 17113 if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) { 17114 ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 17115 sip_pvt_unlock(dialog); 17116 return 0; 17117 } 17118 17119 if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) { 17120 ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 17121 sip_pvt_unlock(dialog); 17122 return 0; 17123 } 17124 17125 /* If we have sessions that needs to be destroyed, do it now */ 17126 /* Check if we have outstanding requests not responsed to or an active call 17127 - if that's the case, wait with destruction */ 17128 if (dialog->needdestroy && !dialog->packets && !dialog->owner) { 17129 /* We absolutely cannot destroy the rtp struct while a bridge is active or we WILL crash */ 17130 if (dialog->rtp && ast_rtp_instance_get_bridged(dialog->rtp)) { 17131 ast_debug(2, "Bridge still active. Delaying destruction of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 17132 sip_pvt_unlock(dialog); 17133 return 0; 17134 } 17135 17136 if (dialog->vrtp && ast_rtp_instance_get_bridged(dialog->vrtp)) { 17137 ast_debug(2, "Bridge still active. Delaying destroy of SIP dialog '%s' Method: %s\n", dialog->callid, sip_methods[dialog->method].text); 17138 sip_pvt_unlock(dialog); 17139 return 0; 17140 } 17141 17142 sip_pvt_unlock(dialog); 17143 17144 /* This dialog needs to be destroyed. */ 17145 ao2_t_link(dialogs_to_destroy, dialog, "Link dialog for destruction"); 17146 return 0; 17147 } 17148 17149 sip_pvt_unlock(dialog); 17150 17151 return 0; 17152 }
| struct sip_pvt* dialog_ref_debug | ( | struct sip_pvt * | p, | |
| char * | tag, | |||
| char * | file, | |||
| int | line, | |||
| const char * | func | |||
| ) | [read] |
Definition at line 2223 of file chan_sip.c.
References __ao2_ref_debug(), ao2_ref, ast_log(), and LOG_ERROR.
02224 { 02225 if (p) 02226 #ifdef REF_DEBUG 02227 __ao2_ref_debug(p, 1, tag, file, line, func); 02228 #else 02229 ao2_ref(p, 1); 02230 #endif 02231 else 02232 ast_log(LOG_ERROR, "Attempt to Ref a null pointer\n"); 02233 return p; 02234 }
| 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.
Definition at line 2953 of file chan_sip.c.
References ao2_t_unlink, ast_channel_unlock, ast_channel_unref, ast_debug, ast_extension_state_del(), ast_free, AST_SCHED_DEL, AST_SCHED_DEL_UNREF, cb_extensionstate(), registry_unref(), sip_pvt_lock_full(), sip_pvt_unlock, stop_session_timer(), and ast_channel::tech_pvt.
Referenced by __sip_autodestruct(), __sip_subscribe_mwi_do(), cleanup_all_regs(), dialog_unlink_callback(), handle_request_subscribe(), manager_sipnotify(), sip_cli_notify(), sip_destroy_peer(), sip_poke_noanswer(), sip_poke_peer(), sip_registry_destroy(), sip_request_call(), sip_send_mwi_to_peer(), transmit_publish(), transmit_register(), and unload_module().
02954 { 02955 struct sip_pkt *cp; 02956 struct ast_channel *owner; 02957 02958 dialog_ref(dialog, "Let's bump the count in the unlink so it doesn't accidentally become dead before we are done"); 02959 02960 ao2_t_unlink(dialogs, dialog, "unlinking dialog via ao2_unlink"); 02961 02962 /* Unlink us from the owner (channel) if we have one */ 02963 owner = sip_pvt_lock_full(dialog); 02964 if (owner) { 02965 ast_debug(1, "Detaching from channel %s\n", owner->name); 02966 owner->tech_pvt = dialog_unref(owner->tech_pvt, "resetting channel dialog ptr in unlink_all"); 02967 ast_channel_unlock(owner); 02968 ast_channel_unref(owner); 02969 dialog->owner = NULL; 02970 } 02971 sip_pvt_unlock(dialog); 02972 02973 if (dialog->registry) { 02974 if (dialog->registry->call == dialog) { 02975 dialog->registry->call = dialog_unref(dialog->registry->call, "nulling out the registry's call dialog field in unlink_all"); 02976 } 02977 dialog->registry = registry_unref(dialog->registry, "delete dialog->registry"); 02978 } 02979 if (dialog->stateid != -1) { 02980 ast_extension_state_del(dialog->stateid, cb_extensionstate); 02981 dialog->stateid = -1; 02982 } 02983 /* Remove link from peer to subscription of MWI */ 02984 if (dialog->relatedpeer && dialog->relatedpeer->mwipvt == dialog) { 02985 dialog->relatedpeer->mwipvt = dialog_unref(dialog->relatedpeer->mwipvt, "delete ->relatedpeer->mwipvt"); 02986 } 02987 if (dialog->relatedpeer && dialog->relatedpeer->call == dialog) { 02988 dialog->relatedpeer->call = dialog_unref(dialog->relatedpeer->call, "unset the relatedpeer->call field in tandem with relatedpeer field itself"); 02989 } 02990 02991 /* remove all current packets in this dialog */ 02992 while((cp = dialog->packets)) { 02993 dialog->packets = dialog->packets->next; 02994 AST_SCHED_DEL(sched, cp->retransid); 02995 dialog_unref(cp->owner, "remove all current packets in this dialog, and the pointer to the dialog too as part of __sip_destroy"); 02996 if (cp->data) { 02997 ast_free(cp->data); 02998 } 02999 ast_free(cp); 03000 } 03001 03002 AST_SCHED_DEL_UNREF(sched, dialog->waitid, dialog_unref(dialog, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr")); 03003 03004 AST_SCHED_DEL_UNREF(sched, dialog->initid, dialog_unref(dialog, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr")); 03005 03006 if (dialog->autokillid > -1) { 03007 AST_SCHED_DEL_UNREF(sched, dialog->autokillid, dialog_unref(dialog, "when you delete the autokillid sched, you should dec the refcount for the stored dialog ptr")); 03008 } 03009 03010 if (dialog->request_queue_sched_id > -1) { 03011 AST_SCHED_DEL_UNREF(sched, dialog->request_queue_sched_id, dialog_unref(dialog, "when you delete the request_queue_sched_id sched, you should dec the refcount for the stored dialog ptr")); 03012 } 03013 03014 AST_SCHED_DEL_UNREF(sched, dialog->provisional_keepalive_sched_id, dialog_unref(dialog, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 03015 03016 if (dialog->t38id > -1) { 03017 AST_SCHED_DEL_UNREF(sched, dialog->t38id, dialog_unref(dialog, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 03018 } 03019 03020 if (dialog->stimer) { 03021 stop_session_timer(dialog); 03022 } 03023 03024 dialog_unref(dialog, "Let's unbump the count in the unlink so the poor pvt can disappear if it is time"); 03025 }
| static int dialog_unlink_callback | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 17164 of file chan_sip.c.
References CMP_MATCH, and dialog_unlink_all().
Referenced by do_monitor().
17165 { 17166 struct sip_pvt *dialog = obj; 17167 17168 dialog_unlink_all(dialog); 17169 17170 return CMP_MATCH; 17171 }
| struct sip_pvt* dialog_unref_debug | ( | struct sip_pvt * | p, | |
| char * | tag, | |||
| char * | file, | |||
| int | line, | |||
| const char * | func | |||
| ) | [read] |
Definition at line 2236 of file chan_sip.c.
References __ao2_ref_debug(), and ao2_ref.
02237 { 02238 if (p) 02239 #ifdef REF_DEBUG 02240 __ao2_ref_debug(p, -1, tag, file, line, func); 02241 #else 02242 ao2_ref(p, -1); 02243 #endif 02244 return NULL; 02245 }
| static void disable_dsp_detect | ( | struct sip_pvt * | p | ) | [static] |
Definition at line 4271 of file chan_sip.c.
References ast_dsp_free().
Referenced by sip_dtmfmode(), sip_hangup(), and sip_setoption().
04272 { 04273 if (p->dsp) { 04274 ast_dsp_free(p->dsp); 04275 p->dsp = NULL; 04276 } 04277 }
| static void display_nat_warning | ( | const char * | cat, | |
| int | reason, | |||
| struct ast_flags * | flags | |||
| ) | [static] |
Definition at line 28078 of file chan_sip.c.
References AST_CLI_YESNO, ast_log(), ast_test_flag, CHANNEL_MODULE_LOAD, and LOG_WARNING.
Referenced by reload_config().
28078 { 28079 int global_nat, specific_nat; 28080 28081 if (reason == CHANNEL_MODULE_LOAD && (specific_nat = ast_test_flag(&flags[0], SIP_NAT_FORCE_RPORT)) != (global_nat = ast_test_flag(&global_flags[0], SIP_NAT_FORCE_RPORT))) { 28082 ast_log(LOG_WARNING, "!!! PLEASE NOTE: Setting 'nat' for a peer/user that differs from the global setting can make\n"); 28083 ast_log(LOG_WARNING, "!!! the name of that peer/user discoverable by an attacker. Replies for non-existent peers/users\n"); 28084 ast_log(LOG_WARNING, "!!! will be sent to a different port than replies for an existing peer/user. If at all possible,\n"); 28085 ast_log(LOG_WARNING, "!!! use the global 'nat' setting and do not set 'nat' per peer/user.\n"); 28086 ast_log(LOG_WARNING, "!!! (config category='%s' global force_rport='%s' peer/user force_rport='%s')\n", cat, AST_CLI_YESNO(global_nat), AST_CLI_YESNO(specific_nat)); 28087 } 28088 }
| static int do_magic_pickup | ( | struct ast_channel * | channel, | |
| const char * | extension, | |||
| const char * | context | |||
| ) | [static] |
Definition at line 22238 of file chan_sip.c.
References ast_debug, ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_str_alloca, ast_str_set(), LOG_ERROR, pbx_exec(), pbx_findapp(), sip_cfg, and str.
Referenced by handle_request_invite().
22239 { 22240 struct ast_str *str = ast_str_alloca(AST_MAX_EXTENSION + AST_MAX_CONTEXT + 2); 22241 struct ast_app *pickup = pbx_findapp("Pickup"); 22242 22243 if (!pickup) { 22244 ast_log(LOG_ERROR, "Unable to perform pickup: Application 'Pickup' not loaded (app_directed_pickup.so).\n"); 22245 return -1; 22246 } 22247 22248 ast_str_set(&str, 0, "%s@%s", extension, sip_cfg.notifycid == IGNORE_CONTEXT ? "PICKUPMARK" : context); 22249 22250 ast_debug(2, "About to call Pickup(%s)\n", str->str); 22251 22252 /* There is no point in capturing the return value since pickup_exec 22253 doesn't return anything meaningful unless the passed data is an empty 22254 string (which in our case it will not be) */ 22255 pbx_exec(channel, pickup, str->str); 22256 22257 return 0; 22258 }
| static void * do_monitor | ( | void * | data | ) | [static] |
The SIP monitoring thread.
Definition at line 25949 of file chan_sip.c.
References ao2_container_count(), ao2_t_callback, ast_debug, ast_io_add(), ast_io_change(), AST_IO_IN, ast_io_remove(), ast_io_wait(), ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_sched_runq(), ast_sched_wait(), ast_verb, dialog_needdestroy(), dialog_unlink_callback(), FALSE, LOG_WARNING, OBJ_MULTIPLE, OBJ_NODATA, OBJ_UNLINK, sip_do_reload(), and sipsock_read().
Referenced by restart_monitor().
25950 { 25951 int res; 25952 time_t t; 25953 int reloading; 25954 25955 /* Add an I/O event to our SIP UDP socket */ 25956 if (sipsock > -1) 25957 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 25958 25959 /* From here on out, we die whenever asked */ 25960 for(;;) { 25961 /* Check for a reload request */ 25962 ast_mutex_lock(&sip_reload_lock); 25963 reloading = sip_reloading; 25964 sip_reloading = FALSE; 25965 ast_mutex_unlock(&sip_reload_lock); 25966 if (reloading) { 25967 ast_verb(1, "Reloading SIP\n"); 25968 sip_do_reload(sip_reloadreason); 25969 25970 /* Change the I/O fd of our UDP socket */ 25971 if (sipsock > -1) { 25972 if (sipsock_read_id) 25973 sipsock_read_id = ast_io_change(io, sipsock_read_id, sipsock, NULL, 0, NULL); 25974 else 25975 sipsock_read_id = ast_io_add(io, sipsock, sipsock_read, AST_IO_IN, NULL); 25976 } else if (sipsock_read_id) { 25977 ast_io_remove(io, sipsock_read_id); 25978 sipsock_read_id = NULL; 25979 } 25980 } 25981 25982 /* Check for dialogs needing to be killed */ 25983 t = time(NULL); 25984 /* don't scan the dialogs list if it hasn't been a reasonable period 25985 of time since the last time we did it (when MWI is being sent, we can 25986 get back to this point every millisecond or less) 25987 */ 25988 /* 25989 * We cannot hold the dialogs container lock when we destroy a 25990 * dialog because of potential deadlocks. Instead we link the 25991 * doomed dialog into dialogs_to_destroy and then iterate over 25992 * that container destroying the dialogs. 25993 */ 25994 ao2_t_callback(dialogs, OBJ_NODATA | OBJ_MULTIPLE, dialog_needdestroy, &t, 25995 "callback to monitor dialog status"); 25996 if (ao2_container_count(dialogs_to_destroy)) { 25997 /* Now destroy the found dialogs that need to be destroyed. */ 25998 ao2_t_callback(dialogs_to_destroy, OBJ_UNLINK | OBJ_NODATA | OBJ_MULTIPLE, 25999 dialog_unlink_callback, NULL, "callback to dialog_unlink_all"); 26000 } 26001 26002 /* XXX TODO The scheduler usage in this module does not have sufficient 26003 * synchronization being done between running the scheduler and places 26004 * scheduling tasks. As it is written, any scheduled item may not run 26005 * any sooner than about 1 second, regardless of whether a sooner time 26006 * was asked for. */ 26007 26008 pthread_testcancel(); 26009 /* Wait for sched or io */ 26010 res = ast_sched_wait(sched); 26011 if ((res < 0) || (res > 1000)) 26012 res = 1000; 26013 res = ast_io_wait(io, res); 26014 if (res > 20) 26015 ast_debug(1, "chan_sip: ast_io_wait ran %d all at once\n", res); 26016 ast_mutex_lock(&monlock); 26017 res = ast_sched_runq(sched); 26018 if (res >= 20) 26019 ast_debug(1, "chan_sip: ast_sched_runq ran %d all at once\n", res); 26020 if (global_store_sip_cause && res >= 100) 26021 ast_log(LOG_WARNING, "scheduler delays detected, setting 'storesipcause' to 'no' in %s will improve performance\n", config); 26022 ast_mutex_unlock(&monlock); 26023 } 26024 26025 /* Never reached */ 26026 return NULL; 26027 }
| static int do_proxy_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum sip_auth_type | code, | |||
| int | sipmethod, | |||
| int | init | |||
| ) | [static] |
Add authentication on outbound SIP packet.
Definition at line 19229 of file chan_sip.c.
References ast_calloc, ast_debug, auth_headers(), reply_digest(), sip_methods, cfsip_methods::text, and transmit_invite().
Referenced by handle_response(), handle_response_invite(), handle_response_notify(), handle_response_publish(), handle_response_refer(), handle_response_subscribe(), and handle_response_update().
19230 { 19231 char *header, *respheader; 19232 char digest[1024]; 19233 19234 if (!p->options && !(p->options = ast_calloc(1, sizeof(*p->options)))) 19235 return -2; 19236 19237 p->authtries++; 19238 auth_headers(code, &header, &respheader); 19239 ast_debug(2, "Auth attempt %d on %s\n", p->authtries, sip_methods[sipmethod].text); 19240 memset(digest, 0, sizeof(digest)); 19241 if (reply_digest(p, req, header, sipmethod, digest, sizeof(digest) )) { 19242 /* No way to authenticate */ 19243 return -1; 19244 } 19245 /* Now we have a reply digest */ 19246 p->options->auth = digest; 19247 p->options->authheader = respheader; 19248 return transmit_invite(p, sipmethod, sipmethod == SIP_INVITE, init, NULL); 19249 }
| static int do_register_auth | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum sip_auth_type | code | |||
| ) | [static] |
Authenticate for outbound registration.
Definition at line 19205 of file chan_sip.c.
References append_history, ast_verbose, auth_headers(), reply_digest(), sip_debug_test_pvt(), and transmit_register().
Referenced by handle_response_register().
19206 { 19207 char *header, *respheader; 19208 char digest[1024]; 19209 19210 p->authtries++; 19211 auth_headers(code, &header, &respheader); 19212 memset(digest, 0, sizeof(digest)); 19213 if (reply_digest(p, req, header, SIP_REGISTER, digest, sizeof(digest))) { 19214 /* There's nothing to use for authentication */ 19215 /* No digest challenge in request */ 19216 if (sip_debug_test_pvt(p) && p->registry) 19217 ast_verbose("No authentication challenge, sending blank registration to domain/host name %s\n", p->registry->hostname); 19218 /* No old challenge */ 19219 return -1; 19220 } 19221 if (p->do_history) 19222 append_history(p, "RegistryAuth", "Try: %d", p->authtries); 19223 if (sip_debug_test_pvt(p) && p->registry) 19224 ast_verbose("Responding to challenge, registration to domain/host name %s\n", p->registry->hostname); 19225 return transmit_register(p->registry, SIP_REGISTER, digest, respheader); 19226 }
| static void do_setnat | ( | struct sip_pvt * | p | ) | [static] |
Set nat mode on the various data sockets.
Definition at line 5084 of file chan_sip.c.
References ast_debug, ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_NAT, ast_test_flag, and ast_udptl_setnat().
Referenced by check_peer_ok(), dialog_initialize_rtp(), sip_alloc(), and transmit_response_using_temp().
05085 { 05086 const char *mode; 05087 int natflags; 05088 05089 natflags = ast_test_flag(&p->flags[1], SIP_PAGE2_SYMMETRICRTP); 05090 mode = natflags ? "On" : "Off"; 05091 05092 if (p->rtp) { 05093 ast_debug(1, "Setting NAT on RTP to %s\n", mode); 05094 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_NAT, natflags); 05095 } 05096 if (p->vrtp) { 05097 ast_debug(1, "Setting NAT on VRTP to %s\n", mode); 05098 ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_NAT, natflags); 05099 } 05100 if (p->udptl) { 05101 ast_debug(1, "Setting NAT on UDPTL to %s\n", mode); 05102 ast_udptl_setnat(p->udptl, natflags); 05103 } 05104 if (p->trtp) { 05105 ast_debug(1, "Setting NAT on TRTP to %s\n", mode); 05106 ast_rtp_instance_set_prop(p->trtp, AST_RTP_PROPERTY_NAT, natflags); 05107 } 05108 }
| static const char * domain_mode_to_text | ( | const enum domain_mode | mode | ) | [static] |
Print domain mode to cli.
Definition at line 17333 of file chan_sip.c.
Referenced by sip_show_domains().
| static const char * dtmfmode2str | ( | int | mode | ) | [static] |
Convert DTMF mode to printable string.
Definition at line 17024 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), sip_show_channel(), and sip_show_settings().
| static void enable_dsp_detect | ( | struct sip_pvt * | p | ) | [static] |
Definition at line 4237 of file chan_sip.c.
References ast_dsp_new(), ast_dsp_set_digitmode(), ast_dsp_set_features(), AST_RTP_DTMF_MODE_INBAND, ast_rtp_instance_dtmf_mode_set(), ast_test_flag, DSP_DIGITMODE_DTMF, DSP_DIGITMODE_RELAXDTMF, DSP_FEATURE_DIGIT_DETECT, and DSP_FEATURE_FAX_DETECT.
Referenced by sip_dtmfmode(), sip_new(), and sip_setoption().
04238 { 04239 int features = 0; 04240 04241 if (p->dsp) { 04242 return; 04243 } 04244 04245 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || 04246 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 04247 if (p->rtp) { 04248 ast_rtp_instance_dtmf_mode_set(p->rtp, AST_RTP_DTMF_MODE_INBAND); 04249 } 04250 features |= DSP_FEATURE_DIGIT_DETECT; 04251 } 04252 04253 if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) { 04254 features |= DSP_FEATURE_FAX_DETECT; 04255 } 04256 04257 if (!features) { 04258 return; 04259 } 04260 04261 if (!(p->dsp = ast_dsp_new())) { 04262 return; 04263 } 04264 04265 ast_dsp_set_features(p->dsp, features); 04266 if (global_relaxdtmf) { 04267 ast_dsp_set_digitmode(p->dsp, DSP_DIGITMODE_DTMF | DSP_DIGITMODE_RELAXDTMF); 04268 } 04269 }
| static int esc_cmp_fn | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 991 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by initialize_escs().
| static void esc_entry_destructor | ( | void * | obj | ) | [static] |
Definition at line 977 of file chan_sip.c.
References AST_SCHED_DEL.
Referenced by create_esc_entry().
00978 { 00979 struct sip_esc_entry *esc_entry = obj; 00980 if (esc_entry->sched_id > -1) { 00981 AST_SCHED_DEL(sched, esc_entry->sched_id); 00982 } 00983 }
| static int esc_hash_fn | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 985 of file chan_sip.c.
References ast_str_hash().
Referenced by initialize_escs().
00986 { 00987 const struct sip_esc_entry *entry = obj; 00988 return ast_str_hash(entry->entity_tag); 00989 }
| static int expire_register | ( | const void * | data | ) | [static] |
Expire registration of SIP peer.
Definition at line 13777 of file chan_sip.c.
References ao2_ref, ao2_t_unlink, ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_sockaddr_isnull(), ast_test_flag, destroy_association(), EVENT_FLAG_SYSTEM, FALSE, manager_event, register_peer_exten(), set_socket_transport(), unlink_peer_from_tables(), and unref_peer().
Referenced by parse_register_contact(), realtime_peer(), reg_source_db(), sip_show_sched(), and sip_unregister().
13778 { 13779 struct sip_peer *peer = (struct sip_peer *)data; 13780 13781 if (!peer) { /* Hmmm. We have no peer. Weird. */ 13782 return 0; 13783 } 13784 13785 peer->expire = -1; 13786 peer->portinuri = 0; 13787 13788 destroy_association(peer); /* remove registration data from storage */ 13789 set_socket_transport(&peer->socket, peer->default_outbound_transport); 13790 13791 if (peer->socket.tcptls_session) { 13792 ao2_ref(peer->socket.tcptls_session, -1); 13793 peer->socket.tcptls_session = NULL; 13794 } 13795 13796 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unregistered\r\nCause: Expired\r\n", peer->name); 13797 register_peer_exten(peer, FALSE); /* Remove regexten */ 13798 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 13799 13800 /* Do we need to release this peer from memory? 13801 Only for realtime peers and autocreated peers 13802 */ 13803 if (peer->is_realtime) { 13804 ast_debug(3, "-REALTIME- peer expired registration. Name: %s. Realtime peer objects now %d\n", peer->name, rpeerobjs); 13805 } 13806 13807 if (peer->selfdestruct || 13808 ast_test_flag(&peer->flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 13809 unlink_peer_from_tables(peer); 13810 } else if (!ast_sockaddr_isnull(&peer->addr)) { 13811 /* If we aren't self-destructing a temp_peer, we still need to unlink the peer 13812 * from the peers_by_ip table, otherwise we end up with multiple copies hanging 13813 * around each time a registration expires and the peer re-registers. */ 13814 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table"); 13815 } 13816 13817 /* Only clear the addr after we check for destruction. The addr must remain 13818 * in order to unlink from the peers_by_ip container correctly */ 13819 memset(&peer->addr, 0, sizeof(peer->addr)); 13820 13821 unref_peer(peer, "removing peer ref for expire_register"); 13822 13823 return 0; 13824 }
| static void extract_host_from_hostport | ( | char ** | hostport | ) | [static] |
Terminate a host:port at the ':'.
| hostport | The address of the hostport string |
Definition at line 14789 of file chan_sip.c.
References ast_sockaddr_split_hostport(), and PARSE_PORT_IGNORE.
Referenced by check_user_full(), get_destination(), and register_verify().
14790 { 14791 char *dont_care; 14792 ast_sockaddr_split_hostport(*hostport, hostport, &dont_care, PARSE_PORT_IGNORE); 14793 }
| static void extract_uri | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Check Contact: URI of SIP message.
Definition at line 11940 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, ast_strlen_zero(), get_header(), get_in_brackets(), and remove_uri_parameters().
Referenced by handle_incoming(), and handle_request_invite().
11941 { 11942 char stripped[SIPBUFSIZE]; 11943 char *c; 11944 11945 ast_copy_string(stripped, get_header(req, "Contact"), sizeof(stripped)); 11946 c = get_in_brackets(stripped); 11947 /* Cut the URI at the at sign after the @, not in the username part */ 11948 c = remove_uri_parameters(c); 11949 if (!ast_strlen_zero(c)) { 11950 ast_string_field_set(p, uri, c); 11951 } 11952 11953 }
| static const char* faxec2str | ( | int | faxec | ) | [static] |
Definition at line 17497 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), and sip_show_settings().
17498 { 17499 return map_x_s(faxecmodes, faxec, "Unknown"); 17500 }
| static int finalize_content | ( | struct sip_request * | req | ) | [static] |
Add 'Content-Length' header and content to SIP message.
Definition at line 9925 of file chan_sip.c.
References add_header(), ast_log(), ast_str_append(), ast_str_buffer(), ast_str_strlen(), and LOG_WARNING.
Referenced by send_request(), and send_response().
09926 { 09927 char clen[10]; 09928 09929 if (req->lines) { 09930 ast_log(LOG_WARNING, "finalize_content() called on a message that has already been finalized\n"); 09931 return -1; 09932 } 09933 09934 snprintf(clen, sizeof(clen), "%zd", ast_str_strlen(req->content)); 09935 add_header(req, "Content-Length", clen); 09936 09937 if (ast_str_strlen(req->content)) { 09938 ast_str_append(&req->data, 0, "\r\n%s", ast_str_buffer(req->content)); 09939 } 09940 req->lines = ast_str_strlen(req->content) ? 1 : 0; 09941 return 0; 09942 }
| static const char * find_alias | ( | const char * | name, | |
| const char * | _default | |||
| ) | [static] |
Find compressed SIP alias.
Structure for conversion between compressed SIP and "normal" SIP
Definition at line 7315 of file chan_sip.c.
References aliases, and ARRAY_LEN.
Referenced by __get_header(), and add_header().
07316 { 07317 /*! \brief Structure for conversion between compressed SIP and "normal" SIP */ 07318 static const struct cfalias { 07319 char * const fullname; 07320 char * const shortname; 07321 } aliases[] = { 07322 { "Content-Type", "c" }, 07323 { "Content-Encoding", "e" }, 07324 { "From", "f" }, 07325 { "Call-ID", "i" }, 07326 { "Contact", "m" }, 07327 { "Content-Length", "l" }, 07328 { "Subject", "s" }, 07329 { "To", "t" }, 07330 { "Supported", "k" }, 07331 { "Refer-To", "r" }, 07332 { "Referred-By", "b" }, 07333 { "Allow-Events", "u" }, 07334 { "Event", "o" }, 07335 { "Via", "v" }, 07336 { "Accept-Contact", "a" }, 07337 { "Reject-Contact", "j" }, 07338 { "Request-Disposition", "d" }, 07339 { "Session-Expires", "x" }, 07340 { "Identity", "y" }, 07341 { "Identity-Info", "n" }, 07342 }; 07343 int x; 07344 07345 for (x = 0; x < ARRAY_LEN(aliases); x++) { 07346 if (!strcasecmp(aliases[x].fullname, name)) 07347 return aliases[x].shortname; 07348 } 07349 07350 return _default; 07351 }
| static int find_by_callid_helper | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1686 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, and ast_cc_agent::private_data.
Referenced by find_sip_cc_agent_by_original_callid().
01687 { 01688 struct ast_cc_agent *agent = obj; 01689 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01690 struct sip_pvt *call_pvt = arg; 01691 01692 return !strcmp(agent_pvt->original_callid, call_pvt->callid) ? CMP_MATCH | CMP_STOP : 0; 01693 }
| static int find_by_name | ( | void * | obj, | |
| void * | arg, | |||
| void * | data, | |||
| int | flags | |||
| ) | [static] |
Definition at line 4995 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, and match().
Referenced by find_peer().
04996 { 04997 struct sip_peer *search = obj, *match = arg; 04998 int *which_objects = data; 04999 05000 /* Usernames in SIP uri's are case sensitive. Domains are not */ 05001 if (strcmp(search->name, match->name)) { 05002 return 0; 05003 } 05004 05005 switch (*which_objects) { 05006 case FINDUSERS: 05007 if (!(search->type & SIP_TYPE_USER)) { 05008 return 0; 05009 } 05010 break; 05011 case FINDPEERS: 05012 if (!(search->type & SIP_TYPE_PEER)) { 05013 return 0; 05014 } 05015 break; 05016 case FINDALLDEVICES: 05017 break; 05018 } 05019 05020 return CMP_MATCH | CMP_STOP; 05021 }
| static int find_by_notify_uri_helper | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1656 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, ast_cc_agent::private_data, and sip_uri_cmp().
Referenced by find_sip_cc_agent_by_notify_uri().
01657 { 01658 struct ast_cc_agent *agent = obj; 01659 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01660 const char *uri = arg; 01661 01662 return !sip_uri_cmp(agent_pvt->notify_uri, uri) ? CMP_MATCH | CMP_STOP : 0; 01663 }
| static int find_by_subscribe_uri_helper | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1671 of file chan_sip.c.
References CMP_MATCH, CMP_STOP, ast_cc_agent::private_data, and sip_uri_cmp().
Referenced by find_sip_cc_agent_by_subscribe_uri().
01672 { 01673 struct ast_cc_agent *agent = obj; 01674 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01675 const char *uri = arg; 01676 01677 return !sip_uri_cmp(agent_pvt->subscribe_uri, uri) ? CMP_MATCH | CMP_STOP : 0; 01678 }
| static struct sip_pvt * find_call | ( | struct sip_request * | req, | |
| struct ast_sockaddr * | addr, | |||
| const int | intended_method | |||
| ) | [static, read] |
find or create a dialog structure for an incoming SIP message. Connect incoming SIP message to current dialog or create new dialog structure Returns a reference to the sip_pvt object, remember to give it back once done. Called by handle_request_do
Definition at line 8080 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_next, ao2_t_callback, ao2_t_find, args, ast_debug, ast_strlen_zero(), match_req_args::authentication_present, match_req_args::callid, dialog_find_multiple(), free_via(), match_req_args::fromtag, get_header(), gettag(), match_req_to_dialog(), match_req_args::method, OBJ_MULTIPLE, OBJ_POINTER, parse_via(), match_req_args::ruri, match_req_args::seqno, sip_alloc(), sip_cfg, sip_methods, SIP_REQ_LOOP_DETECTED, SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, cfsip_methods::text, match_req_args::totag, transmit_response_using_temp(), match_req_args::viabranch, and match_req_args::viasentby.
Referenced by handle_request_do().
08081 { 08082 char totag[128]; 08083 char fromtag[128]; 08084 const char *callid = get_header(req, "Call-ID"); 08085 const char *from = get_header(req, "From"); 08086 const char *to = get_header(req, "To"); 08087 const char *cseq = get_header(req, "Cseq"); 08088 struct sip_pvt *sip_pvt_ptr; 08089 uint32_t seqno; 08090 /* Call-ID, to, from and Cseq are required by RFC 3261. (Max-forwards and via too - ignored now) */ 08091 /* get_header always returns non-NULL so we must use ast_strlen_zero() */ 08092 if (ast_strlen_zero(callid) || ast_strlen_zero(to) || 08093 ast_strlen_zero(from) || ast_strlen_zero(cseq) || 08094 (sscanf(cseq, "%30u", &seqno) != 1)) { 08095 08096 /* RFC 3261 section 24.4.1. Send a 400 Bad Request if the request is malformed. */ 08097 if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) { 08098 transmit_response_using_temp(callid, addr, 1, intended_method, 08099 req, "400 Bad Request"); 08100 } 08101 return NULL; /* Invalid packet */ 08102 } 08103 08104 if (sip_cfg.pedanticsipchecking) { 08105 /* In principle Call-ID's uniquely identify a call, but with a forking SIP proxy 08106 we need more to identify a branch - so we have to check branch, from 08107 and to tags to identify a call leg. 08108 For Asterisk to behave correctly, you need to turn on pedanticsipchecking 08109 in sip.conf 08110 */ 08111 if (gettag(req, "To", totag, sizeof(totag))) 08112 req->has_to_tag = 1; /* Used in handle_request/response */ 08113 gettag(req, "From", fromtag, sizeof(fromtag)); 08114 08115 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); 08116 08117 /* All messages must always have From: tag */ 08118 if (ast_strlen_zero(fromtag)) { 08119 ast_debug(5, "%s request has no from tag, dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from ); 08120 return NULL; 08121 } 08122 /* reject requests that must always have a To: tag */ 08123 if (ast_strlen_zero(totag) && (req->method == SIP_ACK || req->method == SIP_BYE || req->method == SIP_INFO )) { 08124 ast_debug(5, "%s must have a to tag. dropping callid: %s from: %s\n", sip_methods[req->method].text , callid, from ); 08125 return NULL; 08126 } 08127 } 08128 08129 if (!sip_cfg.pedanticsipchecking) { 08130 struct sip_pvt tmp_dialog = { 08131 .callid = callid, 08132 }; 08133 sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find in dialogs"); 08134 if (sip_pvt_ptr) { /* well, if we don't find it-- what IS in there? */ 08135 /* Found the call */ 08136 return sip_pvt_ptr; 08137 } 08138 } else { /* in pedantic mode! -- do the fancy search */ 08139 struct sip_pvt tmp_dialog = { 08140 .callid = callid, 08141 }; 08142 struct match_req_args args = { 0, }; 08143 int found; 08144 struct ao2_iterator *iterator = ao2_t_callback(dialogs, 08145 OBJ_POINTER | OBJ_MULTIPLE, 08146 dialog_find_multiple, 08147 &tmp_dialog, 08148 "pedantic ao2_find in dialogs"); 08149 struct sip_via *via = NULL; 08150 08151 args.method = req->method; 08152 args.callid = NULL; /* we already matched this. */ 08153 args.totag = totag; 08154 args.fromtag = fromtag; 08155 args.seqno = seqno; 08156 08157 /* If this is a Request, set the Via and Authorization header arguments */ 08158 if (req->method != SIP_RESPONSE) { 08159 args.ruri = REQ_OFFSET_TO_STR(req, rlPart2); 08160 via = parse_via(get_header(req, "Via")); 08161 if (via) { 08162 args.viasentby = via->sent_by; 08163 args.viabranch = via->branch; 08164 } 08165 if (!ast_strlen_zero(get_header(req, "Authorization")) || 08166 !ast_strlen_zero(get_header(req, "Proxy-Authorization"))) { 08167 args.authentication_present = 1; 08168 } 08169 } 08170 08171 /* Iterate a list of dialogs already matched by Call-id */ 08172 while (iterator && (sip_pvt_ptr = ao2_iterator_next(iterator))) { 08173 found = match_req_to_dialog(sip_pvt_ptr, &args); 08174 08175 switch (found) { 08176 case SIP_REQ_MATCH: 08177 ao2_iterator_destroy(iterator); 08178 free_via(via); 08179 return sip_pvt_ptr; /* return pvt with ref */ 08180 case SIP_REQ_LOOP_DETECTED: 08181 /* This is likely a forked Request that somehow resulted in us receiving multiple parts of the fork. 08182 * RFC 3261 section 8.2.2.2, Indicate that we want to merge requests by sending a 482 response. */ 08183 transmit_response_using_temp(callid, addr, 1, intended_method, req, "482 (Loop Detected)"); 08184 dialog_unref(sip_pvt_ptr, "pvt did not match incoming SIP msg, unref from search."); 08185 ao2_iterator_destroy(iterator); 08186 free_via(via); 08187 return NULL; 08188 case SIP_REQ_NOT_MATCH: 08189 default: 08190 dialog_unref(sip_pvt_ptr, "pvt did not match incoming SIP msg, unref from search"); 08191 } 08192 } 08193 if (iterator) { 08194 ao2_iterator_destroy(iterator); 08195 } 08196 08197 free_via(via); 08198 } /* end of pedantic mode Request/Reponse to Dialog matching */ 08199 08200 /* See if the method is capable of creating a dialog */ 08201 if (sip_methods[intended_method].can_create == CAN_CREATE_DIALOG) { 08202 struct sip_pvt *p = NULL; 08203 08204 if (intended_method == SIP_REFER) { 08205 /* We do support REFER, but not outside of a dialog yet */ 08206 transmit_response_using_temp(callid, addr, 1, intended_method, req, "603 Declined (no dialog)"); 08207 08208 /* Ok, time to create a new SIP dialog object, a pvt */ 08209 } else if (!(p = sip_alloc(callid, addr, 1, intended_method, req))) { 08210 /* We have a memory or file/socket error (can't allocate RTP sockets or something) so we're not 08211 getting a dialog from sip_alloc. 08212 08213 Without a dialog we can't retransmit and handle ACKs and all that, but at least 08214 send an error message. 08215 08216 Sorry, we apologize for the inconvienience 08217 */ 08218 transmit_response_using_temp(callid, addr, 1, intended_method, req, "500 Server internal error"); 08219 ast_debug(4, "Failed allocating SIP dialog, sending 500 Server internal error and giving up\n"); 08220 } 08221 return p; /* can be NULL */ 08222 } else if( sip_methods[intended_method].can_create == CAN_CREATE_DIALOG_UNSUPPORTED_METHOD) { 08223 /* A method we do not support, let's take it on the volley */ 08224 transmit_response_using_temp(callid, addr, 1, intended_method, req, "501 Method Not Implemented"); 08225 ast_debug(2, "Got a request with unsupported SIP method.\n"); 08226 } else if (intended_method != SIP_RESPONSE && intended_method != SIP_ACK) { 08227 /* This is a request outside of a dialog that we don't know about */ 08228 transmit_response_using_temp(callid, addr, 1, intended_method, req, "481 Call leg/transaction does not exist"); 08229 ast_debug(2, "That's odd... Got a request in unknown dialog. Callid %s\n", callid ? callid : "<unknown>"); 08230 } 08231 /* We do not respond to responses for dialogs that we don't know about, we just drop 08232 the session quickly */ 08233 if (intended_method == SIP_RESPONSE) 08234 ast_debug(2, "That's odd... Got a response on a call we don't know about. Callid %s\n", callid ? callid : "<unknown>"); 08235 08236 return NULL; 08237 }
| static int find_calling_channel | ( | void * | obj, | |
| void * | arg, | |||
| void * | data, | |||
| int | flags | |||
| ) | [static] |
Find the channel that is causing the RINGING update.
Definition at line 12561 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, CMP_MATCH, CMP_STOP, ast_channel::context, ast_channel::exten, ast_channel::macroexten, ast_channel::pbx, and sip_cfg.
Referenced by state_notify_build_xml().
12562 { 12563 struct ast_channel *c = obj; 12564 struct sip_pvt *p = data; 12565 int res; 12566 12567 ast_channel_lock(c); 12568 12569 res = (c->pbx && 12570 (!strcasecmp(c->macroexten, p->exten) || !strcasecmp(c->exten, p->exten)) && 12571 (sip_cfg.notifycid == IGNORE_CONTEXT || !strcasecmp(c->context, p->context))); 12572 12573 ast_channel_unlock(c); 12574 12575 return res ? CMP_MATCH | CMP_STOP : 0; 12576 }
| 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.
Definition at line 4412 of file chan_sip.c.
Referenced by get_comma(), get_in_brackets_full(), and parse_moved_contact().
| static struct sip_peer * find_peer | ( | const char * | peer, | |
| struct ast_sockaddr * | addr, | |||
| int | realtime, | |||
| int | which_objects, | |||
| int | devstate_only, | |||
| int | transport | |||
| ) | [static, read] |
Locate device by name or ip address.
| peer,sin,realtime,devstate_only,transport | ||
| which_objects | Define which objects should be matched when doing a lookup by name. Valid options are FINDUSERS, FINDPEERS, or FINDALLDEVICES. Note that this option is not used at all when doing a lookup by IP. |
This is used on find matching device on name or ip/port. If the device was declared as type=peer, we don't match on peer name on incoming INVITEs.
Definition at line 5036 of file chan_sip.c.
References ao2_t_callback_data, ao2_t_find, ast_copy_string(), ast_set_flag, ast_sockaddr_copy(), find_by_name(), OBJ_POINTER, realtime_peer(), and unref_peer().
Referenced by _sip_qualify_peer(), _sip_show_peer(), check_peer_ok(), create_addr(), function_sippeer(), handle_request_notify(), register_verify(), sip_devicestate(), sip_do_debug_peer(), sip_show_user(), sip_unregister(), and transmit_register().
05037 { 05038 struct sip_peer *p = NULL; 05039 struct sip_peer tmp_peer; 05040 05041 if (peer) { 05042 ast_copy_string(tmp_peer.name, peer, sizeof(tmp_peer.name)); 05043 p = ao2_t_callback_data(peers, OBJ_POINTER, find_by_name, &tmp_peer, &which_objects, "ao2_find in peers table"); 05044 } else if (addr) { /* search by addr? */ 05045 ast_sockaddr_copy(&tmp_peer.addr, addr); 05046 tmp_peer.flags[0].flags = 0; 05047 tmp_peer.transports = transport; 05048 p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ 05049 if (!p) { 05050 ast_set_flag(&tmp_peer.flags[0], SIP_INSECURE_PORT); 05051 p = ao2_t_find(peers_by_ip, &tmp_peer, OBJ_POINTER, "ao2_find in peers_by_ip table 2"); /* WAS: p = ASTOBJ_CONTAINER_FIND_FULL(&peerl, sin, name, sip_addr_hashfunc, 1, sip_addrcmp); */ 05052 if (p) { 05053 return p; 05054 } 05055 } 05056 } 05057 05058 if (!p && (realtime || devstate_only)) { 05059 p = realtime_peer(peer, addr, devstate_only, which_objects); 05060 if (p) { 05061 switch (which_objects) { 05062 case FINDUSERS: 05063 if (!(p->type & SIP_TYPE_USER)) { 05064 unref_peer(p, "Wrong type of realtime SIP endpoint"); 05065 return NULL; 05066 } 05067 break; 05068 case FINDPEERS: 05069 if (!(p->type & SIP_TYPE_PEER)) { 05070 unref_peer(p, "Wrong type of realtime SIP endpoint"); 05071 return NULL; 05072 } 05073 break; 05074 case FINDALLDEVICES: 05075 break; 05076 } 05077 } 05078 } 05079 05080 return p; 05081 }
| static struct sip_auth * find_realm_authentication | ( | struct sip_auth_container * | credentials, | |
| const char * | realm | |||
| ) | [static, read] |
Definition at line 27208 of file chan_sip.c.
References AST_LIST_TRAVERSE.
Referenced by build_reply_digest().
27209 { 27210 struct sip_auth *auth; 27211 27212 if (credentials) { 27213 AST_LIST_TRAVERSE(&credentials->list, auth, node) { 27214 if (!strcasecmp(auth->realm, realm)) { 27215 break; 27216 } 27217 } 27218 } else { 27219 auth = NULL; 27220 } 27221 27222 return auth; 27223 }
| static int find_sdp | ( | struct sip_request * | req | ) | [static] |
Determine whether a SIP message contains an SDP in its body.
| req | the SIP request to process |
Also updates req->sdp_start and req->sdp_count to indicate where the SDP lives in the message body.
Definition at line 8589 of file chan_sip.c.
References ast_log(), ast_strdupa, ast_strlen_zero(), FALSE, get_header(), LOG_WARNING, and TRUE.
Referenced by handle_incoming(), handle_request_invite(), handle_response(), and handle_response_invite().
08590 { 08591 const char *content_type; 08592 const char *content_length; 08593 const char *search; 08594 char *boundary; 08595 unsigned int x; 08596 int boundaryisquoted = FALSE; 08597 int found_application_sdp = FALSE; 08598 int found_end_of_headers = FALSE; 08599 08600 content_length = get_header(req, "Content-Length"); 08601 08602 if (!ast_strlen_zero(content_length)) { 08603 if (sscanf(content_length, "%30u", &x) != 1) { 08604 ast_log(LOG_WARNING, "Invalid Content-Length: %s\n", content_length); 08605 return 0; 08606 } 08607 08608 /* Content-Length of zero means there can't possibly be an 08609 SDP here, even if the Content-Type says there is */ 08610 if (x == 0) 08611 return 0; 08612 } 08613 08614 content_type = get_header(req, "Content-Type"); 08615 08616 /* if the body contains only SDP, this is easy */ 08617 if (!strncasecmp(content_type, "application/sdp", 15)) { 08618 req->sdp_start = 0; 08619 req->sdp_count = req->lines; 08620 return req->lines ? 1 : 0; 08621 } 08622 08623 /* if it's not multipart/mixed, there cannot be an SDP */ 08624 if (strncasecmp(content_type, "multipart/mixed", 15)) 08625 return 0; 08626 08627 /* if there is no boundary marker, it's invalid */ 08628 if ((search = strcasestr(content_type, ";boundary="))) 08629 search += 10; 08630 else if ((search = strcasestr(content_type, "; boundary="))) 08631 search += 11; 08632 else 08633 return 0; 08634 08635 if (ast_strlen_zero(search)) 08636 return 0; 08637 08638 /* If the boundary is quoted with ", remove quote */ 08639 if (*search == '\"') { 08640 search++; 08641 boundaryisquoted = TRUE; 08642 } 08643 08644 /* make a duplicate of the string, with two extra characters 08645 at the beginning */ 08646 boundary = ast_strdupa(search - 2); 08647 boundary[0] = boundary[1] = '-'; 08648 /* Remove final quote */ 08649 if (boundaryisquoted) 08650 boundary[strlen(boundary) - 1] = '\0'; 08651 08652 /* search for the boundary marker, the empty line delimiting headers from 08653 sdp part and the end boundry if it exists */ 08654 08655 for (x = 0; x < (req->lines); x++) { 08656 const char *line = REQ_OFFSET_TO_STR(req, line[x]); 08657 if (!strncasecmp(line, boundary, strlen(boundary))){ 08658 if (found_application_sdp && found_end_of_headers) { 08659 req->sdp_count = (x - 1) - req->sdp_start; 08660 return 1; 08661 } 08662 found_application_sdp = FALSE; 08663 } 08664 if (!strcasecmp(line, "Content-Type: application/sdp")) 08665 found_application_sdp = TRUE; 08666 08667 if (ast_strlen_zero(line)) { 08668 if (found_application_sdp && !found_end_of_headers){ 08669 req->sdp_start = x; 08670 found_end_of_headers = TRUE; 08671 } 08672 } 08673 } 08674 if (found_application_sdp && found_end_of_headers) { 08675 req->sdp_count = x - req->sdp_start; 08676 return TRUE; 08677 } 08678 return FALSE; 08679 }
| static struct ast_cc_agent* find_sip_cc_agent_by_notify_uri | ( | const char *const | uri | ) | [static, read] |
Definition at line 1665 of file chan_sip.c.
References ast_cc_agent_callback(), and find_by_notify_uri_helper().
Referenced by get_destination().
01666 { 01667 struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_notify_uri_helper, (char *)uri, "SIP"); 01668 return agent; 01669 }
| static struct ast_cc_agent* find_sip_cc_agent_by_original_callid | ( | struct sip_pvt * | pvt | ) | [static, read] |
Definition at line 1695 of file chan_sip.c.
References ast_cc_agent_callback(), and find_by_callid_helper().
Referenced by add_cc_call_info_to_response().
01696 { 01697 struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_callid_helper, pvt, "SIP"); 01698 return agent; 01699 }
| static struct ast_cc_agent* find_sip_cc_agent_by_subscribe_uri | ( | const char *const | uri | ) | [static, read] |
Definition at line 1680 of file chan_sip.c.
References ast_cc_agent_callback(), and find_by_subscribe_uri_helper().
Referenced by handle_cc_subscribe().
01681 { 01682 struct ast_cc_agent *agent = ast_cc_agent_callback(0, find_by_subscribe_uri_helper, (char *)uri, "SIP"); 01683 return agent; 01684 }
| static int find_sip_method | ( | const char * | msg | ) | [static] |
find_sip_method: Find SIP method from header
Definition at line 3167 of file chan_sip.c.
References ARRAY_LEN, ast_strlen_zero(), cfsip_methods::id, method_match(), and sip_methods.
Referenced by __sip_pretend_ack(), handle_request_do(), handle_response(), mark_parsed_methods(), and sip_hangup().
03168 { 03169 int i, res = 0; 03170 03171 if (ast_strlen_zero(msg)) { 03172 return 0; 03173 } 03174 for (i = 1; i < ARRAY_LEN(sip_methods) && !res; i++) { 03175 if (method_match(i, msg)) { 03176 res = sip_methods[i].id; 03177 } 03178 } 03179 return res; 03180 }
| static int find_sip_monitor_instance_by_subscription_pvt | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1893 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by handle_cc_notify(), and handle_response_subscribe().
| static int find_sip_monitor_instance_by_suspension_entry | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1899 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by cc_handle_publish_error().
| static struct epa_static_data* find_static_data | ( | const char *const | event_package | ) | [static, read] |
Definition at line 905 of file chan_sip.c.
References AST_LIST_LOCK, AST_LIST_TRAVERSE, and AST_LIST_UNLOCK.
Referenced by create_epa_entry().
00906 { 00907 const struct epa_backend *backend = NULL; 00908 00909 AST_LIST_LOCK(&epa_static_data_list); 00910 AST_LIST_TRAVERSE(&epa_static_data_list, backend, next) { 00911 if (!strcmp(backend->static_data->name, event_package)) { 00912 break; 00913 } 00914 } 00915 AST_LIST_UNLOCK(&epa_static_data_list); 00916 return backend ? backend->static_data : NULL; 00917 }
| static struct cfsubscription_types * find_subscription_type | ( | enum subscriptiontype | subtype | ) | [static, read] |
Find subscription type in array.
Definition at line 18390 of file chan_sip.c.
References ARRAY_LEN, subscription_types, and type.
Referenced by transmit_state_notify().
18391 { 18392 int i; 18393 18394 for (i = 1; i < ARRAY_LEN(subscription_types); i++) { 18395 if (subscription_types[i].type == subtype) { 18396 return &subscription_types[i]; 18397 } 18398 } 18399 return &subscription_types[0]; 18400 }
| static void free_old_route | ( | struct sip_route * | route | ) | [static] |
Remove route from route list.
Definition at line 14232 of file chan_sip.c.
References ast_free.
Referenced by __sip_destroy(), and build_route().
14233 { 14234 struct sip_route *next; 14235 14236 while (route) { 14237 next = route->next; 14238 ast_free(route); 14239 route = next; 14240 } 14241 }
| static int func_check_sipdomain | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Dial plan function to check if domain is local.
Definition at line 19495 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), check_sip_domain(), and LOG_WARNING.
19496 { 19497 if (ast_strlen_zero(data)) { 19498 ast_log(LOG_WARNING, "CHECKSIPDOMAIN requires an argument - A domain name\n"); 19499 return -1; 19500 } 19501 if (check_sip_domain(data, NULL, 0)) 19502 ast_copy_string(buf, data, len); 19503 else 19504 buf[0] = '\0'; 19505 return 0; 19506 }
| static int func_header_read | ( | struct ast_channel * | chan, | |
| const char * | function, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
Read SIP header (dialplan function).
Definition at line 19436 of file chan_sip.c.
References __get_header(), args, AST_APP_ARG, ast_channel_lock, ast_channel_unlock, ast_copy_string(), AST_DECLARE_APP_ARGS, ast_log(), AST_STANDARD_APP_ARGS, ast_strlen_zero(), LOG_WARNING, ast_channel::tech, and ast_channel::tech_pvt.
19437 { 19438 struct sip_pvt *p; 19439 const char *content = NULL; 19440 AST_DECLARE_APP_ARGS(args, 19441 AST_APP_ARG(header); 19442 AST_APP_ARG(number); 19443 ); 19444 int i, number, start = 0; 19445 19446 if (ast_strlen_zero(data)) { 19447 ast_log(LOG_WARNING, "This function requires a header name.\n"); 19448 return -1; 19449 } 19450 19451 ast_channel_lock(chan); 19452 if (!IS_SIP_TECH(chan->tech)) { 19453 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 19454 ast_channel_unlock(chan); 19455 return -1; 19456 } 19457 19458 AST_STANDARD_APP_ARGS(args, data); 19459 if (!args.number) { 19460 number = 1; 19461 } else { 19462 sscanf(args.number, "%30d", &number); 19463 if (number < 1) 19464 number = 1; 19465 } 19466 19467 p = chan->tech_pvt; 19468 19469 /* If there is no private structure, this channel is no longer alive */ 19470 if (!p) { 19471 ast_channel_unlock(chan); 19472 return -1; 19473 } 19474 19475 for (i = 0; i < number; i++) 19476 content = __get_header(&p->initreq, args.header, &start); 19477 19478 if (ast_strlen_zero(content)) { 19479 ast_channel_unlock(chan); 19480 return -1; 19481 } 19482 19483 ast_copy_string(buf, content, len); 19484 ast_channel_unlock(chan); 19485 19486 return 0; 19487 }
| static int function_sipchaninfo_read | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPCHANINFO()} Dialplan function - reads sip channel data
Definition at line 19613 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_copy_string(), ast_log(), ast_sockaddr_stringify_addr(), LOG_WARNING, ast_channel::tech, and ast_channel::tech_pvt.
19614 { 19615 struct sip_pvt *p; 19616 static int deprecated = 0; 19617 19618 *buf = 0; 19619 19620 if (!data) { 19621 ast_log(LOG_WARNING, "This function requires a parameter name.\n"); 19622 return -1; 19623 } 19624 19625 ast_channel_lock(chan); 19626 if (!IS_SIP_TECH(chan->tech)) { 19627 ast_log(LOG_WARNING, "This function can only be used on SIP channels.\n"); 19628 ast_channel_unlock(chan); 19629 return -1; 19630 } 19631 19632 if (deprecated++ % 20 == 0) { 19633 /* Deprecated in 1.6.1 */ 19634 ast_log(LOG_WARNING, "SIPCHANINFO() is deprecated. Please transition to using CHANNEL().\n"); 19635 } 19636 19637 p = chan->tech_pvt; 19638 19639 /* If there is no private structure, this channel is no longer alive */ 19640 if (!p) { 19641 ast_channel_unlock(chan); 19642 return -1; 19643 } 19644 19645 if (!strcasecmp(data, "peerip")) { 19646 ast_copy_string(buf, ast_sockaddr_stringify_addr(&p->sa), len); 19647 } else if (!strcasecmp(data, "recvip")) { 19648 ast_copy_string(buf, ast_sockaddr_stringify_addr(&p->recv), len); 19649 } else if (!strcasecmp(data, "from")) { 19650 ast_copy_string(buf, p->from, len); 19651 } else if (!strcasecmp(data, "uri")) { 19652 ast_copy_string(buf, p->uri, len); 19653 } else if (!strcasecmp(data, "useragent")) { 19654 ast_copy_string(buf, p->useragent, len); 19655 } else if (!strcasecmp(data, "peername")) { 19656 ast_copy_string(buf, p->peername, len); 19657 } else if (!strcasecmp(data, "t38passthrough")) { 19658 if (p->t38.state == T38_DISABLED) { 19659 ast_copy_string(buf, "0", len); 19660 } else { /* T38 is offered or enabled in this call */ 19661 ast_copy_string(buf, "1", len); 19662 } 19663 } else { 19664 ast_channel_unlock(chan); 19665 return -1; 19666 } 19667 ast_channel_unlock(chan); 19668 19669 return 0; 19670 }
| static int function_sippeer | ( | struct ast_channel * | chan, | |
| const char * | cmd, | |||
| char * | data, | |||
| char * | buf, | |||
| size_t | len | |||
| ) | [static] |
${SIPPEER()} Dialplan function - reads peer data
Definition at line 19514 of file chan_sip.c.
References ast_codec_pref_index(), ast_copy_string(), ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_print_group(), ast_sockaddr_port, ast_sockaddr_stringify_addr(), ast_str_alloca, ast_test_flag, chanvar, FALSE, find_peer(), LOG_WARNING, ast_variable::name, ast_variable::next, peer_mailboxes_to_str(), peer_status(), TRUE, unref_peer(), and ast_variable::value.
19515 { 19516 struct sip_peer *peer; 19517 char *colname; 19518 19519 if ((colname = strchr(data, ':'))) { /*! \todo Will be deprecated after 1.4 */ 19520 static int deprecation_warning = 0; 19521 *colname++ = '\0'; 19522 if (deprecation_warning++ % 10 == 0) 19523 ast_log(LOG_WARNING, "SIPPEER(): usage of ':' to separate arguments is deprecated. Please use ',' instead.\n"); 19524 } else if ((colname = strchr(data, ','))) 19525 *colname++ = '\0'; 19526 else 19527 colname = "ip"; 19528 19529 if (!(peer = find_peer(data, NULL, TRUE, FINDPEERS, FALSE, 0))) 19530 return -1; 19531 19532 if (!strcasecmp(colname, "ip")) { 19533 ast_copy_string(buf, ast_sockaddr_stringify_addr(&peer->addr), len); 19534 } else if (!strcasecmp(colname, "port")) { 19535 snprintf(buf, len, "%d", ast_sockaddr_port(&peer->addr)); 19536 } else if (!strcasecmp(colname, "status")) { 19537 peer_status(peer, buf, len); 19538 } else if (!strcasecmp(colname, "language")) { 19539 ast_copy_string(buf, peer->language, len); 19540 } else if (!strcasecmp(colname, "regexten")) { 19541 ast_copy_string(buf, peer->regexten, len); 19542 } else if (!strcasecmp(colname, "limit")) { 19543 snprintf(buf, len, "%d", peer->call_limit); 19544 } else if (!strcasecmp(colname, "busylevel")) { 19545 snprintf(buf, len, "%d", peer->busy_level); 19546 } else if (!strcasecmp(colname, "curcalls")) { 19547 snprintf(buf, len, "%d", peer->inUse); 19548 } else if (!strcasecmp(colname, "maxforwards")) { 19549 snprintf(buf, len, "%d", peer->maxforwards); 19550 } else if (!strcasecmp(colname, "accountcode")) { 19551 ast_copy_string(buf, peer->accountcode, len); 19552 } else if (!strcasecmp(colname, "callgroup")) { 19553 ast_print_group(buf, len, peer->callgroup); 19554 } else if (!strcasecmp(colname, "pickupgroup")) { 19555 ast_print_group(buf, len, peer->pickupgroup); 19556 } else if (!strcasecmp(colname, "useragent")) { 19557 ast_copy_string(buf, peer->useragent, len); 19558 } else if (!strcasecmp(colname, "mailbox")) { 19559 struct ast_str *mailbox_str = ast_str_alloca(512); 19560 peer_mailboxes_to_str(&mailbox_str, peer); 19561 ast_copy_string(buf, mailbox_str->str, len); 19562 } else if (!strcasecmp(colname, "context")) { 19563 ast_copy_string(buf, peer->context, len); 19564 } else if (!strcasecmp(colname, "expire")) { 19565 snprintf(buf, len, "%d", peer->expire); 19566 } else if (!strcasecmp(colname, "dynamic")) { 19567 ast_copy_string(buf, peer->host_dynamic ? "yes" : "no", len); 19568 } else if (!strcasecmp(colname, "callerid_name")) { 19569 ast_copy_string(buf, peer->cid_name, len); 19570 } else if (!strcasecmp(colname, "callerid_num")) { 19571 ast_copy_string(buf, peer->cid_num, len); 19572 } else if (!strcasecmp(colname, "codecs")) { 19573 ast_getformatname_multiple(buf, len -1, peer->capability); 19574 } else if (!strcasecmp(colname, "encryption")) { 19575 snprintf(buf, len, "%d", ast_test_flag(&peer->flags[1], SIP_PAGE2_USE_SRTP)); 19576 } else if (!strncasecmp(colname, "chanvar[", 8)) { 19577 char *chanvar=colname + 8; 19578 struct ast_variable *v; 19579 19580 chanvar = strsep(&chanvar, "]"); 19581 for (v = peer->chanvars ; v ; v = v->next) { 19582 if (!strcasecmp(v->name, chanvar)) { 19583 ast_copy_string(buf, v->value, len); 19584 } 19585 } 19586 } else if (!strncasecmp(colname, "codec[", 6)) { 19587 char *codecnum; 19588 format_t codec = 0; 19589 19590 codecnum = colname + 6; /* move past the '[' */ 19591 codecnum = strsep(&codecnum, "]"); /* trim trailing ']' if any */ 19592 if((codec = ast_codec_pref_index(&peer->prefs, atoi(codecnum)))) { 19593 ast_copy_string(buf, ast_getformatname(codec), len); 19594 } else { 19595 buf[0] = '\0'; 19596 } 19597 } else { 19598 buf[0] = '\0'; 19599 } 19600 19601 unref_peer(peer, "unref_peer from function_sippeer, just before return"); 19602 19603 return 0; 19604 }
| static char * generate_random_string | ( | char * | buf, | |
| size_t | size | |||
| ) | [static] |
Generate 32 byte random string for callid's etc.
Definition at line 7544 of file chan_sip.c.
References ast_random().
Referenced by build_callid_pvt(), build_callid_registry(), construct_pidf_body(), and generate_uri().
07545 { 07546 long val[4]; 07547 int x; 07548 07549 for (x=0; x<4; x++) 07550 val[x] = ast_random(); 07551 snprintf(buf, size, "%08lx%08lx%08lx%08lx", val[0], val[1], val[2], val[3]); 07552 07553 return buf; 07554 }
| static char* generate_uri | ( | struct sip_pvt * | pvt, | |
| char * | buf, | |||
| size_t | size | |||
| ) | [static] |
Definition at line 7556 of file chan_sip.c.
References ast_copy_string(), ast_sockaddr_stringify_remote(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_str_set(), and generate_random_string().
Referenced by add_cc_call_info_to_response(), and transmit_cc_notify().
07557 { 07558 struct ast_str *uri = ast_str_alloca(size); 07559 ast_str_set(&uri, 0, "%s", pvt->socket.type == SIP_TRANSPORT_TLS ? "sips:" : "sip:"); 07560 /* Here would be a great place to generate a UUID, but for now we'll 07561 * use the handy random string generation function we already have 07562 */ 07563 ast_str_append(&uri, 0, "%s", generate_random_string(buf, size)); 07564 ast_str_append(&uri, 0, "@%s", ast_sockaddr_stringify_remote(&pvt->ourip)); 07565 ast_copy_string(buf, ast_str_buffer(uri), size); 07566 return buf; 07567 }
| int get_address_family_filter | ( | unsigned int | transport | ) | [static] |
Helper for dns resolution to filter by address family.
Definition at line 25598 of file chan_sip.c.
References ast_sockaddr_is_any(), ast_sockaddr_is_ipv6(), bindaddr, ast_tcptls_session_args::local_address, and ast_sockaddr::ss.
Referenced by __sip_subscribe_mwi_do(), ast_sockaddr_resolve_first(), ast_sockaddr_resolve_first_transport(), build_peer(), proxy_update(), realtime_peer_by_name(), and transmit_register().
25599 { 25600 const struct ast_sockaddr *addr = NULL; 25601 25602 if ((transport == SIP_TRANSPORT_UDP) || !transport) { 25603 addr = &bindaddr; 25604 } 25605 else if (transport == SIP_TRANSPORT_TCP) { 25606 addr = &sip_tcp_desc.local_address; 25607 } 25608 else if (transport == SIP_TRANSPORT_TLS) { 25609 addr = &sip_tls_desc.local_address; 25610 } 25611 25612 if (ast_sockaddr_is_ipv6(addr) && ast_sockaddr_is_any(addr)) { 25613 return 0; 25614 } 25615 25616 return addr->ss.ss_family; 25617 }
| static int get_also_info | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
Call transfer support (old way, deprecated by the IETF).
Definition at line 15847 of file chan_sip.c.
References ast_canmatch_extension(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_verbose, context, get_header(), get_in_brackets(), LOG_WARNING, parse_uri_legacy_check(), pbx_builtin_getvar_helper(), S_OR, sip_cfg, sip_debug_test_pvt(), SIP_PEDANTIC_DECODE, and sip_refer_allocate().
Referenced by handle_request_bye().
15848 { 15849 char tmp[256] = "", *c, *a; 15850 struct sip_request *req = oreq ? oreq : &p->initreq; 15851 struct sip_refer *referdata = NULL; 15852 const char *transfer_context = NULL; 15853 15854 if (!p->refer && !sip_refer_allocate(p)) 15855 return -1; 15856 15857 referdata = p->refer; 15858 15859 ast_copy_string(tmp, get_header(req, "Also"), sizeof(tmp)); 15860 c = get_in_brackets(tmp); 15861 15862 if (parse_uri_legacy_check(c, "sip:,sips:", &c, NULL, &a, NULL)) { 15863 ast_log(LOG_WARNING, "Huh? Not a SIP header in Also: transfer (%s)?\n", c); 15864 return -1; 15865 } 15866 15867 SIP_PEDANTIC_DECODE(c); 15868 SIP_PEDANTIC_DECODE(a); 15869 15870 if (!ast_strlen_zero(a)) { 15871 ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain)); 15872 } 15873 15874 if (sip_debug_test_pvt(p)) 15875 ast_verbose("Looking for %s in %s\n", c, p->context); 15876 15877 if (p->owner) /* Mimic behaviour in res_features.c */ 15878 transfer_context = pbx_builtin_getvar_helper(p->owner, "TRANSFER_CONTEXT"); 15879 15880 /* By default, use the context in the channel sending the REFER */ 15881 if (ast_strlen_zero(transfer_context)) { 15882 transfer_context = S_OR(p->owner->macrocontext, 15883 S_OR(p->context, sip_cfg.default_context)); 15884 } 15885 if (ast_exists_extension(NULL, transfer_context, c, 1, NULL)) { 15886 /* This is a blind transfer */ 15887 ast_debug(1, "SIP Bye-also transfer to Extension %s@%s \n", c, transfer_context); 15888 ast_copy_string(referdata->refer_to, c, sizeof(referdata->refer_to)); 15889 ast_copy_string(referdata->referred_by, "", sizeof(referdata->referred_by)); 15890 ast_copy_string(referdata->refer_contact, "", sizeof(referdata->refer_contact)); 15891 /* Set new context */ 15892 ast_string_field_set(p, context, transfer_context); 15893 return 0; 15894 } else if (ast_canmatch_extension(NULL, p->context, c, 1, NULL)) { 15895 return 1; 15896 } 15897 15898 return -1; 15899 }
| static char* get_body | ( | struct sip_request * | req, | |
| char * | name, | |||
| char | delimiter | |||
| ) | [static] |
Get a specific line from the message body.
Definition at line 7299 of file chan_sip.c.
References get_body_by_line(), and len().
Referenced by handle_cc_notify(), handle_request_info(), and handle_request_notify().
07300 { 07301 int x; 07302 int len = strlen(name); 07303 char *r; 07304 07305 for (x = 0; x < req->lines; x++) { 07306 r = get_body_by_line(REQ_OFFSET_TO_STR(req, line[x]), name, len, delimiter); 07307 if (r[0] != '\0') 07308 return r; 07309 } 07310 07311 return ""; 07312 }
| static char* get_body_by_line | ( | const char * | line, | |
| const char * | name, | |||
| int | nameLen, | |||
| char | delimiter | |||
| ) | [static] |
Reads one line of SIP message body.
Definition at line 7244 of file chan_sip.c.
References ast_skip_blanks().
Referenced by get_body(), and get_sdp_iterate().
07245 { 07246 if (!strncasecmp(line, name, nameLen) && line[nameLen] == delimiter) 07247 return ast_skip_blanks(line + nameLen + 1); 07248 07249 return ""; 07250 }
| static int get_cached_mwi | ( | struct sip_peer * | peer, | |
| int * | new, | |||
| int * | old | |||
| ) | [static] |
Get cached MWI info.
Definition at line 25753 of file chan_sip.c.
References ast_event_destroy(), ast_event_get_cached(), ast_event_get_ie_uint(), AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_MWI, AST_LIST_TRAVERSE, mailbox, and S_OR.
Referenced by sip_send_mwi_to_peer().
25754 { 25755 struct sip_mailbox *mailbox; 25756 int in_cache; 25757 25758 in_cache = 0; 25759 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 25760 struct ast_event *event; 25761 event = ast_event_get_cached(AST_EVENT_MWI, 25762 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox->mailbox, 25763 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, S_OR(mailbox->context, "default"), 25764 AST_EVENT_IE_END); 25765 if (!event) 25766 continue; 25767 *new += ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS); 25768 *old += ast_event_get_ie_uint(event, AST_EVENT_IE_OLDMSGS); 25769 ast_event_destroy(event); 25770 in_cache = 1; 25771 } 25772 25773 return in_cache; 25774 }
| static void get_crypto_attrib | ( | struct sip_srtp * | srtp, | |
| const char ** | a_crypto | |||
| ) | [static] |
Definition at line 11265 of file chan_sip.c.
References ast_log(), LOG_WARNING, sdp_crypto_attrib(), sdp_crypto_offer(), and sdp_crypto_setup().
Referenced by add_sdp().
11266 { 11267 /* Set encryption properties */ 11268 if (srtp) { 11269 if (!srtp->crypto) { 11270 srtp->crypto = sdp_crypto_setup(); 11271 } 11272 if (srtp->crypto && (sdp_crypto_offer(srtp->crypto) >= 0)) { 11273 *a_crypto = sdp_crypto_attrib(srtp->crypto); 11274 } 11275 11276 if (!*a_crypto) { 11277 ast_log(LOG_WARNING, "No SRTP key management enabled\n"); 11278 } 11279 } 11280 }
| static enum sip_get_dest_result get_destination | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq, | |||
| int * | cc_recall_core_id | |||
| ) | [static] |
Find out who the call is for.
We use the request uri as a destination. This code assumes authentication has been done, so that the device (peer/user) context is already set.
Definition at line 15397 of file chan_sip.c.
References ao2_ref, ast_canmatch_extension(), ast_cc_agent_recalling(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_get_hint(), AST_LIST_EMPTY, ast_log(), AST_MAX_EXTENSION, ast_pickup_ext(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_verbose, check_sip_domain(), context, ast_cc_agent::core_id, ast_cc_agent::device_name, exten, extract_host_from_hostport(), find_sip_cc_agent_by_notify_uri(), get_header(), get_in_brackets(), LOG_WARNING, parse_uri_legacy_check(), ast_cc_agent::private_data, S_OR, sip_cfg, sip_debug_test_pvt(), sip_methods, SIP_PEDANTIC_DECODE, and cfsip_methods::text.
Referenced by handle_request_invite(), handle_request_options(), and handle_request_subscribe().
15398 { 15399 char tmp[256] = "", *uri, *unused_password, *domain; 15400 char tmpf[256] = "", *from = NULL; 15401 struct sip_request *req; 15402 char *decoded_uri; 15403 15404 req = oreq; 15405 if (!req) { 15406 req = &p->initreq; 15407 } 15408 15409 /* Find the request URI */ 15410 if (req->rlPart2) 15411 ast_copy_string(tmp, REQ_OFFSET_TO_STR(req, rlPart2), sizeof(tmp)); 15412 15413 uri = ast_strdupa(get_in_brackets(tmp)); 15414 15415 if (parse_uri_legacy_check(uri, "sip:,sips:", &uri, &unused_password, &domain, NULL)) { 15416 ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", uri); 15417 return SIP_GET_DEST_INVALID_URI; 15418 } 15419 15420 SIP_PEDANTIC_DECODE(domain); 15421 SIP_PEDANTIC_DECODE(uri); 15422 15423 extract_host_from_hostport(&domain); 15424 15425 if (ast_strlen_zero(uri)) { 15426 /* 15427 * Either there really was no extension found or the request 15428 * URI had encoded nulls that made the string "empty". Use "s" 15429 * as the extension. 15430 */ 15431 uri = "s"; 15432 } 15433 15434 ast_string_field_set(p, domain, domain); 15435 15436 /* Now find the From: caller ID and name */ 15437 /* XXX Why is this done in get_destination? Isn't it already done? 15438 Needs to be checked 15439 */ 15440 ast_copy_string(tmpf, get_header(req, "From"), sizeof(tmpf)); 15441 if (!ast_strlen_zero(tmpf)) { 15442 from = get_in_brackets(tmpf); 15443 if (parse_uri_legacy_check(from, "sip:,sips:", &from, NULL, &domain, NULL)) { 15444 ast_log(LOG_WARNING, "Not a SIP header (%s)?\n", from); 15445 return SIP_GET_DEST_INVALID_URI; 15446 } 15447 15448 SIP_PEDANTIC_DECODE(from); 15449 SIP_PEDANTIC_DECODE(domain); 15450 15451 extract_host_from_hostport(&domain); 15452 15453 ast_string_field_set(p, fromdomain, domain); 15454 } 15455 15456 if (!AST_LIST_EMPTY(&domain_list)) { 15457 char domain_context[AST_MAX_EXTENSION]; 15458 15459 domain_context[0] = '\0'; 15460 if (!check_sip_domain(p->domain, domain_context, sizeof(domain_context))) { 15461 if (!sip_cfg.allow_external_domains && (req->method == SIP_INVITE || req->method == SIP_REFER)) { 15462 ast_debug(1, "Got SIP %s to non-local domain '%s'; refusing request.\n", sip_methods[req->method].text, p->domain); 15463 return SIP_GET_DEST_REFUSED; 15464 } 15465 } 15466 /* If we don't have a peer (i.e. we're a guest call), 15467 * overwrite the original context */ 15468 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_HAVEPEERCONTEXT) && !ast_strlen_zero(domain_context)) { 15469 ast_string_field_set(p, context, domain_context); 15470 } 15471 } 15472 15473 /* If the request coming in is a subscription and subscribecontext has been specified use it */ 15474 if (req->method == SIP_SUBSCRIBE && !ast_strlen_zero(p->subscribecontext)) { 15475 ast_string_field_set(p, context, p->subscribecontext); 15476 } 15477 15478 if (sip_debug_test_pvt(p)) { 15479 ast_verbose("Looking for %s in %s (domain %s)\n", uri, p->context, p->domain); 15480 } 15481 15482 /* Since extensions.conf can have unescaped characters, try matching a 15483 * decoded uri in addition to the non-decoded uri. */ 15484 decoded_uri = ast_strdupa(uri); 15485 ast_uri_decode(decoded_uri); 15486 15487 /* If this is a subscription we actually just need to see if a hint exists for the extension */ 15488 if (req->method == SIP_SUBSCRIBE) { 15489 char hint[AST_MAX_EXTENSION]; 15490 int which = 0; 15491 if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, uri) || 15492 (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, p->context, decoded_uri) && (which = 1))) { 15493 if (!oreq) { 15494 ast_string_field_set(p, exten, which ? decoded_uri : uri); 15495 } 15496 return SIP_GET_DEST_EXTEN_FOUND; 15497 } else { 15498 return SIP_GET_DEST_EXTEN_NOT_FOUND; 15499 } 15500 } else { 15501 struct ast_cc_agent *agent; 15502 /* Check the dialplan for the username part of the request URI, 15503 the domain will be stored in the SIPDOMAIN variable 15504 Return 0 if we have a matching extension */ 15505 if (ast_exists_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from))) { 15506 if (!oreq) { 15507 ast_string_field_set(p, exten, uri); 15508 } 15509 return SIP_GET_DEST_EXTEN_FOUND; 15510 } 15511 if (ast_exists_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) 15512 || !strcmp(decoded_uri, ast_pickup_ext())) { 15513 if (!oreq) { 15514 ast_string_field_set(p, exten, decoded_uri); 15515 } 15516 return SIP_GET_DEST_EXTEN_FOUND; 15517 } 15518 if ((agent = find_sip_cc_agent_by_notify_uri(tmp))) { 15519 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 15520 /* This is a CC recall. We can set p's extension to the exten from 15521 * the original INVITE 15522 */ 15523 ast_string_field_set(p, exten, agent_pvt->original_exten); 15524 /* And we need to let the CC core know that the caller is attempting 15525 * his recall 15526 */ 15527 ast_cc_agent_recalling(agent->core_id, "SIP caller %s is attempting recall", 15528 agent->device_name); 15529 if (cc_recall_core_id) { 15530 *cc_recall_core_id = agent->core_id; 15531 } 15532 ao2_ref(agent, -1); 15533 return SIP_GET_DEST_EXTEN_FOUND; 15534 } 15535 } 15536 15537 if (ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP) 15538 && (ast_canmatch_extension(NULL, p->context, uri, 1, S_OR(p->cid_num, from)) 15539 || ast_canmatch_extension(NULL, p->context, decoded_uri, 1, S_OR(p->cid_num, from)) 15540 || !strncmp(decoded_uri, ast_pickup_ext(), strlen(decoded_uri)))) { 15541 /* Overlap dialing is enabled and we need more digits to match an extension. */ 15542 return SIP_GET_DEST_EXTEN_MATCHMORE; 15543 } 15544 15545 return SIP_GET_DEST_EXTEN_NOT_FOUND; 15546 }
| static int get_domain | ( | const char * | str, | |
| char * | domain, | |||
| int | len | |||
| ) | [static] |
Extract domain from SIP To/From header.
Definition at line 10760 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strlen_zero(), get_in_brackets(), and LOG_WARNING.
Referenced by get_realm().
10761 { 10762 char tmpf[256]; 10763 char *a, *from; 10764 10765 *domain = '\0'; 10766 ast_copy_string(tmpf, str, sizeof(tmpf)); 10767 from = get_in_brackets(tmpf); 10768 if (!ast_strlen_zero(from)) { 10769 if (strncasecmp(from, "sip:", 4)) { 10770 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", from); 10771 return -1; 10772 } 10773 from += 4; 10774 } else 10775 from = NULL; 10776 10777 if (from) { 10778 int bracket = 0; 10779 10780 /* Strip any params or options from user */ 10781 if ((a = strchr(from, ';'))) 10782 *a = '\0'; 10783 /* Strip port from domain if present */ 10784 for (a = from; *a != '\0'; ++a) { 10785 if (*a == ':' && bracket == 0) { 10786 *a = '\0'; 10787 break; 10788 } else if (*a == '[') { 10789 ++bracket; 10790 } else if (*a == ']') { 10791 --bracket; 10792 } 10793 } 10794 if ((a = strchr(from, '@'))) { 10795 *a = '\0'; 10796 ast_copy_string(domain, a + 1, len); 10797 } else 10798 ast_copy_string(domain, from, len); 10799 } 10800 10801 return ast_strlen_zero(domain); 10802 }
| static struct event_state_compositor* get_esc | ( | const char *const | event_package | ) | [static, read] |
Definition at line 999 of file chan_sip.c.
References ARRAY_LEN, event_state_compositors, and name.
Referenced by create_new_sip_etag(), handle_request_publish(), and publish_expire().
00999 { 01000 int i; 01001 for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) { 01002 if (!strcasecmp(event_package, event_state_compositors[i].name)) { 01003 return &event_state_compositors[i]; 01004 } 01005 } 01006 return NULL; 01007 }
| static struct sip_esc_entry* get_esc_entry | ( | const char * | entity_tag, | |
| struct event_state_compositor * | esc | |||
| ) | [static, read] |
Definition at line 1009 of file chan_sip.c.
References ao2_find, ast_copy_string(), event_state_compositor::compositor, and OBJ_POINTER.
Referenced by handle_sip_publish_modify(), handle_sip_publish_refresh(), and handle_sip_publish_remove().
01009 { 01010 struct sip_esc_entry *entry; 01011 struct sip_esc_entry finder; 01012 01013 ast_copy_string(finder.entity_tag, entity_tag, sizeof(finder.entity_tag)); 01014 01015 entry = ao2_find(esc->compositor, &finder, OBJ_POINTER); 01016 01017 return entry; 01018 }
| static const char * get_header | ( | const struct sip_request * | req, | |
| const char * | name | |||
| ) | [static] |
Get header from SIP request.
Definition at line 7393 of file chan_sip.c.
References __get_header().
Referenced by __transmit_response(), _sip_tcp_helper_thread(), build_route(), cc_handle_publish_error(), change_redirecting_information(), check_auth(), check_user_full(), check_via(), check_via_response(), copy_header(), extract_uri(), find_call(), find_sdp(), get_also_info(), get_destination(), get_pai(), get_rdnis(), get_realm(), get_refer_info(), get_rpid(), gettag(), handle_cc_notify(), handle_cc_subscribe(), handle_incoming(), handle_request_bye(), handle_request_do(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_publish(), handle_request_register(), handle_request_subscribe(), handle_request_update(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_publish(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), handle_response_update(), parse_allowed_methods(), parse_moved_contact(), parse_ok_contact(), parse_register_contact(), proc_422_rsp(), process_via(), receive_message(), register_verify(), reply_digest(), reqprep(), respprep(), send_request(), send_response(), sip_alloc(), sip_get_cc_information(), sip_sipredirect(), transmit_fake_auth_response(), transmit_refer(), transmit_response_with_auth(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), and transmit_state_notify().
07394 { 07395 int start = 0; 07396 return __get_header(req, name, &start); 07397 }
| static struct ast_variable * get_insecure_variable_from_config | ( | struct ast_config * | config | ) | [static, read] |
Definition at line 4677 of file chan_sip.c.
References ast_category_browse(), ast_category_root(), ast_test_flag, ast_variable_retrieve(), set_insecure_flags(), and var.
Referenced by get_insecure_variable_from_sippeers().
04678 { 04679 struct ast_variable *var = NULL; 04680 struct ast_flags flags = {0}; 04681 char *cat = NULL; 04682 const char *insecure; 04683 while ((cat = ast_category_browse(cfg, cat))) { 04684 insecure = ast_variable_retrieve(cfg, cat, "insecure"); 04685 set_insecure_flags(&flags, insecure, -1); 04686 if (ast_test_flag(&flags, SIP_INSECURE_PORT)) { 04687 var = ast_category_root(cfg, cat); 04688 break; 04689 } 04690 } 04691 return var; 04692 }
| static struct ast_variable* get_insecure_variable_from_sippeers | ( | const char * | column, | |
| const char * | value | |||
| ) | [static, read] |
Definition at line 4694 of file chan_sip.c.
References ast_config_destroy(), ast_load_realtime_multientry(), ast_variables_dup(), get_insecure_variable_from_config(), SENTINEL, and var.
Referenced by realtime_peer_by_addr().
04695 { 04696 struct ast_config *peerlist; 04697 struct ast_variable *var = NULL; 04698 if ((peerlist = ast_load_realtime_multientry("sippeers", column, value, "insecure LIKE", "%port%", SENTINEL))) { 04699 if ((var = get_insecure_variable_from_config(peerlist))) { 04700 /* Must clone, because var will get freed along with 04701 * peerlist. */ 04702 var = ast_variables_dup(var); 04703 } 04704 ast_config_destroy(peerlist); 04705 } 04706 return var; 04707 }
| static struct ast_variable* get_insecure_variable_from_sipregs | ( | const char * | column, | |
| const char * | value, | |||
| struct ast_variable ** | var | |||
| ) | [static, read] |
Definition at line 4714 of file chan_sip.c.
References ast_category_browse(), ast_category_root(), ast_config_destroy(), ast_load_realtime_multientry(), ast_test_flag, ast_variable_retrieve(), ast_variables_destroy(), ast_variables_dup(), SENTINEL, and set_insecure_flags().
Referenced by realtime_peer_by_addr().
04715 { 04716 struct ast_variable *varregs = NULL; 04717 struct ast_config *regs, *peers; 04718 char *regscat; 04719 const char *regname; 04720 04721 if (!(regs = ast_load_realtime_multientry("sipregs", column, value, SENTINEL))) { 04722 return NULL; 04723 } 04724 04725 /* Load *all* peers that are probably insecure=port */ 04726 if (!(peers = ast_load_realtime_multientry("sippeers", "insecure LIKE", "%port%", SENTINEL))) { 04727 ast_config_destroy(regs); 04728 return NULL; 04729 } 04730 04731 /* Loop over the sipregs that match IP address and attempt to find an 04732 * insecure=port match to it in sippeers. */ 04733 regscat = NULL; 04734 while ((regscat = ast_category_browse(regs, regscat)) && (regname = ast_variable_retrieve(regs, regscat, "name"))) { 04735 char *peerscat; 04736 const char *peername; 04737 04738 peerscat = NULL; 04739 while ((peerscat = ast_category_browse(peers, peerscat)) && (peername = ast_variable_retrieve(peers, peerscat, "name"))) { 04740 if (!strcasecmp(regname, peername)) { 04741 /* Ensure that it really is insecure=port and 04742 * not something else. */ 04743 const char *insecure = ast_variable_retrieve(peers, peerscat, "insecure"); 04744 struct ast_flags flags = {0}; 04745 set_insecure_flags(&flags, insecure, -1); 04746 if (ast_test_flag(&flags, SIP_INSECURE_PORT)) { 04747 /* ENOMEM checks till the bitter end. */ 04748 if ((varregs = ast_variables_dup(ast_category_root(regs, regscat)))) { 04749 if (!(*var = ast_variables_dup(ast_category_root(peers, peerscat)))) { 04750 ast_variables_destroy(varregs); 04751 varregs = NULL; 04752 } 04753 } 04754 goto done; 04755 } 04756 } 04757 } 04758 } 04759 04760 done: 04761 ast_config_destroy(regs); 04762 ast_config_destroy(peers); 04763 return varregs; 04764 }
| static int get_ip_and_port_from_sdp | ( | struct sip_request * | req, | |
| const enum media_type | media, | |||
| struct ast_sockaddr * | addr | |||
| ) | [static] |
Definition at line 8714 of file chan_sip.c.
References ast_log(), ast_sockaddr_resolve_first_af(), ast_strlen_zero(), get_sdp_iterate(), len(), and LOG_WARNING.
Referenced by handle_request_invite().
08715 { 08716 const char *m; 08717 const char *c; 08718 int miterator = req->sdp_start; 08719 int citerator = req->sdp_start; 08720 int x = 0; 08721 int numberofports; 08722 int len; 08723 int af; 08724 char proto[4], host[258] = ""; /*Initialize to empty so we will know if we have any input */ 08725 08726 c = get_sdp_iterate(&citerator, req, "c"); 08727 if (sscanf(c, "IN %3s %256s", proto, host) != 2) { 08728 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 08729 /* Continue since there may be a valid host in a c= line specific to the audio stream */ 08730 } 08731 /* We only want the m and c lines for audio */ 08732 for (m = get_sdp_iterate(&miterator, req, "m"); !ast_strlen_zero(m); m = get_sdp_iterate(&miterator, req, "m")) { 08733 if ((media == SDP_AUDIO && ((sscanf(m, "audio %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08734 (sscanf(m, "audio %30u RTP/AVP %n", &x, &len) == 1 && len > 0))) || 08735 (media == SDP_VIDEO && ((sscanf(m, "video %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 08736 (sscanf(m, "video %30u RTP/AVP %n", &x, &len) == 1 && len > 0)))) { 08737 /* See if there's a c= line for this media stream. 08738 * XXX There is no guarantee that we'll be grabbing the c= line for this 08739 * particular media stream here. However, this is the same logic used in process_sdp. 08740 */ 08741 c = get_sdp_iterate(&citerator, req, "c"); 08742 if (!ast_strlen_zero(c)) { 08743 sscanf(c, "IN %3s %256s", proto, host); 08744 } 08745 break; 08746 } 08747 } 08748 08749 if (!strcmp("IP4", proto)) { 08750 af = AF_INET; 08751 } else if (!strcmp("IP6", proto)) { 08752 af = AF_INET6; 08753 } else { 08754 ast_log(LOG_WARNING, "Unknown protocol '%s'.\n", proto); 08755 return -1; 08756 } 08757 08758 if (ast_strlen_zero(host) || x == 0) { 08759 ast_log(LOG_WARNING, "Failed to read an alternate host or port in SDP. Expect %s problems\n", media == SDP_AUDIO ? "audio" : "video"); 08760 return -1; 08761 } 08762 08763 if (ast_sockaddr_resolve_first_af(addr, host, 0, af)) { 08764 ast_log(LOG_WARNING, "Could not look up IP address of alternate hostname. Expect %s problems\n", media == SDP_AUDIO? "audio" : "video"); 08765 return -1; 08766 } 08767 08768 return 0; 08769 }
| static int get_msg_text | ( | char * | buf, | |
| int | len, | |||
| struct sip_request * | req | |||
| ) | [static] |
Get message body from a SIP request.
| buf | Destination buffer | |
| len | Destination buffer size | |
| req | The SIP request |
When parsing the request originally, the lines are split by LF or CRLF. This function adds a single LF after every line.
Definition at line 16341 of file chan_sip.c.
Referenced by handle_request_info(), handle_request_notify(), and receive_message().
16342 { 16343 int x; 16344 int linelen; 16345 16346 buf[0] = '\0'; 16347 --len; /* reserve strncat null */ 16348 for (x = 0; len && x < req->lines; ++x) { 16349 const char *line = REQ_OFFSET_TO_STR(req, line[x]); 16350 strncat(buf, line, len); /* safe */ 16351 linelen = strlen(buf); 16352 buf += linelen; 16353 len -= linelen; 16354 if (len) { 16355 strcat(buf, "\n"); /* safe */ 16356 ++buf; 16357 --len; 16358 } 16359 } 16360 return 0; 16361 }
| static const char * get_name_from_variable | ( | const struct ast_variable * | var | ) | [static] |
Definition at line 4766 of file chan_sip.c.
References ast_strlen_zero(), ast_variable::name, ast_variable::next, and ast_variable::value.
Referenced by realtime_peer_by_addr(), and realtime_peer_get_sippeer_helper().
04767 { 04768 /* Don't expect this to return non-NULL. Both NULL and empty 04769 * values can cause the option to get removed from the variable 04770 * list. This is called on ast_variables gotten from both 04771 * ast_load_realtime and ast_load_realtime_multientry. 04772 * - ast_load_realtime removes options with empty values 04773 * - ast_load_realtime_multientry does not! 04774 * For consistent behaviour, we check for the empty name and 04775 * return NULL instead. */ 04776 const struct ast_variable *tmp; 04777 for (tmp = var; tmp; tmp = tmp->next) { 04778 if (!strcasecmp(tmp->name, "name")) { 04779 if (!ast_strlen_zero(tmp->value)) { 04780 return tmp->value; 04781 } 04782 break; 04783 } 04784 } 04785 return NULL; 04786 }
| 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 | |||
| ) | [static] |
Set all IP media addresses for this call.
Definition at line 11172 of file chan_sip.c.
References ast_rtp_instance_get_local_address(), ast_sockaddr_cmp_addr(), ast_sockaddr_copy(), ast_sockaddr_is_any(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, and media_address.
Referenced by add_sdp().
11176 { 11177 int use_externip = 0; 11178 11179 /* First, get our address */ 11180 ast_rtp_instance_get_local_address(p->rtp, addr); 11181 if (p->vrtp) { 11182 ast_rtp_instance_get_local_address(p->vrtp, vaddr); 11183 } 11184 if (p->trtp) { 11185 ast_rtp_instance_get_local_address(p->trtp, taddr); 11186 } 11187 11188 /* If our real IP differs from the local address returned by the RTP engine, use it. */ 11189 /* The premise is that if we are already using that IP to communicate with the client, */ 11190 /* we should be using it for RTP too. */ 11191 use_externip = ast_sockaddr_cmp_addr(&p->ourip, addr); 11192 11193 /* Now, try to figure out where we want them to send data */ 11194 /* Is this a re-invite to move the media out, then use the original offer from caller */ 11195 if (!ast_sockaddr_isnull(&p->redirip)) { /* If we have a redirection IP, use it */ 11196 ast_sockaddr_copy(dest, &p->redirip); 11197 } else { 11198 /* 11199 * Audio Destination IP: 11200 * 11201 * 1. Specifically configured media address. 11202 * 2. Local address as specified by the RTP engine. 11203 * 3. The local IP as defined by chan_sip. 11204 * 11205 * Audio Destination Port: 11206 * 11207 * 1. Provided by the RTP engine. 11208 */ 11209 ast_sockaddr_copy(dest, 11210 !ast_sockaddr_isnull(&media_address) ? &media_address : 11211 !ast_sockaddr_is_any(addr) && !use_externip ? addr : 11212 &p->ourip); 11213 ast_sockaddr_set_port(dest, ast_sockaddr_port(addr)); 11214 } 11215 11216 if (needvideo) { 11217 /* Determine video destination */ 11218 if (!ast_sockaddr_isnull(&p->vredirip)) { 11219 ast_sockaddr_copy(vdest, &p->vredirip); 11220 } else { 11221 /* 11222 * Video Destination IP: 11223 * 11224 * 1. Specifically configured media address. 11225 * 2. Local address as specified by the RTP engine. 11226 * 3. The local IP as defined by chan_sip. 11227 * 11228 * Video Destination Port: 11229 * 11230 * 1. Provided by the RTP engine. 11231 */ 11232 ast_sockaddr_copy(vdest, 11233 !ast_sockaddr_isnull(&media_address) ? &media_address : 11234 !ast_sockaddr_is_any(vaddr) && !use_externip ? vaddr : 11235 &p->ourip); 11236 ast_sockaddr_set_port(vdest, ast_sockaddr_port(vaddr)); 11237 } 11238 } 11239 11240 if (needtext) { 11241 /* Determine text destination */ 11242 if (!ast_sockaddr_isnull(&p->tredirip)) { 11243 ast_sockaddr_copy(tdest, &p->tredirip); 11244 } else { 11245 /* 11246 * Text Destination IP: 11247 * 11248 * 1. Specifically configured media address. 11249 * 2. Local address as specified by the RTP engine. 11250 * 3. The local IP as defined by chan_sip. 11251 * 11252 * Text Destination Port: 11253 * 11254 * 1. Provided by the RTP engine. 11255 */ 11256 ast_sockaddr_copy(tdest, 11257 !ast_sockaddr_isnull(&media_address) ? &media_address : 11258 !ast_sockaddr_is_any(taddr) && !use_externip ? taddr : 11259 &p->ourip); 11260 ast_sockaddr_set_port(tdest, ast_sockaddr_port(taddr)); 11261 } 11262 } 11263 }
| static int get_pai | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
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.
Definition at line 15124 of file chan_sip.c.
References ast_copy_string(), ast_free, ast_is_shrinkable_phonenumber(), AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, ast_set_callerid(), ast_shrink_phone_number(), ast_string_field_set, ast_strlen_zero(), cid_name, cid_num, get_header(), get_in_brackets(), and get_name_and_number().
Referenced by get_rpid().
15125 { 15126 char pai[256]; 15127 char privacy[64]; 15128 char *cid_num = NULL; 15129 char *cid_name = NULL; 15130 char emptyname[1] = ""; 15131 int callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; 15132 char *uri = NULL; 15133 int is_anonymous = 0, do_update = 1, no_name = 0; 15134 15135 ast_copy_string(pai, get_header(req, "P-Asserted-Identity"), sizeof(pai)); 15136 15137 if (ast_strlen_zero(pai)) { 15138 return 0; 15139 } 15140 15141 /* use the reqresp_parser function get_name_and_number*/ 15142 if (get_name_and_number(pai, &cid_name, &cid_num)) { 15143 return 0; 15144 } 15145 15146 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(cid_num)) { 15147 ast_shrink_phone_number(cid_num); 15148 } 15149 15150 uri = get_in_brackets(pai); 15151 if (!strncasecmp(uri, "sip:anonymous@anonymous.invalid", 31)) { 15152 callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; 15153 /*XXX Assume no change in cid_num. Perhaps it should be 15154 * blanked? 15155 */ 15156 ast_free(cid_num); 15157 is_anonymous = 1; 15158 cid_num = (char *)p->cid_num; 15159 } 15160 15161 ast_copy_string(privacy, get_header(req, "Privacy"), sizeof(privacy)); 15162 if (!ast_strlen_zero(privacy) && !strncmp(privacy, "id", 2)) { 15163 callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; 15164 } 15165 if (!cid_name) { 15166 no_name = 1; 15167 cid_name = (char *)emptyname; 15168 } 15169 /* Only return true if the supplied caller id is different */ 15170 if (!strcasecmp(p->cid_num, cid_num) && !strcasecmp(p->cid_name, cid_name) && p->callingpres == callingpres) { 15171 do_update = 0; 15172 } else { 15173 15174 ast_string_field_set(p, cid_num, cid_num); 15175 ast_string_field_set(p, cid_name, cid_name); 15176 p->callingpres = callingpres; 15177 15178 if (p->owner) { 15179 ast_set_callerid(p->owner, cid_num, cid_name, NULL); 15180 p->owner->caller.id.name.presentation = callingpres; 15181 p->owner->caller.id.number.presentation = callingpres; 15182 } 15183 } 15184 15185 /* get_name_and_number allocates memory for cid_num and cid_name so we have to free it */ 15186 if (!is_anonymous) { 15187 ast_free(cid_num); 15188 } 15189 if (!no_name) { 15190 ast_free(cid_name); 15191 } 15192 15193 return do_update; 15194 }
| static int get_rdnis | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq, | |||
| char ** | name, | |||
| char ** | number, | |||
| int * | reason | |||
| ) | [static] |
Get referring dnis.
Definition at line 15297 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_strdup, ast_strip_quoted(), ast_strlen_zero(), ast_verbose, exten, get_header(), get_in_brackets(), LOG_WARNING, pbx_builtin_setvar_helper(), sip_debug_test_pvt(), sip_reason_str_to_code(), and sip_set_redirstr().
Referenced by change_redirecting_information().
15298 { 15299 char tmp[256], *exten, *rexten, *rdomain, *rname = NULL; 15300 char *params, *reason_param = NULL; 15301 struct sip_request *req; 15302 15303 req = oreq ? oreq : &p->initreq; 15304 15305 ast_copy_string(tmp, get_header(req, "Diversion"), sizeof(tmp)); 15306 if (ast_strlen_zero(tmp)) 15307 return -1; 15308 15309 if ((params = strchr(tmp, '>'))) { 15310 params = strchr(params, ';'); 15311 } 15312 15313 exten = get_in_brackets(tmp); 15314 if (!strncasecmp(exten, "sip:", 4)) { 15315 exten += 4; 15316 } else if (!strncasecmp(exten, "sips:", 5)) { 15317 exten += 5; 15318 } else { 15319 ast_log(LOG_WARNING, "Huh? Not an RDNIS SIP header (%s)?\n", exten); 15320 return -1; 15321 } 15322 15323 /* Get diversion-reason param if present */ 15324 if (params) { 15325 *params = '\0'; /* Cut off parameters */ 15326 params++; 15327 while (*params == ';' || *params == ' ') 15328 params++; 15329 /* Check if we have a reason parameter */ 15330 if ((reason_param = strcasestr(params, "reason="))) { 15331 char *end; 15332 reason_param+=7; 15333 if ((end = strchr(reason_param, ';'))) { 15334 *end = '\0'; 15335 } 15336 /* Remove enclosing double-quotes */ 15337 if (*reason_param == '"') 15338 reason_param = ast_strip_quoted(reason_param, "\"", "\""); 15339 if (!ast_strlen_zero(reason_param)) { 15340 sip_set_redirstr(p, reason_param); 15341 if (p->owner) { 15342 pbx_builtin_setvar_helper(p->owner, "__PRIREDIRECTREASON", p->redircause); 15343 pbx_builtin_setvar_helper(p->owner, "__SIPREDIRECTREASON", reason_param); 15344 } 15345 } 15346 } 15347 } 15348 15349 rdomain = exten; 15350 rexten = strsep(&rdomain, "@"); /* trim anything after @ */ 15351 if (p->owner) 15352 pbx_builtin_setvar_helper(p->owner, "__SIPRDNISDOMAIN", rdomain); 15353 15354 if (sip_debug_test_pvt(p)) 15355 ast_verbose("RDNIS for this call is %s (reason %s)\n", exten, reason ? reason_param : ""); 15356 15357 /*ast_string_field_set(p, rdnis, rexten);*/ 15358 15359 if (*tmp == '\"') { 15360 char *end_quote; 15361 rname = tmp + 1; 15362 end_quote = strchr(rname, '\"'); 15363 if (end_quote) { 15364 *end_quote = '\0'; 15365 } 15366 } 15367 15368 if (number) { 15369 *number = ast_strdup(rexten); 15370 } 15371 15372 if (name && rname) { 15373 *name = ast_strdup(rname); 15374 } 15375 15376 if (reason && !ast_strlen_zero(reason_param)) { 15377 *reason = sip_reason_str_to_code(reason_param); 15378 } 15379 15380 return 0; 15381 }
| static void get_realm | ( | struct sip_pvt * | p, | |
| const struct sip_request * | req | |||
| ) | [static] |
Choose realm based on From header and then To header or use globaly configured realm. Realm from From/To header should be listed among served domains in config file: domain=...
Definition at line 10808 of file chan_sip.c.
References AST_LIST_EMPTY, ast_string_field_set, ast_strlen_zero(), check_sip_domain(), get_domain(), get_header(), MAXHOSTNAMELEN, and sip_cfg.
Referenced by transmit_response_with_auth().
10809 { 10810 char domain[MAXHOSTNAMELEN]; 10811 10812 if (!ast_strlen_zero(p->realm)) 10813 return; 10814 10815 if (sip_cfg.domainsasrealm && 10816 !AST_LIST_EMPTY(&domain_list)) 10817 { 10818 /* Check From header first */ 10819 if (!get_domain(get_header(req, "From"), domain, sizeof(domain))) { 10820 if (check_sip_domain(domain, NULL, 0)) { 10821 ast_string_field_set(p, realm, domain); 10822 return; 10823 } 10824 } 10825 /* Check To header */ 10826 if (!get_domain(get_header(req, "To"), domain, sizeof(domain))) { 10827 if (check_sip_domain(domain, NULL, 0)) { 10828 ast_string_field_set(p, realm, domain); 10829 return; 10830 } 10831 } 10832 } 10833 10834 /* Use default realm from config file */ 10835 ast_string_field_set(p, realm, sip_cfg.realm); 10836 }
| static int get_refer_info | ( | struct sip_pvt * | transferer, | |
| struct sip_request * | outgoing_req | |||
| ) | [static] |
Call transfer support (the REFER method) Extracts Refer headers into pvt dialog structure.
Definition at line 15640 of file chan_sip.c.
References ast_bridged_channel(), ast_copy_string(), ast_debug, ast_exists_extension(), ast_log(), ast_strdupa, ast_strlen_zero(), ast_uri_decode(), ast_verbose, ast_channel::context, get_header(), get_in_brackets(), LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), S_OR, sip_cfg, sip_debug_test_pvt(), and SIP_PEDANTIC_DECODE.
Referenced by handle_request_refer().
15641 { 15642 15643 const char *p_referred_by = NULL; 15644 char *h_refer_to = NULL; 15645 char *h_referred_by = NULL; 15646 char *refer_to; 15647 const char *p_refer_to; 15648 char *referred_by_uri = NULL; 15649 char *ptr; 15650 struct sip_request *req = NULL; 15651 const char *transfer_context = NULL; 15652 struct sip_refer *referdata; 15653 15654 15655 req = outgoing_req; 15656 referdata = transferer->refer; 15657 15658 if (!req) { 15659 req = &transferer->initreq; 15660 } 15661 15662 p_refer_to = get_header(req, "Refer-To"); 15663 if (ast_strlen_zero(p_refer_to)) { 15664 ast_log(LOG_WARNING, "Refer-To Header missing. Skipping transfer.\n"); 15665 return -2; /* Syntax error */ 15666 } 15667 h_refer_to = ast_strdupa(p_refer_to); 15668 refer_to = get_in_brackets(h_refer_to); 15669 if (!strncasecmp(refer_to, "sip:", 4)) { 15670 refer_to += 4; /* Skip sip: */ 15671 } else if (!strncasecmp(refer_to, "sips:", 5)) { 15672 refer_to += 5; 15673 } else { 15674 ast_log(LOG_WARNING, "Can't transfer to non-sip: URI. (Refer-to: %s)?\n", refer_to); 15675 return -3; 15676 } 15677 15678 /* Get referred by header if it exists */ 15679 p_referred_by = get_header(req, "Referred-By"); 15680 15681 /* Give useful transfer information to the dialplan */ 15682 if (transferer->owner) { 15683 struct ast_channel *peer = ast_bridged_channel(transferer->owner); 15684 if (peer) { 15685 pbx_builtin_setvar_helper(peer, "SIPREFERRINGCONTEXT", transferer->context); 15686 pbx_builtin_setvar_helper(peer, "SIPREFERREDBYHDR", p_referred_by); 15687 } 15688 } 15689 15690 if (!ast_strlen_zero(p_referred_by)) { 15691 char *lessthan; 15692 h_referred_by = ast_strdupa(p_referred_by); 15693 15694 /* Store referrer's caller ID name */ 15695 ast_copy_string(referdata->referred_by_name, h_referred_by, sizeof(referdata->referred_by_name)); 15696 if ((lessthan = strchr(referdata->referred_by_name, '<'))) { 15697 *(lessthan - 1) = '\0'; /* Space */ 15698 } 15699 15700 referred_by_uri = get_in_brackets(h_referred_by); 15701 15702 if (!strncasecmp(referred_by_uri, "sip:", 4)) { 15703 referred_by_uri += 4; /* Skip sip: */ 15704 } else if (!strncasecmp(referred_by_uri, "sips:", 5)) { 15705 referred_by_uri += 5; /* Skip sips: */ 15706 } else { 15707 ast_log(LOG_WARNING, "Huh? Not a sip: header (Referred-by: %s). Skipping.\n", referred_by_uri); 15708 referred_by_uri = NULL; 15709 } 15710 } 15711 15712 /* Check for arguments in the refer_to header */ 15713 if ((ptr = strcasestr(refer_to, "replaces="))) { 15714 char *to = NULL, *from = NULL; 15715 15716 /* This is an attended transfer */ 15717 referdata->attendedtransfer = 1; 15718 ast_copy_string(referdata->replaces_callid, ptr+9, sizeof(referdata->replaces_callid)); 15719 ast_uri_decode(referdata->replaces_callid); 15720 if ((ptr = strchr(referdata->replaces_callid, ';'))) /* Find options */ { 15721 *ptr++ = '\0'; 15722 } 15723 15724 if (ptr) { 15725 /* Find the different tags before we destroy the string */ 15726 to = strcasestr(ptr, "to-tag="); 15727 from = strcasestr(ptr, "from-tag="); 15728 } 15729 15730 /* Grab the to header */ 15731 if (to) { 15732 ptr = to + 7; 15733 if ((to = strchr(ptr, '&'))) { 15734 *to = '\0'; 15735 } 15736 if ((to = strchr(ptr, ';'))) { 15737 *to = '\0'; 15738 } 15739 ast_copy_string(referdata->replaces_callid_totag, ptr, sizeof(referdata->replaces_callid_totag)); 15740 } 15741 15742 if (from) { 15743 ptr = from + 9; 15744 if ((to = strchr(ptr, '&'))) { 15745 *to = '\0'; 15746 } 15747 if ((to = strchr(ptr, ';'))) { 15748 *to = '\0'; 15749 } 15750 ast_copy_string(referdata->replaces_callid_fromtag, ptr, sizeof(referdata->replaces_callid_fromtag)); 15751 } 15752 15753 if (!strcmp(referdata->replaces_callid, transferer->callid) && 15754 (!sip_cfg.pedanticsipchecking || 15755 (!strcmp(referdata->replaces_callid_fromtag, transferer->theirtag) && 15756 !strcmp(referdata->replaces_callid_totag, transferer->tag)))) { 15757 ast_log(LOG_WARNING, "Got an attempt to replace own Call-ID on %s\n", transferer->callid); 15758 return -4; 15759 } 15760 15761 if (!sip_cfg.pedanticsipchecking) { 15762 ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s (No check of from/to tags)\n", referdata->replaces_callid ); 15763 } else { 15764 ast_debug(2, "Attended transfer: Will use Replace-Call-ID : %s F-tag: %s T-tag: %s\n", referdata->replaces_callid, referdata->replaces_callid_fromtag ? referdata->replaces_callid_fromtag : "<none>", referdata->replaces_callid_totag ? referdata->replaces_callid_totag : "<none>" ); 15765 } 15766 } 15767 15768 if ((ptr = strchr(refer_to, '@'))) { /* Separate domain */ 15769 char *urioption = NULL, *domain; 15770 int bracket = 0; 15771 *ptr++ = '\0'; 15772 15773 if ((urioption = strchr(ptr, ';'))) { /* Separate urioptions */ 15774 *urioption++ = '\0'; 15775 } 15776 15777 domain = ptr; 15778 15779 /* Remove :port */ 15780 for (; *ptr != '\0'; ++ptr) { 15781 if (*ptr == ':' && bracket == 0) { 15782 *ptr = '\0'; 15783 break; 15784 } else if (*ptr == '[') { 15785 ++bracket; 15786 } else if (*ptr == ']') { 15787 --bracket; 15788 } 15789 } 15790 15791 SIP_PEDANTIC_DECODE(domain); 15792 SIP_PEDANTIC_DECODE(urioption); 15793 15794 /* Save the domain for the dial plan */ 15795 ast_copy_string(referdata->refer_to_domain, domain, sizeof(referdata->refer_to_domain)); 15796 if (urioption) { 15797 ast_copy_string(referdata->refer_to_urioption, urioption, sizeof(referdata->refer_to_urioption)); 15798 } 15799 } 15800 15801 if ((ptr = strchr(refer_to, ';'))) /* Remove options */ 15802 *ptr = '\0'; 15803 15804 SIP_PEDANTIC_DECODE(refer_to); 15805 ast_copy_string(referdata->refer_to, refer_to, sizeof(referdata->refer_to)); 15806 15807 if (referred_by_uri) { 15808 if ((ptr = strchr(referred_by_uri, ';'))) /* Remove options */ 15809 *ptr = '\0'; 15810 SIP_PEDANTIC_DECODE(referred_by_uri); 15811 ast_copy_string(referdata->referred_by, referred_by_uri, sizeof(referdata->referred_by)); 15812 } else { 15813 referdata->referred_by[0] = '\0'; 15814 } 15815 15816 /* Determine transfer context */ 15817 if (transferer->owner) /* Mimic behaviour in res_features.c */ 15818 transfer_context = pbx_builtin_getvar_helper(transferer->owner, "TRANSFER_CONTEXT"); 15819 15820 /* By default, use the context in the channel sending the REFER */ 15821 if (ast_strlen_zero(transfer_context)) { 15822 transfer_context = S_OR(transferer->owner->macrocontext, 15823 S_OR(transferer->context, sip_cfg.default_context)); 15824 } 15825 15826 ast_copy_string(referdata->refer_to_context, transfer_context, sizeof(referdata->refer_to_context)); 15827 15828 /* Either an existing extension or the parking extension */ 15829 if (referdata->attendedtransfer || ast_exists_extension(NULL, transfer_context, refer_to, 1, NULL) ) { 15830 if (sip_debug_test_pvt(transferer)) { 15831 ast_verbose("SIP transfer to extension %s@%s by %s\n", refer_to, transfer_context, referred_by_uri); 15832 } 15833 /* We are ready to transfer to the extension */ 15834 return 0; 15835 } 15836 if (sip_debug_test_pvt(transferer)) 15837 ast_verbose("Failed SIP Transfer to non-existing extension %s in context %s\n n", refer_to, transfer_context); 15838 15839 /* Failure, we can't find this extension */ 15840 return -1; 15841 }
| static int get_rpid | ( | struct sip_pvt * | p, | |
| struct sip_request * | oreq | |||
| ) | [static] |
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.
Definition at line 15200 of file chan_sip.c.
References ast_copy_string(), ast_is_shrinkable_phonenumber(), AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED, AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN, AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED, AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN, ast_set_callerid(), ast_shrink_phone_number(), ast_skip_blanks(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, cid_name, cid_num, get_header(), and get_pai().
Referenced by check_peer_ok(), check_user_full(), handle_request_invite(), handle_request_update(), and handle_response_invite().
15201 { 15202 char tmp[256]; 15203 struct sip_request *req; 15204 char *cid_num = ""; 15205 char *cid_name = ""; 15206 int callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; 15207 char *privacy = ""; 15208 char *screen = ""; 15209 char *start, *end; 15210 15211 if (!ast_test_flag(&p->flags[0], SIP_TRUSTRPID)) 15212 return 0; 15213 req = oreq; 15214 if (!req) 15215 req = &p->initreq; 15216 ast_copy_string(tmp, get_header(req, "Remote-Party-ID"), sizeof(tmp)); 15217 if (ast_strlen_zero(tmp)) { 15218 return get_pai(p, req); 15219 } 15220 15221 start = tmp; 15222 if (*start == '"') { 15223 *start++ = '\0'; 15224 end = strchr(start, '"'); 15225 if (!end) 15226 return 0; 15227 *end++ = '\0'; 15228 cid_name = start; 15229 start = ast_skip_blanks(end); 15230 } 15231 15232 if (*start != '<') 15233 return 0; 15234 *start++ = '\0'; 15235 end = strchr(start, '@'); 15236 if (!end) 15237 return 0; 15238 *end++ = '\0'; 15239 if (strncasecmp(start, "sip:", 4)) 15240 return 0; 15241 cid_num = start + 4; 15242 if (global_shrinkcallerid && ast_is_shrinkable_phonenumber(cid_num)) 15243 ast_shrink_phone_number(cid_num); 15244 start = end; 15245 15246 end = strchr(start, '>'); 15247 if (!end) 15248 return 0; 15249 *end++ = '\0'; 15250 if (*end) { 15251 start = end; 15252 if (*start != ';') 15253 return 0; 15254 *start++ = '\0'; 15255 while (!ast_strlen_zero(start)) { 15256 end = strchr(start, ';'); 15257 if (end) 15258 *end++ = '\0'; 15259 if (!strncasecmp(start, "privacy=", 8)) 15260 privacy = start + 8; 15261 else if (!strncasecmp(start, "screen=", 7)) 15262 screen = start + 7; 15263 start = end; 15264 } 15265 15266 if (!strcasecmp(privacy, "full")) { 15267 if (!strcasecmp(screen, "yes")) 15268 callingpres = AST_PRES_PROHIB_USER_NUMBER_PASSED_SCREEN; 15269 else if (!strcasecmp(screen, "no")) 15270 callingpres = AST_PRES_PROHIB_USER_NUMBER_NOT_SCREENED; 15271 } else { 15272 if (!strcasecmp(screen, "yes")) 15273 callingpres = AST_PRES_ALLOWED_USER_NUMBER_PASSED_SCREEN; 15274 else if (!strcasecmp(screen, "no")) 15275 callingpres = AST_PRES_ALLOWED_USER_NUMBER_NOT_SCREENED; 15276 } 15277 } 15278 15279 /* Only return true if the supplied caller id is different */ 15280 if (!strcasecmp(p->cid_num, cid_num) && !strcasecmp(p->cid_name, cid_name) && p->callingpres == callingpres) 15281 return 0; 15282 15283 ast_string_field_set(p, cid_num, cid_num); 15284 ast_string_field_set(p, cid_name, cid_name); 15285 p->callingpres = callingpres; 15286 15287 if (p->owner) { 15288 ast_set_callerid(p->owner, cid_num, cid_name, NULL); 15289 p->owner->caller.id.name.presentation = callingpres; 15290 p->owner->caller.id.number.presentation = callingpres; 15291 } 15292 15293 return 1; 15294 }
| static const char * get_sdp_iterate | ( | int * | start, | |
| struct sip_request * | req, | |||
| const char * | name | |||
| ) | [static] |
Lookup 'name' in the SDP starting at the 'start' line. Returns the matching line, and 'start' is updated with the next line number.
Definition at line 7256 of file chan_sip.c.
References get_body_by_line(), and len().
Referenced by get_ip_and_port_from_sdp(), and process_sdp().
07257 { 07258 int len = strlen(name); 07259 07260 while (*start < (req->sdp_start + req->sdp_count)) { 07261 const char *r = get_body_by_line(REQ_OFFSET_TO_STR(req, line[(*start)++]), name, len, '='); 07262 if (r[0] != '\0') 07263 return r; 07264 } 07265 07266 /* if the line was not found, ensure that *start points past the SDP */ 07267 (*start)++; 07268 07269 return ""; 07270 }
| static char get_sdp_line | ( | int * | start, | |
| int | stop, | |||
| struct sip_request * | req, | |||
| const char ** | value | |||
| ) | [static] |
Fetches the next valid SDP line between the 'start' line (inclusive) and the 'stop' line (exclusive). Returns the type ('a', 'c', ...) and matching line in reference 'start' is updated with the next line number.
Definition at line 7277 of file chan_sip.c.
References ast_skip_blanks(), and type.
Referenced by process_sdp().
07278 { 07279 char type = '\0'; 07280 const char *line = NULL; 07281 07282 if (stop > (req->sdp_start + req->sdp_count)) { 07283 stop = req->sdp_start + req->sdp_count; 07284 } 07285 07286 while (*start < stop) { 07287 line = REQ_OFFSET_TO_STR(req, line[(*start)++]); 07288 if (line[1] == '=') { 07289 type = line[0]; 07290 *value = ast_skip_blanks(line + 2); 07291 break; 07292 } 07293 } 07294 07295 return type; 07296 }
| static struct sip_pvt * get_sip_pvt_byid_locked | ( | const char * | callid, | |
| const char * | totag, | |||
| const char * | fromtag | |||
| ) | [static, read] |
Lock dialog lock and find matching pvt lock.
Definition at line 15551 of file chan_sip.c.
References ao2_t_find, ast_channel_trylock, ast_debug, ast_strlen_zero(), OBJ_POINTER, sip_cfg, sip_pvt_lock, sip_pvt_unlock, and TRUE.
Referenced by handle_request_invite(), and local_attended_transfer().
15552 { 15553 struct sip_pvt *sip_pvt_ptr; 15554 struct sip_pvt tmp_dialog = { 15555 .callid = callid, 15556 }; 15557 15558 if (totag) { 15559 ast_debug(4, "Looking for callid %s (fromtag %s totag %s)\n", callid, fromtag ? fromtag : "<no fromtag>", totag ? totag : "<no totag>"); 15560 } 15561 15562 /* Search dialogs and find the match */ 15563 15564 sip_pvt_ptr = ao2_t_find(dialogs, &tmp_dialog, OBJ_POINTER, "ao2_find of dialog in dialogs table"); 15565 if (sip_pvt_ptr) { 15566 /* Go ahead and lock it (and its owner) before returning */ 15567 sip_pvt_lock(sip_pvt_ptr); 15568 if (sip_cfg.pedanticsipchecking) { 15569 unsigned char frommismatch = 0, tomismatch = 0; 15570 15571 if (ast_strlen_zero(fromtag)) { 15572 sip_pvt_unlock(sip_pvt_ptr); 15573 ast_debug(4, "Matched %s call for callid=%s - no from tag specified, pedantic check fails\n", 15574 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid); 15575 return NULL; 15576 } 15577 15578 if (ast_strlen_zero(totag)) { 15579 sip_pvt_unlock(sip_pvt_ptr); 15580 ast_debug(4, "Matched %s call for callid=%s - no to tag specified, pedantic check fails\n", 15581 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid); 15582 return NULL; 15583 } 15584 /* RFC 3891 15585 * > 3. User Agent Server Behavior: Receiving a Replaces Header 15586 * > The Replaces header contains information used to match an existing 15587 * > SIP dialog (call-id, to-tag, and from-tag). Upon receiving an INVITE 15588 * > with a Replaces header, the User Agent (UA) attempts to match this 15589 * > information with a confirmed or early dialog. The User Agent Server 15590 * > (UAS) matches the to-tag and from-tag parameters as if they were tags 15591 * > present in an incoming request. In other words, the to-tag parameter 15592 * > is compared to the local tag, and the from-tag parameter is compared 15593 * > to the remote tag. 15594 * 15595 * Thus, the totag is always compared to the local tag, regardless if 15596 * this our call is an incoming or outgoing call. 15597 */ 15598 frommismatch = !!strcmp(fromtag, sip_pvt_ptr->theirtag); 15599 tomismatch = !!strcmp(totag, sip_pvt_ptr->tag); 15600 15601 if (frommismatch || tomismatch) { 15602 sip_pvt_unlock(sip_pvt_ptr); 15603 if (frommismatch) { 15604 ast_debug(4, "Matched %s call for callid=%s - pedantic from tag check fails; their tag is %s our tag is %s\n", 15605 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid, 15606 fromtag, sip_pvt_ptr->theirtag); 15607 } 15608 if (tomismatch) { 15609 ast_debug(4, "Matched %s call for callid=%s - pedantic to tag check fails; their tag is %s our tag is %s\n", 15610 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", sip_pvt_ptr->callid, 15611 totag, sip_pvt_ptr->tag); 15612 } 15613 return NULL; 15614 } 15615 } 15616 15617 if (totag) 15618 ast_debug(4, "Matched %s call - their tag is %s Our tag is %s\n", 15619 sip_pvt_ptr->outgoing_call == TRUE ? "OUTGOING": "INCOMING", 15620 sip_pvt_ptr->theirtag, sip_pvt_ptr->tag); 15621 15622 /* deadlock avoidance... */ 15623 while (sip_pvt_ptr->owner && ast_channel_trylock(sip_pvt_ptr->owner)) { 15624 sip_pvt_unlock(sip_pvt_ptr); 15625 usleep(1); 15626 sip_pvt_lock(sip_pvt_ptr); 15627 } 15628 } 15629 15630 return sip_pvt_ptr; 15631 }
| static const char* get_srv_protocol | ( | enum sip_transport | t | ) | [inline, static] |
Return protocol string for srv dns query.
Definition at line 3289 of file chan_sip.c.
Referenced by __sip_subscribe_mwi_do(), build_peer(), create_addr(), and transmit_register().
| static const char* get_srv_service | ( | enum sip_transport | t | ) | [inline, static] |
Return service string for srv dns query.
Definition at line 3303 of file chan_sip.c.
Referenced by __sip_subscribe_mwi_do(), build_peer(), create_addr(), and transmit_register().
| static const char* get_transport | ( | enum sip_transport | t | ) | [inline, static] |
Return transport as string.
Definition at line 3274 of file chan_sip.c.
Referenced by _sip_show_peer(), ast_sip_ouraddrfor(), build_contact(), get_transport_pvt(), handle_request_do(), parse_moved_contact(), sip_show_settings(), sip_show_tcp(), and transmit_notify_with_mwi().
| static const char* get_transport_list | ( | unsigned int | transports | ) | [inline, static] |
Return configuration of transports for a device.
Definition at line 3253 of file chan_sip.c.
Referenced by _sip_show_peer(), peers_data_provider_get(), and sip_show_settings().
03253 { 03254 switch (transports) { 03255 case SIP_TRANSPORT_UDP: 03256 return "UDP"; 03257 case SIP_TRANSPORT_TCP: 03258 return "TCP"; 03259 case SIP_TRANSPORT_TLS: 03260 return "TLS"; 03261 case SIP_TRANSPORT_UDP | SIP_TRANSPORT_TCP: 03262 return "TCP,UDP"; 03263 case SIP_TRANSPORT_UDP | SIP_TRANSPORT_TLS: 03264 return "TLS,UDP"; 03265 case SIP_TRANSPORT_TCP | SIP_TRANSPORT_TLS: 03266 return "TLS,TCP"; 03267 default: 03268 return transports ? 03269 "TLS,TCP,UDP" : "UNKNOWN"; 03270 } 03271 }
| static const char* get_transport_pvt | ( | struct sip_pvt * | p | ) | [inline, static] |
Return transport of dialog.
Definition at line 3321 of file chan_sip.c.
References get_transport(), and set_socket_transport().
Referenced by __sip_xmit(), and build_via().
03322 { 03323 if (p->outboundproxy && p->outboundproxy->transport) { 03324 set_socket_transport(&p->socket, p->outboundproxy->transport); 03325 } 03326 03327 return get_transport(p->socket.type); 03328 }
| static int get_transport_str2enum | ( | const char * | transport | ) | [static] |
Return int representing a bit field of transport types found in const char *transport.
Definition at line 3231 of file chan_sip.c.
References ast_strlen_zero().
Referenced by __set_address_from_contact(), and parse_register_contact().
03232 { 03233 int res = 0; 03234 03235 if (ast_strlen_zero(transport)) { 03236 return res; 03237 } 03238 03239 if (!strcasecmp(transport, "udp")) { 03240 res |= SIP_TRANSPORT_UDP; 03241 } 03242 if (!strcasecmp(transport, "tcp")) { 03243 res |= SIP_TRANSPORT_TCP; 03244 } 03245 if (!strcasecmp(transport, "tls")) { 03246 res |= SIP_TRANSPORT_TLS; 03247 } 03248 03249 return res; 03250 }
| static const char * gettag | ( | const struct sip_request * | req, | |
| const char * | header, | |||
| char * | tagbuf, | |||
| int | tagbufsize | |||
| ) | [static] |
Get tag from packet.
Definition at line 21779 of file chan_sip.c.
References ast_copy_string(), and get_header().
Referenced by find_call(), handle_incoming(), handle_request_subscribe(), and handle_response().
21780 { 21781 const char *thetag; 21782 21783 if (!tagbuf) 21784 return NULL; 21785 tagbuf[0] = '\0'; /* reset the buffer */ 21786 thetag = get_header(req, header); 21787 thetag = strcasestr(thetag, ";tag="); 21788 if (thetag) { 21789 thetag += 5; 21790 ast_copy_string(tagbuf, thetag, tagbufsize); 21791 return strsep(&tagbuf, ";"); 21792 } 21793 return NULL; 21794 }
| static int handle_cc_notify | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
Definition at line 21796 of file chan_sip.c.
References ao2_callback, ao2_ref, ast_cc_monitor_callee_available(), ast_cc_monitor_request_acked(), ast_string_field_set, ast_strlen_zero(), construct_pidf_body(), find_sip_monitor_instance_by_subscription_pvt(), get_body(), get_header(), get_in_brackets(), status, transmit_publish(), and transmit_response().
Referenced by handle_request_notify().
21797 { 21798 struct sip_monitor_instance *monitor_instance = ao2_callback(sip_monitor_instances, 0, 21799 find_sip_monitor_instance_by_subscription_pvt, pvt); 21800 const char *status = get_body(req, "cc-state", ':'); 21801 struct cc_epa_entry *cc_entry; 21802 char *uri; 21803 21804 if (!monitor_instance) { 21805 transmit_response(pvt, "400 Bad Request", req); 21806 return -1; 21807 } 21808 21809 if (ast_strlen_zero(status)) { 21810 ao2_ref(monitor_instance, -1); 21811 transmit_response(pvt, "400 Bad Request", req); 21812 return -1; 21813 } 21814 21815 if (!strcmp(status, "queued")) { 21816 /* We've been told that we're queued. This is the endpoint's way of telling 21817 * us that it has accepted our CC request. We need to alert the core of this 21818 * development 21819 */ 21820 ast_cc_monitor_request_acked(monitor_instance->core_id, "SIP endpoint %s accepted request", monitor_instance->device_name); 21821 transmit_response(pvt, "200 OK", req); 21822 ao2_ref(monitor_instance, -1); 21823 return 0; 21824 } 21825 21826 /* It's open! Yay! */ 21827 uri = get_body(req, "cc-URI", ':'); 21828 if (ast_strlen_zero(uri)) { 21829 uri = get_in_brackets((char *)get_header(req, "From")); 21830 } 21831 21832 ast_string_field_set(monitor_instance, notify_uri, uri); 21833 if (monitor_instance->suspension_entry) { 21834 cc_entry = monitor_instance->suspension_entry->instance_data; 21835 if (cc_entry->current_state == CC_CLOSED) { 21836 /* If we've created a suspension entry and the current state is closed, then that means 21837 * we got a notice from the CC core earlier to suspend monitoring, but because this particular 21838 * call leg had not yet notified us that it was ready for recall, it meant that we 21839 * could not yet send a PUBLISH. Now, however, we can. 21840 */ 21841 construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body, 21842 sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername); 21843 transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_INITIAL, monitor_instance->notify_uri); 21844 } else { 21845 ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available"); 21846 } 21847 } else { 21848 ast_cc_monitor_callee_available(monitor_instance->core_id, "SIP monitored callee has become available"); 21849 } 21850 ao2_ref(monitor_instance, -1); 21851 transmit_response(pvt, "200 OK", req); 21852 21853 return 0; 21854 }
| static int handle_cc_subscribe | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Definition at line 24624 of file chan_sip.c.
References ao2_ref, ast_cc_agent_accept_request(), ast_cc_failed(), ast_log(), ast_strlen_zero(), ast_cc_agent::core_id, ast_cc_agent::device_name, find_sip_cc_agent_by_subscribe_uri(), get_header(), LOG_WARNING, ast_cc_agent::private_data, and transmit_response().
Referenced by handle_request_subscribe().
24625 { 24626 const char *uri = REQ_OFFSET_TO_STR(req, rlPart2); 24627 char *param_separator; 24628 struct ast_cc_agent *agent; 24629 struct sip_cc_agent_pvt *agent_pvt; 24630 const char *expires_str = get_header(req, "Expires"); 24631 int expires = -1; /* Just need it to be non-zero */ 24632 24633 if (!ast_strlen_zero(expires_str)) { 24634 sscanf(expires_str, "%d", &expires); 24635 } 24636 24637 if ((param_separator = strchr(uri, ';'))) { 24638 *param_separator = '\0'; 24639 } 24640 24641 p->subscribed = CALL_COMPLETION; 24642 24643 if (!(agent = find_sip_cc_agent_by_subscribe_uri(uri))) { 24644 if (!expires) { 24645 /* Typically, if a 0 Expires reaches us and we can't find 24646 * the corresponding agent, it means that the CC transaction 24647 * has completed and so the calling side is just trying to 24648 * clean up its subscription. We'll just respond with a 24649 * 200 OK and be done with it 24650 */ 24651 transmit_response(p, "200 OK", req); 24652 return 0; 24653 } 24654 ast_log(LOG_WARNING, "Invalid URI '%s' in CC subscribe\n", uri); 24655 transmit_response(p, "404 Not Found", req); 24656 return -1; 24657 } 24658 24659 agent_pvt = agent->private_data; 24660 24661 if (!expires) { 24662 /* We got sent a SUBSCRIBE and found an agent. This means that CC 24663 * is being canceled. 24664 */ 24665 ast_cc_failed(agent->core_id, "CC is being canceled by %s", agent->device_name); 24666 transmit_response(p, "200 OK", req); 24667 ao2_ref(agent, -1); 24668 return 0; 24669 } 24670 24671 agent_pvt->subscribe_pvt = dialog_ref(p, "SIP CC agent gains reference to subscription dialog"); 24672 ast_cc_agent_accept_request(agent->core_id, "SIP caller %s has requested CC via SUBSCRIBE", 24673 agent->device_name); 24674 24675 /* We don't send a response here. That is done in the agent's ack callback or in the 24676 * agent destructor, should a failure occur before we have responded 24677 */ 24678 ao2_ref(agent, -1); 24679 return 0; 24680 }
| static int handle_common_options | ( | struct ast_flags * | flags, | |
| struct ast_flags * | mask, | |||
| struct ast_variable * | v | |||
| ) | [static] |
Handle flag-type options common to configuration of devices - peers.
| flags | array of two struct ast_flags | |
| mask | array of two struct ast_flags | |
| v | linked list of config variables to process |
Definition at line 26895 of file chan_sip.c.
References ast_clear_flag, ast_copy_string(), ast_false(), ast_log(), ast_set2_flag, ast_set_flag, ast_strdupa, ast_true(), ast_variable::lineno, LOG_WARNING, ast_variable::name, set_insecure_flags(), ast_variable::value, and word.
Referenced by build_peer(), and reload_config().
26896 { 26897 int res = 1; 26898 26899 if (!strcasecmp(v->name, "trustrpid")) { 26900 ast_set_flag(&mask[0], SIP_TRUSTRPID); 26901 ast_set2_flag(&flags[0], ast_true(v->value), SIP_TRUSTRPID); 26902 } else if (!strcasecmp(v->name, "sendrpid")) { 26903 ast_set_flag(&mask[0], SIP_SENDRPID); 26904 if (!strcasecmp(v->value, "pai")) { 26905 ast_set_flag(&flags[0], SIP_SENDRPID_PAI); 26906 } else if (!strcasecmp(v->value, "rpid")) { 26907 ast_set_flag(&flags[0], SIP_SENDRPID_RPID); 26908 } else if (ast_true(v->value)) { 26909 ast_set_flag(&flags[0], SIP_SENDRPID_RPID); 26910 } 26911 } else if (!strcasecmp(v->name, "rpid_update")) { 26912 ast_set_flag(&mask[1], SIP_PAGE2_RPID_UPDATE); 26913 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RPID_UPDATE); 26914 } else if (!strcasecmp(v->name, "rpid_immediate")) { 26915 ast_set_flag(&mask[1], SIP_PAGE2_RPID_IMMEDIATE); 26916 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RPID_IMMEDIATE); 26917 } else if (!strcasecmp(v->name, "g726nonstandard")) { 26918 ast_set_flag(&mask[0], SIP_G726_NONSTANDARD); 26919 ast_set2_flag(&flags[0], ast_true(v->value), SIP_G726_NONSTANDARD); 26920 } else if (!strcasecmp(v->name, "useclientcode")) { 26921 ast_set_flag(&mask[0], SIP_USECLIENTCODE); 26922 ast_set2_flag(&flags[0], ast_true(v->value), SIP_USECLIENTCODE); 26923 } else if (!strcasecmp(v->name, "dtmfmode")) { 26924 ast_set_flag(&mask[0], SIP_DTMF); 26925 ast_clear_flag(&flags[0], SIP_DTMF); 26926 if (!strcasecmp(v->value, "inband")) 26927 ast_set_flag(&flags[0], SIP_DTMF_INBAND); 26928 else if (!strcasecmp(v->value, "rfc2833")) 26929 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 26930 else if (!strcasecmp(v->value, "info")) 26931 ast_set_flag(&flags[0], SIP_DTMF_INFO); 26932 else if (!strcasecmp(v->value, "shortinfo")) 26933 ast_set_flag(&flags[0], SIP_DTMF_SHORTINFO); 26934 else if (!strcasecmp(v->value, "auto")) 26935 ast_set_flag(&flags[0], SIP_DTMF_AUTO); 26936 else { 26937 ast_log(LOG_WARNING, "Unknown dtmf mode '%s' on line %d, using rfc2833\n", v->value, v->lineno); 26938 ast_set_flag(&flags[0], SIP_DTMF_RFC2833); 26939 } 26940 } else if (!strcasecmp(v->name, "nat")) { 26941 ast_set_flag(&mask[0], SIP_NAT_FORCE_RPORT); 26942 ast_set_flag(&flags[0], SIP_NAT_FORCE_RPORT); /* Default to "force_rport" */ 26943 if (!strcasecmp(v->value, "no")) { 26944 ast_clear_flag(&flags[0], SIP_NAT_FORCE_RPORT); 26945 } else if (!strcasecmp(v->value, "yes")) { 26946 /* We've already defaulted to force_rport */ 26947 ast_set_flag(&mask[1], SIP_PAGE2_SYMMETRICRTP); 26948 ast_set_flag(&flags[1], SIP_PAGE2_SYMMETRICRTP); 26949 } else if (!strcasecmp(v->value, "comedia")) { 26950 ast_clear_flag(&flags[0], SIP_NAT_FORCE_RPORT); 26951 ast_set_flag(&mask[1], SIP_PAGE2_SYMMETRICRTP); 26952 ast_set_flag(&flags[1], SIP_PAGE2_SYMMETRICRTP); 26953 } 26954 } else if (!strcasecmp(v->name, "directmedia") || !strcasecmp(v->name, "canreinvite")) { 26955 ast_set_flag(&mask[0], SIP_REINVITE); 26956 ast_clear_flag(&flags[0], SIP_REINVITE); 26957 if (ast_true(v->value)) { 26958 ast_set_flag(&flags[0], SIP_DIRECT_MEDIA | SIP_DIRECT_MEDIA_NAT); 26959 } else if (!ast_false(v->value)) { 26960 char buf[64]; 26961 char *word, *next = buf; 26962 26963 ast_copy_string(buf, v->value, sizeof(buf)); 26964 while ((word = strsep(&next, ","))) { 26965 if (!strcasecmp(word, "update")) { 26966 ast_set_flag(&flags[0], SIP_REINVITE_UPDATE | SIP_DIRECT_MEDIA); 26967 } else if (!strcasecmp(word, "nonat")) { 26968 ast_set_flag(&flags[0], SIP_DIRECT_MEDIA); 26969 ast_clear_flag(&flags[0], SIP_DIRECT_MEDIA_NAT); 26970 } else { 26971 ast_log(LOG_WARNING, "Unknown directmedia mode '%s' on line %d\n", v->value, v->lineno); 26972 } 26973 } 26974 } 26975 } else if (!strcasecmp(v->name, "insecure")) { 26976 ast_set_flag(&mask[0], SIP_INSECURE); 26977 ast_clear_flag(&flags[0], SIP_INSECURE); 26978 set_insecure_flags(&flags[0], v->value, v->lineno); 26979 } else if (!strcasecmp(v->name, "progressinband")) { 26980 ast_set_flag(&mask[0], SIP_PROG_INBAND); 26981 ast_clear_flag(&flags[0], SIP_PROG_INBAND); 26982 if (ast_true(v->value)) 26983 ast_set_flag(&flags[0], SIP_PROG_INBAND_YES); 26984 else if (strcasecmp(v->value, "never")) 26985 ast_set_flag(&flags[0], SIP_PROG_INBAND_NO); 26986 } else if (!strcasecmp(v->name, "promiscredir")) { 26987 ast_set_flag(&mask[0], SIP_PROMISCREDIR); 26988 ast_set2_flag(&flags[0], ast_true(v->value), SIP_PROMISCREDIR); 26989 } else if (!strcasecmp(v->name, "videosupport")) { 26990 if (!strcasecmp(v->value, "always")) { 26991 ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 26992 ast_set_flag(&flags[1], SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 26993 } else { 26994 ast_set_flag(&mask[1], SIP_PAGE2_VIDEOSUPPORT); 26995 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_VIDEOSUPPORT); 26996 } 26997 } else if (!strcasecmp(v->name, "textsupport")) { 26998 ast_set_flag(&mask[1], SIP_PAGE2_TEXTSUPPORT); 26999 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_TEXTSUPPORT); 27000 res = 1; 27001 } else if (!strcasecmp(v->name, "allowoverlap")) { 27002 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWOVERLAP); 27003 ast_clear_flag(&flags[1], SIP_PAGE2_ALLOWOVERLAP); 27004 if (ast_true(v->value)) { 27005 ast_set_flag(&flags[1], SIP_PAGE2_ALLOWOVERLAP_YES); 27006 } else if (!strcasecmp(v->value, "dtmf")){ 27007 ast_set_flag(&flags[1], SIP_PAGE2_ALLOWOVERLAP_DTMF); 27008 } 27009 } else if (!strcasecmp(v->name, "allowsubscribe")) { 27010 ast_set_flag(&mask[1], SIP_PAGE2_ALLOWSUBSCRIBE); 27011 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_ALLOWSUBSCRIBE); 27012 } else if (!strcasecmp(v->name, "ignoresdpversion")) { 27013 ast_set_flag(&mask[1], SIP_PAGE2_IGNORESDPVERSION); 27014 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_IGNORESDPVERSION); 27015 } else if (!strcasecmp(v->name, "faxdetect")) { 27016 ast_set_flag(&mask[1], SIP_PAGE2_FAX_DETECT); 27017 if (ast_true(v->value)) { 27018 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_BOTH); 27019 } else if (ast_false(v->value)) { 27020 ast_clear_flag(&flags[1], SIP_PAGE2_FAX_DETECT_BOTH); 27021 } else { 27022 char *buf = ast_strdupa(v->value); 27023 char *word, *next = buf; 27024 27025 while ((word = strsep(&next, ","))) { 27026 if (!strcasecmp(word, "cng")) { 27027 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_CNG); 27028 } else if (!strcasecmp(word, "t38")) { 27029 ast_set_flag(&flags[1], SIP_PAGE2_FAX_DETECT_T38); 27030 } else { 27031 ast_log(LOG_WARNING, "Unknown faxdetect mode '%s' on line %d.\n", word, v->lineno); 27032 } 27033 } 27034 } 27035 } else if (!strcasecmp(v->name, "rfc2833compensate")) { 27036 ast_set_flag(&mask[1], SIP_PAGE2_RFC2833_COMPENSATE); 27037 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_RFC2833_COMPENSATE); 27038 } else if (!strcasecmp(v->name, "buggymwi")) { 27039 ast_set_flag(&mask[1], SIP_PAGE2_BUGGY_MWI); 27040 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_BUGGY_MWI); 27041 } else 27042 res = 0; 27043 27044 return res; 27045 }
| static int handle_incoming | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct ast_sockaddr * | addr, | |||
| int * | recount, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming SIP requests (methods).
Definition at line 25138 of file chan_sip.c.
References __get_header(), __sip_ack(), ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_debug, ast_log(), ast_random(), ast_skip_blanks(), ast_sockaddr_stringify(), ast_string_field_set, ast_strlen_zero(), ast_verbose, check_pendings(), extract_uri(), find_sdp(), get_header(), gettag(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_options(), handle_request_publish(), handle_request_refer(), handle_request_register(), handle_request_subscribe(), handle_request_update(), handle_response(), cfsip_methods::id, len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, pbx_builtin_setvar_helper(), process_sdp(), pvt_set_needdestroy(), sip_cfg, sip_debug_test_pvt(), sip_methods, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), cfsip_methods::text, transmit_response(), transmit_response_reliable(), transmit_response_with_allow(), and transmit_response_with_retry_after().
Referenced by handle_request_do().
25139 { 25140 /* Called with p->lock held, as well as p->owner->lock if appropriate, keeping things 25141 relatively static */ 25142 const char *cmd; 25143 const char *cseq; 25144 const char *useragent; 25145 const char *via; 25146 const char *callid; 25147 int via_pos = 0; 25148 uint32_t seqno; 25149 int len; 25150 int respid; 25151 int res = 0; 25152 int debug = sip_debug_test_pvt(p); 25153 const char *e; 25154 int error = 0; 25155 int oldmethod = p->method; 25156 int acked = 0; 25157 25158 /* RFC 3261 - 8.1.1 A valid SIP request must contain To, From, CSeq, Call-ID and Via. 25159 * 8.2.6.2 Response must have To, From, Call-ID CSeq, and Via related to the request, 25160 * so we can check to make sure these fields exist for all requests and responses */ 25161 cseq = get_header(req, "Cseq"); 25162 cmd = REQ_OFFSET_TO_STR(req, header[0]); 25163 /* Save the via_pos so we can check later that responses only have 1 Via header */ 25164 via = __get_header(req, "Via", &via_pos); 25165 /* This must exist already because we've called find_call by now */ 25166 callid = get_header(req, "Call-ID"); 25167 25168 /* Must have Cseq */ 25169 if (ast_strlen_zero(cmd) || ast_strlen_zero(cseq) || ast_strlen_zero(via)) { 25170 ast_log(LOG_ERROR, "Dropping this SIP message with Call-ID '%s', it's incomplete.\n", callid); 25171 error = 1; 25172 } 25173 if (!error && sscanf(cseq, "%30u%n", &seqno, &len) != 1) { 25174 ast_log(LOG_ERROR, "No seqno in '%s'. Dropping incomplete message.\n", cmd); 25175 error = 1; 25176 } 25177 if (error) { 25178 if (!p->initreq.headers) { /* New call */ 25179 pvt_set_needdestroy(p, "no headers"); 25180 } 25181 return -1; 25182 } 25183 /* Get the command XXX */ 25184 25185 cmd = REQ_OFFSET_TO_STR(req, rlPart1); 25186 e = ast_skip_blanks(REQ_OFFSET_TO_STR(req, rlPart2)); 25187 25188 /* Save useragent of the client */ 25189 useragent = get_header(req, "User-Agent"); 25190 if (!ast_strlen_zero(useragent)) 25191 ast_string_field_set(p, useragent, useragent); 25192 25193 /* Find out SIP method for incoming request */ 25194 if (req->method == SIP_RESPONSE) { /* Response to our request */ 25195 /* ignore means "don't do anything with it" but still have to 25196 * respond appropriately. 25197 * But in this case this is a response already, so we really 25198 * have nothing to do with this message, and even setting the 25199 * ignore flag is pointless. 25200 */ 25201 if (ast_strlen_zero(e)) { 25202 return 0; 25203 } 25204 if (sscanf(e, "%30d %n", &respid, &len) != 1) { 25205 ast_log(LOG_WARNING, "Invalid response: '%s'\n", e); 25206 return 0; 25207 } 25208 if (respid <= 0) { 25209 ast_log(LOG_WARNING, "Invalid SIP response code: '%d'\n", respid); 25210 return 0; 25211 } 25212 /* RFC 3261 - 8.1.3.3 If more than one Via header field value is present in a reponse 25213 * the UAC SHOULD discard the message. This is not perfect, as it will not catch multiple 25214 * headers joined with a comma. Fixing that would pretty much involve writing a new parser */ 25215 if (!ast_strlen_zero(__get_header(req, "via", &via_pos))) { 25216 ast_log(LOG_WARNING, "Misrouted SIP response '%s' with Call-ID '%s', too many vias\n", e, callid); 25217 return 0; 25218 } 25219 if (p->ocseq && (p->ocseq < seqno)) { 25220 ast_debug(1, "Ignoring out of order response %u (expecting %u)\n", seqno, p->ocseq); 25221 return -1; 25222 } else { 25223 char causevar[256], causeval[256]; 25224 25225 if ((respid == 200) || ((respid >= 300) && (respid <= 399))) { 25226 extract_uri(p, req); 25227 } 25228 25229 handle_response(p, respid, e + len, req, seqno); 25230 25231 if (global_store_sip_cause && p->owner) { 25232 struct ast_channel *owner = p->owner; 25233 25234 snprintf(causevar, sizeof(causevar), "MASTER_CHANNEL(HASH(SIP_CAUSE,%s))", owner->name); 25235 snprintf(causeval, sizeof(causeval), "SIP %s", REQ_OFFSET_TO_STR(req, rlPart2)); 25236 25237 ast_channel_ref(owner); 25238 sip_pvt_unlock(p); 25239 ast_channel_unlock(owner); 25240 *nounlock = 1; 25241 pbx_builtin_setvar_helper(owner, causevar, causeval); 25242 ast_channel_unref(owner); 25243 sip_pvt_lock(p); 25244 } 25245 } 25246 return 0; 25247 } 25248 25249 /* New SIP request coming in 25250 (could be new request in existing SIP dialog as well...) 25251 */ 25252 25253 p->method = req->method; /* Find out which SIP method they are using */ 25254 ast_debug(4, "**** Received %s (%d) - Command in SIP %s\n", sip_methods[p->method].text, sip_methods[p->method].id, cmd); 25255 25256 if (p->icseq && (p->icseq > seqno) ) { 25257 if (p->pendinginvite && seqno == p->pendinginvite && (req->method == SIP_ACK || req->method == SIP_CANCEL)) { 25258 ast_debug(2, "Got CANCEL or ACK on INVITE with transactions in between.\n"); 25259 } else { 25260 ast_debug(1, "Ignoring too old SIP packet packet %u (expecting >= %u)\n", seqno, p->icseq); 25261 if (req->method == SIP_INVITE) { 25262 unsigned int ran = (ast_random() % 10) + 1; 25263 char seconds[4]; 25264 snprintf(seconds, sizeof(seconds), "%u", ran); 25265 transmit_response_with_retry_after(p, "500 Server error", req, seconds); /* respond according to RFC 3261 14.2 with Retry-After betwewn 0 and 10 */ 25266 } else if (req->method != SIP_ACK) { 25267 transmit_response(p, "500 Server error", req); /* We must respond according to RFC 3261 sec 12.2 */ 25268 } 25269 return -1; 25270 } 25271 } else if (p->icseq && 25272 p->icseq == seqno && 25273 req->method != SIP_ACK && 25274 (p->method != SIP_CANCEL || p->alreadygone)) { 25275 /* ignore means "don't do anything with it" but still have to 25276 respond appropriately. We do this if we receive a repeat of 25277 the last sequence number */ 25278 req->ignore = 1; 25279 ast_debug(3, "Ignoring SIP message because of retransmit (%s Seqno %u, ours %u)\n", sip_methods[p->method].text, p->icseq, seqno); 25280 } 25281 25282 /* RFC 3261 section 9. "CANCEL has no effect on a request to which a UAS has 25283 * already given a final response." */ 25284 if (!p->pendinginvite && (req->method == SIP_CANCEL)) { 25285 transmit_response(p, "481 Call/Transaction Does Not Exist", req); 25286 return res; 25287 } 25288 25289 if (seqno >= p->icseq) 25290 /* Next should follow monotonically (but not necessarily 25291 incrementally -- thanks again to the genius authors of SIP -- 25292 increasing */ 25293 p->icseq = seqno; 25294 25295 /* Find their tag if we haven't got it */ 25296 if (ast_strlen_zero(p->theirtag)) { 25297 char tag[128]; 25298 25299 gettag(req, "From", tag, sizeof(tag)); 25300 ast_string_field_set(p, theirtag, tag); 25301 } 25302 snprintf(p->lastmsg, sizeof(p->lastmsg), "Rx: %s", cmd); 25303 25304 if (sip_cfg.pedanticsipchecking) { 25305 /* If this is a request packet without a from tag, it's not 25306 correct according to RFC 3261 */ 25307 /* Check if this a new request in a new dialog with a totag already attached to it, 25308 RFC 3261 - section 12.2 - and we don't want to mess with recovery */ 25309 if (!p->initreq.headers && req->has_to_tag) { 25310 /* If this is a first request and it got a to-tag, it is not for us */ 25311 if (!req->ignore && req->method == SIP_INVITE) { 25312 /* Just because we think this is a dialog-starting INVITE with a to-tag 25313 * doesn't mean it actually is. It could be a reinvite for an established, but 25314 * unknown dialog. In such a case, we need to change our tag to the 25315 * incoming INVITE's to-tag so that they will recognize the 481 we send and 25316 * so that we will properly match their incoming ACK. 25317 */ 25318 char totag[128]; 25319 gettag(req, "To", totag, sizeof(totag)); 25320 ast_string_field_set(p, tag, totag); 25321 p->pendinginvite = p->icseq; 25322 transmit_response_reliable(p, "481 Call/Transaction Does Not Exist", req); 25323 /* Will cease to exist after ACK */ 25324 return res; 25325 } else if (req->method != SIP_ACK) { 25326 transmit_response(p, "481 Call/Transaction Does Not Exist", req); 25327 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 25328 return res; 25329 } 25330 /* Otherwise, this is an ACK. It will always have a to-tag */ 25331 } 25332 } 25333 25334 if (!e && (p->method == SIP_INVITE || p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER || p->method == SIP_NOTIFY || p->method == SIP_PUBLISH)) { 25335 transmit_response(p, "400 Bad request", req); 25336 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 25337 return -1; 25338 } 25339 25340 /* Handle various incoming SIP methods in requests */ 25341 switch (p->method) { 25342 case SIP_OPTIONS: 25343 res = handle_request_options(p, req, addr, e); 25344 break; 25345 case SIP_INVITE: 25346 res = handle_request_invite(p, req, debug, seqno, addr, recount, e, nounlock); 25347 break; 25348 case SIP_REFER: 25349 res = handle_request_refer(p, req, debug, seqno, nounlock); 25350 break; 25351 case SIP_CANCEL: 25352 res = handle_request_cancel(p, req); 25353 break; 25354 case SIP_BYE: 25355 res = handle_request_bye(p, req); 25356 break; 25357 case SIP_MESSAGE: 25358 res = handle_request_message(p, req); 25359 break; 25360 case SIP_PUBLISH: 25361 res = handle_request_publish(p, req, addr, seqno, e); 25362 break; 25363 case SIP_SUBSCRIBE: 25364 res = handle_request_subscribe(p, req, addr, seqno, e); 25365 break; 25366 case SIP_REGISTER: 25367 res = handle_request_register(p, req, addr, e); 25368 break; 25369 case SIP_INFO: 25370 if (req->debug) 25371 ast_verbose("Receiving INFO!\n"); 25372 if (!req->ignore) 25373 handle_request_info(p, req); 25374 else /* if ignoring, transmit response */ 25375 transmit_response(p, "200 OK", req); 25376 break; 25377 case SIP_NOTIFY: 25378 res = handle_request_notify(p, req, addr, seqno, e); 25379 break; 25380 case SIP_UPDATE: 25381 res = handle_request_update(p, req); 25382 break; 25383 case SIP_ACK: 25384 /* Make sure we don't ignore this */ 25385 if (seqno == p->pendinginvite) { 25386 p->invitestate = INV_TERMINATED; 25387 p->pendinginvite = 0; 25388 acked = __sip_ack(p, seqno, 1 /* response */, 0); 25389 if (find_sdp(req)) { 25390 if (process_sdp(p, req, SDP_T38_NONE)) 25391 return -1; 25392 } 25393 check_pendings(p); 25394 } else if (p->glareinvite == seqno) { 25395 /* handle ack for the 491 pending sent for glareinvite */ 25396 p->glareinvite = 0; 25397 acked = __sip_ack(p, seqno, 1, 0); 25398 } 25399 if (!acked) { 25400 /* Got an ACK that did not match anything. Ignore 25401 * silently and restore previous method */ 25402 p->method = oldmethod; 25403 } 25404 if (!p->lastinvite && ast_strlen_zero(p->randdata)) { 25405 pvt_set_needdestroy(p, "unmatched ACK"); 25406 } 25407 break; 25408 default: 25409 transmit_response_with_allow(p, "501 Method Not Implemented", req, 0); 25410 ast_log(LOG_NOTICE, "Unknown SIP command '%s' from '%s'\n", 25411 cmd, ast_sockaddr_stringify(&p->sa)); 25412 /* If this is some new method, and we don't have a call, destroy it now */ 25413 if (!p->initreq.headers) { 25414 pvt_set_needdestroy(p, "unimplemented method"); 25415 } 25416 break; 25417 } 25418 return res; 25419 }
| static int handle_invite_replaces | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| uint32_t | seqno, | |||
| struct ast_sockaddr * | addr, | |||
| int * | nounlock | |||
| ) | [static] |
Handle the transfer part of INVITE with a replaces: header, meaning a target pickup or an attended transfer. Used only once. XXX 'ignore' is unused.
Definition at line 22114 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), AST_CAUSE_SWITCH_CONGESTION, ast_channel_lock, ast_channel_masquerade(), ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_debug, ast_do_masquerade(), ast_hangup(), ast_log(), ast_quiet_chan(), ast_set_flag, ast_setstate(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, FALSE, ast_channel::hangupcause, LOG_ERROR, LOG_NOTICE, LOG_WARNING, sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), ast_channel::tech_pvt, transmit_response(), transmit_response_reliable(), and transmit_response_with_sdp().
Referenced by handle_request_invite().
22115 { 22116 int earlyreplace = 0; 22117 int oneleggedreplace = 0; /* Call with no bridge, propably IVR or voice message */ 22118 struct ast_channel *c = p->owner; /* Our incoming call */ 22119 struct ast_channel *replacecall = p->refer->refer_call->owner; /* The channel we're about to take over */ 22120 struct ast_channel *targetcall; /* The bridge to the take-over target */ 22121 22122 /* Check if we're in ring state */ 22123 if (replacecall->_state == AST_STATE_RING) 22124 earlyreplace = 1; 22125 22126 /* Check if we have a bridge */ 22127 if (!(targetcall = ast_bridged_channel(replacecall))) { 22128 /* We have no bridge */ 22129 if (!earlyreplace) { 22130 ast_debug(2, " Attended transfer attempted to replace call with no bridge (maybe ringing). Channel %s!\n", replacecall->name); 22131 oneleggedreplace = 1; 22132 } 22133 } 22134 if (targetcall && targetcall->_state == AST_STATE_RINGING) 22135 ast_debug(4, "SIP transfer: Target channel is in ringing state\n"); 22136 22137 if (targetcall) 22138 ast_debug(4, "SIP transfer: Invite Replace incoming channel should bridge to channel %s while hanging up channel %s\n", targetcall->name, replacecall->name); 22139 else 22140 ast_debug(4, "SIP transfer: Invite Replace incoming channel should replace and hang up channel %s (one call leg)\n", replacecall->name); 22141 22142 if (req->ignore) { 22143 ast_log(LOG_NOTICE, "Ignoring this INVITE with replaces in a stupid way.\n"); 22144 /* We should answer something here. If we are here, the 22145 call we are replacing exists, so an accepted 22146 can't harm */ 22147 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE, FALSE, FALSE); 22148 /* Do something more clever here */ 22149 if (c) { 22150 *nounlock = 1; 22151 ast_channel_unlock(c); 22152 } 22153 ast_channel_unlock(replacecall); 22154 sip_pvt_unlock(p->refer->refer_call); 22155 return 1; 22156 } 22157 if (!c) { 22158 /* What to do if no channel ??? */ 22159 ast_log(LOG_ERROR, "Unable to create new channel. Invite/replace failed.\n"); 22160 transmit_response_reliable(p, "503 Service Unavailable", req); 22161 append_history(p, "Xfer", "INVITE/Replace Failed. No new channel."); 22162 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22163 ast_channel_unlock(replacecall); 22164 sip_pvt_unlock(p->refer->refer_call); 22165 return 1; 22166 } 22167 append_history(p, "Xfer", "INVITE/Replace received"); 22168 /* We have three channels to play with 22169 channel c: New incoming call 22170 targetcall: Call from PBX to target 22171 p->refer->refer_call: SIP pvt dialog from transferer to pbx. 22172 replacecall: The owner of the previous 22173 We need to masq C into refer_call to connect to 22174 targetcall; 22175 If we are talking to internal audio stream, target call is null. 22176 */ 22177 22178 /* Fake call progress */ 22179 transmit_response(p, "100 Trying", req); 22180 ast_setstate(c, AST_STATE_RING); 22181 22182 /* Masquerade the new call into the referred call to connect to target call 22183 Targetcall is not touched by the masq */ 22184 22185 /* Answer the incoming call and set channel to UP state */ 22186 transmit_response_with_sdp(p, "200 OK", req, XMIT_RELIABLE, FALSE, FALSE); 22187 22188 ast_setstate(c, AST_STATE_UP); 22189 22190 /* Stop music on hold and other generators */ 22191 ast_quiet_chan(replacecall); 22192 ast_quiet_chan(targetcall); 22193 ast_debug(4, "Invite/Replaces: preparing to masquerade %s into %s\n", c->name, replacecall->name); 22194 22195 /* Make sure that the masq does not free our PVT for the old call */ 22196 if (! earlyreplace && ! oneleggedreplace ) 22197 ast_set_flag(&p->refer->refer_call->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 22198 22199 /* Prepare the masquerade - if this does not happen, we will be gone */ 22200 if(ast_channel_masquerade(replacecall, c)) 22201 ast_log(LOG_ERROR, "Failed to masquerade C into Replacecall\n"); 22202 else 22203 ast_debug(4, "Invite/Replaces: Going to masquerade %s into %s\n", c->name, replacecall->name); 22204 22205 /* C should now be in place of replacecall. all channel locks and pvt locks should be removed 22206 * before issuing the masq. Since we are unlocking both the pvt (p) and its owner channel (c) 22207 * it is possible for channel c to be destroyed on us. To prevent this, we must give c a reference 22208 * before any unlocking takes place and remove it only once we are completely done with it */ 22209 ast_channel_ref(c); 22210 ast_channel_unlock(replacecall); 22211 ast_channel_unlock(c); 22212 sip_pvt_unlock(p->refer->refer_call); 22213 sip_pvt_unlock(p); 22214 if (ast_do_masquerade(replacecall)) { 22215 ast_log(LOG_WARNING, "Failed to perform masquerade with INVITE replaces\n"); 22216 } 22217 ast_channel_lock(c); 22218 if (earlyreplace || oneleggedreplace ) { 22219 c->hangupcause = AST_CAUSE_SWITCH_CONGESTION; 22220 } 22221 ast_setstate(c, AST_STATE_DOWN); 22222 ast_channel_unlock(c); 22223 22224 /* The call should be down with no ast_channel, so hang it up */ 22225 c->tech_pvt = dialog_unref(c->tech_pvt, "unref dialog c->tech_pvt"); 22226 22227 /* c and c's tech pvt must be unlocked at this point for ast_hangup */ 22228 ast_hangup(c); 22229 /* this indicates to handle_request_do that the owner channel has already been unlocked */ 22230 *nounlock = 1; 22231 /* lock PVT structure again after hangup */ 22232 sip_pvt_lock(p); 22233 ast_channel_unref(c); 22234 return 0; 22235 }
| static int handle_request_bye | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming BYE request.
Definition at line 23936 of file chan_sip.c.
References __sip_pretend_ack(), append_history, ARRAY_LEN, ast_async_goto(), ast_bridged_channel(), AST_CAUSE_PROTOCOL_ERROR, ast_channel_lock, ast_channel_trylock, ast_channel_unlock, ast_clear_flag, AST_CONTROL_UNHOLD, ast_debug, ast_log(), AST_MAX_USER_FIELD, ast_queue_control(), ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_rtp_instance_get_quality(), ast_rtp_instance_set_stats_vars(), AST_RTP_INSTANCE_STAT_FIELD_QUALITY, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, ast_sockaddr_stringify(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, check_via(), ast_channel::context, context, copy_request(), get_also_info(), get_header(), LOG_NOTICE, LOG_WARNING, parse_sip_options(), pbx_builtin_setvar_helper(), quality, sip_alreadygone(), sip_cfg, sip_methods, sip_pvt_lock, sip_pvt_unlock, sip_queue_hangup_cause(), sip_scheddestroy_final(), stop_media_flows(), stop_session_timer(), ast_channel::tech, ast_channel::tech_pvt, cfsip_methods::text, transmit_response(), transmit_response_reliable(), and transmit_response_with_unsupported().
Referenced by handle_incoming().
23937 { 23938 struct ast_channel *c=NULL; 23939 int res; 23940 struct ast_channel *bridged_to; 23941 const char *required; 23942 23943 /* If we have an INCOMING invite that we haven't answered, terminate that transaction */ 23944 if (p->pendinginvite && !ast_test_flag(&p->flags[0], SIP_OUTGOING) && !req->ignore) { 23945 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 23946 } 23947 23948 __sip_pretend_ack(p); 23949 23950 p->invitestate = INV_TERMINATED; 23951 23952 copy_request(&p->initreq, req); 23953 if (sipdebug) 23954 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 23955 check_via(p, req); 23956 sip_alreadygone(p); 23957 23958 /* Get RTCP quality before end of call */ 23959 if (p->do_history || p->owner) { 23960 char quality_buf[AST_MAX_USER_FIELD], *quality; 23961 struct ast_channel *bridge = p->owner ? ast_bridged_channel(p->owner) : NULL; 23962 23963 /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt 23964 * to lock the bridge. This may get hairy... 23965 */ 23966 while (bridge && ast_channel_trylock(bridge)) { 23967 ast_channel_unlock(p->owner); 23968 do { 23969 /* Can't use DEADLOCK_AVOIDANCE since p is an ao2 object */ 23970 sip_pvt_unlock(p); 23971 usleep(1); 23972 sip_pvt_lock(p); 23973 } while (p->owner && ast_channel_trylock(p->owner)); 23974 bridge = p->owner ? ast_bridged_channel(p->owner) : NULL; 23975 } 23976 23977 23978 if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 23979 if (p->do_history) { 23980 append_history(p, "RTCPaudio", "Quality:%s", quality); 23981 23982 if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_JITTER, quality_buf, sizeof(quality_buf)))) { 23983 append_history(p, "RTCPaudioJitter", "Quality:%s", quality); 23984 } 23985 if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_LOSS, quality_buf, sizeof(quality_buf)))) { 23986 append_history(p, "RTCPaudioLoss", "Quality:%s", quality); 23987 } 23988 if ((quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY_RTT, quality_buf, sizeof(quality_buf)))) { 23989 append_history(p, "RTCPaudioRTT", "Quality:%s", quality); 23990 } 23991 } 23992 23993 if (p->owner) { 23994 ast_rtp_instance_set_stats_vars(p->owner, p->rtp); 23995 } 23996 23997 } 23998 23999 if (bridge) { 24000 struct sip_pvt *q = bridge->tech_pvt; 24001 24002 if (IS_SIP_TECH(bridge->tech) && q && q->rtp) { 24003 ast_rtp_instance_set_stats_vars(bridge, q->rtp); 24004 } 24005 ast_channel_unlock(bridge); 24006 } 24007 24008 if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 24009 if (p->do_history) { 24010 append_history(p, "RTCPvideo", "Quality:%s", quality); 24011 } 24012 if (p->owner) { 24013 pbx_builtin_setvar_helper(p->owner, "RTPVIDEOQOS", quality); 24014 } 24015 } 24016 if (p->trtp && (quality = ast_rtp_instance_get_quality(p->trtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 24017 if (p->do_history) { 24018 append_history(p, "RTCPtext", "Quality:%s", quality); 24019 } 24020 if (p->owner) { 24021 pbx_builtin_setvar_helper(p->owner, "RTPTEXTQOS", quality); 24022 } 24023 } 24024 } 24025 24026 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 24027 stop_session_timer(p); /* Stop Session-Timer */ 24028 24029 if (!ast_strlen_zero(get_header(req, "Also"))) { 24030 ast_log(LOG_NOTICE, "Client '%s' using deprecated BYE/Also transfer method. Ask vendor to support REFER instead\n", 24031 ast_sockaddr_stringify(&p->recv)); 24032 if (ast_strlen_zero(p->context)) 24033 ast_string_field_set(p, context, sip_cfg.default_context); 24034 res = get_also_info(p, req); 24035 if (!res) { 24036 c = p->owner; 24037 if (c) { 24038 bridged_to = ast_bridged_channel(c); 24039 if (bridged_to) { 24040 /* Don't actually hangup here... */ 24041 ast_queue_control(c, AST_CONTROL_UNHOLD); 24042 ast_channel_unlock(c); /* async_goto can do a masquerade, no locks can be held during a masq */ 24043 ast_async_goto(bridged_to, p->context, p->refer->refer_to, 1); 24044 ast_channel_lock(c); 24045 } else 24046 ast_queue_hangup(p->owner); 24047 } 24048 } else { 24049 ast_log(LOG_WARNING, "Invalid transfer information from '%s'\n", ast_sockaddr_stringify(&p->recv)); 24050 if (p->owner) 24051 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_PROTOCOL_ERROR); 24052 } 24053 } else if (p->owner) { 24054 sip_queue_hangup_cause(p, 0); 24055 sip_scheddestroy_final(p, DEFAULT_TRANS_TIMEOUT); 24056 ast_debug(3, "Received bye, issuing owner hangup\n"); 24057 } else { 24058 sip_scheddestroy_final(p, DEFAULT_TRANS_TIMEOUT); 24059 ast_debug(3, "Received bye, no owner, selfdestruct soon.\n"); 24060 } 24061 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 24062 24063 /* Find out what they require */ 24064 required = get_header(req, "Require"); 24065 if (!ast_strlen_zero(required)) { 24066 char unsupported[256] = { 0, }; 24067 parse_sip_options(required, unsupported, ARRAY_LEN(unsupported)); 24068 /* If there are any options required that we do not support, 24069 * then send a 420 with only those unsupported options listed */ 24070 if (!ast_strlen_zero(unsupported)) { 24071 transmit_response_with_unsupported(p, "420 Bad extension (unsupported)", req, unsupported); 24072 ast_log(LOG_WARNING, "Received SIP BYE with unsupported required extension: required:%s unsupported:%s\n", required, unsupported); 24073 } else { 24074 transmit_response(p, "200 OK", req); 24075 } 24076 } else { 24077 transmit_response(p, "200 OK", req); 24078 } 24079 24080 return 1; 24081 }
| static int handle_request_cancel | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming CANCEL request.
Definition at line 23868 of file chan_sip.c.
References __sip_pretend_ack(), ast_debug, ast_free, AST_SCHED_DEL, AST_STATE_UP, ast_str_strlen(), ast_test_flag, check_via(), sip_alreadygone(), sip_queue_hangup_cause(), sip_scheddestroy(), stop_media_flows(), transmit_response(), transmit_response_reliable(), UNLINK, and update_call_counter().
Referenced by handle_incoming().
23869 { 23870 23871 check_via(p, req); 23872 sip_alreadygone(p); 23873 23874 if (p->owner && p->owner->_state == AST_STATE_UP) { 23875 /* This call is up, cancel is ignored, we need a bye */ 23876 transmit_response(p, "200 OK", req); 23877 ast_debug(1, "Got CANCEL on an answered call. Ignoring... \n"); 23878 return 0; 23879 } 23880 23881 /* At this point, we could have cancelled the invite at the same time 23882 as the other side sends a CANCEL. Our final reply with error code 23883 might not have been received by the other side before the CANCEL 23884 was sent, so let's just give up retransmissions and waiting for 23885 ACK on our error code. The call is hanging up any way. */ 23886 if (p->invitestate == INV_TERMINATED || p->invitestate == INV_COMPLETED) { 23887 __sip_pretend_ack(p); 23888 } 23889 if (p->invitestate != INV_TERMINATED) 23890 p->invitestate = INV_CANCELLED; 23891 23892 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) 23893 update_call_counter(p, DEC_CALL_LIMIT); 23894 23895 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 23896 if (p->owner) { 23897 sip_queue_hangup_cause(p, 0); 23898 } else { 23899 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 23900 } 23901 if (ast_str_strlen(p->initreq.data) > 0) { 23902 struct sip_pkt *pkt, *prev_pkt; 23903 /* If the CANCEL we are receiving is a retransmission, and we already have scheduled 23904 * a reliable 487, then we don't want to schedule another one on top of the previous 23905 * one. 23906 * 23907 * As odd as this may sound, we can't rely on the previously-transmitted "reliable" 23908 * response in this situation. What if we've sent all of our reliable responses 23909 * already and now all of a sudden, we get this second CANCEL? 23910 * 23911 * The only way to do this correctly is to cancel our previously-scheduled reliably- 23912 * transmitted response and send a new one in its place. 23913 */ 23914 for (pkt = p->packets, prev_pkt = NULL; pkt; prev_pkt = pkt, pkt = pkt->next) { 23915 if (pkt->seqno == p->lastinvite && pkt->response_code == 487) { 23916 AST_SCHED_DEL(sched, pkt->retransid); 23917 UNLINK(pkt, p->packets, prev_pkt); 23918 dialog_unref(pkt->owner, "unref packet->owner from dialog"); 23919 if (pkt->data) { 23920 ast_free(pkt->data); 23921 } 23922 ast_free(pkt); 23923 break; 23924 } 23925 } 23926 transmit_response_reliable(p, "487 Request Terminated", &p->initreq); 23927 transmit_response(p, "200 OK", req); 23928 return 1; 23929 } else { 23930 transmit_response(p, "481 Call Leg Does Not Exist", req); 23931 return 0; 23932 } 23933 }
| static int handle_request_do | ( | struct sip_request * | req, | |
| struct ast_sockaddr * | addr | |||
| ) | [static] |
Handle incoming SIP message - request or response.
This is used for all transports (udp, tcp and tcp/tls)
Definition at line 25471 of file chan_sip.c.
References ao2_t_ref, append_history, ast_channel_unlock, ast_channel_unref, ast_debug, ast_mutex_lock, ast_mutex_unlock, ast_sockaddr_copy(), ast_sockaddr_stringify(), ast_str_reset(), ast_str_strlen(), ast_update_use_count(), ast_verbose, copy_socket_data(), find_call(), find_sip_method(), get_header(), get_transport(), handle_incoming(), lws2sws(), parse_request(), sip_cfg, sip_debug_test_addr(), sip_pvt_lock_full(), and sip_pvt_unlock.
Referenced by _sip_tcp_helper_thread(), and sipsock_read().
25472 { 25473 struct sip_pvt *p; 25474 struct ast_channel *owner_chan_ref = NULL; 25475 int recount = 0; 25476 int nounlock = 0; 25477 25478 if (sip_debug_test_addr(addr)) /* Set the debug flag early on packet level */ 25479 req->debug = 1; 25480 if (sip_cfg.pedanticsipchecking) 25481 lws2sws(req->data); /* Fix multiline headers */ 25482 if (req->debug) { 25483 ast_verbose("\n<--- SIP read from %s:%s --->\n%s\n<------------->\n", 25484 get_transport(req->socket.type), ast_sockaddr_stringify(addr), req->data->str); 25485 } 25486 25487 if (parse_request(req) == -1) { /* Bad packet, can't parse */ 25488 ast_str_reset(req->data); /* nulling this out is NOT a good idea here. */ 25489 return 1; 25490 } 25491 req->method = find_sip_method(REQ_OFFSET_TO_STR(req, rlPart1)); 25492 25493 if (req->debug) 25494 ast_verbose("--- (%d headers %d lines)%s ---\n", req->headers, req->lines, (req->headers + req->lines == 0) ? " Nat keepalive" : ""); 25495 25496 if (req->headers < 2) { /* Must have at least two headers */ 25497 ast_str_reset(req->data); /* nulling this out is NOT a good idea here. */ 25498 return 1; 25499 } 25500 25501 /* Process request, with netlock held, and with usual deadlock avoidance */ 25502 ast_mutex_lock(&netlock); 25503 25504 /* Find the active SIP dialog or create a new one */ 25505 p = find_call(req, addr, req->method); /* returns p with a reference only. _NOT_ locked*/ 25506 if (p == NULL) { 25507 ast_debug(1, "Invalid SIP message - rejected , no callid, len %zu\n", ast_str_strlen(req->data)); 25508 ast_mutex_unlock(&netlock); 25509 return 1; 25510 } 25511 25512 /* Lock both the pvt and the owner if owner is present. This will 25513 * not fail. */ 25514 owner_chan_ref = sip_pvt_lock_full(p); 25515 25516 copy_socket_data(&p->socket, &req->socket); 25517 ast_sockaddr_copy(&p->recv, addr); 25518 25519 /* if we have an owner, then this request has been authenticated */ 25520 if (p->owner) { 25521 req->authenticated = 1; 25522 } 25523 25524 if (p->do_history) /* This is a request or response, note what it was for */ 25525 append_history(p, "Rx", "%s / %s / %s", req->data->str, get_header(req, "CSeq"), REQ_OFFSET_TO_STR(req, rlPart2)); 25526 25527 if (handle_incoming(p, req, addr, &recount, &nounlock) == -1) { 25528 /* Request failed */ 25529 ast_debug(1, "SIP message could not be handled, bad request: %-70.70s\n", p->callid[0] ? p->callid : "<no callid>"); 25530 } 25531 25532 if (recount) { 25533 ast_update_use_count(); 25534 } 25535 25536 if (p->owner && !nounlock) { 25537 ast_channel_unlock(p->owner); 25538 } 25539 if (owner_chan_ref) { 25540 ast_channel_unref(owner_chan_ref); 25541 } 25542 sip_pvt_unlock(p); 25543 ao2_t_ref(p, -1, "throw away dialog ptr from find_call at end of routine"); /* p is gone after the return */ 25544 ast_mutex_unlock(&netlock); 25545 25546 return 1; 25547 }
| static void handle_request_info | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP INFO Message.
Definition at line 18850 of file chan_sip.c.
References ast_bridged_channel(), ast_cdr_setuserfield(), AST_CONTROL_FLASH, AST_CONTROL_VIDUPDATE, ast_copy_string(), ast_debug, ast_find_call_feature(), AST_FRAME_CONTROL, AST_FRAME_DTMF, ast_log(), AST_LOG_WARNING, ast_queue_control(), ast_queue_frame(), ast_rdlock_call_features(), ast_strlen_zero(), ast_test_flag, ast_unlock_call_features(), ast_verbose, ast_channel::cdr, ast_call_feature::exten, f, get_body(), get_header(), get_msg_text(), ast_frame_subclass::integer, ast_frame::len, LOG_WARNING, sip_scheddestroy(), ast_frame::subclass, and transmit_response().
Referenced by handle_incoming().
18851 { 18852 char buf[1024] = ""; 18853 unsigned int event; 18854 const char *c = get_header(req, "Content-Type"); 18855 18856 /* Need to check the media/type */ 18857 if (!strcasecmp(c, "application/dtmf-relay") || 18858 !strcasecmp(c, "application/vnd.nortelnetworks.digits") || 18859 !strcasecmp(c, "application/dtmf")) { 18860 unsigned int duration = 0; 18861 18862 if (!p->owner) { /* not a PBX call */ 18863 transmit_response(p, "481 Call leg/transaction does not exist", req); 18864 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 18865 return; 18866 } 18867 18868 /* If dtmf-relay or vnd.nortelnetworks.digits, parse the signal and duration; 18869 * otherwise use the body as the signal */ 18870 if (strcasecmp(c, "application/dtmf")) { 18871 const char *msg_body; 18872 18873 if ( ast_strlen_zero(msg_body = get_body(req, "Signal", '=')) 18874 && ast_strlen_zero(msg_body = get_body(req, "d", '='))) { 18875 ast_log(LOG_WARNING, "Unable to retrieve DTMF signal for INFO message on " 18876 "call %s\n", p->callid); 18877 transmit_response(p, "200 OK", req); 18878 return; 18879 } 18880 ast_copy_string(buf, msg_body, sizeof(buf)); 18881 18882 if (!ast_strlen_zero((msg_body = get_body(req, "Duration", '=')))) { 18883 sscanf(msg_body, "%30u", &duration); 18884 } 18885 } else { 18886 /* Type is application/dtmf, simply use what's in the message body */ 18887 get_msg_text(buf, sizeof(buf), req); 18888 } 18889 18890 /* An empty message body requires us to send a 200 OK */ 18891 if (ast_strlen_zero(buf)) { 18892 transmit_response(p, "200 OK", req); 18893 return; 18894 } 18895 18896 if (!duration) { 18897 duration = 100; /* 100 ms */ 18898 } 18899 18900 if (buf[0] == '*') { 18901 event = 10; 18902 } else if (buf[0] == '#') { 18903 event = 11; 18904 } else if (buf[0] == '!') { 18905 event = 16; 18906 } else if ('A' <= buf[0] && buf[0] <= 'D') { 18907 event = 12 + buf[0] - 'A'; 18908 } else if ('a' <= buf[0] && buf[0] <= 'd') { 18909 event = 12 + buf[0] - 'a'; 18910 } else if ((sscanf(buf, "%30u", &event) != 1) || event > 16) { 18911 ast_log(AST_LOG_WARNING, "Unable to convert DTMF event signal code to a valid " 18912 "value for INFO message on call %s\n", p->callid); 18913 transmit_response(p, "200 OK", req); 18914 return; 18915 } 18916 18917 if (event == 16) { 18918 /* send a FLASH event */ 18919 struct ast_frame f = { AST_FRAME_CONTROL, { AST_CONTROL_FLASH, } }; 18920 ast_queue_frame(p->owner, &f); 18921 if (sipdebug) { 18922 ast_verbose("* DTMF-relay event received: FLASH\n"); 18923 } 18924 } else { 18925 /* send a DTMF event */ 18926 struct ast_frame f = { AST_FRAME_DTMF, }; 18927 if (event < 10) { 18928 f.subclass.integer = '0' + event; 18929 } else if (event == 10) { 18930 f.subclass.integer = '*'; 18931 } else if (event == 11) { 18932 f.subclass.integer = '#'; 18933 } else { 18934 f.subclass.integer = 'A' + (event - 12); 18935 } 18936 f.len = duration; 18937 ast_queue_frame(p->owner, &f); 18938 if (sipdebug) { 18939 ast_verbose("* DTMF-relay event received: %c\n", (int) f.subclass.integer); 18940 } 18941 } 18942 transmit_response(p, "200 OK", req); 18943 return; 18944 } else if (!strcasecmp(c, "application/media_control+xml")) { 18945 /* Eh, we'll just assume it's a fast picture update for now */ 18946 if (p->owner) 18947 ast_queue_control(p->owner, AST_CONTROL_VIDUPDATE); 18948 transmit_response(p, "200 OK", req); 18949 return; 18950 } else if (!ast_strlen_zero(c = get_header(req, "X-ClientCode"))) { 18951 /* Client code (from SNOM phone) */ 18952 if (ast_test_flag(&p->flags[0], SIP_USECLIENTCODE)) { 18953 if (p->owner && p->owner->cdr) 18954 ast_cdr_setuserfield(p->owner, c); 18955 if (p->owner && ast_bridged_channel(p->owner) && ast_bridged_channel(p->owner)->cdr) 18956 ast_cdr_setuserfield(ast_bridged_channel(p->owner), c); 18957 transmit_response(p, "200 OK", req); 18958 } else { 18959 transmit_response(p, "403 Forbidden", req); 18960 } 18961 return; 18962 } else if (!ast_strlen_zero(c = get_header(req, "Record"))) { 18963 /* INFO messages generated by some phones to start/stop recording 18964 on phone calls. 18965 OEJ: I think this should be something that is enabled/disabled 18966 per device. I don't want incoming callers to record calls in my 18967 pbx. 18968 */ 18969 18970 struct ast_call_feature *feat; 18971 int j; 18972 struct ast_frame f = { AST_FRAME_DTMF, }; 18973 18974 if (!p->owner) { /* not a PBX call */ 18975 transmit_response(p, "481 Call leg/transaction does not exist", req); 18976 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 18977 return; 18978 } 18979 18980 /* first, get the feature string, if it exists */ 18981 ast_rdlock_call_features(); 18982 feat = ast_find_call_feature("automon"); 18983 if (!feat || ast_strlen_zero(feat->exten)) { 18984 ast_log(LOG_WARNING, "Recording requested, but no One Touch Monitor registered. (See features.conf)\n"); 18985 /* 403 means that we don't support this feature, so don't request it again */ 18986 transmit_response(p, "403 Forbidden", req); 18987 ast_unlock_call_features(); 18988 return; 18989 } 18990 /* Send the feature code to the PBX as DTMF, just like the handset had sent it */ 18991 f.len = 100; 18992 for (j=0; j < strlen(feat->exten); j++) { 18993 f.subclass.integer = feat->exten[j]; 18994 ast_queue_frame(p->owner, &f); 18995 if (sipdebug) 18996 ast_verbose("* DTMF-relay event faked: %c\n", f.subclass.integer); 18997 } 18998 ast_unlock_call_features(); 18999 19000 ast_debug(1, "Got a Request to Record the channel, state %s\n", c); 19001 transmit_response(p, "200 OK", req); 19002 return; 19003 } else if (ast_strlen_zero(c = get_header(req, "Content-Length")) || !strcasecmp(c, "0")) { 19004 /* This is probably just a packet making sure the signalling is still up, just send back a 200 OK */ 19005 transmit_response(p, "200 OK", req); 19006 return; 19007 } 19008 19009 /* Other type of INFO message, not really understood by Asterisk */ 19010 /* if (get_msg_text(buf, sizeof(buf), req)) { */ 19011 19012 ast_log(LOG_WARNING, "Unable to parse INFO message from %s. Content %s\n", p->callid, buf); 19013 transmit_response(p, "415 Unsupported media type", req); 19014 return; 19015 }
| static int handle_request_invite | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| uint32_t | seqno, | |||
| struct ast_sockaddr * | addr, | |||
| int * | recount, | |||
| const char * | e, | |||
| int * | nounlock | |||
| ) | [static] |
Handle incoming INVITE request.
This is a spiral. What we need to do is to just change the outgoing INVITE so that it now routes to the new Request URI. Since we created the INVITE ourselves that should be all we need to do.
Definition at line 22334 of file chan_sip.c.
References __sip_ack(), ast_channel::_state, append_history, ARRAY_LEN, AST_CAUSE_FAILURE, ast_cc_agent_set_interfaces_chanvar(), ast_channel_queue_connected_line_update(), ast_channel_set_redirecting(), ast_channel_unlock, ast_clear_flag, AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER, AST_CONTROL_BUSY, AST_CONTROL_SRCUPDATE, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, ast_copy_string(), ast_debug, ast_hangup(), ast_log(), AST_MAX_CONTEXT, AST_MAX_EXTENSION, ast_null_frame, ast_party_connected_line_init(), ast_party_redirecting_free(), ast_party_redirecting_init(), AST_PBX_CALL_LIMIT, AST_PBX_FAILED, ast_pbx_start(), AST_PBX_SUCCESS, ast_pickup_ext(), ast_queue_control(), ast_queue_frame(), ast_rtp_instance_set_alt_remote_address(), ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_sched_add(), AST_SCHED_DEL_UNREF, ast_set_flag, ast_setstate(), ast_setup_cc_recall_datastore(), ast_skip_blanks(), ast_sockaddr_stringify(), AST_STATE_DOWN, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), ast_verbose, build_contact(), build_route(), change_hold_state(), change_redirecting_information(), check_user_full(), check_via(), connected, context, copy_request(), do_magic_pickup(), ast_channel::exten, exten, extract_uri(), FALSE, find_sdp(), get_destination(), get_header(), get_ip_and_port_from_sdp(), get_rpid(), get_sip_pvt_byid_locked(), handle_invite_replaces(), ast_channel::hangupcause, ast_party_connected_line::id, ast_set_party_connected_line::id, LOG_ERROR, LOG_NOTICE, LOG_WARNING, make_our_tag(), ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, parse_minse(), parse_ok_contact(), parse_session_expires(), parse_sip_options(), ast_party_name::presentation, ast_party_number::presentation, process_sdp(), ref_peer(), restart_session_timer(), S_OR, set_pvt_allowed_methods(), sip_alreadygone(), sip_cancel_destroy(), sip_cfg, sip_methods, sip_new(), sip_pickup(), sip_pvt_lock, sip_pvt_unlock, sip_refer_allocate(), sip_scheddestroy(), sip_st_alloc(), sip_t38_abort(), sip_uri_cmp(), ast_party_connected_line::source, st_get_mode(), st_get_refresher(), st_get_se(), start_session_timer(), ast_party_name::str, ast_party_number::str, ast_party_id::tag, cfsip_methods::text, transmit_fake_auth_response(), transmit_provisional_response(), transmit_response(), transmit_response_reliable(), transmit_response_with_minse(), transmit_response_with_sdp(), transmit_response_with_t38_sdp(), transmit_response_with_unsupported(), TRUE, unref_peer(), update_call_counter(), update_redirecting(), ast_party_name::valid, and ast_party_number::valid.
Referenced by handle_incoming().
22335 { 22336 int res = 1; 22337 int gotdest; 22338 const char *p_replaces; 22339 char *replace_id = NULL; 22340 int refer_locked = 0; 22341 const char *required; 22342 unsigned int required_profile = 0; 22343 struct ast_channel *c = NULL; /* New channel */ 22344 struct sip_peer *authpeer = NULL; /* Matching Peer */ 22345 int reinvite = 0; 22346 int rtn; 22347 struct ast_party_redirecting redirecting; 22348 struct ast_set_party_redirecting update_redirecting; 22349 22350 const char *p_uac_se_hdr; /* UAC's Session-Expires header string */ 22351 const char *p_uac_min_se; /* UAC's requested Min-SE interval (char string) */ 22352 int uac_max_se = -1; /* UAC's Session-Expires in integer format */ 22353 int uac_min_se = -1; /* UAC's Min-SE in integer format */ 22354 int st_active = FALSE; /* Session-Timer on/off boolean */ 22355 int st_interval = 0; /* Session-Timer negotiated refresh interval */ 22356 enum st_refresher st_ref; /* Session-Timer session refresher */ 22357 int dlg_min_se = -1; 22358 struct { 22359 char exten[AST_MAX_EXTENSION]; 22360 char context[AST_MAX_CONTEXT]; 22361 } pickup = { 22362 .exten = "", 22363 }; 22364 st_ref = SESSION_TIMER_REFRESHER_AUTO; 22365 22366 /* Find out what they support */ 22367 if (!p->sipoptions) { 22368 const char *supported = get_header(req, "Supported"); 22369 if (!ast_strlen_zero(supported)) { 22370 p->sipoptions = parse_sip_options(supported, NULL, 0); 22371 } 22372 } 22373 22374 /* Find out what they require */ 22375 required = get_header(req, "Require"); 22376 if (!ast_strlen_zero(required)) { 22377 char unsupported[256] = { 0, }; 22378 required_profile = parse_sip_options(required, unsupported, ARRAY_LEN(unsupported)); 22379 22380 /* If there are any options required that we do not support, 22381 * then send a 420 with only those unsupported options listed */ 22382 if (!ast_strlen_zero(unsupported)) { 22383 transmit_response_with_unsupported(p, "420 Bad extension (unsupported)", req, unsupported); 22384 ast_log(LOG_WARNING, "Received SIP INVITE with unsupported required extension: required:%s unsupported:%s\n", required, unsupported); 22385 p->invitestate = INV_COMPLETED; 22386 if (!p->lastinvite) 22387 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22388 res = -1; 22389 goto request_invite_cleanup; 22390 } 22391 } 22392 22393 /* The option tags may be present in Supported: or Require: headers. 22394 Include the Require: option tags for further processing as well */ 22395 p->sipoptions |= required_profile; 22396 p->reqsipoptions = required_profile; 22397 22398 /* Check if this is a loop */ 22399 if (ast_test_flag(&p->flags[0], SIP_OUTGOING) && p->owner && (p->invitestate != INV_TERMINATED && p->invitestate != INV_CONFIRMED) && p->owner->_state != AST_STATE_UP) { 22400 /* This is a call to ourself. Send ourselves an error code and stop 22401 processing immediately, as SIP really has no good mechanism for 22402 being able to call yourself */ 22403 /* If pedantic is on, we need to check the tags. If they're different, this is 22404 in fact a forked call through a SIP proxy somewhere. */ 22405 int different; 22406 const char *initial_rlPart2 = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); 22407 const char *this_rlPart2 = REQ_OFFSET_TO_STR(req, rlPart2); 22408 if (sip_cfg.pedanticsipchecking) 22409 different = sip_uri_cmp(initial_rlPart2, this_rlPart2); 22410 else 22411 different = strcmp(initial_rlPart2, this_rlPart2); 22412 if (!different) { 22413 transmit_response(p, "482 Loop Detected", req); 22414 p->invitestate = INV_COMPLETED; 22415 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22416 res = 0; 22417 goto request_invite_cleanup; 22418 } else { 22419 /*! This is a spiral. What we need to do is to just change the outgoing INVITE 22420 * so that it now routes to the new Request URI. Since we created the INVITE ourselves 22421 * that should be all we need to do. 22422 * 22423 * \todo XXX This needs to be reviewed. YOu don't change the request URI really, you route the packet 22424 * correctly instead... 22425 */ 22426 char *uri = ast_strdupa(this_rlPart2); 22427 char *at = strchr(uri, '@'); 22428 char *peerorhost; 22429 ast_debug(2, "Potential spiral detected. Original RURI was %s, new RURI is %s\n", initial_rlPart2, this_rlPart2); 22430 transmit_response(p, "100 Trying", req); 22431 if (at) { 22432 *at = '\0'; 22433 } 22434 /* Parse out "sip:" */ 22435 if ((peerorhost = strchr(uri, ':'))) { 22436 *peerorhost++ = '\0'; 22437 } 22438 ast_string_field_set(p, theirtag, NULL); 22439 /* Treat this as if there were a call forward instead... 22440 */ 22441 ast_string_field_set(p->owner, call_forward, peerorhost); 22442 ast_queue_control(p->owner, AST_CONTROL_BUSY); 22443 res = 0; 22444 goto request_invite_cleanup; 22445 } 22446 } 22447 22448 if (!req->ignore && p->pendinginvite) { 22449 if (!ast_test_flag(&p->flags[0], SIP_OUTGOING) && (p->invitestate == INV_COMPLETED || p->invitestate == INV_TERMINATED)) { 22450 /* What do these circumstances mean? We have received an INVITE for an "incoming" dialog for which we 22451 * have sent a final response. We have not yet received an ACK, though (which is why p->pendinginvite is non-zero). 22452 * We also know that the INVITE is not a retransmission, because otherwise the "ignore" flag would be set. 22453 * This means that either we are receiving a reinvite for a terminated dialog, or we are receiving an INVITE with 22454 * credentials based on one we challenged earlier. 22455 * 22456 * The action to take in either case is to treat the INVITE as though it contains an implicit ACK for the previous 22457 * transaction. Calling __sip_ack will take care of this by clearing the p->pendinginvite and removing the response 22458 * from the previous transaction from the list of outstanding packets. 22459 */ 22460 __sip_ack(p, p->pendinginvite, 1, 0); 22461 } else { 22462 /* We already have a pending invite. Sorry. You are on hold. */ 22463 p->glareinvite = seqno; 22464 if (p->rtp && find_sdp(req)) { 22465 struct ast_sockaddr addr; 22466 if (get_ip_and_port_from_sdp(req, SDP_AUDIO, &addr)) { 22467 ast_log(LOG_WARNING, "Failed to set an alternate media source on glared reinvite. Audio may not work properly on this call.\n"); 22468 } else { 22469 ast_rtp_instance_set_alt_remote_address(p->rtp, &addr); 22470 } 22471 if (p->vrtp) { 22472 if (get_ip_and_port_from_sdp(req, SDP_VIDEO, &addr)) { 22473 ast_log(LOG_WARNING, "Failed to set an alternate media source on glared reinvite. Video may not work properly on this call.\n"); 22474 } else { 22475 ast_rtp_instance_set_alt_remote_address(p->vrtp, &addr); 22476 } 22477 } 22478 } 22479 transmit_response_reliable(p, "491 Request Pending", req); 22480 check_via(p, req); 22481 ast_debug(1, "Got INVITE on call where we already have pending INVITE, deferring that - %s\n", p->callid); 22482 /* Don't destroy dialog here */ 22483 res = 0; 22484 goto request_invite_cleanup; 22485 } 22486 } 22487 22488 p_replaces = get_header(req, "Replaces"); 22489 if (!ast_strlen_zero(p_replaces)) { 22490 /* We have a replaces header */ 22491 char *ptr; 22492 char *fromtag = NULL; 22493 char *totag = NULL; 22494 char *start, *to; 22495 int error = 0; 22496 22497 if (p->owner) { 22498 ast_debug(3, "INVITE w Replaces on existing call? Refusing action. [%s]\n", p->callid); 22499 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 22500 check_via(p, req); 22501 copy_request(&p->initreq, req); 22502 /* Do not destroy existing call */ 22503 res = -1; 22504 goto request_invite_cleanup; 22505 } 22506 22507 if (sipdebug) 22508 ast_debug(3, "INVITE part of call transfer. Replaces [%s]\n", p_replaces); 22509 /* Create a buffer we can manipulate */ 22510 replace_id = ast_strdupa(p_replaces); 22511 ast_uri_decode(replace_id); 22512 22513 if (!p->refer && !sip_refer_allocate(p)) { 22514 transmit_response_reliable(p, "500 Server Internal Error", req); 22515 append_history(p, "Xfer", "INVITE/Replace Failed. Out of memory."); 22516 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22517 p->invitestate = INV_COMPLETED; 22518 check_via(p, req); 22519 copy_request(&p->initreq, req); 22520 res = -1; 22521 goto request_invite_cleanup; 22522 } 22523 22524 /* Todo: (When we find phones that support this) 22525 if the replaces header contains ";early-only" 22526 we can only replace the call in early 22527 stage, not after it's up. 22528 22529 If it's not in early mode, 486 Busy. 22530 */ 22531 22532 /* Skip leading whitespace */ 22533 replace_id = ast_skip_blanks(replace_id); 22534 22535 start = replace_id; 22536 while ( (ptr = strsep(&start, ";")) ) { 22537 ptr = ast_skip_blanks(ptr); /* XXX maybe unnecessary ? */ 22538 if ( (to = strcasestr(ptr, "to-tag=") ) ) 22539 totag = to + 7; /* skip the keyword */ 22540 else if ( (to = strcasestr(ptr, "from-tag=") ) ) { 22541 fromtag = to + 9; /* skip the keyword */ 22542 fromtag = strsep(&fromtag, "&"); /* trim what ? */ 22543 } 22544 } 22545 22546 if (sipdebug) 22547 ast_debug(4, "Invite/replaces: Will use Replace-Call-ID : %s Fromtag: %s Totag: %s\n", 22548 replace_id, 22549 fromtag ? fromtag : "<no from tag>", 22550 totag ? totag : "<no to tag>"); 22551 22552 /* Try to find call that we are replacing. 22553 If we have a Replaces header, we need to cancel that call if we succeed with this call. 22554 First we cheat a little and look for a magic call-id from phones that support 22555 dialog-info+xml so we can do technology independent pickup... */ 22556 if (strncmp(replace_id, "pickup-", 7) == 0) { 22557 struct sip_pvt *subscription = NULL; 22558 replace_id += 7; /* Worst case we are looking at \0 */ 22559 22560 if ((subscription = get_sip_pvt_byid_locked(replace_id, totag, fromtag)) == NULL) { 22561 ast_log(LOG_NOTICE, "Unable to find subscription with call-id: %s\n", replace_id); 22562 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replaces)", req); 22563 error = 1; 22564 } else { 22565 ast_log(LOG_NOTICE, "Trying to pick up %s@%s\n", subscription->exten, subscription->context); 22566 ast_copy_string(pickup.exten, subscription->exten, sizeof(pickup.exten)); 22567 ast_copy_string(pickup.context, subscription->context, sizeof(pickup.context)); 22568 sip_pvt_unlock(subscription); 22569 if (subscription->owner) { 22570 ast_channel_unlock(subscription->owner); 22571 } 22572 subscription = dialog_unref(subscription, "unref dialog subscription"); 22573 } 22574 } 22575 22576 /* This locks both refer_call pvt and refer_call pvt's owner!!!*/ 22577 if (!error && ast_strlen_zero(pickup.exten) && (p->refer->refer_call = get_sip_pvt_byid_locked(replace_id, totag, fromtag)) == NULL) { 22578 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existent call id (%s)!\n", replace_id); 22579 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replaces)", req); 22580 error = 1; 22581 } else { 22582 refer_locked = 1; 22583 } 22584 22585 /* The matched call is the call from the transferer to Asterisk . 22586 We want to bridge the bridged part of the call to the 22587 incoming invite, thus taking over the refered call */ 22588 22589 if (p->refer->refer_call == p) { 22590 ast_log(LOG_NOTICE, "INVITE with replaces into it's own call id (%s == %s)!\n", replace_id, p->callid); 22591 transmit_response_reliable(p, "400 Bad request", req); /* The best way to not not accept the transfer */ 22592 error = 1; 22593 } 22594 22595 if (!error && ast_strlen_zero(pickup.exten) && !p->refer->refer_call->owner) { 22596 /* Oops, someting wrong anyway, no owner, no call */ 22597 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-existing call id (%s)!\n", replace_id); 22598 /* Check for better return code */ 22599 transmit_response_reliable(p, "481 Call Leg Does Not Exist (Replace)", req); 22600 error = 1; 22601 } 22602 22603 if (!error && ast_strlen_zero(pickup.exten) && p->refer->refer_call->owner->_state != AST_STATE_RINGING && p->refer->refer_call->owner->_state != AST_STATE_RING && p->refer->refer_call->owner->_state != AST_STATE_UP) { 22604 ast_log(LOG_NOTICE, "Supervised transfer attempted to replace non-ringing or active call id (%s)!\n", replace_id); 22605 transmit_response_reliable(p, "603 Declined (Replaces)", req); 22606 error = 1; 22607 } 22608 22609 if (error) { /* Give up this dialog */ 22610 append_history(p, "Xfer", "INVITE/Replace Failed."); 22611 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22612 sip_pvt_unlock(p); 22613 if (p->refer->refer_call) { 22614 sip_pvt_unlock(p->refer->refer_call); 22615 if (p->refer->refer_call->owner) { 22616 ast_channel_unlock(p->refer->refer_call->owner); 22617 } 22618 p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); 22619 } 22620 refer_locked = 0; 22621 p->invitestate = INV_COMPLETED; 22622 check_via(p, req); 22623 copy_request(&p->initreq, req); 22624 res = -1; 22625 goto request_invite_cleanup; 22626 } 22627 } 22628 22629 /* Check if this is an INVITE that sets up a new dialog or 22630 a re-invite in an existing dialog */ 22631 22632 if (!req->ignore) { 22633 int newcall = (p->initreq.headers ? TRUE : FALSE); 22634 22635 if (sip_cancel_destroy(p)) 22636 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 22637 /* This also counts as a pending invite */ 22638 p->pendinginvite = seqno; 22639 check_via(p, req); 22640 22641 copy_request(&p->initreq, req); /* Save this INVITE as the transaction basis */ 22642 if (sipdebug) 22643 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 22644 if (!p->owner) { /* Not a re-invite */ 22645 if (debug) 22646 ast_verbose("Using INVITE request as basis request - %s\n", p->callid); 22647 if (newcall) 22648 append_history(p, "Invite", "New call: %s", p->callid); 22649 parse_ok_contact(p, req); 22650 } else { /* Re-invite on existing call */ 22651 ast_clear_flag(&p->flags[0], SIP_OUTGOING); /* This is now an inbound dialog */ 22652 if (get_rpid(p, req)) { 22653 struct ast_party_connected_line connected; 22654 struct ast_set_party_connected_line update_connected; 22655 22656 ast_party_connected_line_init(&connected); 22657 memset(&update_connected, 0, sizeof(update_connected)); 22658 22659 update_connected.id.number = 1; 22660 connected.id.number.valid = 1; 22661 connected.id.number.str = (char *) p->cid_num; 22662 connected.id.number.presentation = p->callingpres; 22663 22664 update_connected.id.name = 1; 22665 connected.id.name.valid = 1; 22666 connected.id.name.str = (char *) p->cid_name; 22667 connected.id.name.presentation = p->callingpres; 22668 22669 connected.id.tag = (char *) p->cid_tag; 22670 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER; 22671 ast_channel_queue_connected_line_update(p->owner, &connected, 22672 &update_connected); 22673 } 22674 /* Handle SDP here if we already have an owner */ 22675 if (find_sdp(req)) { 22676 if (process_sdp(p, req, SDP_T38_INITIATE)) { 22677 if (!ast_strlen_zero(get_header(req, "Content-Encoding"))) { 22678 /* Asterisk does not yet support any Content-Encoding methods. Always 22679 * attempt to process the sdp, but return a 415 if a Content-Encoding header 22680 * was present after processing failed. */ 22681 transmit_response_reliable(p, "415 Unsupported Media type", req); 22682 } else { 22683 transmit_response_reliable(p, "488 Not acceptable here", req); 22684 } 22685 if (!p->lastinvite) 22686 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22687 res = -1; 22688 goto request_invite_cleanup; 22689 } 22690 ast_queue_control(p->owner, AST_CONTROL_SRCUPDATE); 22691 } else { 22692 p->jointcapability = p->capability; 22693 ast_debug(1, "Hm.... No sdp for the moment\n"); 22694 /* Some devices signal they want to be put off hold by sending a re-invite 22695 *without* an SDP, which is supposed to mean "Go back to your state" 22696 and since they put os on remote hold, we go back to off hold */ 22697 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 22698 ast_queue_control(p->owner, AST_CONTROL_UNHOLD); 22699 /* Activate a re-invite */ 22700 ast_queue_frame(p->owner, &ast_null_frame); 22701 change_hold_state(p, req, FALSE, 0); 22702 } 22703 } 22704 if (p->do_history) /* This is a response, note what it was for */ 22705 append_history(p, "ReInv", "Re-invite received"); 22706 } 22707 } else if (debug) 22708 ast_verbose("Ignoring this INVITE request\n"); 22709 22710 if (!p->lastinvite && !req->ignore && !p->owner) { 22711 /* This is a new invite */ 22712 /* Handle authentication if this is our first invite */ 22713 int cc_recall_core_id = -1; 22714 set_pvt_allowed_methods(p, req); 22715 res = check_user_full(p, req, SIP_INVITE, e, XMIT_RELIABLE, addr, &authpeer); 22716 if (res == AUTH_CHALLENGE_SENT) { 22717 p->invitestate = INV_COMPLETED; /* Needs to restart in another INVITE transaction */ 22718 res = 0; 22719 goto request_invite_cleanup; 22720 } 22721 if (res < 0) { /* Something failed in authentication */ 22722 if (res == AUTH_FAKE_AUTH) { 22723 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 22724 transmit_fake_auth_response(p, SIP_INVITE, req, XMIT_RELIABLE); 22725 } else { 22726 ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From")); 22727 transmit_response_reliable(p, "403 Forbidden", req); 22728 } 22729 p->invitestate = INV_COMPLETED; 22730 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22731 res = 0; 22732 goto request_invite_cleanup; 22733 } 22734 22735 /* Successful authentication and peer matching so record the peer related to this pvt (for easy access to peer settings) */ 22736 if (p->relatedpeer) { 22737 p->relatedpeer = unref_peer(p->relatedpeer,"unsetting the relatedpeer field in the dialog, before it is set to something else."); 22738 } 22739 if (authpeer) { 22740 p->relatedpeer = ref_peer(authpeer, "setting dialog's relatedpeer pointer"); 22741 } 22742 22743 req->authenticated = 1; 22744 22745 /* We have a successful authentication, process the SDP portion if there is one */ 22746 if (find_sdp(req)) { 22747 if (process_sdp(p, req, SDP_T38_INITIATE)) { 22748 /* Asterisk does not yet support any Content-Encoding methods. Always 22749 * attempt to process the sdp, but return a 415 if a Content-Encoding header 22750 * was present after processing fails. */ 22751 if (!ast_strlen_zero(get_header(req, "Content-Encoding"))) { 22752 transmit_response_reliable(p, "415 Unsupported Media type", req); 22753 } else { 22754 /* Unacceptable codecs */ 22755 transmit_response_reliable(p, "488 Not acceptable here", req); 22756 } 22757 p->invitestate = INV_COMPLETED; 22758 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22759 ast_debug(1, "No compatible codecs for this SIP call.\n"); 22760 res = -1; 22761 goto request_invite_cleanup; 22762 } 22763 } else { /* No SDP in invite, call control session */ 22764 p->jointcapability = p->capability; 22765 ast_debug(2, "No SDP in Invite, third party call control\n"); 22766 } 22767 22768 /* Queue NULL frame to prod ast_rtp_bridge if appropriate */ 22769 /* This seems redundant ... see !p-owner above */ 22770 if (p->owner) 22771 ast_queue_frame(p->owner, &ast_null_frame); 22772 22773 22774 /* Initialize the context if it hasn't been already */ 22775 if (ast_strlen_zero(p->context)) 22776 ast_string_field_set(p, context, sip_cfg.default_context); 22777 22778 22779 /* Check number of concurrent calls -vs- incoming limit HERE */ 22780 ast_debug(1, "Checking SIP call limits for device %s\n", p->username); 22781 if ((res = update_call_counter(p, INC_CALL_LIMIT))) { 22782 if (res < 0) { 22783 ast_log(LOG_NOTICE, "Failed to place call for device %s, too many calls\n", p->username); 22784 transmit_response_reliable(p, "480 Temporarily Unavailable (Call limit) ", req); 22785 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22786 p->invitestate = INV_COMPLETED; 22787 } 22788 res = 0; 22789 goto request_invite_cleanup; 22790 } 22791 gotdest = get_destination(p, NULL, &cc_recall_core_id); /* Get destination right away */ 22792 extract_uri(p, req); /* Get the Contact URI */ 22793 build_contact(p); /* Build our contact header */ 22794 22795 if (p->rtp) { 22796 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 22797 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 22798 } 22799 22800 if (!replace_id && (gotdest != SIP_GET_DEST_EXTEN_FOUND)) { /* No matching extension found */ 22801 switch(gotdest) { 22802 case SIP_GET_DEST_INVALID_URI: 22803 transmit_response_reliable(p, "416 Unsupported URI scheme", req); 22804 break; 22805 case SIP_GET_DEST_EXTEN_MATCHMORE: 22806 if (ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP) 22807 == SIP_PAGE2_ALLOWOVERLAP_YES) { 22808 transmit_response_reliable(p, "484 Address Incomplete", req); 22809 break; 22810 } 22811 /* 22812 * XXX We would have to implement collecting more digits in 22813 * chan_sip for any other schemes of overlap dialing. 22814 * 22815 * For SIP_PAGE2_ALLOWOVERLAP_DTMF it is better to do this in 22816 * the dialplan using the Incomplete application rather than 22817 * having the channel driver do it. 22818 */ 22819 /* Fall through */ 22820 case SIP_GET_DEST_EXTEN_NOT_FOUND: 22821 { 22822 char *decoded_exten = ast_strdupa(p->exten); 22823 transmit_response_reliable(p, "404 Not Found", req); 22824 ast_uri_decode(decoded_exten); 22825 ast_log(LOG_NOTICE, "Call from '%s' (%s) to extension" 22826 " '%s' rejected because extension not found in context '%s'.\n", 22827 S_OR(p->username, p->peername), ast_sockaddr_stringify(&p->recv), decoded_exten, p->context); 22828 } 22829 break; 22830 case SIP_GET_DEST_REFUSED: 22831 default: 22832 transmit_response_reliable(p, "403 Forbidden", req); 22833 } /* end switch */ 22834 22835 p->invitestate = INV_COMPLETED; 22836 update_call_counter(p, DEC_CALL_LIMIT); 22837 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22838 res = 0; 22839 goto request_invite_cleanup; 22840 } else { 22841 22842 /* If no extension was specified, use the s one */ 22843 /* Basically for calling to IP/Host name only */ 22844 if (ast_strlen_zero(p->exten)) 22845 ast_string_field_set(p, exten, "s"); 22846 /* Initialize our tag */ 22847 22848 make_our_tag(p); 22849 /* First invitation - create the channel. Allocation 22850 * failures are handled below. */ 22851 c = sip_new(p, AST_STATE_DOWN, S_OR(p->peername, NULL), NULL); 22852 if (cc_recall_core_id != -1) { 22853 ast_setup_cc_recall_datastore(c, cc_recall_core_id); 22854 ast_cc_agent_set_interfaces_chanvar(c); 22855 } 22856 *recount = 1; 22857 22858 /* Save Record-Route for any later requests we make on this dialogue */ 22859 build_route(p, req, 0, 0); 22860 22861 if (c) { 22862 ast_party_redirecting_init(&redirecting); 22863 memset(&update_redirecting, 0, sizeof(update_redirecting)); 22864 change_redirecting_information(p, req, &redirecting, &update_redirecting, 22865 FALSE); /*Will return immediately if no Diversion header is present */ 22866 ast_channel_set_redirecting(c, &redirecting, &update_redirecting); 22867 ast_party_redirecting_free(&redirecting); 22868 } 22869 } 22870 } else { 22871 ast_party_redirecting_init(&redirecting); 22872 memset(&update_redirecting, 0, sizeof(update_redirecting)); 22873 if (sipdebug) { 22874 if (!req->ignore) 22875 ast_debug(2, "Got a SIP re-invite for call %s\n", p->callid); 22876 else 22877 ast_debug(2, "Got a SIP re-transmit of INVITE for call %s\n", p->callid); 22878 } 22879 if (!req->ignore) 22880 reinvite = 1; 22881 c = p->owner; 22882 change_redirecting_information(p, req, &redirecting, &update_redirecting, FALSE); /*Will return immediately if no Diversion header is present */ 22883 if (c) { 22884 ast_channel_set_redirecting(c, &redirecting, &update_redirecting); 22885 } 22886 ast_party_redirecting_free(&redirecting); 22887 } 22888 22889 /* Session-Timers */ 22890 if ((p->sipoptions & SIP_OPT_TIMER) && !ast_strlen_zero(get_header(req, "Session-Expires"))) { 22891 /* The UAC has requested session-timers for this session. Negotiate 22892 the session refresh interval and who will be the refresher */ 22893 ast_debug(2, "Incoming INVITE with 'timer' option supported and \"Session-Expires\" header.\n"); 22894 22895 /* Allocate Session-Timers struct w/in the dialog */ 22896 if (!p->stimer) 22897 sip_st_alloc(p); 22898 22899 /* Parse the Session-Expires header */ 22900 p_uac_se_hdr = get_header(req, "Session-Expires"); 22901 rtn = parse_session_expires(p_uac_se_hdr, &uac_max_se, &st_ref); 22902 if (rtn != 0) { 22903 transmit_response_reliable(p, "400 Session-Expires Invalid Syntax", req); 22904 p->invitestate = INV_COMPLETED; 22905 if (!p->lastinvite) { 22906 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22907 } 22908 res = -1; 22909 goto request_invite_cleanup; 22910 } 22911 22912 /* Parse the Min-SE header */ 22913 p_uac_min_se = get_header(req, "Min-SE"); 22914 if (!ast_strlen_zero(p_uac_min_se)) { 22915 rtn = parse_minse(p_uac_min_se, &uac_min_se); 22916 if (rtn != 0) { 22917 transmit_response_reliable(p, "400 Min-SE Invalid Syntax", req); 22918 p->invitestate = INV_COMPLETED; 22919 if (!p->lastinvite) { 22920 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22921 } 22922 res = -1; 22923 goto request_invite_cleanup; 22924 } 22925 } 22926 22927 dlg_min_se = st_get_se(p, FALSE); 22928 switch (st_get_mode(p, 1)) { 22929 case SESSION_TIMER_MODE_ACCEPT: 22930 case SESSION_TIMER_MODE_ORIGINATE: 22931 if (uac_max_se > 0 && uac_max_se < dlg_min_se) { 22932 transmit_response_with_minse(p, "422 Session Interval Too Small", req, dlg_min_se); 22933 p->invitestate = INV_COMPLETED; 22934 if (!p->lastinvite) { 22935 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22936 } 22937 res = -1; 22938 goto request_invite_cleanup; 22939 } 22940 22941 p->stimer->st_active_peer_ua = TRUE; 22942 st_active = TRUE; 22943 if (st_ref == SESSION_TIMER_REFRESHER_AUTO) { 22944 st_ref = st_get_refresher(p); 22945 } 22946 22947 if (uac_max_se > 0) { 22948 int dlg_max_se = st_get_se(p, TRUE); 22949 if (dlg_max_se >= uac_min_se) { 22950 st_interval = (uac_max_se < dlg_max_se) ? uac_max_se : dlg_max_se; 22951 } else { 22952 st_interval = uac_max_se; 22953 } 22954 } else { 22955 /* Set to default max value */ 22956 st_interval = global_max_se; 22957 } 22958 break; 22959 22960 case SESSION_TIMER_MODE_REFUSE: 22961 if (p->reqsipoptions & SIP_OPT_TIMER) { 22962 transmit_response_with_unsupported(p, "420 Option Disabled", req, required); 22963 ast_log(LOG_WARNING, "Received SIP INVITE with supported but disabled option: %s\n", required); 22964 p->invitestate = INV_COMPLETED; 22965 if (!p->lastinvite) { 22966 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22967 } 22968 res = -1; 22969 goto request_invite_cleanup; 22970 } 22971 break; 22972 22973 default: 22974 ast_log(LOG_ERROR, "Internal Error %d at %s:%d\n", st_get_mode(p, 1), __FILE__, __LINE__); 22975 break; 22976 } 22977 } else { 22978 /* The UAC did not request session-timers. Asterisk (UAS), will now decide 22979 (based on session-timer-mode in sip.conf) whether to run session-timers for 22980 this session or not. */ 22981 switch (st_get_mode(p, 1)) { 22982 case SESSION_TIMER_MODE_ORIGINATE: 22983 st_active = TRUE; 22984 st_interval = st_get_se(p, TRUE); 22985 st_ref = SESSION_TIMER_REFRESHER_UAS; 22986 p->stimer->st_active_peer_ua = FALSE; 22987 break; 22988 22989 default: 22990 break; 22991 } 22992 } 22993 22994 if (reinvite == 0) { 22995 /* Session-Timers: Start session refresh timer based on negotiation/config */ 22996 if (st_active == TRUE) { 22997 p->stimer->st_active = TRUE; 22998 p->stimer->st_interval = st_interval; 22999 p->stimer->st_ref = st_ref; 23000 start_session_timer(p); 23001 } 23002 } else { 23003 if (p->stimer->st_active == TRUE) { 23004 /* Session-Timers: A re-invite request sent within a dialog will serve as 23005 a refresh request, no matter whether the re-invite was sent for refreshing 23006 the session or modifying it.*/ 23007 ast_debug (2, "Restarting session-timers on a refresh - %s\n", p->callid); 23008 23009 /* The UAC may be adjusting the session-timers mid-session */ 23010 if (st_interval > 0) { 23011 p->stimer->st_interval = st_interval; 23012 p->stimer->st_ref = st_ref; 23013 } 23014 23015 restart_session_timer(p); 23016 if (p->stimer->st_expirys > 0) { 23017 p->stimer->st_expirys--; 23018 } 23019 } 23020 } 23021 23022 if (!req->ignore && p) 23023 p->lastinvite = seqno; 23024 23025 if (c && replace_id) { /* Attended transfer or call pickup - we're the target */ 23026 if (!ast_strlen_zero(pickup.exten)) { 23027 append_history(p, "Xfer", "INVITE/Replace received"); 23028 23029 /* Let the caller know we're giving it a shot */ 23030 transmit_response(p, "100 Trying", req); 23031 p->invitestate = INV_PROCEEDING; 23032 ast_setstate(c, AST_STATE_RING); 23033 23034 /* Do the pickup itself */ 23035 ast_channel_unlock(c); 23036 *nounlock = 1; 23037 23038 /* since p->owner (c) is unlocked, we need to go ahead and unlock pvt for both 23039 * magic pickup and ast_hangup. Both of these functions will attempt to lock 23040 * p->owner again, which can cause a deadlock if we already hold a lock on p. 23041 * Locking order is, channel then pvt. Dead lock avoidance must be used if 23042 * called the other way around. */ 23043 sip_pvt_unlock(p); 23044 do_magic_pickup(c, pickup.exten, pickup.context); 23045 /* Now we're either masqueraded or we failed to pickup, in either case we... */ 23046 ast_hangup(c); 23047 sip_pvt_lock(p); /* pvt is expected to remain locked on return, so re-lock it */ 23048 23049 res = 0; 23050 goto request_invite_cleanup; 23051 } else { 23052 /* Go and take over the target call */ 23053 if (sipdebug) 23054 ast_debug(4, "Sending this call to the invite/replcaes handler %s\n", p->callid); 23055 res = handle_invite_replaces(p, req, debug, seqno, addr, nounlock); 23056 refer_locked = 0; 23057 goto request_invite_cleanup; 23058 } 23059 } 23060 23061 23062 if (c) { /* We have a call -either a new call or an old one (RE-INVITE) */ 23063 enum ast_channel_state c_state = c->_state; 23064 23065 if (c_state != AST_STATE_UP && reinvite && 23066 (p->invitestate == INV_TERMINATED || p->invitestate == INV_CONFIRMED)) { 23067 /* If these conditions are true, and the channel is still in the 'ringing' 23068 * state, then this likely means that we have a situation where the initial 23069 * INVITE transaction has completed *but* the channel's state has not yet been 23070 * changed to UP. The reason this could happen is if the reinvite is received 23071 * on the SIP socket prior to an application calling ast_read on this channel 23072 * to read the answer frame we earlier queued on it. In this case, the reinvite 23073 * is completely legitimate so we need to handle this the same as if the channel 23074 * were already UP. Thus we are purposely falling through to the AST_STATE_UP case. 23075 */ 23076 c_state = AST_STATE_UP; 23077 } 23078 23079 switch(c_state) { 23080 case AST_STATE_DOWN: 23081 ast_debug(2, "%s: New call is still down.... Trying... \n", c->name); 23082 transmit_provisional_response(p, "100 Trying", req, 0); 23083 p->invitestate = INV_PROCEEDING; 23084 ast_setstate(c, AST_STATE_RING); 23085 if (strcmp(p->exten, ast_pickup_ext())) { /* Call to extension -start pbx on this call */ 23086 enum ast_pbx_result result; 23087 23088 result = ast_pbx_start(c); 23089 23090 switch(result) { 23091 case AST_PBX_FAILED: 23092 ast_log(LOG_WARNING, "Failed to start PBX :(\n"); 23093 p->invitestate = INV_COMPLETED; 23094 transmit_response_reliable(p, "503 Unavailable", req); 23095 break; 23096 case AST_PBX_CALL_LIMIT: 23097 ast_log(LOG_WARNING, "Failed to start PBX (call limit reached) \n"); 23098 p->invitestate = INV_COMPLETED; 23099 transmit_response_reliable(p, "480 Temporarily Unavailable", req); 23100 break; 23101 case AST_PBX_SUCCESS: 23102 /* nothing to do */ 23103 break; 23104 } 23105 23106 if (result) { 23107 23108 /* Unlock locks so ast_hangup can do its magic */ 23109 ast_channel_unlock(c); 23110 *nounlock = 1; 23111 sip_pvt_unlock(p); 23112 ast_hangup(c); 23113 sip_pvt_lock(p); 23114 c = NULL; 23115 } 23116 } else { /* Pickup call in call group */ 23117 if (sip_pickup(c)) { 23118 ast_log(LOG_WARNING, "Failed to start Group pickup by %s\n", c->name); 23119 transmit_response_reliable(p, "480 Temporarily Unavailable", req); 23120 sip_alreadygone(p); 23121 c->hangupcause = AST_CAUSE_FAILURE; 23122 23123 /* Unlock locks so ast_hangup can do its magic */ 23124 ast_channel_unlock(c); 23125 *nounlock = 1; 23126 23127 p->invitestate = INV_COMPLETED; 23128 sip_pvt_unlock(p); 23129 ast_hangup(c); 23130 sip_pvt_lock(p); 23131 c = NULL; 23132 } 23133 } 23134 break; 23135 case AST_STATE_RING: 23136 transmit_provisional_response(p, "100 Trying", req, 0); 23137 p->invitestate = INV_PROCEEDING; 23138 break; 23139 case AST_STATE_RINGING: 23140 transmit_provisional_response(p, "180 Ringing", req, 0); 23141 p->invitestate = INV_PROCEEDING; 23142 break; 23143 case AST_STATE_UP: 23144 ast_debug(2, "%s: This call is UP.... \n", c->name); 23145 23146 transmit_response(p, "100 Trying", req); 23147 23148 if (p->t38.state == T38_PEER_REINVITE) { 23149 if (p->t38id > -1) { 23150 /* reset t38 abort timer */ 23151 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "remove ref for t38id")); 23152 } 23153 p->t38id = ast_sched_add(sched, 5000, sip_t38_abort, dialog_ref(p, "passing dialog ptr into sched structure based on t38id for sip_t38_abort.")); 23154 } else if (p->t38.state == T38_ENABLED) { 23155 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 23156 transmit_response_with_t38_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL))); 23157 } else if (p->t38.state == T38_DISABLED) { 23158 /* If this is not a re-invite or something to ignore - it's critical */ 23159 if (p->srtp && !ast_test_flag(p->srtp, SRTP_CRYPTO_OFFER_OK)) { 23160 ast_log(LOG_WARNING, "Target does not support required crypto\n"); 23161 transmit_response_reliable(p, "488 Not Acceptable Here (crypto)", req); 23162 } else { 23163 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 23164 transmit_response_with_sdp(p, "200 OK", req, (reinvite ? XMIT_RELIABLE : (req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL)), p->session_modify == TRUE ? FALSE : TRUE, FALSE); 23165 ast_queue_control(p->owner, AST_CONTROL_UPDATE_RTP_PEER); 23166 } 23167 } 23168 23169 p->invitestate = INV_TERMINATED; 23170 break; 23171 default: 23172 ast_log(LOG_WARNING, "Don't know how to handle INVITE in state %d\n", c->_state); 23173 transmit_response(p, "100 Trying", req); 23174 break; 23175 } 23176 } else { 23177 if (p && (p->autokillid == -1)) { 23178 const char *msg; 23179 23180 if (!p->jointcapability) 23181 msg = "488 Not Acceptable Here (codec error)"; 23182 else { 23183 ast_log(LOG_NOTICE, "Unable to create/find SIP channel for this INVITE\n"); 23184 msg = "503 Unavailable"; 23185 } 23186 transmit_response_reliable(p, msg, req); 23187 p->invitestate = INV_COMPLETED; 23188 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 23189 } 23190 } 23191 23192 request_invite_cleanup: 23193 23194 if (refer_locked && p->refer && p->refer->refer_call) { 23195 sip_pvt_unlock(p->refer->refer_call); 23196 if (p->refer->refer_call->owner) { 23197 ast_channel_unlock(p->refer->refer_call->owner); 23198 } 23199 p->refer->refer_call = dialog_unref(p->refer->refer_call, "unref dialog p->refer->refer_call"); 23200 } 23201 if (authpeer) { 23202 authpeer = unref_peer(authpeer, "unref_peer, from handle_request_invite authpeer"); 23203 } 23204 23205 return res; 23206 }
| static int handle_request_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Handle incoming MESSAGE request.
Definition at line 24084 of file chan_sip.c.
References ast_verbose, receive_message(), and transmit_response().
Referenced by handle_incoming().
24085 { 24086 if (!req->ignore) { 24087 if (req->debug) 24088 ast_verbose("Receiving message!\n"); 24089 receive_message(p, req); 24090 } else 24091 transmit_response(p, "202 Accepted", req); 24092 return 1; 24093 }
| static int handle_request_notify | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct ast_sockaddr * | addr, | |||
| uint32_t | seqno, | |||
| const char * | e | |||
| ) | [static] |
Handle incoming notifications.
Definition at line 21857 of file chan_sip.c.
References AST_CONTROL_TRANSFER, ast_debug, AST_EVENT_IE_CONTEXT, AST_EVENT_IE_END, AST_EVENT_IE_MAILBOX, AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_STR, AST_EVENT_IE_PLTYPE_UINT, AST_EVENT_MWI, ast_event_new(), ast_event_queue_and_cache(), ast_log(), ast_queue_control_data(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), AST_TRANSFER_FAILED, AST_TRANSFER_SUCCESS, FALSE, find_peer(), get_body(), get_header(), get_msg_text(), handle_cc_notify(), LOG_NOTICE, LOG_WARNING, mailbox, sip_scheddestroy(), transmit_response(), TRUE, and unref_peer().
Referenced by handle_incoming().
21858 { 21859 /* This is mostly a skeleton for future improvements */ 21860 /* Mostly created to return proper answers on notifications on outbound REFER's */ 21861 int res = 0; 21862 const char *event = get_header(req, "Event"); 21863 char *sep; 21864 21865 if( (sep = strchr(event, ';')) ) { /* XXX bug here - overwriting string ? */ 21866 *sep++ = '\0'; 21867 } 21868 21869 if (sipdebug) 21870 ast_debug(2, "Got NOTIFY Event: %s\n", event); 21871 21872 if (!strcmp(event, "refer")) { 21873 /* Save nesting depth for now, since there might be other events we will 21874 support in the future */ 21875 21876 /* Handle REFER notifications */ 21877 21878 char buf[1024]; 21879 char *cmd, *code; 21880 int respcode; 21881 int success = TRUE; 21882 21883 /* EventID for each transfer... EventID is basically the REFER cseq 21884 21885 We are getting notifications on a call that we transfered 21886 We should hangup when we are getting a 200 OK in a sipfrag 21887 Check if we have an owner of this event */ 21888 21889 /* Check the content type */ 21890 if (strncasecmp(get_header(req, "Content-Type"), "message/sipfrag", strlen("message/sipfrag"))) { 21891 /* We need a sipfrag */ 21892 transmit_response(p, "400 Bad request", req); 21893 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21894 return -1; 21895 } 21896 21897 /* Get the text of the attachment */ 21898 if (get_msg_text(buf, sizeof(buf), req)) { 21899 ast_log(LOG_WARNING, "Unable to retrieve attachment from NOTIFY %s\n", p->callid); 21900 transmit_response(p, "400 Bad request", req); 21901 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 21902 return -1; 21903 } 21904 21905 /* 21906 From the RFC... 21907 A minimal, but complete, implementation can respond with a single 21908 NOTIFY containing either the body: 21909 SIP/2.0 100 Trying 21910 21911 if the subscription is pending, the body: 21912 SIP/2.0 200 OK 21913 if the reference was successful, the body: 21914 SIP/2.0 503 Service Unavailable 21915 if the reference failed, or the body: 21916 SIP/2.0 603 Declined 21917 21918 if the REFER request was accepted before approval to follow the 21919 reference could be obtained and that approval was subsequently denied 21920 (see Section 2.4.7). 21921 21922 If there are several REFERs in the same dialog, we need to 21923 match the ID of the event header... 21924 */ 21925 ast_debug(3, "* SIP Transfer NOTIFY Attachment: \n---%s\n---\n", buf); 21926 cmd = ast_skip_blanks(buf); 21927 code = cmd; 21928 /* We are at SIP/2.0 */ 21929 while(*code && (*code > 32)) { /* Search white space */ 21930 code++; 21931 } 21932 *code++ = '\0'; 21933 code = ast_skip_blanks(code); 21934 sep = code; 21935 sep++; 21936 while(*sep && (*sep > 32)) { /* Search white space */ 21937 sep++; 21938 } 21939 *sep++ = '\0'; /* Response string */ 21940 respcode = atoi(code); 21941 switch (respcode) { 21942 case 200: /* OK: The new call is up, hangup this call */ 21943 /* Hangup the call that we are replacing */ 21944 break; 21945 case 301: /* Moved permenantly */ 21946 case 302: /* Moved temporarily */ 21947 /* Do we get the header in the packet in this case? */ 21948 success = FALSE; 21949 break; 21950 case 503: /* Service Unavailable: The new call failed */ 21951 case 603: /* Declined: Not accepted */ 21952 /* Cancel transfer, continue the current call */ 21953 success = FALSE; 21954 break; 21955 case 0: /* Parse error */ 21956 /* Cancel transfer, continue the current call */ 21957 ast_log(LOG_NOTICE, "Error parsing sipfrag in NOTIFY in response to REFER.\n"); 21958 success = FALSE; 21959 break; 21960 default: 21961 if (respcode < 200) { 21962 /* ignore provisional responses */ 21963 success = -1; 21964 } else { 21965 ast_log(LOG_NOTICE, "Got unknown code '%d' in NOTIFY in response to REFER.\n", respcode); 21966 success = FALSE; 21967 } 21968 break; 21969 } 21970 if (success == FALSE) { 21971 ast_log(LOG_NOTICE, "Transfer failed. Sorry. Nothing further to do with this call\n"); 21972 } 21973 21974 if (p->owner && success != -1) { 21975 enum ast_control_transfer message = success ? AST_TRANSFER_SUCCESS : AST_TRANSFER_FAILED; 21976 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 21977 } 21978 /* Confirm that we received this packet */ 21979 transmit_response(p, "200 OK", req); 21980 } else if (!strcmp(event, "message-summary")) { 21981 const char *mailbox = NULL; 21982 char *c = ast_strdupa(get_body(req, "Voice-Message", ':')); 21983 21984 if (!p->mwi) { 21985 struct sip_peer *peer = find_peer(NULL, &p->recv, TRUE, FINDPEERS, FALSE, p->socket.type); 21986 21987 if (peer) { 21988 mailbox = ast_strdupa(peer->unsolicited_mailbox); 21989 unref_peer(peer, "removing unsolicited mwi ref"); 21990 } 21991 } else { 21992 mailbox = p->mwi->mailbox; 21993 } 21994 21995 if (!ast_strlen_zero(mailbox) && !ast_strlen_zero(c)) { 21996 char *old = strsep(&c, " "); 21997 char *new = strsep(&old, "/"); 21998 struct ast_event *event; 21999 22000 if ((event = ast_event_new(AST_EVENT_MWI, 22001 AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox, 22002 AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, "SIP_Remote", 22003 AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(new), 22004 AST_EVENT_IE_OLDMSGS, AST_EVENT_IE_PLTYPE_UINT, atoi(old), 22005 AST_EVENT_IE_END))) { 22006 ast_event_queue_and_cache(event); 22007 } 22008 transmit_response(p, "200 OK", req); 22009 } else { 22010 transmit_response(p, "489 Bad event", req); 22011 res = -1; 22012 } 22013 } else if (!strcmp(event, "keep-alive")) { 22014 /* Used by Sipura/Linksys for NAT pinhole, 22015 * just confirm that we received the packet. */ 22016 transmit_response(p, "200 OK", req); 22017 } else if (!strcmp(event, "call-completion")) { 22018 res = handle_cc_notify(p, req); 22019 } else { 22020 /* We don't understand this event. */ 22021 transmit_response(p, "489 Bad event", req); 22022 res = -1; 22023 } 22024 22025 if (!p->lastinvite) 22026 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22027 22028 return res; 22029 }
| static int handle_request_options | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct ast_sockaddr * | addr, | |||
| const char * | e | |||
| ) | [static] |
Handle incoming OPTIONS request An OPTIONS request should be answered like an INVITE from the same UA, including SDP.
Definition at line 22034 of file chan_sip.c.
References ast_log(), ast_shutting_down(), ast_string_field_set, ast_strlen_zero(), build_contact(), check_user(), context, copy_request(), get_destination(), get_header(), LOG_NOTICE, set_pvt_allowed_methods(), sip_cfg, sip_scheddestroy(), transmit_fake_auth_response(), transmit_response(), and transmit_response_with_allow().
Referenced by handle_incoming().
22035 { 22036 const char *msg; 22037 enum sip_get_dest_result gotdest; 22038 int res; 22039 22040 if (p->lastinvite) { 22041 /* if this is a request in an active dialog, just confirm that the dialog exists. */ 22042 transmit_response_with_allow(p, "200 OK", req, 0); 22043 return 0; 22044 } 22045 22046 if (sip_cfg.auth_options_requests) { 22047 /* Do authentication if this OPTIONS request began the dialog */ 22048 copy_request(&p->initreq, req); 22049 set_pvt_allowed_methods(p, req); 22050 res = check_user(p, req, SIP_OPTIONS, e, XMIT_UNRELIABLE, addr); 22051 if (res == AUTH_CHALLENGE_SENT) { 22052 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22053 return 0; 22054 } 22055 if (res < 0) { /* Something failed in authentication */ 22056 if (res == AUTH_FAKE_AUTH) { 22057 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 22058 transmit_fake_auth_response(p, SIP_OPTIONS, req, XMIT_UNRELIABLE); 22059 } else { 22060 ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From")); 22061 transmit_response(p, "403 Forbidden", req); 22062 } 22063 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22064 return 0; 22065 } 22066 } 22067 22068 /* must go through authentication before getting here */ 22069 gotdest = get_destination(p, req, NULL); 22070 build_contact(p); 22071 22072 if (ast_strlen_zero(p->context)) 22073 ast_string_field_set(p, context, sip_cfg.default_context); 22074 22075 if (ast_shutting_down()) { 22076 msg = "503 Unavailable"; 22077 } else { 22078 msg = "404 Not Found"; 22079 switch (gotdest) { 22080 case SIP_GET_DEST_INVALID_URI: 22081 msg = "416 Unsupported URI scheme"; 22082 break; 22083 case SIP_GET_DEST_EXTEN_MATCHMORE: 22084 case SIP_GET_DEST_REFUSED: 22085 case SIP_GET_DEST_EXTEN_NOT_FOUND: 22086 //msg = "404 Not Found"; 22087 break; 22088 case SIP_GET_DEST_EXTEN_FOUND: 22089 msg = "200 OK"; 22090 break; 22091 } 22092 } 22093 transmit_response_with_allow(p, msg, req, 0); 22094 22095 /* Destroy if this OPTIONS was the opening request, but not if 22096 it's in the middle of a normal call flow. */ 22097 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 22098 22099 return 0; 22100 }
| 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] |
Definition at line 24516 of file chan_sip.c.
References __sip_ack(), ast_log(), ast_string_field_set, ast_strlen_zero(), check_user(), determine_sip_publish_type(), get_esc(), get_header(), handle_sip_publish_initial(), handle_sip_publish_modify(), handle_sip_publish_refresh(), handle_sip_publish_remove(), LOG_NOTICE, pvt_set_needdestroy(), sip_scheddestroy(), transmit_fake_auth_response(), transmit_response(), transmit_response_reliable(), and transmit_response_with_minexpires().
Referenced by handle_incoming().
24517 { 24518 const char *etag = get_header(req, "SIP-If-Match"); 24519 const char *event = get_header(req, "Event"); 24520 struct event_state_compositor *esc; 24521 enum sip_publish_type publish_type; 24522 const char *expires_str = get_header(req, "Expires"); 24523 int expires_int; 24524 int auth_result; 24525 int handler_result = -1; 24526 24527 if (ast_strlen_zero(event)) { 24528 transmit_response(p, "489 Bad Event", req); 24529 pvt_set_needdestroy(p, "missing Event: header"); 24530 return -1; 24531 } 24532 24533 if (!(esc = get_esc(event))) { 24534 transmit_response(p, "489 Bad Event", req); 24535 pvt_set_needdestroy(p, "unknown event package in publish"); 24536 return -1; 24537 } 24538 24539 auth_result = check_user(p, req, SIP_PUBLISH, uri, XMIT_RELIABLE, addr); 24540 if (auth_result == AUTH_CHALLENGE_SENT) { 24541 p->lastinvite = seqno; 24542 return 0; 24543 } else if (auth_result < 0) { 24544 if (auth_result == AUTH_FAKE_AUTH) { 24545 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 24546 transmit_fake_auth_response(p, SIP_INVITE, req, XMIT_RELIABLE); 24547 } else { 24548 ast_log(LOG_NOTICE, "Failed to authenticate device %s\n", get_header(req, "From")); 24549 transmit_response_reliable(p, "403 Forbidden", req); 24550 } 24551 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 24552 ast_string_field_set(p, theirtag, NULL); 24553 return 0; 24554 } else if (auth_result == AUTH_SUCCESSFUL && p->lastinvite) { 24555 /* We need to stop retransmitting the 401 */ 24556 __sip_ack(p, p->lastinvite, 1, 0); 24557 } 24558 24559 publish_type = determine_sip_publish_type(req, event, etag, expires_str, &expires_int); 24560 24561 if (expires_int > max_expiry) { 24562 expires_int = max_expiry; 24563 } else if (expires_int < min_expiry && expires_int > 0) { 24564 transmit_response_with_minexpires(p, "423 Interval too small", req); 24565 pvt_set_needdestroy(p, "Expires is less that the min expires allowed."); 24566 return 0; 24567 } 24568 p->expiry = expires_int; 24569 24570 /* It is the responsibility of these handlers to formulate any response 24571 * sent for a PUBLISH 24572 */ 24573 switch (publish_type) { 24574 case SIP_PUBLISH_UNKNOWN: 24575 transmit_response(p, "400 Bad Request", req); 24576 break; 24577 case SIP_PUBLISH_INITIAL: 24578 handler_result = handle_sip_publish_initial(p, req, esc, expires_int); 24579 break; 24580 case SIP_PUBLISH_REFRESH: 24581 handler_result = handle_sip_publish_refresh(p, req, esc, etag, expires_int); 24582 break; 24583 case SIP_PUBLISH_MODIFY: 24584 handler_result = handle_sip_publish_modify(p, req, esc, etag, expires_int); 24585 break; 24586 case SIP_PUBLISH_REMOVE: 24587 handler_result = handle_sip_publish_remove(p, req, esc, etag); 24588 break; 24589 default: 24590 transmit_response(p, "400 Impossible Condition", req); 24591 break; 24592 } 24593 if (!handler_result && p->expiry > 0) { 24594 sip_scheddestroy(p, (p->expiry + 10) * 1000); 24595 } else { 24596 pvt_set_needdestroy(p, "forcing expiration"); 24597 } 24598 24599 return handler_result; 24600 }
| static int handle_request_refer | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | debug, | |||
| uint32_t | seqno, | |||
| int * | nounlock | |||
| ) | [static] |
Chan1: Call between asterisk and transferer Chan2: Call between asterisk and transferee
Definition at line 23474 of file chan_sip.c.
References append_history, ast_async_goto(), ast_bridged_channel(), AST_CAUSE_NORMAL_CLEARING, AST_CEL_ATTENDEDTRANSFER, AST_CEL_BLINDTRANSFER, ast_cel_report_event(), ast_channel_lock, ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_clear_flag, AST_CONTROL_UNHOLD, ast_debug, ast_indicate(), AST_LIST_EMPTY, ast_manager_event_multichan, ast_parking_ext_valid(), ast_queue_control(), ast_set_flag, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verbose, check_sip_domain(), context, EVENT_FLAG_CALL, FALSE, get_refer_info(), local_attended_transfer(), pbx_builtin_setvar_helper(), pvt_set_needdestroy(), sip_alreadygone(), sip_cfg, sip_park(), sip_pvt_lock, sip_pvt_unlock, sip_refer_allocate(), transmit_notify_with_sipfrag(), transmit_response(), and TRUE.
Referenced by handle_incoming().
23475 { 23476 /*! 23477 * Chan1: Call between asterisk and transferer 23478 * Chan2: Call between asterisk and transferee 23479 */ 23480 struct sip_dual current = { 0, }; 23481 struct ast_channel *chans[2] = { 0, }; 23482 char *refer_to = NULL; 23483 char *refer_to_domain = NULL; 23484 char *refer_to_context = NULL; 23485 char *referred_by = NULL; 23486 char *callid = NULL; 23487 int localtransfer = 0; 23488 int attendedtransfer = 0; 23489 int res = 0; 23490 23491 if (req->debug) { 23492 ast_verbose("Call %s got a SIP call transfer from %s: (REFER)!\n", 23493 p->callid, 23494 ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "callee" : "caller"); 23495 } 23496 23497 if (!p->owner) { 23498 /* This is a REFER outside of an existing SIP dialog */ 23499 /* We can't handle that, so decline it */ 23500 ast_debug(3, "Call %s: Declined REFER, outside of dialog...\n", p->callid); 23501 transmit_response(p, "603 Declined (No dialog)", req); 23502 if (!req->ignore) { 23503 append_history(p, "Xfer", "Refer failed. Outside of dialog."); 23504 sip_alreadygone(p); 23505 pvt_set_needdestroy(p, "outside of dialog"); 23506 } 23507 res = 0; 23508 goto handle_refer_cleanup; 23509 } 23510 23511 /* Check if transfer is allowed from this device */ 23512 if (p->allowtransfer == TRANSFER_CLOSED ) { 23513 /* Transfer not allowed, decline */ 23514 transmit_response(p, "603 Declined (policy)", req); 23515 append_history(p, "Xfer", "Refer failed. Allowtransfer == closed."); 23516 /* Do not destroy SIP session */ 23517 res = 0; 23518 goto handle_refer_cleanup; 23519 } 23520 23521 if (!req->ignore && ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 23522 /* Already have a pending REFER */ 23523 transmit_response(p, "491 Request pending", req); 23524 append_history(p, "Xfer", "Refer failed. Request pending."); 23525 res = 0; 23526 goto handle_refer_cleanup; 23527 } 23528 23529 /* Allocate memory for call transfer data */ 23530 if (!p->refer && !sip_refer_allocate(p)) { 23531 transmit_response(p, "500 Internal Server Error", req); 23532 append_history(p, "Xfer", "Refer failed. Memory allocation error."); 23533 res = -3; 23534 goto handle_refer_cleanup; 23535 } 23536 23537 res = get_refer_info(p, req); /* Extract headers */ 23538 23539 p->refer->status = REFER_SENT; 23540 23541 if (res != 0) { 23542 switch (res) { 23543 case -2: /* Syntax error */ 23544 transmit_response(p, "400 Bad Request (Refer-to missing)", req); 23545 append_history(p, "Xfer", "Refer failed. Refer-to missing."); 23546 if (req->debug) { 23547 ast_debug(1, "SIP transfer to black hole can't be handled (no refer-to: )\n"); 23548 } 23549 break; 23550 case -3: 23551 transmit_response(p, "603 Declined (Non sip: uri)", req); 23552 append_history(p, "Xfer", "Refer failed. Non SIP uri"); 23553 if (req->debug) { 23554 ast_debug(1, "SIP transfer to non-SIP uri denied\n"); 23555 } 23556 break; 23557 default: 23558 /* Refer-to extension not found, fake a failed transfer */ 23559 transmit_response(p, "202 Accepted", req); 23560 append_history(p, "Xfer", "Refer failed. Bad extension."); 23561 transmit_notify_with_sipfrag(p, seqno, "404 Not found", TRUE); 23562 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 23563 if (req->debug) { 23564 ast_debug(1, "SIP transfer to bad extension: %s\n", p->refer->refer_to); 23565 } 23566 break; 23567 } 23568 res = 0; 23569 goto handle_refer_cleanup; 23570 } 23571 if (ast_strlen_zero(p->context)) { 23572 ast_string_field_set(p, context, sip_cfg.default_context); 23573 } 23574 23575 /* If we do not support SIP domains, all transfers are local */ 23576 if (sip_cfg.allow_external_domains && check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 23577 p->refer->localtransfer = 1; 23578 if (sipdebug) { 23579 ast_debug(3, "This SIP transfer is local : %s\n", p->refer->refer_to_domain); 23580 } 23581 } else if (AST_LIST_EMPTY(&domain_list) || check_sip_domain(p->refer->refer_to_domain, NULL, 0)) { 23582 /* This PBX doesn't bother with SIP domains or domain is local, so this transfer is local */ 23583 p->refer->localtransfer = 1; 23584 } else if (sipdebug) { 23585 ast_debug(3, "This SIP transfer is to a remote SIP extension (remote domain %s)\n", p->refer->refer_to_domain); 23586 } 23587 23588 /* Is this a repeat of a current request? Ignore it */ 23589 /* Don't know what else to do right now. */ 23590 if (req->ignore) { 23591 goto handle_refer_cleanup; 23592 } 23593 23594 /* If this is a blind transfer, we have the following 23595 channels to work with: 23596 - chan1, chan2: The current call between transferer and transferee (2 channels) 23597 - target_channel: A new call from the transferee to the target (1 channel) 23598 We need to stay tuned to what happens in order to be able 23599 to bring back the call to the transferer */ 23600 23601 /* If this is a attended transfer, we should have all call legs within reach: 23602 - chan1, chan2: The call between the transferer and transferee (2 channels) 23603 - target_channel, targetcall_pvt: The call between the transferer and the target (2 channels) 23604 We want to bridge chan2 with targetcall_pvt! 23605 23606 The replaces call id in the refer message points 23607 to the call leg between Asterisk and the transferer. 23608 So we need to connect the target and the transferee channel 23609 and hangup the two other channels silently 23610 23611 If the target is non-local, the call ID could be on a remote 23612 machine and we need to send an INVITE with replaces to the 23613 target. We basically handle this as a blind transfer 23614 and let the sip_call function catch that we need replaces 23615 header in the INVITE. 23616 */ 23617 23618 /* Get the transferer's channel */ 23619 chans[0] = current.chan1 = p->owner; 23620 23621 /* Find the other part of the bridge (2) - transferee */ 23622 chans[1] = current.chan2 = ast_bridged_channel(current.chan1); 23623 23624 ast_channel_ref(current.chan1); 23625 if (current.chan2) { 23626 ast_channel_ref(current.chan2); 23627 } 23628 23629 if (sipdebug) { 23630 ast_debug(3, "SIP %s transfer: Transferer channel %s, transferee channel %s\n", 23631 p->refer->attendedtransfer ? "attended" : "blind", 23632 current.chan1->name, 23633 current.chan2 ? current.chan2->name : "<none>"); 23634 } 23635 23636 if (!current.chan2 && !p->refer->attendedtransfer) { 23637 /* No bridged channel, propably IVR or echo or similar... */ 23638 /* Guess we should masquerade or something here */ 23639 /* Until we figure it out, refuse transfer of such calls */ 23640 if (sipdebug) { 23641 ast_debug(3, "Refused SIP transfer on non-bridged channel.\n"); 23642 } 23643 p->refer->status = REFER_FAILED; 23644 append_history(p, "Xfer", "Refer failed. Non-bridged channel."); 23645 transmit_response(p, "603 Declined", req); 23646 res = -1; 23647 goto handle_refer_cleanup; 23648 } 23649 23650 if (current.chan2) { 23651 if (sipdebug) { 23652 ast_debug(4, "Got SIP transfer, applying to bridged peer '%s'\n", current.chan2->name); 23653 } 23654 ast_queue_control(current.chan1, AST_CONTROL_UNHOLD); 23655 } 23656 23657 ast_set_flag(&p->flags[0], SIP_GOTREFER); 23658 23659 /* From here on failures will be indicated with NOTIFY requests */ 23660 transmit_response(p, "202 Accepted", req); 23661 23662 /* Attended transfer: Find all call legs and bridge transferee with target*/ 23663 if (p->refer->attendedtransfer) { 23664 /* both p and p->owner _MUST_ be locked while calling local_attended_transfer */ 23665 if ((res = local_attended_transfer(p, ¤t, req, seqno, nounlock))) { 23666 goto handle_refer_cleanup; /* We're done with the transfer */ 23667 } 23668 /* Fall through for remote transfers that we did not find locally */ 23669 if (sipdebug) { 23670 ast_debug(4, "SIP attended transfer: Still not our call - generating INVITE with replaces\n"); 23671 } 23672 /* Fallthrough if we can't find the call leg internally */ 23673 } 23674 23675 /* Copy data we can not safely access after letting the pvt lock go. */ 23676 refer_to = ast_strdupa(p->refer->refer_to); 23677 refer_to_domain = ast_strdupa(p->refer->refer_to_domain); 23678 refer_to_context = ast_strdupa(p->refer->refer_to_context); 23679 referred_by = ast_strdupa(p->refer->referred_by); 23680 callid = ast_strdupa(p->callid); 23681 localtransfer = p->refer->localtransfer; 23682 attendedtransfer = p->refer->attendedtransfer; 23683 23684 if (!*nounlock) { 23685 ast_channel_unlock(p->owner); 23686 *nounlock = 1; 23687 } 23688 sip_pvt_unlock(p); 23689 23690 /* Parking a call. DO NOT hold any locks while calling ast_parking_ext_valid() */ 23691 if (localtransfer && ast_parking_ext_valid(refer_to, current.chan1, refer_to_context)) { 23692 sip_pvt_lock(p); 23693 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 23694 p->refer->status = REFER_200OK; 23695 append_history(p, "Xfer", "REFER to call parking."); 23696 sip_pvt_unlock(p); 23697 23698 ast_manager_event_multichan(EVENT_FLAG_CALL, "Transfer", 2, chans, 23699 "TransferMethod: SIP\r\n" 23700 "TransferType: Blind\r\n" 23701 "Channel: %s\r\n" 23702 "Uniqueid: %s\r\n" 23703 "SIP-Callid: %s\r\n" 23704 "TargetChannel: %s\r\n" 23705 "TargetUniqueid: %s\r\n" 23706 "TransferExten: %s\r\n" 23707 "Transfer2Parking: Yes\r\n", 23708 current.chan1->name, 23709 current.chan1->uniqueid, 23710 callid, 23711 current.chan2->name, 23712 current.chan2->uniqueid, 23713 refer_to); 23714 23715 if (sipdebug) { 23716 ast_debug(4, "SIP transfer to parking: trying to park %s. Parked by %s\n", current.chan2->name, current.chan1->name); 23717 } 23718 23719 /* DO NOT hold any locks while calling sip_park */ 23720 if (sip_park(current.chan2, current.chan1, req, seqno, refer_to, refer_to_context)) { 23721 sip_pvt_lock(p); 23722 transmit_notify_with_sipfrag(p, seqno, "500 Internal Server Error", TRUE); 23723 } else { 23724 sip_pvt_lock(p); 23725 } 23726 goto handle_refer_cleanup; 23727 } 23728 23729 /* Blind transfers and remote attended xfers. 23730 * Locks should not be held while calling pbx_builtin_setvar_helper. This function 23731 * locks the channel being passed into it.*/ 23732 if (current.chan1 && current.chan2) { 23733 ast_debug(3, "chan1->name: %s\n", current.chan1->name); 23734 pbx_builtin_setvar_helper(current.chan1, "BLINDTRANSFER", current.chan2->name); 23735 } 23736 23737 if (current.chan2) { 23738 pbx_builtin_setvar_helper(current.chan2, "BLINDTRANSFER", current.chan1->name); 23739 pbx_builtin_setvar_helper(current.chan2, "SIPDOMAIN", refer_to_domain); 23740 pbx_builtin_setvar_helper(current.chan2, "SIPTRANSFER", "yes"); 23741 /* One for the new channel */ 23742 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER", "yes"); 23743 /* Attended transfer to remote host, prepare headers for the INVITE */ 23744 if (!ast_strlen_zero(referred_by)) { 23745 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REFERER", referred_by); 23746 } 23747 } 23748 23749 sip_pvt_lock(p); 23750 /* Generate a Replaces string to be used in the INVITE during attended transfer */ 23751 if (!ast_strlen_zero(p->refer->replaces_callid)) { 23752 char tempheader[SIPBUFSIZE]; 23753 snprintf(tempheader, sizeof(tempheader), "%s%s%s%s%s", p->refer->replaces_callid, 23754 p->refer->replaces_callid_totag ? ";to-tag=" : "", 23755 p->refer->replaces_callid_totag, 23756 p->refer->replaces_callid_fromtag ? ";from-tag=" : "", 23757 p->refer->replaces_callid_fromtag); 23758 23759 if (current.chan2) { 23760 sip_pvt_unlock(p); 23761 pbx_builtin_setvar_helper(current.chan2, "_SIPTRANSFER_REPLACES", tempheader); 23762 sip_pvt_lock(p); 23763 } 23764 } 23765 23766 /* Connect the call */ 23767 23768 /* FAKE ringing if not attended transfer */ 23769 if (!p->refer->attendedtransfer) { 23770 transmit_notify_with_sipfrag(p, seqno, "180 Ringing", FALSE); 23771 } 23772 23773 /* For blind transfer, this will lead to a new call */ 23774 /* For attended transfer to remote host, this will lead to 23775 a new SIP call with a replaces header, if the dial plan allows it 23776 */ 23777 if (!current.chan2) { 23778 /* We have no bridge, so we're talking with Asterisk somehow */ 23779 /* We need to masquerade this call */ 23780 /* What to do to fix this situation: 23781 * Set up the new call in a new channel 23782 * Let the new channel masq into this channel 23783 Please add that code here :-) 23784 */ 23785 p->refer->status = REFER_FAILED; 23786 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable (can't handle one-legged xfers)", TRUE); 23787 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 23788 append_history(p, "Xfer", "Refer failed (only bridged calls)."); 23789 res = -1; 23790 goto handle_refer_cleanup; 23791 } 23792 ast_set_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 23793 23794 /* Do not hold the pvt lock during the indicate and async_goto. Those functions 23795 * lock channels which will invalidate locking order if the pvt lock is held.*/ 23796 /* For blind transfers, move the call to the new extensions. For attended transfers on multiple 23797 * servers - generate an INVITE with Replaces. Either way, let the dial plan decided 23798 * indicate before masquerade so the indication actually makes it to the real channel 23799 * when using local channels with MOH passthru */ 23800 sip_pvt_unlock(p); 23801 ast_indicate(current.chan2, AST_CONTROL_UNHOLD); 23802 res = ast_async_goto(current.chan2, refer_to_context, refer_to, 1); 23803 23804 if (!res) { 23805 ast_manager_event_multichan(EVENT_FLAG_CALL, "Transfer", 2, chans, 23806 "TransferMethod: SIP\r\n" 23807 "TransferType: Blind\r\n" 23808 "Channel: %s\r\n" 23809 "Uniqueid: %s\r\n" 23810 "SIP-Callid: %s\r\n" 23811 "TargetChannel: %s\r\n" 23812 "TargetUniqueid: %s\r\n" 23813 "TransferExten: %s\r\n" 23814 "TransferContext: %s\r\n", 23815 current.chan1->name, 23816 current.chan1->uniqueid, 23817 callid, 23818 current.chan2->name, 23819 current.chan2->uniqueid, 23820 refer_to, 23821 refer_to_context); 23822 /* Success - we have a new channel */ 23823 ast_debug(3, "%s transfer succeeded. Telling transferer.\n", attendedtransfer? "Attended" : "Blind"); 23824 23825 /* XXX - what to we put in CEL 'extra' for attended transfers to external systems? NULL for now */ 23826 ast_channel_lock(current.chan1); 23827 ast_cel_report_event(current.chan1, p->refer->attendedtransfer? AST_CEL_ATTENDEDTRANSFER : AST_CEL_BLINDTRANSFER, NULL, p->refer->attendedtransfer ? NULL : p->refer->refer_to, current.chan2); 23828 ast_channel_unlock(current.chan1); 23829 23830 sip_pvt_lock(p); 23831 transmit_notify_with_sipfrag(p, seqno, "200 Ok", TRUE); 23832 if (p->refer->localtransfer) { 23833 p->refer->status = REFER_200OK; 23834 } 23835 if (p->owner) { 23836 p->owner->hangupcause = AST_CAUSE_NORMAL_CLEARING; 23837 } 23838 append_history(p, "Xfer", "Refer succeeded."); 23839 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 23840 /* Do not hangup call, the other side do that when we say 200 OK */ 23841 /* We could possibly implement a timer here, auto congestion */ 23842 res = 0; 23843 } else { 23844 sip_pvt_lock(p); 23845 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Don't delay hangup */ 23846 ast_debug(3, "%s transfer failed. Resuming original call.\n", p->refer->attendedtransfer? "Attended" : "Blind"); 23847 append_history(p, "Xfer", "Refer failed."); 23848 /* Failure of some kind */ 23849 p->refer->status = REFER_FAILED; 23850 transmit_notify_with_sipfrag(p, seqno, "503 Service Unavailable", TRUE); 23851 ast_clear_flag(&p->flags[0], SIP_GOTREFER); 23852 res = -1; 23853 } 23854 23855 handle_refer_cleanup: 23856 if (current.chan1) { 23857 ast_channel_unref(current.chan1); 23858 } 23859 if (current.chan2) { 23860 ast_channel_unref(current.chan2); 23861 } 23862 23863 /* Make sure we exit with the pvt locked */ 23864 return res; 23865 }
| static int handle_request_register | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct ast_sockaddr * | sin, | |||
| const char * | e | |||
| ) | [static] |
Handle incoming REGISTER request.
Definition at line 25069 of file chan_sip.c.
References append_history, ast_debug, ast_log(), ast_sockaddr_stringify(), check_via(), copy_request(), get_header(), LOG_NOTICE, LOG_WARNING, register_verify(), sip_methods, sip_scheddestroy(), and cfsip_methods::text.
Referenced by handle_incoming().
25070 { 25071 enum check_auth_result res; 25072 25073 /* If this is not the intial request, and the initial request isn't 25074 * a register, something screwy happened, so bail */ 25075 if (p->initreq.headers && p->initreq.method != SIP_REGISTER) { 25076 ast_log(LOG_WARNING, "Ignoring spurious REGISTER with Call-ID: %s\n", p->callid); 25077 return -1; 25078 } 25079 25080 /* Use this as the basis */ 25081 copy_request(&p->initreq, req); 25082 if (sipdebug) 25083 ast_debug(4, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 25084 check_via(p, req); 25085 if ((res = register_verify(p, addr, req, e)) < 0) { 25086 const char *reason; 25087 25088 switch (res) { 25089 case AUTH_SECRET_FAILED: 25090 reason = "Wrong password"; 25091 break; 25092 case AUTH_USERNAME_MISMATCH: 25093 reason = "Username/auth name mismatch"; 25094 break; 25095 case AUTH_NOT_FOUND: 25096 reason = "No matching peer found"; 25097 break; 25098 case AUTH_UNKNOWN_DOMAIN: 25099 reason = "Not a local domain"; 25100 break; 25101 case AUTH_PEER_NOT_DYNAMIC: 25102 reason = "Peer is not supposed to register"; 25103 break; 25104 case AUTH_ACL_FAILED: 25105 reason = "Device does not match ACL"; 25106 break; 25107 case AUTH_BAD_TRANSPORT: 25108 reason = "Device not configured to use this transport type"; 25109 break; 25110 default: 25111 reason = "Unknown failure"; 25112 break; 25113 } 25114 ast_log(LOG_NOTICE, "Registration from '%s' failed for '%s' - %s\n", 25115 get_header(req, "To"), ast_sockaddr_stringify(addr), 25116 reason); 25117 append_history(p, "RegRequest", "Failed : Account %s : %s", get_header(req, "To"), reason); 25118 } else { 25119 req->authenticated = 1; 25120 append_history(p, "RegRequest", "Succeeded : Account %s", get_header(req, "To")); 25121 } 25122 25123 if (res < 1) { 25124 /* Destroy the session, but keep us around for just a bit in case they don't 25125 get our 200 OK */ 25126 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 25127 } 25128 return res; 25129 }
| static int handle_request_subscribe | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct ast_sockaddr * | addr, | |||
| uint32_t | seqno, | |||
| const char * | e | |||
| ) | [static] |
Handle incoming SUBSCRIBE request.
Definition at line 24683 of file chan_sip.c.
References __get_header(), add_peer_mwi_subs(), ao2_lock, ao2_unlock, append_history, ast_debug, ast_extension_state(), ast_extension_state2str(), ast_extension_state_add_destroy(), ast_extension_state_del(), AST_LIST_EMPTY, ast_log(), ast_set_flag, ast_sockaddr_stringify(), ast_string_field_build, ast_strlen_zero(), ast_test_flag, ast_verbose, build_contact(), build_route(), cb_extensionstate(), cb_extensionstate_destroy(), check_user_full(), check_via(), copy_request(), dialog_unlink_all(), FALSE, get_destination(), get_header(), gettag(), handle_cc_subscribe(), LOG_DEBUG, LOG_NOTICE, LOG_WARNING, make_our_tag(), MAX, NONE, option_debug, parse_ok_contact(), pvt_set_needdestroy(), ref_peer(), S_OR, set_pvt_allowed_methods(), sip_cancel_destroy(), sip_cfg, sip_methods, sip_scheddestroy(), sip_send_mwi_to_peer(), cfsip_methods::text, transmit_fake_auth_response(), transmit_response(), transmit_response_reliable(), transmit_response_with_minexpires(), transmit_state_notify(), and unref_peer().
Referenced by handle_incoming().
24684 { 24685 int gotdest = 0; 24686 int res = 0; 24687 int firststate; 24688 struct sip_peer *authpeer = NULL; 24689 const char *eventheader = get_header(req, "Event"); /* Get Event package name */ 24690 int resubscribe = (p->subscribed != NONE) && !req->ignore; 24691 char *event_end; 24692 ptrdiff_t event_len = 0; 24693 24694 if (p->initreq.headers) { 24695 /* We already have a dialog */ 24696 if (p->initreq.method != SIP_SUBSCRIBE) { 24697 /* This is a SUBSCRIBE within another SIP dialog, which we do not support */ 24698 /* For transfers, this could happen, but since we haven't seen it happening, let us just refuse this */ 24699 transmit_response(p, "403 Forbidden (within dialog)", req); 24700 /* Do not destroy session, since we will break the call if we do */ 24701 ast_debug(1, "Got a subscription within the context of another call, can't handle that - %s (Method %s)\n", p->callid, sip_methods[p->initreq.method].text); 24702 return 0; 24703 } else if (req->debug) { 24704 if (resubscribe) 24705 ast_debug(1, "Got a re-subscribe on existing subscription %s\n", p->callid); 24706 else 24707 ast_debug(1, "Got a new subscription %s (possibly with auth) or retransmission\n", p->callid); 24708 } 24709 } 24710 24711 /* Check if we have a global disallow setting on subscriptions. 24712 if so, we don't have to check peer settings after auth, which saves a lot of processing 24713 */ 24714 if (!sip_cfg.allowsubscribe) { 24715 transmit_response(p, "403 Forbidden (policy)", req); 24716 pvt_set_needdestroy(p, "forbidden"); 24717 return 0; 24718 } 24719 24720 if (!req->ignore && !resubscribe) { /* Set up dialog, new subscription */ 24721 const char *to = get_header(req, "To"); 24722 char totag[128]; 24723 set_pvt_allowed_methods(p, req); 24724 24725 /* Check to see if a tag was provided, if so this is actually a resubscription of a dialog we no longer know about */ 24726 if (!ast_strlen_zero(to) && gettag(req, "To", totag, sizeof(totag))) { 24727 if (req->debug) 24728 ast_verbose("Received resubscription for a dialog we no longer know about. Telling remote side to subscribe again.\n"); 24729 transmit_response(p, "481 Subscription does not exist", req); 24730 pvt_set_needdestroy(p, "subscription does not exist"); 24731 return 0; 24732 } 24733 24734 /* Use this as the basis */ 24735 if (req->debug) 24736 ast_verbose("Creating new subscription\n"); 24737 24738 copy_request(&p->initreq, req); 24739 if (sipdebug) 24740 ast_debug(4, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 24741 check_via(p, req); 24742 build_route(p, req, 0, 0); 24743 } else if (req->debug && req->ignore) 24744 ast_verbose("Ignoring this SUBSCRIBE request\n"); 24745 24746 /* Find parameters to Event: header value and remove them for now */ 24747 if (ast_strlen_zero(eventheader)) { 24748 transmit_response(p, "489 Bad Event", req); 24749 ast_debug(2, "Received SIP subscribe for unknown event package: <none>\n"); 24750 pvt_set_needdestroy(p, "unknown event package in subscribe"); 24751 return 0; 24752 } 24753 24754 event_end = strchr(eventheader, ';'); 24755 if (event_end) { 24756 event_len = event_end - eventheader; 24757 } 24758 24759 /* Handle authentication if we're new and not a retransmission. We can't just 24760 * use if !req->ignore, because then we'll end up sending 24761 * a 200 OK if someone retransmits without sending auth */ 24762 if (p->subscribed == NONE || resubscribe) { 24763 res = check_user_full(p, req, SIP_SUBSCRIBE, e, 0, addr, &authpeer); 24764 24765 /* if an authentication response was sent, we are done here */ 24766 if (res == AUTH_CHALLENGE_SENT) /* authpeer = NULL here */ 24767 return 0; 24768 if (res != AUTH_SUCCESSFUL) { 24769 if (res == AUTH_FAKE_AUTH) { 24770 ast_log(LOG_NOTICE, "Sending fake auth rejection for device %s\n", get_header(req, "From")); 24771 transmit_fake_auth_response(p, SIP_SUBSCRIBE, req, XMIT_UNRELIABLE); 24772 } else { 24773 ast_log(LOG_NOTICE, "Failed to authenticate device %s for SUBSCRIBE\n", get_header(req, "From")); 24774 transmit_response_reliable(p, "403 Forbidden", req); 24775 } 24776 24777 pvt_set_needdestroy(p, "authentication failed"); 24778 return 0; 24779 } 24780 } 24781 24782 /* At this point, we hold a reference to authpeer (if not NULL). It 24783 * must be released when done. 24784 */ 24785 24786 /* Check if this device is allowed to subscribe at all */ 24787 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWSUBSCRIBE)) { 24788 transmit_response(p, "403 Forbidden (policy)", req); 24789 pvt_set_needdestroy(p, "subscription not allowed"); 24790 if (authpeer) { 24791 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 1)"); 24792 } 24793 return 0; 24794 } 24795 24796 if (strncmp(eventheader, "message-summary", MAX(event_len, 15)) && strncmp(eventheader, "call-completion", MAX(event_len, 15))) { 24797 /* Get destination right away */ 24798 gotdest = get_destination(p, NULL, NULL); 24799 } 24800 24801 /* Get full contact header - this needs to be used as a request URI in NOTIFY's */ 24802 parse_ok_contact(p, req); 24803 24804 build_contact(p); 24805 if (gotdest != SIP_GET_DEST_EXTEN_FOUND) { 24806 if (gotdest == SIP_GET_DEST_INVALID_URI) { 24807 transmit_response(p, "416 Unsupported URI scheme", req); 24808 } else { 24809 transmit_response(p, "404 Not Found", req); 24810 } 24811 pvt_set_needdestroy(p, "subscription target not found"); 24812 if (authpeer) { 24813 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 2)"); 24814 } 24815 return 0; 24816 } 24817 24818 /* Initialize tag for new subscriptions */ 24819 if (ast_strlen_zero(p->tag)) 24820 make_our_tag(p); 24821 24822 if (!strncmp(eventheader, "presence", MAX(event_len, 8)) || !strncmp(eventheader, "dialog", MAX(event_len, 6))) { /* Presence, RFC 3842 */ 24823 unsigned int pidf_xml; 24824 const char *accept; 24825 int start = 0; 24826 enum subscriptiontype subscribed = NONE; 24827 const char *unknown_acceptheader = NULL; 24828 24829 /* Header from Xten Eye-beam Accept: multipart/related, application/rlmi+xml, application/pidf+xml, application/xpidf+xml */ 24830 accept = __get_header(req, "Accept", &start); 24831 while ((subscribed == NONE) && !ast_strlen_zero(accept)) { 24832 pidf_xml = strstr(accept, "application/pidf+xml") ? 1 : 0; 24833 24834 /* Older versions of Polycom firmware will claim pidf+xml, but really 24835 * they only support xpidf+xml. */ 24836 if (pidf_xml && strstr(p->useragent, "Polycom")) { 24837 subscribed = XPIDF_XML; 24838 } else if (pidf_xml) { 24839 subscribed = PIDF_XML; /* RFC 3863 format */ 24840 } else if (strstr(accept, "application/dialog-info+xml")) { 24841 subscribed = DIALOG_INFO_XML; 24842 /* IETF draft: draft-ietf-sipping-dialog-package-05.txt */ 24843 } else if (strstr(accept, "application/cpim-pidf+xml")) { 24844 subscribed = CPIM_PIDF_XML; /* RFC 3863 format */ 24845 } else if (strstr(accept, "application/xpidf+xml")) { 24846 subscribed = XPIDF_XML; /* Early pre-RFC 3863 format with MSN additions (Microsoft Messenger) */ 24847 } else { 24848 unknown_acceptheader = accept; 24849 } 24850 /* check to see if there is another Accept header present */ 24851 accept = __get_header(req, "Accept", &start); 24852 } 24853 24854 if (!start) { 24855 if (p->subscribed == NONE) { /* if the subscribed field is not already set, and there is no accept header... */ 24856 transmit_response(p, "489 Bad Event", req); 24857 ast_log(LOG_WARNING,"SUBSCRIBE failure: no Accept header: pvt: " 24858 "stateid: %d, laststate: %d, dialogver: %u, subscribecont: " 24859 "'%s', subscribeuri: '%s'\n", 24860 p->stateid, 24861 p->laststate, 24862 p->dialogver, 24863 p->subscribecontext, 24864 p->subscribeuri); 24865 pvt_set_needdestroy(p, "no Accept header"); 24866 if (authpeer) { 24867 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 2)"); 24868 } 24869 return 0; 24870 } 24871 /* if p->subscribed is non-zero, then accept is not obligatory; according to rfc 3265 section 3.1.3, at least. 24872 so, we'll just let it ride, keeping the value from a previous subscription, and not abort the subscription */ 24873 } else if (subscribed == NONE) { 24874 /* Can't find a format for events that we know about */ 24875 char mybuf[200]; 24876 if (!ast_strlen_zero(unknown_acceptheader)) { 24877 snprintf(mybuf, sizeof(mybuf), "489 Bad Event (format %s)", unknown_acceptheader); 24878 } else { 24879 snprintf(mybuf, sizeof(mybuf), "489 Bad Event"); 24880 } 24881 transmit_response(p, mybuf, req); 24882 ast_log(LOG_WARNING,"SUBSCRIBE failure: unrecognized format:" 24883 "'%s' pvt: subscribed: %d, stateid: %d, laststate: %d," 24884 "dialogver: %u, subscribecont: '%s', subscribeuri: '%s'\n", 24885 unknown_acceptheader, 24886 (int)p->subscribed, 24887 p->stateid, 24888 p->laststate, 24889 p->dialogver, 24890 p->subscribecontext, 24891 p->subscribeuri); 24892 pvt_set_needdestroy(p, "unrecognized format"); 24893 if (authpeer) { 24894 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 2)"); 24895 } 24896 return 0; 24897 } else { 24898 p->subscribed = subscribed; 24899 } 24900 } else if (!strncmp(eventheader, "message-summary", MAX(event_len, 15))) { 24901 int start = 0; 24902 int found_supported = 0; 24903 const char *acceptheader; 24904 24905 acceptheader = __get_header(req, "Accept", &start); 24906 while (!found_supported && !ast_strlen_zero(acceptheader)) { 24907 found_supported = strcmp(acceptheader, "application/simple-message-summary") ? 0 : 1; 24908 if (!found_supported && (option_debug > 2)) { 24909 ast_log(LOG_DEBUG, "Received SIP mailbox subscription for unknown format: %s\n", acceptheader); 24910 } 24911 acceptheader = __get_header(req, "Accept", &start); 24912 } 24913 if (start && !found_supported) { 24914 /* Format requested that we do not support */ 24915 transmit_response(p, "406 Not Acceptable", req); 24916 ast_debug(2, "Received SIP mailbox subscription for unknown format: %s\n", acceptheader); 24917 pvt_set_needdestroy(p, "unknown format"); 24918 if (authpeer) { 24919 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 3)"); 24920 } 24921 return 0; 24922 } 24923 /* Looks like they actually want a mailbox status 24924 This version of Asterisk supports mailbox subscriptions 24925 The subscribed URI needs to exist in the dial plan 24926 In most devices, this is configurable to the voicemailmain extension you use 24927 */ 24928 if (!authpeer || AST_LIST_EMPTY(&authpeer->mailboxes)) { 24929 if (!authpeer) { 24930 transmit_response(p, "404 Not found", req); 24931 } else { 24932 transmit_response(p, "404 Not found (no mailbox)", req); 24933 ast_log(LOG_NOTICE, "Received SIP subscribe for peer without mailbox: %s\n", S_OR(authpeer->name, "")); 24934 } 24935 pvt_set_needdestroy(p, "received 404 response"); 24936 if (authpeer) { 24937 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 3)"); 24938 } 24939 return 0; 24940 } 24941 24942 p->subscribed = MWI_NOTIFICATION; 24943 if (ast_test_flag(&authpeer->flags[1], SIP_PAGE2_SUBSCRIBEMWIONLY)) { 24944 ao2_unlock(p); 24945 add_peer_mwi_subs(authpeer); 24946 ao2_lock(p); 24947 } 24948 if (authpeer->mwipvt != p) { /* Destroy old PVT if this is a new one */ 24949 /* We only allow one subscription per peer */ 24950 if (authpeer->mwipvt) { 24951 dialog_unlink_all(authpeer->mwipvt); 24952 authpeer->mwipvt = dialog_unref(authpeer->mwipvt, "unref dialog authpeer->mwipvt"); 24953 } 24954 authpeer->mwipvt = dialog_ref(p, "setting peers' mwipvt to p"); 24955 } 24956 if (p->relatedpeer != authpeer) { 24957 if (p->relatedpeer) { 24958 unref_peer(p->relatedpeer, "Unref previously stored relatedpeer ptr"); 24959 } 24960 p->relatedpeer = ref_peer(authpeer, "setting dialog's relatedpeer pointer"); 24961 } 24962 /* Do not release authpeer here */ 24963 } else if (!strncmp(eventheader, "call-completion", MAX(event_len, 15))) { 24964 handle_cc_subscribe(p, req); 24965 } else { /* At this point, Asterisk does not understand the specified event */ 24966 transmit_response(p, "489 Bad Event", req); 24967 ast_debug(2, "Received SIP subscribe for unknown event package: %s\n", eventheader); 24968 pvt_set_needdestroy(p, "unknown event package"); 24969 if (authpeer) { 24970 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 5)"); 24971 } 24972 return 0; 24973 } 24974 24975 /* Add subscription for extension state from the PBX core */ 24976 if (p->subscribed != MWI_NOTIFICATION && p->subscribed != CALL_COMPLETION && !resubscribe) { 24977 if (p->stateid != -1) { 24978 ast_extension_state_del(p->stateid, cb_extensionstate); 24979 } 24980 dialog_ref(p, "copying dialog ptr into extension state struct"); 24981 p->stateid = ast_extension_state_add_destroy(p->context, p->exten, 24982 cb_extensionstate, cb_extensionstate_destroy, p); 24983 if (p->stateid == -1) { 24984 dialog_unref(p, "copying dialog ptr into extension state struct failed"); 24985 } 24986 } 24987 24988 if (!req->ignore) { 24989 p->lastinvite = seqno; 24990 } 24991 if (!p->needdestroy) { 24992 p->expiry = atoi(get_header(req, "Expires")); 24993 24994 /* check if the requested expiry-time is within the approved limits from sip.conf */ 24995 if (p->expiry > max_expiry) { 24996 p->expiry = max_expiry; 24997 } else if (p->expiry < min_expiry && p->expiry > 0) { 24998 transmit_response_with_minexpires(p, "423 Interval too small", req); 24999 ast_log(LOG_WARNING, "Received subscription for extension \"%s\" context \"%s\" " 25000 "with Expire header less that 'minexpire' limit. Received \"Expire: %d\" min is %d\n", 25001 p->exten, p->context, p->expiry, min_expiry); 25002 pvt_set_needdestroy(p, "Expires is less that the min expires allowed."); 25003 if (authpeer) { 25004 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 6)"); 25005 } 25006 return 0; 25007 } 25008 25009 if (sipdebug) { 25010 const char *action = p->expiry > 0 ? "Adding" : "Removing"; 25011 if (p->subscribed == MWI_NOTIFICATION && p->relatedpeer) { 25012 ast_debug(2, "%s subscription for mailbox notification - peer %s\n", 25013 action, p->relatedpeer->name); 25014 } else if (p->subscribed == CALL_COMPLETION) { 25015 ast_debug(2, "%s CC subscription for peer %s\n", action, p->username); 25016 } else { 25017 ast_debug(2, "%s subscription for extension %s context %s for peer %s\n", 25018 action, p->exten, p->context, p->username); 25019 } 25020 } 25021 if (p->autokillid > -1 && sip_cancel_destroy(p)) /* Remove subscription expiry for renewals */ 25022 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 25023 if (p->expiry > 0) 25024 sip_scheddestroy(p, (p->expiry + 10) * 1000); /* Set timer for destruction of call at expiration */ 25025 25026 if (p->subscribed == MWI_NOTIFICATION) { 25027 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 25028 transmit_response(p, "200 OK", req); 25029 if (p->relatedpeer) { /* Send first notification */ 25030 struct sip_peer *peer = p->relatedpeer; 25031 ref_peer(peer, "ensure a peer ref is held during MWI sending"); 25032 ao2_unlock(p); 25033 sip_send_mwi_to_peer(peer, 0); 25034 ao2_lock(p); 25035 unref_peer(peer, "release a peer ref now that MWI is sent"); 25036 } 25037 } else if (p->subscribed != CALL_COMPLETION) { 25038 if ((firststate = ast_extension_state(NULL, p->context, p->exten)) < 0) { 25039 25040 ast_log(LOG_NOTICE, "Got SUBSCRIBE for extension %s@%s from %s, but there is no hint for that extension.\n", p->exten, p->context, ast_sockaddr_stringify(&p->sa)); 25041 transmit_response(p, "404 Not found", req); 25042 pvt_set_needdestroy(p, "no extension for SUBSCRIBE"); 25043 if (authpeer) { 25044 unref_peer(authpeer, "unref_peer, from handle_request_subscribe (authpeer 6)"); 25045 } 25046 return 0; 25047 } 25048 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 25049 transmit_response(p, "200 OK", req); 25050 transmit_state_notify(p, firststate, 1, FALSE); /* Send first notification */ 25051 append_history(p, "Subscribestatus", "%s", ast_extension_state2str(firststate)); 25052 /* hide the 'complete' exten/context in the refer_to field for later display */ 25053 ast_string_field_build(p, subscribeuri, "%s@%s", p->exten, p->context); 25054 /* Deleted the slow iteration of all sip dialogs to find old subscribes from this peer for exten@context */ 25055 25056 } 25057 if (!p->expiry) { 25058 pvt_set_needdestroy(p, "forcing expiration"); 25059 } 25060 } 25061 25062 if (authpeer) { 25063 unref_peer(authpeer, "unref pointer into (*authpeer)"); 25064 } 25065 return 1; 25066 }
| static int handle_request_update | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
bare-bones support for SIP UPDATE
XXX This is not even close to being RFC 3311-compliant. We don't advertise that we support the UPDATE method, so no one should ever try sending us an UPDATE anyway. However, Asterisk can send an UPDATE to change connected line information, so we need to be prepared to handle this. The way we distinguish such an UPDATE is through the X-Asterisk-rpid-update header.
Actually updating the media session may be some future work.
Definition at line 22292 of file chan_sip.c.
References ast_channel_queue_connected_line_update(), AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER, ast_party_connected_line_init(), ast_strlen_zero(), connected, get_header(), get_rpid(), ast_party_connected_line::id, ast_set_party_connected_line::id, ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, ast_party_name::presentation, ast_party_number::presentation, ast_party_connected_line::source, ast_party_name::str, ast_party_number::str, ast_party_id::tag, transmit_response(), ast_party_name::valid, and ast_party_number::valid.
Referenced by handle_incoming().
22293 { 22294 if (ast_strlen_zero(get_header(req, "X-Asterisk-rpid-update"))) { 22295 transmit_response(p, "501 Method Not Implemented", req); 22296 return 0; 22297 } 22298 if (!p->owner) { 22299 transmit_response(p, "481 Call/Transaction Does Not Exist", req); 22300 return 0; 22301 } 22302 if (get_rpid(p, req)) { 22303 struct ast_party_connected_line connected; 22304 struct ast_set_party_connected_line update_connected; 22305 22306 ast_party_connected_line_init(&connected); 22307 memset(&update_connected, 0, sizeof(update_connected)); 22308 22309 update_connected.id.number = 1; 22310 connected.id.number.valid = 1; 22311 connected.id.number.str = (char *) p->cid_num; 22312 connected.id.number.presentation = p->callingpres; 22313 22314 update_connected.id.name = 1; 22315 connected.id.name.valid = 1; 22316 connected.id.name.str = (char *) p->cid_name; 22317 connected.id.name.presentation = p->callingpres; 22318 22319 connected.id.tag = (char *) p->cid_tag; 22320 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER; 22321 ast_channel_queue_connected_line_update(p->owner, &connected, &update_connected); 22322 } 22323 transmit_response(p, "200 OK", req); 22324 return 0; 22325 }
| static void handle_response | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Handle SIP response in dialogue.
Definition at line 21072 of file chan_sip.c.
References __sip_ack(), __sip_semi_ack(), append_history, AST_CC_CCBS, ast_channel_set_redirecting(), ast_clear_flag, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, ast_debug, ast_log(), ast_party_redirecting_free(), ast_party_redirecting_init(), ast_queue_control(), ast_queue_hangup_with_cause(), ast_set_flag, ast_skip_blanks(), ast_skip_nonblanks(), ast_sockaddr_stringify(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, ast_verbose, change_redirecting_information(), do_proxy_auth(), FALSE, find_sdp(), find_sip_method(), get_header(), gettag(), handle_response_info(), handle_response_invite(), handle_response_message(), handle_response_notify(), handle_response_peerpoke(), handle_response_publish(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), handle_response_update(), hangup_sip2cause(), ast_channel::hangupcause, LOG_NOTICE, LOG_WARNING, mark_method_allowed(), mark_method_unallowed(), process_sdp(), pvt_set_needdestroy(), rh, sip_alreadygone(), sip_cancel_destroy(), sip_handle_cc(), sip_methods, stop_media_flows(), text, transmit_request(), TRUE, and update_redirecting().
Referenced by handle_incoming().
21073 { 21074 struct ast_channel *owner; 21075 int sipmethod; 21076 const char *c = get_header(req, "Cseq"); 21077 /* GCC 4.2 complains if I try to cast c as a char * when passing it to ast_skip_nonblanks, so make a copy of it */ 21078 char *c_copy = ast_strdupa(c); 21079 /* Skip the Cseq and its subsequent spaces */ 21080 const char *msg = ast_skip_blanks(ast_skip_nonblanks(c_copy)); 21081 21082 if (!msg) 21083 msg = ""; 21084 21085 sipmethod = find_sip_method(msg); 21086 21087 owner = p->owner; 21088 if (owner) { 21089 const char *rp = NULL, *rh = NULL; 21090 21091 owner->hangupcause = 0; 21092 if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && (rh = get_header(req, "Reason"))) { 21093 rh = ast_skip_blanks(rh); 21094 if (!strncasecmp(rh, "Q.850", 5)) { 21095 rp = strstr(rh, "cause="); 21096 if (rp && sscanf(rp + 6, "%30d", &owner->hangupcause) == 1) { 21097 owner->hangupcause &= 0x7f; 21098 if (req->debug) 21099 ast_verbose("Using Reason header for cause code: %d\n", owner->hangupcause); 21100 } 21101 } 21102 } 21103 21104 if (!owner->hangupcause) 21105 owner->hangupcause = hangup_sip2cause(resp); 21106 } 21107 21108 if (p->socket.type == SIP_TRANSPORT_UDP) { 21109 int ack_res = FALSE; 21110 21111 /* Acknowledge whatever it is destined for */ 21112 if ((resp >= 100) && (resp <= 199)) { 21113 /* NON-INVITE messages do not ack a 1XX response. RFC 3261 section 17.1.2.2 */ 21114 if (sipmethod == SIP_INVITE) { 21115 ack_res = __sip_semi_ack(p, seqno, 0, sipmethod); 21116 } 21117 } else { 21118 ack_res = __sip_ack(p, seqno, 0, sipmethod); 21119 } 21120 21121 if (ack_res == FALSE) { 21122 /* RFC 3261 13.2.2.4 and 17.1.1.2 - We must re-send ACKs to re-transmitted final responses */ 21123 if (sipmethod == SIP_INVITE && resp >= 200) { 21124 transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, resp < 300 ? TRUE: FALSE); 21125 } 21126 21127 append_history(p, "Ignore", "Ignoring this retransmit\n"); 21128 return; 21129 } 21130 } 21131 21132 /* If this is a NOTIFY for a subscription clear the flag that indicates that we have a NOTIFY pending */ 21133 if (!p->owner && sipmethod == SIP_NOTIFY && p->pendinginvite) { 21134 p->pendinginvite = 0; 21135 } 21136 21137 /* Get their tag if we haven't already */ 21138 if (ast_strlen_zero(p->theirtag) || (resp >= 200)) { 21139 char tag[128]; 21140 21141 gettag(req, "To", tag, sizeof(tag)); 21142 ast_string_field_set(p, theirtag, tag); 21143 } 21144 /* This needs to be configurable on a channel/peer level, 21145 not mandatory for all communication. Sadly enough, NAT implementations 21146 are not so stable so we can always rely on these headers. 21147 Temporarily disabled, while waiting for fix. 21148 Fix assigned to Rizzo :-) 21149 */ 21150 /* check_via_response(p, req); */ 21151 21152 /* RFC 3261 Section 15 specifies that if we receive a 408 or 481 21153 * in response to a BYE, then we should end the current dialog 21154 * and session. It is known that at least one phone manufacturer 21155 * potentially will send a 404 in response to a BYE, so we'll be 21156 * liberal in what we accept and end the dialog and session if we 21157 * receive any of those responses to a BYE. 21158 */ 21159 if ((resp == 404 || resp == 408 || resp == 481) && sipmethod == SIP_BYE) { 21160 pvt_set_needdestroy(p, "received 4XX response to a BYE"); 21161 return; 21162 } 21163 21164 if (p->relatedpeer && sipmethod == SIP_OPTIONS) { 21165 /* We don't really care what the response is, just that it replied back. 21166 Well, as long as it's not a 100 response... since we might 21167 need to hang around for something more "definitive" */ 21168 if (resp != 100) 21169 handle_response_peerpoke(p, resp, req); 21170 } else if (sipmethod == SIP_REFER && resp >= 200) { 21171 handle_response_refer(p, resp, rest, req, seqno); 21172 } else if (sipmethod == SIP_PUBLISH) { 21173 /* SIP PUBLISH transcends this morass of doodoo and instead 21174 * we just always call the response handler. Good gravy! 21175 */ 21176 handle_response_publish(p, resp, rest, req, seqno); 21177 } else if (sipmethod == SIP_INFO) { 21178 /* More good gravy! */ 21179 handle_response_info(p, resp, rest, req, seqno); 21180 } else if (sipmethod == SIP_MESSAGE) { 21181 /* More good gravy! */ 21182 handle_response_message(p, resp, rest, req, seqno); 21183 } else if (sipmethod == SIP_NOTIFY) { 21184 /* The gravy train continues to roll */ 21185 handle_response_notify(p, resp, rest, req, seqno); 21186 } else if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 21187 switch(resp) { 21188 case 100: /* 100 Trying */ 21189 case 101: /* 101 Dialog establishment */ 21190 case 183: /* 183 Session Progress */ 21191 case 180: /* 180 Ringing */ 21192 case 182: /* 182 Queued */ 21193 case 181: /* 181 Call Is Being Forwarded */ 21194 if (sipmethod == SIP_INVITE) 21195 handle_response_invite(p, resp, rest, req, seqno); 21196 break; 21197 case 200: /* 200 OK */ 21198 p->authtries = 0; /* Reset authentication counter */ 21199 if (sipmethod == SIP_INVITE) { 21200 handle_response_invite(p, resp, rest, req, seqno); 21201 } else if (sipmethod == SIP_REGISTER) { 21202 handle_response_register(p, resp, rest, req, seqno); 21203 } else if (sipmethod == SIP_SUBSCRIBE) { 21204 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21205 handle_response_subscribe(p, resp, rest, req, seqno); 21206 } else if (sipmethod == SIP_BYE) { /* Ok, we're ready to go */ 21207 pvt_set_needdestroy(p, "received 200 response"); 21208 ast_clear_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21209 } 21210 break; 21211 case 401: /* Not www-authorized on SIP method */ 21212 case 407: /* Proxy auth required */ 21213 if (sipmethod == SIP_INVITE) 21214 handle_response_invite(p, resp, rest, req, seqno); 21215 else if (sipmethod == SIP_SUBSCRIBE) 21216 handle_response_subscribe(p, resp, rest, req, seqno); 21217 else if (p->registry && sipmethod == SIP_REGISTER) 21218 handle_response_register(p, resp, rest, req, seqno); 21219 else if (sipmethod == SIP_UPDATE) { 21220 handle_response_update(p, resp, rest, req, seqno); 21221 } else if (sipmethod == SIP_BYE) { 21222 if (p->options) 21223 p->options->auth_type = resp; 21224 if (ast_strlen_zero(p->authname)) { 21225 ast_log(LOG_WARNING, "Asked to authenticate %s, to %s but we have no matching peer!\n", 21226 msg, ast_sockaddr_stringify(&p->recv)); 21227 pvt_set_needdestroy(p, "unable to authenticate BYE"); 21228 } else if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, sipmethod, 0)) { 21229 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 21230 pvt_set_needdestroy(p, "failed to authenticate BYE"); 21231 } 21232 } else { 21233 ast_log(LOG_WARNING, "Got authentication request (%d) on %s to '%s'\n", resp, sip_methods[sipmethod].text, get_header(req, "To")); 21234 pvt_set_needdestroy(p, "received 407 response"); 21235 } 21236 break; 21237 case 403: /* Forbidden - we failed authentication */ 21238 if (sipmethod == SIP_INVITE) 21239 handle_response_invite(p, resp, rest, req, seqno); 21240 else if (sipmethod == SIP_SUBSCRIBE) 21241 handle_response_subscribe(p, resp, rest, req, seqno); 21242 else if (p->registry && sipmethod == SIP_REGISTER) 21243 handle_response_register(p, resp, rest, req, seqno); 21244 else { 21245 ast_log(LOG_WARNING, "Forbidden - maybe wrong password on authentication for %s\n", msg); 21246 pvt_set_needdestroy(p, "received 403 response"); 21247 } 21248 break; 21249 case 404: /* Not found */ 21250 if (p->registry && sipmethod == SIP_REGISTER) 21251 handle_response_register(p, resp, rest, req, seqno); 21252 else if (sipmethod == SIP_INVITE) 21253 handle_response_invite(p, resp, rest, req, seqno); 21254 else if (sipmethod == SIP_SUBSCRIBE) 21255 handle_response_subscribe(p, resp, rest, req, seqno); 21256 else if (owner) 21257 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 21258 break; 21259 case 423: /* Interval too brief */ 21260 if (sipmethod == SIP_REGISTER) 21261 handle_response_register(p, resp, rest, req, seqno); 21262 break; 21263 case 408: /* Request timeout - terminate dialog */ 21264 if (sipmethod == SIP_INVITE) 21265 handle_response_invite(p, resp, rest, req, seqno); 21266 else if (sipmethod == SIP_REGISTER) 21267 handle_response_register(p, resp, rest, req, seqno); 21268 else if (sipmethod == SIP_BYE) { 21269 pvt_set_needdestroy(p, "received 408 response"); 21270 ast_debug(4, "Got timeout on bye. Thanks for the answer. Now, kill this call\n"); 21271 } else { 21272 if (owner) 21273 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 21274 pvt_set_needdestroy(p, "received 408 response"); 21275 } 21276 break; 21277 21278 case 428: 21279 case 422: /* Session-Timers: Session Interval Too Small */ 21280 if (sipmethod == SIP_INVITE) { 21281 handle_response_invite(p, resp, rest, req, seqno); 21282 } 21283 break; 21284 21285 case 481: /* Call leg does not exist */ 21286 if (sipmethod == SIP_INVITE) { 21287 handle_response_invite(p, resp, rest, req, seqno); 21288 } else if (sipmethod == SIP_SUBSCRIBE) { 21289 handle_response_subscribe(p, resp, rest, req, seqno); 21290 } else if (sipmethod == SIP_BYE) { 21291 /* The other side has no transaction to bye, 21292 just assume it's all right then */ 21293 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 21294 } else if (sipmethod == SIP_CANCEL) { 21295 /* The other side has no transaction to cancel, 21296 just assume it's all right then */ 21297 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 21298 } else { 21299 ast_log(LOG_WARNING, "Remote host can't match request %s to call '%s'. Giving up.\n", sip_methods[sipmethod].text, p->callid); 21300 /* Guessing that this is not an important request */ 21301 } 21302 break; 21303 case 487: 21304 if (sipmethod == SIP_INVITE) 21305 handle_response_invite(p, resp, rest, req, seqno); 21306 break; 21307 case 415: /* Unsupported media type */ 21308 case 488: /* Not acceptable here - codec error */ 21309 case 606: /* Not Acceptable */ 21310 if (sipmethod == SIP_INVITE) 21311 handle_response_invite(p, resp, rest, req, seqno); 21312 break; 21313 case 491: /* Pending */ 21314 if (sipmethod == SIP_INVITE) 21315 handle_response_invite(p, resp, rest, req, seqno); 21316 else { 21317 ast_debug(1, "Got 491 on %s, unsupported. Call ID %s\n", sip_methods[sipmethod].text, p->callid); 21318 pvt_set_needdestroy(p, "received 491 response"); 21319 } 21320 break; 21321 case 405: /* Method not allowed */ 21322 case 501: /* Not Implemented */ 21323 mark_method_unallowed(&p->allowed_methods, sipmethod); 21324 if (p->relatedpeer) { 21325 mark_method_allowed(&p->relatedpeer->disallowed_methods, sipmethod); 21326 } 21327 if (sipmethod == SIP_INVITE) 21328 handle_response_invite(p, resp, rest, req, seqno); 21329 else 21330 ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", ast_sockaddr_stringify(&p->sa), msg); 21331 break; 21332 default: 21333 if ((resp >= 300) && (resp < 700)) { 21334 /* Fatal response */ 21335 if ((resp != 487)) 21336 ast_verb(3, "Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_sockaddr_stringify(&p->sa)); 21337 21338 if (sipmethod == SIP_INVITE) 21339 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 21340 21341 /* XXX Locking issues?? XXX */ 21342 switch(resp) { 21343 case 300: /* Multiple Choices */ 21344 case 301: /* Moved permanently */ 21345 case 302: /* Moved temporarily */ 21346 case 305: /* Use Proxy */ 21347 if (p->owner) { 21348 struct ast_party_redirecting redirecting; 21349 struct ast_set_party_redirecting update_redirecting; 21350 21351 ast_party_redirecting_init(&redirecting); 21352 memset(&update_redirecting, 0, sizeof(update_redirecting)); 21353 change_redirecting_information(p, req, &redirecting, 21354 &update_redirecting, TRUE); 21355 ast_channel_set_redirecting(p->owner, &redirecting, 21356 &update_redirecting); 21357 ast_party_redirecting_free(&redirecting); 21358 } 21359 /* Fall through */ 21360 case 486: /* Busy here */ 21361 case 600: /* Busy everywhere */ 21362 case 603: /* Decline */ 21363 if (p->owner) { 21364 sip_handle_cc(p, req, AST_CC_CCBS); 21365 ast_queue_control(p->owner, AST_CONTROL_BUSY); 21366 } 21367 break; 21368 case 482: /* Loop Detected */ 21369 case 480: /* Temporarily Unavailable */ 21370 case 404: /* Not Found */ 21371 case 410: /* Gone */ 21372 case 400: /* Bad Request */ 21373 case 500: /* Server error */ 21374 if (sipmethod == SIP_SUBSCRIBE) { 21375 handle_response_subscribe(p, resp, rest, req, seqno); 21376 break; 21377 } 21378 /* Fall through */ 21379 case 502: /* Bad gateway */ 21380 case 503: /* Service Unavailable */ 21381 case 504: /* Server Timeout */ 21382 if (owner) 21383 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 21384 break; 21385 case 484: /* Address Incomplete */ 21386 if (owner && sipmethod != SIP_BYE) { 21387 switch (ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP)) { 21388 case SIP_PAGE2_ALLOWOVERLAP_YES: 21389 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 21390 break; 21391 default: 21392 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(404)); 21393 break; 21394 } 21395 } 21396 break; 21397 default: 21398 /* Send hangup */ 21399 if (owner && sipmethod != SIP_BYE) 21400 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 21401 break; 21402 } 21403 /* ACK on invite */ 21404 if (sipmethod == SIP_INVITE) 21405 transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 21406 sip_alreadygone(p); 21407 if (!p->owner) { 21408 pvt_set_needdestroy(p, "transaction completed"); 21409 } 21410 } else if ((resp >= 100) && (resp < 200)) { 21411 if (sipmethod == SIP_INVITE) { 21412 if (!req->ignore && sip_cancel_destroy(p)) 21413 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 21414 if (find_sdp(req)) 21415 process_sdp(p, req, SDP_T38_NONE); 21416 if (p->owner) { 21417 /* Queue a progress frame */ 21418 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 21419 } 21420 } 21421 } else 21422 ast_log(LOG_NOTICE, "Don't know how to handle a %d %s response from %s\n", resp, rest, p->owner ? p->owner->name : ast_sockaddr_stringify(&p->sa)); 21423 } 21424 } else { 21425 /* Responses to OUTGOING SIP requests on INCOMING calls 21426 get handled here. As well as out-of-call message responses */ 21427 if (req->debug) 21428 ast_verbose("SIP Response message for INCOMING dialog %s arrived\n", msg); 21429 21430 if (sipmethod == SIP_INVITE && resp == 200) { 21431 /* Tags in early session is replaced by the tag in 200 OK, which is 21432 the final reply to our INVITE */ 21433 char tag[128]; 21434 21435 gettag(req, "To", tag, sizeof(tag)); 21436 ast_string_field_set(p, theirtag, tag); 21437 } 21438 21439 switch(resp) { 21440 case 200: 21441 if (sipmethod == SIP_INVITE) { 21442 handle_response_invite(p, resp, rest, req, seqno); 21443 } else if (sipmethod == SIP_CANCEL) { 21444 ast_debug(1, "Got 200 OK on CANCEL\n"); 21445 21446 /* Wait for 487, then destroy */ 21447 } else if (sipmethod == SIP_BYE) { 21448 pvt_set_needdestroy(p, "transaction completed"); 21449 } 21450 break; 21451 case 401: /* www-auth */ 21452 case 407: 21453 if (sipmethod == SIP_INVITE) 21454 handle_response_invite(p, resp, rest, req, seqno); 21455 else if (sipmethod == SIP_BYE) { 21456 if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, sipmethod, 0)) { 21457 ast_log(LOG_NOTICE, "Failed to authenticate on %s to '%s'\n", msg, get_header(&p->initreq, "From")); 21458 pvt_set_needdestroy(p, "failed to authenticate BYE"); 21459 } 21460 } 21461 break; 21462 case 481: /* Call leg does not exist */ 21463 if (sipmethod == SIP_INVITE) { 21464 /* Re-invite failed */ 21465 handle_response_invite(p, resp, rest, req, seqno); 21466 } else if (sipmethod == SIP_BYE) { 21467 pvt_set_needdestroy(p, "received 481 response"); 21468 } else if (sipdebug) { 21469 ast_debug(1, "Remote host can't match request %s to call '%s'. Giving up\n", sip_methods[sipmethod].text, p->callid); 21470 } 21471 break; 21472 case 501: /* Not Implemented */ 21473 if (sipmethod == SIP_INVITE) 21474 handle_response_invite(p, resp, rest, req, seqno); 21475 break; 21476 default: /* Errors without handlers */ 21477 if ((resp >= 100) && (resp < 200)) { 21478 if (sipmethod == SIP_INVITE) { /* re-invite */ 21479 if (!req->ignore && sip_cancel_destroy(p)) 21480 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 21481 } 21482 } 21483 if ((resp >= 300) && (resp < 700)) { 21484 if ((resp != 487)) 21485 ast_verb(3, "Incoming call: Got SIP response %d \"%s\" back from %s\n", resp, rest, ast_sockaddr_stringify(&p->sa)); 21486 switch(resp) { 21487 case 415: /* Unsupported media type */ 21488 case 488: /* Not acceptable here - codec error */ 21489 case 603: /* Decline */ 21490 case 500: /* Server error */ 21491 case 502: /* Bad gateway */ 21492 case 503: /* Service Unavailable */ 21493 case 504: /* Server timeout */ 21494 21495 /* re-invite failed */ 21496 if (sipmethod == SIP_INVITE && sip_cancel_destroy(p)) 21497 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 21498 break; 21499 } 21500 } 21501 break; 21502 } 21503 } 21504 }
| static void handle_response_info | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 20986 of file chan_sip.c.
References ast_log(), ast_sockaddr_stringify(), ast_verb, LOG_WARNING, mark_method_allowed(), mark_method_unallowed(), sip_methods, text, and cfsip_methods::text.
Referenced by handle_response().
20987 { 20988 int sipmethod = SIP_INFO; 20989 20990 switch (resp) { 20991 case 401: /* Not www-authorized on SIP method */ 20992 case 407: /* Proxy auth required */ 20993 ast_log(LOG_WARNING, "Host '%s' requests authentication (%d) for '%s'\n", 20994 ast_sockaddr_stringify(&p->sa), resp, sip_methods[sipmethod].text); 20995 break; 20996 case 405: /* Method not allowed */ 20997 case 501: /* Not Implemented */ 20998 mark_method_unallowed(&p->allowed_methods, sipmethod); 20999 if (p->relatedpeer) { 21000 mark_method_allowed(&p->relatedpeer->disallowed_methods, sipmethod); 21001 } 21002 ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", 21003 ast_sockaddr_stringify(&p->sa), sip_methods[sipmethod].text); 21004 break; 21005 default: 21006 if (300 <= resp && resp < 700) { 21007 ast_verb(3, "Got SIP %s response %d \"%s\" back from host '%s'\n", 21008 sip_methods[sipmethod].text, resp, rest, ast_sockaddr_stringify(&p->sa)); 21009 } 21010 break; 21011 } 21012 }
| static void handle_response_invite | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Handle SIP response to INVITE dialogue.
Definition at line 20088 of file chan_sip.c.
References append_history, AST_CAUSE_NORMAL_CLEARING, AST_CC_CCNR, ast_channel_queue_connected_line_update(), ast_channel_queue_redirecting_update(), AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, AST_CONTROL_ANSWER, AST_CONTROL_CONGESTION, AST_CONTROL_PROGRESS, AST_CONTROL_RINGING, AST_CONTROL_UPDATE_RTP_PEER, ast_debug, ast_log(), ast_null_frame, ast_party_connected_line_init(), ast_party_redirecting_free(), ast_party_redirecting_init(), AST_PRES_ALLOWED, AST_PRES_RESTRICTION, ast_queue_control(), ast_queue_frame(), ast_queue_hangup_with_cause(), ast_random(), ast_rtp_instance_activate(), ast_sched_add(), AST_SCHED_DEL_UNREF, ast_set_flag, ast_setstate(), AST_STATE_RINGING, AST_STATE_UP, ast_string_field_set, ast_strlen_zero(), ast_test_flag, build_route(), change_redirecting_information(), change_t38_state(), check_pendings(), connected, do_proxy_auth(), EVENT_FLAG_SYSTEM, FALSE, find_sdp(), get_header(), get_rpid(), hangup_sip2cause(), ast_party_connected_line::id, ast_set_party_connected_line::id, LOG_NOTICE, LOG_WARNING, manager_event, ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, parse_ok_contact(), parse_session_expires(), ast_party_name::presentation, ast_party_number::presentation, proc_422_rsp(), process_sdp(), pvt_set_needdestroy(), set_address_from_contact(), set_pvt_allowed_methods(), sip_alreadygone(), sip_cancel_destroy(), sip_cfg, sip_handle_cc(), sip_queue_hangup_cause(), sip_reinvite_retry(), sip_scheddestroy(), ast_party_connected_line::source, st_get_mode(), start_session_timer(), ast_party_name::str, ast_party_number::str, ast_party_id::tag, transmit_reinvite_with_sdp(), transmit_request(), TRUE, update_call_counter(), update_redirecting(), ast_party_name::valid, and ast_party_number::valid.
Referenced by handle_response().
20089 { 20090 int outgoing = ast_test_flag(&p->flags[0], SIP_OUTGOING); 20091 int res = 0; 20092 int xmitres = 0; 20093 int reinvite = ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 20094 char *p_hdrval; 20095 int rtn; 20096 struct ast_party_connected_line connected; 20097 struct ast_set_party_connected_line update_connected; 20098 20099 if (reinvite) 20100 ast_debug(4, "SIP response %d to RE-invite on %s call %s\n", resp, outgoing ? "outgoing" : "incoming", p->callid); 20101 else 20102 ast_debug(4, "SIP response %d to standard invite\n", resp); 20103 20104 if (p->alreadygone) { /* This call is already gone */ 20105 ast_debug(1, "Got response on call that is already terminated: %s (ignoring)\n", p->callid); 20106 return; 20107 } 20108 20109 /* Acknowledge sequence number - This only happens on INVITE from SIP-call */ 20110 /* Don't auto congest anymore since we've gotten something useful back */ 20111 AST_SCHED_DEL_UNREF(sched, p->initid, dialog_unref(p, "when you delete the initid sched, you should dec the refcount for the stored dialog ptr")); 20112 20113 /* RFC3261 says we must treat every 1xx response (but not 100) 20114 that we don't recognize as if it was 183. 20115 */ 20116 if (resp > 100 && resp < 200 && resp!=101 && resp != 180 && resp != 181 && resp != 182 && resp != 183) 20117 resp = 183; 20118 20119 /* Any response between 100 and 199 is PROCEEDING */ 20120 if (resp >= 100 && resp < 200 && p->invitestate == INV_CALLING) 20121 p->invitestate = INV_PROCEEDING; 20122 20123 /* Final response, not 200 ? */ 20124 if (resp >= 300 && (p->invitestate == INV_CALLING || p->invitestate == INV_PROCEEDING || p->invitestate == INV_EARLY_MEDIA )) 20125 p->invitestate = INV_COMPLETED; 20126 20127 if ((resp >= 200 && reinvite)) { 20128 p->ongoing_reinvite = 0; 20129 if (p->reinviteid > -1) { 20130 AST_SCHED_DEL_UNREF(sched, p->reinviteid, dialog_unref(p, "unref dialog for reinvite timeout because of a final response")); 20131 } 20132 } 20133 20134 /* Final response, clear out pending invite */ 20135 if ((resp == 200 || resp >= 300) && p->pendinginvite && seqno == p->pendinginvite) { 20136 p->pendinginvite = 0; 20137 } 20138 20139 /* If this is a response to our initial INVITE, we need to set what we can use 20140 * for this peer. 20141 */ 20142 if (!reinvite) { 20143 set_pvt_allowed_methods(p, req); 20144 } 20145 20146 switch (resp) { 20147 case 100: /* Trying */ 20148 case 101: /* Dialog establishment */ 20149 if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p)) 20150 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20151 check_pendings(p); 20152 break; 20153 20154 case 180: /* 180 Ringing */ 20155 case 182: /* 182 Queued */ 20156 if (!req->ignore && p->invitestate != INV_CANCELLED && sip_cancel_destroy(p)) 20157 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20158 /* Store Route-set from provisional SIP responses so 20159 * early-dialog request can be routed properly 20160 * */ 20161 parse_ok_contact(p, req); 20162 if (!reinvite) { 20163 build_route(p, req, 1, resp); 20164 } 20165 if (!req->ignore && p->owner) { 20166 if (get_rpid(p, req)) { 20167 /* Queue a connected line update */ 20168 ast_party_connected_line_init(&connected); 20169 memset(&update_connected, 0, sizeof(update_connected)); 20170 20171 update_connected.id.number = 1; 20172 connected.id.number.valid = 1; 20173 connected.id.number.str = (char *) p->cid_num; 20174 connected.id.number.presentation = p->callingpres; 20175 20176 update_connected.id.name = 1; 20177 connected.id.name.valid = 1; 20178 connected.id.name.str = (char *) p->cid_name; 20179 connected.id.name.presentation = p->callingpres; 20180 20181 connected.id.tag = (char *) p->cid_tag; 20182 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 20183 ast_channel_queue_connected_line_update(p->owner, &connected, 20184 &update_connected); 20185 } 20186 sip_handle_cc(p, req, AST_CC_CCNR); 20187 ast_queue_control(p->owner, AST_CONTROL_RINGING); 20188 if (p->owner->_state != AST_STATE_UP) { 20189 ast_setstate(p->owner, AST_STATE_RINGING); 20190 } 20191 } 20192 if (find_sdp(req)) { 20193 if (p->invitestate != INV_CANCELLED) 20194 p->invitestate = INV_EARLY_MEDIA; 20195 res = process_sdp(p, req, SDP_T38_NONE); 20196 if (!req->ignore && p->owner) { 20197 /* Queue a progress frame only if we have SDP in 180 or 182 */ 20198 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 20199 } 20200 ast_rtp_instance_activate(p->rtp); 20201 } 20202 check_pendings(p); 20203 break; 20204 20205 case 181: /* Call Is Being Forwarded */ 20206 if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 20207 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20208 /* Store Route-set from provisional SIP responses so 20209 * early-dialog request can be routed properly 20210 * */ 20211 parse_ok_contact(p, req); 20212 if (!reinvite) { 20213 build_route(p, req, 1, resp); 20214 } 20215 if (!req->ignore && p->owner) { 20216 struct ast_party_redirecting redirecting; 20217 struct ast_set_party_redirecting update_redirecting; 20218 20219 ast_party_redirecting_init(&redirecting); 20220 memset(&update_redirecting, 0, sizeof(update_redirecting)); 20221 change_redirecting_information(p, req, &redirecting, &update_redirecting, 20222 FALSE); 20223 ast_channel_queue_redirecting_update(p->owner, &redirecting, 20224 &update_redirecting); 20225 ast_party_redirecting_free(&redirecting); 20226 sip_handle_cc(p, req, AST_CC_CCNR); 20227 } 20228 check_pendings(p); 20229 break; 20230 20231 case 183: /* Session progress */ 20232 if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 20233 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20234 /* Store Route-set from provisional SIP responses so 20235 * early-dialog request can be routed properly 20236 * */ 20237 parse_ok_contact(p, req); 20238 if (!reinvite) { 20239 build_route(p, req, 1, resp); 20240 } 20241 if (!req->ignore && p->owner) { 20242 if (get_rpid(p, req)) { 20243 /* Queue a connected line update */ 20244 ast_party_connected_line_init(&connected); 20245 memset(&update_connected, 0, sizeof(update_connected)); 20246 20247 update_connected.id.number = 1; 20248 connected.id.number.valid = 1; 20249 connected.id.number.str = (char *) p->cid_num; 20250 connected.id.number.presentation = p->callingpres; 20251 20252 update_connected.id.name = 1; 20253 connected.id.name.valid = 1; 20254 connected.id.name.str = (char *) p->cid_name; 20255 connected.id.name.presentation = p->callingpres; 20256 20257 connected.id.tag = (char *) p->cid_tag; 20258 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 20259 ast_channel_queue_connected_line_update(p->owner, &connected, 20260 &update_connected); 20261 } 20262 sip_handle_cc(p, req, AST_CC_CCNR); 20263 } 20264 if (find_sdp(req)) { 20265 if (p->invitestate != INV_CANCELLED) 20266 p->invitestate = INV_EARLY_MEDIA; 20267 res = process_sdp(p, req, SDP_T38_NONE); 20268 if (!req->ignore && p->owner) { 20269 /* Queue a progress frame */ 20270 ast_queue_control(p->owner, AST_CONTROL_PROGRESS); 20271 } 20272 ast_rtp_instance_activate(p->rtp); 20273 } else { 20274 /* Alcatel PBXs are known to send 183s with no SDP after sending 20275 * a 100 Trying response. We're just going to treat this sort of thing 20276 * the same as we would treat a 180 Ringing 20277 */ 20278 if (!req->ignore && p->owner) { 20279 ast_queue_control(p->owner, AST_CONTROL_RINGING); 20280 } 20281 } 20282 check_pendings(p); 20283 break; 20284 20285 case 200: /* 200 OK on invite - someone's answering our call */ 20286 if (!req->ignore && (p->invitestate != INV_CANCELLED) && sip_cancel_destroy(p)) 20287 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 20288 p->authtries = 0; 20289 if (find_sdp(req)) { 20290 if ((res = process_sdp(p, req, SDP_T38_ACCEPT)) && !req->ignore) 20291 if (!reinvite) { 20292 /* This 200 OK's SDP is not acceptable, so we need to ack, then hangup */ 20293 /* For re-invites, we try to recover */ 20294 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 20295 } 20296 ast_rtp_instance_activate(p->rtp); 20297 } 20298 20299 if (!req->ignore && p->owner) { 20300 int rpid_changed; 20301 20302 rpid_changed = get_rpid(p, req); 20303 if (rpid_changed || !reinvite) { 20304 /* Queue a connected line update */ 20305 ast_party_connected_line_init(&connected); 20306 memset(&update_connected, 0, sizeof(update_connected)); 20307 if (rpid_changed 20308 || !ast_strlen_zero(p->cid_num) 20309 || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 20310 update_connected.id.number = 1; 20311 connected.id.number.valid = 1; 20312 connected.id.number.str = (char *) p->cid_num; 20313 connected.id.number.presentation = p->callingpres; 20314 } 20315 if (rpid_changed 20316 || !ast_strlen_zero(p->cid_name) 20317 || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 20318 update_connected.id.name = 1; 20319 connected.id.name.valid = 1; 20320 connected.id.name.str = (char *) p->cid_name; 20321 connected.id.name.presentation = p->callingpres; 20322 } 20323 if (update_connected.id.number || update_connected.id.name) { 20324 connected.id.tag = (char *) p->cid_tag; 20325 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 20326 ast_channel_queue_connected_line_update(p->owner, &connected, 20327 &update_connected); 20328 } 20329 } 20330 } 20331 20332 /* Parse contact header for continued conversation */ 20333 /* When we get 200 OK, we know which device (and IP) to contact for this call */ 20334 /* This is important when we have a SIP proxy between us and the phone */ 20335 if (outgoing) { 20336 update_call_counter(p, DEC_CALL_RINGING); 20337 parse_ok_contact(p, req); 20338 /* Save Record-Route for any later requests we make on this dialogue */ 20339 if (!reinvite) { 20340 build_route(p, req, 1, resp); 20341 } 20342 if(set_address_from_contact(p)) { 20343 /* Bad contact - we don't know how to reach this device */ 20344 /* We need to ACK, but then send a bye */ 20345 if (!p->route && !req->ignore) 20346 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 20347 } 20348 20349 } 20350 20351 if (!req->ignore && p->owner) { 20352 if (!reinvite) { 20353 ast_queue_control(p->owner, AST_CONTROL_ANSWER); 20354 if (sip_cfg.callevents) 20355 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 20356 "Channel: %s\r\nChanneltype: %s\r\nUniqueid: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\nPeername: %s\r\n", 20357 p->owner->name, "SIP", p->owner->uniqueid, p->callid, p->fullcontact, p->peername); 20358 } else { /* RE-invite */ 20359 if (p->t38.state == T38_DISABLED) { 20360 ast_queue_control(p->owner, AST_CONTROL_UPDATE_RTP_PEER); 20361 } else { 20362 ast_queue_frame(p->owner, &ast_null_frame); 20363 } 20364 } 20365 } else { 20366 /* It's possible we're getting an 200 OK after we've tried to disconnect 20367 by sending CANCEL */ 20368 /* First send ACK, then send bye */ 20369 if (!req->ignore) 20370 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 20371 } 20372 20373 /* Check for Session-Timers related headers */ 20374 if (st_get_mode(p, 0) != SESSION_TIMER_MODE_REFUSE && p->outgoing_call == TRUE && !reinvite) { 20375 p_hdrval = (char*)get_header(req, "Session-Expires"); 20376 if (!ast_strlen_zero(p_hdrval)) { 20377 /* UAS supports Session-Timers */ 20378 enum st_refresher tmp_st_ref = SESSION_TIMER_REFRESHER_AUTO; 20379 int tmp_st_interval = 0; 20380 rtn = parse_session_expires(p_hdrval, &tmp_st_interval, &tmp_st_ref); 20381 if (rtn != 0) { 20382 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 20383 } 20384 if (tmp_st_ref == SESSION_TIMER_REFRESHER_UAC || 20385 tmp_st_ref == SESSION_TIMER_REFRESHER_UAS) { 20386 p->stimer->st_ref = tmp_st_ref; 20387 } 20388 if (tmp_st_interval) { 20389 p->stimer->st_interval = tmp_st_interval; 20390 } 20391 p->stimer->st_active = TRUE; 20392 p->stimer->st_active_peer_ua = TRUE; 20393 start_session_timer(p); 20394 } else { 20395 /* UAS doesn't support Session-Timers */ 20396 if (st_get_mode(p, 0) == SESSION_TIMER_MODE_ORIGINATE) { 20397 p->stimer->st_ref = SESSION_TIMER_REFRESHER_UAC; 20398 p->stimer->st_active_peer_ua = FALSE; 20399 start_session_timer(p); 20400 } 20401 } 20402 } 20403 20404 20405 /* If I understand this right, the branch is different for a non-200 ACK only */ 20406 p->invitestate = INV_TERMINATED; 20407 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 20408 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, TRUE); 20409 check_pendings(p); 20410 break; 20411 20412 case 407: /* Proxy authentication */ 20413 case 401: /* Www auth */ 20414 /* First we ACK */ 20415 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20416 if (p->options) 20417 p->options->auth_type = resp; 20418 20419 /* Then we AUTH */ 20420 ast_string_field_set(p, theirtag, NULL); /* forget their old tag, so we don't match tags when getting response */ 20421 if (!req->ignore) { 20422 if (p->authtries < MAX_AUTHTRIES) 20423 p->invitestate = INV_CALLING; 20424 if (p->authtries == MAX_AUTHTRIES || do_proxy_auth(p, req, resp, SIP_INVITE, 1)) { 20425 ast_log(LOG_NOTICE, "Failed to authenticate on INVITE to '%s'\n", get_header(&p->initreq, "From")); 20426 pvt_set_needdestroy(p, "failed to authenticate on INVITE"); 20427 sip_alreadygone(p); 20428 if (p->owner) 20429 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 20430 } 20431 } 20432 break; 20433 20434 case 403: /* Forbidden */ 20435 /* First we ACK */ 20436 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20437 ast_log(LOG_WARNING, "Received response: \"Forbidden\" from '%s'\n", get_header(&p->initreq, "From")); 20438 if (!req->ignore && p->owner) { 20439 sip_queue_hangup_cause(p, hangup_sip2cause(resp)); 20440 } 20441 break; 20442 20443 case 404: /* Not found */ 20444 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20445 if (p->owner && !req->ignore) { 20446 sip_queue_hangup_cause(p, hangup_sip2cause(resp)); 20447 } 20448 break; 20449 20450 case 408: /* Request timeout */ 20451 case 481: /* Call leg does not exist */ 20452 /* Could be REFER caused INVITE with replaces */ 20453 ast_log(LOG_WARNING, "Re-invite to non-existing call leg on other UA. SIP dialog '%s'. Giving up.\n", p->callid); 20454 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20455 if (p->owner) { 20456 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 20457 } 20458 break; 20459 20460 case 422: /* Session-Timers: Session interval too small */ 20461 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20462 ast_string_field_set(p, theirtag, NULL); 20463 proc_422_rsp(p, req); 20464 break; 20465 20466 case 428: /* Use identity header - rfc 4474 - not supported by Asterisk yet */ 20467 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20468 append_history(p, "Identity", "SIP identity is required. Not supported by Asterisk."); 20469 ast_log(LOG_WARNING, "SIP identity required by proxy. SIP dialog '%s'. Giving up.\n", p->callid); 20470 if (p->owner && !req->ignore) { 20471 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 20472 } 20473 break; 20474 20475 case 487: /* Cancelled transaction */ 20476 /* We have sent CANCEL on an outbound INVITE 20477 This transaction is already scheduled to be killed by sip_hangup(). 20478 */ 20479 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20480 if (p->owner && !req->ignore) { 20481 ast_queue_hangup_with_cause(p->owner, AST_CAUSE_NORMAL_CLEARING); 20482 append_history(p, "Hangup", "Got 487 on CANCEL request from us. Queued AST hangup request"); 20483 } else if (!req->ignore) { 20484 update_call_counter(p, DEC_CALL_LIMIT); 20485 append_history(p, "Hangup", "Got 487 on CANCEL request from us on call without owner. Killing this dialog."); 20486 } 20487 check_pendings(p); 20488 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20489 break; 20490 case 415: /* Unsupported media type */ 20491 case 488: /* Not acceptable here */ 20492 case 606: /* Not Acceptable */ 20493 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20494 if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) { 20495 change_t38_state(p, T38_DISABLED); 20496 /* Try to reset RTP timers */ 20497 //ast_rtp_set_rtptimers_onhold(p->rtp); 20498 20499 /* Trigger a reinvite back to audio */ 20500 transmit_reinvite_with_sdp(p, FALSE, FALSE); 20501 } else { 20502 /* We can't set up this call, so give up */ 20503 if (p->owner && !req->ignore) { 20504 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 20505 } 20506 } 20507 break; 20508 case 491: /* Pending */ 20509 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20510 if (p->owner && !req->ignore) { 20511 if (p->owner->_state != AST_STATE_UP) { 20512 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 20513 } else { 20514 /* This is a re-invite that failed. */ 20515 /* Reset the flag after a while 20516 */ 20517 int wait; 20518 /* RFC 3261, if owner of call, wait between 2.1 to 4 seconds, 20519 * if not owner of call, wait 0 to 2 seconds */ 20520 if (p->outgoing_call) { 20521 wait = 2100 + ast_random() % 2000; 20522 } else { 20523 wait = ast_random() % 2000; 20524 } 20525 p->waitid = ast_sched_add(sched, wait, sip_reinvite_retry, dialog_ref(p, "passing dialog ptr into sched structure based on waitid for sip_reinvite_retry.")); 20526 ast_log(LOG_WARNING, "just did sched_add waitid(%d) for sip_reinvite_retry for dialog %s in handle_response_invite\n", p->waitid, p->callid); 20527 ast_debug(2, "Reinvite race. Waiting %d secs before retry\n", wait); 20528 } 20529 } 20530 break; 20531 20532 case 405: /* Not allowed */ 20533 case 501: /* Not implemented */ 20534 xmitres = transmit_request(p, SIP_ACK, seqno, XMIT_UNRELIABLE, FALSE); 20535 if (p->owner) { 20536 ast_queue_hangup_with_cause(p->owner, hangup_sip2cause(resp)); 20537 } 20538 break; 20539 } 20540 if (xmitres == XMIT_ERROR) 20541 ast_log(LOG_WARNING, "Could not transmit message in dialog %s\n", p->callid); 20542 }
| static void handle_response_message | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 21022 of file chan_sip.c.
References ast_log(), ast_sockaddr_stringify(), ast_verb, LOG_WARNING, mark_method_allowed(), mark_method_unallowed(), sip_methods, text, and cfsip_methods::text.
Referenced by handle_response().
21023 { 21024 int sipmethod = SIP_MESSAGE; 21025 /* Out-of-dialog MESSAGE currently not supported. */ 21026 //int in_dialog = ast_test_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 21027 21028 switch (resp) { 21029 case 401: /* Not www-authorized on SIP method */ 21030 case 407: /* Proxy auth required */ 21031 ast_log(LOG_WARNING, "Host '%s' requests authentication (%d) for '%s'\n", 21032 ast_sockaddr_stringify(&p->sa), resp, sip_methods[sipmethod].text); 21033 break; 21034 case 405: /* Method not allowed */ 21035 case 501: /* Not Implemented */ 21036 mark_method_unallowed(&p->allowed_methods, sipmethod); 21037 if (p->relatedpeer) { 21038 mark_method_allowed(&p->relatedpeer->disallowed_methods, sipmethod); 21039 } 21040 ast_log(LOG_WARNING, "Host '%s' does not implement '%s'\n", 21041 ast_sockaddr_stringify(&p->sa), sip_methods[sipmethod].text); 21042 break; 21043 default: 21044 if (100 <= resp && resp < 200) { 21045 /* Must allow provisional responses for out-of-dialog requests. */ 21046 } else if (200 <= resp && resp < 300) { 21047 p->authtries = 0; /* Reset authentication counter */ 21048 } else if (300 <= resp && resp < 700) { 21049 ast_verb(3, "Got SIP %s response %d \"%s\" back from host '%s'\n", 21050 sip_methods[sipmethod].text, resp, rest, ast_sockaddr_stringify(&p->sa)); 21051 } 21052 break; 21053 } 21054 }
| static void handle_response_notify | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 20547 of file chan_sip.c.
References ast_clear_flag, ast_debug, ast_log(), ast_sockaddr_stringify(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, cb_extensionstate(), do_proxy_auth(), get_header(), LOG_NOTICE, LOG_WARNING, NONE, and pvt_set_needdestroy().
Referenced by handle_response().
20548 { 20549 switch (resp) { 20550 case 200: /* Notify accepted */ 20551 /* They got the notify, this is the end */ 20552 if (p->owner) { 20553 if (p->refer) { 20554 ast_log(LOG_NOTICE, "Got OK on REFER Notify message\n"); 20555 } else { 20556 ast_log(LOG_WARNING, "Notify answer on an owned channel? - %s\n", p->owner->name); 20557 } 20558 } else { 20559 if (p->subscribed == NONE && !p->refer) { 20560 ast_debug(4, "Got 200 accepted on NOTIFY %s\n", p->callid); 20561 pvt_set_needdestroy(p, "received 200 response"); 20562 } 20563 if (ast_test_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE)) { 20564 /* Ready to send the next state we have on queue */ 20565 ast_clear_flag(&p->flags[1], SIP_PAGE2_STATECHANGEQUEUE); 20566 cb_extensionstate((char *)p->context, (char *)p->exten, p->laststate, (void *) p); 20567 } 20568 } 20569 break; 20570 case 401: /* Not www-authorized on SIP method */ 20571 case 407: /* Proxy auth */ 20572 if (!p->notify) { 20573 break; /* Only device notify can use NOTIFY auth */ 20574 } 20575 ast_string_field_set(p, theirtag, NULL); 20576 if (ast_strlen_zero(p->authname)) { 20577 ast_log(LOG_WARNING, "Asked to authenticate NOTIFY to %s but we have no matching peer or realm auth!\n", ast_sockaddr_stringify(&p->recv)); 20578 pvt_set_needdestroy(p, "unable to authenticate NOTIFY"); 20579 } 20580 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_NOTIFY, 0)) { 20581 ast_log(LOG_NOTICE, "Failed to authenticate on NOTIFY to '%s'\n", get_header(&p->initreq, "From")); 20582 pvt_set_needdestroy(p, "failed to authenticate NOTIFY"); 20583 } 20584 break; 20585 case 481: /* Call leg does not exist */ 20586 pvt_set_needdestroy(p, "Received 481 response for NOTIFY"); 20587 break; 20588 } 20589 }
| static void handle_response_peerpoke | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| struct sip_request * | req | |||
| ) | [static] |
Handle qualification responses (OPTIONS).
Definition at line 20919 of file chan_sip.c.
References ast_check_realtime(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), AST_SCHED_REPLACE_UNREF, ast_tvdiff_ms(), ast_tvnow(), ast_update_realtime(), DEFAULT_FREQ_NOTOK, EVENT_FLAG_SYSTEM, LOG_NOTICE, manager_event, pvt_set_needdestroy(), ref_peer(), register_peer_exten(), SENTINEL, sip_cfg, sip_poke_peer_s(), TRUE, and unref_peer().
Referenced by handle_response().
20920 { 20921 struct sip_peer *peer = /* ref_peer( */ p->relatedpeer /* , "bump refcount on p, as it is being used in this function(handle_response_peerpoke)")*/ ; /* hope this is already refcounted! */ 20922 int statechanged, is_reachable, was_reachable; 20923 int pingtime = ast_tvdiff_ms(ast_tvnow(), peer->ps); 20924 20925 /* 20926 * Compute the response time to a ping (goes in peer->lastms.) 20927 * -1 means did not respond, 0 means unknown, 20928 * 1..maxms is a valid response, >maxms means late response. 20929 */ 20930 if (pingtime < 1) { /* zero = unknown, so round up to 1 */ 20931 pingtime = 1; 20932 } 20933 20934 if (!peer->maxms) { /* this should never happens */ 20935 pvt_set_needdestroy(p, "got OPTIONS response but qualify is not enabled"); 20936 return; 20937 } 20938 20939 /* Now determine new state and whether it has changed. 20940 * Use some helper variables to simplify the writing 20941 * of the expressions. 20942 */ 20943 was_reachable = peer->lastms > 0 && peer->lastms <= peer->maxms; 20944 is_reachable = pingtime <= peer->maxms; 20945 statechanged = peer->lastms == 0 /* yes, unknown before */ 20946 || was_reachable != is_reachable; 20947 20948 peer->lastms = pingtime; 20949 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 20950 if (statechanged) { 20951 const char *s = is_reachable ? "Reachable" : "Lagged"; 20952 char str_lastms[20]; 20953 snprintf(str_lastms, sizeof(str_lastms), "%d", pingtime); 20954 20955 ast_log(LOG_NOTICE, "Peer '%s' is now %s. (%dms / %dms)\n", 20956 peer->name, s, pingtime, peer->maxms); 20957 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 20958 if (sip_cfg.peer_rtupdate) { 20959 ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", str_lastms, SENTINEL); 20960 } 20961 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 20962 "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: %s\r\nTime: %d\r\n", 20963 peer->name, s, pingtime); 20964 if (is_reachable && sip_cfg.regextenonqualify) 20965 register_peer_exten(peer, TRUE); 20966 } 20967 20968 pvt_set_needdestroy(p, "got OPTIONS response"); 20969 20970 /* Try again eventually */ 20971 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, 20972 is_reachable ? peer->qualifyfreq : DEFAULT_FREQ_NOTOK, 20973 sip_poke_peer_s, peer, 20974 unref_peer(_data, "removing poke peer ref"), 20975 unref_peer(peer, "removing poke peer ref"), 20976 ref_peer(peer, "adding poke peer ref")); 20977 }
| static void handle_response_publish | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 20002 of file chan_sip.c.
References ast_assert, ast_copy_string(), ast_log(), ast_string_field_set, ast_strlen_zero(), do_proxy_auth(), get_header(), LOG_NOTICE, mark_method_unallowed(), pvt_set_needdestroy(), and sip_alreadygone().
Referenced by handle_response().
20003 { 20004 struct sip_epa_entry *epa_entry = p->epa_entry; 20005 const char *etag = get_header(req, "Sip-ETag"); 20006 20007 ast_assert(epa_entry != NULL); 20008 20009 if (resp == 401 || resp == 407) { 20010 ast_string_field_set(p, theirtag, NULL); 20011 if (p->options) { 20012 p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH); 20013 } 20014 if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, SIP_PUBLISH, 0)) { 20015 ast_log(LOG_NOTICE, "Failed to authenticate on PUBLISH to '%s'\n", get_header(&p->initreq, "From")); 20016 pvt_set_needdestroy(p, "Failed to authenticate on PUBLISH"); 20017 sip_alreadygone(p); 20018 } 20019 return; 20020 } 20021 20022 if (resp == 501 || resp == 405) { 20023 mark_method_unallowed(&p->allowed_methods, SIP_PUBLISH); 20024 } 20025 20026 if (resp == 200) { 20027 p->authtries = 0; 20028 /* If I've read section 6, item 6 of RFC 3903 correctly, 20029 * an ESC will only generate a new etag when it sends a 200 OK 20030 */ 20031 if (!ast_strlen_zero(etag)) { 20032 ast_copy_string(epa_entry->entity_tag, etag, sizeof(epa_entry->entity_tag)); 20033 } 20034 /* The nominal case. Everything went well. Everybody is happy. 20035 * Each EPA will have a specific action to take as a result of this 20036 * development, so ... callbacks! 20037 */ 20038 if (epa_entry->static_data->handle_ok) { 20039 epa_entry->static_data->handle_ok(p, req, epa_entry); 20040 } 20041 } else { 20042 /* Rather than try to make individual callbacks for each error 20043 * type, there is just a single error callback. The callback 20044 * can distinguish between error messages and do what it needs to 20045 */ 20046 if (epa_entry->static_data->handle_error) { 20047 epa_entry->static_data->handle_error(p, resp, req, epa_entry); 20048 } 20049 } 20050 }
| static void handle_response_refer | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 20675 of file chan_sip.c.
References AST_CONTROL_CONGESTION, AST_CONTROL_TRANSFER, ast_debug, ast_log(), ast_queue_control(), ast_queue_control_data(), ast_sockaddr_stringify(), ast_strlen_zero(), AST_TRANSFER_FAILED, do_proxy_auth(), get_header(), LOG_NOTICE, LOG_WARNING, and pvt_set_needdestroy().
Referenced by handle_response().
20676 { 20677 enum ast_control_transfer message = AST_TRANSFER_FAILED; 20678 20679 /* If no refer structure exists, then do nothing */ 20680 if (!p->refer) 20681 return; 20682 20683 switch (resp) { 20684 case 202: /* Transfer accepted */ 20685 /* We need to do something here */ 20686 /* The transferee is now sending INVITE to target */ 20687 p->refer->status = REFER_ACCEPTED; 20688 /* Now wait for next message */ 20689 ast_debug(3, "Got 202 accepted on transfer\n"); 20690 /* We should hang along, waiting for NOTIFY's here */ 20691 break; 20692 20693 case 401: /* Not www-authorized on SIP method */ 20694 case 407: /* Proxy auth */ 20695 if (ast_strlen_zero(p->authname)) { 20696 ast_log(LOG_WARNING, "Asked to authenticate REFER to %s but we have no matching peer or realm auth!\n", 20697 ast_sockaddr_stringify(&p->recv)); 20698 if (p->owner) { 20699 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20700 } 20701 pvt_set_needdestroy(p, "unable to authenticate REFER"); 20702 } 20703 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_REFER, 0)) { 20704 ast_log(LOG_NOTICE, "Failed to authenticate on REFER to '%s'\n", get_header(&p->initreq, "From")); 20705 p->refer->status = REFER_NOAUTH; 20706 if (p->owner) { 20707 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20708 } 20709 pvt_set_needdestroy(p, "failed to authenticate REFER"); 20710 } 20711 break; 20712 20713 case 405: /* Method not allowed */ 20714 /* Return to the current call onhold */ 20715 /* Status flag needed to be reset */ 20716 ast_log(LOG_NOTICE, "SIP transfer to %s failed, REFER not allowed. \n", p->refer->refer_to); 20717 pvt_set_needdestroy(p, "received 405 response"); 20718 p->refer->status = REFER_FAILED; 20719 if (p->owner) { 20720 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20721 } 20722 break; 20723 20724 case 481: /* Call leg does not exist */ 20725 20726 /* A transfer with Replaces did not work */ 20727 /* OEJ: We should Set flag, cancel the REFER, go back 20728 to original call - but right now we can't */ 20729 ast_log(LOG_WARNING, "Remote host can't match REFER request to call '%s'. Giving up.\n", p->callid); 20730 if (p->owner) 20731 ast_queue_control(p->owner, AST_CONTROL_CONGESTION); 20732 pvt_set_needdestroy(p, "received 481 response"); 20733 break; 20734 20735 case 500: /* Server error */ 20736 case 501: /* Method not implemented */ 20737 /* Return to the current call onhold */ 20738 /* Status flag needed to be reset */ 20739 ast_log(LOG_NOTICE, "SIP transfer to %s failed, call miserably fails. \n", p->refer->refer_to); 20740 pvt_set_needdestroy(p, "received 500/501 response"); 20741 p->refer->status = REFER_FAILED; 20742 if (p->owner) { 20743 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20744 } 20745 break; 20746 case 603: /* Transfer declined */ 20747 ast_log(LOG_NOTICE, "SIP transfer to %s declined, call miserably fails. \n", p->refer->refer_to); 20748 p->refer->status = REFER_FAILED; 20749 pvt_set_needdestroy(p, "received 603 response"); 20750 if (p->owner) { 20751 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20752 } 20753 break; 20754 default: 20755 /* We should treat unrecognized 9xx as 900. 400 is actually 20756 specified as a possible response, but any 4-6xx is 20757 theoretically possible. */ 20758 20759 if (resp < 299) { /* 1xx cases don't get here */ 20760 ast_log(LOG_WARNING, "SIP transfer to %s had unxpected 2xx response (%d), confusion is possible. \n", p->refer->refer_to, resp); 20761 } else { 20762 ast_log(LOG_WARNING, "SIP transfer to %s with response (%d). \n", p->refer->refer_to, resp); 20763 } 20764 20765 p->refer->status = REFER_FAILED; 20766 pvt_set_needdestroy(p, "received failure response"); 20767 if (p->owner) { 20768 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 20769 } 20770 break; 20771 } 20772 }
| static int handle_response_register | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Handle responses on REGISTER to services.
Definition at line 20775 of file chan_sip.c.
References __get_header(), ast_debug, ast_log(), AST_SCHED_DEL_UNREF, AST_SCHED_REPLACE_UNREF, ast_strlen_zero(), ast_tvnow(), do_register_auth(), EVENT_FLAG_SYSTEM, get_header(), LOG_NOTICE, LOG_WARNING, manager_event, MAX, pvt_set_needdestroy(), REG_STATE_NOAUTH, REG_STATE_REGISTERED, REG_STATE_REJECTED, REG_STATE_UNREGISTERED, registry_addref(), registry_unref(), regstate2str(), S_OR, sip_reregister(), sip_scheddestroy(), and transmit_register().
Referenced by handle_response().
20776 { 20777 int expires, expires_ms; 20778 struct sip_registry *r; 20779 r=p->registry; 20780 20781 switch (resp) { 20782 case 401: /* Unauthorized */ 20783 if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) { 20784 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s@%s' (Tries %d)\n", p->registry->username, p->registry->hostname, p->authtries); 20785 pvt_set_needdestroy(p, "failed to authenticate REGISTER"); 20786 } 20787 break; 20788 case 403: /* Forbidden */ 20789 ast_log(LOG_WARNING, "Forbidden - wrong password on authentication for REGISTER for '%s' to '%s'\n", p->registry->username, p->registry->hostname); 20790 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 403")); 20791 r->regstate = REG_STATE_NOAUTH; 20792 pvt_set_needdestroy(p, "received 403 response"); 20793 break; 20794 case 404: /* Not found */ 20795 ast_log(LOG_WARNING, "Got 404 Not found on SIP register to service %s@%s, giving up\n", p->registry->username, p->registry->hostname); 20796 pvt_set_needdestroy(p, "received 404 response"); 20797 if (r->call) 20798 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 404"); 20799 r->regstate = REG_STATE_REJECTED; 20800 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 404")); 20801 break; 20802 case 407: /* Proxy auth */ 20803 if (p->authtries == MAX_AUTHTRIES || do_register_auth(p, req, resp)) { 20804 ast_log(LOG_NOTICE, "Failed to authenticate on REGISTER to '%s' (tries '%d')\n", get_header(&p->initreq, "From"), p->authtries); 20805 pvt_set_needdestroy(p, "failed to authenticate REGISTER"); 20806 } 20807 break; 20808 case 408: /* Request timeout */ 20809 /* Got a timeout response, so reset the counter of failed responses */ 20810 if (r) { 20811 r->regattempts = 0; 20812 } else { 20813 ast_log(LOG_WARNING, "Got a 408 response to our REGISTER on call %s after we had destroyed the registry object\n", p->callid); 20814 } 20815 break; 20816 case 423: /* Interval too brief */ 20817 r->expiry = atoi(get_header(req, "Min-Expires")); 20818 ast_log(LOG_WARNING, "Got 423 Interval too brief for service %s@%s, minimum is %d seconds\n", p->registry->username, p->registry->hostname, r->expiry); 20819 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 423")); 20820 if (r->call) { 20821 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 423"); 20822 pvt_set_needdestroy(p, "received 423 response"); 20823 } 20824 if (r->expiry > max_expiry) { 20825 ast_log(LOG_WARNING, "Required expiration time from %s@%s is too high, giving up\n", p->registry->username, p->registry->hostname); 20826 r->expiry = r->configured_expiry; 20827 r->regstate = REG_STATE_REJECTED; 20828 } else { 20829 r->regstate = REG_STATE_UNREGISTERED; 20830 transmit_register(r, SIP_REGISTER, NULL, NULL); 20831 } 20832 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate)); 20833 break; 20834 case 479: /* SER: Not able to process the URI - address is wrong in register*/ 20835 ast_log(LOG_WARNING, "Got error 479 on register to %s@%s, giving up (check config)\n", p->registry->username, p->registry->hostname); 20836 pvt_set_needdestroy(p, "received 479 response"); 20837 if (r->call) 20838 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 479"); 20839 r->regstate = REG_STATE_REJECTED; 20840 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 479")); 20841 break; 20842 case 200: /* 200 OK */ 20843 if (!r) { 20844 ast_log(LOG_WARNING, "Got 200 OK on REGISTER, but there isn't a registry entry for '%s' (we probably already got the OK)\n", S_OR(p->peername, p->username)); 20845 pvt_set_needdestroy(p, "received erroneous 200 response"); 20846 return 0; 20847 } 20848 20849 r->regstate = REG_STATE_REGISTERED; 20850 r->regtime = ast_tvnow(); /* Reset time of last successful registration */ 20851 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nDomain: %s\r\nStatus: %s\r\n", r->hostname, regstate2str(r->regstate)); 20852 r->regattempts = 0; 20853 ast_debug(1, "Registration successful\n"); 20854 if (r->timeout > -1) { 20855 ast_debug(1, "Cancelling timeout %d\n", r->timeout); 20856 } 20857 AST_SCHED_DEL_UNREF(sched, r->timeout, registry_unref(r, "reg ptr unref from handle_response_register 200")); 20858 if (r->call) 20859 r->call = dialog_unref(r->call, "unsetting registry->call pointer-- case 200"); 20860 p->registry = registry_unref(p->registry, "unref registry entry p->registry"); 20861 /* Let this one hang around until we have all the responses */ 20862 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 20863 /* p->needdestroy = 1; */ 20864 20865 /* set us up for re-registering 20866 * figure out how long we got registered for 20867 * according to section 6.13 of RFC, contact headers override 20868 * expires headers, so check those first */ 20869 expires = 0; 20870 20871 /* XXX todo: try to save the extra call */ 20872 if (!ast_strlen_zero(get_header(req, "Contact"))) { 20873 const char *contact = NULL; 20874 const char *tmptmp = NULL; 20875 int start = 0; 20876 for(;;) { 20877 contact = __get_header(req, "Contact", &start); 20878 /* this loop ensures we get a contact header about our register request */ 20879 if(!ast_strlen_zero(contact)) { 20880 if( (tmptmp=strstr(contact, p->our_contact))) { 20881 contact=tmptmp; 20882 break; 20883 } 20884 } else 20885 break; 20886 } 20887 tmptmp = strcasestr(contact, "expires="); 20888 if (tmptmp) { 20889 if (sscanf(tmptmp + 8, "%30d;", &expires) != 1) 20890 expires = 0; 20891 } 20892 20893 } 20894 if (!expires) 20895 expires=atoi(get_header(req, "expires")); 20896 if (!expires) 20897 expires=default_expiry; 20898 20899 expires_ms = expires * 1000; 20900 if (expires <= EXPIRY_GUARD_LIMIT) 20901 expires_ms -= MAX((expires_ms * EXPIRY_GUARD_PCT), EXPIRY_GUARD_MIN); 20902 else 20903 expires_ms -= EXPIRY_GUARD_SECS * 1000; 20904 if (sipdebug) 20905 ast_log(LOG_NOTICE, "Outbound Registration: Expiry for %s is %d sec (Scheduling reregistration in %d s)\n", r->hostname, expires, expires_ms/1000); 20906 20907 r->refresh= (int) expires_ms / 1000; 20908 20909 /* Schedule re-registration before we expire */ 20910 AST_SCHED_REPLACE_UNREF(r->expire, sched, expires_ms, sip_reregister, r, 20911 registry_unref(_data,"unref in REPLACE del fail"), 20912 registry_unref(r,"unref in REPLACE add fail"), 20913 registry_addref(r,"The Addition side of REPLACE")); 20914 } 20915 return 1; 20916 }
| static void handle_response_subscribe | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 20592 of file chan_sip.c.
References ao2_callback, ast_cc_monitor_failed(), ast_debug, ast_free, ast_log(), ast_sched_add(), ast_string_field_set, ASTOBJ_REF, ASTOBJ_UNREF, do_proxy_auth(), find_sip_monitor_instance_by_subscription_pvt(), get_header(), LOG_NOTICE, LOG_WARNING, pvt_set_needdestroy(), set_pvt_allowed_methods(), sip_alreadygone(), sip_subscribe_mwi_destroy(), sip_subscribe_mwi_do(), and transmit_response_with_date().
Referenced by handle_response().
20593 { 20594 if (p->subscribed == CALL_COMPLETION) { 20595 struct sip_monitor_instance *monitor_instance; 20596 20597 if (resp < 300) { 20598 return; 20599 } 20600 20601 /* Final failure response received. */ 20602 monitor_instance = ao2_callback(sip_monitor_instances, 0, 20603 find_sip_monitor_instance_by_subscription_pvt, p); 20604 if (monitor_instance) { 20605 ast_cc_monitor_failed(monitor_instance->core_id, 20606 monitor_instance->device_name, 20607 "Received error response to our SUBSCRIBE"); 20608 } 20609 return; 20610 } 20611 20612 if (p->subscribed != MWI_NOTIFICATION) { 20613 return; 20614 } 20615 if (!p->mwi) { 20616 return; 20617 } 20618 20619 switch (resp) { 20620 case 200: /* Subscription accepted */ 20621 ast_debug(3, "Got 200 OK on subscription for MWI\n"); 20622 set_pvt_allowed_methods(p, req); 20623 if (p->options) { 20624 ast_free(p->options); 20625 p->options = NULL; 20626 } 20627 p->mwi->subscribed = 1; 20628 if ((p->mwi->resub = ast_sched_add(sched, mwi_expiry * 1000, sip_subscribe_mwi_do, ASTOBJ_REF(p->mwi))) < 0) { 20629 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20630 } 20631 break; 20632 case 401: 20633 case 407: 20634 ast_string_field_set(p, theirtag, NULL); 20635 if (p->authtries > 1 || do_proxy_auth(p, req, resp, SIP_SUBSCRIBE, 0)) { 20636 ast_log(LOG_NOTICE, "Failed to authenticate on SUBSCRIBE to '%s'\n", get_header(&p->initreq, "From")); 20637 p->mwi->call = NULL; 20638 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20639 pvt_set_needdestroy(p, "failed to authenticate SUBSCRIBE"); 20640 } 20641 break; 20642 case 403: 20643 transmit_response_with_date(p, "200 OK", req); 20644 ast_log(LOG_WARNING, "Authentication failed while trying to subscribe for MWI.\n"); 20645 p->mwi->call = NULL; 20646 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20647 pvt_set_needdestroy(p, "received 403 response"); 20648 sip_alreadygone(p); 20649 break; 20650 case 404: 20651 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side said that a mailbox may not have been configured.\n"); 20652 p->mwi->call = NULL; 20653 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20654 pvt_set_needdestroy(p, "received 404 response"); 20655 break; 20656 case 481: 20657 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side said that our dialog did not exist.\n"); 20658 p->mwi->call = NULL; 20659 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20660 pvt_set_needdestroy(p, "received 481 response"); 20661 break; 20662 case 500: 20663 case 501: 20664 ast_log(LOG_WARNING, "Subscription failed for MWI. The remote side may have suffered a heart attack.\n"); 20665 p->mwi->call = NULL; 20666 ASTOBJ_UNREF(p->mwi, sip_subscribe_mwi_destroy); 20667 pvt_set_needdestroy(p, "received 500/501 response"); 20668 break; 20669 } 20670 }
| static void handle_response_update | ( | struct sip_pvt * | p, | |
| int | resp, | |||
| const char * | rest, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno | |||
| ) | [static] |
Handle authentication challenge for SIP UPDATE.
This function is only called upon the receipt of a 401/407 response to an UPDATE.
Definition at line 19942 of file chan_sip.c.
References ast_log(), do_proxy_auth(), get_header(), and LOG_NOTICE.
Referenced by handle_response().
19943 { 19944 if (p->options) { 19945 p->options->auth_type = (resp == 401 ? WWW_AUTH : PROXY_AUTH); 19946 } 19947 if ((p->authtries == MAX_AUTHTRIES) || do_proxy_auth(p, req, resp, SIP_UPDATE, 1)) { 19948 ast_log(LOG_NOTICE, "Failed to authenticate on UPDATE to '%s'\n", get_header(&p->initreq, "From")); 19949 } 19950 }
| static int handle_sip_publish_initial | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct event_state_compositor * | esc, | |||
| const int | expires | |||
| ) | [static] |
Definition at line 24410 of file chan_sip.c.
References ao2_ref, event_state_compositor::callbacks, create_esc_entry(), transmit_response(), and transmit_response_with_sip_etag().
Referenced by handle_request_publish().
24411 { 24412 struct sip_esc_entry *esc_entry = create_esc_entry(esc, req, expires); 24413 int res = 0; 24414 24415 if (!esc_entry) { 24416 transmit_response(p, "503 Internal Server Failure", req); 24417 return -1; 24418 } 24419 24420 if (esc->callbacks->initial_handler) { 24421 res = esc->callbacks->initial_handler(p, req, esc, esc_entry); 24422 } 24423 24424 if (!res) { 24425 transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 0); 24426 } 24427 24428 ao2_ref(esc_entry, -1); 24429 return res; 24430 }
| 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] |
Definition at line 24460 of file chan_sip.c.
References ao2_ref, AST_SCHED_REPLACE_UNREF, event_state_compositor::callbacks, get_esc_entry(), publish_expire(), transmit_response(), and transmit_response_with_sip_etag().
Referenced by handle_request_publish().
24461 { 24462 struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc); 24463 int expires_ms = expires * 1000; 24464 int res = 0; 24465 24466 if (!esc_entry) { 24467 transmit_response(p, "412 Conditional Request Failed", req); 24468 return -1; 24469 } 24470 24471 AST_SCHED_REPLACE_UNREF(esc_entry->sched_id, sched, expires_ms, publish_expire, esc_entry, 24472 ao2_ref(_data, -1), 24473 ao2_ref(esc_entry, -1), 24474 ao2_ref(esc_entry, +1)); 24475 24476 if (esc->callbacks->modify_handler) { 24477 res = esc->callbacks->modify_handler(p, req, esc, esc_entry); 24478 } 24479 24480 if (!res) { 24481 transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1); 24482 } 24483 24484 ao2_ref(esc_entry, -1); 24485 return res; 24486 }
| 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] |
Definition at line 24432 of file chan_sip.c.
References ao2_ref, AST_SCHED_REPLACE_UNREF, event_state_compositor::callbacks, get_esc_entry(), publish_expire(), transmit_response(), and transmit_response_with_sip_etag().
Referenced by handle_request_publish().
24433 { 24434 struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc); 24435 int expires_ms = expires * 1000; 24436 int res = 0; 24437 24438 if (!esc_entry) { 24439 transmit_response(p, "412 Conditional Request Failed", req); 24440 return -1; 24441 } 24442 24443 AST_SCHED_REPLACE_UNREF(esc_entry->sched_id, sched, expires_ms, publish_expire, esc_entry, 24444 ao2_ref(_data, -1), 24445 ao2_ref(esc_entry, -1), 24446 ao2_ref(esc_entry, +1)); 24447 24448 if (esc->callbacks->refresh_handler) { 24449 res = esc->callbacks->refresh_handler(p, req, esc, esc_entry); 24450 } 24451 24452 if (!res) { 24453 transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1); 24454 } 24455 24456 ao2_ref(esc_entry, -1); 24457 return res; 24458 }
| static int handle_sip_publish_remove | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| struct event_state_compositor * | esc, | |||
| const char *const | etag | |||
| ) | [static] |
Definition at line 24488 of file chan_sip.c.
References ao2_ref, ao2_unlink, AST_SCHED_DEL, event_state_compositor::callbacks, event_state_compositor::compositor, get_esc_entry(), transmit_response(), and transmit_response_with_sip_etag().
Referenced by handle_request_publish().
24489 { 24490 struct sip_esc_entry *esc_entry = get_esc_entry(etag, esc); 24491 int res = 0; 24492 24493 if (!esc_entry) { 24494 transmit_response(p, "412 Conditional Request Failed", req); 24495 return -1; 24496 } 24497 24498 AST_SCHED_DEL(sched, esc_entry->sched_id); 24499 /* Scheduler's ref of the esc_entry */ 24500 ao2_ref(esc_entry, -1); 24501 24502 if (esc->callbacks->remove_handler) { 24503 res = esc->callbacks->remove_handler(p, req, esc, esc_entry); 24504 } 24505 24506 if (!res) { 24507 transmit_response_with_sip_etag(p, "200 OK", req, esc_entry, 1); 24508 } 24509 24510 /* Ref from finding the esc_entry earlier in function */ 24511 ao2_unlink(esc->compositor, esc_entry); 24512 ao2_ref(esc_entry, -1); 24513 return res; 24514 }
| static int handle_t38_options | ( | struct ast_flags * | flags, | |
| struct ast_flags * | mask, | |||
| struct ast_variable * | v, | |||
| int * | maxdatagram | |||
| ) | [static] |
Handle T.38 configuration options common to users and peers.
Definition at line 26850 of file chan_sip.c.
References ast_clear_flag, ast_log(), ast_set2_flag, ast_set_flag, ast_strdupa, ast_true(), ast_variable::lineno, LOG_WARNING, ast_variable::name, ast_variable::value, and word.
Referenced by build_peer(), and reload_config().
26852 { 26853 int res = 1; 26854 26855 if (!strcasecmp(v->name, "t38pt_udptl")) { 26856 char *buf = ast_strdupa(v->value); 26857 char *word, *next = buf; 26858 26859 ast_set_flag(&mask[1], SIP_PAGE2_T38SUPPORT); 26860 26861 while ((word = strsep(&next, ","))) { 26862 if (ast_true(word) || !strcasecmp(word, "fec")) { 26863 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 26864 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL_FEC); 26865 } else if (!strcasecmp(word, "redundancy")) { 26866 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 26867 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY); 26868 } else if (!strcasecmp(word, "none")) { 26869 ast_clear_flag(&flags[1], SIP_PAGE2_T38SUPPORT); 26870 ast_set_flag(&flags[1], SIP_PAGE2_T38SUPPORT_UDPTL); 26871 } else if (!strncasecmp(word, "maxdatagram=", 12)) { 26872 if (sscanf(&word[12], "%30u", maxdatagram) != 1) { 26873 ast_log(LOG_WARNING, "Invalid maxdatagram '%s' at line %d of %s\n", v->value, v->lineno, config); 26874 *maxdatagram = global_t38_maxdatagram; 26875 } 26876 } 26877 } 26878 } else if (!strcasecmp(v->name, "t38pt_usertpsource")) { 26879 ast_set_flag(&mask[1], SIP_PAGE2_UDPTL_DESTINATION); 26880 ast_set2_flag(&flags[1], ast_true(v->value), SIP_PAGE2_UDPTL_DESTINATION); 26881 } else { 26882 res = 0; 26883 } 26884 26885 return res; 26886 }
| const char* hangup_cause2sip | ( | int | cause | ) |
Convert Asterisk hangup causes to SIP codes.
Possible values from causes.h
AST_CAUSE_NOTDEFINED AST_CAUSE_NORMAL AST_CAUSE_BUSY
AST_CAUSE_FAILURE AST_CAUSE_CONGESTION AST_CAUSE_UNALLOCATED
In addition to these, a lot of PRI codes is defined in causes.h
...should we take care of them too ?
Quote RFC 3398
ISUP Cause value SIP response
---------------- ------------
1 unallocated number 404 Not Found
2 no route to network 404 Not found
3 no route to destination 404 Not found
16 normal call clearing --- (*)
17 user busy 486 Busy here
18 no user responding 408 Request Timeout
19 no answer from the user 480 Temporarily unavailable
20 subscriber absent 480 Temporarily unavailable
21 call rejected 403 Forbidden (+)
22 number changed (w/o diagnostic) 410 Gone
22 number changed (w/ diagnostic) 301 Moved Permanently
23 redirection to new destination 410 Gone
26 non-selected user clearing 404 Not Found (=)
27 destination out of order 502 Bad Gateway
28 address incomplete 484 Address incomplete
29 facility rejected 501 Not implemented
31 normal unspecified 480 Temporarily unavailable
Definition at line 6181 of file chan_sip.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CHAN_NOT_IMPLEMENTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_ROUTE_TRANSIT_NET, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL_UNSPECIFIED, AST_CAUSE_NOTDEFINED, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNALLOCATED, AST_CAUSE_UNREGISTERED, AST_CAUSE_USER_BUSY, and ast_debug.
Referenced by sip_hangup().
06182 { 06183 switch (cause) { 06184 case AST_CAUSE_UNALLOCATED: /* 1 */ 06185 case AST_CAUSE_NO_ROUTE_DESTINATION: /* 3 IAX2: Can't find extension in context */ 06186 case AST_CAUSE_NO_ROUTE_TRANSIT_NET: /* 2 */ 06187 return "404 Not Found"; 06188 case AST_CAUSE_CONGESTION: /* 34 */ 06189 case AST_CAUSE_SWITCH_CONGESTION: /* 42 */ 06190 return "503 Service Unavailable"; 06191 case AST_CAUSE_NO_USER_RESPONSE: /* 18 */ 06192 return "408 Request Timeout"; 06193 case AST_CAUSE_NO_ANSWER: /* 19 */ 06194 case AST_CAUSE_UNREGISTERED: /* 20 */ 06195 return "480 Temporarily unavailable"; 06196 case AST_CAUSE_CALL_REJECTED: /* 21 */ 06197 return "403 Forbidden"; 06198 case AST_CAUSE_NUMBER_CHANGED: /* 22 */ 06199 return "410 Gone"; 06200 case AST_CAUSE_NORMAL_UNSPECIFIED: /* 31 */ 06201 return "480 Temporarily unavailable"; 06202 case AST_CAUSE_INVALID_NUMBER_FORMAT: 06203 return "484 Address incomplete"; 06204 case AST_CAUSE_USER_BUSY: 06205 return "486 Busy here"; 06206 case AST_CAUSE_FAILURE: 06207 return "500 Server internal failure"; 06208 case AST_CAUSE_FACILITY_REJECTED: /* 29 */ 06209 return "501 Not Implemented"; 06210 case AST_CAUSE_CHAN_NOT_IMPLEMENTED: 06211 return "503 Service Unavailable"; 06212 /* Used in chan_iax2 */ 06213 case AST_CAUSE_DESTINATION_OUT_OF_ORDER: 06214 return "502 Bad Gateway"; 06215 case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL: /* Can't find codec to connect to host */ 06216 return "488 Not Acceptable Here"; 06217 06218 case AST_CAUSE_NOTDEFINED: 06219 default: 06220 ast_debug(1, "AST hangup cause %d (no match found in SIP)\n", cause); 06221 return NULL; 06222 } 06223 06224 /* Never reached */ 06225 return 0; 06226 }
| int hangup_sip2cause | ( | int | cause | ) |
Convert SIP hangup causes to Asterisk hangup causes.
Definition at line 6059 of file chan_sip.c.
References AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_BUSY, AST_CAUSE_CALL_REJECTED, AST_CAUSE_CONGESTION, AST_CAUSE_DESTINATION_OUT_OF_ORDER, AST_CAUSE_FACILITY_REJECTED, AST_CAUSE_FAILURE, AST_CAUSE_INTERWORKING, AST_CAUSE_INVALID_NUMBER_FORMAT, AST_CAUSE_NO_ANSWER, AST_CAUSE_NO_ROUTE_DESTINATION, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_NORMAL, AST_CAUSE_NORMAL_TEMPORARY_FAILURE, AST_CAUSE_NUMBER_CHANGED, AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE, AST_CAUSE_UNALLOCATED, and AST_CAUSE_USER_BUSY.
Referenced by __transmit_response(), handle_response(), and handle_response_invite().
06060 { 06061 /* Possible values taken from causes.h */ 06062 06063 switch(cause) { 06064 case 401: /* Unauthorized */ 06065 return AST_CAUSE_CALL_REJECTED; 06066 case 403: /* Not found */ 06067 return AST_CAUSE_CALL_REJECTED; 06068 case 404: /* Not found */ 06069 return AST_CAUSE_UNALLOCATED; 06070 case 405: /* Method not allowed */ 06071 return AST_CAUSE_INTERWORKING; 06072 case 407: /* Proxy authentication required */ 06073 return AST_CAUSE_CALL_REJECTED; 06074 case 408: /* No reaction */ 06075 return AST_CAUSE_NO_USER_RESPONSE; 06076 case 409: /* Conflict */ 06077 return AST_CAUSE_NORMAL_TEMPORARY_FAILURE; 06078 case 410: /* Gone */ 06079 return AST_CAUSE_NUMBER_CHANGED; 06080 case 411: /* Length required */ 06081 return AST_CAUSE_INTERWORKING; 06082 case 413: /* Request entity too large */ 06083 return AST_CAUSE_INTERWORKING; 06084 case 414: /* Request URI too large */ 06085 return AST_CAUSE_INTERWORKING; 06086 case 415: /* Unsupported media type */ 06087 return AST_CAUSE_INTERWORKING; 06088 case 420: /* Bad extension */ 06089 return AST_CAUSE_NO_ROUTE_DESTINATION; 06090 case 480: /* No answer */ 06091 return AST_CAUSE_NO_ANSWER; 06092 case 481: /* No answer */ 06093 return AST_CAUSE_INTERWORKING; 06094 case 482: /* Loop detected */ 06095 return AST_CAUSE_INTERWORKING; 06096 case 483: /* Too many hops */ 06097 return AST_CAUSE_NO_ANSWER; 06098 case 484: /* Address incomplete */ 06099 return AST_CAUSE_INVALID_NUMBER_FORMAT; 06100 case 485: /* Ambiguous */ 06101 return AST_CAUSE_UNALLOCATED; 06102 case 486: /* Busy everywhere */ 06103 return AST_CAUSE_BUSY; 06104 case 487: /* Request terminated */ 06105 return AST_CAUSE_INTERWORKING; 06106 case 488: /* No codecs approved */ 06107 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 06108 case 491: /* Request pending */ 06109 return AST_CAUSE_INTERWORKING; 06110 case 493: /* Undecipherable */ 06111 return AST_CAUSE_INTERWORKING; 06112 case 500: /* Server internal failure */ 06113 return AST_CAUSE_FAILURE; 06114 case 501: /* Call rejected */ 06115 return AST_CAUSE_FACILITY_REJECTED; 06116 case 502: 06117 return AST_CAUSE_DESTINATION_OUT_OF_ORDER; 06118 case 503: /* Service unavailable */ 06119 return AST_CAUSE_CONGESTION; 06120 case 504: /* Gateway timeout */ 06121 return AST_CAUSE_RECOVERY_ON_TIMER_EXPIRE; 06122 case 505: /* SIP version not supported */ 06123 return AST_CAUSE_INTERWORKING; 06124 case 600: /* Busy everywhere */ 06125 return AST_CAUSE_USER_BUSY; 06126 case 603: /* Decline */ 06127 return AST_CAUSE_CALL_REJECTED; 06128 case 604: /* Does not exist anywhere */ 06129 return AST_CAUSE_UNALLOCATED; 06130 case 606: /* Not acceptable */ 06131 return AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 06132 default: 06133 if (cause < 500 && cause >= 400) { 06134 /* 4xx class error that is unknown - someting wrong with our request */ 06135 return AST_CAUSE_INTERWORKING; 06136 } else if (cause < 600 && cause >= 500) { 06137 /* 5xx class error - problem in the remote end */ 06138 return AST_CAUSE_CONGESTION; 06139 } else if (cause < 700 && cause >= 600) { 06140 /* 6xx - global errors in the 4xx class */ 06141 return AST_CAUSE_INTERWORKING; 06142 } 06143 return AST_CAUSE_NORMAL; 06144 } 06145 /* Never reached */ 06146 return 0; 06147 }
| static int init_req | ( | struct sip_request * | req, | |
| int | sipmethod, | |||
| const char * | recip | |||
| ) | [static] |
Initialize SIP request.
Definition at line 10187 of file chan_sip.c.
References ast_free, ast_str_create(), ast_str_set(), sip_methods, and cfsip_methods::text.
Referenced by initreqprep(), reqprep(), and transmit_register().
10188 { 10189 /* Initialize a request */ 10190 memset(req, 0, sizeof(*req)); 10191 if (!(req->data = ast_str_create(SIP_MIN_PACKET))) 10192 goto e_return; 10193 if (!(req->content = ast_str_create(SIP_MIN_PACKET))) 10194 goto e_free_data; 10195 req->method = sipmethod; 10196 req->header[0] = 0; 10197 ast_str_set(&req->data, 0, "%s %s SIP/2.0\r\n", sip_methods[sipmethod].text, recip); 10198 req->headers++; 10199 return 0; 10200 10201 e_free_data: 10202 ast_free(req->data); 10203 req->data = NULL; 10204 e_return: 10205 return -1; 10206 }
| static int init_resp | ( | struct sip_request * | resp, | |
| const char * | msg | |||
| ) | [static] |
Initialize SIP response, based on SIP request.
Definition at line 10165 of file chan_sip.c.
References ast_free, ast_str_create(), and ast_str_set().
Referenced by respprep().
10166 { 10167 /* Initialize a response */ 10168 memset(resp, 0, sizeof(*resp)); 10169 resp->method = SIP_RESPONSE; 10170 if (!(resp->data = ast_str_create(SIP_MIN_PACKET))) 10171 goto e_return; 10172 if (!(resp->content = ast_str_create(SIP_MIN_PACKET))) 10173 goto e_free_data; 10174 resp->header[0] = 0; 10175 ast_str_set(&resp->data, 0, "SIP/2.0 %s\r\n", msg); 10176 resp->headers++; 10177 return 0; 10178 10179 e_free_data: 10180 ast_free(resp->data); 10181 resp->data = NULL; 10182 e_return: 10183 return -1; 10184 }
| static int initialize_escs | ( | void | ) | [static] |
Definition at line 1067 of file chan_sip.c.
References ao2_container_alloc, ARRAY_LEN, esc_cmp_fn(), esc_hash_fn(), and event_state_compositors.
Referenced by load_module().
01068 { 01069 int i, res = 0; 01070 for (i = 0; i < ARRAY_LEN(event_state_compositors); i++) { 01071 if (!((event_state_compositors[i].compositor) = 01072 ao2_container_alloc(ESC_MAX_BUCKETS, esc_hash_fn, esc_cmp_fn))) { 01073 res = -1; 01074 } 01075 } 01076 return res; 01077 }
| static void initialize_initreq | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Initialize the initital request packet in the pvt structure. This packet is used for creating replies and future requests in a dialog.
Definition at line 3070 of file chan_sip.c.
References ast_debug, ast_verbose, copy_request(), parse_request(), sip_methods, and cfsip_methods::text.
Referenced by transmit_invite(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_register(), transmit_reinvite_with_sdp(), and update_connectedline().
03071 { 03072 if (p->initreq.headers) { 03073 ast_debug(1, "Initializing already initialized SIP dialog %s (presumably reinvite)\n", p->callid); 03074 } else { 03075 ast_debug(1, "Initializing initreq for method %s - callid %s\n", sip_methods[req->method].text, p->callid); 03076 } 03077 /* Use this as the basis */ 03078 copy_request(&p->initreq, req); 03079 parse_request(&p->initreq); 03080 if (req->debug) { 03081 ast_verbose("Initreq: %d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 03082 } 03083 }
| static int initialize_udptl | ( | struct sip_pvt * | p | ) | [static] |
Definition at line 6809 of file chan_sip.c.
References ast_channel_set_fd(), ast_clear_flag, ast_debug, ast_log(), AST_LOG_WARNING, ast_test_flag, ast_udptl_fd(), ast_udptl_new_with_bindaddr(), ast_udptl_setnat(), ast_udptl_setqos(), bindaddr, and set_t38_capabilities().
Referenced by process_sdp(), process_sdp_a_image(), and sip_indicate().
06810 { 06811 int natflags = ast_test_flag(&p->flags[1], SIP_PAGE2_SYMMETRICRTP); 06812 06813 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) { 06814 return 1; 06815 } 06816 06817 /* If we've already initialized T38, don't take any further action */ 06818 if (p->udptl) { 06819 return 0; 06820 } 06821 06822 /* T38 can be supported by this dialog, create it and set the derived properties */ 06823 if ((p->udptl = ast_udptl_new_with_bindaddr(sched, io, 0, &bindaddr))) { 06824 if (p->owner) { 06825 ast_channel_set_fd(p->owner, 5, ast_udptl_fd(p->udptl)); 06826 } 06827 06828 ast_udptl_setqos(p->udptl, global_tos_audio, global_cos_audio); 06829 p->t38_maxdatagram = p->relatedpeer ? p->relatedpeer->t38_maxdatagram : global_t38_maxdatagram; 06830 set_t38_capabilities(p); 06831 06832 ast_debug(1, "Setting NAT on UDPTL to %s\n", natflags ? "On" : "Off"); 06833 ast_udptl_setnat(p->udptl, natflags); 06834 } else { 06835 ast_log(AST_LOG_WARNING, "UDPTL creation failed - disabling T38 for this dialog\n"); 06836 ast_clear_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT); 06837 return 1; 06838 } 06839 06840 return 0; 06841 }
| static void initreqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod, | |||
| const char *const | explicit_uri | |||
| ) | [static] |
Initiate new SIP request to peer/user.
Definition at line 11972 of file chan_sip.c.
References add_header(), add_header_max_forwards(), add_route(), AST_DIGIT_ANYNUM, ast_escape_quoted(), ast_party_id_presentation(), AST_PRES_ALLOWED, AST_PRES_RESTRICTION, ast_sockaddr_port, ast_sockaddr_stringify_host_remote(), ast_str_alloca, ast_str_append(), ast_str_set(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_encode(), build_contact(), exten, init_req(), ourport, S_OR, sip_cfg, sip_methods, sip_standard_port(), and cfsip_methods::text.
Referenced by transmit_invite(), and transmit_notify_with_mwi().
11973 { 11974 struct ast_str *invite = ast_str_alloca(256); 11975 char from[256]; 11976 char to[256]; 11977 char tmp_n[SIPBUFSIZE/2]; /* build a local copy of 'n' if needed */ 11978 char tmp_l[SIPBUFSIZE/2]; /* build a local copy of 'l' if needed */ 11979 const char *l = NULL; /* XXX what is this, exactly ? */ 11980 const char *n = NULL; /* XXX what is this, exactly ? */ 11981 const char *d = NULL; /* domain in from header */ 11982 const char *urioptions = ""; 11983 int ourport; 11984 11985 if (ast_test_flag(&p->flags[0], SIP_USEREQPHONE)) { 11986 const char *s = p->username; /* being a string field, cannot be NULL */ 11987 11988 /* Test p->username against allowed characters in AST_DIGIT_ANY 11989 If it matches the allowed characters list, then sipuser = ";user=phone" 11990 If not, then sipuser = "" 11991 */ 11992 /* + is allowed in first position in a tel: uri */ 11993 if (*s == '+') 11994 s++; 11995 for (; *s; s++) { 11996 if (!strchr(AST_DIGIT_ANYNUM, *s) ) 11997 break; 11998 } 11999 /* If we have only digits, add ;user=phone to the uri */ 12000 if (!*s) 12001 urioptions = ";user=phone"; 12002 } 12003 12004 12005 snprintf(p->lastmsg, sizeof(p->lastmsg), "Init: %s", sip_methods[sipmethod].text); 12006 12007 d = S_OR(p->fromdomain, ast_sockaddr_stringify_host_remote(&p->ourip)); 12008 if (p->owner) { 12009 if ((ast_party_id_presentation(&p->owner->connected.id) & AST_PRES_RESTRICTION) == AST_PRES_ALLOWED) { 12010 l = p->owner->connected.id.number.valid ? p->owner->connected.id.number.str : NULL; 12011 n = p->owner->connected.id.name.valid ? p->owner->connected.id.name.str : NULL; 12012 } else { 12013 /* Even if we are using RPID, we shouldn't leak information in the From if the user wants 12014 * their callerid restricted */ 12015 l = CALLERID_UNKNOWN; 12016 n = l; 12017 d = FROMDOMAIN_INVALID; 12018 } 12019 } 12020 12021 /* Hey, it's a NOTIFY! See if they've configured a mwi_from. 12022 * XXX Right now, this logic works because the only place that mwi_from 12023 * is set on the sip_pvt is in sip_send_mwi_to_peer. If things changed, then 12024 * we might end up putting the mwi_from setting into other types of NOTIFY 12025 * messages as well. 12026 */ 12027 if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->mwi_from)) { 12028 l = p->mwi_from; 12029 } 12030 12031 if (ast_strlen_zero(l)) 12032 l = default_callerid; 12033 if (ast_strlen_zero(n)) 12034 n = l; 12035 /* Allow user to be overridden */ 12036 if (!ast_strlen_zero(p->fromuser)) 12037 l = p->fromuser; 12038 else /* Save for any further attempts */ 12039 ast_string_field_set(p, fromuser, l); 12040 12041 /* Allow user to be overridden */ 12042 if (!ast_strlen_zero(p->fromname)) 12043 n = p->fromname; 12044 else /* Save for any further attempts */ 12045 ast_string_field_set(p, fromname, n); 12046 12047 if (sip_cfg.pedanticsipchecking) { 12048 ast_escape_quoted(n, tmp_n, sizeof(tmp_n)); 12049 n = tmp_n; 12050 ast_uri_encode(l, tmp_l, sizeof(tmp_l), 0); 12051 l = tmp_l; 12052 } 12053 12054 ourport = (p->fromdomainport) ? p->fromdomainport : ast_sockaddr_port(&p->ourip); 12055 if (!sip_standard_port(p->socket.type, ourport)) { 12056 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s:%d>;tag=%s", n, l, d, ourport, p->tag); 12057 } else { 12058 snprintf(from, sizeof(from), "\"%s\" <sip:%s@%s>;tag=%s", n, l, d, p->tag); 12059 } 12060 12061 if (!ast_strlen_zero(explicit_uri)) { 12062 ast_str_set(&invite, 0, "%s", explicit_uri); 12063 } else { 12064 /* If we're calling a registered SIP peer, use the fullcontact to dial to the peer */ 12065 if (!ast_strlen_zero(p->fullcontact)) { 12066 /* If we have full contact, trust it */ 12067 ast_str_append(&invite, 0, "%s", p->fullcontact); 12068 } else { 12069 /* Otherwise, use the username while waiting for registration */ 12070 ast_str_append(&invite, 0, "sip:"); 12071 if (!ast_strlen_zero(p->username)) { 12072 n = p->username; 12073 if (sip_cfg.pedanticsipchecking) { 12074 ast_uri_encode(n, tmp_n, sizeof(tmp_n), 0); 12075 n = tmp_n; 12076 } 12077 ast_str_append(&invite, 0, "%s@", n); 12078 } 12079 ast_str_append(&invite, 0, "%s", p->tohost); 12080 if (p->portinuri) { 12081 ast_str_append(&invite, 0, ":%d", ast_sockaddr_port(&p->sa)); 12082 } 12083 ast_str_append(&invite, 0, "%s", urioptions); 12084 } 12085 } 12086 12087 /* If custom URI options have been provided, append them */ 12088 if (p->options && !ast_strlen_zero(p->options->uri_options)) 12089 ast_str_append(&invite, 0, ";%s", p->options->uri_options); 12090 12091 /* This is the request URI, which is the next hop of the call 12092 which may or may not be the destination of the call 12093 */ 12094 ast_string_field_set(p, uri, invite->str); 12095 12096 if (!ast_strlen_zero(p->todnid)) { 12097 /*! \todo Need to add back the VXML URL here at some point, possibly use build_string for all this junk */ 12098 if (!strchr(p->todnid, '@')) { 12099 /* We have no domain in the dnid */ 12100 snprintf(to, sizeof(to), "<sip:%s@%s>%s%s", p->todnid, p->tohost, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag); 12101 } else { 12102 snprintf(to, sizeof(to), "<sip:%s>%s%s", p->todnid, ast_strlen_zero(p->theirtag) ? "" : ";tag=", p->theirtag); 12103 } 12104 } else { 12105 if (sipmethod == SIP_NOTIFY && !ast_strlen_zero(p->theirtag)) { 12106 /* If this is a NOTIFY, use the From: tag in the subscribe (RFC 3265) */ 12107 snprintf(to, sizeof(to), "<%s%s>;tag=%s", (strncasecmp(p->uri, "sip:", 4) ? "sip:" : ""), p->uri, p->theirtag); 12108 } else if (p->options && p->options->vxml_url) { 12109 /* If there is a VXML URL append it to the SIP URL */ 12110 snprintf(to, sizeof(to), "<%s>;%s", p->uri, p->options->vxml_url); 12111 } else { 12112 snprintf(to, sizeof(to), "<%s>", p->uri); 12113 } 12114 } 12115 12116 init_req(req, sipmethod, p->uri); 12117 /* now tmp_n is available so reuse it to build the CSeq */ 12118 snprintf(tmp_n, sizeof(tmp_n), "%u %s", ++p->ocseq, sip_methods[sipmethod].text); 12119 12120 add_header(req, "Via", p->via); 12121 add_header_max_forwards(p, req); 12122 /* This will be a no-op most of the time. However, under certain circumstances, 12123 * NOTIFY messages will use this function for preparing the request and should 12124 * have Route headers present. 12125 */ 12126 add_route(req, p->route); 12127 12128 add_header(req, "From", from); 12129 add_header(req, "To", to); 12130 ast_string_field_set(p, exten, l); 12131 build_contact(p); 12132 add_header(req, "Contact", p->our_contact); 12133 add_header(req, "Call-ID", p->callid); 12134 add_header(req, "CSeq", tmp_n); 12135 if (!ast_strlen_zero(global_useragent)) { 12136 add_header(req, "User-Agent", global_useragent); 12137 } 12138 }
| static const char * insecure2str | ( | int | mode | ) | [static] |
Convert Insecure setting to printable string.
Definition at line 17044 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer().
17045 { 17046 return map_x_s(insecurestr, mode, "<error>"); 17047 }
| static int interpret_t38_parameters | ( | struct sip_pvt * | p, | |
| const struct ast_control_t38_parameters * | parameters | |||
| ) | [static] |
Helper function which updates T.38 capability information and triggers a reinvite.
Definition at line 6717 of file chan_sip.c.
References AST_CONTROL_T38_PARAMETERS, ast_queue_control_data(), AST_SCHED_DEL_UNREF, ast_set_flag, AST_T38_NEGOTIATED, AST_T38_REFUSED, AST_T38_REQUEST_NEGOTIATE, AST_T38_REQUEST_PARMS, AST_T38_REQUEST_TERMINATE, AST_T38_TERMINATED, ast_test_flag, ast_udptl_get_far_max_ifp(), ast_udptl_set_local_max_ifp(), change_t38_state(), FALSE, ast_control_t38_parameters::fill_bit_removal, ast_control_t38_parameters::max_ifp, MIN, ast_control_t38_parameters::request_response, transmit_reinvite_with_sdp(), transmit_response_reliable(), transmit_response_with_t38_sdp(), and TRUE.
Referenced by sip_indicate().
06718 { 06719 int res = 0; 06720 06721 if (!ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) || !p->udptl) { 06722 return -1; 06723 } 06724 switch (parameters->request_response) { 06725 case AST_T38_NEGOTIATED: 06726 case AST_T38_REQUEST_NEGOTIATE: /* Request T38 */ 06727 /* Negotiation can not take place without a valid max_ifp value. */ 06728 if (!parameters->max_ifp) { 06729 change_t38_state(p, T38_DISABLED); 06730 if (p->t38.state == T38_PEER_REINVITE) { 06731 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06732 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 06733 } 06734 break; 06735 } else if (p->t38.state == T38_PEER_REINVITE) { 06736 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06737 p->t38.our_parms = *parameters; 06738 /* modify our parameters to conform to the peer's parameters, 06739 * based on the rules in the ITU T.38 recommendation 06740 */ 06741 if (!p->t38.their_parms.fill_bit_removal) { 06742 p->t38.our_parms.fill_bit_removal = FALSE; 06743 } 06744 if (!p->t38.their_parms.transcoding_mmr) { 06745 p->t38.our_parms.transcoding_mmr = FALSE; 06746 } 06747 if (!p->t38.their_parms.transcoding_jbig) { 06748 p->t38.our_parms.transcoding_jbig = FALSE; 06749 } 06750 p->t38.our_parms.version = MIN(p->t38.our_parms.version, p->t38.their_parms.version); 06751 p->t38.our_parms.rate_management = p->t38.their_parms.rate_management; 06752 ast_udptl_set_local_max_ifp(p->udptl, p->t38.our_parms.max_ifp); 06753 change_t38_state(p, T38_ENABLED); 06754 transmit_response_with_t38_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL); 06755 } else if (p->t38.state != T38_ENABLED) { 06756 p->t38.our_parms = *parameters; 06757 ast_udptl_set_local_max_ifp(p->udptl, p->t38.our_parms.max_ifp); 06758 change_t38_state(p, T38_LOCAL_REINVITE); 06759 if (!p->pendinginvite) { 06760 transmit_reinvite_with_sdp(p, TRUE, FALSE); 06761 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 06762 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 06763 } 06764 } 06765 break; 06766 case AST_T38_TERMINATED: 06767 case AST_T38_REFUSED: 06768 case AST_T38_REQUEST_TERMINATE: /* Shutdown T38 */ 06769 if (p->t38.state == T38_PEER_REINVITE) { 06770 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06771 change_t38_state(p, T38_DISABLED); 06772 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 06773 } else if (p->t38.state == T38_ENABLED) 06774 transmit_reinvite_with_sdp(p, FALSE, FALSE); 06775 break; 06776 case AST_T38_REQUEST_PARMS: { /* Application wants remote's parameters re-sent */ 06777 struct ast_control_t38_parameters parameters = p->t38.their_parms; 06778 06779 if (p->t38.state == T38_PEER_REINVITE) { 06780 AST_SCHED_DEL_UNREF(sched, p->t38id, dialog_unref(p, "when you delete the t38id sched, you should dec the refcount for the stored dialog ptr")); 06781 parameters.max_ifp = ast_udptl_get_far_max_ifp(p->udptl); 06782 parameters.request_response = AST_T38_REQUEST_NEGOTIATE; 06783 ast_queue_control_data(p->owner, AST_CONTROL_T38_PARAMETERS, ¶meters, sizeof(parameters)); 06784 /* we need to return a positive value here, so that applications that 06785 * send this request can determine conclusively whether it was accepted or not... 06786 * older versions of chan_sip would just silently accept it and return zero. 06787 */ 06788 res = AST_T38_REQUEST_PARMS; 06789 } 06790 break; 06791 } 06792 default: 06793 res = -1; 06794 break; 06795 } 06796 06797 return res; 06798 }
| static int is_method_allowed | ( | unsigned int * | allowed_methods, | |
| enum sipmethod | method | |||
| ) | [static] |
Check if method is allowed for a device or a dialog.
Definition at line 8353 of file chan_sip.c.
Referenced by sip_sendtext(), and update_connectedline().
| static void list_route | ( | struct sip_route * | route | ) | [static] |
List all routes - mostly for debugging.
Definition at line 14244 of file chan_sip.c.
References ast_verbose.
Referenced by build_route().
14245 { 14246 if (!route) { 14247 ast_verbose("list_route: no route\n"); 14248 } else { 14249 for (;route; route = route->next) 14250 ast_verbose("list_route: hop: <%s>\n", route->hop); 14251 } 14252 }
| static int load_module | ( | void | ) | [static] |
PBX load module - initialization.
Definition at line 30582 of file chan_sip.c.
References ao2_container_alloc, ao2_t_container_alloc, ARRAY_LEN, ast_cc_agent_register(), ast_cc_monitor_register(), ast_channel_register(), ast_check_realtime(), ast_cli_register_multiple(), ast_custom_function_register, ast_data_register_multiple, ast_log(), ast_manager_register_xml, AST_MODULE_LOAD_DECLINE, AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_SUCCESS, ast_realtime_require_field(), ast_register_application_xml, ast_rtp_glue_register, AST_TEST_REGISTER, ast_udptl_proto_register(), ast_verbose, ASTOBJ_CONTAINER_INIT, CHANNEL_MODULE_LOAD, dialog_cmp_cb(), dialog_hash_cb(), EVENT_FLAG_REPORTING, EVENT_FLAG_SYSTEM, initialize_escs(), io_context_create(), io_context_destroy(), LOG_ERROR, manager_show_registry(), manager_sip_qualify_peer(), manager_sip_show_peer(), manager_sip_show_peers(), manager_sipnotify(), network_change_event_subscribe(), peer_cmp_cb(), peer_hash_cb(), peer_ipcmp_cb(), peer_iphash_cb(), regl, reload_config(), restart_monitor(), RQ_CHAR, RQ_INTEGER4, RQ_UINTEGER2, sched_context_create(), sched_context_destroy(), ast_channel_tech::send_digit_begin, SENTINEL, sip_addheader(), sip_dtmfmode(), sip_epa_register(), sip_is_xml_parsable(), sip_monitor_instance_cmp_fn(), sip_monitor_instance_hash_fn(), sip_poke_all_peers(), sip_register_tests(), sip_removeheader(), sip_reqresp_parser_init(), sip_send_all_mwi_subscriptions(), sip_send_all_registers(), sip_tech_info, submwil, threadt_cmp_cb(), and threadt_hash_cb().
30583 { 30584 ast_verbose("SIP channel loading...\n"); 30585 30586 /* the fact that ao2_containers can't resize automatically is a major worry! */ 30587 /* if the number of objects gets above MAX_XXX_BUCKETS, things will slow down */ 30588 peers = ao2_t_container_alloc(HASH_PEER_SIZE, peer_hash_cb, peer_cmp_cb, "allocate peers"); 30589 peers_by_ip = ao2_t_container_alloc(HASH_PEER_SIZE, peer_iphash_cb, peer_ipcmp_cb, "allocate peers_by_ip"); 30590 dialogs = ao2_t_container_alloc(HASH_DIALOG_SIZE, dialog_hash_cb, dialog_cmp_cb, "allocate dialogs"); 30591 dialogs_to_destroy = ao2_t_container_alloc(1, NULL, NULL, "allocate dialogs_to_destroy"); 30592 threadt = ao2_t_container_alloc(HASH_DIALOG_SIZE, threadt_hash_cb, threadt_cmp_cb, "allocate threadt table"); 30593 if (!peers || !peers_by_ip || !dialogs || !dialogs_to_destroy || !threadt) { 30594 ast_log(LOG_ERROR, "Unable to create primary SIP container(s)\n"); 30595 return AST_MODULE_LOAD_FAILURE; 30596 } 30597 30598 ASTOBJ_CONTAINER_INIT(®l); /* Registry object list -- not searched for anything */ 30599 ASTOBJ_CONTAINER_INIT(&submwil); /* MWI subscription object list */ 30600 30601 if (!(sched = sched_context_create())) { 30602 ast_log(LOG_ERROR, "Unable to create scheduler context\n"); 30603 return AST_MODULE_LOAD_FAILURE; 30604 } 30605 30606 if (!(io = io_context_create())) { 30607 ast_log(LOG_ERROR, "Unable to create I/O context\n"); 30608 sched_context_destroy(sched); 30609 return AST_MODULE_LOAD_FAILURE; 30610 } 30611 30612 sip_reloadreason = CHANNEL_MODULE_LOAD; 30613 30614 can_parse_xml = sip_is_xml_parsable(); 30615 if (reload_config(sip_reloadreason)) { /* Load the configuration from sip.conf */ 30616 return AST_MODULE_LOAD_DECLINE; 30617 } 30618 30619 /* Prepare the version that does not require DTMF BEGIN frames. 30620 * We need to use tricks such as memcpy and casts because the variable 30621 * has const fields. 30622 */ 30623 memcpy(&sip_tech_info, &sip_tech, sizeof(sip_tech)); 30624 memset((void *) &sip_tech_info.send_digit_begin, 0, sizeof(sip_tech_info.send_digit_begin)); 30625 30626 /* Make sure we can register our sip channel type */ 30627 if (ast_channel_register(&sip_tech)) { 30628 ast_log(LOG_ERROR, "Unable to register channel type 'SIP'\n"); 30629 io_context_destroy(io); 30630 sched_context_destroy(sched); 30631 return AST_MODULE_LOAD_FAILURE; 30632 } 30633 30634 #ifdef TEST_FRAMEWORK 30635 AST_TEST_REGISTER(test_sip_peers_get); 30636 AST_TEST_REGISTER(test_sip_mwi_subscribe_parse); 30637 #endif 30638 30639 /* Register AstData providers */ 30640 ast_data_register_multiple(sip_data_providers, ARRAY_LEN(sip_data_providers)); 30641 30642 /* Register all CLI functions for SIP */ 30643 ast_cli_register_multiple(cli_sip, ARRAY_LEN(cli_sip)); 30644 30645 /* Tell the UDPTL subdriver that we're here */ 30646 ast_udptl_proto_register(&sip_udptl); 30647 30648 /* Tell the RTP engine about our RTP glue */ 30649 ast_rtp_glue_register(&sip_rtp_glue); 30650 30651 /* Register dialplan applications */ 30652 ast_register_application_xml(app_dtmfmode, sip_dtmfmode); 30653 ast_register_application_xml(app_sipaddheader, sip_addheader); 30654 ast_register_application_xml(app_sipremoveheader, sip_removeheader); 30655 30656 /* Register dialplan functions */ 30657 ast_custom_function_register(&sip_header_function); 30658 ast_custom_function_register(&sippeer_function); 30659 ast_custom_function_register(&sipchaninfo_function); 30660 ast_custom_function_register(&checksipdomain_function); 30661 30662 /* Register manager commands */ 30663 ast_manager_register_xml("SIPpeers", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_show_peers); 30664 ast_manager_register_xml("SIPshowpeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_show_peer); 30665 ast_manager_register_xml("SIPqualifypeer", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_sip_qualify_peer); 30666 ast_manager_register_xml("SIPshowregistry", EVENT_FLAG_SYSTEM | EVENT_FLAG_REPORTING, manager_show_registry); 30667 ast_manager_register_xml("SIPnotify", EVENT_FLAG_SYSTEM, manager_sipnotify); 30668 sip_poke_all_peers(); 30669 sip_send_all_registers(); 30670 sip_send_all_mwi_subscriptions(); 30671 initialize_escs(); 30672 30673 if (sip_epa_register(&cc_epa_static_data)) { 30674 return AST_MODULE_LOAD_DECLINE; 30675 } 30676 30677 if (sip_reqresp_parser_init() == -1) { 30678 ast_log(LOG_ERROR, "Unable to initialize the SIP request and response parser\n"); 30679 return AST_MODULE_LOAD_DECLINE; 30680 } 30681 30682 if (can_parse_xml) { 30683 /* SIP CC agents require the ability to parse XML PIDF bodies 30684 * in incoming PUBLISH requests 30685 */ 30686 if (ast_cc_agent_register(&sip_cc_agent_callbacks)) { 30687 return AST_MODULE_LOAD_DECLINE; 30688 } 30689 } 30690 if (ast_cc_monitor_register(&sip_cc_monitor_callbacks)) { 30691 return AST_MODULE_LOAD_DECLINE; 30692 } 30693 if (!(sip_monitor_instances = ao2_container_alloc(37, sip_monitor_instance_hash_fn, sip_monitor_instance_cmp_fn))) { 30694 return AST_MODULE_LOAD_DECLINE; 30695 } 30696 30697 /* And start the monitor for the first time */ 30698 restart_monitor(); 30699 30700 ast_realtime_require_field(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", 30701 "name", RQ_CHAR, 10, 30702 "ipaddr", RQ_CHAR, INET6_ADDRSTRLEN - 1, 30703 "port", RQ_UINTEGER2, 5, 30704 "regseconds", RQ_INTEGER4, 11, 30705 "defaultuser", RQ_CHAR, 10, 30706 "fullcontact", RQ_CHAR, 35, 30707 "regserver", RQ_CHAR, 20, 30708 "useragent", RQ_CHAR, 20, 30709 "lastms", RQ_INTEGER4, 11, 30710 SENTINEL); 30711 30712 30713 sip_register_tests(); 30714 network_change_event_subscribe(); 30715 30716 return AST_MODULE_LOAD_SUCCESS; 30717 }
| static int local_attended_transfer | ( | struct sip_pvt * | transferer, | |
| struct sip_dual * | current, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno, | |||
| int * | nounlock | |||
| ) | [static] |
Find all call legs and bridge transferee with target called from handle_request_refer.
If this function is successful, only the transferer pvt lock will remain on return. Setting nounlock indicates to handle_request_do() that the pvt's owner it locked does not require an unlock.
Definition at line 23221 of file chan_sip.c.
References ao2_t_ref, append_history, ast_bridged_channel(), AST_CEL_ATTENDEDTRANSFER, ast_cel_report_event(), ast_channel_queue_connected_line_update(), ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_clear_flag, ast_connected_line_build_data(), AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER, AST_CONTROL_READ_ACTION, AST_CONTROL_RINGING, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_do_masquerade(), AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO, ast_indicate(), ast_manager_event_multichan, ast_party_connected_line_copy(), ast_party_connected_line_free(), ast_party_connected_line_init(), ast_queue_control_data(), ast_set_flag, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_streamfile(), ast_strlen_zero(), ast_waitstream(), attempt_transfer(), EVENT_FLAG_CALL, frame_size, get_sip_pvt_byid_locked(), pbx_builtin_getvar_helper(), sip_pvt_lock, sip_pvt_unlock, ast_party_connected_line::source, transmit_notify_with_sipfrag(), TRUE, and xfersound.
Referenced by handle_request_refer().
23222 { 23223 struct sip_dual target; /* Chan 1: Call from tranferer to Asterisk */ 23224 /* Chan 2: Call from Asterisk to target */ 23225 int res = 0; 23226 struct sip_pvt *targetcall_pvt; 23227 struct ast_party_connected_line connected_to_transferee; 23228 struct ast_party_connected_line connected_to_target; 23229 char transferer_linkedid[32]; 23230 struct ast_channel *chans[2]; 23231 23232 /* Check if the call ID of the replaces header does exist locally */ 23233 if (!(targetcall_pvt = get_sip_pvt_byid_locked(transferer->refer->replaces_callid, transferer->refer->replaces_callid_totag, 23234 transferer->refer->replaces_callid_fromtag))) { 23235 if (transferer->refer->localtransfer) { 23236 /* We did not find the refered call. Sorry, can't accept then */ 23237 /* Let's fake a response from someone else in order 23238 to follow the standard */ 23239 transmit_notify_with_sipfrag(transferer, seqno, "481 Call leg/transaction does not exist", TRUE); 23240 append_history(transferer, "Xfer", "Refer failed"); 23241 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 23242 transferer->refer->status = REFER_FAILED; 23243 return -1; 23244 } 23245 /* Fall through for remote transfers that we did not find locally */ 23246 ast_debug(3, "SIP attended transfer: Not our call - generating INVITE with replaces\n"); 23247 return 0; 23248 } 23249 23250 /* Ok, we can accept this transfer */ 23251 append_history(transferer, "Xfer", "Refer accepted"); 23252 if (!targetcall_pvt->owner) { /* No active channel */ 23253 ast_debug(4, "SIP attended transfer: Error: No owner of target call\n"); 23254 /* Cancel transfer */ 23255 transmit_notify_with_sipfrag(transferer, seqno, "503 Service Unavailable", TRUE); 23256 append_history(transferer, "Xfer", "Refer failed"); 23257 ast_clear_flag(&transferer->flags[0], SIP_GOTREFER); 23258 transferer->refer->status = REFER_FAILED; 23259 sip_pvt_unlock(targetcall_pvt); 23260 if (targetcall_pvt) 23261 ao2_t_ref(targetcall_pvt, -1, "Drop targetcall_pvt pointer"); 23262 return -1; 23263 } 23264 23265 /* We have a channel, find the bridge */ 23266 target.chan1 = targetcall_pvt->owner; /* Transferer to Asterisk */ 23267 target.chan2 = ast_bridged_channel(targetcall_pvt->owner); /* Asterisk to target */ 23268 23269 if (!target.chan2 || !(target.chan2->_state == AST_STATE_UP || target.chan2->_state == AST_STATE_RINGING) ) { 23270 /* Wrong state of new channel */ 23271 if (target.chan2) 23272 ast_debug(4, "SIP attended transfer: Error: Wrong state of target call: %s\n", ast_state2str(target.chan2->_state)); 23273 else if (target.chan1->_state != AST_STATE_RING) 23274 ast_debug(4, "SIP attended transfer: Error: No target channel\n"); 23275 else 23276 ast_debug(4, "SIP attended transfer: Attempting transfer in ringing state\n"); 23277 } 23278 23279 /* Transfer */ 23280 if (sipdebug) { 23281 if (current->chan2) /* We have two bridges */ 23282 ast_debug(4, "SIP attended transfer: trying to bridge %s and %s\n", target.chan1->name, current->chan2->name); 23283 else /* One bridge, propably transfer of IVR/voicemail etc */ 23284 ast_debug(4, "SIP attended transfer: trying to make %s take over (masq) %s\n", target.chan1->name, current->chan1->name); 23285 } 23286 23287 ast_set_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Delay hangup */ 23288 23289 ast_copy_string(transferer_linkedid, transferer->owner->linkedid, sizeof(transferer_linkedid)); 23290 23291 /* Perform the transfer */ 23292 chans[0] = transferer->owner; 23293 chans[1] = target.chan1; 23294 ast_manager_event_multichan(EVENT_FLAG_CALL, "Transfer", 2, chans, 23295 "TransferMethod: SIP\r\n" 23296 "TransferType: Attended\r\n" 23297 "Channel: %s\r\n" 23298 "Uniqueid: %s\r\n" 23299 "SIP-Callid: %s\r\n" 23300 "TargetChannel: %s\r\n" 23301 "TargetUniqueid: %s\r\n", 23302 transferer->owner->name, 23303 transferer->owner->uniqueid, 23304 transferer->callid, 23305 target.chan1->name, 23306 target.chan1->uniqueid); 23307 ast_party_connected_line_init(&connected_to_transferee); 23308 ast_party_connected_line_init(&connected_to_target); 23309 /* No need to lock current->chan1 here since it was locked in sipsock_read */ 23310 ast_party_connected_line_copy(&connected_to_transferee, ¤t->chan1->connected); 23311 /* No need to lock target.chan1 here since it was locked in get_sip_pvt_byid_locked */ 23312 ast_party_connected_line_copy(&connected_to_target, &target.chan1->connected); 23313 connected_to_target.source = connected_to_transferee.source = AST_CONNECTED_LINE_UPDATE_SOURCE_TRANSFER; 23314 res = attempt_transfer(current, &target); 23315 if (res) { 23316 /* Failed transfer */ 23317 transmit_notify_with_sipfrag(transferer, seqno, "486 Busy Here", TRUE); 23318 append_history(transferer, "Xfer", "Refer failed"); 23319 ast_clear_flag(&transferer->flags[0], SIP_DEFER_BYE_ON_TRANSFER); 23320 /* if transfer failed, go ahead and unlock targetcall_pvt and it's owner channel */ 23321 sip_pvt_unlock(targetcall_pvt); 23322 ast_channel_unlock(target.chan1); 23323 } else { 23324 /* Transfer succeeded! */ 23325 const char *xfersound = pbx_builtin_getvar_helper(target.chan1, "ATTENDED_TRANSFER_COMPLETE_SOUND"); 23326 23327 /* target.chan1 was locked in get_sip_pvt_byid_locked, do not unlock target.chan1 before this */ 23328 ast_cel_report_event(target.chan1, AST_CEL_ATTENDEDTRANSFER, NULL, transferer_linkedid, target.chan2); 23329 23330 /* Tell transferer that we're done. */ 23331 transmit_notify_with_sipfrag(transferer, seqno, "200 OK", TRUE); 23332 append_history(transferer, "Xfer", "Refer succeeded"); 23333 transferer->refer->status = REFER_200OK; 23334 if (target.chan2 && !ast_strlen_zero(xfersound) && ast_streamfile(target.chan2, xfersound, target.chan2->language) >= 0) { 23335 ast_waitstream(target.chan2, ""); 23336 } 23337 23338 /* By forcing the masquerade, we know that target.chan1 and target.chan2 are bridged. We then 23339 * can queue connected line updates where they need to go. 23340 * 23341 * before a masquerade, all channel and pvt locks must be unlocked. Any recursive 23342 * channel locks held before this function invalidates channel container locking order. 23343 * Since we are unlocking both the pvt (transferer) and its owner channel (current.chan1) 23344 * it is possible for current.chan1 to be destroyed in the pbx thread. To prevent this 23345 * we must give c a reference before any unlocking takes place. 23346 */ 23347 23348 ast_channel_ref(current->chan1); 23349 ast_channel_unlock(current->chan1); /* current.chan1 is p->owner before the masq, it was locked by socket_read()*/ 23350 ast_channel_unlock(target.chan1); 23351 *nounlock = 1; /* we just unlocked the dialog's channel and have no plans of locking it again. */ 23352 sip_pvt_unlock(targetcall_pvt); 23353 sip_pvt_unlock(transferer); 23354 23355 ast_do_masquerade(target.chan1); 23356 23357 ast_indicate(target.chan1, AST_CONTROL_UNHOLD); 23358 if (target.chan2) { 23359 ast_indicate(target.chan2, AST_CONTROL_UNHOLD); 23360 } 23361 23362 if (current->chan2 && current->chan2->_state == AST_STATE_RING) { 23363 ast_indicate(target.chan1, AST_CONTROL_RINGING); 23364 } 23365 23366 if (target.chan2) { 23367 ast_channel_queue_connected_line_update(target.chan1, &connected_to_transferee, NULL); 23368 ast_channel_queue_connected_line_update(target.chan2, &connected_to_target, NULL); 23369 } else { 23370 /* Since target.chan1 isn't actually connected to another channel, there is no way for us 23371 * to queue a frame so that its connected line status will be updated. 23372 * 23373 * Instead, we use the somewhat hackish approach of using a special control frame type that 23374 * instructs ast_read to perform a specific action. In this case, the frame we queue tells 23375 * ast_read to call the connected line interception macro configured for target.chan1. 23376 */ 23377 struct ast_control_read_action_payload *frame_payload; 23378 int payload_size; 23379 int frame_size; 23380 unsigned char connected_line_data[1024]; 23381 payload_size = ast_connected_line_build_data(connected_line_data, 23382 sizeof(connected_line_data), &connected_to_target, NULL); 23383 frame_size = payload_size + sizeof(*frame_payload); 23384 if (payload_size != -1 && (frame_payload = alloca(frame_size))) { 23385 frame_payload->payload_size = payload_size; 23386 memcpy(frame_payload->payload, connected_line_data, payload_size); 23387 frame_payload->action = AST_FRAME_READ_ACTION_CONNECTED_LINE_MACRO; 23388 ast_queue_control_data(target.chan1, AST_CONTROL_READ_ACTION, frame_payload, frame_size); 23389 } 23390 /* In addition to queueing the read action frame so that target.chan1's connected line info 23391 * will be updated, we also are going to queue a plain old connected line update on target.chan1. This 23392 * way, either Dial or Queue can apply this connected line update to the outgoing ringing channel. 23393 */ 23394 ast_channel_queue_connected_line_update(target.chan1, &connected_to_transferee, NULL); 23395 23396 } 23397 sip_pvt_lock(transferer); /* the transferer pvt is expected to remain locked on return */ 23398 23399 ast_channel_unref(current->chan1); 23400 } 23401 23402 /* at this point if the transfer is successful only the transferer pvt should be locked. */ 23403 ast_party_connected_line_free(&connected_to_target); 23404 ast_party_connected_line_free(&connected_to_transferee); 23405 if (targetcall_pvt) 23406 ao2_t_ref(targetcall_pvt, -1, "drop targetcall_pvt"); 23407 return 1; 23408 }
| static void lws2sws | ( | struct ast_str * | msgbuf | ) | [static] |
Parse multiline SIP headers into one header This is enabled if pedanticsipchecking is enabled.
Definition at line 8441 of file chan_sip.c.
References ast_str_strlen(), and len().
Referenced by handle_request_do().
08442 { 08443 char *msgbuf = data->str; 08444 int len = ast_str_strlen(data); 08445 int h = 0, t = 0; 08446 int lws = 0; 08447 08448 for (; h < len;) { 08449 /* Eliminate all CRs */ 08450 if (msgbuf[h] == '\r') { 08451 h++; 08452 continue; 08453 } 08454 /* Check for end-of-line */ 08455 if (msgbuf[h] == '\n') { 08456 /* Check for end-of-message */ 08457 if (h + 1 == len) 08458 break; 08459 /* Check for a continuation line */ 08460 if (msgbuf[h + 1] == ' ' || msgbuf[h + 1] == '\t') { 08461 /* Merge continuation line */ 08462 h++; 08463 continue; 08464 } 08465 /* Propagate LF and start new line */ 08466 msgbuf[t++] = msgbuf[h++]; 08467 lws = 0; 08468 continue; 08469 } 08470 if (msgbuf[h] == ' ' || msgbuf[h] == '\t') { 08471 if (lws) { 08472 h++; 08473 continue; 08474 } 08475 msgbuf[t++] = msgbuf[h++]; 08476 lws = 1; 08477 continue; 08478 } 08479 msgbuf[t++] = msgbuf[h++]; 08480 if (lws) 08481 lws = 0; 08482 } 08483 msgbuf[t] = '\0'; 08484 data->used = t; 08485 }
| static void make_our_tag | ( | struct sip_pvt * | pvt | ) | [static] |
Make our SIP dialog tag.
Definition at line 7636 of file chan_sip.c.
References ast_random(), and ast_string_field_build.
Referenced by handle_request_invite(), handle_request_subscribe(), sip_alloc(), transmit_register(), and transmit_response_using_temp().
07637 { 07638 ast_string_field_build(pvt, tag, "as%08lx", ast_random()); 07639 }
| static int manager_show_registry | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP registrations in the manager API.
Definition at line 16657 of file chan_sip.c.
References ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_listack(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, regl, regstate2str(), S_OR, and total.
Referenced by load_module().
16658 { 16659 const char *id = astman_get_header(m, "ActionID"); 16660 char idtext[256] = ""; 16661 int total = 0; 16662 16663 if (!ast_strlen_zero(id)) 16664 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 16665 16666 astman_send_listack(s, m, "Registrations will follow", "start"); 16667 16668 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 16669 ASTOBJ_RDLOCK(iterator); 16670 astman_append(s, 16671 "Event: RegistryEntry\r\n" 16672 "%s" 16673 "Host: %s\r\n" 16674 "Port: %d\r\n" 16675 "Username: %s\r\n" 16676 "Domain: %s\r\n" 16677 "DomainPort: %d\r\n" 16678 "Refresh: %d\r\n" 16679 "State: %s\r\n" 16680 "RegistrationTime: %ld\r\n" 16681 "\r\n", 16682 idtext, 16683 iterator->hostname, 16684 iterator->portno ? iterator->portno : STANDARD_SIP_PORT, 16685 iterator->username, 16686 S_OR(iterator->regdomain,iterator->hostname), 16687 iterator->regdomainport ? iterator->regdomainport : STANDARD_SIP_PORT, 16688 iterator->refresh, 16689 regstate2str(iterator->regstate), 16690 (long) iterator->regtime.tv_sec); 16691 ASTOBJ_UNLOCK(iterator); 16692 total++; 16693 } while(0)); 16694 16695 astman_append(s, 16696 "Event: RegistrationsComplete\r\n" 16697 "EventList: Complete\r\n" 16698 "ListItems: %d\r\n" 16699 "%s" 16700 "\r\n", total, idtext); 16701 16702 return 0; 16703 }
| static int manager_sip_qualify_peer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Qualify SIP peers in the manager API.
Definition at line 17439 of file chan_sip.c.
References _sip_qualify_peer(), ast_strlen_zero(), astman_append(), astman_get_header(), and astman_send_error().
Referenced by load_module().
17440 { 17441 const char *a[4]; 17442 const char *peer; 17443 17444 peer = astman_get_header(m, "Peer"); 17445 if (ast_strlen_zero(peer)) { 17446 astman_send_error(s, m, "Peer: <name> missing."); 17447 return 0; 17448 } 17449 a[0] = "sip"; 17450 a[1] = "qualify"; 17451 a[2] = "peer"; 17452 a[3] = peer; 17453 17454 _sip_qualify_peer(1, -1, s, m, 4, a); 17455 astman_append(s, "\r\n\r\n" ); 17456 return 0; 17457 }
| static int manager_sip_show_peer | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 17380 of file chan_sip.c.
References _sip_show_peer(), ast_strlen_zero(), astman_append(), astman_get_header(), and astman_send_error().
Referenced by load_module().
17381 { 17382 const char *a[4]; 17383 const char *peer; 17384 17385 peer = astman_get_header(m, "Peer"); 17386 if (ast_strlen_zero(peer)) { 17387 astman_send_error(s, m, "Peer: <name> missing."); 17388 return 0; 17389 } 17390 a[0] = "sip"; 17391 a[1] = "show"; 17392 a[2] = "peer"; 17393 a[3] = peer; 17394 17395 _sip_show_peer(1, -1, s, m, 4, a); 17396 astman_append(s, "\r\n" ); 17397 return 0; 17398 }
| static int manager_sip_show_peers | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Show SIP peers in the manager API.
Definition at line 16707 of file chan_sip.c.
References _sip_show_peers(), ast_strlen_zero(), astman_append(), astman_get_header(), astman_send_listack(), and total.
Referenced by load_module().
16708 { 16709 const char *id = astman_get_header(m, "ActionID"); 16710 const char *a[] = {"sip", "show", "peers"}; 16711 char idtext[256] = ""; 16712 int total = 0; 16713 16714 if (!ast_strlen_zero(id)) 16715 snprintf(idtext, sizeof(idtext), "ActionID: %s\r\n", id); 16716 16717 astman_send_listack(s, m, "Peer status list will follow", "start"); 16718 /* List the peers in separate manager events */ 16719 _sip_show_peers(-1, &total, s, m, 3, a); 16720 /* Send final confirmation */ 16721 astman_append(s, 16722 "Event: PeerlistComplete\r\n" 16723 "EventList: Complete\r\n" 16724 "ListItems: %d\r\n" 16725 "%s" 16726 "\r\n", total, idtext); 16727 return 0; 16728 }
| static int manager_sipnotify | ( | struct mansession * | s, | |
| const struct message * | m | |||
| ) | [static] |
Definition at line 12972 of file chan_sip.c.
References ast_log(), ast_set_flag, ast_str_append(), ast_str_strlen(), ast_strlen_zero(), ast_variable_new(), ast_variables_destroy(), astman_get_header(), astman_get_variables(), astman_send_ack(), astman_send_error(), create_addr(), dialog_unlink_all(), LOG_WARNING, ast_variable::name, ast_variable::next, sip_alloc(), sip_notify_allocate(), sip_scheddestroy(), transmit_invite(), ast_variable::value, and var.
Referenced by load_module().
12973 { 12974 const char *channame = astman_get_header(m, "Channel"); 12975 struct ast_variable *vars = astman_get_variables(m); 12976 struct sip_pvt *p; 12977 struct ast_variable *header, *var; 12978 12979 if (ast_strlen_zero(channame)) { 12980 astman_send_error(s, m, "SIPNotify requires a channel name"); 12981 return 0; 12982 } 12983 12984 if (!strncasecmp(channame, "sip/", 4)) { 12985 channame += 4; 12986 } 12987 12988 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) { 12989 astman_send_error(s, m, "Unable to build sip pvt data for notify (memory/socket error)"); 12990 return 0; 12991 } 12992 12993 if (create_addr(p, channame, NULL, 0, NULL)) { 12994 /* Maybe they're not registered, etc. */ 12995 dialog_unlink_all(p); 12996 dialog_unref(p, "unref dialog inside for loop" ); 12997 /* sip_destroy(p); */ 12998 astman_send_error(s, m, "Could not create address"); 12999 return 0; 13000 } 13001 13002 /* Notify is outgoing call */ 13003 ast_set_flag(&p->flags[0], SIP_OUTGOING); 13004 sip_notify_allocate(p); 13005 13006 p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", ""); 13007 13008 for (var = vars; var; var = var->next) { 13009 if (!strcasecmp(var->name, "Content")) { 13010 if (ast_str_strlen(p->notify->content)) 13011 ast_str_append(&p->notify->content, 0, "\r\n"); 13012 ast_str_append(&p->notify->content, 0, "%s", var->value); 13013 } else if (!strcasecmp(var->name, "Content-Length")) { 13014 ast_log(LOG_WARNING, "it is not necessary to specify Content-Length, ignoring\n"); 13015 } else { 13016 header->next = ast_variable_new(var->name, var->value, ""); 13017 header = header->next; 13018 } 13019 } 13020 13021 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); 13022 transmit_invite(p, SIP_NOTIFY, 0, 2, NULL); 13023 dialog_unref(p, "bump down the count of p since we're done with it."); 13024 13025 astman_send_ack(s, m, "Notify Sent"); 13026 ast_variables_destroy(vars); 13027 return 0; 13028 }
| static int map_s_x | ( | const struct _map_x_s * | table, | |
| const char * | s, | |||
| int | errorvalue | |||
| ) | [static] |
map from a string to an integer value, case insensitive. If no match is found, return errorvalue.
Definition at line 2263 of file chan_sip.c.
Referenced by str2dtmfmode(), str2stmode(), and str2strefresher().
02264 { 02265 const struct _map_x_s *cur; 02266 02267 for (cur = table; cur->s; cur++) 02268 if (!strcasecmp(cur->s, s)) 02269 return cur->x; 02270 return errorvalue; 02271 }
| static const char* map_x_s | ( | const struct _map_x_s * | table, | |
| int | x, | |||
| const char * | errorstring | |||
| ) | [static] |
map from an integer value to a string. If no match is found, return errorstring
Definition at line 2250 of file chan_sip.c.
Referenced by allowoverlap2str(), dtmfmode2str(), faxec2str(), insecure2str(), referstatus2str(), regstate2str(), stmode2str(), and strefresher2str().
02251 { 02252 const struct _map_x_s *cur; 02253 02254 for (cur = table; cur->s; cur++) 02255 if (cur->x == x) 02256 return cur->s; 02257 return errorstring; 02258 }
| static void mark_method_allowed | ( | unsigned int * | allowed_methods, | |
| enum sipmethod | method | |||
| ) | [static] |
Definition at line 8342 of file chan_sip.c.
Referenced by handle_response(), handle_response_info(), handle_response_message(), mark_parsed_methods(), and set_pvt_allowed_methods().
| static void mark_method_unallowed | ( | unsigned int * | allowed_methods, | |
| enum sipmethod | method | |||
| ) | [static] |
Definition at line 8347 of file chan_sip.c.
Referenced by handle_response(), handle_response_info(), handle_response_message(), and handle_response_publish().
| static void mark_parsed_methods | ( | unsigned int * | methods, | |
| char * | methods_str | |||
| ) | [static] |
Definition at line 8358 of file chan_sip.c.
References ast_skip_blanks(), ast_strlen_zero(), find_sip_method(), and mark_method_allowed().
Referenced by build_peer(), parse_allowed_methods(), and reload_config().
08359 { 08360 char *method; 08361 for (method = strsep(&methods_str, ","); !ast_strlen_zero(method); method = strsep(&methods_str, ",")) { 08362 int id = find_sip_method(ast_skip_blanks(method)); 08363 if (id == SIP_UNKNOWN) { 08364 continue; 08365 } 08366 mark_method_allowed(methods, id); 08367 } 08368 }
| static int match_and_cleanup_peer_sched | ( | void * | peerobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 2875 of file chan_sip.c.
References ast_dnsmgr_release(), CMP_MATCH, peer_sched_cleanup(), SIP_PEERS_ALL, and unref_peer().
Referenced by unlink_peers_from_tables().
02876 { 02877 struct sip_peer *peer = peerobj; 02878 peer_unlink_flag_t which = *(peer_unlink_flag_t *)arg; 02879 02880 if (which == SIP_PEERS_ALL || peer->the_mark) { 02881 peer_sched_cleanup(peer); 02882 if (peer->dnsmgr) { 02883 ast_dnsmgr_release(peer->dnsmgr); 02884 peer->dnsmgr = NULL; 02885 unref_peer(peer, "Release peer from dnsmgr"); 02886 } 02887 return CMP_MATCH; 02888 } 02889 return 0; 02890 }
| static enum match_req_res match_req_to_dialog | ( | struct sip_pvt * | sip_pvt_ptr, | |
| struct match_req_args * | arg | |||
| ) | [static] |
Definition at line 7882 of file chan_sip.c.
References ast_strlen_zero(), ast_test_flag, match_req_args::authentication_present, match_req_args::callid, match_req_args::fromtag, match_req_args::method, match_req_args::ruri, match_req_args::seqno, SIP_REQ_LOOP_DETECTED, SIP_REQ_MATCH, SIP_REQ_NOT_MATCH, sip_uri_cmp(), match_req_args::totag, match_req_args::viabranch, and match_req_args::viasentby.
Referenced by find_call().
07883 { 07884 const char *init_ruri = NULL; 07885 if (sip_pvt_ptr->initreq.headers) { 07886 init_ruri = REQ_OFFSET_TO_STR(&sip_pvt_ptr->initreq, rlPart2); 07887 } 07888 07889 /* 07890 * Match Tags and call-id to Dialog 07891 */ 07892 if (!ast_strlen_zero(arg->callid) && strcmp(sip_pvt_ptr->callid, arg->callid)) { 07893 /* call-id does not match. */ 07894 return SIP_REQ_NOT_MATCH; 07895 } 07896 if (arg->method == SIP_RESPONSE) { 07897 /* Verify totag if we have one stored for this dialog, but never be strict about this for 07898 * a response until the dialog is established */ 07899 if (!ast_strlen_zero(sip_pvt_ptr->theirtag) && ast_test_flag(&sip_pvt_ptr->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { 07900 if (ast_strlen_zero(arg->totag)) { 07901 /* missing totag when they already gave us one earlier */ 07902 return SIP_REQ_NOT_MATCH; 07903 } 07904 if (strcmp(arg->totag, sip_pvt_ptr->theirtag)) { 07905 /* The totag of the response does not match the one we have stored */ 07906 return SIP_REQ_NOT_MATCH; 07907 } 07908 } 07909 /* Verify fromtag of response matches the tag we gave them. */ 07910 if (strcmp(arg->fromtag, sip_pvt_ptr->tag)) { 07911 /* fromtag from response does not match our tag */ 07912 return SIP_REQ_NOT_MATCH; 07913 } 07914 } else { 07915 /* Verify the fromtag of Request matches the tag they provided earlier. 07916 * If this is a Request with authentication credentials, forget their old 07917 * tag as it is not valid after the 401 or 407 response. */ 07918 if (!arg->authentication_present && strcmp(arg->fromtag, sip_pvt_ptr->theirtag)) { 07919 /* their tag does not match the one was have stored for them */ 07920 return SIP_REQ_NOT_MATCH; 07921 } 07922 /* Verify if totag is present in Request, that it matches what we gave them as our tag earlier */ 07923 if (!ast_strlen_zero(arg->totag) && (strcmp(arg->totag, sip_pvt_ptr->tag))) { 07924 /* totag from Request does not match our tag */ 07925 return SIP_REQ_NOT_MATCH; 07926 } 07927 } 07928 07929 /* 07930 * Compare incoming request against initial transaction. 07931 * 07932 * This is a best effort attempt at distinguishing forked requests from 07933 * our initial transaction. If all the elements are NOT in place to evaluate 07934 * this, this block is ignored and the dialog match is made regardless. 07935 * Once the totag is established after the dialog is confirmed, this is not necessary. 07936 * 07937 * CRITERIA required for initial transaction matching. 07938 * 07939 * 1. Is a Request 07940 * 2. Callid and theirtag match (this is done in the dialog matching block) 07941 * 3. totag is NOT present 07942 * 4. CSeq matchs our initial transaction's cseq number 07943 * 5. pvt has init via branch parameter stored 07944 */ 07945 if ((arg->method != SIP_RESPONSE) && /* must be a Request */ 07946 ast_strlen_zero(arg->totag) && /* must not have a totag */ 07947 (sip_pvt_ptr->init_icseq == arg->seqno) && /* the cseq must be the same as this dialogs initial cseq */ 07948 !ast_strlen_zero(sip_pvt_ptr->initviabranch) && /* The dialog must have started with a RFC3261 compliant branch tag */ 07949 init_ruri) { /* the dialog must have an initial request uri associated with it */ 07950 /* This Request matches all the criteria required for Loop/Merge detection. 07951 * Now we must go down the path of comparing VIA's and RURIs. */ 07952 if (ast_strlen_zero(arg->viabranch) || 07953 strcmp(arg->viabranch, sip_pvt_ptr->initviabranch) || 07954 ast_strlen_zero(arg->viasentby) || 07955 strcmp(arg->viasentby, sip_pvt_ptr->initviasentby)) { 07956 /* At this point, this request does not match this Dialog.*/ 07957 07958 /* if methods are different this is just a mismatch */ 07959 if ((sip_pvt_ptr->method != arg->method)) { 07960 return SIP_REQ_NOT_MATCH; 07961 } 07962 07963 /* If RUIs are different, this is a forked request to a separate URI. 07964 * Returning a mismatch allows this Request to be processed separately. */ 07965 if (sip_uri_cmp(init_ruri, arg->ruri)) { 07966 /* not a match, request uris are different */ 07967 return SIP_REQ_NOT_MATCH; 07968 } 07969 07970 /* Loop/Merge Detected 07971 * 07972 * ---Current Matches to Initial Request--- 07973 * request uri 07974 * Call-id 07975 * their-tag 07976 * no totag present 07977 * method 07978 * cseq 07979 * 07980 * --- Does not Match Initial Request --- 07981 * Top Via 07982 * 07983 * Without the same Via, this can not match our initial transaction for this dialog, 07984 * but given that this Request matches everything else associated with that initial 07985 * Request this is most certainly a Forked request in which we have already received 07986 * part of the fork. 07987 */ 07988 return SIP_REQ_LOOP_DETECTED; 07989 } 07990 } /* end of Request Via check */ 07991 07992 /* Match Authentication Request. 07993 * 07994 * A Request with an Authentication header must come back with the 07995 * same Request URI. Otherwise it is not a match. 07996 */ 07997 if ((arg->method != SIP_RESPONSE) && /* Must be a Request type to even begin checking this */ 07998 ast_strlen_zero(arg->totag) && /* no totag is present to match */ 07999 arg->authentication_present && /* Authentication header is present in Request */ 08000 sip_uri_cmp(init_ruri, arg->ruri)) { /* Compare the Request URI of both the last Request and this new one */ 08001 08002 /* Authentication was provided, but the Request URI did not match the last one on this dialog. */ 08003 return SIP_REQ_NOT_MATCH; 08004 } 08005 08006 return SIP_REQ_MATCH; 08007 }
| static int method_match | ( | enum sipmethod | id, | |
| const char * | name | |||
| ) | [static] |
returns true if 'name' (with optional trailing whitespace) matches the sip method 'id'. Strictly speaking, SIP methods are case SENSITIVE, but we do a case-insensitive comparison to be more tolerant. following Jon Postel's rule: Be gentle in what you accept, strict with what you send
Definition at line 3157 of file chan_sip.c.
References len(), sip_methods, and text.
Referenced by __sip_autodestruct(), __sip_semi_ack(), and find_sip_method().
03158 { 03159 int len = strlen(sip_methods[id].text); 03160 int l_name = name ? strlen(name) : 0; 03161 /* true if the string is long enough, and ends with whitespace, and matches */ 03162 return (l_name >= len && name && name[len] < 33 && 03163 !strncasecmp(sip_methods[id].text, name, len)); 03164 }
| static void mwi_event_cb | ( | const struct ast_event * | event, | |
| void * | userdata | |||
| ) | [static] |
Receive MWI events that we have subscribed to.
Definition at line 14586 of file chan_sip.c.
References sip_send_mwi_to_peer().
Referenced by add_peer_mwi_subs().
14587 { 14588 struct sip_peer *peer = userdata; 14589 14590 sip_send_mwi_to_peer(peer, 0); 14591 }
| static void network_change_event_cb | ( | const struct ast_event * | event, | |
| void * | userdata | |||
| ) | [static] |
Definition at line 14616 of file chan_sip.c.
References ast_debug, ast_sched_add(), and network_change_event_sched_cb().
Referenced by network_change_event_subscribe().
14617 { 14618 ast_debug(1, "SIP, got a network change event, renewing all SIP registrations.\n"); 14619 if (network_change_event_sched_id == -1) { 14620 network_change_event_sched_id = ast_sched_add(sched, 1000, network_change_event_sched_cb, NULL); 14621 } 14622 }
| static int network_change_event_sched_cb | ( | const void * | data | ) | [static] |
Definition at line 14608 of file chan_sip.c.
References sip_send_all_mwi_subscriptions(), and sip_send_all_registers().
Referenced by network_change_event_cb().
14609 { 14610 network_change_event_sched_id = -1; 14611 sip_send_all_registers(); 14612 sip_send_all_mwi_subscriptions(); 14613 return 0; 14614 }
| static void network_change_event_subscribe | ( | void | ) | [static] |
Definition at line 14593 of file chan_sip.c.
References AST_EVENT_IE_END, AST_EVENT_NETWORK_CHANGE, ast_event_subscribe(), and network_change_event_cb().
Referenced by load_module(), and reload_config().
14594 { 14595 if (!network_change_event_subscription) { 14596 network_change_event_subscription = ast_event_subscribe(AST_EVENT_NETWORK_CHANGE, 14597 network_change_event_cb, "SIP Network Change", NULL, AST_EVENT_IE_END); 14598 } 14599 }
| static void network_change_event_unsubscribe | ( | void | ) | [static] |
Definition at line 14601 of file chan_sip.c.
References ast_event_unsubscribe().
Referenced by reload_config(), and unload_module().
14602 { 14603 if (network_change_event_subscription) { 14604 network_change_event_subscription = ast_event_unsubscribe(network_change_event_subscription); 14605 } 14606 }
| static struct sip_proxy* obproxy_get | ( | struct sip_pvt * | dialog, | |
| struct sip_peer * | peer | |||
| ) | [static, read] |
Get default outbound proxy or global proxy.
Definition at line 3129 of file chan_sip.c.
References append_history, ast_debug, and sip_cfg.
Referenced by __sip_subscribe_mwi_do(), create_addr(), create_addr_from_peer(), and transmit_register().
03130 { 03131 if (peer && peer->outboundproxy) { 03132 if (sipdebug) { 03133 ast_debug(1, "OBPROXY: Applying peer OBproxy to this call\n"); 03134 } 03135 append_history(dialog, "OBproxy", "Using peer obproxy %s", peer->outboundproxy->name); 03136 return peer->outboundproxy; 03137 } 03138 if (sip_cfg.outboundproxy.name[0]) { 03139 if (sipdebug) { 03140 ast_debug(1, "OBPROXY: Applying global OBproxy to this call\n"); 03141 } 03142 append_history(dialog, "OBproxy", "Using global obproxy %s", sip_cfg.outboundproxy.name); 03143 return &sip_cfg.outboundproxy; 03144 } 03145 if (sipdebug) { 03146 ast_debug(1, "OBPROXY: Not applying OBproxy to this call\n"); 03147 } 03148 return NULL; 03149 }
| static void on_dns_update_mwi | ( | struct ast_sockaddr * | old, | |
| struct ast_sockaddr * | new, | |||
| void * | data | |||
| ) | [static] |
Definition at line 12458 of file chan_sip.c.
References ast_debug, ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), and ast_strdupa.
Referenced by __sip_subscribe_mwi_do().
12459 { 12460 struct sip_subscription_mwi *mwi = data; 12461 const char *old_str; 12462 12463 /* This shouldn't happen, but just in case */ 12464 if (ast_sockaddr_isnull(new)) { 12465 ast_debug(1, "Empty sockaddr change...ignoring!\n"); 12466 return; 12467 } 12468 12469 old_str = ast_strdupa(ast_sockaddr_stringify(old)); 12470 ast_debug(1, "Changing mwi %s from %s to %s\n", mwi->hostname, old_str, ast_sockaddr_stringify(new)); 12471 ast_sockaddr_copy(&mwi->us, new); 12472 }
| static void on_dns_update_peer | ( | struct ast_sockaddr * | old, | |
| struct ast_sockaddr * | new, | |||
| void * | data | |||
| ) | [static] |
Definition at line 12429 of file chan_sip.c.
References ao2_link, ao2_lock, ao2_unlink, ao2_unlock, ast_debug, ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_strdupa, and default_sip_port().
Referenced by build_peer(), and transmit_register().
12430 { 12431 struct sip_peer *peer = data; 12432 const char *old_str; 12433 12434 /* This shouldn't happen, but just in case */ 12435 if (ast_sockaddr_isnull(new)) { 12436 ast_debug(1, "Empty sockaddr change...ignoring!\n"); 12437 return; 12438 } 12439 12440 if (!ast_sockaddr_isnull(&peer->addr)) { 12441 ao2_unlink(peers_by_ip, peer); 12442 } 12443 12444 if (!ast_sockaddr_port(new)) { 12445 ast_sockaddr_set_port(new, default_sip_port(peer->socket.type)); 12446 } 12447 12448 old_str = ast_strdupa(ast_sockaddr_stringify(old)); 12449 ast_debug(1, "Changing peer %s address from %s to %s\n", peer->name, old_str, ast_sockaddr_stringify(new)); 12450 12451 ao2_lock(peer); 12452 ast_sockaddr_copy(&peer->addr, new); 12453 ao2_unlock(peer); 12454 12455 ao2_link(peers_by_ip, peer); 12456 }
| static void on_dns_update_registry | ( | struct ast_sockaddr * | old, | |
| struct ast_sockaddr * | new, | |||
| void * | data | |||
| ) | [static] |
Definition at line 12408 of file chan_sip.c.
References ast_debug, ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_strdupa, and S_OR.
Referenced by transmit_register().
12409 { 12410 struct sip_registry *reg = data; 12411 const char *old_str; 12412 12413 /* This shouldn't happen, but just in case */ 12414 if (ast_sockaddr_isnull(new)) { 12415 ast_debug(1, "Empty sockaddr change...ignoring!\n"); 12416 return; 12417 } 12418 12419 if (!ast_sockaddr_port(new)) { 12420 ast_sockaddr_set_port(new, reg->portno); 12421 } 12422 12423 old_str = ast_strdupa(ast_sockaddr_stringify(old)); 12424 12425 ast_debug(1, "Changing registry %s from %s to %s\n", S_OR(reg->peername, reg->hostname), old_str, ast_sockaddr_stringify(new)); 12426 ast_sockaddr_copy(®->us, new); 12427 }
| static unsigned int parse_allowed_methods | ( | struct sip_request * | req | ) | [static] |
parse the Allow header to see what methods the endpoint we are communicating with allows.
We parse the allow header on incoming Registrations and save the result to the SIP peer that is registering. When the registration expires, we clear what we know about the peer's allowed methods. When the peer re-registers, we once again parse to see if the list of allowed methods has changed.
For peers that do not register, we parse the first message we receive during a call to see what is allowed, and save the information for the duration of the call.
| req | The SIP request we are parsing |
| The | methods allowed |
Definition at line 8385 of file chan_sip.c.
References ast_strdupa, ast_strip_quoted(), ast_strlen_zero(), get_header(), and mark_parsed_methods().
Referenced by set_pvt_allowed_methods().
08386 { 08387 char *allow = ast_strdupa(get_header(req, "Allow")); 08388 unsigned int allowed_methods = SIP_UNKNOWN; 08389 08390 if (ast_strlen_zero(allow)) { 08391 /* I have witnessed that REGISTER requests from Polycom phones do not 08392 * place the phone's allowed methods in an Allow header. Instead, they place the 08393 * allowed methods in a methods= parameter in the Contact header. 08394 */ 08395 char *contact = ast_strdupa(get_header(req, "Contact")); 08396 char *methods = strstr(contact, ";methods="); 08397 08398 if (ast_strlen_zero(methods)) { 08399 /* RFC 3261 states: 08400 * 08401 * "The absence of an Allow header field MUST NOT be 08402 * interpreted to mean that the UA sending the message supports no 08403 * methods. Rather, it implies that the UA is not providing any 08404 * information on what methods it supports." 08405 * 08406 * For simplicity, we'll assume that the peer allows all known 08407 * SIP methods if they have no Allow header. We can then clear out the necessary 08408 * bits if the peer lets us know that we have sent an unsupported method. 08409 */ 08410 return UINT_MAX; 08411 } 08412 allow = ast_strip_quoted(methods + 9, "\"", "\""); 08413 } 08414 mark_parsed_methods(&allowed_methods, allow); 08415 return allowed_methods; 08416 }
| static void parse_copy | ( | struct sip_request * | dst, | |
| const struct sip_request * | src | |||
| ) | [static] |
Copy SIP request, parse it.
Definition at line 4077 of file chan_sip.c.
References copy_request(), and parse_request().
Referenced by send_request(), and send_response().
04078 { 04079 copy_request(dst, src); 04080 parse_request(dst); 04081 }
| int parse_minse | ( | const char * | p_hdrval, | |
| int *const | p_interval | |||
| ) | [static] |
Session-Timers: Function for parsing Min-SE header.
Definition at line 26203 of file chan_sip.c.
References ast_debug, ast_log(), ast_skip_blanks(), ast_strlen_zero(), and LOG_WARNING.
Referenced by handle_request_invite(), and proc_422_rsp().
26204 { 26205 if (ast_strlen_zero(p_hdrval)) { 26206 ast_log(LOG_WARNING, "Null Min-SE header\n"); 26207 return -1; 26208 } 26209 26210 *p_interval = 0; 26211 p_hdrval = ast_skip_blanks(p_hdrval); 26212 if (!sscanf(p_hdrval, "%30d", p_interval)) { 26213 ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval); 26214 return -1; 26215 } 26216 26217 ast_debug(2, "Received Min-SE: %d\n", *p_interval); 26218 return 0; 26219 }
| static void parse_moved_contact | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| char ** | name, | |||
| char ** | number, | |||
| int | set_call_forward | |||
| ) | [static] |
Parse 302 Moved temporalily response.
Definition at line 19755 of file chan_sip.c.
References ao2_ref, ast_copy_string(), ast_debug, ast_log(), ast_strdup, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_uri_decode(), find_closing_quote(), get_header(), get_in_brackets(), get_transport(), LOG_NOTICE, pbx_builtin_setvar_helper(), remove_uri_parameters(), and set_socket_transport().
Referenced by change_redirecting_information().
19756 { 19757 char contact[SIPBUFSIZE]; 19758 char *contact_name = NULL; 19759 char *contact_number = NULL; 19760 char *separator, *trans; 19761 char *domain; 19762 enum sip_transport transport = SIP_TRANSPORT_UDP; 19763 19764 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 19765 if ((separator = strchr(contact, ','))) 19766 *separator = '\0'; 19767 19768 contact_number = get_in_brackets(contact); 19769 if ((trans = strcasestr(contact_number, ";transport="))) { 19770 trans += 11; 19771 19772 if ((separator = strchr(trans, ';'))) 19773 *separator = '\0'; 19774 19775 if (!strncasecmp(trans, "tcp", 3)) 19776 transport = SIP_TRANSPORT_TCP; 19777 else if (!strncasecmp(trans, "tls", 3)) 19778 transport = SIP_TRANSPORT_TLS; 19779 else { 19780 if (strncasecmp(trans, "udp", 3)) 19781 ast_debug(1, "received contact with an invalid transport, '%s'\n", contact_number); 19782 /* This will assume UDP for all unknown transports */ 19783 transport = SIP_TRANSPORT_UDP; 19784 } 19785 } 19786 contact_number = remove_uri_parameters(contact_number); 19787 19788 if (p->socket.tcptls_session) { 19789 ao2_ref(p->socket.tcptls_session, -1); 19790 p->socket.tcptls_session = NULL; 19791 } 19792 19793 set_socket_transport(&p->socket, transport); 19794 19795 if (set_call_forward && ast_test_flag(&p->flags[0], SIP_PROMISCREDIR)) { 19796 char *host = NULL; 19797 if (!strncasecmp(contact_number, "sip:", 4)) 19798 contact_number += 4; 19799 else if (!strncasecmp(contact_number, "sips:", 5)) 19800 contact_number += 5; 19801 separator = strchr(contact_number, '/'); 19802 if (separator) 19803 *separator = '\0'; 19804 if ((host = strchr(contact_number, '@'))) { 19805 *host++ = '\0'; 19806 ast_debug(2, "Found promiscuous redirection to 'SIP/%s::::%s@%s'\n", contact_number, get_transport(transport), host); 19807 if (p->owner) 19808 ast_string_field_build(p->owner, call_forward, "SIP/%s::::%s@%s", contact_number, get_transport(transport), host); 19809 } else { 19810 ast_debug(2, "Found promiscuous redirection to 'SIP/::::%s@%s'\n", get_transport(transport), contact_number); 19811 if (p->owner) 19812 ast_string_field_build(p->owner, call_forward, "SIP/::::%s@%s", get_transport(transport), contact_number); 19813 } 19814 } else { 19815 separator = strchr(contact, '@'); 19816 if (separator) { 19817 *separator++ = '\0'; 19818 domain = separator; 19819 } else { 19820 /* No username part */ 19821 domain = contact; 19822 } 19823 separator = strchr(contact, '/'); /* WHEN do we hae a forward slash in the URI? */ 19824 if (separator) 19825 *separator = '\0'; 19826 19827 if (!strncasecmp(contact_number, "sip:", 4)) 19828 contact_number += 4; 19829 else if (!strncasecmp(contact_number, "sips:", 5)) 19830 contact_number += 5; 19831 separator = strchr(contact_number, ';'); /* And username ; parameters? */ 19832 if (separator) 19833 *separator = '\0'; 19834 ast_uri_decode(contact_number); 19835 if (set_call_forward) { 19836 ast_debug(2, "Received 302 Redirect to extension '%s' (domain %s)\n", contact_number, domain); 19837 if (p->owner) { 19838 pbx_builtin_setvar_helper(p->owner, "SIPDOMAIN", domain); 19839 ast_string_field_set(p->owner, call_forward, contact_number); 19840 } 19841 } 19842 } 19843 19844 /* We've gotten the number for the contact, now get the name */ 19845 19846 if (*contact == '\"') { 19847 contact_name = contact + 1; 19848 if (!(separator = (char *)find_closing_quote(contact_name, NULL))) { 19849 ast_log(LOG_NOTICE, "No closing quote on name in Contact header? %s\n", contact); 19850 } 19851 *separator = '\0'; 19852 } 19853 19854 if (name && !ast_strlen_zero(contact_name)) { 19855 *name = ast_strdup(contact_name); 19856 } 19857 if (number) { 19858 *number = ast_strdup(contact_number); 19859 } 19860 }
| static int parse_ok_contact | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
Save contact header for 200 OK on INVITE.
Definition at line 13916 of file chan_sip.c.
References ast_copy_string(), ast_string_field_set, get_header(), get_in_brackets(), and TRUE.
Referenced by handle_request_invite(), handle_request_subscribe(), and handle_response_invite().
13917 { 13918 char contact[SIPBUFSIZE]; 13919 char *c; 13920 13921 /* Look for brackets */ 13922 ast_copy_string(contact, get_header(req, "Contact"), sizeof(contact)); 13923 c = get_in_brackets(contact); 13924 13925 /* Save full contact to call pvt for later bye or re-invite */ 13926 ast_string_field_set(pvt, fullcontact, c); 13927 13928 /* Save URI for later ACKs, BYE or RE-invites */ 13929 ast_string_field_set(pvt, okcontacturi, c); 13930 13931 /* We should return false for URI:s we can't handle, 13932 like tel:, mailto:,ldap: etc */ 13933 return TRUE; 13934 }
| static enum parse_register_result parse_register_contact | ( | struct sip_pvt * | pvt, | |
| struct sip_peer * | p, | |||
| struct sip_request * | req | |||
| ) | [static] |
Parse contact header and save registration (peer registration).
Definition at line 14023 of file chan_sip.c.
References __get_header(), ao2_t_link, ao2_t_unlink, ast_apply_ha(), ast_copy_string(), ast_db_put(), ast_debug, ast_log(), ast_sched_add(), AST_SCHED_DEL_UNREF, ast_sched_when(), AST_SENSE_ALLOW, ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_strdupa, ast_string_field_build, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_verb, ast_verbose, copy_socket_data(), default_sip_port(), EVENT_FLAG_SYSTEM, expire_register(), FALSE, get_header(), get_in_brackets(), get_transport_str2enum(), LOG_NOTICE, LOG_WARNING, manager_event, parse_uri_legacy_check(), ref_peer(), register_peer_exten(), set_socket_transport(), sip_cfg, sip_poke_peer(), TRUE, unref_peer(), VERBOSE_PREFIX_3, and VERBOSITY_ATLEAST.
Referenced by register_verify().
14024 { 14025 char contact[SIPBUFSIZE]; 14026 char data[SIPBUFSIZE]; 14027 const char *expires = get_header(req, "Expires"); 14028 int expire = atoi(expires); 14029 char *curi = NULL, *hostport = NULL, *transport = NULL; 14030 int transport_type; 14031 const char *useragent; 14032 struct ast_sockaddr oldsin, testsa; 14033 char *firstcuri = NULL; 14034 int start = 0; 14035 int wildcard_found = 0; 14036 int single_binding_found = 0; 14037 14038 ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact)); 14039 14040 if (ast_strlen_zero(expires)) { /* No expires header, try look in Contact: */ 14041 char *s = strcasestr(contact, ";expires="); 14042 if (s) { 14043 expires = strsep(&s, ";"); /* trim ; and beyond */ 14044 if (sscanf(expires + 9, "%30d", &expire) != 1) { 14045 expire = default_expiry; 14046 } 14047 } else { 14048 /* Nothing has been specified */ 14049 expire = default_expiry; 14050 } 14051 } 14052 14053 copy_socket_data(&pvt->socket, &req->socket); 14054 14055 do { 14056 /* Look for brackets */ 14057 curi = contact; 14058 if (strchr(contact, '<') == NULL) /* No <, check for ; and strip it */ 14059 strsep(&curi, ";"); /* This is Header options, not URI options */ 14060 curi = get_in_brackets(contact); 14061 if (!firstcuri) { 14062 firstcuri = ast_strdupa(curi); 14063 } 14064 14065 if (!strcasecmp(curi, "*")) { 14066 wildcard_found = 1; 14067 } else { 14068 single_binding_found = 1; 14069 } 14070 14071 if (wildcard_found && (ast_strlen_zero(expires) || expire != 0 || single_binding_found)) { 14072 /* Contact header parameter "*" detected, so punt if: Expires header is missing, 14073 * Expires value is not zero, or another Contact header is present. */ 14074 return PARSE_REGISTER_FAILED; 14075 } 14076 14077 ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact)); 14078 } while (!ast_strlen_zero(contact)); 14079 curi = firstcuri; 14080 14081 /* if they did not specify Contact: or Expires:, they are querying 14082 what we currently have stored as their contact address, so return 14083 it 14084 */ 14085 if (ast_strlen_zero(curi) && ast_strlen_zero(expires)) { 14086 /* If we have an active registration, tell them when the registration is going to expire */ 14087 if (peer->expire > -1 && !ast_strlen_zero(peer->fullcontact)) { 14088 pvt->expiry = ast_sched_when(sched, peer->expire); 14089 } 14090 return PARSE_REGISTER_QUERY; 14091 } else if (!strcasecmp(curi, "*") || !expire) { /* Unregister this peer */ 14092 /* This means remove all registrations and return OK */ 14093 AST_SCHED_DEL_UNREF(sched, peer->expire, 14094 unref_peer(peer, "remove register expire ref")); 14095 ast_verb(3, "Unregistered SIP '%s'\n", peer->name); 14096 expire_register(ref_peer(peer,"add ref for explicit expire_register")); 14097 return PARSE_REGISTER_UPDATE; 14098 } 14099 14100 /* Store whatever we got as a contact from the client */ 14101 ast_string_field_set(peer, fullcontact, curi); 14102 14103 /* For the 200 OK, we should use the received contact */ 14104 ast_string_field_build(pvt, our_contact, "<%s>", curi); 14105 14106 /* Make sure it's a SIP URL */ 14107 if (ast_strlen_zero(curi) || parse_uri_legacy_check(curi, "sip:,sips:", &curi, NULL, &hostport, &transport)) { 14108 ast_log(LOG_NOTICE, "Not a valid SIP contact (missing sip:/sips:) trying to use anyway\n"); 14109 } 14110 14111 /* handle the transport type specified in Contact header. */ 14112 if (!(transport_type = get_transport_str2enum(transport))) { 14113 transport_type = pvt->socket.type; 14114 } 14115 14116 /* if the peer's socket type is different than the Registration 14117 * transport type, change it. If it got this far, it is a 14118 * supported type, but check just in case */ 14119 if ((peer->socket.type != transport_type) && (peer->transports & transport_type)) { 14120 set_socket_transport(&peer->socket, transport_type); 14121 } 14122 14123 oldsin = peer->addr; 14124 14125 /* If we were already linked into the peers_by_ip container unlink ourselves so nobody can find us */ 14126 if (!ast_sockaddr_isnull(&peer->addr) && (!peer->is_realtime || ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS))) { 14127 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table"); 14128 } 14129 14130 if (!ast_test_flag(&peer->flags[0], SIP_NAT_FORCE_RPORT) && !ast_test_flag(&peer->flags[0], SIP_NAT_RPORT_PRESENT)) { 14131 /* use the data provided in the Contact header for call routing */ 14132 ast_debug(1, "Store REGISTER's Contact header for call routing.\n"); 14133 /* XXX This could block for a long time XXX */ 14134 /*! \todo Check NAPTR/SRV if we have not got a port in the URI */ 14135 if (ast_sockaddr_resolve_first_transport(&testsa, hostport, 0, peer->socket.type)) { 14136 ast_log(LOG_WARNING, "Invalid hostport '%s'\n", hostport); 14137 ast_string_field_set(peer, fullcontact, ""); 14138 ast_string_field_set(pvt, our_contact, ""); 14139 return PARSE_REGISTER_FAILED; 14140 } 14141 14142 /* If we have a port number in the given URI, make sure we do remember to not check for NAPTR/SRV records. 14143 The hostport part is actually a host. */ 14144 peer->portinuri = ast_sockaddr_port(&testsa) ? TRUE : FALSE; 14145 14146 if (!ast_sockaddr_port(&testsa)) { 14147 ast_sockaddr_set_port(&testsa, default_sip_port(transport_type)); 14148 } 14149 14150 ast_sockaddr_copy(&peer->addr, &testsa); 14151 } else { 14152 /* Don't trust the contact field. Just use what they came to us 14153 with */ 14154 ast_debug(1, "Store REGISTER's src-IP:port for call routing.\n"); 14155 peer->addr = pvt->recv; 14156 } 14157 14158 /* Check that they're allowed to register at this IP */ 14159 if (ast_apply_ha(sip_cfg.contact_ha, &peer->addr) != AST_SENSE_ALLOW || 14160 ast_apply_ha(peer->contactha, &peer->addr) != AST_SENSE_ALLOW) { 14161 ast_log(LOG_WARNING, "Domain '%s' disallowed by contact ACL (violating IP %s)\n", hostport, 14162 ast_sockaddr_stringify_addr(&testsa)); 14163 ast_string_field_set(peer, fullcontact, ""); 14164 ast_string_field_set(pvt, our_contact, ""); 14165 return PARSE_REGISTER_DENIED; 14166 } 14167 14168 /* if the Contact header information copied into peer->addr matches the 14169 * received address, and the transport types are the same, then copy socket 14170 * data into the peer struct */ 14171 if ((peer->socket.type == pvt->socket.type) && 14172 !ast_sockaddr_cmp(&peer->addr, &pvt->recv)) { 14173 copy_socket_data(&peer->socket, &pvt->socket); 14174 } 14175 14176 /* Now that our address has been updated put ourselves back into the container for lookups */ 14177 if (!peer->is_realtime || ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 14178 ao2_t_link(peers_by_ip, peer, "ao2_link into peers_by_ip table"); 14179 } 14180 14181 /* Save SIP options profile */ 14182 peer->sipoptions = pvt->sipoptions; 14183 14184 if (!ast_strlen_zero(curi) && ast_strlen_zero(peer->username)) { 14185 ast_string_field_set(peer, username, curi); 14186 } 14187 14188 AST_SCHED_DEL_UNREF(sched, peer->expire, 14189 unref_peer(peer, "remove register expire ref")); 14190 14191 if (expire > max_expiry) { 14192 expire = max_expiry; 14193 } 14194 if (expire < min_expiry) { 14195 expire = min_expiry; 14196 } 14197 if (peer->is_realtime && !ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 14198 peer->expire = -1; 14199 } else { 14200 peer->expire = ast_sched_add(sched, (expire + 10) * 1000, expire_register, 14201 ref_peer(peer, "add registration ref")); 14202 if (peer->expire == -1) { 14203 unref_peer(peer, "remote registration ref"); 14204 } 14205 } 14206 pvt->expiry = expire; 14207 snprintf(data, sizeof(data), "%s:%d:%s:%s", ast_sockaddr_stringify(&peer->addr), 14208 expire, peer->username, peer->fullcontact); 14209 /* We might not immediately be able to reconnect via TCP, but try caching it anyhow */ 14210 if (!peer->rt_fromcontact || !sip_cfg.peer_rtupdate) 14211 ast_db_put("SIP/Registry", peer->name, data); 14212 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(&peer->addr)); 14213 14214 /* Is this a new IP address for us? */ 14215 if (VERBOSITY_ATLEAST(2) && ast_sockaddr_cmp(&peer->addr, &oldsin)) { 14216 ast_verbose(VERBOSE_PREFIX_3 "Registered SIP '%s' at %s\n", peer->name, 14217 ast_sockaddr_stringify(&peer->addr)); 14218 } 14219 sip_poke_peer(peer, 0); 14220 register_peer_exten(peer, 1); 14221 14222 /* Save User agent */ 14223 useragent = get_header(req, "User-Agent"); 14224 if (strcasecmp(useragent, peer->useragent)) { 14225 ast_string_field_set(peer, useragent, useragent); 14226 ast_verb(4, "Saved useragent \"%s\" for peer %s\n", peer->useragent, peer->name); 14227 } 14228 return PARSE_REGISTER_UPDATE; 14229 }
| static int parse_request | ( | struct sip_request * | req | ) | [static] |
Parse a SIP message.
Definition at line 8490 of file chan_sip.c.
References ast_debug, ast_log(), ast_str_strlen(), ast_strlen_zero(), determine_firstline_parts(), and LOG_WARNING.
Referenced by _sip_tcp_helper_thread(), handle_request_do(), initialize_initreq(), and parse_copy().
08491 { 08492 char *c = req->data->str; 08493 ptrdiff_t *dst = req->header; 08494 int i = 0, lim = SIP_MAX_HEADERS - 1; 08495 unsigned int skipping_headers = 0; 08496 ptrdiff_t current_header_offset = 0; 08497 char *previous_header = ""; 08498 08499 req->header[0] = 0; 08500 req->headers = -1; /* mark that we are working on the header */ 08501 for (; *c; c++) { 08502 if (*c == '\r') { /* remove \r */ 08503 *c = '\0'; 08504 } else if (*c == '\n') { /* end of this line */ 08505 *c = '\0'; 08506 current_header_offset = (c + 1) - req->data->str; 08507 previous_header = req->data->str + dst[i]; 08508 if (skipping_headers) { 08509 /* check to see if this line is blank; if so, turn off 08510 the skipping flag, so the next line will be processed 08511 as a body line */ 08512 if (ast_strlen_zero(previous_header)) { 08513 skipping_headers = 0; 08514 } 08515 dst[i] = current_header_offset; /* record start of next line */ 08516 continue; 08517 } 08518 if (sipdebug) { 08519 ast_debug(4, "%7s %2d [%3d]: %s\n", 08520 req->headers < 0 ? "Header" : "Body", 08521 i, (int) strlen(previous_header), previous_header); 08522 } 08523 if (ast_strlen_zero(previous_header) && req->headers < 0) { 08524 req->headers = i; /* record number of header lines */ 08525 dst = req->line; /* start working on the body */ 08526 i = 0; 08527 lim = SIP_MAX_LINES - 1; 08528 } else { /* move to next line, check for overflows */ 08529 if (i++ == lim) { 08530 /* if we're processing headers, then skip any remaining 08531 headers and move on to processing the body, otherwise 08532 we're done */ 08533 if (req->headers != -1) { 08534 break; 08535 } else { 08536 req->headers = i; 08537 dst = req->line; 08538 i = 0; 08539 lim = SIP_MAX_LINES - 1; 08540 skipping_headers = 1; 08541 } 08542 } 08543 } 08544 dst[i] = current_header_offset; /* record start of next line */ 08545 } 08546 } 08547 08548 /* Check for last header or body line without CRLF. The RFC for SDP requires CRLF, 08549 but since some devices send without, we'll be generous in what we accept. However, 08550 if we've already reached the maximum number of lines for portion of the message 08551 we were parsing, we can't accept any more, so just ignore it. 08552 */ 08553 previous_header = req->data->str + dst[i]; 08554 if ((i < lim) && !ast_strlen_zero(previous_header)) { 08555 if (sipdebug) { 08556 ast_debug(4, "%7s %2d [%3d]: %s\n", 08557 req->headers < 0 ? "Header" : "Body", 08558 i, (int) strlen(previous_header), previous_header ); 08559 } 08560 i++; 08561 } 08562 08563 /* update count of header or body lines */ 08564 if (req->headers >= 0) { /* we are in the body */ 08565 req->lines = i; 08566 } else { /* no body */ 08567 req->headers = i; 08568 req->lines = 0; 08569 /* req->data->used will be a NULL byte */ 08570 req->line[0] = ast_str_strlen(req->data); 08571 } 08572 08573 if (*c) { 08574 ast_log(LOG_WARNING, "Too many lines, skipping <%s>\n", c); 08575 } 08576 08577 /* Split up the first line parts */ 08578 return determine_firstline_parts(req); 08579 }
| int parse_session_expires | ( | const char * | p_hdrval, | |
| int *const | p_interval, | |||
| enum st_refresher *const | p_ref | |||
| ) | [static] |
Session-Timers: Function for parsing Session-Expires header.
Definition at line 26223 of file chan_sip.c.
References ast_debug, ast_log(), ast_skip_blanks(), ast_strdupa, ast_strlen_zero(), and LOG_WARNING.
Referenced by handle_request_invite(), and handle_response_invite().
26224 { 26225 char *p_token; 26226 int ref_idx; 26227 char *p_se_hdr; 26228 26229 if (ast_strlen_zero(p_hdrval)) { 26230 ast_log(LOG_WARNING, "Null Session-Expires header\n"); 26231 return -1; 26232 } 26233 26234 *p_ref = SESSION_TIMER_REFRESHER_AUTO; 26235 *p_interval = 0; 26236 26237 p_se_hdr = ast_strdupa(p_hdrval); 26238 p_se_hdr = ast_skip_blanks(p_se_hdr); 26239 26240 while ((p_token = strsep(&p_se_hdr, ";"))) { 26241 p_token = ast_skip_blanks(p_token); 26242 if (!sscanf(p_token, "%30d", p_interval)) { 26243 ast_log(LOG_WARNING, "Parsing of Session-Expires failed\n"); 26244 return -1; 26245 } 26246 26247 ast_debug(2, "Session-Expires: %d\n", *p_interval); 26248 26249 if (!p_se_hdr) 26250 continue; 26251 26252 p_se_hdr = ast_skip_blanks(p_se_hdr); 26253 ref_idx = strlen("refresher="); 26254 if (!strncasecmp(p_se_hdr, "refresher=", ref_idx)) { 26255 p_se_hdr += ref_idx; 26256 p_se_hdr = ast_skip_blanks(p_se_hdr); 26257 26258 if (!strncasecmp(p_se_hdr, "uac", strlen("uac"))) { 26259 *p_ref = SESSION_TIMER_REFRESHER_UAC; 26260 ast_debug(2, "Refresher: UAC\n"); 26261 } else if (!strncasecmp(p_se_hdr, "uas", strlen("uas"))) { 26262 *p_ref = SESSION_TIMER_REFRESHER_UAS; 26263 ast_debug(2, "Refresher: UAS\n"); 26264 } else { 26265 ast_log(LOG_WARNING, "Invalid refresher value %s\n", p_se_hdr); 26266 return -1; 26267 } 26268 break; 26269 } 26270 } 26271 return 0; 26272 }
| static int parse_uri_legacy_check | ( | char * | uri, | |
| const char * | scheme, | |||
| char ** | user, | |||
| char ** | pass, | |||
| char ** | hostport, | |||
| char ** | transport | |||
| ) | [static] |
parse uri in a way that allows semicolon stripping if legacy mode is enabled
Definition at line 13942 of file chan_sip.c.
References parse_uri(), and sip_cfg.
Referenced by __set_address_from_contact(), check_user_full(), get_also_info(), get_destination(), parse_register_contact(), and register_verify().
13943 { 13944 int ret = parse_uri(uri, scheme, user, pass, hostport, transport); 13945 if (sip_cfg.legacy_useroption_parsing) { /* if legacy mode is active, strip semis from the user field */ 13946 char *p; 13947 if ((p = strchr(uri, (int)';'))) { 13948 *p = '\0'; 13949 } 13950 } 13951 return ret; 13952 }
| static int peer_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 30033 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by load_module().
| static int peer_dump_func | ( | void * | userobj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 16955 of file chan_sip.c.
References ao2_t_ref, ast_cli(), and ast_cli_args::fd.
Referenced by sip_show_objects().
16956 { 16957 struct sip_peer *peer = userobj; 16958 int refc = ao2_t_ref(userobj, 0, ""); 16959 struct ast_cli_args *a = (struct ast_cli_args *) arg; 16960 16961 ast_cli(a->fd, "name: %s\ntype: peer\nobjflags: %d\nrefcount: %d\n\n", 16962 peer->name, 0, refc); 16963 return 0; 16964 }
| static int peer_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 30023 of file chan_sip.c.
References ast_str_case_hash().
Referenced by load_module().
30024 { 30025 const struct sip_peer *peer = obj; 30026 30027 return ast_str_case_hash(peer->name); 30028 }
| static int peer_ipcmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Match Peers by IP and Port number.
This function has two modes.
This callback will be used twice when doing peer matching. There is a first pass for full IP+port matching, and a second pass in case there is a match that meets the insecure=port criteria.
Definition at line 30081 of file chan_sip.c.
References ast_sockaddr_cmp_addr(), ast_sockaddr_port, ast_test_flag, CMP_MATCH, and CMP_STOP.
Referenced by load_module().
30082 { 30083 struct sip_peer *peer = obj, *peer2 = arg; 30084 30085 if (ast_sockaddr_cmp_addr(&peer->addr, &peer2->addr)) { 30086 /* IP doesn't match */ 30087 return 0; 30088 } 30089 30090 /* We matched the IP, check to see if we need to match by port as well. */ 30091 if ((peer->transports & peer2->transports) & (SIP_TRANSPORT_TLS | SIP_TRANSPORT_TCP)) { 30092 /* peer matching on port is not possible with TCP/TLS */ 30093 return CMP_MATCH | CMP_STOP; 30094 } else if (ast_test_flag(&peer2->flags[0], SIP_INSECURE_PORT)) { 30095 /* We are allowing match without port for peers configured that 30096 * way in this pass through the peers. */ 30097 return ast_test_flag(&peer->flags[0], SIP_INSECURE_PORT) ? 30098 (CMP_MATCH | CMP_STOP) : 0; 30099 } 30100 30101 /* Now only return a match if the port matches, as well. */ 30102 return ast_sockaddr_port(&peer->addr) == ast_sockaddr_port(&peer2->addr) ? 30103 (CMP_MATCH | CMP_STOP) : 0; 30104 }
| static int peer_iphash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Hash function based on the the peer's ip address. For IPv6, we use the end of the address.
Definition at line 30045 of file chan_sip.c.
References ast_log(), ast_sockaddr_hash(), ast_sockaddr_isnull(), and LOG_ERROR.
Referenced by load_module().
30046 { 30047 const struct sip_peer *peer = obj; 30048 int ret = 0; 30049 30050 if (ast_sockaddr_isnull(&peer->addr)) { 30051 ast_log(LOG_ERROR, "Empty address\n"); 30052 } 30053 30054 ret = ast_sockaddr_hash(&peer->addr); 30055 30056 if (ret < 0) { 30057 ret = -ret; 30058 } 30059 30060 return ret; 30061 }
| static void peer_mailboxes_to_str | ( | struct ast_str ** | mailbox_str, | |
| struct sip_peer * | peer | |||
| ) | [static] |
list peer mailboxes to CLI
Definition at line 17477 of file chan_sip.c.
References AST_LIST_NEXT, AST_LIST_TRAVERSE, ast_str_append(), ast_strlen_zero(), mailbox, and S_OR.
Referenced by _sip_show_peer(), function_sippeer(), show_channels_cb(), and sip_send_mwi_to_peer().
17478 { 17479 struct sip_mailbox *mailbox; 17480 17481 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 17482 ast_str_append(mailbox_str, 0, "%s%s%s%s", 17483 mailbox->mailbox, 17484 ast_strlen_zero(mailbox->context) ? "" : "@", 17485 S_OR(mailbox->context, ""), 17486 AST_LIST_NEXT(mailbox, entry) ? "," : ""); 17487 } 17488 }
| static int peer_markall_func | ( | void * | device, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 28071 of file chan_sip.c.
Referenced by reload_config().
| static void peer_sched_cleanup | ( | struct sip_peer * | peer | ) | [static] |
Definition at line 2856 of file chan_sip.c.
References AST_SCHED_DEL_UNREF, and unref_peer().
Referenced by match_and_cleanup_peer_sched().
02857 { 02858 if (peer->pokeexpire != -1) { 02859 AST_SCHED_DEL_UNREF(sched, peer->pokeexpire, 02860 unref_peer(peer, "removing poke peer ref")); 02861 } 02862 if (peer->expire != -1) { 02863 AST_SCHED_DEL_UNREF(sched, peer->expire, 02864 unref_peer(peer, "remove register expire ref")); 02865 } 02866 }
| static int peer_status | ( | struct sip_peer * | peer, | |
| char * | status, | |||
| int | statuslen | |||
| ) | [static] |
Definition at line 16522 of file chan_sip.c.
References ast_copy_string().
Referenced by _sip_show_peer(), _sip_show_peers(), and function_sippeer().
16523 { 16524 int res = 0; 16525 if (peer->maxms) { 16526 if (peer->lastms < 0) { 16527 ast_copy_string(status, "UNREACHABLE", statuslen); 16528 } else if (peer->lastms > peer->maxms) { 16529 snprintf(status, statuslen, "LAGGED (%d ms)", peer->lastms); 16530 res = 1; 16531 } else if (peer->lastms) { 16532 snprintf(status, statuslen, "OK (%d ms)", peer->lastms); 16533 res = 1; 16534 } else { 16535 ast_copy_string(status, "UNKNOWN", statuslen); 16536 } 16537 } else { 16538 ast_copy_string(status, "Unmonitored", statuslen); 16539 /* Checking if port is 0 */ 16540 res = -1; 16541 } 16542 return res; 16543 }
| int peercomparefunc | ( | const void * | a, | |
| const void * | b | |||
| ) |
Definition at line 16750 of file chan_sip.c.
Referenced by _sip_show_peers().
| static int peers_data_provider_get | ( | const struct ast_data_search * | search, | |
| struct ast_data * | data_root | |||
| ) | [static] |
Definition at line 30462 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_iterator_next, ao2_lock, ao2_ref, ao2_unlock, ARRAY_LEN, ast_cdr_flags2str(), ast_data_add_bool(), ast_data_add_codecs(), ast_data_add_int(), ast_data_add_node(), ast_data_add_str(), ast_data_add_structure, ast_data_remove_node(), ast_data_search_match(), ast_describe_caller_presentation(), AST_LIST_TRAVERSE, get_transport_list(), mailbox, text, and transfermode2str().
30464 { 30465 struct sip_peer *peer; 30466 struct ao2_iterator i; 30467 struct ast_data *data_peer, *data_peer_mailboxes = NULL, *data_peer_mailbox, *enum_node; 30468 struct ast_data *data_sip_options; 30469 int total_mailboxes, x; 30470 struct sip_mailbox *mailbox; 30471 30472 i = ao2_iterator_init(peers, 0); 30473 while ((peer = ao2_iterator_next(&i))) { 30474 ao2_lock(peer); 30475 30476 data_peer = ast_data_add_node(data_root, "peer"); 30477 if (!data_peer) { 30478 ao2_unlock(peer); 30479 ao2_ref(peer, -1); 30480 continue; 30481 } 30482 30483 ast_data_add_structure(sip_peer, data_peer, peer); 30484 30485 /* transfer mode */ 30486 enum_node = ast_data_add_node(data_peer, "allowtransfer"); 30487 if (!enum_node) { 30488 ao2_unlock(peer); 30489 ao2_ref(peer, -1); 30490 continue; 30491 } 30492 ast_data_add_str(enum_node, "text", transfermode2str(peer->allowtransfer)); 30493 ast_data_add_int(enum_node, "value", peer->allowtransfer); 30494 30495 /* transports */ 30496 ast_data_add_str(data_peer, "transports", get_transport_list(peer->transports)); 30497 30498 /* peer type */ 30499 if ((peer->type & SIP_TYPE_USER) && (peer->type & SIP_TYPE_PEER)) { 30500 ast_data_add_str(data_peer, "type", "friend"); 30501 } else if (peer->type & SIP_TYPE_PEER) { 30502 ast_data_add_str(data_peer, "type", "peer"); 30503 } else if (peer->type & SIP_TYPE_USER) { 30504 ast_data_add_str(data_peer, "type", "user"); 30505 } 30506 30507 /* mailboxes */ 30508 total_mailboxes = 0; 30509 AST_LIST_TRAVERSE(&peer->mailboxes, mailbox, entry) { 30510 if (!total_mailboxes) { 30511 data_peer_mailboxes = ast_data_add_node(data_peer, "mailboxes"); 30512 if (!data_peer_mailboxes) { 30513 break; 30514 } 30515 total_mailboxes++; 30516 } 30517 30518 data_peer_mailbox = ast_data_add_node(data_peer_mailboxes, "mailbox"); 30519 if (!data_peer_mailbox) { 30520 continue; 30521 } 30522 ast_data_add_str(data_peer_mailbox, "mailbox", mailbox->mailbox); 30523 ast_data_add_str(data_peer_mailbox, "context", mailbox->context); 30524 } 30525 30526 /* amaflags */ 30527 enum_node = ast_data_add_node(data_peer, "amaflags"); 30528 if (!enum_node) { 30529 ao2_unlock(peer); 30530 ao2_ref(peer, -1); 30531 continue; 30532 } 30533 ast_data_add_int(enum_node, "value", peer->amaflags); 30534 ast_data_add_str(enum_node, "text", ast_cdr_flags2str(peer->amaflags)); 30535 30536 /* sip options */ 30537 data_sip_options = ast_data_add_node(data_peer, "sipoptions"); 30538 if (!data_sip_options) { 30539 ao2_unlock(peer); 30540 ao2_ref(peer, -1); 30541 continue; 30542 } 30543 for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { 30544 ast_data_add_bool(data_sip_options, sip_options[x].text, peer->sipoptions & sip_options[x].id); 30545 } 30546 30547 /* callingpres */ 30548 enum_node = ast_data_add_node(data_peer, "callingpres"); 30549 if (!enum_node) { 30550 ao2_unlock(peer); 30551 ao2_ref(peer, -1); 30552 continue; 30553 } 30554 ast_data_add_int(enum_node, "value", peer->callingpres); 30555 ast_data_add_str(enum_node, "text", ast_describe_caller_presentation(peer->callingpres)); 30556 30557 /* codecs */ 30558 ast_data_add_codecs(data_peer, "codecs", peer->capability); 30559 30560 if (!ast_data_search_match(search, data_peer)) { 30561 ast_data_remove_node(data_root, data_peer); 30562 } 30563 30564 ao2_unlock(peer); 30565 ao2_ref(peer, -1); 30566 } 30567 ao2_iterator_destroy(&i); 30568 30569 return 0; 30570 }
| 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.
Definition at line 3118 of file chan_sip.c.
References ast_strlen_zero().
Referenced by build_peer(), reload_config(), and sip_parse_register_line().
03119 { 03120 int port = standard; 03121 if (ast_strlen_zero(pt) || (sscanf(pt, "%30d", &port) != 1) || (port < 1) || (port > 65535)) { 03122 port = standard; 03123 } 03124 03125 return port; 03126 }
| static void print_codec_to_cli | ( | int | fd, | |
| struct ast_codec_pref * | pref | |||
| ) | [static] |
Print codec list from preference to CLI/manager.
Definition at line 17314 of file chan_sip.c.
References ast_cli(), ast_codec_pref_index(), ast_getformatname(), and ast_codec_pref::framing.
Referenced by _sip_show_peer(), sip_show_settings(), and sip_show_user().
17315 { 17316 int x; 17317 format_t codec; 17318 17319 for(x = 0; x < 64 ; x++) { 17320 codec = ast_codec_pref_index(pref, x); 17321 if (!codec) 17322 break; 17323 ast_cli(fd, "%s", ast_getformatname(codec)); 17324 ast_cli(fd, ":%d", pref->framing[x]); 17325 if (x < 31 && ast_codec_pref_index(pref, x + 1)) 17326 ast_cli(fd, ","); 17327 } 17328 if (!x) 17329 ast_cli(fd, "none"); 17330 }
| static void print_group | ( | int | fd, | |
| ast_group_t | group, | |||
| int | crlf | |||
| ) | [static] |
Print call group and pickup group.
Definition at line 17007 of file chan_sip.c.
References ast_cli(), and ast_print_group().
Referenced by _sip_show_peer(), and sip_show_user().
17008 { 17009 char buf[256]; 17010 ast_cli(fd, crlf ? "%s\r\n" : "%s\n", ast_print_group(buf, sizeof(buf), group) ); 17011 }
| static void proc_422_rsp | ( | struct sip_pvt * | p, | |
| struct sip_request * | rsp | |||
| ) | [static] |
Handle 422 response to INVITE with session-timer requested.
Session-Timers: An INVITE originated by Asterisk that asks for session-timers support from the UAS can result into a 422 response. This is how a UAS or an intermediary proxy server tells Asterisk that the session refresh interval offered by Asterisk is too low for them. The proc_422_rsp() function handles a 422 response. It extracts the Min-SE header that comes back in 422 and sends a new INVITE accordingly.
Definition at line 26282 of file chan_sip.c.
References ast_log(), ast_strlen_zero(), get_header(), LOG_WARNING, parse_minse(), and transmit_invite().
Referenced by handle_response_invite().
26283 { 26284 int rtn; 26285 const char *p_hdrval; 26286 int minse; 26287 26288 p_hdrval = get_header(rsp, "Min-SE"); 26289 if (ast_strlen_zero(p_hdrval)) { 26290 ast_log(LOG_WARNING, "422 response without a Min-SE header %s\n", p_hdrval); 26291 return; 26292 } 26293 rtn = parse_minse(p_hdrval, &minse); 26294 if (rtn != 0) { 26295 ast_log(LOG_WARNING, "Parsing of Min-SE header failed %s\n", p_hdrval); 26296 return; 26297 } 26298 p->stimer->st_interval = minse; 26299 transmit_invite(p, SIP_INVITE, 1, 2, NULL); 26300 }
| static int proc_session_timer | ( | const void * | vp | ) | [static] |
Session-Timers: Process session refresh timeout event.
Definition at line 26119 of file chan_sip.c.
References ast_channel_trylock, ast_channel_unlock, ast_debug, ast_log(), AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_UP, FALSE, LOG_ERROR, LOG_WARNING, sip_pvt_lock, sip_pvt_unlock, stop_session_timer(), transmit_reinvite_with_sdp(), and TRUE.
Referenced by start_session_timer().
26120 { 26121 struct sip_pvt *p = (struct sip_pvt *) vp; 26122 int sendreinv = FALSE; 26123 int res = 0; 26124 26125 if (!p->stimer) { 26126 ast_log(LOG_WARNING, "Null stimer in proc_session_timer - %s\n", p->callid); 26127 goto return_unref; 26128 } 26129 26130 ast_debug(2, "Session timer expired: %d - %s\n", p->stimer->st_schedid, p->callid); 26131 26132 if (!p->owner) { 26133 goto return_unref; 26134 } 26135 26136 if ((p->stimer->st_active != TRUE) || (p->owner->_state != AST_STATE_UP)) { 26137 goto return_unref; 26138 } 26139 26140 switch (p->stimer->st_ref) { 26141 case SESSION_TIMER_REFRESHER_UAC: 26142 if (p->outgoing_call == TRUE) { 26143 sendreinv = TRUE; 26144 } 26145 break; 26146 case SESSION_TIMER_REFRESHER_UAS: 26147 if (p->outgoing_call != TRUE) { 26148 sendreinv = TRUE; 26149 } 26150 break; 26151 default: 26152 ast_log(LOG_ERROR, "Unknown session refresher %d\n", p->stimer->st_ref); 26153 goto return_unref; 26154 } 26155 26156 if (sendreinv == TRUE) { 26157 res = 1; 26158 transmit_reinvite_with_sdp(p, FALSE, TRUE); 26159 } else { 26160 p->stimer->st_expirys++; 26161 if (p->stimer->st_expirys >= 2) { 26162 if (p->stimer->quit_flag) { 26163 goto return_unref; 26164 } 26165 ast_log(LOG_WARNING, "Session-Timer expired - %s\n", p->callid); 26166 sip_pvt_lock(p); 26167 while (p->owner && ast_channel_trylock(p->owner)) { 26168 sip_pvt_unlock(p); 26169 usleep(1); 26170 if (p->stimer && p->stimer->quit_flag) { 26171 goto return_unref; 26172 } 26173 sip_pvt_lock(p); 26174 } 26175 26176 ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV); 26177 ast_channel_unlock(p->owner); 26178 sip_pvt_unlock(p); 26179 } else { 26180 res = 1; 26181 } 26182 } 26183 26184 return_unref: 26185 if (!res) { 26186 /* An error occurred. Stop session timer processing */ 26187 if (p->stimer) { 26188 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 26189 p->stimer->st_schedid = -1; 26190 stop_session_timer(p); 26191 } 26192 26193 /* If we are not asking to be rescheduled, then we need to release our 26194 * reference to the dialog. */ 26195 dialog_unref(p, "removing session timer ref"); 26196 } 26197 26198 return res; 26199 }
| static int process_crypto | ( | struct sip_pvt * | p, | |
| struct ast_rtp_instance * | rtp, | |||
| struct sip_srtp ** | srtp, | |||
| const char * | a | |||
| ) | [static] |
Definition at line 29874 of file chan_sip.c.
References ast_debug, ast_log(), ast_set_flag, ast_test_flag, FALSE, LOG_WARNING, sdp_crypto_process(), sdp_crypto_setup(), setup_srtp(), and TRUE.
Referenced by process_sdp().
29875 { 29876 /* If no RTP instance exists for this media stream don't bother processing the crypto line */ 29877 if (!rtp) { 29878 ast_debug(3, "Received offer with crypto line for media stream that is not enabled\n"); 29879 return FALSE; 29880 } 29881 29882 if (strncasecmp(a, "crypto:", 7)) { 29883 return FALSE; 29884 } 29885 if (!*srtp) { 29886 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 29887 ast_log(LOG_WARNING, "Ignoring unexpected crypto attribute in SDP answer\n"); 29888 return FALSE; 29889 } 29890 29891 if (setup_srtp(srtp) < 0) { 29892 return FALSE; 29893 } 29894 } 29895 29896 if (!(*srtp)->crypto && !((*srtp)->crypto = sdp_crypto_setup())) { 29897 return FALSE; 29898 } 29899 29900 if (sdp_crypto_process((*srtp)->crypto, a, rtp) < 0) { 29901 return FALSE; 29902 } 29903 29904 ast_set_flag(*srtp, SRTP_CRYPTO_OFFER_OK); 29905 29906 return TRUE; 29907 }
| static int process_sdp | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| int | t38action | |||
| ) | [static] |
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().
< RTP audio destination IP address
< RTP video destination IP address
< RTP text destination IP address
< UDPTL image destination IP address
< RTP audio destination port number
< RTP video destination port number
< RTP text destination port number
< UDPTL image destination port number
Definition at line 8787 of file chan_sip.c.
References ast_async_goto(), ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_clear_flag, ast_codec_choose(), AST_CONTROL_HOLD, AST_CONTROL_UNHOLD, ast_copy_string(), ast_debug, ast_exists_extension(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_T140RED, ast_getformatname_multiple(), ast_log(), ast_null_frame, ast_queue_control(), ast_queue_control_data(), ast_queue_frame(), ast_rtp_codecs_payload_formats(), ast_rtp_codecs_payloads_clear(), ast_rtp_codecs_payloads_copy(), ast_rtp_codecs_payloads_set_m_type(), AST_RTP_DTMF, ast_rtp_instance_fd(), ast_rtp_instance_get_codecs(), ast_rtp_instance_get_remote_address(), ast_rtp_instance_set_prop(), ast_rtp_instance_set_remote_address(), ast_rtp_instance_stop(), ast_rtp_lookup_mime_multiple2(), AST_RTP_PROPERTY_DTMF, AST_RTP_PROPERTY_DTMF_COMPENSATE, AST_RTP_PROPERTY_RTCP, ast_rtp_red_init(), ast_set_flag, ast_set_read_format(), ast_set_write_format(), ast_skip_blanks(), ast_sockaddr_isnull(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_str_alloca, ast_strlen_zero(), ast_test_flag, ast_udptl_get_far_max_datagram(), ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), ast_udptl_set_peer(), ast_udptl_stop(), ast_verbose, change_hold_state(), change_t38_state(), FALSE, get_sdp_iterate(), get_sdp_line(), initialize_udptl(), len(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, pbx_builtin_setvar_helper(), process_crypto(), process_sdp_a_audio(), process_sdp_a_image(), process_sdp_a_sendonly(), process_sdp_a_text(), process_sdp_a_video(), process_sdp_c(), process_sdp_o(), S_COR, S_OR, sip_debug_test_pvt(), sockaddr_is_null_or_any(), text, TRUE, type, UDPTL_ERROR_CORRECTION_NONE, value, and VERBOSE_PREFIX_2.
Referenced by handle_incoming(), handle_request_invite(), handle_response(), and handle_response_invite().
08788 { 08789 /* Iterators for SDP parsing */ 08790 int start = req->sdp_start; 08791 int next = start; 08792 int iterator = start; 08793 08794 /* Temporary vars for SDP parsing */ 08795 char type = '\0'; 08796 const char *value = NULL; 08797 const char *m = NULL; /* SDP media offer */ 08798 const char *nextm = NULL; 08799 int len = -1; 08800 08801 /* Host information */ 08802 struct ast_sockaddr sessionsa; 08803 struct ast_sockaddr audiosa; 08804 struct ast_sockaddr videosa; 08805 struct ast_sockaddr textsa; 08806 struct ast_sockaddr imagesa; 08807 struct ast_sockaddr *sa = NULL; /*!< RTP audio destination IP address */ 08808 struct ast_sockaddr *vsa = NULL; /*!< RTP video destination IP address */ 08809 struct ast_sockaddr *tsa = NULL; /*!< RTP text destination IP address */ 08810 struct ast_sockaddr *isa = NULL; /*!< UDPTL image destination IP address */ 08811 int portno = -1; /*!< RTP audio destination port number */ 08812 int vportno = -1; /*!< RTP video destination port number */ 08813 int tportno = -1; /*!< RTP text destination port number */ 08814 int udptlportno = -1; /*!< UDPTL image destination port number */ 08815 08816 /* Peer capability is the capability in the SDP, non codec is RFC2833 DTMF (101) */ 08817 format_t peercapability = 0, vpeercapability = 0, tpeercapability = 0; 08818 int peernoncodeccapability = 0, vpeernoncodeccapability = 0, tpeernoncodeccapability = 0; 08819 08820 struct ast_rtp_codecs newaudiortp, newvideortp, newtextrtp; 08821 format_t newjointcapability; /* Negotiated capability */ 08822 format_t newpeercapability; 08823 int newnoncodeccapability; 08824 08825 const char *codecs; 08826 int codec; 08827 08828 /* SRTP */ 08829 int secure_audio = FALSE; 08830 int secure_video = FALSE; 08831 08832 /* Others */ 08833 int sendonly = -1; 08834 int numberofports; 08835 int numberofmediastreams = 0; 08836 int last_rtpmap_codec = 0; 08837 int red_data_pt[10]; /* For T.140 RED */ 08838 int red_num_gen = 0; /* For T.140 RED */ 08839 char red_fmtp[100] = "empty"; /* For T.140 RED */ 08840 int debug = sip_debug_test_pvt(p); 08841 08842 /* START UNKNOWN */ 08843 char buf[SIPBUFSIZE]; 08844 /* END UNKNOWN */ 08845 08846 /* Initial check */ 08847 if (!p->rtp) { 08848 ast_log(LOG_ERROR, "Got SDP but have no RTP session allocated.\n"); 08849 return -1; 08850 } 08851 08852 /* Make sure that the codec structures are all cleared out */ 08853 ast_rtp_codecs_payloads_clear(&newaudiortp, NULL); 08854 ast_rtp_codecs_payloads_clear(&newvideortp, NULL); 08855 ast_rtp_codecs_payloads_clear(&newtextrtp, NULL); 08856 08857 /* Update our last rtprx when we receive an SDP, too */ 08858 p->lastrtprx = p->lastrtptx = time(NULL); /* XXX why both ? */ 08859 08860 memset(p->offered_media, 0, sizeof(p->offered_media)); 08861 08862 /* default: novideo and notext set */ 08863 p->novideo = TRUE; 08864 p->notext = TRUE; 08865 08866 /* Scan for the first media stream (m=) line to limit scanning of globals */ 08867 nextm = get_sdp_iterate(&next, req, "m"); 08868 if (ast_strlen_zero(nextm)) { 08869 ast_log(LOG_WARNING, "Insufficient information for SDP (m= not found)\n"); 08870 return -1; 08871 } 08872 08873 /* Scan session level SDP parameters (lines before first media stream) */ 08874 while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') { 08875 int processed = FALSE; 08876 switch (type) { 08877 case 'o': 08878 /* If we end up receiving SDP that doesn't actually modify the session we don't want to treat this as a fatal 08879 * error. We just want to ignore the SDP and let the rest of the packet be handled as normal. 08880 */ 08881 if (!process_sdp_o(value, p)) 08882 return (p->session_modify == FALSE) ? 0 : -1; 08883 break; 08884 case 'c': 08885 if (process_sdp_c(value, &sessionsa)) { 08886 processed = TRUE; 08887 sa = &sessionsa; 08888 vsa = sa; 08889 tsa = sa; 08890 isa = sa; 08891 } 08892 break; 08893 case 'a': 08894 if (process_sdp_a_sendonly(value, &sendonly)) { 08895 processed = TRUE; 08896 } 08897 else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) 08898 processed = TRUE; 08899 else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) 08900 processed = TRUE; 08901 else if (process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) 08902 processed = TRUE; 08903 else if (process_sdp_a_image(value, p)) 08904 processed = TRUE; 08905 break; 08906 } 08907 08908 ast_debug(3, "Processing session-level SDP %c=%s... %s\n", type, value, (processed == TRUE)? "OK." : "UNSUPPORTED OR FAILED."); 08909 } 08910 08911 /* Scan media stream (m=) specific parameters loop */ 08912 while (!ast_strlen_zero(nextm)) { 08913 int audio = FALSE; 08914 int video = FALSE; 08915 int image = FALSE; 08916 int text = FALSE; 08917 int processed_crypto = FALSE; 08918 char protocol[5] = {0,}; 08919 int x; 08920 08921 numberofports = 0; 08922 len = -1; 08923 start = next; 08924 m = nextm; 08925 iterator = next; 08926 nextm = get_sdp_iterate(&next, req, "m"); 08927 08928 /* Check for 'audio' media offer */ 08929 if (strncmp(m, "audio ", 6) == 0) { 08930 if ((sscanf(m, "audio %30u/%30u RTP/%4s %n", &x, &numberofports, protocol, &len) == 3 && len > 0) || 08931 (sscanf(m, "audio %30u RTP/%4s %n", &x, protocol, &len) == 2 && len > 0)) { 08932 if (x == 0) { 08933 ast_log(LOG_WARNING, "Ignoring audio media offer because port number is zero\n"); 08934 continue; 08935 } 08936 08937 /* Check number of ports offered for stream */ 08938 if (numberofports > 1) { 08939 ast_log(LOG_WARNING, "%d ports offered for audio media, not supported by Asterisk. Will try anyway...\n", numberofports); 08940 } 08941 08942 if (!strcmp(protocol, "SAVP")) { 08943 secure_audio = 1; 08944 } else if (strcmp(protocol, "AVP")) { 08945 ast_log(LOG_WARNING, "Unknown RTP profile in audio offer: %s\n", m); 08946 continue; 08947 } 08948 08949 if (p->offered_media[SDP_AUDIO].order_offered) { 08950 ast_log(LOG_WARNING, "Rejecting non-primary audio stream: %s\n", m); 08951 return -1; 08952 } 08953 08954 audio = TRUE; 08955 p->offered_media[SDP_AUDIO].order_offered = ++numberofmediastreams; 08956 portno = x; 08957 08958 /* Scan through the RTP payload types specified in a "m=" line: */ 08959 codecs = m + len; 08960 ast_copy_string(p->offered_media[SDP_AUDIO].codecs, codecs, sizeof(p->offered_media[SDP_AUDIO].codecs)); 08961 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 08962 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 08963 ast_log(LOG_WARNING, "Invalid syntax in RTP audio format list: %s\n", codecs); 08964 return -1; 08965 } 08966 if (debug) { 08967 ast_verbose("Found RTP audio format %d\n", codec); 08968 } 08969 08970 ast_rtp_codecs_payloads_set_m_type(&newaudiortp, NULL, codec); 08971 } 08972 } else { 08973 ast_log(LOG_WARNING, "Rejecting audio media offer due to invalid or unsupported syntax: %s\n", m); 08974 return -1; 08975 } 08976 } 08977 /* Check for 'video' media offer */ 08978 else if (strncmp(m, "video ", 6) == 0) { 08979 if ((sscanf(m, "video %30u/%30u RTP/%4s %n", &x, &numberofports, protocol, &len) == 3 && len > 0) || 08980 (sscanf(m, "video %30u RTP/%4s %n", &x, protocol, &len) == 2 && len > 0)) { 08981 if (x == 0) { 08982 ast_log(LOG_WARNING, "Ignoring video media offer because port number is zero\n"); 08983 continue; 08984 } 08985 08986 /* Check number of ports offered for stream */ 08987 if (numberofports > 1) { 08988 ast_log(LOG_WARNING, "%d ports offered for video media, not supported by Asterisk. Will try anyway...\n", numberofports); 08989 } 08990 08991 if (!strcmp(protocol, "SAVP")) { 08992 secure_video = 1; 08993 } else if (strcmp(protocol, "AVP")) { 08994 ast_log(LOG_WARNING, "Unknown RTP profile in video offer: %s\n", m); 08995 continue; 08996 } 08997 08998 if (p->offered_media[SDP_VIDEO].order_offered) { 08999 ast_log(LOG_WARNING, "Rejecting non-primary video stream: %s\n", m); 09000 return -1; 09001 } 09002 09003 video = TRUE; 09004 p->novideo = FALSE; 09005 p->offered_media[SDP_VIDEO].order_offered = ++numberofmediastreams; 09006 vportno = x; 09007 09008 /* Scan through the RTP payload types specified in a "m=" line: */ 09009 codecs = m + len; 09010 ast_copy_string(p->offered_media[SDP_VIDEO].codecs, codecs, sizeof(p->offered_media[SDP_VIDEO].codecs)); 09011 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 09012 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 09013 ast_log(LOG_WARNING, "Invalid syntax in RTP video format list: %s\n", codecs); 09014 return -1; 09015 } 09016 if (debug) { 09017 ast_verbose("Found RTP video format %d\n", codec); 09018 } 09019 ast_rtp_codecs_payloads_set_m_type(&newvideortp, NULL, codec); 09020 } 09021 } else { 09022 ast_log(LOG_WARNING, "Rejecting video media offer due to invalid or unsupported syntax: %s\n", m); 09023 return -1; 09024 } 09025 } 09026 /* Check for 'text' media offer */ 09027 else if (strncmp(m, "text ", 5) == 0) { 09028 if ((sscanf(m, "text %30u/%30u RTP/AVP %n", &x, &numberofports, &len) == 2 && len > 0) || 09029 (sscanf(m, "text %30u RTP/AVP %n", &x, &len) == 1 && len > 0)) { 09030 if (x == 0) { 09031 ast_log(LOG_WARNING, "Ignoring text media offer because port number is zero\n"); 09032 continue; 09033 } 09034 09035 /* Check number of ports offered for stream */ 09036 if (numberofports > 1) { 09037 ast_log(LOG_WARNING, "%d ports offered for text media, not supported by Asterisk. Will try anyway...\n", numberofports); 09038 } 09039 09040 if (p->offered_media[SDP_TEXT].order_offered) { 09041 ast_log(LOG_WARNING, "Rejecting non-primary text stream: %s\n", m); 09042 return -1; 09043 } 09044 09045 text = TRUE; 09046 p->notext = FALSE; 09047 p->offered_media[SDP_TEXT].order_offered = ++numberofmediastreams; 09048 tportno = x; 09049 09050 /* Scan through the RTP payload types specified in a "m=" line: */ 09051 codecs = m + len; 09052 ast_copy_string(p->offered_media[SDP_TEXT].codecs, codecs, sizeof(p->offered_media[SDP_TEXT].codecs)); 09053 for (; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) { 09054 if (sscanf(codecs, "%30u%n", &codec, &len) != 1) { 09055 ast_log(LOG_WARNING, "Invalid syntax in RTP video format list: %s\n", codecs); 09056 return -1; 09057 } 09058 if (debug) { 09059 ast_verbose("Found RTP text format %d\n", codec); 09060 } 09061 ast_rtp_codecs_payloads_set_m_type(&newtextrtp, NULL, codec); 09062 } 09063 } else { 09064 ast_log(LOG_WARNING, "Rejecting text media offer due to invalid or unsupported syntax: %s\n", m); 09065 return -1; 09066 } 09067 } 09068 /* Check for 'image' media offer */ 09069 else if (strncmp(m, "image ", 6) == 0) { 09070 if (((sscanf(m, "image %30u udptl t38%n", &x, &len) == 1 && len > 0) || 09071 (sscanf(m, "image %30u UDPTL t38%n", &x, &len) == 1 && len > 0))) { 09072 if (x == 0) { 09073 ast_log(LOG_WARNING, "Ignoring image media offer because port number is zero\n"); 09074 continue; 09075 } 09076 09077 if (initialize_udptl(p)) { 09078 return -1; 09079 } 09080 09081 if (p->offered_media[SDP_IMAGE].order_offered) { 09082 ast_log(LOG_WARNING, "Rejecting non-primary image stream: %s\n", m); 09083 return -1; 09084 } 09085 09086 image = TRUE; 09087 if (debug) { 09088 ast_verbose("Got T.38 offer in SDP in dialog %s\n", p->callid); 09089 } 09090 09091 p->offered_media[SDP_IMAGE].order_offered = ++numberofmediastreams; 09092 udptlportno = x; 09093 09094 if (p->t38.state != T38_ENABLED) { 09095 memset(&p->t38.their_parms, 0, sizeof(p->t38.their_parms)); 09096 09097 /* default EC to none, the remote end should 09098 * respond with the EC they want to use */ 09099 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 09100 } 09101 } else { 09102 ast_log(LOG_WARNING, "Rejecting image media offer due to invalid or unsupported syntax: %s\n", m); 09103 return -1; 09104 } 09105 } else { 09106 ast_log(LOG_WARNING, "Unsupported top-level media type in offer: %s\n", m); 09107 continue; 09108 } 09109 09110 /* Media stream specific parameters */ 09111 while ((type = get_sdp_line(&iterator, next - 1, req, &value)) != '\0') { 09112 int processed = FALSE; 09113 09114 switch (type) { 09115 case 'c': 09116 if (audio) { 09117 if (process_sdp_c(value, &audiosa)) { 09118 processed = TRUE; 09119 sa = &audiosa; 09120 } 09121 } else if (video) { 09122 if (process_sdp_c(value, &videosa)) { 09123 processed = TRUE; 09124 vsa = &videosa; 09125 } 09126 } else if (text) { 09127 if (process_sdp_c(value, &textsa)) { 09128 processed = TRUE; 09129 tsa = &textsa; 09130 } 09131 } else if (image) { 09132 if (process_sdp_c(value, &imagesa)) { 09133 processed = TRUE; 09134 isa = &imagesa; 09135 } 09136 } 09137 break; 09138 case 'a': 09139 /* Audio specific scanning */ 09140 if (audio) { 09141 if (process_sdp_a_sendonly(value, &sendonly)) { 09142 processed = TRUE; 09143 } else if (!processed_crypto && process_crypto(p, p->rtp, &p->srtp, value)) { 09144 processed_crypto = TRUE; 09145 processed = TRUE; 09146 } else if (process_sdp_a_audio(value, p, &newaudiortp, &last_rtpmap_codec)) { 09147 processed = TRUE; 09148 } 09149 } 09150 /* Video specific scanning */ 09151 else if (video) { 09152 if (!processed_crypto && process_crypto(p, p->vrtp, &p->vsrtp, value)) { 09153 processed_crypto = TRUE; 09154 processed = TRUE; 09155 } else if (process_sdp_a_video(value, p, &newvideortp, &last_rtpmap_codec)) { 09156 processed = TRUE; 09157 } 09158 } 09159 /* Text (T.140) specific scanning */ 09160 else if (text) { 09161 if (process_sdp_a_text(value, p, &newtextrtp, red_fmtp, &red_num_gen, red_data_pt, &last_rtpmap_codec)) { 09162 processed = TRUE; 09163 } else if (!processed_crypto && process_crypto(p, p->trtp, &p->tsrtp, value)) { 09164 processed_crypto = TRUE; 09165 processed = TRUE; 09166 } 09167 } 09168 /* Image (T.38 FAX) specific scanning */ 09169 else if (image) { 09170 if (process_sdp_a_image(value, p)) 09171 processed = TRUE; 09172 } 09173 break; 09174 } 09175 09176 ast_debug(3, "Processing media-level (%s) SDP %c=%s... %s\n", 09177 (audio == TRUE)? "audio" : (video == TRUE)? "video" : (text == TRUE)? "text" : "image", 09178 type, value, 09179 (processed == TRUE)? "OK." : "UNSUPPORTED OR FAILED."); 09180 } 09181 } 09182 09183 /* Sanity checks */ 09184 if (!sa && !vsa && !tsa && !isa) { 09185 ast_log(LOG_WARNING, "Insufficient information in SDP (c=)...\n"); 09186 return -1; 09187 } 09188 09189 if ((portno == -1) && 09190 (vportno == -1) && 09191 (tportno == -1) && 09192 (udptlportno == -1)) { 09193 ast_log(LOG_WARNING, "Failing due to no acceptable offer found\n"); 09194 return -1; 09195 } 09196 09197 if (secure_audio && !(p->srtp && (ast_test_flag(p->srtp, SRTP_CRYPTO_OFFER_OK)))) { 09198 ast_log(LOG_WARNING, "Can't provide secure audio requested in SDP offer\n"); 09199 return -1; 09200 } 09201 09202 if (!secure_audio && p->srtp) { 09203 ast_log(LOG_WARNING, "We are requesting SRTP for audio, but they responded without it!\n"); 09204 return -1; 09205 } 09206 09207 if (secure_video && !(p->vsrtp && (ast_test_flag(p->vsrtp, SRTP_CRYPTO_OFFER_OK)))) { 09208 ast_log(LOG_WARNING, "Can't provide secure video requested in SDP offer\n"); 09209 return -1; 09210 } 09211 09212 if (!p->novideo && !secure_video && p->vsrtp) { 09213 ast_log(LOG_WARNING, "We are requesting SRTP for video, but they responded without it!\n"); 09214 return -1; 09215 } 09216 09217 if (!(secure_audio || secure_video) && ast_test_flag(&p->flags[1], SIP_PAGE2_USE_SRTP)) { 09218 ast_log(LOG_WARNING, "Matched device setup to use SRTP, but request was not!\n"); 09219 return -1; 09220 } 09221 09222 if (udptlportno == -1) { 09223 change_t38_state(p, T38_DISABLED); 09224 } 09225 09226 /* Now gather all of the codecs that we are asked for: */ 09227 ast_rtp_codecs_payload_formats(&newaudiortp, &peercapability, &peernoncodeccapability); 09228 ast_rtp_codecs_payload_formats(&newvideortp, &vpeercapability, &vpeernoncodeccapability); 09229 ast_rtp_codecs_payload_formats(&newtextrtp, &tpeercapability, &tpeernoncodeccapability); 09230 09231 newjointcapability = p->capability & (peercapability | vpeercapability | tpeercapability); 09232 newpeercapability = (peercapability | vpeercapability | tpeercapability); 09233 newnoncodeccapability = p->noncodeccapability & peernoncodeccapability; 09234 09235 if (debug) { 09236 /* shame on whoever coded this.... */ 09237 char s1[SIPBUFSIZE], s2[SIPBUFSIZE], s3[SIPBUFSIZE], s4[SIPBUFSIZE], s5[SIPBUFSIZE]; 09238 09239 ast_verbose("Capabilities: us - %s, peer - audio=%s/video=%s/text=%s, combined - %s\n", 09240 ast_getformatname_multiple(s1, SIPBUFSIZE, p->capability), 09241 ast_getformatname_multiple(s2, SIPBUFSIZE, peercapability), 09242 ast_getformatname_multiple(s3, SIPBUFSIZE, vpeercapability), 09243 ast_getformatname_multiple(s4, SIPBUFSIZE, tpeercapability), 09244 ast_getformatname_multiple(s5, SIPBUFSIZE, newjointcapability)); 09245 } 09246 if (debug) { 09247 struct ast_str *s1 = ast_str_alloca(SIPBUFSIZE); 09248 struct ast_str *s2 = ast_str_alloca(SIPBUFSIZE); 09249 struct ast_str *s3 = ast_str_alloca(SIPBUFSIZE); 09250 09251 ast_verbose("Non-codec capabilities (dtmf): us - %s, peer - %s, combined - %s\n", 09252 ast_rtp_lookup_mime_multiple2(s1, p->noncodeccapability, 0, 0), 09253 ast_rtp_lookup_mime_multiple2(s2, peernoncodeccapability, 0, 0), 09254 ast_rtp_lookup_mime_multiple2(s3, newnoncodeccapability, 0, 0)); 09255 } 09256 if (!newjointcapability && udptlportno == -1) { 09257 ast_log(LOG_NOTICE, "No compatible codecs, not accepting this offer!\n"); 09258 /* Do NOT Change current setting */ 09259 return -1; 09260 } 09261 09262 if (portno != -1 || vportno != -1 || tportno != -1) { 09263 /* We are now ready to change the sip session and RTP structures with the offered codecs, since 09264 they are acceptable */ 09265 p->jointcapability = newjointcapability; /* Our joint codec profile for this call */ 09266 p->peercapability = newpeercapability; /* The other side's capability in latest offer */ 09267 p->jointnoncodeccapability = newnoncodeccapability; /* DTMF capabilities */ 09268 09269 /* respond with single most preferred joint codec, limiting the other side's choice */ 09270 if (ast_test_flag(&p->flags[1], SIP_PAGE2_PREFERRED_CODEC)) { 09271 p->jointcapability = ast_codec_choose(&p->prefs, p->jointcapability, 1); 09272 } 09273 } 09274 09275 /* Setup audio address and port */ 09276 if (p->rtp) { 09277 if (portno > 0) { 09278 ast_sockaddr_set_port(sa, portno); 09279 ast_rtp_instance_set_remote_address(p->rtp, sa); 09280 if (debug) { 09281 ast_verbose("Peer audio RTP is at port %s\n", 09282 ast_sockaddr_stringify(sa)); 09283 } 09284 09285 ast_rtp_codecs_payloads_copy(&newaudiortp, ast_rtp_instance_get_codecs(p->rtp), p->rtp); 09286 /* Ensure RTCP is enabled since it may be inactive 09287 if we're coming back from a T.38 session */ 09288 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1); 09289 /* Ensure audio RTCP reads are enabled */ 09290 if (p->owner) { 09291 ast_channel_set_fd(p->owner, 1, ast_rtp_instance_fd(p->rtp, 1)); 09292 } 09293 09294 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO) { 09295 ast_clear_flag(&p->flags[0], SIP_DTMF); 09296 if (newnoncodeccapability & AST_RTP_DTMF) { 09297 /* XXX Would it be reasonable to drop the DSP at this point? XXX */ 09298 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 09299 /* Since RFC2833 is now negotiated we need to change some properties of the RTP stream */ 09300 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, 1); 09301 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF_COMPENSATE, ast_test_flag(&p->flags[1], SIP_PAGE2_RFC2833_COMPENSATE)); 09302 } else { 09303 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 09304 } 09305 } 09306 } else if (udptlportno > 0) { 09307 if (debug) 09308 ast_verbose("Got T.38 Re-invite without audio. Keeping RTP active during T.38 session.\n"); 09309 /* Prevent audio RTCP reads */ 09310 if (p->owner) { 09311 ast_channel_set_fd(p->owner, 1, -1); 09312 } 09313 /* Silence RTCP while audio RTP is inactive */ 09314 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0); 09315 } else { 09316 ast_rtp_instance_stop(p->rtp); 09317 if (debug) 09318 ast_verbose("Peer doesn't provide audio\n"); 09319 } 09320 } 09321 09322 /* Setup video address and port */ 09323 if (p->vrtp) { 09324 if (vportno > 0) { 09325 ast_sockaddr_set_port(vsa, vportno); 09326 ast_rtp_instance_set_remote_address(p->vrtp, vsa); 09327 if (debug) { 09328 ast_verbose("Peer video RTP is at port %s\n", 09329 ast_sockaddr_stringify(vsa)); 09330 } 09331 ast_rtp_codecs_payloads_copy(&newvideortp, ast_rtp_instance_get_codecs(p->vrtp), p->vrtp); 09332 } else { 09333 ast_rtp_instance_stop(p->vrtp); 09334 if (debug) 09335 ast_verbose("Peer doesn't provide video\n"); 09336 } 09337 } 09338 09339 /* Setup text address and port */ 09340 if (p->trtp) { 09341 if (tportno > 0) { 09342 ast_sockaddr_set_port(tsa, tportno); 09343 ast_rtp_instance_set_remote_address(p->trtp, tsa); 09344 if (debug) { 09345 ast_verbose("Peer T.140 RTP is at port %s\n", 09346 ast_sockaddr_stringify(tsa)); 09347 } 09348 if ((p->jointcapability & AST_FORMAT_T140RED)) { 09349 p->red = 1; 09350 ast_rtp_red_init(p->trtp, 300, red_data_pt, 2); 09351 } else { 09352 p->red = 0; 09353 } 09354 ast_rtp_codecs_payloads_copy(&newtextrtp, ast_rtp_instance_get_codecs(p->trtp), p->trtp); 09355 } else { 09356 ast_rtp_instance_stop(p->trtp); 09357 if (debug) 09358 ast_verbose("Peer doesn't provide T.140\n"); 09359 } 09360 } 09361 09362 /* Setup image address and port */ 09363 if (p->udptl) { 09364 if (udptlportno > 0) { 09365 if (ast_test_flag(&p->flags[1], SIP_PAGE2_SYMMETRICRTP) && ast_test_flag(&p->flags[1], SIP_PAGE2_UDPTL_DESTINATION)) { 09366 ast_rtp_instance_get_remote_address(p->rtp, isa); 09367 if (!ast_sockaddr_isnull(isa) && debug) { 09368 ast_debug(1, "Peer T.38 UDPTL is set behind NAT and with destination, destination address now %s\n", ast_sockaddr_stringify(isa)); 09369 } 09370 } 09371 ast_sockaddr_set_port(isa, udptlportno); 09372 ast_udptl_set_peer(p->udptl, isa); 09373 if (debug) 09374 ast_debug(1,"Peer T.38 UDPTL is at port %s\n", ast_sockaddr_stringify(isa)); 09375 09376 /* verify the far max ifp can be calculated. this requires far max datagram to be set. */ 09377 if (!ast_udptl_get_far_max_datagram(p->udptl)) { 09378 /* setting to zero will force a default if none was provided by the SDP */ 09379 ast_udptl_set_far_max_datagram(p->udptl, 0); 09380 } 09381 09382 /* Remote party offers T38, we need to update state */ 09383 if ((t38action == SDP_T38_ACCEPT) && 09384 (p->t38.state == T38_LOCAL_REINVITE)) { 09385 change_t38_state(p, T38_ENABLED); 09386 } else if ((t38action == SDP_T38_INITIATE) && 09387 p->owner && p->lastinvite) { 09388 change_t38_state(p, T38_PEER_REINVITE); /* T38 Offered in re-invite from remote party */ 09389 /* If fax detection is enabled then send us off to the fax extension */ 09390 if (ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38)) { 09391 ast_channel_lock(p->owner); 09392 if (strcmp(p->owner->exten, "fax")) { 09393 const char *target_context = S_OR(p->owner->macrocontext, p->owner->context); 09394 ast_channel_unlock(p->owner); 09395 if (ast_exists_extension(p->owner, target_context, "fax", 1, 09396 S_COR(p->owner->caller.id.number.valid, p->owner->caller.id.number.str, NULL))) { 09397 ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to peer T.38 re-INVITE\n", p->owner->name); 09398 pbx_builtin_setvar_helper(p->owner, "FAXEXTEN", p->owner->exten); 09399 if (ast_async_goto(p->owner, target_context, "fax", 1)) { 09400 ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", p->owner->name, target_context); 09401 } 09402 } else { 09403 ast_log(LOG_NOTICE, "T.38 re-INVITE detected but no fax extension\n"); 09404 } 09405 } else { 09406 ast_channel_unlock(p->owner); 09407 } 09408 } 09409 } 09410 } else { 09411 change_t38_state(p, T38_DISABLED); 09412 ast_udptl_stop(p->udptl); 09413 if (debug) 09414 ast_debug(1, "Peer doesn't provide T.38 UDPTL\n"); 09415 } 09416 } 09417 09418 if ((portno == -1) && (p->t38.state != T38_DISABLED)) { 09419 ast_debug(3, "Have T.38 but no audio, accepting offer anyway\n"); 09420 return 0; 09421 } 09422 09423 /* Ok, we're going with this offer */ 09424 ast_debug(2, "We're settling with these formats: %s\n", ast_getformatname_multiple(buf, SIPBUFSIZE, p->jointcapability)); 09425 09426 if (!p->owner) /* There's no open channel owning us so we can return here. For a re-invite or so, we proceed */ 09427 return 0; 09428 09429 ast_debug(4, "We have an owner, now see if we need to change this call\n"); 09430 09431 if (!(p->owner->nativeformats & p->jointcapability) && (p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 09432 if (debug) { 09433 char s1[SIPBUFSIZE], s2[SIPBUFSIZE]; 09434 ast_debug(1, "Oooh, we need to change our audio formats since our peer supports only %s and not %s\n", 09435 ast_getformatname_multiple(s1, SIPBUFSIZE, p->jointcapability), 09436 ast_getformatname_multiple(s2, SIPBUFSIZE, p->owner->nativeformats)); 09437 } 09438 p->owner->nativeformats = ast_codec_choose(&p->prefs, p->jointcapability, 1) | (p->capability & vpeercapability) | (p->capability & tpeercapability); 09439 ast_set_read_format(p->owner, p->owner->readformat); 09440 ast_set_write_format(p->owner, p->owner->writeformat); 09441 } 09442 09443 if (ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD) && (!ast_sockaddr_isnull(sa) || !ast_sockaddr_isnull(vsa) || !ast_sockaddr_isnull(tsa) || !ast_sockaddr_isnull(isa)) && (!sendonly || sendonly == -1)) { 09444 ast_queue_control(p->owner, AST_CONTROL_UNHOLD); 09445 /* Activate a re-invite */ 09446 ast_queue_frame(p->owner, &ast_null_frame); 09447 change_hold_state(p, req, FALSE, sendonly); 09448 } else if ((sockaddr_is_null_or_any(sa) && sockaddr_is_null_or_any(vsa) && sockaddr_is_null_or_any(tsa) && sockaddr_is_null_or_any(isa)) || (sendonly && sendonly != -1)) { 09449 ast_queue_control_data(p->owner, AST_CONTROL_HOLD, 09450 S_OR(p->mohsuggest, NULL), 09451 !ast_strlen_zero(p->mohsuggest) ? strlen(p->mohsuggest) + 1 : 0); 09452 if (sendonly) 09453 ast_rtp_instance_stop(p->rtp); 09454 /* RTCP needs to go ahead, even if we're on hold!!! */ 09455 /* Activate a re-invite */ 09456 ast_queue_frame(p->owner, &ast_null_frame); 09457 change_hold_state(p, req, TRUE, sendonly); 09458 } 09459 09460 return 0; 09461 }
| static int process_sdp_a_audio | ( | const char * | a, | |
| struct sip_pvt * | p, | |||
| struct ast_rtp_codecs * | newaudiortp, | |||
| int * | last_rtpmap_codec | |||
| ) | [static] |
Definition at line 9589 of file chan_sip.c.
References ast_codec_pref_setsize(), ast_debug, AST_FORMAT_G719, AST_FORMAT_SIREN14, AST_FORMAT_SIREN7, ast_getformatname(), ast_log(), ast_rtp_codecs_packetization_set(), ast_rtp_codecs_payload_lookup(), ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_codecs_payloads_unset(), ast_rtp_instance_get_codecs(), AST_RTP_MAX_PT, AST_RTP_OPT_G726_NONSTANDARD, ast_test_flag, ast_verbose, ast_rtp_payload_type::asterisk_format, ast_rtp_payload_type::code, FALSE, format, LOG_WARNING, ast_rtp_codecs::pref, sip_debug_test_pvt(), and TRUE.
Referenced by process_sdp().
09590 { 09591 int found = FALSE; 09592 int codec; 09593 char mimeSubtype[128]; 09594 char fmtp_string[64]; 09595 unsigned int sample_rate; 09596 int debug = sip_debug_test_pvt(p); 09597 09598 if (!strncasecmp(a, "ptime", 5)) { 09599 char *tmp = strrchr(a, ':'); 09600 long int framing = 0; 09601 if (tmp) { 09602 tmp++; 09603 framing = strtol(tmp, NULL, 10); 09604 if (framing == LONG_MIN || framing == LONG_MAX) { 09605 framing = 0; 09606 ast_debug(1, "Can't read framing from SDP: %s\n", a); 09607 } 09608 } 09609 if (framing && p->autoframing) { 09610 struct ast_codec_pref *pref = &ast_rtp_instance_get_codecs(p->rtp)->pref; 09611 int codec_n; 09612 for (codec_n = 0; codec_n < AST_RTP_MAX_PT; codec_n++) { 09613 struct ast_rtp_payload_type format = ast_rtp_codecs_payload_lookup(ast_rtp_instance_get_codecs(p->rtp), codec_n); 09614 if (!format.asterisk_format || !format.code) /* non-codec or not found */ 09615 continue; 09616 ast_debug(1, "Setting framing for %s to %ld\n", ast_getformatname(format.code), framing); 09617 ast_codec_pref_setsize(pref, format.code, framing); 09618 } 09619 ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, pref); 09620 } 09621 found = TRUE; 09622 } else if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 09623 /* We have a rtpmap to handle */ 09624 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 09625 if (!(ast_rtp_codecs_payloads_set_rtpmap_type_rate(newaudiortp, NULL, codec, "audio", mimeSubtype, 09626 ast_test_flag(&p->flags[0], SIP_G726_NONSTANDARD) ? AST_RTP_OPT_G726_NONSTANDARD : 0, sample_rate))) { 09627 if (debug) 09628 ast_verbose("Found audio description format %s for ID %d\n", mimeSubtype, codec); 09629 //found_rtpmap_codecs[last_rtpmap_codec] = codec; 09630 (*last_rtpmap_codec)++; 09631 found = TRUE; 09632 } else { 09633 ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec); 09634 if (debug) 09635 ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec); 09636 } 09637 } else { 09638 if (debug) 09639 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 09640 } 09641 } else if (sscanf(a, "fmtp: %30u %63s", &codec, fmtp_string) == 2) { 09642 struct ast_rtp_payload_type payload; 09643 09644 payload = ast_rtp_codecs_payload_lookup(newaudiortp, codec); 09645 if (payload.code && payload.asterisk_format) { 09646 unsigned int bit_rate; 09647 09648 switch (payload.code) { 09649 case AST_FORMAT_SIREN7: 09650 if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) { 09651 if (bit_rate != 32000) { 09652 ast_log(LOG_WARNING, "Got Siren7 offer at %d bps, but only 32000 bps supported; ignoring.\n", bit_rate); 09653 ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec); 09654 } else { 09655 found = TRUE; 09656 } 09657 } 09658 break; 09659 case AST_FORMAT_SIREN14: 09660 if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) { 09661 if (bit_rate != 48000) { 09662 ast_log(LOG_WARNING, "Got Siren14 offer at %d bps, but only 48000 bps supported; ignoring.\n", bit_rate); 09663 ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec); 09664 } else { 09665 found = TRUE; 09666 } 09667 } 09668 break; 09669 case AST_FORMAT_G719: 09670 if (sscanf(fmtp_string, "bitrate=%30u", &bit_rate) == 1) { 09671 if (bit_rate != 64000) { 09672 ast_log(LOG_WARNING, "Got G.719 offer at %d bps, but only 64000 bps supported; ignoring.\n", bit_rate); 09673 ast_rtp_codecs_payloads_unset(newaudiortp, NULL, codec); 09674 } else { 09675 found = TRUE; 09676 } 09677 } 09678 } 09679 } 09680 } 09681 09682 return found; 09683 }
| static int process_sdp_a_image | ( | const char * | a, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Definition at line 9768 of file chan_sip.c.
References ast_debug, AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, AST_T38_RATE_9600, AST_T38_RATE_MANAGEMENT_LOCAL_TCF, AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF, ast_udptl_set_error_correction_scheme(), ast_udptl_set_far_max_datagram(), FALSE, initialize_udptl(), TRUE, UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by process_sdp().
09769 { 09770 int found = FALSE; 09771 char s[256]; 09772 unsigned int x; 09773 09774 if (initialize_udptl(p)) { 09775 return found; 09776 } 09777 09778 if ((sscanf(a, "T38FaxMaxBuffer:%30u", &x) == 1)) { 09779 ast_debug(3, "MaxBufferSize:%d\n", x); 09780 found = TRUE; 09781 } else if ((sscanf(a, "T38MaxBitRate:%30u", &x) == 1) || (sscanf(a, "T38FaxMaxRate:%30u", &x) == 1)) { 09782 ast_debug(3, "T38MaxBitRate: %d\n", x); 09783 switch (x) { 09784 case 14400: 09785 p->t38.their_parms.rate = AST_T38_RATE_14400; 09786 break; 09787 case 12000: 09788 p->t38.their_parms.rate = AST_T38_RATE_12000; 09789 break; 09790 case 9600: 09791 p->t38.their_parms.rate = AST_T38_RATE_9600; 09792 break; 09793 case 7200: 09794 p->t38.their_parms.rate = AST_T38_RATE_7200; 09795 break; 09796 case 4800: 09797 p->t38.their_parms.rate = AST_T38_RATE_4800; 09798 break; 09799 case 2400: 09800 p->t38.their_parms.rate = AST_T38_RATE_2400; 09801 break; 09802 } 09803 found = TRUE; 09804 } else if ((sscanf(a, "T38FaxVersion:%30u", &x) == 1)) { 09805 ast_debug(3, "FaxVersion: %u\n", x); 09806 p->t38.their_parms.version = x; 09807 found = TRUE; 09808 } else if ((sscanf(a, "T38FaxMaxDatagram:%30u", &x) == 1) || (sscanf(a, "T38MaxDatagram:%30u", &x) == 1)) { 09809 /* override the supplied value if the configuration requests it */ 09810 if (((signed int) p->t38_maxdatagram >= 0) && ((unsigned int) p->t38_maxdatagram > x)) { 09811 ast_debug(1, "Overriding T38FaxMaxDatagram '%d' with '%d'\n", x, p->t38_maxdatagram); 09812 x = p->t38_maxdatagram; 09813 } 09814 ast_debug(3, "FaxMaxDatagram: %u\n", x); 09815 ast_udptl_set_far_max_datagram(p->udptl, x); 09816 found = TRUE; 09817 } else if ((strncmp(a, "T38FaxFillBitRemoval", 20) == 0)) { 09818 if (sscanf(a, "T38FaxFillBitRemoval:%30u", &x) == 1) { 09819 ast_debug(3, "FillBitRemoval: %d\n", x); 09820 if (x == 1) { 09821 p->t38.their_parms.fill_bit_removal = TRUE; 09822 } 09823 } else { 09824 ast_debug(3, "FillBitRemoval\n"); 09825 p->t38.their_parms.fill_bit_removal = TRUE; 09826 } 09827 found = TRUE; 09828 } else if ((strncmp(a, "T38FaxTranscodingMMR", 20) == 0)) { 09829 if (sscanf(a, "T38FaxTranscodingMMR:%30u", &x) == 1) { 09830 ast_debug(3, "Transcoding MMR: %d\n", x); 09831 if (x == 1) { 09832 p->t38.their_parms.transcoding_mmr = TRUE; 09833 } 09834 } else { 09835 ast_debug(3, "Transcoding MMR\n"); 09836 p->t38.their_parms.transcoding_mmr = TRUE; 09837 } 09838 found = TRUE; 09839 } else if ((strncmp(a, "T38FaxTranscodingJBIG", 21) == 0)) { 09840 if (sscanf(a, "T38FaxTranscodingJBIG:%30u", &x) == 1) { 09841 ast_debug(3, "Transcoding JBIG: %d\n", x); 09842 if (x == 1) { 09843 p->t38.their_parms.transcoding_jbig = TRUE; 09844 } 09845 } else { 09846 ast_debug(3, "Transcoding JBIG\n"); 09847 p->t38.their_parms.transcoding_jbig = TRUE; 09848 } 09849 found = TRUE; 09850 } else if ((sscanf(a, "T38FaxRateManagement:%255s", s) == 1)) { 09851 ast_debug(3, "RateManagement: %s\n", s); 09852 if (!strcasecmp(s, "localTCF")) 09853 p->t38.their_parms.rate_management = AST_T38_RATE_MANAGEMENT_LOCAL_TCF; 09854 else if (!strcasecmp(s, "transferredTCF")) 09855 p->t38.their_parms.rate_management = AST_T38_RATE_MANAGEMENT_TRANSFERRED_TCF; 09856 found = TRUE; 09857 } else if ((sscanf(a, "T38FaxUdpEC:%255s", s) == 1)) { 09858 ast_debug(3, "UDP EC: %s\n", s); 09859 if (!strcasecmp(s, "t38UDPRedundancy")) { 09860 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_REDUNDANCY); 09861 } else if (!strcasecmp(s, "t38UDPFEC")) { 09862 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_FEC); 09863 } else { 09864 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 09865 } 09866 found = TRUE; 09867 } 09868 09869 return found; 09870 }
| static int process_sdp_a_sendonly | ( | const char * | a, | |
| int * | sendonly | |||
| ) | [static] |
Definition at line 9569 of file chan_sip.c.
Referenced by process_sdp().
09570 { 09571 int found = FALSE; 09572 09573 if (!strcasecmp(a, "sendonly")) { 09574 if (*sendonly == -1) 09575 *sendonly = 1; 09576 found = TRUE; 09577 } else if (!strcasecmp(a, "inactive")) { 09578 if (*sendonly == -1) 09579 *sendonly = 2; 09580 found = TRUE; 09581 } else if (!strcasecmp(a, "sendrecv")) { 09582 if (*sendonly == -1) 09583 *sendonly = 0; 09584 found = TRUE; 09585 } 09586 return found; 09587 }
| 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] |
Definition at line 9719 of file chan_sip.c.
References AST_RED_MAX_GENERATION, ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_verbose, FALSE, sip_debug_test_pvt(), and TRUE.
Referenced by process_sdp().
09720 { 09721 int found = FALSE; 09722 int codec; 09723 char mimeSubtype[128]; 09724 unsigned int sample_rate; 09725 char *red_cp; 09726 int debug = sip_debug_test_pvt(p); 09727 09728 if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 09729 /* We have a rtpmap to handle */ 09730 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 09731 if (!strncasecmp(mimeSubtype, "T140", 4)) { /* Text */ 09732 if (p->trtp) { 09733 /* ast_verbose("Adding t140 mimeSubtype to textrtp struct\n"); */ 09734 ast_rtp_codecs_payloads_set_rtpmap_type_rate(newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate); 09735 found = TRUE; 09736 } 09737 } else if (!strncasecmp(mimeSubtype, "RED", 3)) { /* Text with Redudancy */ 09738 if (p->trtp) { 09739 ast_rtp_codecs_payloads_set_rtpmap_type_rate(newtextrtp, NULL, codec, "text", mimeSubtype, 0, sample_rate); 09740 sprintf(red_fmtp, "fmtp:%d ", codec); 09741 if (debug) 09742 ast_verbose("RED submimetype has payload type: %d\n", codec); 09743 found = TRUE; 09744 } 09745 } 09746 } else { 09747 if (debug) 09748 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 09749 } 09750 } else if (!strncmp(a, red_fmtp, strlen(red_fmtp))) { 09751 /* count numbers of generations in fmtp */ 09752 red_cp = &red_fmtp[strlen(red_fmtp)]; 09753 strncpy(red_fmtp, a, 100); 09754 09755 sscanf(red_cp, "%30u", &red_data_pt[*red_num_gen]); 09756 red_cp = strtok(red_cp, "/"); 09757 while (red_cp && (*red_num_gen)++ < AST_RED_MAX_GENERATION) { 09758 sscanf(red_cp, "%30u", &red_data_pt[*red_num_gen]); 09759 red_cp = strtok(NULL, "/"); 09760 } 09761 red_cp = red_fmtp; 09762 found = TRUE; 09763 } 09764 09765 return found; 09766 }
| static int process_sdp_a_video | ( | const char * | a, | |
| struct sip_pvt * | p, | |||
| struct ast_rtp_codecs * | newvideortp, | |||
| int * | last_rtpmap_codec | |||
| ) | [static] |
Definition at line 9685 of file chan_sip.c.
References ast_rtp_codecs_payloads_set_rtpmap_type_rate(), ast_rtp_codecs_payloads_unset(), ast_verbose, FALSE, sip_debug_test_pvt(), and TRUE.
Referenced by process_sdp().
09686 { 09687 int found = FALSE; 09688 int codec; 09689 char mimeSubtype[128]; 09690 unsigned int sample_rate; 09691 int debug = sip_debug_test_pvt(p); 09692 09693 if (sscanf(a, "rtpmap: %30u %127[^/]/%30u", &codec, mimeSubtype, &sample_rate) == 3) { 09694 /* We have a rtpmap to handle */ 09695 if (*last_rtpmap_codec < SDP_MAX_RTPMAP_CODECS) { 09696 /* Note: should really look at the '#chans' params too */ 09697 if (!strncasecmp(mimeSubtype, "H26", 3) || !strncasecmp(mimeSubtype, "MP4", 3)) { 09698 if (!(ast_rtp_codecs_payloads_set_rtpmap_type_rate(newvideortp, NULL, codec, "video", mimeSubtype, 0, sample_rate))) { 09699 if (debug) 09700 ast_verbose("Found video description format %s for ID %d\n", mimeSubtype, codec); 09701 //found_rtpmap_codecs[last_rtpmap_codec] = codec; 09702 (*last_rtpmap_codec)++; 09703 found = TRUE; 09704 } else { 09705 ast_rtp_codecs_payloads_unset(newvideortp, NULL, codec); 09706 if (debug) 09707 ast_verbose("Found unknown media description format %s for ID %d\n", mimeSubtype, codec); 09708 } 09709 } 09710 } else { 09711 if (debug) 09712 ast_verbose("Discarded description format %s for ID %d\n", mimeSubtype, codec); 09713 } 09714 } 09715 09716 return found; 09717 }
| static int process_sdp_c | ( | const char * | c, | |
| struct ast_sockaddr * | addr | |||
| ) | [static] |
Definition at line 9542 of file chan_sip.c.
References ast_log(), ast_sockaddr_resolve_first_af(), FALSE, LOG_WARNING, and TRUE.
Referenced by process_sdp().
09543 { 09544 char proto[4], host[258]; 09545 int af; 09546 09547 /* Check for Media-description-level-address */ 09548 if (sscanf(c, "IN %3s %255s", proto, host) == 2) { 09549 if (!strcmp("IP4", proto)) { 09550 af = AF_INET; 09551 } else if (!strcmp("IP6", proto)) { 09552 af = AF_INET6; 09553 } else { 09554 ast_log(LOG_WARNING, "Unknown protocol '%s'.\n", proto); 09555 return FALSE; 09556 } 09557 if (ast_sockaddr_resolve_first_af(addr, host, 0, af)) { 09558 ast_log(LOG_WARNING, "Unable to lookup RTP Audio host in c= line, '%s'\n", c); 09559 return FALSE; 09560 } 09561 return TRUE; 09562 } else { 09563 ast_log(LOG_WARNING, "Invalid host in c= line, '%s'\n", c); 09564 return FALSE; 09565 } 09566 return FALSE; 09567 }
| static int process_sdp_o | ( | const char * | o, | |
| struct sip_pvt * | p | |||
| ) | [static] |
Definition at line 9463 of file chan_sip.c.
References ast_debug, ast_log(), ast_strdupa, ast_strlen_zero(), ast_test_flag, FALSE, LOG_WARNING, and TRUE.
Referenced by process_sdp().
09464 { 09465 char *o_copy; 09466 char *token; 09467 int64_t rua_version; 09468 09469 /* Store the SDP version number of remote UA. This will allow us to 09470 distinguish between session modifications and session refreshes. If 09471 the remote UA does not send an incremented SDP version number in a 09472 subsequent RE-INVITE then that means its not changing media session. 09473 The RE-INVITE may have been sent to update connected party, remote 09474 target or to refresh the session (Session-Timers). Asterisk must not 09475 change media session and increment its own version number in answer 09476 SDP in this case. */ 09477 09478 p->session_modify = TRUE; 09479 09480 if (ast_strlen_zero(o)) { 09481 ast_log(LOG_WARNING, "SDP syntax error. SDP without an o= line\n"); 09482 return FALSE; 09483 } 09484 09485 o_copy = ast_strdupa(o); 09486 token = strsep(&o_copy, " "); /* Skip username */ 09487 if (!o_copy) { 09488 ast_log(LOG_WARNING, "SDP syntax error in o= line username\n"); 09489 return FALSE; 09490 } 09491 token = strsep(&o_copy, " "); /* Skip session-id */ 09492 if (!o_copy) { 09493 ast_log(LOG_WARNING, "SDP syntax error in o= line session-id\n"); 09494 return FALSE; 09495 } 09496 token = strsep(&o_copy, " "); /* Version */ 09497 if (!o_copy) { 09498 ast_log(LOG_WARNING, "SDP syntax error in o= line\n"); 09499 return FALSE; 09500 } 09501 if (!sscanf(token, "%30" SCNd64, &rua_version)) { 09502 ast_log(LOG_WARNING, "SDP syntax error in o= line version\n"); 09503 return FALSE; 09504 } 09505 09506 /* we need to check the SDP version number the other end sent us; 09507 * our rules for deciding what to accept are a bit complex. 09508 * 09509 * 1) if 'ignoresdpversion' has been set for this dialog, then 09510 * we will just accept whatever they sent and assume it is 09511 * a modification of the session, even if it is not 09512 * 2) otherwise, if this is the first SDP we've seen from them 09513 * we accept it 09514 * 3) otherwise, if the new SDP version number is higher than the 09515 * old one, we accept it 09516 * 4) otherwise, if this SDP is in response to us requesting a switch 09517 * to T.38, we accept the SDP, but also generate a warning message 09518 * that this peer should have the 'ignoresdpversion' option set, 09519 * because it is not following the SDP offer/answer RFC; if we did 09520 * not request a switch to T.38, then we stop parsing the SDP, as it 09521 * has not changed from the previous version 09522 */ 09523 09524 if (ast_test_flag(&p->flags[1], SIP_PAGE2_IGNORESDPVERSION) || 09525 (p->sessionversion_remote < 0) || 09526 (p->sessionversion_remote < rua_version)) { 09527 p->sessionversion_remote = rua_version; 09528 } else { 09529 if (p->t38.state == T38_LOCAL_REINVITE) { 09530 p->sessionversion_remote = rua_version; 09531 ast_log(LOG_WARNING, "Call %s responded to our T.38 reinvite without changing SDP version; 'ignoresdpversion' should be set for this peer.\n", p->callid); 09532 } else { 09533 p->session_modify = FALSE; 09534 ast_debug(2, "Call %s responded to our reinvite without changing SDP version; ignoring SDP.\n", p->callid); 09535 return FALSE; 09536 } 09537 } 09538 09539 return TRUE; 09540 }
| static int process_via | ( | struct sip_pvt * | p, | |
| const struct sip_request * | req | |||
| ) | [static] |
Process the Via header according to RFC 3261 section 18.2.2.
| p | a sip_pvt structure that will be modified according to the received header | |
| req | a sip request with a Via header to process |
This function will update the destination of the response according to the Via header in the request and RFC 3261 section 18.2.2. We do not have a transport layer so we ignore certain values like the 'received' param (we set the destination address to the addres the request came from in the respprep() function).
| -1 | error | |
| 0 | success |
Definition at line 7826 of file chan_sip.c.
References addr_is_multicast(), ast_log(), ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, free_via(), get_header(), LOG_ERROR, LOG_WARNING, PARSE_PORT_FORBID, and parse_via().
Referenced by respprep().
07827 { 07828 struct sip_via *via = parse_via(get_header(req, "Via")); 07829 07830 if (!via) { 07831 ast_log(LOG_ERROR, "error processing via header\n"); 07832 return -1; 07833 } 07834 07835 if (via->maddr) { 07836 if (ast_sockaddr_resolve_first_transport(&p->sa, via->maddr, PARSE_PORT_FORBID, p->socket.type)) { 07837 ast_log(LOG_WARNING, "Can't find address for maddr '%s'\n", via->maddr); 07838 ast_log(LOG_ERROR, "error processing via header\n"); 07839 free_via(via); 07840 return -1; 07841 } 07842 07843 if (addr_is_multicast(&p->sa)) { 07844 setsockopt(sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->ttl, sizeof(via->ttl)); 07845 } 07846 } 07847 07848 ast_sockaddr_set_port(&p->sa, via->port ? via->port : STANDARD_SIP_PORT); 07849 07850 free_via(via); 07851 return 0; 07852 }
| static int proxy_update | ( | struct sip_proxy * | proxy | ) | [static] |
Resolve DNS srv name or host name in a sip_proxy structure
Definition at line 3093 of file chan_sip.c.
References ast_get_ip_or_srv(), ast_log(), ast_sockaddr_parse(), ast_sockaddr_set_port, FALSE, get_address_family_filter(), LOG_WARNING, sip_cfg, and TRUE.
Referenced by build_peer(), and reload_config().
03094 { 03095 /* if it's actually an IP address and not a name, 03096 there's no need for a managed lookup */ 03097 if (!ast_sockaddr_parse(&proxy->ip, proxy->name, 0)) { 03098 /* Ok, not an IP address, then let's check if it's a domain or host */ 03099 /* XXX Todo - if we have proxy port, don't do SRV */ 03100 proxy->ip.ss.ss_family = get_address_family_filter(SIP_TRANSPORT_UDP); /* Filter address family */ 03101 if (ast_get_ip_or_srv(&proxy->ip, proxy->name, sip_cfg.srvlookup ? "_sip._udp" : NULL) < 0) { 03102 ast_log(LOG_WARNING, "Unable to locate host '%s'\n", proxy->name); 03103 return FALSE; 03104 } 03105 03106 } 03107 03108 ast_sockaddr_set_port(&proxy->ip, proxy->port); 03109 03110 proxy->last_dnsupdate = time(NULL); 03111 return TRUE; 03112 }
| static int publish_expire | ( | const void * | data | ) | [static] |
Definition at line 1020 of file chan_sip.c.
References ao2_ref, ao2_unlink, ast_assert, event_state_compositor::compositor, and get_esc().
Referenced by create_esc_entry(), handle_sip_publish_modify(), and handle_sip_publish_refresh().
01021 { 01022 struct sip_esc_entry *esc_entry = (struct sip_esc_entry *) data; 01023 struct event_state_compositor *esc = get_esc(esc_entry->event); 01024 01025 ast_assert(esc != NULL); 01026 01027 ao2_unlink(esc->compositor, esc_entry); 01028 ao2_ref(esc_entry, -1); 01029 return 0; 01030 }
| static void pvt_set_needdestroy | ( | struct sip_pvt * | pvt, | |
| const char * | reason | |||
| ) | [inline, static] |
Definition at line 3058 of file chan_sip.c.
References append_history.
Referenced by __sip_autodestruct(), handle_incoming(), handle_request_publish(), handle_request_refer(), handle_request_subscribe(), handle_response(), handle_response_invite(), handle_response_notify(), handle_response_peerpoke(), handle_response_publish(), handle_response_refer(), handle_response_register(), handle_response_subscribe(), retrans_pkt(), sip_hangup(), and sip_reg_timeout().
03059 { 03060 if (pvt->final_destruction_scheduled) { 03061 return; /* This is already scheduled for final destruction, let the scheduler take care of it. */ 03062 } 03063 append_history(pvt, "NeedDestroy", "Setting needdestroy because %s", reason); 03064 pvt->needdestroy = 1; 03065 }
| static struct sip_peer * realtime_peer | ( | const char * | newpeername, | |
| struct ast_sockaddr * | addr, | |||
| int | devstate_only, | |||
| int | which_objects | |||
| ) | [static, read] |
realtime_peer: Get peer from realtime storage Checks the "sippeers" realtime family from extconfig.conf Checks the "sipregs" realtime family from extconfig.conf if it's configured. This returns a pointer to a peer and because we use build_peer, we can rest assured that the refcount is bumped.
Definition at line 4931 of file chan_sip.c.
References ao2_t_link, ast_check_realtime(), ast_copy_flags, ast_copy_string(), ast_debug, AST_SCHED_REPLACE_UNREF, ast_sockaddr_isnull(), ast_sockaddr_stringify_addr(), ast_test_flag, ast_variables_destroy(), build_peer(), cleanup(), expire_register(), ipaddr, ast_variable::name, ast_variable::next, realtime_peer_by_addr(), realtime_peer_by_name(), ref_peer(), sip_cfg, TRUE, unref_peer(), ast_variable::value, and var.
Referenced by find_peer().
04932 { 04933 struct sip_peer *peer = NULL; 04934 struct ast_variable *var = NULL; 04935 struct ast_variable *varregs = NULL; 04936 char ipaddr[INET6_ADDRSTRLEN]; 04937 int realtimeregs = ast_check_realtime("sipregs"); 04938 04939 if (addr) { 04940 ast_copy_string(ipaddr, ast_sockaddr_stringify_addr(addr), sizeof(ipaddr)); 04941 } else { 04942 ipaddr[0] = '\0'; 04943 } 04944 04945 if (newpeername && realtime_peer_by_name(&newpeername, addr, ipaddr, &var, realtimeregs ? &varregs : NULL)) { 04946 ; 04947 } else if (addr && realtime_peer_by_addr(&newpeername, addr, ipaddr, &var, realtimeregs ? &varregs : NULL)) { 04948 ; 04949 } else { 04950 return NULL; 04951 } 04952 04953 /* If we're looking for users, don't return peers (although this check 04954 * should probably be done in realtime_peer_by_* instead...) */ 04955 if (which_objects == FINDUSERS) { 04956 struct ast_variable *tmp; 04957 for (tmp = var; tmp; tmp = tmp->next) { 04958 if (!strcasecmp(tmp->name, "type") && (!strcasecmp(tmp->value, "peer"))) { 04959 goto cleanup; 04960 } 04961 } 04962 } 04963 04964 /* Peer found in realtime, now build it in memory */ 04965 peer = build_peer(newpeername, var, varregs, TRUE, devstate_only); 04966 if (!peer) { 04967 goto cleanup; 04968 } 04969 04970 ast_debug(3, "-REALTIME- loading peer from database to memory. Name: %s. Peer objects: %d\n", peer->name, rpeerobjs); 04971 04972 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && !devstate_only) { 04973 /* Cache peer */ 04974 ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_RTAUTOCLEAR|SIP_PAGE2_RTCACHEFRIENDS); 04975 if (ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR)) { 04976 AST_SCHED_REPLACE_UNREF(peer->expire, sched, sip_cfg.rtautoclear * 1000, expire_register, peer, 04977 unref_peer(_data, "remove registration ref"), 04978 unref_peer(peer, "remove registration ref"), 04979 ref_peer(peer, "add registration ref")); 04980 } 04981 ao2_t_link(peers, peer, "link peer into peers table"); 04982 if (!ast_sockaddr_isnull(&peer->addr)) { 04983 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 04984 } 04985 } 04986 peer->is_realtime = 1; 04987 04988 cleanup: 04989 ast_variables_destroy(var); 04990 ast_variables_destroy(varregs); 04991 return peer; 04992 }
| static int realtime_peer_by_addr | ( | const char ** | name, | |
| struct ast_sockaddr * | addr, | |||
| const char * | ipaddr, | |||
| struct ast_variable ** | var, | |||
| struct ast_variable ** | varregs | |||
| ) | [static] |
Definition at line 4862 of file chan_sip.c.
References ast_copy_string(), ast_load_realtime(), ast_log(), ast_sockaddr_stringify_port(), ast_variables_destroy(), get_insecure_variable_from_sippeers(), get_insecure_variable_from_sipregs(), get_name_from_variable(), LOG_WARNING, realtime_peer_get_sippeer_helper(), and SENTINEL.
Referenced by realtime_peer().
04863 { 04864 char portstring[6]; /* up to 5 digits plus null terminator */ 04865 ast_copy_string(portstring, ast_sockaddr_stringify_port(addr), sizeof(portstring)); 04866 04867 /* We're not finding this peer by this name anymore. Reset it. */ 04868 *name = NULL; 04869 04870 /* First check for fixed IP hosts */ 04871 if ((*var = ast_load_realtime("sippeers", "host", ipaddr, "port", portstring, SENTINEL))) { 04872 ; 04873 /* Check for registered hosts (in sipregs) */ 04874 } else if (varregs && (*varregs = ast_load_realtime("sipregs", "ipaddr", ipaddr, "port", portstring, SENTINEL)) && 04875 (*var = realtime_peer_get_sippeer_helper(name, varregs))) { 04876 ; 04877 /* Check for registered hosts (in sippeers) */ 04878 } else if (!varregs && (*var = ast_load_realtime("sippeers", "ipaddr", ipaddr, "port", portstring, SENTINEL))) { 04879 ; 04880 /* We couldn't match on ipaddress and port, so we need to check if port is insecure */ 04881 } else if ((*var = get_insecure_variable_from_sippeers("host", ipaddr))) { 04882 ; 04883 /* Same as above, but try the IP address field (in sipregs) 04884 * Observe that it fetches the name/var at the same time, without the 04885 * realtime_peer_get_sippeer_helper. Also note that it is quite inefficient. 04886 * Avoid sipregs if possible. */ 04887 } else if (varregs && (*varregs = get_insecure_variable_from_sipregs("ipaddr", ipaddr, var))) { 04888 ; 04889 /* Same as above, but try the IP address field (in sippeers) */ 04890 } else if (!varregs && (*var = get_insecure_variable_from_sippeers("ipaddr", ipaddr))) { 04891 ; 04892 } 04893 04894 /* Nothing found? */ 04895 if (!*var) { 04896 return 0; 04897 } 04898 04899 /* Check peer name. It must not be empty. There may exist a 04900 * different match that does have a name, but it's too late for 04901 * that now. */ 04902 if (!*name && !(*name = get_name_from_variable(*var))) { 04903 ast_log(LOG_WARNING, "Found peer for IP %s but it has no name\n", ipaddr); 04904 ast_variables_destroy(*var); 04905 *var = NULL; 04906 if (varregs && *varregs) { 04907 ast_variables_destroy(*varregs); 04908 *varregs = NULL; 04909 } 04910 return 0; 04911 } 04912 04913 /* Make sure varregs is populated if var is. The inverse, 04914 * ensuring that var is set when varregs is, is taken 04915 * care of by realtime_peer_get_sippeer_helper(). */ 04916 if (varregs && !*varregs) { 04917 *varregs = ast_load_realtime("sipregs", "name", *name, SENTINEL); 04918 } 04919 return 1; 04920 }
| 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] |
Definition at line 4790 of file chan_sip.c.
References ast_free, ast_load_realtime(), ast_sockaddr_cmp(), ast_sockaddr_resolve(), ast_variables_destroy(), get_address_family_filter(), ast_variable::name, ast_variable::next, PARSE_PORT_FORBID, SENTINEL, and ast_variable::value.
Referenced by realtime_peer().
04791 { 04792 /* Peer by name and host=dynamic */ 04793 if ((*var = ast_load_realtime("sippeers", "name", *name, "host", "dynamic", SENTINEL))) { 04794 ; 04795 /* Peer by name and host=IP */ 04796 } else if (addr && !(*var = ast_load_realtime("sippeers", "name", *name, "host", ipaddr, SENTINEL))) { 04797 ; 04798 /* Peer by name and host=HOSTNAME */ 04799 } else if ((*var = ast_load_realtime("sippeers", "name", *name, SENTINEL))) { 04800 /*!\note 04801 * If this one loaded something, then we need to ensure that the host 04802 * field matched. The only reason why we can't have this as a criteria 04803 * is because we only have the IP address and the host field might be 04804 * set as a name (and the reverse PTR might not match). 04805 */ 04806 if (addr) { 04807 struct ast_variable *tmp; 04808 for (tmp = *var; tmp; tmp = tmp->next) { 04809 if (!strcasecmp(tmp->name, "host")) { 04810 struct ast_sockaddr *addrs = NULL; 04811 04812 if (ast_sockaddr_resolve(&addrs, 04813 tmp->value, 04814 PARSE_PORT_FORBID, 04815 get_address_family_filter(SIP_TRANSPORT_UDP)) <= 0 || 04816 ast_sockaddr_cmp(&addrs[0], addr)) { 04817 /* No match */ 04818 ast_variables_destroy(*var); 04819 *var = NULL; 04820 } 04821 ast_free(addrs); 04822 break; 04823 } 04824 } 04825 } 04826 } 04827 04828 /* Did we find anything? */ 04829 if (*var) { 04830 if (varregs) { 04831 *varregs = ast_load_realtime("sipregs", "name", *name, SENTINEL); 04832 } 04833 return 1; 04834 } 04835 return 0; 04836 }
| static struct ast_variable* realtime_peer_get_sippeer_helper | ( | const char ** | name, | |
| struct ast_variable ** | varregs | |||
| ) | [static, read] |
Definition at line 4844 of file chan_sip.c.
References ast_load_realtime(), ast_log(), ast_variables_destroy(), get_name_from_variable(), LOG_WARNING, SENTINEL, and var.
Referenced by realtime_peer_by_addr().
04844 { 04845 struct ast_variable *var = NULL; 04846 const char *old_name = *name; 04847 *name = get_name_from_variable(*varregs); 04848 if (!*name || !(var = ast_load_realtime("sippeers", "name", *name, SENTINEL))) { 04849 if (!*name) { 04850 ast_log(LOG_WARNING, "Found sipreg but it has no name\n"); 04851 } 04852 ast_variables_destroy(*varregs); 04853 *varregs = NULL; 04854 *name = old_name; 04855 } 04856 return var; 04857 }
| static void realtime_update_peer | ( | const char * | peername, | |
| struct ast_sockaddr * | addr, | |||
| const char * | username, | |||
| const char * | fullcontact, | |||
| const char * | useragent, | |||
| int | expirey, | |||
| unsigned short | deprecated_username, | |||
| int | lastms | |||
| ) | [static] |
Update peer object in realtime storage If the Asterisk system name is set in asterisk.conf, we will use that name and store that in the "regserver" field in the sippeers table to facilitate multi-server setups.
Definition at line 4500 of file chan_sip.c.
References ast_check_realtime(), ast_config_AST_SYSTEM_NAME, ast_copy_string(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), ast_strlen_zero(), ast_update_realtime(), ipaddr, SENTINEL, and sip_cfg.
Referenced by update_peer().
04501 { 04502 char port[10]; 04503 char ipaddr[INET6_ADDRSTRLEN]; 04504 char regseconds[20]; 04505 char *tablename = NULL; 04506 char str_lastms[20]; 04507 04508 const char *sysname = ast_config_AST_SYSTEM_NAME; 04509 char *syslabel = NULL; 04510 04511 time_t nowtime = time(NULL) + expirey; 04512 const char *fc = fullcontact ? "fullcontact" : NULL; 04513 04514 int realtimeregs = ast_check_realtime("sipregs"); 04515 04516 tablename = realtimeregs ? "sipregs" : "sippeers"; 04517 04518 04519 snprintf(str_lastms, sizeof(str_lastms), "%d", lastms); 04520 snprintf(regseconds, sizeof(regseconds), "%d", (int)nowtime); /* Expiration time */ 04521 ast_copy_string(ipaddr, ast_sockaddr_isnull(addr) ? "" : ast_sockaddr_stringify_addr(addr), sizeof(ipaddr)); 04522 ast_copy_string(port, ast_sockaddr_port(addr) ? ast_sockaddr_stringify_port(addr) : "", sizeof(port)); 04523 04524 if (ast_strlen_zero(sysname)) /* No system name, disable this */ 04525 sysname = NULL; 04526 else if (sip_cfg.rtsave_sysname) 04527 syslabel = "regserver"; 04528 04529 /* XXX IMPORTANT: Anytime you add a new parameter to be updated, you 04530 * must also add it to contrib/scripts/asterisk.ldap-schema, 04531 * contrib/scripts/asterisk.ldif, 04532 * and to configs/res_ldap.conf.sample as described in 04533 * bugs 15156 and 15895 04534 */ 04535 if (fc) { 04536 ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr, 04537 "port", port, "regseconds", regseconds, 04538 deprecated_username ? "username" : "defaultuser", defaultuser, 04539 "useragent", useragent, "lastms", str_lastms, 04540 fc, fullcontact, syslabel, sysname, SENTINEL); /* note fc and syslabel _can_ be NULL */ 04541 } else { 04542 ast_update_realtime(tablename, "name", peername, "ipaddr", ipaddr, 04543 "port", port, "regseconds", regseconds, 04544 "useragent", useragent, "lastms", str_lastms, 04545 deprecated_username ? "username" : "defaultuser", defaultuser, 04546 syslabel, sysname, SENTINEL); /* note syslabel _can_ be NULL */ 04547 } 04548 }
| static void receive_message | ( | struct sip_pvt * | p, | |
| struct sip_request * | req | |||
| ) | [static] |
Receive SIP MESSAGE method messages.
Definition at line 16367 of file chan_sip.c.
References AST_FRAME_TEXT, ast_log(), ast_queue_frame(), ast_verbose, ast_frame::data, ast_frame::datalen, f, ast_frame::frametype, get_header(), get_msg_text(), ast_frame_subclass::integer, LOG_WARNING, ast_frame::offset, ast_frame::ptr, sip_debug_test_pvt(), sip_scheddestroy(), ast_frame::subclass, and transmit_response().
Referenced by handle_request_message().
16368 { 16369 char buf[1400]; 16370 char *bufp; 16371 struct ast_frame f; 16372 const char *content_type = get_header(req, "Content-Type"); 16373 16374 if (strncmp(content_type, "text/plain", strlen("text/plain"))) { /* No text/plain attachment */ 16375 transmit_response(p, "415 Unsupported Media Type", req); /* Good enough, or? */ 16376 if (!p->owner) 16377 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16378 return; 16379 } 16380 16381 if (get_msg_text(buf, sizeof(buf), req)) { 16382 ast_log(LOG_WARNING, "Unable to retrieve text from %s\n", p->callid); 16383 transmit_response(p, "500 Internal Server Error", req); 16384 if (!p->owner) { 16385 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16386 } 16387 return; 16388 } 16389 16390 /* Strip trailing line feeds from message body. (get_msg_text may add 16391 * a trailing linefeed and we don't need any at the end) */ 16392 bufp = buf + strlen(buf); 16393 while (--bufp >= buf && *bufp == '\n') { 16394 *bufp = '\0'; 16395 } 16396 16397 if (p->owner) { 16398 if (sip_debug_test_pvt(p)) 16399 ast_verbose("SIP Text message received: '%s'\n", buf); 16400 memset(&f, 0, sizeof(f)); 16401 f.frametype = AST_FRAME_TEXT; 16402 f.subclass.integer = 0; 16403 f.offset = 0; 16404 f.data.ptr = buf; 16405 f.datalen = strlen(buf) + 1; 16406 ast_queue_frame(p->owner, &f); 16407 transmit_response(p, "202 Accepted", req); /* We respond 202 accepted, since we relay the message */ 16408 return; 16409 } 16410 16411 /* Message outside of a call, we do not support that */ 16412 ast_log(LOG_WARNING, "Received message to %s from %s, dropped it...\n Content-Type:%s\n Message: %s\n", get_header(req, "To"), get_header(req, "From"), content_type, buf); 16413 transmit_response(p, "405 Method Not Allowed", req); 16414 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 16415 return; 16416 }
| static struct sip_peer* ref_peer | ( | struct sip_peer * | peer, | |
| char * | tag | |||
| ) | [static, read] |
Definition at line 2849 of file chan_sip.c.
References ao2_t_ref.
Referenced by build_peer(), create_addr(), handle_request_invite(), handle_request_subscribe(), handle_response_peerpoke(), parse_register_contact(), realtime_peer(), reg_source_db(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_unregister(), and update_call_counter().
02850 { 02851 ao2_t_ref(peer, 1, tag); 02852 return peer; 02853 }
| static void ref_proxy | ( | struct sip_pvt * | pvt, | |
| struct sip_proxy * | proxy | |||
| ) | [static] |
maintain proper refcounts for a sip_pvt's outboundproxy
This function sets pvt's outboundproxy pointer to the one referenced by the proxy parameter. Because proxy may be a refcounted object, and because pvt's old outboundproxy may also be a refcounted object, we need to maintain the proper refcounts.
| pvt | The sip_pvt for which we wish to set the outboundproxy | |
| proxy | The sip_proxy which we will point pvt towards. |
Definition at line 2931 of file chan_sip.c.
References ao2_ref, and sip_cfg.
Referenced by __sip_ack(), __sip_subscribe_mwi_do(), create_addr(), and create_addr_from_peer().
02932 { 02933 struct sip_proxy *old_obproxy = pvt->outboundproxy; 02934 /* The sip_cfg.outboundproxy is statically allocated, and so 02935 * we don't ever need to adjust refcounts for it 02936 */ 02937 if (proxy && proxy != &sip_cfg.outboundproxy) { 02938 ao2_ref(proxy, +1); 02939 } 02940 pvt->outboundproxy = proxy; 02941 if (old_obproxy && old_obproxy != &sip_cfg.outboundproxy) { 02942 ao2_ref(old_obproxy, -1); 02943 } 02944 }
| static const char * referstatus2str | ( | enum referstatus | rstatus | ) | [static] |
Convert transfer status to string.
Definition at line 3053 of file chan_sip.c.
References map_x_s().
Referenced by show_channels_cb().
03054 { 03055 return map_x_s(referstatusstrings, rstatus, ""); 03056 }
| static void reg_source_db | ( | struct sip_peer * | peer | ) | [static] |
Get registration details from Asterisk DB.
Definition at line 13852 of file chan_sip.c.
References args, AST_APP_ARG, ast_db_get(), ast_debug, AST_DECLARE_APP_ARGS, AST_NONSTANDARD_RAW_ARGS, ast_random(), AST_SCHED_REPLACE_UNREF, ast_sockaddr_copy(), ast_sockaddr_parse(), ast_sockaddr_stringify_host(), ast_string_field_set, expire_register(), ref_peer(), register_peer_exten(), sip_cfg, sip_poke_peer(), sip_poke_peer_s(), TRUE, and unref_peer().
Referenced by build_peer(), and temp_peer().
13853 { 13854 char data[256]; 13855 struct ast_sockaddr sa; 13856 int expire; 13857 char full_addr[128]; 13858 AST_DECLARE_APP_ARGS(args, 13859 AST_APP_ARG(addr); 13860 AST_APP_ARG(port); 13861 AST_APP_ARG(expiry_str); 13862 AST_APP_ARG(username); 13863 AST_APP_ARG(contact); 13864 ); 13865 13866 /* If read-only RT backend, then refresh from local DB cache */ 13867 if (peer->rt_fromcontact && sip_cfg.peer_rtupdate) { 13868 return; 13869 } 13870 if (ast_db_get("SIP/Registry", peer->name, data, sizeof(data))) { 13871 return; 13872 } 13873 13874 AST_NONSTANDARD_RAW_ARGS(args, data, ':'); 13875 13876 snprintf(full_addr, sizeof(full_addr), "%s:%s", args.addr, args.port); 13877 13878 if (!ast_sockaddr_parse(&sa, full_addr, 0)) { 13879 return; 13880 } 13881 13882 if (args.expiry_str) { 13883 expire = atoi(args.expiry_str); 13884 } else { 13885 return; 13886 } 13887 13888 if (args.username) { 13889 ast_string_field_set(peer, username, args.username); 13890 } 13891 if (args.contact) { 13892 ast_string_field_set(peer, fullcontact, args.contact); 13893 } 13894 13895 ast_debug(2, "SIP Seeding peer from astdb: '%s' at %s@%s for %d\n", 13896 peer->name, peer->username, ast_sockaddr_stringify_host(&sa), expire); 13897 13898 ast_sockaddr_copy(&peer->addr, &sa); 13899 if (sipsock < 0) { 13900 /* SIP isn't up yet, so schedule a poke only, pretty soon */ 13901 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, ast_random() % 5000 + 1, sip_poke_peer_s, peer, 13902 unref_peer(_data, "removing poke peer ref"), 13903 unref_peer(peer, "removing poke peer ref"), 13904 ref_peer(peer, "adding poke peer ref")); 13905 } else { 13906 sip_poke_peer(peer, 0); 13907 } 13908 AST_SCHED_REPLACE_UNREF(peer->expire, sched, (expire + 10) * 1000, expire_register, peer, 13909 unref_peer(_data, "remove registration ref"), 13910 unref_peer(peer, "remove registration ref"), 13911 ref_peer(peer, "add registration ref")); 13912 register_peer_exten(peer, TRUE); 13913 }
| static void register_peer_exten | ( | struct sip_peer * | peer, | |
| int | onoff | |||
| ) | [static] |
Automatically add peer extension to dial plan.
Definition at line 4551 of file chan_sip.c.
References ast_add_extension(), ast_context_find(), ast_context_remove_extension(), ast_copy_string(), ast_exists_extension(), ast_free_ptr(), ast_log(), ast_strdup, ast_strlen_zero(), context, E_MATCH, ext, LOG_WARNING, pbx_find_extension(), S_OR, and sip_cfg.
Referenced by expire_register(), handle_response_peerpoke(), parse_register_contact(), reg_source_db(), sip_destroy_peer(), and sip_poke_noanswer().
04552 { 04553 char multi[256]; 04554 char *stringp, *ext, *context; 04555 struct pbx_find_info q = { .stacklen = 0 }; 04556 04557 /* XXX note that sip_cfg.regcontext is both a global 'enable' flag and 04558 * the name of the global regexten context, if not specified 04559 * individually. 04560 */ 04561 if (ast_strlen_zero(sip_cfg.regcontext)) 04562 return; 04563 04564 ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi)); 04565 stringp = multi; 04566 while ((ext = strsep(&stringp, "&"))) { 04567 if ((context = strchr(ext, '@'))) { 04568 *context++ = '\0'; /* split ext@context */ 04569 if (!ast_context_find(context)) { 04570 ast_log(LOG_WARNING, "Context %s must exist in regcontext= in sip.conf!\n", context); 04571 continue; 04572 } 04573 } else { 04574 context = sip_cfg.regcontext; 04575 } 04576 if (onoff) { 04577 if (!ast_exists_extension(NULL, context, ext, 1, NULL)) { 04578 ast_add_extension(context, 1, ext, 1, NULL, NULL, "Noop", 04579 ast_strdup(peer->name), ast_free_ptr, "SIP"); 04580 } 04581 } else if (pbx_find_extension(NULL, NULL, &q, context, ext, 1, NULL, "", E_MATCH)) { 04582 ast_context_remove_extension(context, ext, 1, NULL); 04583 } 04584 } 04585 }
| static enum check_auth_result register_verify | ( | struct sip_pvt * | p, | |
| struct ast_sockaddr * | addr, | |||
| struct sip_request * | req, | |||
| const char * | uri | |||
| ) | [static] |
Verify registration of user
Definition at line 14814 of file chan_sip.c.
References ao2_lock, ao2_t_link, ao2_unlock, ast_apply_ha(), ast_copy_flags, ast_copy_string(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), AST_LIST_EMPTY, ast_log(), ast_set_flag, ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_sockaddr_stringify_port(), ast_strdupa, ast_string_field_set, ast_strlen_zero(), build_contact(), check_auth(), check_request_transport, check_sip_domain(), EVENT_FLAG_SYSTEM, exten, extract_host_from_hostport(), FALSE, find_peer(), get_header(), get_in_brackets(), LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, name, parse_register_contact(), parse_uri_legacy_check(), remove_uri_parameters(), sip_cancel_destroy(), sip_cfg, SIP_PEDANTIC_DECODE, sip_send_mwi_to_peer(), temp_peer(), terminate_uri(), transmit_fake_auth_response(), transmit_response(), transmit_response_with_date(), TRUE, unref_peer(), update_peer(), and update_peer_lastmsgssent().
Referenced by handle_request_register().
14816 { 14817 enum check_auth_result res = AUTH_NOT_FOUND; 14818 struct sip_peer *peer; 14819 char tmp[256]; 14820 char *c, *name, *unused_password, *domain; 14821 char *uri2 = ast_strdupa(uri); 14822 int send_mwi = 0; 14823 14824 terminate_uri(uri2); 14825 14826 ast_copy_string(tmp, get_header(req, "To"), sizeof(tmp)); 14827 14828 c = get_in_brackets(tmp); 14829 c = remove_uri_parameters(c); 14830 14831 if (parse_uri_legacy_check(c, "sip:,sips:", &name, &unused_password, &domain, NULL)) { 14832 ast_log(LOG_NOTICE, "Invalid to address: '%s' from %s (missing sip:) trying to use anyway...\n", c, ast_sockaddr_stringify_addr(addr)); 14833 return -1; 14834 } 14835 14836 SIP_PEDANTIC_DECODE(name); 14837 SIP_PEDANTIC_DECODE(domain); 14838 14839 extract_host_from_hostport(&domain); 14840 14841 if (ast_strlen_zero(domain)) { 14842 /* <sip:name@[EMPTY]>, never good */ 14843 transmit_response(p, "404 Not found", &p->initreq); 14844 return AUTH_UNKNOWN_DOMAIN; 14845 } 14846 14847 if (ast_strlen_zero(name)) { 14848 /* <sip:[EMPTY][@]hostport>, unsure whether valid for 14849 * registration. RFC 3261, 10.2 states: 14850 * "The To header field and the Request-URI field typically 14851 * differ, as the former contains a user name." 14852 * But, Asterisk has always treated the domain-only uri as a 14853 * username: we allow admins to create accounts described by 14854 * domain name. */ 14855 name = domain; 14856 } 14857 14858 /* This here differs from 1.4 and 1.6: the domain matching ACLs were 14859 * skipped if it was a domain-only URI (used as username). Here we treat 14860 * <sip:hostport> as <sip:host@hostport> and won't forget to test the 14861 * domain ACLs against host. */ 14862 if (!AST_LIST_EMPTY(&domain_list)) { 14863 if (!check_sip_domain(domain, NULL, 0)) { 14864 if (sip_cfg.alwaysauthreject) { 14865 transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE); 14866 } else { 14867 transmit_response(p, "404 Not found (unknown domain)", &p->initreq); 14868 } 14869 return AUTH_UNKNOWN_DOMAIN; 14870 } 14871 } 14872 14873 ast_string_field_set(p, exten, name); 14874 build_contact(p); 14875 if (req->ignore) { 14876 /* Expires is a special case, where we only want to load the peer if this isn't a deregistration attempt */ 14877 const char *expires = get_header(req, "Expires"); 14878 int expire = atoi(expires); 14879 14880 if (ast_strlen_zero(expires)) { /* No expires header; look in Contact */ 14881 if ((expires = strcasestr(get_header(req, "Contact"), ";expires="))) { 14882 expire = atoi(expires + 9); 14883 } 14884 } 14885 if (!ast_strlen_zero(expires) && expire == 0) { 14886 transmit_response_with_date(p, "200 OK", req); 14887 return 0; 14888 } 14889 } 14890 peer = find_peer(name, NULL, TRUE, FINDPEERS, FALSE, 0); 14891 14892 if (!(peer && ast_apply_ha(peer->ha, addr))) { 14893 /* Peer fails ACL check */ 14894 if (peer) { 14895 unref_peer(peer, "register_verify: unref_peer: from find_peer operation"); 14896 peer = NULL; 14897 res = AUTH_ACL_FAILED; 14898 } else { 14899 res = AUTH_NOT_FOUND; 14900 } 14901 } 14902 14903 if (peer) { 14904 ao2_lock(peer); 14905 if (!peer->host_dynamic) { 14906 ast_log(LOG_ERROR, "Peer '%s' is trying to register, but not configured as host=dynamic\n", peer->name); 14907 res = AUTH_PEER_NOT_DYNAMIC; 14908 } else { 14909 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_NAT_FORCE_RPORT); 14910 if (!(res = check_auth(p, req, peer->name, peer->secret, peer->md5secret, SIP_REGISTER, uri2, XMIT_UNRELIABLE, req->ignore))) { 14911 if (sip_cancel_destroy(p)) 14912 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 14913 14914 if (check_request_transport(peer, req)) { 14915 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 14916 transmit_response_with_date(p, "403 Forbidden", req); 14917 res = AUTH_BAD_TRANSPORT; 14918 } else { 14919 14920 /* We have a successful registration attempt with proper authentication, 14921 now, update the peer */ 14922 switch (parse_register_contact(p, peer, req)) { 14923 case PARSE_REGISTER_DENIED: 14924 ast_log(LOG_WARNING, "Registration denied because of contact ACL\n"); 14925 transmit_response_with_date(p, "603 Denied", req); 14926 res = 0; 14927 break; 14928 case PARSE_REGISTER_FAILED: 14929 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 14930 transmit_response_with_date(p, "400 Bad Request", req); 14931 res = 0; 14932 break; 14933 case PARSE_REGISTER_QUERY: 14934 ast_string_field_set(p, fullcontact, peer->fullcontact); 14935 transmit_response_with_date(p, "200 OK", req); 14936 res = 0; 14937 break; 14938 case PARSE_REGISTER_UPDATE: 14939 ast_string_field_set(p, fullcontact, peer->fullcontact); 14940 update_peer(peer, p->expiry); 14941 /* Say OK and ask subsystem to retransmit msg counter */ 14942 transmit_response_with_date(p, "200 OK", req); 14943 send_mwi = 1; 14944 res = 0; 14945 break; 14946 } 14947 } 14948 14949 } 14950 } 14951 ao2_unlock(peer); 14952 } 14953 if (!peer && sip_cfg.autocreatepeer) { 14954 /* Create peer if we have autocreate mode enabled */ 14955 peer = temp_peer(name); 14956 if (peer) { 14957 ao2_t_link(peers, peer, "link peer into peer table"); 14958 if (!ast_sockaddr_isnull(&peer->addr)) { 14959 ao2_t_link(peers_by_ip, peer, "link peer into peers-by-ip table"); 14960 } 14961 ao2_lock(peer); 14962 if (sip_cancel_destroy(p)) 14963 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 14964 switch (parse_register_contact(p, peer, req)) { 14965 case PARSE_REGISTER_DENIED: 14966 ast_log(LOG_WARNING, "Registration denied because of contact ACL\n"); 14967 transmit_response_with_date(p, "403 Forbidden (ACL)", req); 14968 res = 0; 14969 break; 14970 case PARSE_REGISTER_FAILED: 14971 ast_log(LOG_WARNING, "Failed to parse contact info\n"); 14972 transmit_response_with_date(p, "400 Bad Request", req); 14973 res = 0; 14974 break; 14975 case PARSE_REGISTER_QUERY: 14976 ast_string_field_set(p, fullcontact, peer->fullcontact); 14977 transmit_response_with_date(p, "200 OK", req); 14978 send_mwi = 1; 14979 res = 0; 14980 break; 14981 case PARSE_REGISTER_UPDATE: 14982 ast_string_field_set(p, fullcontact, peer->fullcontact); 14983 /* Say OK and ask subsystem to retransmit msg counter */ 14984 transmit_response_with_date(p, "200 OK", req); 14985 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Registered\r\nAddress: %s\r\n", peer->name, ast_sockaddr_stringify(addr)); 14986 send_mwi = 1; 14987 res = 0; 14988 break; 14989 } 14990 ao2_unlock(peer); 14991 } 14992 } 14993 if (!res) { 14994 if (send_mwi) { 14995 sip_send_mwi_to_peer(peer, 0); 14996 } else { 14997 update_peer_lastmsgssent(peer, -1, 0); 14998 } 14999 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 15000 } 15001 if (res < 0) { 15002 switch (res) { 15003 case AUTH_SECRET_FAILED: 15004 /* Wrong password in authentication. Go away, don't try again until you fixed it */ 15005 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 15006 if (global_authfailureevents) { 15007 const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr)); 15008 const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr)); 15009 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 15010 "ChannelType: SIP\r\n" 15011 "Peer: SIP/%s\r\n" 15012 "PeerStatus: Rejected\r\n" 15013 "Cause: AUTH_SECRET_FAILED\r\n" 15014 "Address: %s\r\n" 15015 "Port: %s\r\n", 15016 name, peer_addr, peer_port); 15017 } 15018 break; 15019 case AUTH_USERNAME_MISMATCH: 15020 /* Username and digest username does not match. 15021 Asterisk uses the From: username for authentication. We need the 15022 devices to use the same authentication user name until we support 15023 proper authentication by digest auth name */ 15024 case AUTH_NOT_FOUND: 15025 case AUTH_PEER_NOT_DYNAMIC: 15026 case AUTH_ACL_FAILED: 15027 if (sip_cfg.alwaysauthreject) { 15028 transmit_fake_auth_response(p, SIP_REGISTER, &p->initreq, XMIT_UNRELIABLE); 15029 if (global_authfailureevents) { 15030 const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr)); 15031 const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr)); 15032 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 15033 "ChannelType: SIP\r\n" 15034 "Peer: SIP/%s\r\n" 15035 "PeerStatus: Rejected\r\n" 15036 "Cause: %s\r\n" 15037 "Address: %s\r\n" 15038 "Port: %s\r\n", 15039 name, 15040 res == AUTH_PEER_NOT_DYNAMIC ? "AUTH_PEER_NOT_DYNAMIC" : "URI_NOT_FOUND", 15041 peer_addr, peer_port); 15042 } 15043 } else { 15044 /* URI not found */ 15045 if (res == AUTH_PEER_NOT_DYNAMIC) { 15046 transmit_response(p, "403 Forbidden", &p->initreq); 15047 if (global_authfailureevents) { 15048 const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr)); 15049 const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr)); 15050 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 15051 "ChannelType: SIP\r\n" 15052 "Peer: SIP/%s\r\n" 15053 "PeerStatus: Rejected\r\n" 15054 "Cause: AUTH_PEER_NOT_DYNAMIC\r\n" 15055 "Address: %s\r\n" 15056 "Port: %s\r\n", 15057 name, peer_addr, peer_port); 15058 } 15059 } else { 15060 transmit_response(p, "404 Not found", &p->initreq); 15061 if (global_authfailureevents) { 15062 const char *peer_addr = ast_strdupa(ast_sockaddr_stringify_addr(addr)); 15063 const char *peer_port = ast_strdupa(ast_sockaddr_stringify_port(addr)); 15064 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", 15065 "ChannelType: SIP\r\n" 15066 "Peer: SIP/%s\r\n" 15067 "PeerStatus: Rejected\r\n" 15068 "Cause: %s\r\n" 15069 "Address: %s\r\n" 15070 "Port: %s\r\n", 15071 name, 15072 (res == AUTH_USERNAME_MISMATCH) ? "AUTH_USERNAME_MISMATCH" : "URI_NOT_FOUND", 15073 peer_addr, peer_port); 15074 } 15075 } 15076 } 15077 break; 15078 case AUTH_BAD_TRANSPORT: 15079 default: 15080 break; 15081 } 15082 } 15083 if (peer) { 15084 unref_peer(peer, "register_verify: unref_peer: tossing stack peer pointer at end of func"); 15085 } 15086 15087 return res; 15088 }
| static struct sip_registry* registry_addref | ( | struct sip_registry * | reg, | |
| char * | tag | |||
| ) | [static, read] |
Add object reference to SIP registry.
Definition at line 3035 of file chan_sip.c.
References ast_debug, and ASTOBJ_REF.
Referenced by handle_response_register(), sip_send_all_registers(), and transmit_register().
03036 { 03037 ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount + 1); 03038 return ASTOBJ_REF(reg); /* Add pointer to registry in packet */ 03039 }
| void * registry_unref | ( | struct sip_registry * | reg, | |
| char * | tag | |||
| ) | [static] |
Definition at line 3027 of file chan_sip.c.
References ast_debug, ASTOBJ_UNREF, and sip_registry_destroy().
Referenced by __sip_destroy(), cleanup_all_regs(), dialog_unlink_all(), handle_response_register(), sip_reg_timeout(), sip_register(), sip_registry_destroy(), sip_reregister(), sip_send_all_registers(), and transmit_register().
03028 { 03029 ast_debug(3, "SIP Registry %s: refcount now %d\n", reg->hostname, reg->refcount - 1); 03030 ASTOBJ_UNREF(reg, sip_registry_destroy); 03031 return NULL; 03032 }
| static const char * regstate2str | ( | enum sipregistrystate | regstate | ) | [static] |
Convert registration state status to string.
Definition at line 13124 of file chan_sip.c.
References map_x_s().
Referenced by handle_response_register(), manager_show_registry(), sip_reg_timeout(), and sip_show_registry().
13125 { 13126 return map_x_s(regstatestrings, regstate, "Unknown"); 13127 }
| static int reinvite_timeout | ( | const void * | data | ) | [static] |
Definition at line 6228 of file chan_sip.c.
References ao2_unlock, ast_channel_unlock, ast_channel_unref, check_pendings(), and sip_pvt_lock_full().
Referenced by sip_hangup().
06229 { 06230 struct sip_pvt *dialog = (struct sip_pvt *) data; 06231 struct ast_channel *owner = sip_pvt_lock_full(dialog); 06232 dialog->reinviteid = -1; 06233 check_pendings(dialog); 06234 if (owner) { 06235 ast_channel_unlock(owner); 06236 ast_channel_unref(owner); 06237 } 06238 ao2_unlock(dialog); 06239 dialog_unref(dialog, "unref for reinvite timeout"); 06240 return 0; 06241 }
| static int reload | ( | void | ) | [static] |
Part of Asterisk module interface.
Definition at line 29969 of file chan_sip.c.
References sip_reload().
29970 { 29971 if (sip_reload(0, 0, NULL)) 29972 return 0; 29973 return 1; 29974 }
| static int reload_config | ( | enum channelreloadreason | reason | ) | [static] |
Re-read SIP.conf config file.
< Don't force proxy usage, use route: headers
< Keep track of hold status for a peer
< Match auth username if available instead of From: Default off.
< Default DTMF setting: RFC2833
< Allow re-invites
< Default to nat=force_rport
Definition at line 28123 of file chan_sip.c.
References ast_tcptls_session_args::accept_fd, add_realm_authentication(), add_sip_domain(), ao2_t_callback, ao2_t_link, ao2_t_ref, ast_append_ha(), ast_bind(), ast_category_browse(), AST_CERTFILE, ast_clear_flag, ast_config_AST_SYSTEM_NAME, ast_config_destroy(), ast_config_load, ast_context_find_or_create(), ast_copy_string(), ast_debug, ast_enable_packet_fragmentation(), ast_false(), ast_find_ourip(), AST_FLAGS_ALL, ast_free, ast_free_ha(), ast_get_version(), ast_jb_read_conf(), AST_LIST_EMPTY, ast_log(), AST_MAX_CONTEXT, ast_mutex_lock, ast_mutex_unlock, ast_parse_allow_disallow(), ast_parse_arg(), ast_set2_flag, ast_set_flag, ast_set_qos(), ast_skip_blanks(), ast_sockaddr_cmp(), ast_sockaddr_copy(), ast_sockaddr_is_any(), ast_sockaddr_is_ipv6(), ast_sockaddr_isnull(), ast_sockaddr_parse(), ast_sockaddr_port, ast_sockaddr_resolve_first(), ast_sockaddr_set_port, ast_sockaddr_setnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_ssl_setup(), ast_str2cos(), ast_str2tos(), ast_strdup, ast_strdupa, ast_strip(), ast_strlen_zero(), ast_tcptls_server_start(), ast_test_flag, ast_tls_read_conf(), ast_true(), ast_unload_realtime(), ast_variable_browse(), ast_variable_retrieve(), ast_verb, ASTOBJ_CONTAINER_DESTROYALL, bindaddr, build_peer(), ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, CHANNEL_MODULE_LOAD, channelreloadreason2txt(), ast_tls_config::cipher, cleanup_all_regs(), cleanup_stale_contexts(), clear_sip_domains(), CONFIG_FLAG_FILEUNCHANGED, CONFIG_STATUS_FILEINVALID, CONFIG_STATUS_FILEUNCHANGED, context, DEFAULT_AUTHLIMIT, DEFAULT_AUTHTIMEOUT, DEFAULT_CONTEXT, DEFAULT_MAXMS, DEFAULT_PARKINGLOT, default_prefs, DEFAULT_REALM, display_nat_warning(), dummy(), ast_tls_config::enabled, errno, EVENT_FLAG_SYSTEM, externaddr, FALSE, gen, global_jbconf, handle_common_options(), handle_t38_options(), internip, ast_variable::lineno, ast_tcptls_session_args::local_address, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, mark_parsed_methods(), MAXHOSTNAMELEN, media_address, ast_variable::name, network_change_event_subscribe(), network_change_event_unsubscribe(), ast_variable::next, OBJ_NODATA, PARSE_ADDR, PARSE_DEFAULT, PARSE_IN_RANGE, PARSE_INT32, peer_markall_func(), port_str2int(), proxy_update(), ast_tls_config::pvtfile, regl, S_OR, secret, sip_cfg, sip_parse_host(), sip_register(), sip_registry_destroy(), sip_subscribe_mwi(), str2stmode(), str2strefresher(), ast_tcptls_session_args::tls_cfg, TRUE, unref_peer(), and ast_variable::value.
Referenced by load_module(), and sip_do_reload().
28124 { 28125 struct ast_config *cfg, *ucfg; 28126 struct ast_variable *v; 28127 struct sip_peer *peer; 28128 char *cat, *stringp, *context, *oldregcontext; 28129 char newcontexts[AST_MAX_CONTEXT], oldcontexts[AST_MAX_CONTEXT]; 28130 struct ast_flags dummy[2]; 28131 struct ast_flags config_flags = { reason == CHANNEL_MODULE_LOAD ? 0 : ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) ? 0 : CONFIG_FLAG_FILEUNCHANGED }; 28132 int auto_sip_domains = FALSE; 28133 struct ast_sockaddr old_bindaddr = bindaddr; 28134 int registry_count = 0, peer_count = 0, timerb_set = 0, timert1_set = 0; 28135 int subscribe_network_change = 1; 28136 time_t run_start, run_end; 28137 int bindport = 0; 28138 28139 run_start = time(0); 28140 ast_unload_realtime("sipregs"); 28141 ast_unload_realtime("sippeers"); 28142 cfg = ast_config_load(config, config_flags); 28143 28144 /* We *must* have a config file otherwise stop immediately */ 28145 if (!cfg) { 28146 ast_log(LOG_NOTICE, "Unable to load config %s\n", config); 28147 return -1; 28148 } else if (cfg == CONFIG_STATUS_FILEUNCHANGED) { 28149 ucfg = ast_config_load("users.conf", config_flags); 28150 if (ucfg == CONFIG_STATUS_FILEUNCHANGED) { 28151 return 1; 28152 } else if (ucfg == CONFIG_STATUS_FILEINVALID) { 28153 ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n"); 28154 return 1; 28155 } 28156 /* Must reread both files, because one changed */ 28157 ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); 28158 if ((cfg = ast_config_load(config, config_flags)) == CONFIG_STATUS_FILEINVALID) { 28159 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config); 28160 ast_config_destroy(ucfg); 28161 return 1; 28162 } 28163 if (!cfg) { 28164 /* should have been able to reload here */ 28165 ast_log(LOG_NOTICE, "Unable to load config %s\n", config); 28166 return -1; 28167 } 28168 } else if (cfg == CONFIG_STATUS_FILEINVALID) { 28169 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed\n", config); 28170 return 1; 28171 } else { 28172 ast_clear_flag(&config_flags, CONFIG_FLAG_FILEUNCHANGED); 28173 if ((ucfg = ast_config_load("users.conf", config_flags)) == CONFIG_STATUS_FILEINVALID) { 28174 ast_log(LOG_ERROR, "Contents of users.conf are invalid and cannot be parsed\n"); 28175 ast_config_destroy(cfg); 28176 return 1; 28177 } 28178 } 28179 28180 ast_free_ha(sip_cfg.contact_ha); 28181 sip_cfg.contact_ha = NULL; 28182 28183 default_tls_cfg.enabled = FALSE; /* Default: Disable TLS */ 28184 28185 if (reason != CHANNEL_MODULE_LOAD) { 28186 ast_debug(4, "--------------- SIP reload started\n"); 28187 28188 clear_sip_domains(); 28189 ast_mutex_lock(&authl_lock); 28190 if (authl) { 28191 ao2_t_ref(authl, -1, "Removing old global authentication"); 28192 authl = NULL; 28193 } 28194 ast_mutex_unlock(&authl_lock); 28195 28196 28197 cleanup_all_regs(); 28198 /* Then, actually destroy users and registry */ 28199 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 28200 ast_debug(4, "--------------- Done destroying registry list\n"); 28201 ao2_t_callback(peers, OBJ_NODATA, peer_markall_func, NULL, "callback to mark all peers"); 28202 } 28203 28204 /* Reset certificate handling for TLS sessions */ 28205 if (reason != CHANNEL_MODULE_LOAD) { 28206 ast_free(default_tls_cfg.certfile); 28207 ast_free(default_tls_cfg.pvtfile); 28208 ast_free(default_tls_cfg.cipher); 28209 ast_free(default_tls_cfg.cafile); 28210 ast_free(default_tls_cfg.capath); 28211 } 28212 default_tls_cfg.certfile = ast_strdup(AST_CERTFILE); /*XXX Not sure if this is useful */ 28213 default_tls_cfg.pvtfile = ast_strdup(""); 28214 default_tls_cfg.cipher = ast_strdup(""); 28215 default_tls_cfg.cafile = ast_strdup(""); 28216 default_tls_cfg.capath = ast_strdup(""); 28217 28218 /* Initialize copy of current sip_cfg.regcontext for later use in removing stale contexts */ 28219 ast_copy_string(oldcontexts, sip_cfg.regcontext, sizeof(oldcontexts)); 28220 oldregcontext = oldcontexts; 28221 28222 /* Clear all flags before setting default values */ 28223 /* Preserve debugging settings for console */ 28224 sipdebug &= sip_debug_console; 28225 ast_clear_flag(&global_flags[0], AST_FLAGS_ALL); 28226 ast_clear_flag(&global_flags[1], AST_FLAGS_ALL); 28227 ast_clear_flag(&global_flags[2], AST_FLAGS_ALL); 28228 28229 /* Reset IP addresses */ 28230 ast_sockaddr_parse(&bindaddr, "0.0.0.0:0", 0); 28231 memset(&internip, 0, sizeof(internip)); 28232 28233 /* Free memory for local network address mask */ 28234 ast_free_ha(localaddr); 28235 memset(&localaddr, 0, sizeof(localaddr)); 28236 memset(&externaddr, 0, sizeof(externaddr)); 28237 memset(&media_address, 0, sizeof(media_address)); 28238 memset(&default_prefs, 0 , sizeof(default_prefs)); 28239 memset(&sip_cfg.outboundproxy, 0, sizeof(struct sip_proxy)); 28240 sip_cfg.outboundproxy.force = FALSE; /*!< Don't force proxy usage, use route: headers */ 28241 default_transports = SIP_TRANSPORT_UDP; 28242 default_primary_transport = SIP_TRANSPORT_UDP; 28243 ourport_tcp = STANDARD_SIP_PORT; 28244 ourport_tls = STANDARD_TLS_PORT; 28245 externtcpport = STANDARD_SIP_PORT; 28246 externtlsport = STANDARD_TLS_PORT; 28247 sip_cfg.srvlookup = DEFAULT_SRVLOOKUP; 28248 global_tos_sip = DEFAULT_TOS_SIP; 28249 global_tos_audio = DEFAULT_TOS_AUDIO; 28250 global_tos_video = DEFAULT_TOS_VIDEO; 28251 global_tos_text = DEFAULT_TOS_TEXT; 28252 global_cos_sip = DEFAULT_COS_SIP; 28253 global_cos_audio = DEFAULT_COS_AUDIO; 28254 global_cos_video = DEFAULT_COS_VIDEO; 28255 global_cos_text = DEFAULT_COS_TEXT; 28256 28257 externhost[0] = '\0'; /* External host name (for behind NAT DynDNS support) */ 28258 externexpire = 0; /* Expiration for DNS re-issuing */ 28259 externrefresh = 10; 28260 28261 /* Reset channel settings to default before re-configuring */ 28262 sip_cfg.allow_external_domains = DEFAULT_ALLOW_EXT_DOM; /* Allow external invites */ 28263 sip_cfg.regcontext[0] = '\0'; 28264 sip_cfg.capability = DEFAULT_CAPABILITY; 28265 sip_cfg.regextenonqualify = DEFAULT_REGEXTENONQUALIFY; 28266 sip_cfg.legacy_useroption_parsing = DEFAULT_LEGACY_USEROPTION_PARSING; 28267 sip_cfg.notifyringing = DEFAULT_NOTIFYRINGING; 28268 sip_cfg.notifycid = DEFAULT_NOTIFYCID; 28269 sip_cfg.notifyhold = FALSE; /*!< Keep track of hold status for a peer */ 28270 sip_cfg.directrtpsetup = FALSE; /* Experimental feature, disabled by default */ 28271 sip_cfg.alwaysauthreject = DEFAULT_ALWAYSAUTHREJECT; 28272 sip_cfg.auth_options_requests = DEFAULT_AUTH_OPTIONS; 28273 sip_cfg.allowsubscribe = FALSE; 28274 sip_cfg.disallowed_methods = SIP_UNKNOWN; 28275 sip_cfg.contact_ha = NULL; /* Reset the contact ACL */ 28276 snprintf(global_useragent, sizeof(global_useragent), "%s %s", DEFAULT_USERAGENT, ast_get_version()); 28277 snprintf(global_sdpsession, sizeof(global_sdpsession), "%s %s", DEFAULT_SDPSESSION, ast_get_version()); 28278 snprintf(global_sdpowner, sizeof(global_sdpowner), "%s", DEFAULT_SDPOWNER); 28279 global_prematuremediafilter = TRUE; 28280 ast_copy_string(default_notifymime, DEFAULT_NOTIFYMIME, sizeof(default_notifymime)); 28281 ast_copy_string(sip_cfg.realm, S_OR(ast_config_AST_SYSTEM_NAME, DEFAULT_REALM), sizeof(sip_cfg.realm)); 28282 sip_cfg.domainsasrealm = DEFAULT_DOMAINSASREALM; 28283 ast_copy_string(default_callerid, DEFAULT_CALLERID, sizeof(default_callerid)); 28284 ast_copy_string(default_mwi_from, DEFAULT_MWI_FROM, sizeof(default_mwi_from)); 28285 sip_cfg.compactheaders = DEFAULT_COMPACTHEADERS; 28286 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 28287 global_regattempts_max = 0; 28288 sip_cfg.pedanticsipchecking = DEFAULT_PEDANTIC; 28289 sip_cfg.autocreatepeer = DEFAULT_AUTOCREATEPEER; 28290 global_autoframing = 0; 28291 sip_cfg.allowguest = DEFAULT_ALLOWGUEST; 28292 global_callcounter = DEFAULT_CALLCOUNTER; 28293 global_match_auth_username = FALSE; /*!< Match auth username if available instead of From: Default off. */ 28294 global_rtptimeout = 0; 28295 global_rtpholdtimeout = 0; 28296 global_rtpkeepalive = DEFAULT_RTPKEEPALIVE; 28297 sip_cfg.allowtransfer = TRANSFER_OPENFORALL; /* Merrily accept all transfers by default */ 28298 sip_cfg.rtautoclear = 120; 28299 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE); /* Default for all devices: TRUE */ 28300 ast_set_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP_YES); /* Default for all devices: Yes */ 28301 sip_cfg.peer_rtupdate = TRUE; 28302 global_dynamic_exclude_static = 0; /* Exclude static peers */ 28303 sip_cfg.tcp_enabled = FALSE; 28304 28305 /* Session-Timers */ 28306 global_st_mode = SESSION_TIMER_MODE_ACCEPT; 28307 global_st_refresher = SESSION_TIMER_REFRESHER_UAS; 28308 global_min_se = DEFAULT_MIN_SE; 28309 global_max_se = DEFAULT_MAX_SE; 28310 28311 /* Peer poking settings */ 28312 global_qualify_gap = DEFAULT_QUALIFY_GAP; 28313 global_qualify_peers = DEFAULT_QUALIFY_PEERS; 28314 28315 /* Initialize some reasonable defaults at SIP reload (used both for channel and as default for devices */ 28316 ast_copy_string(sip_cfg.default_context, DEFAULT_CONTEXT, sizeof(sip_cfg.default_context)); 28317 sip_cfg.default_subscribecontext[0] = '\0'; 28318 sip_cfg.default_max_forwards = DEFAULT_MAX_FORWARDS; 28319 default_language[0] = '\0'; 28320 default_fromdomain[0] = '\0'; 28321 default_fromdomainport = 0; 28322 default_qualify = DEFAULT_QUALIFY; 28323 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 28324 ast_copy_string(default_mohinterpret, DEFAULT_MOHINTERPRET, sizeof(default_mohinterpret)); 28325 ast_copy_string(default_mohsuggest, DEFAULT_MOHSUGGEST, sizeof(default_mohsuggest)); 28326 ast_copy_string(default_vmexten, DEFAULT_VMEXTEN, sizeof(default_vmexten)); 28327 ast_set_flag(&global_flags[0], SIP_DTMF_RFC2833); /*!< Default DTMF setting: RFC2833 */ 28328 ast_set_flag(&global_flags[0], SIP_DIRECT_MEDIA); /*!< Allow re-invites */ 28329 ast_set_flag(&global_flags[0], SIP_NAT_FORCE_RPORT); /*!< Default to nat=force_rport */ 28330 ast_copy_string(default_engine, DEFAULT_ENGINE, sizeof(default_engine)); 28331 ast_copy_string(default_parkinglot, DEFAULT_PARKINGLOT, sizeof(default_parkinglot)); 28332 28333 /* Debugging settings, always default to off */ 28334 dumphistory = FALSE; 28335 recordhistory = FALSE; 28336 sipdebug &= ~sip_debug_config; 28337 28338 /* Misc settings for the channel */ 28339 global_relaxdtmf = FALSE; 28340 sip_cfg.callevents = DEFAULT_CALLEVENTS; 28341 global_authfailureevents = FALSE; 28342 global_t1 = DEFAULT_TIMER_T1; 28343 global_timer_b = 64 * DEFAULT_TIMER_T1; 28344 global_t1min = DEFAULT_T1MIN; 28345 global_qualifyfreq = DEFAULT_QUALIFYFREQ; 28346 global_t38_maxdatagram = -1; 28347 global_shrinkcallerid = 1; 28348 authlimit = DEFAULT_AUTHLIMIT; 28349 authtimeout = DEFAULT_AUTHTIMEOUT; 28350 global_store_sip_cause = DEFAULT_STORE_SIP_CAUSE; 28351 28352 sip_cfg.matchexternaddrlocally = DEFAULT_MATCHEXTERNADDRLOCALLY; 28353 28354 /* Copy the default jb config over global_jbconf */ 28355 memcpy(&global_jbconf, &default_jbconf, sizeof(struct ast_jb_conf)); 28356 28357 ast_clear_flag(&global_flags[1], SIP_PAGE2_FAX_DETECT); 28358 ast_clear_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT | SIP_PAGE2_VIDEOSUPPORT_ALWAYS); 28359 ast_clear_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT); 28360 ast_clear_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION); 28361 28362 28363 /* Read the [general] config section of sip.conf (or from realtime config) */ 28364 for (v = ast_variable_browse(cfg, "general"); v; v = v->next) { 28365 if (handle_common_options(&global_flags[0], &dummy[0], v)) { 28366 continue; 28367 } 28368 if (handle_t38_options(&global_flags[0], &dummy[0], v, &global_t38_maxdatagram)) { 28369 continue; 28370 } 28371 /* handle jb conf */ 28372 if (!ast_jb_read_conf(&global_jbconf, v->name, v->value)) 28373 continue; 28374 28375 /* handle tls conf */ 28376 if (!ast_tls_read_conf(&default_tls_cfg, &sip_tls_desc, v->name, v->value)) { 28377 continue; 28378 } 28379 28380 if (!strcasecmp(v->name, "context")) { 28381 ast_copy_string(sip_cfg.default_context, v->value, sizeof(sip_cfg.default_context)); 28382 } else if (!strcasecmp(v->name, "subscribecontext")) { 28383 ast_copy_string(sip_cfg.default_subscribecontext, v->value, sizeof(sip_cfg.default_subscribecontext)); 28384 } else if (!strcasecmp(v->name, "callcounter")) { 28385 global_callcounter = ast_true(v->value) ? 1 : 0; 28386 } else if (!strcasecmp(v->name, "allowguest")) { 28387 sip_cfg.allowguest = ast_true(v->value) ? 1 : 0; 28388 } else if (!strcasecmp(v->name, "realm")) { 28389 ast_copy_string(sip_cfg.realm, v->value, sizeof(sip_cfg.realm)); 28390 } else if (!strcasecmp(v->name, "domainsasrealm")) { 28391 sip_cfg.domainsasrealm = ast_true(v->value); 28392 } else if (!strcasecmp(v->name, "useragent")) { 28393 ast_copy_string(global_useragent, v->value, sizeof(global_useragent)); 28394 ast_debug(1, "Setting SIP channel User-Agent Name to %s\n", global_useragent); 28395 } else if (!strcasecmp(v->name, "sdpsession")) { 28396 ast_copy_string(global_sdpsession, v->value, sizeof(global_sdpsession)); 28397 } else if (!strcasecmp(v->name, "sdpowner")) { 28398 /* Field cannot contain spaces */ 28399 if (!strstr(v->value, " ")) { 28400 ast_copy_string(global_sdpowner, v->value, sizeof(global_sdpowner)); 28401 } else { 28402 ast_log(LOG_WARNING, "'%s' must not contain spaces at line %d. Using default.\n", v->value, v->lineno); 28403 } 28404 } else if (!strcasecmp(v->name, "allowtransfer")) { 28405 sip_cfg.allowtransfer = ast_true(v->value) ? TRANSFER_OPENFORALL : TRANSFER_CLOSED; 28406 } else if (!strcasecmp(v->name, "rtcachefriends")) { 28407 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_RTCACHEFRIENDS); 28408 } else if (!strcasecmp(v->name, "rtsavesysname")) { 28409 sip_cfg.rtsave_sysname = ast_true(v->value); 28410 } else if (!strcasecmp(v->name, "rtupdate")) { 28411 sip_cfg.peer_rtupdate = ast_true(v->value); 28412 } else if (!strcasecmp(v->name, "ignoreregexpire")) { 28413 sip_cfg.ignore_regexpire = ast_true(v->value); 28414 } else if (!strcasecmp(v->name, "timert1")) { 28415 /* Defaults to 500ms, but RFC 3261 states that it is recommended 28416 * for the value to be set higher, though a lower value is only 28417 * allowed on private networks unconnected to the Internet. */ 28418 global_t1 = atoi(v->value); 28419 } else if (!strcasecmp(v->name, "timerb")) { 28420 int tmp = atoi(v->value); 28421 if (tmp < 500) { 28422 global_timer_b = global_t1 * 64; 28423 ast_log(LOG_WARNING, "Invalid value for timerb ('%s'). Setting to default ('%d').\n", v->value, global_timer_b); 28424 } 28425 timerb_set = 1; 28426 } else if (!strcasecmp(v->name, "t1min")) { 28427 global_t1min = atoi(v->value); 28428 } else if (!strcasecmp(v->name, "transport")) { 28429 char *val = ast_strdupa(v->value); 28430 char *trans; 28431 28432 default_transports = default_primary_transport = 0; 28433 while ((trans = strsep(&val, ","))) { 28434 trans = ast_skip_blanks(trans); 28435 28436 if (!strncasecmp(trans, "udp", 3)) { 28437 default_transports |= SIP_TRANSPORT_UDP; 28438 } else if (!strncasecmp(trans, "tcp", 3)) { 28439 default_transports |= SIP_TRANSPORT_TCP; 28440 } else if (!strncasecmp(trans, "tls", 3)) { 28441 default_transports |= SIP_TRANSPORT_TLS; 28442 } else { 28443 ast_log(LOG_NOTICE, "'%s' is not a valid transport type. if no other is specified, udp will be used.\n", trans); 28444 } 28445 if (default_primary_transport == 0) { 28446 default_primary_transport = default_transports; 28447 } 28448 } 28449 } else if (!strcasecmp(v->name, "tcpenable")) { 28450 if (!ast_false(v->value)) { 28451 ast_debug(2, "Enabling TCP socket for listening\n"); 28452 sip_cfg.tcp_enabled = TRUE; 28453 } 28454 } else if (!strcasecmp(v->name, "tcpbindaddr")) { 28455 if (ast_parse_arg(v->value, PARSE_ADDR, 28456 &sip_tcp_desc.local_address)) { 28457 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", 28458 v->name, v->value, v->lineno, config); 28459 } 28460 ast_debug(2, "Setting TCP socket address to %s\n", 28461 ast_sockaddr_stringify(&sip_tcp_desc.local_address)); 28462 } else if (!strcasecmp(v->name, "dynamic_exclude_static") || !strcasecmp(v->name, "dynamic_excludes_static")) { 28463 global_dynamic_exclude_static = ast_true(v->value); 28464 } else if (!strcasecmp(v->name, "contactpermit") || !strcasecmp(v->name, "contactdeny")) { 28465 int ha_error = 0; 28466 sip_cfg.contact_ha = ast_append_ha(v->name + 7, v->value, sip_cfg.contact_ha, &ha_error); 28467 if (ha_error) { 28468 ast_log(LOG_ERROR, "Bad ACL entry in configuration line %d : %s\n", v->lineno, v->value); 28469 } 28470 } else if (!strcasecmp(v->name, "rtautoclear")) { 28471 int i = atoi(v->value); 28472 if (i > 0) { 28473 sip_cfg.rtautoclear = i; 28474 } else { 28475 i = 0; 28476 } 28477 ast_set2_flag(&global_flags[1], i || ast_true(v->value), SIP_PAGE2_RTAUTOCLEAR); 28478 } else if (!strcasecmp(v->name, "usereqphone")) { 28479 ast_set2_flag(&global_flags[0], ast_true(v->value), SIP_USEREQPHONE); 28480 } else if (!strcasecmp(v->name, "prematuremedia")) { 28481 global_prematuremediafilter = ast_true(v->value); 28482 } else if (!strcasecmp(v->name, "relaxdtmf")) { 28483 global_relaxdtmf = ast_true(v->value); 28484 } else if (!strcasecmp(v->name, "vmexten")) { 28485 ast_copy_string(default_vmexten, v->value, sizeof(default_vmexten)); 28486 } else if (!strcasecmp(v->name, "rtptimeout")) { 28487 if ((sscanf(v->value, "%30d", &global_rtptimeout) != 1) || (global_rtptimeout < 0)) { 28488 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 28489 global_rtptimeout = 0; 28490 } 28491 } else if (!strcasecmp(v->name, "rtpholdtimeout")) { 28492 if ((sscanf(v->value, "%30d", &global_rtpholdtimeout) != 1) || (global_rtpholdtimeout < 0)) { 28493 ast_log(LOG_WARNING, "'%s' is not a valid RTP hold time at line %d. Using default.\n", v->value, v->lineno); 28494 global_rtpholdtimeout = 0; 28495 } 28496 } else if (!strcasecmp(v->name, "rtpkeepalive")) { 28497 if ((sscanf(v->value, "%30d", &global_rtpkeepalive) != 1) || (global_rtpkeepalive < 0)) { 28498 ast_log(LOG_WARNING, "'%s' is not a valid RTP keepalive time at line %d. Using default.\n", v->value, v->lineno); 28499 global_rtpkeepalive = DEFAULT_RTPKEEPALIVE; 28500 } 28501 } else if (!strcasecmp(v->name, "compactheaders")) { 28502 sip_cfg.compactheaders = ast_true(v->value); 28503 } else if (!strcasecmp(v->name, "notifymimetype")) { 28504 ast_copy_string(default_notifymime, v->value, sizeof(default_notifymime)); 28505 } else if (!strcasecmp(v->name, "directrtpsetup")) { 28506 sip_cfg.directrtpsetup = ast_true(v->value); 28507 } else if (!strcasecmp(v->name, "notifyringing")) { 28508 sip_cfg.notifyringing = ast_true(v->value); 28509 } else if (!strcasecmp(v->name, "notifyhold")) { 28510 sip_cfg.notifyhold = ast_true(v->value); 28511 } else if (!strcasecmp(v->name, "notifycid")) { 28512 if (!strcasecmp(v->value, "ignore-context")) { 28513 sip_cfg.notifycid = IGNORE_CONTEXT; 28514 } else { 28515 sip_cfg.notifycid = ast_true(v->value) ? ENABLED : DISABLED; 28516 } 28517 } else if (!strcasecmp(v->name, "alwaysauthreject")) { 28518 sip_cfg.alwaysauthreject = ast_true(v->value); 28519 } else if (!strcasecmp(v->name, "auth_options_requests")) { 28520 if (ast_true(v->value)) { 28521 sip_cfg.auth_options_requests = 1; 28522 } 28523 } else if (!strcasecmp(v->name, "mohinterpret")) { 28524 ast_copy_string(default_mohinterpret, v->value, sizeof(default_mohinterpret)); 28525 } else if (!strcasecmp(v->name, "mohsuggest")) { 28526 ast_copy_string(default_mohsuggest, v->value, sizeof(default_mohsuggest)); 28527 } else if (!strcasecmp(v->name, "language")) { 28528 ast_copy_string(default_language, v->value, sizeof(default_language)); 28529 } else if (!strcasecmp(v->name, "regcontext")) { 28530 ast_copy_string(newcontexts, v->value, sizeof(newcontexts)); 28531 stringp = newcontexts; 28532 /* Let's remove any contexts that are no longer defined in regcontext */ 28533 cleanup_stale_contexts(stringp, oldregcontext); 28534 /* Create contexts if they don't exist already */ 28535 while ((context = strsep(&stringp, "&"))) { 28536 ast_copy_string(used_context, context, sizeof(used_context)); 28537 ast_context_find_or_create(NULL, NULL, context, "SIP"); 28538 } 28539 ast_copy_string(sip_cfg.regcontext, v->value, sizeof(sip_cfg.regcontext)); 28540 } else if (!strcasecmp(v->name, "regextenonqualify")) { 28541 sip_cfg.regextenonqualify = ast_true(v->value); 28542 } else if (!strcasecmp(v->name, "legacy_useroption_parsing")) { 28543 sip_cfg.legacy_useroption_parsing = ast_true(v->value); 28544 } else if (!strcasecmp(v->name, "callerid")) { 28545 ast_copy_string(default_callerid, v->value, sizeof(default_callerid)); 28546 } else if (!strcasecmp(v->name, "mwi_from")) { 28547 ast_copy_string(default_mwi_from, v->value, sizeof(default_mwi_from)); 28548 } else if (!strcasecmp(v->name, "fromdomain")) { 28549 char *fromdomainport; 28550 ast_copy_string(default_fromdomain, v->value, sizeof(default_fromdomain)); 28551 if ((fromdomainport = strchr(default_fromdomain, ':'))) { 28552 *fromdomainport++ = '\0'; 28553 if (!(default_fromdomainport = port_str2int(fromdomainport, 0))) { 28554 ast_log(LOG_NOTICE, "'%s' is not a valid port number for fromdomain.\n",fromdomainport); 28555 } 28556 } else { 28557 default_fromdomainport = STANDARD_SIP_PORT; 28558 } 28559 } else if (!strcasecmp(v->name, "outboundproxy")) { 28560 char *host, *proxyname, *sep; 28561 28562 if (ast_strlen_zero(v->value)) { 28563 ast_log(LOG_WARNING, "no value given for outbound proxy on line %d of sip.conf\n", v->lineno); 28564 continue; 28565 } 28566 28567 host = ast_strdupa(v->value); 28568 if (!host) { 28569 ast_log(LOG_WARNING, "Unable to allocate stack space for parsing outboundproxy\n"); 28570 continue; 28571 } 28572 28573 host = ast_skip_blanks(host); 28574 sep = strchr(host, ','); 28575 if (sep) { 28576 *sep++ = '\0'; 28577 sip_cfg.outboundproxy.force = !strncasecmp(ast_skip_blanks(sep), "force", 5); 28578 } else { 28579 sip_cfg.outboundproxy.force = FALSE; 28580 } 28581 28582 sip_parse_host(host, v->lineno, &proxyname, 28583 &sip_cfg.outboundproxy.port, 28584 &sip_cfg.outboundproxy.transport); 28585 28586 if (ast_strlen_zero(proxyname)) { 28587 ast_log(LOG_WARNING, "you must specify a name for the outboundproxy on line %d of sip.conf\n", v->lineno); 28588 sip_cfg.outboundproxy.name[0] = '\0'; 28589 continue; 28590 } 28591 28592 ast_copy_string(sip_cfg.outboundproxy.name, proxyname, sizeof(sip_cfg.outboundproxy.name)); 28593 28594 proxy_update(&sip_cfg.outboundproxy); 28595 } else if (!strcasecmp(v->name, "autocreatepeer")) { 28596 sip_cfg.autocreatepeer = ast_true(v->value); 28597 } else if (!strcasecmp(v->name, "match_auth_username")) { 28598 global_match_auth_username = ast_true(v->value); 28599 } else if (!strcasecmp(v->name, "srvlookup")) { 28600 sip_cfg.srvlookup = ast_true(v->value); 28601 } else if (!strcasecmp(v->name, "pedantic")) { 28602 sip_cfg.pedanticsipchecking = ast_true(v->value); 28603 } else if (!strcasecmp(v->name, "maxexpirey") || !strcasecmp(v->name, "maxexpiry")) { 28604 max_expiry = atoi(v->value); 28605 if (max_expiry < 1) { 28606 max_expiry = DEFAULT_MAX_EXPIRY; 28607 } 28608 } else if (!strcasecmp(v->name, "minexpirey") || !strcasecmp(v->name, "minexpiry")) { 28609 min_expiry = atoi(v->value); 28610 if (min_expiry < 1) { 28611 min_expiry = DEFAULT_MIN_EXPIRY; 28612 } 28613 } else if (!strcasecmp(v->name, "defaultexpiry") || !strcasecmp(v->name, "defaultexpirey")) { 28614 default_expiry = atoi(v->value); 28615 if (default_expiry < 1) { 28616 default_expiry = DEFAULT_DEFAULT_EXPIRY; 28617 } 28618 } else if (!strcasecmp(v->name, "mwiexpiry") || !strcasecmp(v->name, "mwiexpirey")) { 28619 mwi_expiry = atoi(v->value); 28620 if (mwi_expiry < 1) { 28621 mwi_expiry = DEFAULT_MWI_EXPIRY; 28622 } 28623 } else if (!strcasecmp(v->name, "tcpauthtimeout")) { 28624 if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE, 28625 &authtimeout, DEFAULT_AUTHTIMEOUT, 1, INT_MAX)) { 28626 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", 28627 v->name, v->value, v->lineno, config); 28628 } 28629 } else if (!strcasecmp(v->name, "tcpauthlimit")) { 28630 if (ast_parse_arg(v->value, PARSE_INT32|PARSE_DEFAULT|PARSE_IN_RANGE, 28631 &authlimit, DEFAULT_AUTHLIMIT, 1, INT_MAX)) { 28632 ast_log(LOG_WARNING, "Invalid %s '%s' at line %d of %s\n", 28633 v->name, v->value, v->lineno, config); 28634 } 28635 } else if (!strcasecmp(v->name, "sipdebug")) { 28636 if (ast_true(v->value)) 28637 sipdebug |= sip_debug_config; 28638 } else if (!strcasecmp(v->name, "dumphistory")) { 28639 dumphistory = ast_true(v->value); 28640 } else if (!strcasecmp(v->name, "recordhistory")) { 28641 recordhistory = ast_true(v->value); 28642 } else if (!strcasecmp(v->name, "registertimeout")) { 28643 global_reg_timeout = atoi(v->value); 28644 if (global_reg_timeout < 1) { 28645 global_reg_timeout = DEFAULT_REGISTRATION_TIMEOUT; 28646 } 28647 } else if (!strcasecmp(v->name, "registerattempts")) { 28648 global_regattempts_max = atoi(v->value); 28649 } else if (!strcasecmp(v->name, "bindaddr") || !strcasecmp(v->name, "udpbindaddr")) { 28650 if (ast_parse_arg(v->value, PARSE_ADDR, &bindaddr)) { 28651 ast_log(LOG_WARNING, "Invalid address: %s\n", v->value); 28652 } 28653 } else if (!strcasecmp(v->name, "localnet")) { 28654 struct ast_ha *na; 28655 int ha_error = 0; 28656 28657 if (!(na = ast_append_ha("d", v->value, localaddr, &ha_error))) { 28658 ast_log(LOG_WARNING, "Invalid localnet value: %s\n", v->value); 28659 } else { 28660 localaddr = na; 28661 } 28662 if (ha_error) { 28663 ast_log(LOG_ERROR, "Bad localnet configuration value line %d : %s\n", v->lineno, v->value); 28664 } 28665 } else if (!strcasecmp(v->name, "media_address")) { 28666 if (ast_parse_arg(v->value, PARSE_ADDR, &media_address)) 28667 ast_log(LOG_WARNING, "Invalid address for media_address keyword: %s\n", v->value); 28668 } else if (!strcasecmp(v->name, "externaddr") || !strcasecmp(v->name, "externip")) { 28669 if (ast_parse_arg(v->value, PARSE_ADDR, &externaddr)) { 28670 ast_log(LOG_WARNING, 28671 "Invalid address for externaddr keyword: %s\n", 28672 v->value); 28673 } 28674 externexpire = 0; 28675 } else if (!strcasecmp(v->name, "externhost")) { 28676 ast_copy_string(externhost, v->value, sizeof(externhost)); 28677 if (ast_sockaddr_resolve_first(&externaddr, externhost, 0)) { 28678 ast_log(LOG_WARNING, "Invalid address for externhost keyword: %s\n", externhost); 28679 } 28680 externexpire = time(NULL); 28681 } else if (!strcasecmp(v->name, "externrefresh")) { 28682 if (sscanf(v->value, "%30d", &externrefresh) != 1) { 28683 ast_log(LOG_WARNING, "Invalid externrefresh value '%s', must be an integer >0 at line %d\n", v->value, v->lineno); 28684 externrefresh = 10; 28685 } 28686 } else if (!strcasecmp(v->name, "externtcpport")) { 28687 if (!(externtcpport = port_str2int(v->value, 0))) { 28688 ast_log(LOG_WARNING, "Invalid externtcpport value, must be a positive integer between 1 and 65535 at line %d\n", v->lineno); 28689 externtcpport = 0; 28690 } 28691 } else if (!strcasecmp(v->name, "externtlsport")) { 28692 if (!(externtlsport = port_str2int(v->value, STANDARD_TLS_PORT))) { 28693 ast_log(LOG_WARNING, "Invalid externtlsport value, must be a positive integer between 1 and 65535 at line %d\n", v->lineno); 28694 } 28695 } else if (!strcasecmp(v->name, "allow")) { 28696 int error = ast_parse_allow_disallow(&default_prefs, &sip_cfg.capability, v->value, TRUE); 28697 if (error) { 28698 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 28699 } 28700 } else if (!strcasecmp(v->name, "disallow")) { 28701 int error = ast_parse_allow_disallow(&default_prefs, &sip_cfg.capability, v->value, FALSE); 28702 if (error) { 28703 ast_log(LOG_WARNING, "Codec configuration errors found in line %d : %s = %s\n", v->lineno, v->name, v->value); 28704 } 28705 } else if (!strcasecmp(v->name, "preferred_codec_only")) { 28706 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_PREFERRED_CODEC); 28707 } else if (!strcasecmp(v->name, "autoframing")) { 28708 global_autoframing = ast_true(v->value); 28709 } else if (!strcasecmp(v->name, "allowexternaldomains")) { 28710 sip_cfg.allow_external_domains = ast_true(v->value); 28711 } else if (!strcasecmp(v->name, "autodomain")) { 28712 auto_sip_domains = ast_true(v->value); 28713 } else if (!strcasecmp(v->name, "domain")) { 28714 char *domain = ast_strdupa(v->value); 28715 char *cntx = strchr(domain, ','); 28716 28717 if (cntx) { 28718 *cntx++ = '\0'; 28719 } 28720 28721 if (ast_strlen_zero(cntx)) { 28722 ast_debug(1, "No context specified at line %d for domain '%s'\n", v->lineno, domain); 28723 } 28724 if (ast_strlen_zero(domain)) { 28725 ast_log(LOG_WARNING, "Empty domain specified at line %d\n", v->lineno); 28726 } else { 28727 add_sip_domain(ast_strip(domain), SIP_DOMAIN_CONFIG, cntx ? ast_strip(cntx) : ""); 28728 } 28729 } else if (!strcasecmp(v->name, "register")) { 28730 if (sip_register(v->value, v->lineno) == 0) { 28731 registry_count++; 28732 } 28733 } else if (!strcasecmp(v->name, "mwi")) { 28734 sip_subscribe_mwi(v->value, v->lineno); 28735 } else if (!strcasecmp(v->name, "tos_sip")) { 28736 if (ast_str2tos(v->value, &global_tos_sip)) { 28737 ast_log(LOG_WARNING, "Invalid tos_sip value at line %d, refer to QoS documentation\n", v->lineno); 28738 } 28739 } else if (!strcasecmp(v->name, "tos_audio")) { 28740 if (ast_str2tos(v->value, &global_tos_audio)) { 28741 ast_log(LOG_WARNING, "Invalid tos_audio value at line %d, refer to QoS documentation\n", v->lineno); 28742 } 28743 } else if (!strcasecmp(v->name, "tos_video")) { 28744 if (ast_str2tos(v->value, &global_tos_video)) { 28745 ast_log(LOG_WARNING, "Invalid tos_video value at line %d, refer to QoS documentation\n", v->lineno); 28746 } 28747 } else if (!strcasecmp(v->name, "tos_text")) { 28748 if (ast_str2tos(v->value, &global_tos_text)) { 28749 ast_log(LOG_WARNING, "Invalid tos_text value at line %d, refer to QoS documentation\n", v->lineno); 28750 } 28751 } else if (!strcasecmp(v->name, "cos_sip")) { 28752 if (ast_str2cos(v->value, &global_cos_sip)) { 28753 ast_log(LOG_WARNING, "Invalid cos_sip value at line %d, refer to QoS documentation\n", v->lineno); 28754 } 28755 } else if (!strcasecmp(v->name, "cos_audio")) { 28756 if (ast_str2cos(v->value, &global_cos_audio)) { 28757 ast_log(LOG_WARNING, "Invalid cos_audio value at line %d, refer to QoS documentation\n", v->lineno); 28758 } 28759 } else if (!strcasecmp(v->name, "cos_video")) { 28760 if (ast_str2cos(v->value, &global_cos_video)) { 28761 ast_log(LOG_WARNING, "Invalid cos_video value at line %d, refer to QoS documentation\n", v->lineno); 28762 } 28763 } else if (!strcasecmp(v->name, "cos_text")) { 28764 if (ast_str2cos(v->value, &global_cos_text)) { 28765 ast_log(LOG_WARNING, "Invalid cos_text value at line %d, refer to QoS documentation\n", v->lineno); 28766 } 28767 } else if (!strcasecmp(v->name, "bindport")) { 28768 if (sscanf(v->value, "%5d", &bindport) != 1) { 28769 ast_log(LOG_WARNING, "Invalid port number '%s' at line %d of %s\n", v->value, v->lineno, config); 28770 } 28771 } else if (!strcasecmp(v->name, "qualify")) { 28772 if (!strcasecmp(v->value, "no")) { 28773 default_qualify = 0; 28774 } else if (!strcasecmp(v->value, "yes")) { 28775 default_qualify = DEFAULT_MAXMS; 28776 } else if (sscanf(v->value, "%30d", &default_qualify) != 1) { 28777 ast_log(LOG_WARNING, "Qualification default should be 'yes', 'no', or a number of milliseconds at line %d of sip.conf\n", v->lineno); 28778 default_qualify = 0; 28779 } 28780 } else if (!strcasecmp(v->name, "qualifyfreq")) { 28781 int i; 28782 if (sscanf(v->value, "%30d", &i) == 1) { 28783 global_qualifyfreq = i * 1000; 28784 } else { 28785 ast_log(LOG_WARNING, "Invalid qualifyfreq number '%s' at line %d of %s\n", v->value, v->lineno, config); 28786 global_qualifyfreq = DEFAULT_QUALIFYFREQ; 28787 } 28788 } else if (!strcasecmp(v->name, "callevents")) { 28789 sip_cfg.callevents = ast_true(v->value); 28790 } else if (!strcasecmp(v->name, "authfailureevents")) { 28791 global_authfailureevents = ast_true(v->value); 28792 } else if (!strcasecmp(v->name, "maxcallbitrate")) { 28793 default_maxcallbitrate = atoi(v->value); 28794 if (default_maxcallbitrate < 0) 28795 default_maxcallbitrate = DEFAULT_MAX_CALL_BITRATE; 28796 } else if (!strcasecmp(v->name, "matchexternaddrlocally") || !strcasecmp(v->name, "matchexterniplocally")) { 28797 sip_cfg.matchexternaddrlocally = ast_true(v->value); 28798 } else if (!strcasecmp(v->name, "session-timers")) { 28799 int i = (int) str2stmode(v->value); 28800 if (i < 0) { 28801 ast_log(LOG_WARNING, "Invalid session-timers '%s' at line %d of %s\n", v->value, v->lineno, config); 28802 global_st_mode = SESSION_TIMER_MODE_ACCEPT; 28803 } else { 28804 global_st_mode = i; 28805 } 28806 } else if (!strcasecmp(v->name, "session-expires")) { 28807 if (sscanf(v->value, "%30d", &global_max_se) != 1) { 28808 ast_log(LOG_WARNING, "Invalid session-expires '%s' at line %d of %s\n", v->value, v->lineno, config); 28809 global_max_se = DEFAULT_MAX_SE; 28810 } 28811 } else if (!strcasecmp(v->name, "session-minse")) { 28812 if (sscanf(v->value, "%30d", &global_min_se) != 1) { 28813 ast_log(LOG_WARNING, "Invalid session-minse '%s' at line %d of %s\n", v->value, v->lineno, config); 28814 global_min_se = DEFAULT_MIN_SE; 28815 } 28816 if (global_min_se < 90) { 28817 ast_log(LOG_WARNING, "session-minse '%s' at line %d of %s is not allowed to be < 90 secs\n", v->value, v->lineno, config); 28818 global_min_se = DEFAULT_MIN_SE; 28819 } 28820 } else if (!strcasecmp(v->name, "session-refresher")) { 28821 int i = (int) str2strefresher(v->value); 28822 if (i < 0) { 28823 ast_log(LOG_WARNING, "Invalid session-refresher '%s' at line %d of %s\n", v->value, v->lineno, config); 28824 global_st_refresher = SESSION_TIMER_REFRESHER_UAS; 28825 } else { 28826 global_st_refresher = i; 28827 } 28828 } else if (!strcasecmp(v->name, "storesipcause")) { 28829 global_store_sip_cause = ast_true(v->value); 28830 } else if (!strcasecmp(v->name, "qualifygap")) { 28831 if (sscanf(v->value, "%30d", &global_qualify_gap) != 1) { 28832 ast_log(LOG_WARNING, "Invalid qualifygap '%s' at line %d of %s\n", v->value, v->lineno, config); 28833 global_qualify_gap = DEFAULT_QUALIFY_GAP; 28834 } 28835 } else if (!strcasecmp(v->name, "qualifypeers")) { 28836 if (sscanf(v->value, "%30d", &global_qualify_peers) != 1) { 28837 ast_log(LOG_WARNING, "Invalid pokepeers '%s' at line %d of %s\n", v->value, v->lineno, config); 28838 global_qualify_peers = DEFAULT_QUALIFY_PEERS; 28839 } 28840 } else if (!strcasecmp(v->name, "disallowed_methods")) { 28841 char *disallow = ast_strdupa(v->value); 28842 mark_parsed_methods(&sip_cfg.disallowed_methods, disallow); 28843 } else if (!strcasecmp(v->name, "shrinkcallerid")) { 28844 if (ast_true(v->value)) { 28845 global_shrinkcallerid = 1; 28846 } else if (ast_false(v->value)) { 28847 global_shrinkcallerid = 0; 28848 } else { 28849 ast_log(LOG_WARNING, "shrinkcallerid value %s is not valid at line %d.\n", v->value, v->lineno); 28850 } 28851 } else if (!strcasecmp(v->name, "use_q850_reason")) { 28852 ast_set2_flag(&global_flags[1], ast_true(v->value), SIP_PAGE2_Q850_REASON); 28853 } else if (!strcasecmp(v->name, "maxforwards")) { 28854 if (sscanf(v->value, "%30d", &sip_cfg.default_max_forwards) != 1 28855 || sip_cfg.default_max_forwards < 1 || 255 < sip_cfg.default_max_forwards) { 28856 ast_log(LOG_WARNING, "'%s' is not a valid maxforwards value at line %d. Using default.\n", v->value, v->lineno); 28857 sip_cfg.default_max_forwards = DEFAULT_MAX_FORWARDS; 28858 } 28859 } else if (!strcasecmp(v->name, "subscribe_network_change_event")) { 28860 if (ast_true(v->value)) { 28861 subscribe_network_change = 1; 28862 } else if (ast_false(v->value)) { 28863 subscribe_network_change = 0; 28864 } else { 28865 ast_log(LOG_WARNING, "subscribe_network_change_event value %s is not valid at line %d.\n", v->value, v->lineno); 28866 } 28867 } else if (!strcasecmp(v->name, "snom_aoc_enabled")) { 28868 ast_set2_flag(&global_flags[2], ast_true(v->value), SIP_PAGE3_SNOM_AOC); 28869 } else if (!strcasecmp(v->name, "parkinglot")) { 28870 ast_copy_string(default_parkinglot, v->value, sizeof(default_parkinglot)); 28871 } 28872 } 28873 28874 if (subscribe_network_change) { 28875 network_change_event_subscribe(); 28876 } else { 28877 network_change_event_unsubscribe(); 28878 } 28879 28880 if (global_t1 < global_t1min) { 28881 ast_log(LOG_WARNING, "'t1min' (%d) cannot be greater than 't1timer' (%d). Resetting 't1timer' to the value of 't1min'\n", global_t1min, global_t1); 28882 global_t1 = global_t1min; 28883 } 28884 28885 if (global_timer_b < global_t1 * 64) { 28886 if (timerb_set && timert1_set) { 28887 ast_log(LOG_WARNING, "Timer B has been set lower than recommended (%d < 64 * timert1=%d). (RFC 3261, 17.1.1.2)\n", global_timer_b, global_t1); 28888 } else if (timerb_set) { 28889 if ((global_t1 = global_timer_b / 64) < global_t1min) { 28890 ast_log(LOG_WARNING, "Timer B has been set lower than recommended (%d < 64 * timert1=%d). (RFC 3261, 17.1.1.2)\n", global_timer_b, global_t1); 28891 global_t1 = global_t1min; 28892 global_timer_b = global_t1 * 64; 28893 } 28894 } else { 28895 global_timer_b = global_t1 * 64; 28896 } 28897 } 28898 if (!sip_cfg.allow_external_domains && AST_LIST_EMPTY(&domain_list)) { 28899 ast_log(LOG_WARNING, "To disallow external domains, you need to configure local SIP domains.\n"); 28900 sip_cfg.allow_external_domains = 1; 28901 } 28902 /* If not or badly configured, set default transports */ 28903 if (!sip_cfg.tcp_enabled && (default_transports & SIP_TRANSPORT_TCP)) { 28904 ast_log(LOG_WARNING, "Cannot use 'tcp' transport with tcpenable=no. Removing from available transports.\n"); 28905 default_primary_transport &= ~SIP_TRANSPORT_TCP; 28906 default_transports &= ~SIP_TRANSPORT_TCP; 28907 } 28908 if (!default_tls_cfg.enabled && (default_transports & SIP_TRANSPORT_TLS)) { 28909 ast_log(LOG_WARNING, "Cannot use 'tls' transport with tlsenable=no. Removing from available transports.\n"); 28910 default_primary_transport &= ~SIP_TRANSPORT_TLS; 28911 default_transports &= ~SIP_TRANSPORT_TLS; 28912 } 28913 if (!default_transports) { 28914 ast_log(LOG_WARNING, "No valid transports available, falling back to 'udp'.\n"); 28915 default_transports = default_primary_transport = SIP_TRANSPORT_UDP; 28916 } else if (!default_primary_transport) { 28917 ast_log(LOG_WARNING, "No valid default transport. Selecting 'udp' as default.\n"); 28918 default_primary_transport = SIP_TRANSPORT_UDP; 28919 } 28920 28921 /* Build list of authentication to various SIP realms, i.e. service providers */ 28922 for (v = ast_variable_browse(cfg, "authentication"); v ; v = v->next) { 28923 /* Format for authentication is auth = username:password@realm */ 28924 if (!strcasecmp(v->name, "auth")) { 28925 add_realm_authentication(&authl, v->value, v->lineno); 28926 } 28927 } 28928 28929 if (bindport) { 28930 if (ast_sockaddr_port(&bindaddr)) { 28931 ast_log(LOG_WARNING, "bindport is also specified in bindaddr. " 28932 "Using %d.\n", bindport); 28933 } 28934 ast_sockaddr_set_port(&bindaddr, bindport); 28935 } 28936 28937 if (!ast_sockaddr_port(&bindaddr)) { 28938 ast_sockaddr_set_port(&bindaddr, STANDARD_SIP_PORT); 28939 } 28940 28941 /* Set UDP address and open socket */ 28942 ast_sockaddr_copy(&internip, &bindaddr); 28943 if (ast_find_ourip(&internip, &bindaddr, 0)) { 28944 ast_log(LOG_WARNING, "Unable to get own IP address, SIP disabled\n"); 28945 ast_config_destroy(cfg); 28946 return 0; 28947 } 28948 28949 ast_mutex_lock(&netlock); 28950 if ((sipsock > -1) && (ast_sockaddr_cmp(&old_bindaddr, &bindaddr))) { 28951 close(sipsock); 28952 sipsock = -1; 28953 } 28954 if (sipsock < 0) { 28955 sipsock = socket(ast_sockaddr_is_ipv6(&bindaddr) ? 28956 AF_INET6 : AF_INET, SOCK_DGRAM, 0); 28957 if (sipsock < 0) { 28958 ast_log(LOG_WARNING, "Unable to create SIP socket: %s\n", strerror(errno)); 28959 ast_config_destroy(cfg); 28960 ast_mutex_unlock(&netlock); 28961 return -1; 28962 } else { 28963 /* Allow SIP clients on the same host to access us: */ 28964 const int reuseFlag = 1; 28965 28966 setsockopt(sipsock, SOL_SOCKET, SO_REUSEADDR, 28967 (const char*)&reuseFlag, 28968 sizeof reuseFlag); 28969 28970 ast_enable_packet_fragmentation(sipsock); 28971 28972 if (ast_bind(sipsock, &bindaddr) < 0) { 28973 ast_log(LOG_WARNING, "Failed to bind to %s: %s\n", 28974 ast_sockaddr_stringify(&bindaddr), strerror(errno)); 28975 close(sipsock); 28976 sipsock = -1; 28977 } else { 28978 ast_verb(2, "SIP Listening on %s\n", ast_sockaddr_stringify(&bindaddr)); 28979 ast_set_qos(sipsock, global_tos_sip, global_cos_sip, "SIP"); 28980 } 28981 } 28982 } else { 28983 ast_set_qos(sipsock, global_tos_sip, global_cos_sip, "SIP"); 28984 } 28985 ast_mutex_unlock(&netlock); 28986 28987 /* Start TCP server */ 28988 if (sip_cfg.tcp_enabled) { 28989 if (ast_sockaddr_isnull(&sip_tcp_desc.local_address)) { 28990 ast_sockaddr_copy(&sip_tcp_desc.local_address, &bindaddr); 28991 } 28992 if (!ast_sockaddr_port(&sip_tcp_desc.local_address)) { 28993 ast_sockaddr_set_port(&sip_tcp_desc.local_address, STANDARD_SIP_PORT); 28994 } 28995 } else { 28996 ast_sockaddr_setnull(&sip_tcp_desc.local_address); 28997 } 28998 ast_tcptls_server_start(&sip_tcp_desc); 28999 if (sip_cfg.tcp_enabled && sip_tcp_desc.accept_fd == -1) { 29000 /* TCP server start failed. Tell the admin */ 29001 ast_log(LOG_ERROR, "SIP TCP Server start failed. Not listening on TCP socket.\n"); 29002 } else { 29003 ast_debug(2, "SIP TCP server started\n"); 29004 } 29005 29006 /* Start TLS server if needed */ 29007 memcpy(sip_tls_desc.tls_cfg, &default_tls_cfg, sizeof(default_tls_cfg)); 29008 29009 if (ast_ssl_setup(sip_tls_desc.tls_cfg)) { 29010 if (ast_sockaddr_isnull(&sip_tls_desc.local_address)) { 29011 ast_sockaddr_copy(&sip_tls_desc.local_address, &bindaddr); 29012 ast_sockaddr_set_port(&sip_tls_desc.local_address, 29013 STANDARD_TLS_PORT); 29014 } 29015 if (!ast_sockaddr_port(&sip_tls_desc.local_address)) { 29016 ast_sockaddr_set_port(&sip_tls_desc.local_address, 29017 STANDARD_TLS_PORT); 29018 } 29019 ast_tcptls_server_start(&sip_tls_desc); 29020 if (default_tls_cfg.enabled && sip_tls_desc.accept_fd == -1) { 29021 ast_log(LOG_ERROR, "TLS Server start failed. Not listening on TLS socket.\n"); 29022 sip_tls_desc.tls_cfg = NULL; 29023 } 29024 } else if (sip_tls_desc.tls_cfg->enabled) { 29025 sip_tls_desc.tls_cfg = NULL; 29026 ast_log(LOG_WARNING, "SIP TLS server did not load because of errors.\n"); 29027 } 29028 29029 if (ucfg) { 29030 struct ast_variable *gen; 29031 int genhassip, genregistersip; 29032 const char *hassip, *registersip; 29033 29034 genhassip = ast_true(ast_variable_retrieve(ucfg, "general", "hassip")); 29035 genregistersip = ast_true(ast_variable_retrieve(ucfg, "general", "registersip")); 29036 gen = ast_variable_browse(ucfg, "general"); 29037 cat = ast_category_browse(ucfg, NULL); 29038 while (cat) { 29039 if (strcasecmp(cat, "general")) { 29040 hassip = ast_variable_retrieve(ucfg, cat, "hassip"); 29041 registersip = ast_variable_retrieve(ucfg, cat, "registersip"); 29042 if (ast_true(hassip) || (!hassip && genhassip)) { 29043 peer = build_peer(cat, gen, ast_variable_browse(ucfg, cat), 0, 0); 29044 if (peer) { 29045 /* user.conf entries are always of type friend */ 29046 peer->type = SIP_TYPE_USER | SIP_TYPE_PEER; 29047 ao2_t_link(peers, peer, "link peer into peer table"); 29048 if ((peer->type & SIP_TYPE_PEER) && !ast_sockaddr_isnull(&peer->addr)) { 29049 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 29050 } 29051 29052 unref_peer(peer, "unref_peer: from reload_config"); 29053 peer_count++; 29054 } 29055 } 29056 if (ast_true(registersip) || (!registersip && genregistersip)) { 29057 char tmp[256]; 29058 const char *host = ast_variable_retrieve(ucfg, cat, "host"); 29059 const char *username = ast_variable_retrieve(ucfg, cat, "username"); 29060 const char *secret = ast_variable_retrieve(ucfg, cat, "secret"); 29061 const char *contact = ast_variable_retrieve(ucfg, cat, "contact"); 29062 const char *authuser = ast_variable_retrieve(ucfg, cat, "authuser"); 29063 if (!host) { 29064 host = ast_variable_retrieve(ucfg, "general", "host"); 29065 } 29066 if (!username) { 29067 username = ast_variable_retrieve(ucfg, "general", "username"); 29068 } 29069 if (!secret) { 29070 secret = ast_variable_retrieve(ucfg, "general", "secret"); 29071 } 29072 if (!contact) { 29073 contact = "s"; 29074 } 29075 if (!ast_strlen_zero(username) && !ast_strlen_zero(host)) { 29076 if (!ast_strlen_zero(secret)) { 29077 if (!ast_strlen_zero(authuser)) { 29078 snprintf(tmp, sizeof(tmp), "%s?%s:%s:%s@%s/%s", cat, username, secret, authuser, host, contact); 29079 } else { 29080 snprintf(tmp, sizeof(tmp), "%s?%s:%s@%s/%s", cat, username, secret, host, contact); 29081 } 29082 } else if (!ast_strlen_zero(authuser)) { 29083 snprintf(tmp, sizeof(tmp), "%s?%s::%s@%s/%s", cat, username, authuser, host, contact); 29084 } else { 29085 snprintf(tmp, sizeof(tmp), "%s?%s@%s/%s", cat, username, host, contact); 29086 } 29087 if (sip_register(tmp, 0) == 0) { 29088 registry_count++; 29089 } 29090 } 29091 } 29092 } 29093 cat = ast_category_browse(ucfg, cat); 29094 } 29095 ast_config_destroy(ucfg); 29096 } 29097 29098 /* Load peers, users and friends */ 29099 cat = NULL; 29100 while ( (cat = ast_category_browse(cfg, cat)) ) { 29101 const char *utype; 29102 if (!strcasecmp(cat, "general") || !strcasecmp(cat, "authentication")) 29103 continue; 29104 utype = ast_variable_retrieve(cfg, cat, "type"); 29105 if (!utype) { 29106 ast_log(LOG_WARNING, "Section '%s' lacks type\n", cat); 29107 continue; 29108 } else { 29109 if (!strcasecmp(utype, "user")) { 29110 ; 29111 } else if (!strcasecmp(utype, "friend")) { 29112 ; 29113 } else if (!strcasecmp(utype, "peer")) { 29114 ; 29115 } else { 29116 ast_log(LOG_WARNING, "Unknown type '%s' for '%s' in %s\n", utype, cat, "sip.conf"); 29117 continue; 29118 } 29119 peer = build_peer(cat, ast_variable_browse(cfg, cat), NULL, 0, 0); 29120 if (peer) { 29121 display_nat_warning(cat, reason, &peer->flags[0]); 29122 ao2_t_link(peers, peer, "link peer into peers table"); 29123 if ((peer->type & SIP_TYPE_PEER) && !ast_sockaddr_isnull(&peer->addr)) { 29124 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 29125 } 29126 unref_peer(peer, "unref the result of the build_peer call. Now, the links from the tables are the only ones left."); 29127 peer_count++; 29128 } 29129 } 29130 } 29131 29132 /* Add default domains - host name, IP address and IP:port 29133 * Only do this if user added any sip domain with "localdomains" 29134 * In order to *not* break backwards compatibility 29135 * Some phones address us at IP only, some with additional port number 29136 */ 29137 if (auto_sip_domains) { 29138 char temp[MAXHOSTNAMELEN]; 29139 29140 /* First our default IP address */ 29141 if (!ast_sockaddr_isnull(&bindaddr) && !ast_sockaddr_is_any(&bindaddr)) { 29142 add_sip_domain(ast_sockaddr_stringify_addr(&bindaddr), 29143 SIP_DOMAIN_AUTO, NULL); 29144 } else if (!ast_sockaddr_isnull(&internip) && !ast_sockaddr_is_any(&internip)) { 29145 /* Our internal IP address, if configured */ 29146 add_sip_domain(ast_sockaddr_stringify_addr(&internip), 29147 SIP_DOMAIN_AUTO, NULL); 29148 } else { 29149 ast_log(LOG_NOTICE, "Can't add wildcard IP address to domain list, please add IP address to domain manually.\n"); 29150 } 29151 29152 /* If TCP is running on a different IP than UDP, then add it too */ 29153 if (!ast_sockaddr_isnull(&sip_tcp_desc.local_address) && 29154 !ast_sockaddr_cmp(&bindaddr, &sip_tcp_desc.local_address)) { 29155 add_sip_domain(ast_sockaddr_stringify_addr(&sip_tcp_desc.local_address), 29156 SIP_DOMAIN_AUTO, NULL); 29157 } 29158 29159 /* If TLS is running on a different IP than UDP and TCP, then add that too */ 29160 if (!ast_sockaddr_isnull(&sip_tls_desc.local_address) && 29161 !ast_sockaddr_cmp(&bindaddr, &sip_tls_desc.local_address) && 29162 !ast_sockaddr_cmp(&sip_tcp_desc.local_address, 29163 &sip_tls_desc.local_address)) { 29164 add_sip_domain(ast_sockaddr_stringify_addr(&sip_tcp_desc.local_address), 29165 SIP_DOMAIN_AUTO, NULL); 29166 } 29167 29168 /* Our extern IP address, if configured */ 29169 if (!ast_sockaddr_isnull(&externaddr)) { 29170 add_sip_domain(ast_sockaddr_stringify_addr(&externaddr), 29171 SIP_DOMAIN_AUTO, NULL); 29172 } 29173 29174 /* Extern host name (NAT traversal support) */ 29175 if (!ast_strlen_zero(externhost)) { 29176 add_sip_domain(externhost, SIP_DOMAIN_AUTO, NULL); 29177 } 29178 29179 /* Our host name */ 29180 if (!gethostname(temp, sizeof(temp))) { 29181 add_sip_domain(temp, SIP_DOMAIN_AUTO, NULL); 29182 } 29183 } 29184 29185 /* Release configuration from memory */ 29186 ast_config_destroy(cfg); 29187 29188 /* Load the list of manual NOTIFY types to support */ 29189 if (notify_types) 29190 ast_config_destroy(notify_types); 29191 if ((notify_types = ast_config_load(notify_config, config_flags)) == CONFIG_STATUS_FILEINVALID) { 29192 ast_log(LOG_ERROR, "Contents of %s are invalid and cannot be parsed.\n", notify_config); 29193 notify_types = NULL; 29194 } 29195 29196 /* Done, tell the manager */ 29197 manager_event(EVENT_FLAG_SYSTEM, "ChannelReload", "ChannelType: SIP\r\nReloadReason: %s\r\nRegistry_Count: %d\r\nPeer_Count: %d\r\n", channelreloadreason2txt(reason), registry_count, peer_count); 29198 run_end = time(0); 29199 ast_debug(4, "SIP reload_config done...Runtime= %d sec\n", (int)(run_end-run_start)); 29200 29201 return 0; 29202 }
| static char * remove_uri_parameters | ( | char * | uri | ) | [static] |
Definition at line 11926 of file chan_sip.c.
Referenced by extract_uri(), parse_moved_contact(), register_verify(), reqprep(), and transmit_state_notify().
11927 { 11928 char *atsign; 11929 atsign = strchr(uri, '@'); /* First, locate the at sign */ 11930 if (!atsign) { 11931 atsign = uri; /* Ok hostname only, let's stick with the rest */ 11932 } 11933 atsign = strchr(atsign, ';'); /* Locate semi colon */ 11934 if (atsign) 11935 *atsign = '\0'; /* Kill at the semi colon */ 11936 return uri; 11937 }
| static int reply_digest | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| char * | header, | |||
| int | sipmethod, | |||
| char * | digest, | |||
| int | digest_len | |||
| ) | [static] |
reply to authentication for outbound registrations
Definition at line 19255 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_skip_blanks(), ast_string_field_ptr_set, ast_string_field_set, ast_strlen_zero(), build_reply_digest(), get_header(), and LOG_WARNING.
Referenced by do_proxy_auth(), and do_register_auth().
19256 { 19257 char tmp[512]; 19258 char *c; 19259 char oldnonce[256]; 19260 19261 /* table of recognised keywords, and places where they should be copied */ 19262 const struct x { 19263 const char *key; 19264 const ast_string_field *field; 19265 } *i, keys[] = { 19266 { "realm=", &p->realm }, 19267 { "nonce=", &p->nonce }, 19268 { "opaque=", &p->opaque }, 19269 { "qop=", &p->qop }, 19270 { "domain=", &p->domain }, 19271 { NULL, 0 }, 19272 }; 19273 19274 ast_copy_string(tmp, get_header(req, header), sizeof(tmp)); 19275 if (ast_strlen_zero(tmp)) 19276 return -1; 19277 if (strncasecmp(tmp, "Digest ", strlen("Digest "))) { 19278 ast_log(LOG_WARNING, "missing Digest.\n"); 19279 return -1; 19280 } 19281 c = tmp + strlen("Digest "); 19282 ast_copy_string(oldnonce, p->nonce, sizeof(oldnonce)); 19283 while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */ 19284 for (i = keys; i->key != NULL; i++) { 19285 char *src, *separator; 19286 if (strncasecmp(c, i->key, strlen(i->key)) != 0) 19287 continue; 19288 /* Found. Skip keyword, take text in quotes or up to the separator. */ 19289 c += strlen(i->key); 19290 if (*c == '"') { 19291 src = ++c; 19292 separator = "\""; 19293 } else { 19294 src = c; 19295 separator = ","; 19296 } 19297 strsep(&c, separator); /* clear separator and move ptr */ 19298 ast_string_field_ptr_set(p, i->field, src); 19299 break; 19300 } 19301 if (i->key == NULL) /* not found, try ',' */ 19302 strsep(&c, ","); 19303 } 19304 /* Reset nonce count */ 19305 if (strcmp(p->nonce, oldnonce)) 19306 p->noncecount = 0; 19307 19308 /* Save auth data for following registrations */ 19309 if (p->registry) { 19310 struct sip_registry *r = p->registry; 19311 19312 if (strcmp(r->nonce, p->nonce)) { 19313 ast_string_field_set(r, realm, p->realm); 19314 ast_string_field_set(r, nonce, p->nonce); 19315 ast_string_field_set(r, authdomain, p->domain); 19316 ast_string_field_set(r, opaque, p->opaque); 19317 ast_string_field_set(r, qop, p->qop); 19318 r->noncecount = 0; 19319 } 19320 } 19321 return build_reply_digest(p, sipmethod, digest, digest_len); 19322 }
| static int reqprep | ( | struct sip_request * | req, | |
| struct sip_pvt * | p, | |||
| int | sipmethod, | |||
| uint32_t | seqno, | |||
| int | newbranch | |||
| ) | [static] |
Initialize a SIP request message (not the initial one in a dialog).
< Strict routing flag
Definition at line 10360 of file chan_sip.c.
References add_header(), add_header_max_forwards(), add_route(), ast_copy_string(), ast_debug, ast_random(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, build_via(), copy_header(), FALSE, get_header(), get_in_brackets(), init_req(), remove_uri_parameters(), set_destination(), sip_methods, st_get_se(), strefresher2str(), text, cfsip_methods::text, TRUE, and url.
Referenced by transmit_cc_notify(), transmit_info_with_aoc(), transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), transmit_state_notify(), and update_connectedline().
10361 { 10362 struct sip_request *orig = &p->initreq; 10363 char stripped[80]; 10364 char tmp[80]; 10365 char newto[256]; 10366 const char *c; 10367 const char *ot, *of; 10368 int is_strict = FALSE; /*!< Strict routing flag */ 10369 int is_outbound = ast_test_flag(&p->flags[0], SIP_OUTGOING); /* Session direction */ 10370 10371 memset(req, 0, sizeof(struct sip_request)); 10372 10373 snprintf(p->lastmsg, sizeof(p->lastmsg), "Tx: %s", sip_methods[sipmethod].text); 10374 10375 if (!seqno) { 10376 p->ocseq++; 10377 seqno = p->ocseq; 10378 } 10379 10380 /* A CANCEL must have the same branch as the INVITE that it is canceling. */ 10381 if (sipmethod == SIP_CANCEL) { 10382 p->branch = p->invite_branch; 10383 build_via(p); 10384 } else if (newbranch && (sipmethod == SIP_INVITE)) { 10385 p->branch ^= ast_random(); 10386 p->invite_branch = p->branch; 10387 build_via(p); 10388 } else if (newbranch) { 10389 p->branch ^= ast_random(); 10390 build_via(p); 10391 } 10392 10393 /* Check for strict or loose router */ 10394 if (p->route && !ast_strlen_zero(p->route->hop) && strstr(p->route->hop, ";lr") == NULL) { 10395 is_strict = TRUE; 10396 if (sipdebug) 10397 ast_debug(1, "Strict routing enforced for session %s\n", p->callid); 10398 } 10399 10400 if (sipmethod == SIP_CANCEL) 10401 c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); /* Use original URI */ 10402 else if (sipmethod == SIP_ACK) { 10403 /* Use URI from Contact: in 200 OK (if INVITE) 10404 (we only have the contacturi on INVITEs) */ 10405 if (!ast_strlen_zero(p->okcontacturi)) 10406 c = is_strict ? p->route->hop : p->okcontacturi; 10407 else 10408 c = REQ_OFFSET_TO_STR(&p->initreq, rlPart2); 10409 } else if (!ast_strlen_zero(p->okcontacturi)) 10410 c = is_strict ? p->route->hop : p->okcontacturi; /* Use for BYE or REINVITE */ 10411 else if (!ast_strlen_zero(p->uri)) 10412 c = p->uri; 10413 else { 10414 char *n; 10415 /* We have no URI, use To: or From: header as URI (depending on direction) */ 10416 ast_copy_string(stripped, get_header(orig, is_outbound ? "To" : "From"), 10417 sizeof(stripped)); 10418 n = get_in_brackets(stripped); 10419 c = remove_uri_parameters(n); 10420 } 10421 init_req(req, sipmethod, c); 10422 10423 snprintf(tmp, sizeof(tmp), "%u %s", seqno, sip_methods[sipmethod].text); 10424 10425 add_header(req, "Via", p->via); 10426 /* 10427 * Use the learned route set unless this is a CANCEL on an ACK for a non-2xx 10428 * final response. For a CANCEL or ACK, we have to send to the same destination 10429 * as the original INVITE. 10430 */ 10431 if (p->route && 10432 !(sipmethod == SIP_CANCEL || 10433 (sipmethod == SIP_ACK && (p->invitestate == INV_COMPLETED || p->invitestate == INV_CANCELLED)))) { 10434 set_destination(p, p->route->hop); 10435 add_route(req, is_strict ? p->route->next : p->route); 10436 } 10437 add_header_max_forwards(p, req); 10438 10439 ot = get_header(orig, "To"); 10440 of = get_header(orig, "From"); 10441 10442 /* Add tag *unless* this is a CANCEL, in which case we need to send it exactly 10443 as our original request, including tag (or presumably lack thereof) */ 10444 if (!strcasestr(ot, "tag=") && sipmethod != SIP_CANCEL) { 10445 /* Add the proper tag if we don't have it already. If they have specified 10446 their tag, use it. Otherwise, use our own tag */ 10447 if (is_outbound && !ast_strlen_zero(p->theirtag)) 10448 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 10449 else if (!is_outbound) 10450 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 10451 else 10452 snprintf(newto, sizeof(newto), "%s", ot); 10453 ot = newto; 10454 } 10455 10456 if (is_outbound) { 10457 add_header(req, "From", of); 10458 add_header(req, "To", ot); 10459 } else { 10460 add_header(req, "From", ot); 10461 add_header(req, "To", of); 10462 } 10463 /* Do not add Contact for MESSAGE, BYE and Cancel requests */ 10464 if (sipmethod != SIP_BYE && sipmethod != SIP_CANCEL && sipmethod != SIP_MESSAGE) 10465 add_header(req, "Contact", p->our_contact); 10466 10467 copy_header(req, orig, "Call-ID"); 10468 add_header(req, "CSeq", tmp); 10469 10470 if (!ast_strlen_zero(global_useragent)) 10471 add_header(req, "User-Agent", global_useragent); 10472 10473 if (!ast_strlen_zero(p->url)) { 10474 add_header(req, "Access-URL", p->url); 10475 ast_string_field_set(p, url, NULL); 10476 } 10477 10478 /* Add Session-Timers related headers if the feature is active for this session. 10479 An exception to this behavior is the ACK request. Since Asterisk never requires 10480 session-timers support from a remote end-point (UAS) in an INVITE, it must 10481 not send 'Require: timer' header in the ACK request. 10482 This should only be added in the INVITE transactions, not MESSAGE or REFER or other 10483 in-dialog messages. 10484 */ 10485 if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_active_peer_ua == TRUE 10486 && sipmethod == SIP_INVITE) { 10487 char se_hdr[256]; 10488 snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->stimer->st_interval, 10489 strefresher2str(p->stimer->st_ref)); 10490 add_header(req, "Session-Expires", se_hdr); 10491 snprintf(se_hdr, sizeof(se_hdr), "%d", st_get_se(p, FALSE)); 10492 add_header(req, "Min-SE", se_hdr); 10493 } 10494 10495 return 0; 10496 }
| static int resp_needs_contact | ( | const char * | msg, | |
| enum sipmethod | method | |||
| ) | [inline, static] |
Test if this response needs a contact header.
Definition at line 10223 of file chan_sip.c.
Referenced by respprep().
10223 { 10224 /* Requirements for Contact header inclusion in responses generated 10225 * from the header tables found in the following RFCs. Where the 10226 * Contact header was marked mandatory (m) or optional (o) this 10227 * function returns 1. 10228 * 10229 * - RFC 3261 (ACK, BYE, CANCEL, INVITE, OPTIONS, REGISTER) 10230 * - RFC 2976 (INFO) 10231 * - RFC 3262 (PRACK) 10232 * - RFC 3265 (SUBSCRIBE, NOTIFY) 10233 * - RFC 3311 (UPDATE) 10234 * - RFC 3428 (MESSAGE) 10235 * - RFC 3515 (REFER) 10236 * - RFC 3903 (PUBLISH) 10237 */ 10238 10239 switch (method) { 10240 /* 1xx, 2xx, 3xx, 485 */ 10241 case SIP_INVITE: 10242 case SIP_UPDATE: 10243 case SIP_SUBSCRIBE: 10244 case SIP_NOTIFY: 10245 if ((msg[0] >= '1' && msg[0] <= '3') || !strncmp(msg, "485", 3)) 10246 return 1; 10247 break; 10248 10249 /* 2xx, 3xx, 485 */ 10250 case SIP_REGISTER: 10251 case SIP_OPTIONS: 10252 if (msg[0] == '2' || msg[0] == '3' || !strncmp(msg, "485", 3)) 10253 return 1; 10254 break; 10255 10256 /* 3xx, 485 */ 10257 case SIP_BYE: 10258 case SIP_PRACK: 10259 case SIP_MESSAGE: 10260 case SIP_PUBLISH: 10261 if (msg[0] == '3' || !strncmp(msg, "485", 3)) 10262 return 1; 10263 break; 10264 10265 /* 2xx, 3xx, 4xx, 5xx, 6xx */ 10266 case SIP_REFER: 10267 if (msg[0] >= '2' && msg[0] <= '6') 10268 return 1; 10269 break; 10270 10271 /* contact will not be included for everything else */ 10272 case SIP_ACK: 10273 case SIP_CANCEL: 10274 case SIP_INFO: 10275 case SIP_PING: 10276 default: 10277 return 0; 10278 } 10279 return 0; 10280 }
| static int respprep | ( | struct sip_request * | resp, | |
| struct sip_pvt * | p, | |||
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Prepare SIP response packet.
Definition at line 10283 of file chan_sip.c.
References add_header(), add_supported_header(), ast_copy_string(), ast_log(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, copy_all_header(), copy_header(), copy_via_headers(), get_header(), init_resp(), LOG_WARNING, process_via(), resp_needs_contact(), strefresher2str(), TRUE, and url.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_minexpires(), transmit_response_with_minse(), transmit_response_with_retry_after(), transmit_response_with_sdp(), transmit_response_with_sip_etag(), transmit_response_with_t38_sdp(), transmit_response_with_unsupported(), update_connectedline(), and update_redirecting().
10284 { 10285 char newto[256]; 10286 const char *ot; 10287 10288 init_resp(resp, msg); 10289 copy_via_headers(p, resp, req, "Via"); 10290 if (msg[0] == '1' || msg[0] == '2') 10291 copy_all_header(resp, req, "Record-Route"); 10292 copy_header(resp, req, "From"); 10293 ot = get_header(req, "To"); 10294 if (!strcasestr(ot, "tag=") && strncmp(msg, "100", 3)) { 10295 /* Add the proper tag if we don't have it already. If they have specified 10296 their tag, use it. Otherwise, use our own tag */ 10297 if (!ast_strlen_zero(p->theirtag) && ast_test_flag(&p->flags[0], SIP_OUTGOING)) 10298 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->theirtag); 10299 else if (p->tag && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) 10300 snprintf(newto, sizeof(newto), "%s;tag=%s", ot, p->tag); 10301 else 10302 ast_copy_string(newto, ot, sizeof(newto)); 10303 ot = newto; 10304 } 10305 add_header(resp, "To", ot); 10306 copy_header(resp, req, "Call-ID"); 10307 copy_header(resp, req, "CSeq"); 10308 if (!ast_strlen_zero(global_useragent)) 10309 add_header(resp, "Server", global_useragent); 10310 add_header(resp, "Allow", ALLOWED_METHODS); 10311 add_supported_header(p, resp); 10312 10313 /* If this is an invite, add Session-Timers related headers if the feature is active for this session */ 10314 if (p->method == SIP_INVITE && p->stimer && p->stimer->st_active == TRUE && p->stimer->st_active_peer_ua == TRUE) { 10315 char se_hdr[256]; 10316 snprintf(se_hdr, sizeof(se_hdr), "%d;refresher=%s", p->stimer->st_interval, 10317 strefresher2str(p->stimer->st_ref)); 10318 add_header(resp, "Session-Expires", se_hdr); 10319 } 10320 10321 if (msg[0] == '2' && (p->method == SIP_SUBSCRIBE || p->method == SIP_REGISTER)) { 10322 /* For registration responses, we also need expiry and 10323 contact info */ 10324 char tmp[256]; 10325 10326 snprintf(tmp, sizeof(tmp), "%d", p->expiry); 10327 add_header(resp, "Expires", tmp); 10328 if (p->expiry) { /* Only add contact if we have an expiry time */ 10329 char contact[SIPBUFSIZE]; 10330 const char *contact_uri = p->method == SIP_SUBSCRIBE ? p->our_contact : p->fullcontact; 10331 char *brackets = strchr(contact_uri, '<'); 10332 snprintf(contact, sizeof(contact), "%s%s%s;expires=%d", brackets ? "" : "<", contact_uri, brackets ? "" : ">", p->expiry); 10333 add_header(resp, "Contact", contact); /* Not when we unregister */ 10334 } 10335 } else if (!ast_strlen_zero(p->our_contact) && resp_needs_contact(msg, p->method)) { 10336 add_header(resp, "Contact", p->our_contact); 10337 } 10338 10339 if (!ast_strlen_zero(p->url)) { 10340 add_header(resp, "Access-URL", p->url); 10341 ast_string_field_set(p, url, NULL); 10342 } 10343 10344 /* default to routing the response to the address where the request 10345 * came from. Since we don't have a transport layer, we do this here. 10346 * The process_via() function will update the port to either the port 10347 * specified in the via header or the default port later on (per RFC 10348 * 3261 section 18.2.2). 10349 */ 10350 p->sa = p->recv; 10351 10352 if (process_via(p, req)) { 10353 ast_log(LOG_WARNING, "error processing via header, will send response to originating address\n"); 10354 } 10355 10356 return 0; 10357 }
| static int restart_monitor | ( | void | ) | [static] |
Start the channel monitor thread.
Definition at line 26030 of file chan_sip.c.
References ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_pthread_create_background, AST_PTHREADT_NULL, AST_PTHREADT_STOP, do_monitor(), LOG_ERROR, and LOG_WARNING.
Referenced by load_module(), sip_reload(), and sip_request_call().
26031 { 26032 /* If we're supposed to be stopped -- stay stopped */ 26033 if (monitor_thread == AST_PTHREADT_STOP) 26034 return 0; 26035 ast_mutex_lock(&monlock); 26036 if (monitor_thread == pthread_self()) { 26037 ast_mutex_unlock(&monlock); 26038 ast_log(LOG_WARNING, "Cannot kill myself\n"); 26039 return -1; 26040 } 26041 if (monitor_thread != AST_PTHREADT_NULL) { 26042 /* Wake up the thread */ 26043 pthread_kill(monitor_thread, SIGURG); 26044 } else { 26045 /* Start a new monitor */ 26046 if (ast_pthread_create_background(&monitor_thread, NULL, do_monitor, NULL) < 0) { 26047 ast_mutex_unlock(&monlock); 26048 ast_log(LOG_ERROR, "Unable to start monitor thread.\n"); 26049 return -1; 26050 } 26051 } 26052 ast_mutex_unlock(&monlock); 26053 return 0; 26054 }
| static void restart_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Restart session timer.
Definition at line 26058 of file chan_sip.c.
References ast_debug, ast_log(), AST_SCHED_DEL_UNREF, LOG_WARNING, start_session_timer(), and TRUE.
Referenced by handle_request_invite().
26059 { 26060 if (!p->stimer) { 26061 ast_log(LOG_WARNING, "Null stimer in restart_session_timer - %s\n", p->callid); 26062 return; 26063 } 26064 26065 if (p->stimer->st_active == TRUE) { 26066 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 26067 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 26068 dialog_unref(p, "Removing session timer ref")); 26069 start_session_timer(p); 26070 } 26071 }
| static int retrans_pkt | ( | const void * | data | ) | [static] |
Retransmit SIP message if no answer (Called from scheduler).
Definition at line 3550 of file chan_sip.c.
References __sip_xmit(), append_history, AST_CAUSE_NO_USER_RESPONSE, AST_CAUSE_PROTOCOL_ERROR, ast_channel_trylock, ast_channel_unlock, ast_debug, ast_free, ast_log(), ast_queue_hangup_with_cause(), ast_sockaddr_stringify(), ast_test_flag, ast_tvdiff_ms(), ast_tvnow(), ast_verbose, DEFAULT_RETRANS, LOG_WARNING, pvt_set_needdestroy(), sip_alreadygone(), sip_debug_test_pvt(), sip_methods, sip_nat_mode(), sip_pvt_lock, sip_pvt_unlock, sip_real_dst(), cfsip_methods::text, and UNLINK.
Referenced by __sip_reliable_xmit(), and sip_show_sched().
03551 { 03552 struct sip_pkt *pkt = (struct sip_pkt *)data, *prev, *cur = NULL; 03553 int reschedule = DEFAULT_RETRANS; 03554 int xmitres = 0; 03555 /* how many ms until retrans timeout is reached */ 03556 int64_t diff = pkt->retrans_stop_time - ast_tvdiff_ms(ast_tvnow(), pkt->time_sent); 03557 03558 /* Do not retransmit if time out is reached. This will be negative if the time between 03559 * the first transmission and now is larger than our timeout period. This is a fail safe 03560 * check in case the scheduler gets behind or the clock is changed. */ 03561 if ((diff <= 0) || (diff > pkt->retrans_stop_time)) { 03562 pkt->retrans_stop = 1; 03563 } 03564 03565 /* Lock channel PVT */ 03566 sip_pvt_lock(pkt->owner); 03567 03568 if (!pkt->retrans_stop) { 03569 pkt->retrans++; 03570 if (!pkt->timer_t1) { /* Re-schedule using timer_a and timer_t1 */ 03571 if (sipdebug) { 03572 ast_debug(4, "SIP TIMER: Not rescheduling id #%d:%s (Method %d) (No timer T1)\n", 03573 pkt->retransid, 03574 sip_methods[pkt->method].text, 03575 pkt->method); 03576 } 03577 } else { 03578 int siptimer_a; 03579 03580 if (sipdebug) { 03581 ast_debug(4, "SIP TIMER: Rescheduling retransmission #%d (%d) %s - %d\n", 03582 pkt->retransid, 03583 pkt->retrans, 03584 sip_methods[pkt->method].text, 03585 pkt->method); 03586 } 03587 if (!pkt->timer_a) { 03588 pkt->timer_a = 2 ; 03589 } else { 03590 pkt->timer_a = 2 * pkt->timer_a; 03591 } 03592 03593 /* For non-invites, a maximum of 4 secs */ 03594 siptimer_a = pkt->timer_t1 * pkt->timer_a; /* Double each time */ 03595 if (pkt->method != SIP_INVITE && siptimer_a > 4000) { 03596 siptimer_a = 4000; 03597 } 03598 03599 /* Reschedule re-transmit */ 03600 reschedule = siptimer_a; 03601 ast_debug(4, "** SIP timers: Rescheduling retransmission %d to %d ms (t1 %d ms (Retrans id #%d)) \n", 03602 pkt->retrans + 1, 03603 siptimer_a, 03604 pkt->timer_t1, 03605 pkt->retransid); 03606 } 03607 03608 if (sip_debug_test_pvt(pkt->owner)) { 03609 const struct ast_sockaddr *dst = sip_real_dst(pkt->owner); 03610 ast_verbose("Retransmitting #%d (%s) to %s:\n%s\n---\n", 03611 pkt->retrans, sip_nat_mode(pkt->owner), 03612 ast_sockaddr_stringify(dst), 03613 pkt->data->str); 03614 } 03615 03616 append_history(pkt->owner, "ReTx", "%d %s", reschedule, pkt->data->str); 03617 xmitres = __sip_xmit(pkt->owner, pkt->data); 03618 03619 /* If there was no error during the network transmission, schedule the next retransmission, 03620 * but if the next retransmission is going to be beyond our timeout period, mark the packet's 03621 * stop_retrans value and set the next retransmit to be the exact time of timeout. This will 03622 * allow any responses to the packet to be processed before the packet is destroyed on the next 03623 * call to this function by the scheduler. */ 03624 if (xmitres != XMIT_ERROR) { 03625 if (reschedule >= diff) { 03626 pkt->retrans_stop = 1; 03627 reschedule = diff; 03628 } 03629 sip_pvt_unlock(pkt->owner); 03630 return reschedule; 03631 } 03632 } 03633 03634 /* At this point, either the packet's retransmission timed out, or there was a 03635 * transmission error, either way destroy the scheduler item and this packet. */ 03636 03637 pkt->retransid = -1; /* Kill this scheduler item */ 03638 03639 if (pkt->method != SIP_OPTIONS && xmitres == 0) { 03640 if (pkt->is_fatal || sipdebug) { /* Tell us if it's critical or if we're debugging */ 03641 ast_log(LOG_WARNING, "Retransmission timeout reached on transmission %s for seqno %u (%s %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n" 03642 "Packet timed out after %dms with no response\n", 03643 pkt->owner->callid, 03644 pkt->seqno, 03645 pkt->is_fatal ? "Critical" : "Non-critical", 03646 pkt->is_resp ? "Response" : "Request", 03647 (int) ast_tvdiff_ms(ast_tvnow(), pkt->time_sent)); 03648 } 03649 } else if (pkt->method == SIP_OPTIONS && sipdebug) { 03650 ast_log(LOG_WARNING, "Cancelling retransmit of OPTIONs (call id %s) -- See https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions\n", pkt->owner->callid); 03651 } 03652 03653 if (xmitres == XMIT_ERROR) { 03654 ast_log(LOG_WARNING, "Transmit error :: Cancelling transmission on Call ID %s\n", pkt->owner->callid); 03655 append_history(pkt->owner, "XmitErr", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03656 } else { 03657 append_history(pkt->owner, "MaxRetries", "%s", pkt->is_fatal ? "(Critical)" : "(Non-critical)"); 03658 } 03659 03660 if (pkt->is_fatal) { 03661 while(pkt->owner->owner && ast_channel_trylock(pkt->owner->owner)) { 03662 sip_pvt_unlock(pkt->owner); /* SIP_PVT, not channel */ 03663 usleep(1); 03664 sip_pvt_lock(pkt->owner); 03665 } 03666 if (pkt->owner->owner && !pkt->owner->owner->hangupcause) { 03667 pkt->owner->owner->hangupcause = AST_CAUSE_NO_USER_RESPONSE; 03668 } 03669 if (pkt->owner->owner) { 03670 ast_log(LOG_WARNING, "Hanging up call %s - no reply to our critical packet (see https://wiki.asterisk.org/wiki/display/AST/SIP+Retransmissions).\n", pkt->owner->callid); 03671 03672 if (pkt->is_resp && 03673 (pkt->response_code >= 200) && 03674 (pkt->response_code < 300) && 03675 pkt->owner->pendinginvite && 03676 ast_test_flag(&pkt->owner->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { 03677 /* This is a timeout of the 2XX response to a pending INVITE. In this case terminate the INVITE 03678 * transaction just as if we received the ACK, but immediately hangup with a BYE (sip_hangup 03679 * will send the BYE as long as the dialog is not set as "alreadygone") 03680 * RFC 3261 section 13.3.1.4. 03681 * "If the server retransmits the 2xx response for 64*T1 seconds without receiving 03682 * an ACK, the dialog is confirmed, but the session SHOULD be terminated. This is 03683 * accomplished with a BYE, as described in Section 15." */ 03684 pkt->owner->invitestate = INV_TERMINATED; 03685 pkt->owner->pendinginvite = 0; 03686 } else { 03687 /* there is nothing left to do, mark the dialog as gone */ 03688 sip_alreadygone(pkt->owner); 03689 } 03690 ast_queue_hangup_with_cause(pkt->owner->owner, AST_CAUSE_PROTOCOL_ERROR); 03691 ast_channel_unlock(pkt->owner->owner); 03692 } else { 03693 /* If no channel owner, destroy now */ 03694 03695 /* Let the peerpoke system expire packets when the timer expires for poke_noanswer */ 03696 if (pkt->method != SIP_OPTIONS && pkt->method != SIP_REGISTER) { 03697 pvt_set_needdestroy(pkt->owner, "no response to critical packet"); 03698 sip_alreadygone(pkt->owner); 03699 append_history(pkt->owner, "DialogKill", "Killing this failed dialog immediately"); 03700 } 03701 } 03702 } 03703 03704 if (pkt->method == SIP_BYE) { 03705 /* We're not getting answers on SIP BYE's. Tear down the call anyway. */ 03706 sip_alreadygone(pkt->owner); 03707 if (pkt->owner->owner) { 03708 ast_channel_unlock(pkt->owner->owner); 03709 } 03710 append_history(pkt->owner, "ByeFailure", "Remote peer doesn't respond to bye. Destroying call anyway."); 03711 pvt_set_needdestroy(pkt->owner, "no response to BYE"); 03712 } 03713 03714 /* Remove the packet */ 03715 for (prev = NULL, cur = pkt->owner->packets; cur; prev = cur, cur = cur->next) { 03716 if (cur == pkt) { 03717 UNLINK(cur, pkt->owner->packets, prev); 03718 sip_pvt_unlock(pkt->owner); 03719 if (pkt->owner) { 03720 pkt->owner = dialog_unref(pkt->owner,"pkt is being freed, its dialog ref is dead now"); 03721 } 03722 if (pkt->data) { 03723 ast_free(pkt->data); 03724 } 03725 pkt->data = NULL; 03726 ast_free(pkt); 03727 return 0; 03728 } 03729 } 03730 /* error case */ 03731 ast_log(LOG_WARNING, "Weird, couldn't find packet owner!\n"); 03732 sip_pvt_unlock(pkt->owner); 03733 return 0; 03734 }
| static int send_provisional_keepalive | ( | const void * | data | ) | [static] |
Definition at line 4141 of file chan_sip.c.
References send_provisional_keepalive_full().
Referenced by update_provisional_keepalive().
04141 { 04142 struct sip_pvt *pvt = (struct sip_pvt *) data; 04143 04144 return send_provisional_keepalive_full(pvt, 0); 04145 }
| static int send_provisional_keepalive_full | ( | struct sip_pvt * | pvt, | |
| int | with_sdp | |||
| ) | [static] |
Definition at line 4092 of file chan_sip.c.
References ast_channel_unlock, ast_channel_unref, FALSE, S_OR, sip_pvt_lock_full(), sip_pvt_unlock, transmit_response(), and transmit_response_with_sdp().
Referenced by send_provisional_keepalive(), and send_provisional_keepalive_with_sdp().
04093 { 04094 const char *msg = NULL; 04095 struct ast_channel *chan; 04096 int res = 0; 04097 04098 chan = sip_pvt_lock_full(pvt); 04099 04100 if (!pvt->last_provisional || !strncasecmp(pvt->last_provisional, "100", 3)) { 04101 msg = "183 Session Progress"; 04102 } 04103 04104 if (pvt->invitestate < INV_COMPLETED) { 04105 if (with_sdp) { 04106 transmit_response_with_sdp(pvt, S_OR(msg, pvt->last_provisional), &pvt->initreq, XMIT_UNRELIABLE, FALSE, FALSE); 04107 } else { 04108 transmit_response(pvt, S_OR(msg, pvt->last_provisional), &pvt->initreq); 04109 } 04110 res = PROVIS_KEEPALIVE_TIMEOUT; 04111 } 04112 04113 if (chan) { 04114 ast_channel_unlock(chan); 04115 chan = ast_channel_unref(chan); 04116 } 04117 04118 if (!res) { 04119 pvt->provisional_keepalive_sched_id = -1; 04120 } 04121 04122 sip_pvt_unlock(pvt); 04123 04124 #if 0 04125 /* 04126 * XXX BUG TODO 04127 * 04128 * Without this code, it appears as if this function is leaking its 04129 * reference to the sip_pvt. However, adding it introduces a crash. 04130 * This points to some sort of reference count imbalance elsewhere, 04131 * but I'm not sure where ... 04132 */ 04133 if (!res) { 04134 dialog_unref(pvt, "dialog ref for provisional keepalive"); 04135 } 04136 #endif 04137 04138 return res; 04139 }
| static int send_provisional_keepalive_with_sdp | ( | const void * | data | ) | [static] |
Definition at line 4147 of file chan_sip.c.
References send_provisional_keepalive_full().
Referenced by update_provisional_keepalive().
04147 { 04148 struct sip_pvt *pvt = (void *)data; 04149 04150 return send_provisional_keepalive_full(pvt, 1); 04151 }
| static int send_request | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| uint32_t | seqno | |||
| ) | [static] |
Definition at line 4204 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, ast_sockaddr_stringify(), ast_test_flag, ast_verbose, deinit_req(), finalize_content(), get_header(), parse_copy(), sip_debug_test_pvt(), sip_methods, and cfsip_methods::text.
Referenced by transmit_cc_notify(), transmit_info_with_aoc(), transmit_info_with_digit(), transmit_info_with_vidupdate(), transmit_invite(), transmit_message_with_text(), transmit_notify_with_mwi(), transmit_notify_with_sipfrag(), transmit_refer(), transmit_register(), transmit_reinvite_with_sdp(), transmit_request(), transmit_request_with_auth(), transmit_state_notify(), and update_connectedline().
04205 { 04206 int res; 04207 04208 /* If we have an outbound proxy, reset peer address 04209 Only do this once. 04210 */ 04211 if (p->outboundproxy) { 04212 p->sa = p->outboundproxy->ip; 04213 } 04214 04215 finalize_content(req); 04216 add_blank(req); 04217 if (sip_debug_test_pvt(p)) { 04218 if (ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT)) { 04219 ast_verbose("%sTransmitting (NAT) to %s:\n%s\n---\n", reliable ? "Reliably " : "", ast_sockaddr_stringify(&p->recv), req->data->str); 04220 } else { 04221 ast_verbose("%sTransmitting (no NAT) to %s:\n%s\n---\n", reliable ? "Reliably " : "", ast_sockaddr_stringify(&p->sa), req->data->str); 04222 } 04223 } 04224 if (p->do_history) { 04225 struct sip_request tmp = { .rlPart1 = 0, }; 04226 parse_copy(&tmp, req); 04227 append_history(p, reliable ? "TxReqRel" : "TxReq", "%s / %s - %s", tmp.data->str, get_header(&tmp, "CSeq"), sip_methods[tmp.method].text); 04228 deinit_req(&tmp); 04229 } 04230 res = (reliable) ? 04231 __sip_reliable_xmit(p, seqno, 0, req->data, (reliable == XMIT_CRITICAL), req->method) : 04232 __sip_xmit(p, req->data); 04233 deinit_req(req); 04234 return res; 04235 }
| static int send_response | ( | struct sip_pvt * | p, | |
| struct sip_request * | req, | |||
| enum xmittype | reliable, | |||
| uint32_t | seqno | |||
| ) | [static] |
Transmit response on SIP request.
Definition at line 4162 of file chan_sip.c.
References __sip_reliable_xmit(), __sip_xmit(), add_blank(), append_history, AST_SCHED_DEL_UNREF, ast_sockaddr_stringify(), ast_verbose, deinit_req(), finalize_content(), get_header(), parse_copy(), sip_debug_test_pvt(), sip_methods, sip_nat_mode(), sip_real_dst(), and cfsip_methods::text.
Referenced by __transmit_response(), transmit_response_with_allow(), transmit_response_with_auth(), transmit_response_with_date(), transmit_response_with_minexpires(), transmit_response_with_minse(), transmit_response_with_retry_after(), transmit_response_with_sdp(), transmit_response_with_sip_etag(), transmit_response_with_t38_sdp(), transmit_response_with_unsupported(), update_connectedline(), and update_redirecting().
04163 { 04164 int res; 04165 04166 finalize_content(req); 04167 add_blank(req); 04168 if (sip_debug_test_pvt(p)) { 04169 const struct ast_sockaddr *dst = sip_real_dst(p); 04170 04171 ast_verbose("\n<--- %sTransmitting (%s) to %s --->\n%s\n<------------>\n", 04172 reliable ? "Reliably " : "", sip_nat_mode(p), 04173 ast_sockaddr_stringify(dst), 04174 req->data->str); 04175 } 04176 if (p->do_history) { 04177 struct sip_request tmp = { .rlPart1 = 0, }; 04178 parse_copy(&tmp, req); 04179 append_history(p, reliable ? "TxRespRel" : "TxResp", "%s / %s - %s", tmp.data->str, get_header(&tmp, "CSeq"), 04180 (tmp.method == SIP_RESPONSE || tmp.method == SIP_UNKNOWN) ? REQ_OFFSET_TO_STR(&tmp, rlPart2) : sip_methods[tmp.method].text); 04181 deinit_req(&tmp); 04182 } 04183 04184 /* If we are sending a final response to an INVITE, stop retransmitting provisional responses */ 04185 if (p->initreq.method == SIP_INVITE && reliable == XMIT_CRITICAL) { 04186 AST_SCHED_DEL_UNREF(sched, p->provisional_keepalive_sched_id, dialog_unref(p, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 04187 } 04188 04189 res = (reliable) ? 04190 __sip_reliable_xmit(p, seqno, 1, req->data, (reliable == XMIT_CRITICAL), req->method) : 04191 __sip_xmit(p, req->data); 04192 deinit_req(req); 04193 if (res > 0) { 04194 return 0; 04195 } 04196 return res; 04197 }
| static enum ast_cc_service_type service_string_to_service_type | ( | const char *const | service_string | ) | [static] |
Definition at line 841 of file chan_sip.c.
References AST_CC_CCBS, AST_CC_CCNL, AST_CC_NONE, service, and sip_cc_service_map.
Referenced by sip_get_cc_information().
00842 { 00843 enum ast_cc_service_type service; 00844 for (service = AST_CC_CCBS; service <= AST_CC_CCNL; ++service) { 00845 if (!strcasecmp(service_string, sip_cc_service_map[service].service_string)) { 00846 return service; 00847 } 00848 } 00849 return AST_CC_NONE; 00850 }
| static int set_address_from_contact | ( | struct sip_pvt * | pvt | ) | [static] |
Change the other partys IP address based on given contact.
Definition at line 14009 of file chan_sip.c.
References __set_address_from_contact(), and ast_test_flag.
Referenced by handle_response_invite().
14010 { 14011 if (ast_test_flag(&pvt->flags[0], SIP_NAT_FORCE_RPORT)) { 14012 /* NAT: Don't trust the contact field. Just use what they came to us 14013 with. */ 14014 /*! \todo We need to save the TRANSPORT here too */ 14015 pvt->sa = pvt->recv; 14016 return 0; 14017 } 14018 14019 return __set_address_from_contact(pvt->fullcontact, &pvt->sa, pvt->socket.type == SIP_TRANSPORT_TLS ? 1 : 0); 14020 }
| static void set_destination | ( | struct sip_pvt * | p, | |
| char * | uri | |||
| ) | [static] |
Set destination from SIP URI.
Parse uri to h (host) and port - uri is already just the part inside the <> general form we are expecting is sip[s]:username[:password][;parameter][:port][;...] If there's a port given, turn NAPTR/SRV off. NAPTR might indicate SIPS preference even for SIP: uri's
If there's a sips: uri scheme, TLS will be required.
Definition at line 10092 of file chan_sip.c.
References ast_copy_string(), ast_log(), ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, ast_sockaddr_stringify(), ast_verbose, FALSE, hostname, LOG_WARNING, PARSE_PORT_FORBID, sip_debug_test_pvt(), and TRUE.
Referenced by reqprep().
10093 { 10094 char *h, *maddr, hostname[256]; 10095 int hn; 10096 int debug=sip_debug_test_pvt(p); 10097 int tls_on = FALSE; 10098 10099 if (debug) 10100 ast_verbose("set_destination: Parsing <%s> for address/port to send to\n", uri); 10101 10102 /* Find and parse hostname */ 10103 h = strchr(uri, '@'); 10104 if (h) 10105 ++h; 10106 else { 10107 h = uri; 10108 if (!strncasecmp(h, "sip:", 4)) { 10109 h += 4; 10110 } else if (!strncasecmp(h, "sips:", 5)) { 10111 h += 5; 10112 tls_on = TRUE; 10113 } 10114 } 10115 hn = strcspn(h, ";>") + 1; 10116 if (hn > sizeof(hostname)) 10117 hn = sizeof(hostname); 10118 ast_copy_string(hostname, h, hn); 10119 /* XXX bug here if string has been trimmed to sizeof(hostname) */ 10120 h += hn - 1; 10121 10122 /*! \todo XXX If we have sip_cfg.srvlookup on, then look for NAPTR/SRV, 10123 * otherwise, just look for A records */ 10124 if (ast_sockaddr_resolve_first_transport(&p->sa, hostname, 0, p->socket.type)) { 10125 ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname); 10126 return; 10127 } 10128 10129 /* Got the hostname - but maybe there's a "maddr=" to override address? */ 10130 maddr = strstr(h, "maddr="); 10131 if (maddr) { 10132 int port; 10133 10134 maddr += 6; 10135 hn = strspn(maddr, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" 10136 "0123456789-.:[]") + 1; 10137 if (hn > sizeof(hostname)) 10138 hn = sizeof(hostname); 10139 ast_copy_string(hostname, maddr, hn); 10140 10141 port = ast_sockaddr_port(&p->sa); 10142 10143 /*! \todo XXX If we have sip_cfg.srvlookup on, then look for 10144 * NAPTR/SRV, otherwise, just look for A records */ 10145 if (ast_sockaddr_resolve_first_transport(&p->sa, hostname, PARSE_PORT_FORBID, p->socket.type)) { 10146 ast_log(LOG_WARNING, "Can't find address for host '%s'\n", hostname); 10147 return; 10148 } 10149 10150 ast_sockaddr_set_port(&p->sa, port); 10151 } 10152 10153 if (!ast_sockaddr_port(&p->sa)) { 10154 ast_sockaddr_set_port(&p->sa, tls_on ? 10155 STANDARD_TLS_PORT : STANDARD_SIP_PORT); 10156 } 10157 10158 if (debug) { 10159 ast_verbose("set_destination: set destination to %s\n", 10160 ast_sockaddr_stringify(&p->sa)); 10161 } 10162 }
| static void set_insecure_flags | ( | struct ast_flags * | flags, | |
| const char * | value, | |||
| int | lineno | |||
| ) | [static] |
Parse insecure= setting in sip.conf and set flags according to setting.
Definition at line 26824 of file chan_sip.c.
References ast_copy_string(), ast_false(), ast_log(), ast_set_flag, ast_strlen_zero(), LOG_WARNING, and word.
Referenced by get_insecure_variable_from_config(), get_insecure_variable_from_sipregs(), and handle_common_options().
26825 { 26826 if (ast_strlen_zero(value)) 26827 return; 26828 26829 if (!ast_false(value)) { 26830 char buf[64]; 26831 char *word, *next; 26832 26833 ast_copy_string(buf, value, sizeof(buf)); 26834 next = buf; 26835 while ((word = strsep(&next, ","))) { 26836 if (!strcasecmp(word, "port")) 26837 ast_set_flag(&flags[0], SIP_INSECURE_PORT); 26838 else if (!strcasecmp(word, "invite")) 26839 ast_set_flag(&flags[0], SIP_INSECURE_INVITE); 26840 else 26841 ast_log(LOG_WARNING, "Unknown insecure mode '%s' on line %d\n", value, lineno); 26842 } 26843 } 26844 }
| static void set_nonce_randdata | ( | struct sip_pvt * | p, | |
| int | forceupdate | |||
| ) | [static] |
builds the sip_pvt's randdata field which is used for the nonce challenge. When forceupdate is not set, the nonce is only updated if the current one is stale. In this case, a stalenonce is one which has already received a response, if a nonce has not received a response it is not always necessary or beneficial to create a new one.
Definition at line 14369 of file chan_sip.c.
References ast_random(), ast_string_field_build, and ast_strlen_zero().
Referenced by check_auth(), and transmit_fake_auth_response().
14370 { 14371 if (p->stalenonce || forceupdate || ast_strlen_zero(p->randdata)) { 14372 ast_string_field_build(p, randdata, "%08lx", ast_random()); /* Create nonce for challenge */ 14373 p->stalenonce = 0; 14374 } 14375 }
| static void set_peer_defaults | ( | struct sip_peer * | peer | ) | [static] |
Set peer defaults before configuring specific configurations.
Definition at line 27244 of file chan_sip.c.
References ast_copy_flags, ast_sockaddr_setnull(), ast_string_field_set, cid_name, cid_num, clear_peer_mailboxes(), context, default_prefs, language, mohinterpret, mohsuggest, secret, set_socket_transport(), and sip_cfg.
Referenced by build_peer(), and temp_peer().
27245 { 27246 if (peer->expire == 0) { 27247 /* Don't reset expire or port time during reload 27248 if we have an active registration 27249 */ 27250 peer->expire = -1; 27251 peer->pokeexpire = -1; 27252 set_socket_transport(&peer->socket, SIP_TRANSPORT_UDP); 27253 } 27254 peer->type = SIP_TYPE_PEER; 27255 ast_copy_flags(&peer->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 27256 ast_copy_flags(&peer->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 27257 ast_copy_flags(&peer->flags[2], &global_flags[2], SIP_PAGE3_FLAGS_TO_COPY); 27258 ast_string_field_set(peer, context, sip_cfg.default_context); 27259 ast_string_field_set(peer, subscribecontext, sip_cfg.default_subscribecontext); 27260 ast_string_field_set(peer, language, default_language); 27261 ast_string_field_set(peer, mohinterpret, default_mohinterpret); 27262 ast_string_field_set(peer, mohsuggest, default_mohsuggest); 27263 ast_string_field_set(peer, engine, default_engine); 27264 ast_sockaddr_setnull(&peer->addr); 27265 ast_sockaddr_setnull(&peer->defaddr); 27266 peer->capability = sip_cfg.capability; 27267 peer->maxcallbitrate = default_maxcallbitrate; 27268 peer->rtptimeout = global_rtptimeout; 27269 peer->rtpholdtimeout = global_rtpholdtimeout; 27270 peer->rtpkeepalive = global_rtpkeepalive; 27271 peer->allowtransfer = sip_cfg.allowtransfer; 27272 peer->autoframing = global_autoframing; 27273 peer->t38_maxdatagram = global_t38_maxdatagram; 27274 peer->qualifyfreq = global_qualifyfreq; 27275 if (global_callcounter) 27276 peer->call_limit=INT_MAX; 27277 ast_string_field_set(peer, vmexten, default_vmexten); 27278 ast_string_field_set(peer, secret, ""); 27279 ast_string_field_set(peer, remotesecret, ""); 27280 ast_string_field_set(peer, md5secret, ""); 27281 ast_string_field_set(peer, cid_num, ""); 27282 ast_string_field_set(peer, cid_name, ""); 27283 ast_string_field_set(peer, cid_tag, ""); 27284 ast_string_field_set(peer, fromdomain, ""); 27285 ast_string_field_set(peer, fromuser, ""); 27286 ast_string_field_set(peer, regexten, ""); 27287 peer->callgroup = 0; 27288 peer->pickupgroup = 0; 27289 peer->maxms = default_qualify; 27290 peer->prefs = default_prefs; 27291 peer->stimer.st_mode_oper = global_st_mode; /* Session-Timers */ 27292 peer->stimer.st_ref = global_st_refresher; 27293 peer->stimer.st_min_se = global_min_se; 27294 peer->stimer.st_max_se = global_max_se; 27295 peer->timer_t1 = global_t1; 27296 peer->timer_b = global_timer_b; 27297 clear_peer_mailboxes(peer); 27298 peer->disallowed_methods = sip_cfg.disallowed_methods; 27299 peer->transports = default_transports; 27300 peer->default_outbound_transport = default_primary_transport; 27301 }
| static unsigned int set_pvt_allowed_methods | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req | |||
| ) | [static] |
A wrapper for parse_allowed_methods geared toward sip_pvts
This function, in addition to setting the allowed methods for a sip_pvt also will take into account the setting of the SIP_PAGE2_RPID_UPDATE flag.
| pvt | The sip_pvt we are setting the allowed_methods for | |
| req | The request which we are parsing |
| The | methods alloweded by the sip_pvt |
Definition at line 8427 of file chan_sip.c.
References ast_test_flag, mark_method_allowed(), and parse_allowed_methods().
Referenced by check_peer_ok(), handle_request_invite(), handle_request_options(), handle_request_subscribe(), handle_response_invite(), and handle_response_subscribe().
08428 { 08429 pvt->allowed_methods = parse_allowed_methods(req); 08430 08431 if (ast_test_flag(&pvt->flags[1], SIP_PAGE2_RPID_UPDATE)) { 08432 mark_method_allowed(&pvt->allowed_methods, SIP_UPDATE); 08433 } 08434 pvt->allowed_methods &= ~(pvt->disallowed_methods); 08435 08436 return pvt->allowed_methods; 08437 }
| static void set_socket_transport | ( | struct sip_socket * | socket, | |
| int | transport | |||
| ) | [static] |
Definition at line 13763 of file chan_sip.c.
References ao2_ref.
Referenced by __sip_subscribe_mwi_do(), _sip_tcp_helper_thread(), build_peer(), create_addr(), expire_register(), get_transport_pvt(), parse_moved_contact(), parse_register_contact(), set_peer_defaults(), sip_alloc(), sip_request_call(), sip_send_mwi_to_peer(), sipsock_read(), and transmit_register().
13764 { 13765 /* if the transport type changes, clear all socket data */ 13766 if (socket->type != transport) { 13767 socket->fd = -1; 13768 socket->type = transport; 13769 if (socket->tcptls_session) { 13770 ao2_ref(socket->tcptls_session, -1); 13771 socket->tcptls_session = NULL; 13772 } 13773 } 13774 }
| static void set_t38_capabilities | ( | struct sip_pvt * | p | ) | [static] |
Set the global T38 capabilities on a SIP dialog structure.
Definition at line 5160 of file chan_sip.c.
References ast_test_flag, ast_udptl_set_error_correction_scheme(), UDPTL_ERROR_CORRECTION_FEC, UDPTL_ERROR_CORRECTION_NONE, and UDPTL_ERROR_CORRECTION_REDUNDANCY.
Referenced by check_peer_ok(), and initialize_udptl().
05161 { 05162 if (p->udptl) { 05163 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL_REDUNDANCY) { 05164 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_REDUNDANCY); 05165 } else if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL_FEC) { 05166 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_FEC); 05167 } else if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT) == SIP_PAGE2_T38SUPPORT_UDPTL) { 05168 ast_udptl_set_error_correction_scheme(p->udptl, UDPTL_ERROR_CORRECTION_NONE); 05169 } 05170 } 05171 }
| static int setup_srtp | ( | struct sip_srtp ** | srtp | ) | [static] |
Definition at line 29860 of file chan_sip.c.
References ast_log(), ast_rtp_engine_srtp_is_registered(), LOG_ERROR, and sip_srtp_alloc().
Referenced by process_crypto(), and sip_call().
29861 { 29862 if (!ast_rtp_engine_srtp_is_registered()) { 29863 ast_log(LOG_ERROR, "No SRTP module loaded, can't setup SRTP session.\n"); 29864 return -1; 29865 } 29866 29867 if (!(*srtp = sip_srtp_alloc())) { /* Allocate SRTP data structure */ 29868 return -1; 29869 } 29870 29871 return 0; 29872 }
| static int show_channels_cb | ( | void * | __cur, | |
| void * | __arg, | |||
| int | flags | |||
| ) | [static] |
callback for show channel|subscription
Definition at line 18415 of file chan_sip.c.
References ast_cli(), AST_CLI_YESNO, ast_extension_state2str(), ast_getformatname_multiple(), ast_sockaddr_stringify_addr(), ast_str_alloca, ast_test_flag, FORMAT, FORMAT4, NONE, peer_mailboxes_to_str(), referstatus2str(), S_OR, sip_real_dst(), and subscription_type2str().
Referenced by sip_show_channels().
18416 { 18417 struct sip_pvt *cur = __cur; 18418 struct __show_chan_arg *arg = __arg; 18419 const struct ast_sockaddr *dst = sip_real_dst(cur); 18420 18421 /* XXX indentation preserved to reduce diff. Will be fixed later */ 18422 if (cur->subscribed == NONE && !arg->subscriptions) { 18423 /* set if SIP transfer in progress */ 18424 const char *referstatus = cur->refer ? referstatus2str(cur->refer->status) : ""; 18425 char formatbuf[SIPBUFSIZE/2]; 18426 18427 ast_cli(arg->fd, FORMAT, ast_sockaddr_stringify_addr(dst), 18428 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 18429 cur->callid, 18430 ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0), 18431 AST_CLI_YESNO(ast_test_flag(&cur->flags[1], SIP_PAGE2_CALL_ONHOLD)), 18432 cur->needdestroy ? "(d)" : "", 18433 cur->lastmsg , 18434 referstatus, 18435 cur->relatedpeer ? cur->relatedpeer->name : "<guest>" 18436 ); 18437 arg->numchans++; 18438 } 18439 if (cur->subscribed != NONE && arg->subscriptions) { 18440 struct ast_str *mailbox_str = ast_str_alloca(512); 18441 if (cur->subscribed == MWI_NOTIFICATION && cur->relatedpeer) 18442 peer_mailboxes_to_str(&mailbox_str, cur->relatedpeer); 18443 ast_cli(arg->fd, FORMAT4, ast_sockaddr_stringify_addr(dst), 18444 S_OR(cur->username, S_OR(cur->cid_num, "(None)")), 18445 cur->callid, 18446 /* the 'complete' exten/context is hidden in the refer_to field for subscriptions */ 18447 cur->subscribed == MWI_NOTIFICATION ? "--" : cur->subscribeuri, 18448 cur->subscribed == MWI_NOTIFICATION ? "<none>" : ast_extension_state2str(cur->laststate), 18449 subscription_type2str(cur->subscribed), 18450 cur->subscribed == MWI_NOTIFICATION ? S_OR(mailbox_str->str, "<none>") : "<none>", 18451 cur->expiry 18452 ); 18453 arg->numchans++; 18454 } 18455 return 0; /* don't care, we scan all channels */ 18456 }
| static int show_chanstats_cb | ( | void * | __cur, | |
| void * | __arg, | |||
| int | flags | |||
| ) | [static] |
Callback for show_chanstats.
Definition at line 18026 of file chan_sip.c.
References ast_cli(), ast_log(), ast_rtp_instance_get_stats(), AST_RTP_INSTANCE_STAT_ALL, ast_sockaddr_stringify_addr(), ast_tvdiff_ms(), ast_tvnow(), ast_tvzero(), ast_channel::cdr, invstate2stringtable::desc, FORMAT, invitestate2string, LOG_WARNING, NONE, ast_rtp_instance_stats::rxcount, ast_rtp_instance_stats::rxjitter, ast_rtp_instance_stats::rxploss, ast_cdr::start, ast_rtp_instance_stats::txcount, ast_rtp_instance_stats::txjitter, and ast_rtp_instance_stats::txploss.
Referenced by sip_show_channelstats().
18027 { 18028 #define FORMAT2 "%-15.15s %-11.11s %-8.8s %-10.10s %-10.10s ( %%) %-6.6s %-10.10s %-10.10s ( %%) %-6.6s\n" 18029 #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" 18030 struct sip_pvt *cur = __cur; 18031 struct ast_rtp_instance_stats stats; 18032 char durbuf[10]; 18033 int duration; 18034 int durh, durm, durs; 18035 struct ast_channel *c = cur->owner; 18036 struct __show_chan_arg *arg = __arg; 18037 int fd = arg->fd; 18038 18039 18040 if (cur->subscribed != NONE) /* Subscriptions */ 18041 return 0; /* don't care, we scan all channels */ 18042 18043 if (!cur->rtp) { 18044 if (sipdebug) { 18045 ast_cli(fd, "%-15.15s %-11.11s (inv state: %s) -- %s\n", 18046 ast_sockaddr_stringify_addr(&cur->sa), cur->callid, 18047 invitestate2string[cur->invitestate].desc, 18048 "-- No RTP active"); 18049 } 18050 return 0; /* don't care, we scan all channels */ 18051 } 18052 18053 if (ast_rtp_instance_get_stats(cur->rtp, &stats, AST_RTP_INSTANCE_STAT_ALL)) { 18054 ast_log(LOG_WARNING, "Could not get RTP stats.\n"); 18055 return 0; 18056 } 18057 18058 if (c && c->cdr && !ast_tvzero(c->cdr->start)) { 18059 duration = (int)(ast_tvdiff_ms(ast_tvnow(), c->cdr->start) / 1000); 18060 durh = duration / 3600; 18061 durm = (duration % 3600) / 60; 18062 durs = duration % 60; 18063 snprintf(durbuf, sizeof(durbuf), "%02d:%02d:%02d", durh, durm, durs); 18064 } else { 18065 durbuf[0] = '\0'; 18066 } 18067 18068 ast_cli(fd, FORMAT, 18069 ast_sockaddr_stringify_addr(&cur->sa), 18070 cur->callid, 18071 durbuf, 18072 stats.rxcount > (unsigned int) 100000 ? (unsigned int) (stats.rxcount)/(unsigned int) 1000 : stats.rxcount, 18073 stats.rxcount > (unsigned int) 100000 ? "K":" ", 18074 stats.rxploss, 18075 (stats.rxcount + stats.rxploss) > 0 ? (double) stats.rxploss / (stats.rxcount + stats.rxploss) * 100 : 0, 18076 stats.rxjitter, 18077 stats.txcount > (unsigned int) 100000 ? (unsigned int) (stats.txcount)/(unsigned int) 1000 : stats.txcount, 18078 stats.txcount > (unsigned int) 100000 ? "K":" ", 18079 stats.txploss, 18080 stats.txcount > 0 ? (double) stats.txploss / stats.txcount * 100 : 0, 18081 stats.txjitter 18082 ); 18083 arg->numchans++; 18084 18085 return 0; /* don't care, we scan all channels */ 18086 }
| static int sip_addheader | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
Add a SIP header to an outbound INVITE.
Definition at line 29650 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_get_encoded_str(), ast_log(), ast_strlen_zero(), FALSE, inbuf(), len(), LOG_WARNING, pbx_builtin_getvar_helper(), pbx_builtin_setvar_helper(), and TRUE.
Referenced by load_module().
29651 { 29652 int no = 0; 29653 int ok = FALSE; 29654 char varbuf[30]; 29655 const char *inbuf = data; 29656 char *subbuf; 29657 29658 if (ast_strlen_zero(inbuf)) { 29659 ast_log(LOG_WARNING, "This application requires the argument: Header\n"); 29660 return 0; 29661 } 29662 ast_channel_lock(chan); 29663 29664 /* Check for headers */ 29665 while (!ok && no <= 50) { 29666 no++; 29667 snprintf(varbuf, sizeof(varbuf), "__SIPADDHEADER%.2d", no); 29668 29669 /* Compare without the leading underscores */ 29670 if ((pbx_builtin_getvar_helper(chan, (const char *) varbuf + 2) == (const char *) NULL)) { 29671 ok = TRUE; 29672 } 29673 } 29674 if (ok) { 29675 size_t len = strlen(inbuf); 29676 subbuf = alloca(len + 1); 29677 ast_get_encoded_str(inbuf, subbuf, len + 1); 29678 pbx_builtin_setvar_helper(chan, varbuf, subbuf); 29679 if (sipdebug) { 29680 ast_debug(1, "SIP Header added \"%s\" as %s\n", inbuf, varbuf); 29681 } 29682 } else { 29683 ast_log(LOG_WARNING, "Too many SIP headers added, max 50\n"); 29684 } 29685 ast_channel_unlock(chan); 29686 return 0; 29687 }
| struct sip_pvt* sip_alloc | ( | ast_string_field | callid, | |
| struct ast_sockaddr * | addr, | |||
| int | useglobal_nat, | |||
| const int | intended_method, | |||
| struct sip_request * | req | |||
| ) | [read] |
Allocate sip_pvt structure, set defaults and link in the container. Returns a reference to the object so whoever uses it later must remember to release the reference.
Definition at line 7665 of file chan_sip.c.
References ao2_t_alloc, ao2_t_link, ao2_t_ref, ast_cc_config_params_init, ast_copy_flags, ast_debug, AST_LIST_HEAD_INIT_NOLOCK, 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, build_callid_pvt(), build_via(), context, default_prefs, do_setnat(), free_via(), get_header(), internip, make_our_tag(), mohinterpret, mohsuggest, NONE, parkinglot, parse_via(), set_socket_transport(), sip_cfg, sip_destroy_fn(), sip_methods, cfsip_methods::text, and TRUE.
Referenced by __sip_subscribe_mwi_do(), find_call(), manager_sipnotify(), sip_cc_monitor_request_cc(), sip_cli_notify(), sip_poke_peer(), sip_request_call(), sip_send_mwi_to_peer(), transmit_publish(), and transmit_register().
07667 { 07668 struct sip_pvt *p; 07669 07670 if (!(p = ao2_t_alloc(sizeof(*p), sip_destroy_fn, "allocate a dialog(pvt) struct"))) 07671 return NULL; 07672 07673 if (ast_string_field_init(p, 512)) { 07674 ao2_t_ref(p, -1, "failed to string_field_init, drop p"); 07675 return NULL; 07676 } 07677 07678 if (!(p->cc_params = ast_cc_config_params_init())) { 07679 ao2_t_ref(p, -1, "Yuck, couldn't allocate cc_params struct. Get rid o' p"); 07680 return NULL; 07681 } 07682 07683 /* If this dialog is created as the result of an incoming Request. Lets store 07684 * some information about that request */ 07685 if (req) { 07686 struct sip_via *via; 07687 const char *cseq = get_header(req, "Cseq"); 07688 uint32_t seqno; 07689 07690 /* get branch parameter from initial Request that started this dialog */ 07691 via = parse_via(get_header(req, "Via")); 07692 if (via) { 07693 /* only store the branch if it begins with the magic prefix "z9hG4bK", otherwise 07694 * it is not useful to us to have it */ 07695 if (!ast_strlen_zero(via->branch) && !strncasecmp(via->branch, "z9hG4bK", 7)) { 07696 ast_string_field_set(p, initviabranch, via->branch); 07697 ast_string_field_set(p, initviasentby, via->sent_by); 07698 } 07699 free_via(via); 07700 } 07701 07702 /* Store initial incoming cseq. An error in sscanf here is ignored. There is no approperiate 07703 * except not storing the number. CSeq validation must take place before dialog creation in find_call */ 07704 if (!ast_strlen_zero(cseq) && (sscanf(cseq, "%30u", &seqno) == 1)) { 07705 p->init_icseq = seqno; 07706 } 07707 /* Later in ast_sip_ouraddrfor we need this to choose the right ip and port for the specific transport */ 07708 set_socket_transport(&p->socket, req->socket.type); 07709 } else { 07710 set_socket_transport(&p->socket, SIP_TRANSPORT_UDP); 07711 } 07712 07713 p->socket.fd = -1; 07714 p->method = intended_method; 07715 p->initid = -1; 07716 p->waitid = -1; 07717 p->reinviteid = -1; 07718 p->autokillid = -1; 07719 p->request_queue_sched_id = -1; 07720 p->provisional_keepalive_sched_id = -1; 07721 p->t38id = -1; 07722 p->subscribed = NONE; 07723 p->stateid = -1; 07724 p->sessionversion_remote = -1; 07725 p->session_modify = TRUE; 07726 p->stimer = NULL; 07727 p->prefs = default_prefs; /* Set default codecs for this call */ 07728 p->maxforwards = sip_cfg.default_max_forwards; 07729 07730 if (intended_method != SIP_OPTIONS) { /* Peerpoke has it's own system */ 07731 p->timer_t1 = global_t1; /* Default SIP retransmission timer T1 (RFC 3261) */ 07732 p->timer_b = global_timer_b; /* Default SIP transaction timer B (RFC 3261) */ 07733 } 07734 07735 if (!addr) { 07736 p->ourip = internip; 07737 } else { 07738 ast_sockaddr_copy(&p->sa, addr); 07739 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 07740 } 07741 07742 /* Copy global flags to this PVT at setup. */ 07743 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_FLAGS_TO_COPY); 07744 ast_copy_flags(&p->flags[1], &global_flags[1], SIP_PAGE2_FLAGS_TO_COPY); 07745 ast_copy_flags(&p->flags[2], &global_flags[2], SIP_PAGE3_FLAGS_TO_COPY); 07746 07747 p->do_history = recordhistory; 07748 07749 p->branch = ast_random(); 07750 make_our_tag(p); 07751 p->ocseq = INITIAL_CSEQ; 07752 p->allowed_methods = UINT_MAX; 07753 07754 if (sip_methods[intended_method].need_rtp) { 07755 p->maxcallbitrate = default_maxcallbitrate; 07756 p->autoframing = global_autoframing; 07757 } 07758 07759 if (useglobal_nat && addr) { 07760 /* Setup NAT structure according to global settings if we have an address */ 07761 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT_FORCE_RPORT); 07762 ast_sockaddr_copy(&p->recv, addr); 07763 07764 do_setnat(p); 07765 } 07766 07767 if (p->method != SIP_REGISTER) { 07768 ast_string_field_set(p, fromdomain, default_fromdomain); 07769 p->fromdomainport = default_fromdomainport; 07770 } 07771 build_via(p); 07772 if (!callid) 07773 build_callid_pvt(p); 07774 else 07775 ast_string_field_set(p, callid, callid); 07776 /* Assign default music on hold class */ 07777 ast_string_field_set(p, mohinterpret, default_mohinterpret); 07778 ast_string_field_set(p, mohsuggest, default_mohsuggest); 07779 p->capability = sip_cfg.capability; 07780 p->allowtransfer = sip_cfg.allowtransfer; 07781 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) || 07782 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 07783 p->noncodeccapability |= AST_RTP_DTMF; 07784 } 07785 ast_string_field_set(p, context, sip_cfg.default_context); 07786 ast_string_field_set(p, parkinglot, default_parkinglot); 07787 ast_string_field_set(p, engine, default_engine); 07788 07789 AST_LIST_HEAD_INIT_NOLOCK(&p->request_queue); 07790 07791 /* Add to active dialog list */ 07792 07793 ao2_t_link(dialogs, p, "link pvt into dialogs table"); 07794 07795 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"); 07796 return p; 07797 }
| static void sip_alreadygone | ( | struct sip_pvt * | dialog | ) | [static] |
Encapsulate setting of SIP_ALREADYGONE to be able to trace it with debugging.
Definition at line 3086 of file chan_sip.c.
References ast_debug.
Referenced by handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_refer(), handle_response(), handle_response_invite(), handle_response_publish(), handle_response_subscribe(), retrans_pkt(), sip_indicate(), and sip_sipredirect().
03087 { 03088 ast_debug(3, "Setting SIP_ALREADYGONE on dialog %s\n", dialog->callid); 03089 dialog->alreadygone = 1; 03090 }
| static int sip_answer | ( | struct ast_channel * | ast | ) | [static] |
sip_answer: Answer SIP call , send 200 OK on Invite Part of PBX interface
Definition at line 6482 of file chan_sip.c.
References ast_channel::_state, ast_debug, ast_rtp_instance_update_source(), ast_set_flag, ast_setstate(), AST_STATE_UP, FALSE, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_response_with_sdp(), TRUE, and try_suggested_sip_codec().
06483 { 06484 int res = 0; 06485 struct sip_pvt *p = ast->tech_pvt; 06486 06487 sip_pvt_lock(p); 06488 if (ast->_state != AST_STATE_UP) { 06489 try_suggested_sip_codec(p); 06490 06491 ast_setstate(ast, AST_STATE_UP); 06492 ast_debug(1, "SIP answering channel: %s\n", ast->name); 06493 ast_rtp_instance_update_source(p->rtp); 06494 res = transmit_response_with_sdp(p, "200 OK", &p->initreq, XMIT_CRITICAL, FALSE, TRUE); 06495 ast_set_flag(&p->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 06496 } 06497 sip_pvt_unlock(p); 06498 return res; 06499 }
| static int sip_call | ( | struct ast_channel * | ast, | |
| char * | dest, | |||
| int | timeout | |||
| ) | [static] |
Initiate SIP call from PBX used from the dial() application.
Definition at line 5534 of file chan_sip.c.
References ast_channel::_state, ao2_t_ref, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_USER_BUSY, ast_cc_get_monitor_by_recall_core_id(), ast_cc_is_recall(), ast_channel_get_device_name(), AST_CHANNEL_NAME, ast_channel_queue_connected_line_update(), ast_clear_flag, AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER, ast_copy_string(), ast_debug, AST_FORMAT_AUDIO_MASK, AST_LIST_TRAVERSE, ast_log(), ast_party_connected_line_init(), ast_party_id_presentation(), AST_PRES_ALLOWED, AST_PRES_RESTRICTION, ast_rtp_instance_available_formats(), AST_SCHED_REPLACE_UNREF, ast_set_flag, AST_STATE_DOWN, AST_STATE_RESERVED, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_var_name(), ast_var_value(), auto_congest(), ast_channel::caller, cid_name, connected, ast_channel::hangupcause, ast_party_connected_line::id, ast_set_party_connected_line::id, ast_party_caller::id, LOG_WARNING, ast_party_id::name, ast_set_party_id::name, ast_party_id::number, ast_set_party_id::number, ast_party_name::presentation, ast_party_number::presentation, ast_cc_monitor::private_data, setup_srtp(), sip_pvt_lock, sip_pvt_unlock, ast_party_connected_line::source, ast_party_name::str, ast_party_number::str, ast_party_id::tag, ast_channel::tech_pvt, transmit_invite(), update_call_counter(), ast_party_name::valid, ast_party_number::valid, and ast_channel::varshead.
05535 { 05536 int res; 05537 struct sip_pvt *p = ast->tech_pvt; /* chan is locked, so the reference cannot go away */ 05538 struct varshead *headp; 05539 struct ast_var_t *current; 05540 const char *referer = NULL; /* SIP referrer */ 05541 int cc_core_id; 05542 char uri[SIPBUFSIZE] = ""; 05543 05544 if ((ast->_state != AST_STATE_DOWN) && (ast->_state != AST_STATE_RESERVED)) { 05545 ast_log(LOG_WARNING, "sip_call called on %s, neither down nor reserved\n", ast->name); 05546 return -1; 05547 } 05548 05549 if (ast_cc_is_recall(ast, &cc_core_id, "SIP")) { 05550 char device_name[AST_CHANNEL_NAME]; 05551 struct ast_cc_monitor *recall_monitor; 05552 struct sip_monitor_instance *monitor_instance; 05553 ast_channel_get_device_name(ast, device_name, sizeof(device_name)); 05554 if ((recall_monitor = ast_cc_get_monitor_by_recall_core_id(cc_core_id, device_name))) { 05555 monitor_instance = recall_monitor->private_data; 05556 ast_copy_string(uri, monitor_instance->notify_uri, sizeof(uri)); 05557 ao2_t_ref(recall_monitor, -1, "Got the URI we need so unreffing monitor"); 05558 } 05559 } 05560 05561 /* Check whether there is vxml_url, distinctive ring variables */ 05562 headp=&ast->varshead; 05563 AST_LIST_TRAVERSE(headp, current, entries) { 05564 /* Check whether there is a VXML_URL variable */ 05565 if (!p->options->vxml_url && !strcasecmp(ast_var_name(current), "VXML_URL")) { 05566 p->options->vxml_url = ast_var_value(current); 05567 } else if (!p->options->uri_options && !strcasecmp(ast_var_name(current), "SIP_URI_OPTIONS")) { 05568 p->options->uri_options = ast_var_value(current); 05569 } else if (!p->options->addsipheaders && !strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 05570 /* Check whether there is a variable with a name starting with SIPADDHEADER */ 05571 p->options->addsipheaders = 1; 05572 } else if (!strcasecmp(ast_var_name(current), "SIPFROMDOMAIN")) { 05573 ast_string_field_set(p, fromdomain, ast_var_value(current)); 05574 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER")) { 05575 /* This is a transfered call */ 05576 p->options->transfer = 1; 05577 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REFERER")) { 05578 /* This is the referrer */ 05579 referer = ast_var_value(current); 05580 } else if (!strcasecmp(ast_var_name(current), "SIPTRANSFER_REPLACES")) { 05581 /* We're replacing a call. */ 05582 p->options->replaces = ast_var_value(current); 05583 } else if (!strcasecmp(ast_var_name(current), "SIP_MAX_FORWARDS")) { 05584 if (sscanf(ast_var_value(current), "%d", &(p->maxforwards)) != 1) { 05585 ast_log(LOG_WARNING, "The SIP_MAX_FORWARDS channel variable is not a valid integer.\n"); 05586 } 05587 } 05588 } 05589 05590 /* Check to see if we should try to force encryption */ 05591 if (p->req_secure_signaling && p->socket.type != SIP_TRANSPORT_TLS) { 05592 ast_log(LOG_WARNING, "Encrypted signaling is required\n"); 05593 ast->hangupcause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; 05594 return -1; 05595 } 05596 05597 if (ast_test_flag(&p->flags[1], SIP_PAGE2_USE_SRTP)) { 05598 if (ast_test_flag(&p->flags[0], SIP_REINVITE)) { 05599 ast_debug(1, "Direct media not possible when using SRTP, ignoring canreinvite setting\n"); 05600 ast_clear_flag(&p->flags[0], SIP_REINVITE); 05601 } 05602 05603 if (p->rtp && !p->srtp && setup_srtp(&p->srtp) < 0) { 05604 ast_log(LOG_WARNING, "SRTP audio setup failed\n"); 05605 return -1; 05606 } 05607 05608 if (p->vrtp && !p->vsrtp && setup_srtp(&p->vsrtp) < 0) { 05609 ast_log(LOG_WARNING, "SRTP video setup failed\n"); 05610 return -1; 05611 } 05612 05613 if (p->trtp && !p->tsrtp && setup_srtp(&p->tsrtp) < 0) { 05614 ast_log(LOG_WARNING, "SRTP text setup failed\n"); 05615 return -1; 05616 } 05617 } 05618 05619 res = 0; 05620 ast_set_flag(&p->flags[0], SIP_OUTGOING); 05621 05622 /* T.38 re-INVITE FAX detection should never be done for outgoing calls, 05623 * so ensure it is disabled. 05624 */ 05625 ast_clear_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_T38); 05626 05627 if (p->options->transfer) { 05628 char buf[SIPBUFSIZE/2]; 05629 05630 if (referer) { 05631 if (sipdebug) 05632 ast_debug(3, "Call for %s transfered by %s\n", p->username, referer); 05633 snprintf(buf, sizeof(buf)-1, "-> %s (via %s)", p->cid_name, referer); 05634 } else 05635 snprintf(buf, sizeof(buf)-1, "-> %s", p->cid_name); 05636 ast_string_field_set(p, cid_name, buf); 05637 } 05638 ast_debug(1, "Outgoing Call for %s\n", p->username); 05639 05640 res = update_call_counter(p, INC_CALL_RINGING); 05641 05642 if (res == -1) { 05643 ast->hangupcause = AST_CAUSE_USER_BUSY; 05644 return res; 05645 } 05646 p->callingpres = ast_party_id_presentation(&ast->caller.id); 05647 p->jointcapability = ast_rtp_instance_available_formats(p->rtp, p->capability, p->prefcodec); 05648 p->jointnoncodeccapability = p->noncodeccapability; 05649 05650 /* If there are no audio formats left to offer, punt */ 05651 if (!(p->jointcapability & AST_FORMAT_AUDIO_MASK)) { 05652 ast_log(LOG_WARNING, "No audio format found to offer. Cancelling call to %s\n", p->username); 05653 res = -1; 05654 } else { 05655 int xmitres; 05656 struct ast_party_connected_line connected; 05657 struct ast_set_party_connected_line update_connected; 05658 05659 sip_pvt_lock(p); 05660 05661 /* Supply initial connected line information if available. */ 05662 memset(&update_connected, 0, sizeof(update_connected)); 05663 ast_party_connected_line_init(&connected); 05664 if (!ast_strlen_zero(p->cid_num) 05665 || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 05666 update_connected.id.number = 1; 05667 connected.id.number.valid = 1; 05668 connected.id.number.str = (char *) p->cid_num; 05669 connected.id.number.presentation = p->callingpres; 05670 } 05671 if (!ast_strlen_zero(p->cid_name) 05672 || (p->callingpres & AST_PRES_RESTRICTION) != AST_PRES_ALLOWED) { 05673 update_connected.id.name = 1; 05674 connected.id.name.valid = 1; 05675 connected.id.name.str = (char *) p->cid_name; 05676 connected.id.name.presentation = p->callingpres; 05677 } 05678 if (update_connected.id.number || update_connected.id.name) { 05679 connected.id.tag = (char *) p->cid_tag; 05680 connected.source = AST_CONNECTED_LINE_UPDATE_SOURCE_ANSWER; 05681 ast_channel_queue_connected_line_update(ast, &connected, &update_connected); 05682 } 05683 05684 xmitres = transmit_invite(p, SIP_INVITE, 1, 2, uri); 05685 sip_pvt_unlock(p); 05686 if (xmitres == XMIT_ERROR) 05687 return -1; 05688 p->invitestate = INV_CALLING; 05689 05690 /* Initialize auto-congest time */ 05691 AST_SCHED_REPLACE_UNREF(p->initid, sched, p->timer_b, auto_congest, p, 05692 dialog_unref(_data, "dialog ptr dec when SCHED_REPLACE del op succeeded"), 05693 dialog_unref(p, "dialog ptr dec when SCHED_REPLACE add failed"), 05694 dialog_ref(p, "dialog ptr inc when SCHED_REPLACE add succeeded") ); 05695 } 05696 return res; 05697 }
| int sip_cancel_destroy | ( | struct sip_pvt * | p | ) |
Cancel destruction of SIP dialog. Be careful as this also absorbs the reference - if you call it from within the scheduler, this might be the last reference.
Definition at line 3954 of file chan_sip.c.
References append_history, and AST_SCHED_DEL_UNREF.
Referenced by handle_request_invite(), handle_request_subscribe(), handle_response(), handle_response_invite(), register_verify(), sip_hangup(), and sip_scheddestroy().
03955 { 03956 if (p->final_destruction_scheduled) { 03957 return 0; 03958 } 03959 03960 if (p->autokillid > -1) { 03961 append_history(p, "CancelDestroy", ""); 03962 AST_SCHED_DEL_UNREF(sched, p->autokillid, dialog_unref(p, "remove ref for autokillid")); 03963 } 03964 return 0; 03965 }
| static void sip_cc_agent_destructor | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1814 of file chan_sip.c.
References ast_free, ast_test_flag, ast_cc_agent::private_data, sip_cc_agent_stop_offer_timer(), sip_pvt_lock, sip_pvt_unlock, and transmit_response().
01815 { 01816 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01817 01818 if (!agent_pvt) { 01819 /* The agent constructor probably failed. */ 01820 return; 01821 } 01822 01823 sip_cc_agent_stop_offer_timer(agent); 01824 if (agent_pvt->subscribe_pvt) { 01825 sip_pvt_lock(agent_pvt->subscribe_pvt); 01826 if (!ast_test_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED)) { 01827 /* If we haven't sent a 200 OK for the SUBSCRIBE dialog yet, then we need to send a response letting 01828 * the subscriber know something went wrong 01829 */ 01830 transmit_response(agent_pvt->subscribe_pvt, "500 Internal Server Error", &agent_pvt->subscribe_pvt->initreq); 01831 } 01832 sip_pvt_unlock(agent_pvt->subscribe_pvt); 01833 agent_pvt->subscribe_pvt = dialog_unref(agent_pvt->subscribe_pvt, "SIP CC agent destructor: Remove ref to subscription"); 01834 } 01835 ast_free(agent_pvt); 01836 }
| static int sip_cc_agent_init | ( | struct ast_cc_agent * | agent, | |
| struct ast_channel * | chan | |||
| ) | [static] |
Definition at line 1701 of file chan_sip.c.
References ast_assert, ast_calloc, ast_copy_string(), ast_set_flag, ast_cc_agent::private_data, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech, ast_channel::tech_pvt, and ast_channel_tech::type.
01702 { 01703 struct sip_cc_agent_pvt *agent_pvt = ast_calloc(1, sizeof(*agent_pvt)); 01704 struct sip_pvt *call_pvt = chan->tech_pvt; 01705 01706 if (!agent_pvt) { 01707 return -1; 01708 } 01709 01710 ast_assert(!strcmp(chan->tech->type, "SIP")); 01711 01712 ast_copy_string(agent_pvt->original_callid, call_pvt->callid, sizeof(agent_pvt->original_callid)); 01713 ast_copy_string(agent_pvt->original_exten, call_pvt->exten, sizeof(agent_pvt->original_exten)); 01714 agent_pvt->offer_timer_id = -1; 01715 agent->private_data = agent_pvt; 01716 sip_pvt_lock(call_pvt); 01717 ast_set_flag(&call_pvt->flags[0], SIP_OFFER_CC); 01718 sip_pvt_unlock(call_pvt); 01719 return 0; 01720 }
| static int sip_cc_agent_recall | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1794 of file chan_sip.c.
References ast_cc_agent_caller_busy(), ast_cc_agent::core_id, ast_cc_agent::device_name, ast_cc_agent::private_data, sip_pvt_lock, sip_pvt_unlock, and transmit_cc_notify().
01795 { 01796 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01797 /* If we have received a PUBLISH beforehand stating that the caller in question 01798 * is not available, we can save ourself a bit of effort here and just report 01799 * the caller as busy 01800 */ 01801 if (!agent_pvt->is_available) { 01802 return ast_cc_agent_caller_busy(agent->core_id, "Caller %s is busy, reporting to the core", 01803 agent->device_name); 01804 } 01805 /* Otherwise, we transmit a NOTIFY to the caller and await either 01806 * a PUBLISH or an INVITE 01807 */ 01808 sip_pvt_lock(agent_pvt->subscribe_pvt); 01809 transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_READY); 01810 sip_pvt_unlock(agent_pvt->subscribe_pvt); 01811 return 0; 01812 }
| static void sip_cc_agent_respond | ( | struct ast_cc_agent * | agent, | |
| enum ast_cc_agent_response_reason | reason | |||
| ) | [static] |
Definition at line 1750 of file chan_sip.c.
References AST_CC_AGENT_RESPONSE_SUCCESS, ast_set_flag, ast_strlen_zero(), ast_cc_agent::private_data, sip_pvt_lock, sip_pvt_unlock, transmit_cc_notify(), transmit_response(), and TRUE.
01751 { 01752 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01753 01754 sip_pvt_lock(agent_pvt->subscribe_pvt); 01755 ast_set_flag(&agent_pvt->subscribe_pvt->flags[1], SIP_PAGE2_DIALOG_ESTABLISHED); 01756 if (reason == AST_CC_AGENT_RESPONSE_SUCCESS || !ast_strlen_zero(agent_pvt->notify_uri)) { 01757 /* The second half of this if statement may be a bit hard to grasp, 01758 * so here's an explanation. When a subscription comes into 01759 * chan_sip, as long as it is not malformed, it will be passed 01760 * to the CC core. If the core senses an out-of-order state transition, 01761 * then the core will call this callback with the "reason" set to a 01762 * failure condition. 01763 * However, an out-of-order state transition will occur during a resubscription 01764 * for CC. In such a case, we can see that we have already generated a notify_uri 01765 * and so we can detect that this isn't a *real* failure. Rather, it is just 01766 * something the core doesn't recognize as a legitimate SIP state transition. 01767 * Thus we respond with happiness and flowers. 01768 */ 01769 transmit_response(agent_pvt->subscribe_pvt, "200 OK", &agent_pvt->subscribe_pvt->initreq); 01770 transmit_cc_notify(agent, agent_pvt->subscribe_pvt, CC_QUEUED); 01771 } else { 01772 transmit_response(agent_pvt->subscribe_pvt, "500 Internal Error", &agent_pvt->subscribe_pvt->initreq); 01773 } 01774 sip_pvt_unlock(agent_pvt->subscribe_pvt); 01775 agent_pvt->is_available = TRUE; 01776 }
| static int sip_cc_agent_start_monitoring | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1785 of file chan_sip.c.
| static int sip_cc_agent_start_offer_timer | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1732 of file chan_sip.c.
References ast_get_cc_offer_timer(), ast_sched_add(), ast_cc_agent::cc_params, ast_cc_agent::private_data, and sip_offer_timer_expire().
01733 { 01734 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01735 int when; 01736 01737 when = ast_get_cc_offer_timer(agent->cc_params) * 1000; 01738 agent_pvt->offer_timer_id = ast_sched_add(sched, when, sip_offer_timer_expire, agent); 01739 return 0; 01740 }
| static int sip_cc_agent_status_request | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1778 of file chan_sip.c.
References ast_cc_agent_status_response(), AST_DEVICE_INUSE, AST_DEVICE_NOT_INUSE, ast_cc_agent::core_id, and ast_cc_agent::private_data.
01779 { 01780 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01781 enum ast_device_state state = agent_pvt->is_available ? AST_DEVICE_NOT_INUSE : AST_DEVICE_INUSE; 01782 return ast_cc_agent_status_response(agent->core_id, state); 01783 }
| static int sip_cc_agent_stop_offer_timer | ( | struct ast_cc_agent * | agent | ) | [static] |
Definition at line 1742 of file chan_sip.c.
References AST_SCHED_DEL, and ast_cc_agent::private_data.
Referenced by sip_cc_agent_destructor().
01743 { 01744 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01745 01746 AST_SCHED_DEL(sched, agent_pvt->offer_timer_id); 01747 return 0; 01748 }
| static int sip_cc_monitor_cancel_available_timer | ( | struct ast_cc_monitor * | monitor, | |
| int * | sched_id | |||
| ) | [static] |
Definition at line 2053 of file chan_sip.c.
References ao2_t_ref, and AST_SCHED_DEL.
02054 { 02055 if (*sched_id != -1) { 02056 AST_SCHED_DEL(sched, *sched_id); 02057 ao2_t_ref(monitor, -1, "Removing scheduler's reference to the monitor"); 02058 } 02059 return 0; 02060 }
| static void sip_cc_monitor_destructor | ( | void * | private_data | ) | [static] |
Definition at line 2062 of file chan_sip.c.
References ao2_unlink, and ast_module_unref().
02063 { 02064 struct sip_monitor_instance *monitor_instance = private_data; 02065 ao2_unlink(sip_monitor_instances, monitor_instance); 02066 ast_module_unref(ast_module_info->self); 02067 }
| static int sip_cc_monitor_request_cc | ( | struct ast_cc_monitor * | monitor, | |
| int * | available_timer_id | |||
| ) | [static] |
Definition at line 1920 of file chan_sip.c.
References ao2_t_ref, ast_cc_available_timer_expire(), AST_CC_CCBS, ast_get_ccbs_available_timer(), ast_get_ccnr_available_timer(), ast_sched_add(), ast_set_flag, ast_sip_ouraddrfor(), ast_cc_interface::config_params, create_addr(), FALSE, ast_cc_monitor::interface, ast_cc_monitor::private_data, service, ast_cc_monitor::service_offered, sip_alloc(), sip_pvt_lock, sip_pvt_unlock, and transmit_invite().
01921 { 01922 struct sip_monitor_instance *monitor_instance = monitor->private_data; 01923 enum ast_cc_service_type service = monitor->service_offered; 01924 int when; 01925 01926 if (!monitor_instance) { 01927 return -1; 01928 } 01929 01930 if (!(monitor_instance->subscription_pvt = sip_alloc(NULL, NULL, 0, SIP_SUBSCRIBE, NULL))) { 01931 return -1; 01932 } 01933 01934 when = service == AST_CC_CCBS ? ast_get_ccbs_available_timer(monitor->interface->config_params) : 01935 ast_get_ccnr_available_timer(monitor->interface->config_params); 01936 01937 sip_pvt_lock(monitor_instance->subscription_pvt); 01938 ast_set_flag(&monitor_instance->subscription_pvt->flags[0], SIP_OUTGOING); 01939 create_addr(monitor_instance->subscription_pvt, monitor_instance->peername, 0, 1, NULL); 01940 ast_sip_ouraddrfor(&monitor_instance->subscription_pvt->sa, &monitor_instance->subscription_pvt->ourip, monitor_instance->subscription_pvt); 01941 monitor_instance->subscription_pvt->subscribed = CALL_COMPLETION; 01942 monitor_instance->subscription_pvt->expiry = when; 01943 01944 transmit_invite(monitor_instance->subscription_pvt, SIP_SUBSCRIBE, FALSE, 2, monitor_instance->subscribe_uri); 01945 sip_pvt_unlock(monitor_instance->subscription_pvt); 01946 01947 ao2_t_ref(monitor, +1, "Adding a ref to the monitor for the scheduler"); 01948 *available_timer_id = ast_sched_add(sched, when * 1000, ast_cc_available_timer_expire, monitor); 01949 return 0; 01950 }
| static int sip_cc_monitor_suspend | ( | struct ast_cc_monitor * | monitor | ) | [static] |
Definition at line 1978 of file chan_sip.c.
References ao2_ref, ast_calloc, ast_log(), ast_strlen_zero(), construct_pidf_body(), ast_cc_monitor::core_id, create_epa_entry(), LOG_WARNING, ast_cc_monitor::private_data, and transmit_publish().
01979 { 01980 struct sip_monitor_instance *monitor_instance = monitor->private_data; 01981 enum sip_publish_type publish_type; 01982 struct cc_epa_entry *cc_entry; 01983 01984 if (!monitor_instance) { 01985 return -1; 01986 } 01987 01988 if (!monitor_instance->suspension_entry) { 01989 /* We haven't yet allocated the suspension entry, so let's give it a shot */ 01990 if (!(monitor_instance->suspension_entry = create_epa_entry("call-completion", monitor_instance->peername))) { 01991 ast_log(LOG_WARNING, "Unable to allocate sip EPA entry for call-completion\n"); 01992 ao2_ref(monitor_instance, -1); 01993 return -1; 01994 } 01995 if (!(cc_entry = ast_calloc(1, sizeof(*cc_entry)))) { 01996 ast_log(LOG_WARNING, "Unable to allocate space for instance data of EPA entry for call-completion\n"); 01997 ao2_ref(monitor_instance, -1); 01998 return -1; 01999 } 02000 cc_entry->core_id = monitor->core_id; 02001 monitor_instance->suspension_entry->instance_data = cc_entry; 02002 publish_type = SIP_PUBLISH_INITIAL; 02003 } else { 02004 publish_type = SIP_PUBLISH_MODIFY; 02005 cc_entry = monitor_instance->suspension_entry->instance_data; 02006 } 02007 02008 cc_entry->current_state = CC_CLOSED; 02009 02010 if (ast_strlen_zero(monitor_instance->notify_uri)) { 02011 /* If we have no set notify_uri, then what this means is that we have 02012 * not received a NOTIFY from this destination stating that he is 02013 * currently available. 02014 * 02015 * This situation can arise when the core calls the suspend callbacks 02016 * of multiple destinations. If one of the other destinations aside 02017 * from this one notified Asterisk that he is available, then there 02018 * is no reason to take any suspension action on this device. Rather, 02019 * we should return now and if we receive a NOTIFY while monitoring 02020 * is still "suspended" then we can immediately respond with the 02021 * proper PUBLISH to let this endpoint know what is going on. 02022 */ 02023 return 0; 02024 } 02025 construct_pidf_body(CC_CLOSED, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername); 02026 return transmit_publish(monitor_instance->suspension_entry, publish_type, monitor_instance->notify_uri); 02027 }
| static int sip_cc_monitor_unsuspend | ( | struct ast_cc_monitor * | monitor | ) | [static] |
Definition at line 2029 of file chan_sip.c.
References ast_assert, ast_strlen_zero(), construct_pidf_body(), ast_cc_monitor::private_data, and transmit_publish().
02030 { 02031 struct sip_monitor_instance *monitor_instance = monitor->private_data; 02032 struct cc_epa_entry *cc_entry; 02033 02034 if (!monitor_instance) { 02035 return -1; 02036 } 02037 02038 ast_assert(monitor_instance->suspension_entry != NULL); 02039 02040 cc_entry = monitor_instance->suspension_entry->instance_data; 02041 cc_entry->current_state = CC_OPEN; 02042 if (ast_strlen_zero(monitor_instance->notify_uri)) { 02043 /* This means we are being asked to unsuspend a call leg we never 02044 * sent a PUBLISH on. As such, there is no reason to send another 02045 * PUBLISH at this point either. We can just return instead. 02046 */ 02047 return 0; 02048 } 02049 construct_pidf_body(CC_OPEN, monitor_instance->suspension_entry->body, sizeof(monitor_instance->suspension_entry->body), monitor_instance->peername); 02050 return transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_MODIFY, monitor_instance->notify_uri); 02051 }
| static int sip_check_authtimeout | ( | time_t | start | ) | [static] |
Check if the authtimeout has expired.
| start | the time when the session started |
| 0 | the timeout has expired | |
| -1 | error |
Definition at line 2483 of file chan_sip.c.
References ast_log(), errno, and LOG_ERROR.
Referenced by _sip_tcp_helper_thread().
02484 { 02485 int timeout; 02486 time_t now; 02487 if(time(&now) == -1) { 02488 ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno)); 02489 return -1; 02490 } 02491 02492 timeout = (authtimeout - (now - start)) * 1000; 02493 if (timeout < 0) { 02494 /* we have timed out */ 02495 return 0; 02496 } 02497 02498 return timeout; 02499 }
| static char * sip_cli_notify | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Cli command to send SIP notify to peer.
Definition at line 19092 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), ast_log(), ast_set_flag, ast_str_append(), ast_str_strlen(), ast_unescape_semicolon(), ast_variable_browse(), ast_variable_new(), CLI_FAILURE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sipnotify(), create_addr(), dialog_unlink_all(), ast_cli_args::fd, ast_cli_args::line, LOG_WARNING, ast_cli_args::n, ast_variable::name, ast_variable::next, ast_cli_args::pos, sip_alloc(), sip_notify_allocate(), sip_scheddestroy(), transmit_invite(), ast_cli_entry::usage, ast_variable::value, var, and ast_cli_args::word.
19093 { 19094 struct ast_variable *varlist; 19095 int i; 19096 19097 switch (cmd) { 19098 case CLI_INIT: 19099 e->command = "sip notify"; 19100 e->usage = 19101 "Usage: sip notify <type> <peer> [<peer>...]\n" 19102 " Send a NOTIFY message to a SIP peer or peers\n" 19103 " Message types are defined in sip_notify.conf\n"; 19104 return NULL; 19105 case CLI_GENERATE: 19106 return complete_sipnotify(a->line, a->word, a->pos, a->n); 19107 } 19108 19109 if (a->argc < 4) 19110 return CLI_SHOWUSAGE; 19111 19112 if (!notify_types) { 19113 ast_cli(a->fd, "No %s file found, or no types listed there\n", notify_config); 19114 return CLI_FAILURE; 19115 } 19116 19117 varlist = ast_variable_browse(notify_types, a->argv[2]); 19118 19119 if (!varlist) { 19120 ast_cli(a->fd, "Unable to find notify type '%s'\n", a->argv[2]); 19121 return CLI_FAILURE; 19122 } 19123 19124 for (i = 3; i < a->argc; i++) { 19125 struct sip_pvt *p; 19126 char buf[512]; 19127 struct ast_variable *header, *var; 19128 19129 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) { 19130 ast_log(LOG_WARNING, "Unable to build sip pvt data for notify (memory/socket error)\n"); 19131 return CLI_FAILURE; 19132 } 19133 19134 if (create_addr(p, a->argv[i], NULL, 1, NULL)) { 19135 /* Maybe they're not registered, etc. */ 19136 dialog_unlink_all(p); 19137 dialog_unref(p, "unref dialog inside for loop" ); 19138 /* sip_destroy(p); */ 19139 ast_cli(a->fd, "Could not create address for '%s'\n", a->argv[i]); 19140 continue; 19141 } 19142 19143 /* Notify is outgoing call */ 19144 ast_set_flag(&p->flags[0], SIP_OUTGOING); 19145 sip_notify_allocate(p); 19146 p->notify->headers = header = ast_variable_new("Subscription-State", "terminated", ""); 19147 19148 for (var = varlist; var; var = var->next) { 19149 ast_copy_string(buf, var->value, sizeof(buf)); 19150 ast_unescape_semicolon(buf); 19151 19152 if (!strcasecmp(var->name, "Content")) { 19153 if (ast_str_strlen(p->notify->content)) 19154 ast_str_append(&p->notify->content, 0, "\r\n"); 19155 ast_str_append(&p->notify->content, 0, "%s", buf); 19156 } else if (!strcasecmp(var->name, "Content-Length")) { 19157 ast_log(LOG_WARNING, "it is not necessary to specify Content-Length in sip_notify.conf, ignoring\n"); 19158 } else { 19159 header->next = ast_variable_new(var->name, buf, ""); 19160 header = header->next; 19161 } 19162 } 19163 19164 /* Recalculate our side, and recalculate Call ID */ 19165 ast_cli(a->fd, "Sending NOTIFY of type '%s' to '%s'\n", a->argv[2], a->argv[i]); 19166 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); 19167 transmit_invite(p, SIP_NOTIFY, 0, 2, NULL); 19168 dialog_unref(p, "bump down the count of p since we're done with it."); 19169 } 19170 19171 return CLI_SUCCESS; 19172 }
| static int sip_debug_test_addr | ( | const struct ast_sockaddr * | addr | ) | [inline, static] |
See if we pass debug IP filter.
Definition at line 3183 of file chan_sip.c.
References ast_sockaddr_cmp(), ast_sockaddr_cmp_addr(), ast_sockaddr_isnull(), ast_sockaddr_port, and debugaddr.
Referenced by check_peer_ok(), handle_request_do(), and sip_debug_test_pvt().
03184 { 03185 /* Can't debug if sipdebug is not enabled */ 03186 if (!sipdebug) { 03187 return 0; 03188 } 03189 03190 /* A null debug_addr means we'll debug any address */ 03191 if (ast_sockaddr_isnull(&debugaddr)) { 03192 return 1; 03193 } 03194 03195 /* If no port was specified for a debug address, just compare the 03196 * addresses, otherwise compare the address and port 03197 */ 03198 if (ast_sockaddr_port(&debugaddr)) { 03199 return !ast_sockaddr_cmp(&debugaddr, addr); 03200 } else { 03201 return !ast_sockaddr_cmp_addr(&debugaddr, addr); 03202 } 03203 }
| static int sip_debug_test_pvt | ( | struct sip_pvt * | p | ) | [inline, static] |
Test PVT for debugging output.
Definition at line 3222 of file chan_sip.c.
References sip_debug_test_addr(), and sip_real_dst().
Referenced by __sip_destroy(), add_sdp(), build_route(), check_via(), do_register_auth(), get_also_info(), get_destination(), get_rdnis(), get_refer_info(), handle_incoming(), process_sdp(), process_sdp_a_audio(), process_sdp_a_text(), process_sdp_a_video(), receive_message(), retrans_pkt(), send_request(), send_response(), set_destination(), sip_scheddestroy(), sip_sendhtml(), sip_sendtext(), and transmit_register().
03223 { 03224 if (!sipdebug) { 03225 return 0; 03226 } 03227 return sip_debug_test_addr(sip_real_dst(p)); 03228 }
| struct sip_pvt* sip_destroy | ( | struct sip_pvt * | p | ) | [read] |
Destroy SIP call structure. Make it return NULL so the caller can do things like foo = sip_destroy(foo); and reduce the chance of bugs due to dangling pointers.
Definition at line 6051 of file chan_sip.c.
References __sip_destroy(), ast_debug, and TRUE.
Referenced by sip_destroy_fn(), and sip_subscribe_mwi_destroy().
06052 { 06053 ast_debug(3, "Destroying SIP dialog %s\n", p->callid); 06054 __sip_destroy(p, TRUE, TRUE); 06055 return NULL; 06056 }
| static void sip_destroy_fn | ( | void * | p | ) | [static] |
Definition at line 6041 of file chan_sip.c.
References sip_destroy().
Referenced by sip_alloc().
06042 { 06043 sip_destroy(p); 06044 }
| static void sip_destroy_peer | ( | struct sip_peer * | peer | ) | [static] |
Destroy peer object from memory.
Definition at line 4610 of file chan_sip.c.
References ao2_ref, ao2_t_ref, ast_atomic_fetchadd_int(), ast_cc_config_params_destroy(), ast_debug, ast_free_ha(), ast_string_field_free_memory, ast_test_flag, ast_variables_destroy(), clear_peer_mailboxes(), dialog_unlink_all(), FALSE, and register_peer_exten().
Referenced by sip_destroy_peer_fn().
04611 { 04612 ast_debug(3, "Destroying SIP peer %s\n", peer->name); 04613 04614 /* 04615 * Remove any mailbox event subscriptions for this peer before 04616 * we destroy anything. An event subscription callback may be 04617 * happening right now. 04618 */ 04619 clear_peer_mailboxes(peer); 04620 04621 if (peer->outboundproxy) { 04622 ao2_ref(peer->outboundproxy, -1); 04623 peer->outboundproxy = NULL; 04624 } 04625 04626 /* Delete it, it needs to disappear */ 04627 if (peer->call) { 04628 dialog_unlink_all(peer->call); 04629 peer->call = dialog_unref(peer->call, "peer->call is being unset"); 04630 } 04631 04632 if (peer->mwipvt) { /* We have an active subscription, delete it */ 04633 dialog_unlink_all(peer->mwipvt); 04634 peer->mwipvt = dialog_unref(peer->mwipvt, "unreffing peer->mwipvt"); 04635 } 04636 04637 if (peer->chanvars) { 04638 ast_variables_destroy(peer->chanvars); 04639 peer->chanvars = NULL; 04640 } 04641 04642 register_peer_exten(peer, FALSE); 04643 ast_free_ha(peer->ha); 04644 ast_free_ha(peer->directmediaha); 04645 if (peer->selfdestruct) 04646 ast_atomic_fetchadd_int(&apeerobjs, -1); 04647 else if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && peer->is_realtime) { 04648 ast_atomic_fetchadd_int(&rpeerobjs, -1); 04649 ast_debug(3, "-REALTIME- peer Destroyed. Name: %s. Realtime Peer objects: %d\n", peer->name, rpeerobjs); 04650 } else 04651 ast_atomic_fetchadd_int(&speerobjs, -1); 04652 if (peer->auth) { 04653 ao2_t_ref(peer->auth, -1, "Removing peer authentication"); 04654 peer->auth = NULL; 04655 } 04656 04657 if (peer->socket.tcptls_session) { 04658 ao2_ref(peer->socket.tcptls_session, -1); 04659 peer->socket.tcptls_session = NULL; 04660 } 04661 04662 ast_cc_config_params_destroy(peer->cc_params); 04663 04664 ast_string_field_free_memory(peer); 04665 }
| static void sip_destroy_peer_fn | ( | void * | peer | ) | [static] |
Definition at line 4604 of file chan_sip.c.
References sip_destroy_peer().
Referenced by build_peer(), and temp_peer().
04605 { 04606 sip_destroy_peer(peer); 04607 }
| static int sip_devicestate | ( | void * | data | ) | [static] |
Part of PBX channel interface.
If we have qualify on and the device is not reachable, regardless of registration state we return AST_DEVICE_UNAVAILABLE
For peers with call limit:
For peers without call limit:
Peers that does not have a known call and can't be reached by OPTIONS
If we return AST_DEVICE_UNKNOWN, the device state engine will try to find out a state by walking the channel list.
The queue system (app_queue.c) treats a member as "active" if devicestate is != AST_DEVICE_UNAVAILBALE && != AST_DEVICE_INVALID
When placing a call to the queue member, queue system sets a member to busy if != AST_DEVICE_NOT_INUSE and != AST_DEVICE_UNKNOWN
Definition at line 26546 of file chan_sip.c.
References ast_debug, AST_DEVICE_BUSY, AST_DEVICE_INUSE, AST_DEVICE_INVALID, AST_DEVICE_NOT_INUSE, AST_DEVICE_ONHOLD, AST_DEVICE_RINGING, AST_DEVICE_RINGINUSE, AST_DEVICE_UNAVAILABLE, ast_sockaddr_isnull(), ast_strdupa, FALSE, find_peer(), TRUE, and unref_peer().
26547 { 26548 char *host; 26549 char *tmp; 26550 struct sip_peer *p; 26551 26552 int res = AST_DEVICE_INVALID; 26553 26554 /* make sure data is not null. Maybe unnecessary, but better be safe */ 26555 host = ast_strdupa(data ? data : ""); 26556 if ((tmp = strchr(host, '@'))) 26557 host = tmp + 1; 26558 26559 ast_debug(3, "Checking device state for peer %s\n", host); 26560 26561 /* If find_peer asks for a realtime peer, then this breaks rtautoclear. This 26562 * is because when a peer tries to autoexpire, the last thing it does is to 26563 * queue up an event telling the system that the devicestate has changed 26564 * (presumably to unavailable). If we ask for a realtime peer here, this would 26565 * load it BACK into memory, thus defeating the point of trying to clear dead 26566 * hosts out of memory. 26567 */ 26568 if ((p = find_peer(host, NULL, FALSE, FINDALLDEVICES, TRUE, 0))) { 26569 if (!(ast_sockaddr_isnull(&p->addr) && ast_sockaddr_isnull(&p->defaddr))) { 26570 /* we have an address for the peer */ 26571 26572 /* Check status in this order 26573 - Hold 26574 - Ringing 26575 - Busy (enforced only by call limit) 26576 - Inuse (we have a call) 26577 - Unreachable (qualify) 26578 If we don't find any of these state, report AST_DEVICE_NOT_INUSE 26579 for registered devices */ 26580 26581 if (p->onHold) 26582 /* First check for hold or ring states */ 26583 res = AST_DEVICE_ONHOLD; 26584 else if (p->inRinging) { 26585 if (p->inRinging == p->inUse) 26586 res = AST_DEVICE_RINGING; 26587 else 26588 res = AST_DEVICE_RINGINUSE; 26589 } else if (p->call_limit && (p->inUse == p->call_limit)) 26590 /* check call limit */ 26591 res = AST_DEVICE_BUSY; 26592 else if (p->call_limit && p->busy_level && p->inUse >= p->busy_level) 26593 /* We're forcing busy before we've reached the call limit */ 26594 res = AST_DEVICE_BUSY; 26595 else if (p->call_limit && p->inUse) 26596 /* Not busy, but we do have a call */ 26597 res = AST_DEVICE_INUSE; 26598 else if (p->maxms && ((p->lastms > p->maxms) || (p->lastms < 0))) 26599 /* We don't have a call. Are we reachable at all? Requires qualify= */ 26600 res = AST_DEVICE_UNAVAILABLE; 26601 else /* Default reply if we're registered and have no other data */ 26602 res = AST_DEVICE_NOT_INUSE; 26603 } else { 26604 /* there is no address, it's unavailable */ 26605 res = AST_DEVICE_UNAVAILABLE; 26606 } 26607 unref_peer(p, "unref_peer, from sip_devicestate, release ref from find_peer"); 26608 } 26609 26610 return res; 26611 }
| static char * sip_do_debug | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Turn on SIP debugging (CLI command).
Definition at line 19049 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_peer(), debugaddr, ast_cli_args::fd, ast_cli_args::n, ast_cli_args::pos, sip_do_debug_ip(), sip_do_debug_peer(), ast_cli_entry::usage, and ast_cli_args::word.
19050 { 19051 int oldsipdebug = sipdebug & sip_debug_console; 19052 const char *what; 19053 19054 if (cmd == CLI_INIT) { 19055 e->command = "sip set debug {on|off|ip|peer}"; 19056 e->usage = 19057 "Usage: sip set debug {off|on|ip addr[:port]|peer peername}\n" 19058 " Globally disables dumping of SIP packets,\n" 19059 " or enables it either globally or for a (single)\n" 19060 " IP address or registered peer.\n"; 19061 return NULL; 19062 } else if (cmd == CLI_GENERATE) { 19063 if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) 19064 return complete_sip_peer(a->word, a->n, 0); 19065 return NULL; 19066 } 19067 19068 what = a->argv[e->args-1]; /* guaranteed to exist */ 19069 if (a->argc == e->args) { /* on/off */ 19070 if (!strcasecmp(what, "on")) { 19071 sipdebug |= sip_debug_console; 19072 sipdebug_text = 1; /*! \note this can be a special debug command - "sip debug text" or something */ 19073 memset(&debugaddr, 0, sizeof(debugaddr)); 19074 ast_cli(a->fd, "SIP Debugging %senabled\n", oldsipdebug ? "re-" : ""); 19075 return CLI_SUCCESS; 19076 } else if (!strcasecmp(what, "off")) { 19077 sipdebug &= ~sip_debug_console; 19078 sipdebug_text = 0; 19079 ast_cli(a->fd, "SIP Debugging Disabled\n"); 19080 return CLI_SUCCESS; 19081 } 19082 } else if (a->argc == e->args +1) {/* ip/peer */ 19083 if (!strcasecmp(what, "ip")) 19084 return sip_do_debug_ip(a->fd, a->argv[e->args]); 19085 else if (!strcasecmp(what, "peer")) 19086 return sip_do_debug_peer(a->fd, a->argv[e->args]); 19087 } 19088 return CLI_SHOWUSAGE; /* default, failure */ 19089 }
| static char * sip_do_debug_ip | ( | int | fd, | |
| const char * | arg | |||
| ) | [static] |
Enable SIP Debugging for a single IP.
Definition at line 19018 of file chan_sip.c.
References ast_cli(), ast_sockaddr_resolve_first_af(), ast_sockaddr_stringify_addr(), CLI_SHOWUSAGE, CLI_SUCCESS, and debugaddr.
Referenced by sip_do_debug().
19019 { 19020 if (ast_sockaddr_resolve_first_af(&debugaddr, arg, 0, 0)) { 19021 return CLI_SHOWUSAGE; 19022 } 19023 19024 ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_sockaddr_stringify_addr(&debugaddr)); 19025 sipdebug |= sip_debug_console; 19026 19027 return CLI_SUCCESS; 19028 }
| static char * sip_do_debug_peer | ( | int | fd, | |
| const char * | arg | |||
| ) | [static] |
Turn on SIP debugging for a given peer.
Definition at line 19031 of file chan_sip.c.
References ast_cli(), ast_sockaddr_copy(), ast_sockaddr_isnull(), ast_sockaddr_stringify_addr(), CLI_SUCCESS, debugaddr, FALSE, find_peer(), TRUE, and unref_peer().
Referenced by sip_do_debug().
19032 { 19033 struct sip_peer *peer = find_peer(arg, NULL, TRUE, FINDPEERS, FALSE, 0); 19034 if (!peer) 19035 ast_cli(fd, "No such peer '%s'\n", arg); 19036 else if (ast_sockaddr_isnull(&peer->addr)) 19037 ast_cli(fd, "Unable to get IP address of peer '%s'\n", arg); 19038 else { 19039 ast_sockaddr_copy(&debugaddr, &peer->addr); 19040 ast_cli(fd, "SIP Debugging Enabled for IP: %s\n", ast_sockaddr_stringify_addr(&debugaddr)); 19041 sipdebug |= sip_debug_console; 19042 } 19043 if (peer) 19044 unref_peer(peer, "sip_do_debug_peer: unref_peer, from find_peer call"); 19045 return CLI_SUCCESS; 19046 }
| static int sip_do_reload | ( | enum channelreloadreason | reason | ) | [static] |
Reload module.
Definition at line 29910 of file chan_sip.c.
References ast_debug, ast_sched_dump(), reload_config(), sip_poke_all_peers(), sip_send_all_mwi_subscriptions(), sip_send_all_registers(), and unlink_marked_peers_from_tables().
Referenced by do_monitor().
29911 { 29912 time_t start_poke, end_poke; 29913 29914 reload_config(reason); 29915 ast_sched_dump(sched); 29916 29917 start_poke = time(0); 29918 /* Prune peers who still are supposed to be deleted */ 29919 unlink_marked_peers_from_tables(); 29920 29921 ast_debug(4, "--------------- Done destroying pruned peers\n"); 29922 29923 /* Send qualify (OPTIONS) to all peers */ 29924 sip_poke_all_peers(); 29925 29926 /* Register with all services */ 29927 sip_send_all_registers(); 29928 29929 sip_send_all_mwi_subscriptions(); 29930 29931 end_poke = time(0); 29932 29933 ast_debug(4, "do_reload finished. peer poke/prune reg contact time = %d sec.\n", (int)(end_poke-start_poke)); 29934 29935 ast_debug(4, "--------------- SIP reload done\n"); 29936 29937 return 0; 29938 }
| static int sip_dtmfmode | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
Set the DTMFmode for an outbound SIP call (application).
Definition at line 29596 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_clear_flag, ast_log(), AST_RTP_DTMF, ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_DTMF, ast_set_flag, ast_test_flag, disable_dsp_detect(), enable_dsp_detect(), LOG_WARNING, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
Referenced by load_module().
29597 { 29598 struct sip_pvt *p; 29599 const char *mode = data; 29600 29601 if (!data) { 29602 ast_log(LOG_WARNING, "This application requires the argument: info, inband, rfc2833\n"); 29603 return 0; 29604 } 29605 ast_channel_lock(chan); 29606 if (!IS_SIP_TECH(chan->tech)) { 29607 ast_log(LOG_WARNING, "Call this application only on SIP incoming calls\n"); 29608 ast_channel_unlock(chan); 29609 return 0; 29610 } 29611 p = chan->tech_pvt; 29612 if (!p) { 29613 ast_channel_unlock(chan); 29614 return 0; 29615 } 29616 sip_pvt_lock(p); 29617 if (!strcasecmp(mode, "info")) { 29618 ast_clear_flag(&p->flags[0], SIP_DTMF); 29619 ast_set_flag(&p->flags[0], SIP_DTMF_INFO); 29620 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 29621 } else if (!strcasecmp(mode, "shortinfo")) { 29622 ast_clear_flag(&p->flags[0], SIP_DTMF); 29623 ast_set_flag(&p->flags[0], SIP_DTMF_SHORTINFO); 29624 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 29625 } else if (!strcasecmp(mode, "rfc2833")) { 29626 ast_clear_flag(&p->flags[0], SIP_DTMF); 29627 ast_set_flag(&p->flags[0], SIP_DTMF_RFC2833); 29628 p->jointnoncodeccapability |= AST_RTP_DTMF; 29629 } else if (!strcasecmp(mode, "inband")) { 29630 ast_clear_flag(&p->flags[0], SIP_DTMF); 29631 ast_set_flag(&p->flags[0], SIP_DTMF_INBAND); 29632 p->jointnoncodeccapability &= ~AST_RTP_DTMF; 29633 } else { 29634 ast_log(LOG_WARNING, "I don't know about this dtmf mode: %s\n", mode); 29635 } 29636 if (p->rtp) 29637 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_DTMF, ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833); 29638 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || 29639 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 29640 enable_dsp_detect(p); 29641 } else { 29642 disable_dsp_detect(p); 29643 } 29644 sip_pvt_unlock(p); 29645 ast_channel_unlock(chan); 29646 return 0; 29647 }
| static void sip_dump_history | ( | struct sip_pvt * | dialog | ) | [static] |
Dump SIP history to debug log file at end of lifespan for SIP dialog.
Definition at line 18818 of file chan_sip.c.
References ast_debug, AST_LIST_TRAVERSE, ast_log(), LOG_NOTICE, and option_debug.
Referenced by __sip_destroy().
18819 { 18820 int x = 0; 18821 struct sip_history *hist; 18822 static int errmsg = 0; 18823 18824 if (!dialog) 18825 return; 18826 18827 if (!option_debug && !sipdebug) { 18828 if (!errmsg) { 18829 ast_log(LOG_NOTICE, "You must have debugging enabled (SIP or Asterisk) in order to dump SIP history.\n"); 18830 errmsg = 1; 18831 } 18832 return; 18833 } 18834 18835 ast_debug(1, "\n---------- SIP HISTORY for '%s' \n", dialog->callid); 18836 if (dialog->subscribed) 18837 ast_debug(1, " * Subscription\n"); 18838 else 18839 ast_debug(1, " * SIP Call\n"); 18840 if (dialog->history) 18841 AST_LIST_TRAVERSE(dialog->history, hist, list) 18842 ast_debug(1, " %-3.3d. %s\n", ++x, hist->event); 18843 if (!x) 18844 ast_debug(1, "Call '%s' has no history\n", dialog->callid); 18845 ast_debug(1, "\n---------- END SIP HISTORY for '%s' \n", dialog->callid); 18846 }
| static int sip_epa_register | ( | const struct epa_static_data * | static_data | ) | [static] |
Definition at line 862 of file chan_sip.c.
References ast_calloc, AST_LIST_INSERT_TAIL, AST_LIST_LOCK, and AST_LIST_UNLOCK.
Referenced by load_module().
00863 { 00864 struct epa_backend *backend = ast_calloc(1, sizeof(*backend)); 00865 00866 if (!backend) { 00867 return -1; 00868 } 00869 00870 backend->static_data = static_data; 00871 00872 AST_LIST_LOCK(&epa_static_data_list); 00873 AST_LIST_INSERT_TAIL(&epa_static_data_list, backend, next); 00874 AST_LIST_UNLOCK(&epa_static_data_list); 00875 return 0; 00876 }
| static void sip_epa_unregister_all | ( | void | ) | [static] |
Definition at line 878 of file chan_sip.c.
References ast_free, AST_LIST_LOCK, AST_LIST_REMOVE_HEAD, and AST_LIST_UNLOCK.
Referenced by unload_module().
00879 { 00880 struct epa_backend *backend; 00881 00882 AST_LIST_LOCK(&epa_static_data_list); 00883 while ((backend = AST_LIST_REMOVE_HEAD(&epa_static_data_list, next))) { 00884 ast_free(backend); 00885 } 00886 AST_LIST_UNLOCK(&epa_static_data_list); 00887 }
| static int sip_fixup | ( | struct ast_channel * | oldchan, | |
| struct ast_channel * | newchan | |||
| ) | [static] |
sip_fixup: Fix up a channel: If a channel is consumed, this is called. Basically update any ->owner links
Definition at line 6610 of file chan_sip.c.
References append_history, ast_debug, AST_FLAG_ZOMBIE, ast_log(), ast_test_flag, LOG_WARNING, sip_pvt_lock, sip_pvt_unlock, sip_set_rtp_peer(), and ast_channel::tech_pvt.
06611 { 06612 int ret = -1; 06613 struct sip_pvt *p; 06614 06615 if (newchan && ast_test_flag(newchan, AST_FLAG_ZOMBIE)) 06616 ast_debug(1, "New channel is zombie\n"); 06617 if (oldchan && ast_test_flag(oldchan, AST_FLAG_ZOMBIE)) 06618 ast_debug(1, "Old channel is zombie\n"); 06619 06620 if (!newchan || !newchan->tech_pvt) { 06621 if (!newchan) 06622 ast_log(LOG_WARNING, "No new channel! Fixup of %s failed.\n", oldchan->name); 06623 else 06624 ast_log(LOG_WARNING, "No SIP tech_pvt! Fixup of %s failed.\n", oldchan->name); 06625 return -1; 06626 } 06627 p = newchan->tech_pvt; 06628 06629 sip_pvt_lock(p); 06630 append_history(p, "Masq", "Old channel: %s\n", oldchan->name); 06631 append_history(p, "Masq (cont)", "...new owner: %s\n", newchan->name); 06632 if (p->owner != oldchan) 06633 ast_log(LOG_WARNING, "old channel wasn't %p but was %p\n", oldchan, p->owner); 06634 else { 06635 p->owner = newchan; 06636 /* Re-invite RTP back to Asterisk. Needed if channel is masqueraded out of a native 06637 RTP bridge (i.e., RTP not going through Asterisk): RTP bridge code might not be 06638 able to do this if the masquerade happens before the bridge breaks (e.g., AMI 06639 redirect of both channels). Note that a channel can not be masqueraded *into* 06640 a native bridge. So there is no danger that this breaks a native bridge that 06641 should stay up. */ 06642 sip_set_rtp_peer(newchan, NULL, NULL, 0, 0, 0); 06643 ret = 0; 06644 } 06645 ast_debug(3, "SIP Fixup: New owner for dialogue %s: %s (Old parent: %s)\n", p->callid, p->owner->name, oldchan->name); 06646 06647 sip_pvt_unlock(p); 06648 return ret; 06649 }
| static const char * sip_get_callid | ( | struct ast_channel * | chan | ) | [static] |
Deliver SIP call ID for the call.
Definition at line 4458 of file chan_sip.c.
References ast_channel::tech_pvt.
| static int sip_get_cc_information | ( | struct sip_request * | req, | |
| char * | subscribe_uri, | |||
| size_t | size, | |||
| enum ast_cc_service_type * | service | |||
| ) | [static] |
Definition at line 2069 of file chan_sip.c.
References AST_CC_NONE, ast_copy_string(), ast_strdupa, ast_strlen_zero(), get_header(), get_in_brackets(), and service_string_to_service_type().
Referenced by sip_handle_cc().
02070 { 02071 char *call_info = ast_strdupa(get_header(req, "Call-Info")); 02072 char *uri; 02073 char *purpose; 02074 char *service_str; 02075 static const char cc_purpose[] = "purpose=call-completion"; 02076 static const int cc_purpose_len = sizeof(cc_purpose) - 1; 02077 02078 if (ast_strlen_zero(call_info)) { 02079 /* No Call-Info present. Definitely no CC offer */ 02080 return -1; 02081 } 02082 02083 uri = strsep(&call_info, ";"); 02084 02085 while ((purpose = strsep(&call_info, ";"))) { 02086 if (!strncmp(purpose, cc_purpose, cc_purpose_len)) { 02087 break; 02088 } 02089 } 02090 if (!purpose) { 02091 /* We didn't find the appropriate purpose= parameter. Oh well */ 02092 return -1; 02093 } 02094 02095 /* Okay, call-completion has been offered. Let's figure out what type of service this is */ 02096 while ((service_str = strsep(&call_info, ";"))) { 02097 if (!strncmp(service_str, "m=", 2)) { 02098 break; 02099 } 02100 } 02101 if (!service_str) { 02102 /* So they didn't offer a particular service, We'll just go with CCBS since it really 02103 * doesn't matter anyway 02104 */ 02105 service_str = "BS"; 02106 } else { 02107 /* We already determined that there is an "m=" so no need to check 02108 * the result of this strsep 02109 */ 02110 strsep(&service_str, "="); 02111 } 02112 02113 if ((*service = service_string_to_service_type(service_str)) == AST_CC_NONE) { 02114 /* Invalid service offered */ 02115 return -1; 02116 } 02117 02118 ast_copy_string(subscribe_uri, get_in_brackets(uri), size); 02119 02120 return 0; 02121 }
| static format_t sip_get_codec | ( | struct ast_channel * | chan | ) | [static] |
Definition at line 29576 of file chan_sip.c.
References ast_channel::tech_pvt.
29577 { 29578 struct sip_pvt *p = chan->tech_pvt; 29579 return p->peercapability ? p->peercapability : p->capability; 29580 }
| static enum ast_rtp_glue_result sip_get_rtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp_instance ** | instance | |||
| ) | [static] |
Definition at line 29308 of file chan_sip.c.
References ao2_ref, apply_directmedia_ha(), ast_bridged_channel(), AST_JB_FORCED, AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_LOCAL, AST_RTP_GLUE_RESULT_REMOTE, ast_test_flag, global_jbconf, sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
29309 { 29310 struct sip_pvt *p = NULL; 29311 struct ast_channel *opp_chan; 29312 struct sip_pvt *opp = NULL; 29313 enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_LOCAL; 29314 29315 if (!(p = chan->tech_pvt)) { 29316 return AST_RTP_GLUE_RESULT_FORBID; 29317 } 29318 29319 if (!(opp_chan = ast_bridged_channel(chan))) { 29320 return AST_RTP_GLUE_RESULT_FORBID; 29321 } else if ((opp_chan->tech != &sip_tech) || (!(opp = opp_chan->tech_pvt))) { 29322 return AST_RTP_GLUE_RESULT_FORBID; 29323 } 29324 29325 sip_pvt_lock(p); 29326 while (sip_pvt_trylock(opp)) { 29327 sip_pvt_unlock(p); 29328 usleep(1); 29329 sip_pvt_lock(p); 29330 } 29331 29332 if (!(p->rtp)) { 29333 sip_pvt_unlock(opp); 29334 sip_pvt_unlock(p); 29335 return AST_RTP_GLUE_RESULT_FORBID; 29336 } 29337 29338 ao2_ref(p->rtp, +1); 29339 *instance = p->rtp; 29340 29341 if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { 29342 res = AST_RTP_GLUE_RESULT_REMOTE; 29343 if (!apply_directmedia_ha(p, opp, "audio")) { 29344 res = AST_RTP_GLUE_RESULT_FORBID; 29345 } 29346 } else if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA_NAT)) { 29347 res = AST_RTP_GLUE_RESULT_REMOTE; 29348 } else if (ast_test_flag(&global_jbconf, AST_JB_FORCED)) { 29349 res = AST_RTP_GLUE_RESULT_FORBID; 29350 } 29351 29352 sip_pvt_unlock(opp); 29353 29354 if (p->srtp) { 29355 res = AST_RTP_GLUE_RESULT_FORBID; 29356 } 29357 29358 sip_pvt_unlock(p); 29359 29360 return res; 29361 }
| static enum ast_rtp_glue_result sip_get_trtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp_instance ** | instance | |||
| ) | [static] |
Definition at line 29409 of file chan_sip.c.
References ao2_ref, apply_directmedia_ha(), ast_bridged_channel(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_test_flag, sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
29410 { 29411 struct sip_pvt *p = NULL; 29412 struct ast_channel *opp_chan; 29413 struct sip_pvt *opp = NULL; 29414 enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID; 29415 29416 if (!(p = chan->tech_pvt)) { 29417 return AST_RTP_GLUE_RESULT_FORBID; 29418 } 29419 29420 if (!(opp_chan = ast_bridged_channel(chan))) { 29421 return AST_RTP_GLUE_RESULT_FORBID; 29422 } else if ((opp_chan->tech != &sip_tech) || (!(opp = opp_chan->tech_pvt))) { 29423 return AST_RTP_GLUE_RESULT_FORBID; 29424 } 29425 29426 sip_pvt_lock(p); 29427 while (sip_pvt_trylock(opp)) { 29428 sip_pvt_unlock(p); 29429 usleep(1); 29430 sip_pvt_lock(p); 29431 } 29432 29433 if (!(p->trtp)) { 29434 sip_pvt_unlock(opp); 29435 sip_pvt_unlock(p); 29436 return AST_RTP_GLUE_RESULT_FORBID; 29437 } 29438 29439 ao2_ref(p->trtp, +1); 29440 *instance = p->trtp; 29441 29442 if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { 29443 res = AST_RTP_GLUE_RESULT_REMOTE; 29444 if (!apply_directmedia_ha(p, opp, "text")) { 29445 res = AST_RTP_GLUE_RESULT_FORBID; 29446 } 29447 } 29448 29449 sip_pvt_unlock(opp); 29450 sip_pvt_unlock(p); 29451 29452 return res; 29453 }
| static struct ast_udptl * sip_get_udptl_peer | ( | struct ast_channel * | chan | ) | [static, read] |
Definition at line 29229 of file chan_sip.c.
References apply_directmedia_ha(), ast_bridged_channel(), ast_test_flag, sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
29230 { 29231 struct sip_pvt *p; 29232 struct ast_channel *opp_chan; 29233 struct sip_pvt *opp; 29234 struct ast_udptl *udptl = NULL; 29235 29236 p = chan->tech_pvt; 29237 if (!p) { 29238 return NULL; 29239 } 29240 29241 if (!(opp_chan = ast_bridged_channel(chan))) { 29242 return NULL; 29243 } else if ((opp_chan->tech != &sip_tech) || (!(opp = opp_chan->tech_pvt))) { 29244 return NULL; 29245 } 29246 29247 sip_pvt_lock(p); 29248 while (sip_pvt_trylock(opp)) { 29249 sip_pvt_unlock(p); 29250 usleep(1); 29251 sip_pvt_lock(p); 29252 } 29253 29254 if (p->udptl && ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { 29255 if (apply_directmedia_ha(p, opp, "UDPTL T.38 data")) { 29256 udptl = p->udptl; 29257 } 29258 } 29259 29260 sip_pvt_unlock(opp); 29261 sip_pvt_unlock(p); 29262 return udptl; 29263 }
| static enum ast_rtp_glue_result sip_get_vrtp_peer | ( | struct ast_channel * | chan, | |
| struct ast_rtp_instance ** | instance | |||
| ) | [static] |
Definition at line 29363 of file chan_sip.c.
References ao2_ref, apply_directmedia_ha(), ast_bridged_channel(), AST_RTP_GLUE_RESULT_FORBID, AST_RTP_GLUE_RESULT_REMOTE, ast_test_flag, sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, ast_channel::tech, and ast_channel::tech_pvt.
29364 { 29365 struct sip_pvt *p = NULL; 29366 struct ast_channel *opp_chan; 29367 struct sip_pvt *opp = NULL; 29368 enum ast_rtp_glue_result res = AST_RTP_GLUE_RESULT_FORBID; 29369 29370 if (!(p = chan->tech_pvt)) { 29371 return AST_RTP_GLUE_RESULT_FORBID; 29372 } 29373 29374 if (!(opp_chan = ast_bridged_channel(chan))) { 29375 return AST_RTP_GLUE_RESULT_FORBID; 29376 } else if ((opp_chan->tech != &sip_tech) || (!(opp = opp_chan->tech_pvt))) { 29377 return AST_RTP_GLUE_RESULT_FORBID; 29378 } 29379 29380 sip_pvt_lock(p); 29381 while (sip_pvt_trylock(opp)) { 29382 sip_pvt_unlock(p); 29383 usleep(1); 29384 sip_pvt_lock(p); 29385 } 29386 29387 if (!(p->vrtp)) { 29388 sip_pvt_unlock(opp); 29389 sip_pvt_unlock(p); 29390 return AST_RTP_GLUE_RESULT_FORBID; 29391 } 29392 29393 ao2_ref(p->vrtp, +1); 29394 *instance = p->vrtp; 29395 29396 if (ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA)) { 29397 res = AST_RTP_GLUE_RESULT_REMOTE; 29398 if (!apply_directmedia_ha(p, opp, "video")) { 29399 res = AST_RTP_GLUE_RESULT_FORBID; 29400 } 29401 } 29402 29403 sip_pvt_unlock(opp); 29404 sip_pvt_unlock(p); 29405 29406 return res; 29407 }
| static void sip_handle_cc | ( | struct sip_pvt * | pvt, | |
| struct sip_request * | req, | |||
| enum ast_cc_service_type | service | |||
| ) | [static] |
Definition at line 2140 of file chan_sip.c.
References ao2_ref, AST_CC_GENERIC_MONITOR_TYPE, ast_cc_get_current_core_id(), AST_CC_MONITOR_ALWAYS, AST_CC_MONITOR_GENERIC, AST_CC_MONITOR_NATIVE, AST_CC_MONITOR_NEVER, ast_channel_get_device_name(), AST_CHANNEL_NAME, ast_get_cc_monitor_policy(), ast_module_ref(), ast_queue_cc_frame(), sip_get_cc_information(), and sip_monitor_instance_init().
Referenced by handle_response(), and handle_response_invite().
02141 { 02142 enum ast_cc_monitor_policies monitor_policy = ast_get_cc_monitor_policy(pvt->cc_params); 02143 int core_id; 02144 char interface_name[AST_CHANNEL_NAME]; 02145 02146 if (monitor_policy == AST_CC_MONITOR_NEVER) { 02147 /* Don't bother, just return */ 02148 return; 02149 } 02150 02151 if ((core_id = ast_cc_get_current_core_id(pvt->owner)) == -1) { 02152 /* For some reason, CC is invalid, so don't try it! */ 02153 return; 02154 } 02155 02156 ast_channel_get_device_name(pvt->owner, interface_name, sizeof(interface_name)); 02157 02158 if (monitor_policy == AST_CC_MONITOR_ALWAYS || monitor_policy == AST_CC_MONITOR_NATIVE) { 02159 char subscribe_uri[SIPBUFSIZE]; 02160 char device_name[AST_CHANNEL_NAME]; 02161 enum ast_cc_service_type offered_service; 02162 struct sip_monitor_instance *monitor_instance; 02163 if (sip_get_cc_information(req, subscribe_uri, sizeof(subscribe_uri), &offered_service)) { 02164 /* If CC isn't being offered to us, or for some reason the CC offer is 02165 * not formatted correctly, then it may still be possible to use generic 02166 * call completion since the monitor policy may be "always" 02167 */ 02168 goto generic; 02169 } 02170 ast_channel_get_device_name(pvt->owner, device_name, sizeof(device_name)); 02171 if (!(monitor_instance = sip_monitor_instance_init(core_id, subscribe_uri, pvt->peername, device_name))) { 02172 /* Same deal. We can try using generic still */ 02173 goto generic; 02174 } 02175 /* We bump the refcount of chan_sip because once we queue this frame, the CC core 02176 * will have a reference to callbacks in this module. We decrement the module 02177 * refcount once the monitor destructor is called 02178 */ 02179 ast_module_ref(ast_module_info->self); 02180 ast_queue_cc_frame(pvt->owner, "SIP", pvt->dialstring, offered_service, monitor_instance); 02181 ao2_ref(monitor_instance, -1); 02182 return; 02183 } 02184 02185 generic: 02186 if (monitor_policy == AST_CC_MONITOR_GENERIC || monitor_policy == AST_CC_MONITOR_ALWAYS) { 02187 ast_queue_cc_frame(pvt->owner, AST_CC_GENERIC_MONITOR_TYPE, interface_name, service, NULL); 02188 } 02189 }
| static int sip_hangup | ( | struct ast_channel * | ast | ) | [static] |
sip_hangup: Hangup SIP call Part of PBX interface, called from ast_hangup
Definition at line 6245 of file chan_sip.c.
References __sip_semi_ack(), ast_channel::_state, append_history, ast_bridged_channel(), ast_cause2str(), AST_CAUSE_ANSWERED_ELSEWHERE, ast_channel_trylock, ast_channel_unlock, ast_clear_flag, ast_debug, AST_FLAG_ANSWERED_ELSEWHERE, ast_log(), AST_MAX_USER_FIELD, ast_module_unref(), ast_rtp_instance_get_quality(), ast_rtp_instance_set_stats_vars(), AST_RTP_INSTANCE_STAT_FIELD_QUALITY, ast_sched_add(), AST_SCHED_DEL_UNREF, ast_set_flag, ast_state2str(), AST_STATE_UP, ast_strlen_zero(), ast_test_flag, CHANNEL_DEADLOCK_AVOIDANCE, disable_dsp_detect(), FALSE, find_sip_method(), hangup_cause2sip(), ast_channel::hangupcause, LOG_WARNING, pbx_builtin_setvar_helper(), pvt_set_needdestroy(), quality, reinvite_timeout(), sip_cancel_destroy(), sip_pvt_lock, sip_pvt_trylock, sip_pvt_unlock, sip_scheddestroy(), stop_media_flows(), stop_session_timer(), ast_channel::tech, ast_channel::tech_pvt, transmit_request(), transmit_request_with_auth(), transmit_response_reliable(), TRUE, and update_call_counter().
06246 { 06247 struct sip_pvt *p = ast->tech_pvt; 06248 int needcancel = FALSE; 06249 int needdestroy = 0; 06250 struct ast_channel *oldowner = ast; 06251 06252 if (!p) { 06253 ast_debug(1, "Asked to hangup channel that was not connected\n"); 06254 return 0; 06255 } 06256 if (ast_test_flag(ast, AST_FLAG_ANSWERED_ELSEWHERE) || ast->hangupcause == AST_CAUSE_ANSWERED_ELSEWHERE) { 06257 ast_debug(1, "This call was answered elsewhere\n"); 06258 if (ast->hangupcause == AST_CAUSE_ANSWERED_ELSEWHERE) { 06259 ast_debug(1, "####### It's the cause code, buddy. The cause code!!!\n"); 06260 } 06261 append_history(p, "Cancel", "Call answered elsewhere"); 06262 p->answered_elsewhere = TRUE; 06263 } 06264 06265 /* Store hangupcause locally in PVT so we still have it before disconnect */ 06266 if (p->owner) 06267 p->hangupcause = p->owner->hangupcause; 06268 06269 if (ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 06270 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 06271 if (sipdebug) 06272 ast_debug(1, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 06273 update_call_counter(p, DEC_CALL_LIMIT); 06274 } 06275 ast_debug(4, "SIP Transfer: Not hanging up right now... Rescheduling hangup for %s.\n", p->callid); 06276 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06277 ast_clear_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER); /* Really hang up next time */ 06278 p->needdestroy = 0; 06279 p->owner->tech_pvt = dialog_unref(p->owner->tech_pvt, "unref p->owner->tech_pvt"); 06280 sip_pvt_lock(p); 06281 p->owner = NULL; /* Owner will be gone after we return, so take it away */ 06282 sip_pvt_unlock(p); 06283 ast_module_unref(ast_module_info->self); 06284 return 0; 06285 } 06286 06287 ast_debug(1, "Hangup call %s, SIP callid %s\n", ast->name, p->callid); 06288 06289 sip_pvt_lock(p); 06290 if (ast_test_flag(&p->flags[0], SIP_INC_COUNT) || ast_test_flag(&p->flags[1], SIP_PAGE2_CALL_ONHOLD)) { 06291 if (sipdebug) 06292 ast_debug(1, "update_call_counter(%s) - decrement call limit counter on hangup\n", p->username); 06293 update_call_counter(p, DEC_CALL_LIMIT); 06294 } 06295 06296 /* Determine how to disconnect */ 06297 if (p->owner != ast) { 06298 ast_log(LOG_WARNING, "Huh? We aren't the owner? Can't hangup call.\n"); 06299 sip_pvt_unlock(p); 06300 return 0; 06301 } 06302 /* If the call is not UP, we need to send CANCEL instead of BYE */ 06303 /* In case of re-invites, the call might be UP even though we have an incomplete invite transaction */ 06304 if (p->invitestate < INV_COMPLETED && p->owner->_state != AST_STATE_UP) { 06305 needcancel = TRUE; 06306 ast_debug(4, "Hanging up channel in state %s (not UP)\n", ast_state2str(ast->_state)); 06307 } 06308 06309 stop_media_flows(p); /* Immediately stop RTP, VRTP and UDPTL as applicable */ 06310 06311 append_history(p, needcancel ? "Cancel" : "Hangup", "Cause %s", p->owner ? ast_cause2str(p->hangupcause) : "Unknown"); 06312 06313 /* Disconnect */ 06314 disable_dsp_detect(p); 06315 06316 p->owner = NULL; 06317 ast->tech_pvt = dialog_unref(ast->tech_pvt, "unref ast->tech_pvt"); 06318 06319 ast_module_unref(ast_module_info->self); 06320 /* Do not destroy this pvt until we have timeout or 06321 get an answer to the BYE or INVITE/CANCEL 06322 If we get no answer during retransmit period, drop the call anyway. 06323 (Sorry, mother-in-law, you can't deny a hangup by sending 06324 603 declined to BYE...) 06325 */ 06326 if (p->alreadygone) 06327 needdestroy = 1; /* Set destroy flag at end of this function */ 06328 else if (p->invitestate != INV_CALLING) 06329 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06330 06331 /* Start the process if it's not already started */ 06332 if (!p->alreadygone && p->initreq.data && !ast_strlen_zero(p->initreq.data->str)) { 06333 if (needcancel) { /* Outgoing call, not up */ 06334 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06335 /* if we can't send right now, mark it pending */ 06336 if (p->invitestate == INV_CALLING) { 06337 /* We can't send anything in CALLING state */ 06338 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 06339 /* Do we need a timer here if we don't hear from them at all? Yes we do or else we will get hung dialogs and those are no fun. */ 06340 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06341 append_history(p, "DELAY", "Not sending cancel, waiting for timeout"); 06342 } else { 06343 struct sip_pkt *cur; 06344 06345 for (cur = p->packets; cur; cur = cur->next) { 06346 __sip_semi_ack(p, cur->seqno, cur->is_resp, cur->method ? cur->method : find_sip_method(cur->data->str)); 06347 } 06348 p->invitestate = INV_CANCELLED; 06349 /* Send a new request: CANCEL */ 06350 transmit_request(p, SIP_CANCEL, p->lastinvite, XMIT_RELIABLE, FALSE); 06351 /* Actually don't destroy us yet, wait for the 487 on our original 06352 INVITE, but do set an autodestruct just in case we never get it. */ 06353 needdestroy = 0; 06354 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 06355 } 06356 } else { /* Incoming call, not up */ 06357 const char *res; 06358 AST_SCHED_DEL_UNREF(sched, p->provisional_keepalive_sched_id, dialog_unref(p, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 06359 if (p->hangupcause && (res = hangup_cause2sip(p->hangupcause))) 06360 transmit_response_reliable(p, res, &p->initreq); 06361 else 06362 transmit_response_reliable(p, "603 Declined", &p->initreq); 06363 p->invitestate = INV_TERMINATED; 06364 } 06365 } else { /* Call is in UP state, send BYE */ 06366 if (p->stimer->st_active == TRUE) { 06367 stop_session_timer(p); 06368 } 06369 06370 if (!p->pendinginvite) { 06371 struct ast_channel *bridge = ast_bridged_channel(oldowner); 06372 char quality_buf[AST_MAX_USER_FIELD], *quality; 06373 06374 /* We need to get the lock on bridge because ast_rtp_instance_set_stats_vars will attempt 06375 * to lock the bridge. This may get hairy... 06376 */ 06377 while (bridge && ast_channel_trylock(bridge)) { 06378 sip_pvt_unlock(p); 06379 do { 06380 CHANNEL_DEADLOCK_AVOIDANCE(oldowner); 06381 } while (sip_pvt_trylock(p)); 06382 bridge = ast_bridged_channel(oldowner); 06383 } 06384 06385 if (p->rtp) { 06386 ast_rtp_instance_set_stats_vars(oldowner, p->rtp); 06387 } 06388 06389 if (bridge) { 06390 struct sip_pvt *q = bridge->tech_pvt; 06391 06392 if (IS_SIP_TECH(bridge->tech) && q && q->rtp) { 06393 ast_rtp_instance_set_stats_vars(bridge, q->rtp); 06394 } 06395 ast_channel_unlock(bridge); 06396 } 06397 06398 /* 06399 * The channel variables are set below just to get the AMI 06400 * VarSet event because the channel is being hungup. 06401 */ 06402 if (p->rtp && (quality = ast_rtp_instance_get_quality(p->rtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 06403 if (p->do_history) { 06404 append_history(p, "RTCPaudio", "Quality:%s", quality); 06405 } 06406 pbx_builtin_setvar_helper(oldowner, "RTPAUDIOQOS", quality); 06407 } 06408 if (p->vrtp && (quality = ast_rtp_instance_get_quality(p->vrtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 06409 if (p->do_history) { 06410 append_history(p, "RTCPvideo", "Quality:%s", quality); 06411 } 06412 pbx_builtin_setvar_helper(oldowner, "RTPVIDEOQOS", quality); 06413 } 06414 if (p->trtp && (quality = ast_rtp_instance_get_quality(p->trtp, AST_RTP_INSTANCE_STAT_FIELD_QUALITY, quality_buf, sizeof(quality_buf)))) { 06415 if (p->do_history) { 06416 append_history(p, "RTCPtext", "Quality:%s", quality); 06417 } 06418 pbx_builtin_setvar_helper(oldowner, "RTPTEXTQOS", quality); 06419 } 06420 06421 /* Send a hangup */ 06422 if (oldowner->_state == AST_STATE_UP) { 06423 transmit_request_with_auth(p, SIP_BYE, 0, XMIT_RELIABLE, 1); 06424 } 06425 06426 } else { 06427 /* Note we will need a BYE when this all settles out 06428 but we can't send one while we have "INVITE" outstanding. */ 06429 ast_set_flag(&p->flags[0], SIP_PENDINGBYE); 06430 ast_clear_flag(&p->flags[0], SIP_NEEDREINVITE); 06431 AST_SCHED_DEL_UNREF(sched, p->waitid, dialog_unref(p, "when you delete the waitid sched, you should dec the refcount for the stored dialog ptr")); 06432 if (sip_cancel_destroy(p)) { 06433 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 06434 } 06435 /* If we have an ongoing reinvite, there is a chance that we have gotten a provisional 06436 * response, but something weird has happened and we will never receive a final response. 06437 * So, just in case, check for pending actions after a bit of time to trigger the pending 06438 * bye that we are setting above */ 06439 if (p->ongoing_reinvite && p->reinviteid < 0) { 06440 p->reinviteid = ast_sched_add(sched, 32 * p->timer_t1, reinvite_timeout, dialog_ref(p, "ref for reinvite_timeout")); 06441 } 06442 } 06443 } 06444 } 06445 if (needdestroy) { 06446 pvt_set_needdestroy(p, "hangup"); 06447 } 06448 sip_pvt_unlock(p); 06449 return 0; 06450 }
| static int sip_indicate | ( | struct ast_channel * | ast, | |
| int | condition, | |||
| const void * | data, | |||
| size_t | datalen | |||
| ) | [static] |
Play indication to user With SIP a lot of indications is sent as messages, letting the device play the indication - busy signal, congestion etc.
Definition at line 6848 of file chan_sip.c.
References ast_channel::_state, AST_AOC_D, ast_aoc_decode(), ast_aoc_destroy_decoded(), AST_AOC_E, ast_aoc_get_msg_type(), ast_aoc_get_termination_request(), AST_AOC_REQUEST, AST_AOC_S, AST_CONTROL_AOC, AST_CONTROL_BUSY, AST_CONTROL_CONGESTION, AST_CONTROL_CONNECTED_LINE, AST_CONTROL_FLASH, AST_CONTROL_HOLD, AST_CONTROL_INCOMPLETE, AST_CONTROL_PROCEEDING, AST_CONTROL_PROGRESS, AST_CONTROL_REDIRECTING, AST_CONTROL_RINGING, AST_CONTROL_SRCCHANGE, AST_CONTROL_SRCUPDATE, AST_CONTROL_T38_PARAMETERS, AST_CONTROL_UNHOLD, AST_CONTROL_UPDATE_RTP_PEER, AST_CONTROL_VIDUPDATE, ast_debug, ast_log(), ast_moh_start(), ast_moh_stop(), ast_rtp_instance_change_source(), ast_rtp_instance_update_source(), ast_set_flag, AST_SOFTHANGUP_DEV, ast_softhangup_nolock(), AST_STATE_RING, AST_STATE_UP, ast_test_flag, initialize_udptl(), interpret_t38_parameters(), LOG_ERROR, LOG_WARNING, sip_alreadygone(), sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_info_with_aoc(), transmit_info_with_vidupdate(), transmit_provisional_response(), transmit_response(), transmit_response_reliable(), TRUE, update_connectedline(), and update_redirecting().
06849 { 06850 struct sip_pvt *p = ast->tech_pvt; 06851 int res = 0; 06852 06853 sip_pvt_lock(p); 06854 switch(condition) { 06855 case AST_CONTROL_RINGING: 06856 if (ast->_state == AST_STATE_RING) { 06857 p->invitestate = INV_EARLY_MEDIA; 06858 if (!ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) || 06859 (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER)) { 06860 /* Send 180 ringing if out-of-band seems reasonable */ 06861 transmit_provisional_response(p, "180 Ringing", &p->initreq, 0); 06862 ast_set_flag(&p->flags[0], SIP_RINGING); 06863 if (ast_test_flag(&p->flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_YES) 06864 break; 06865 } else { 06866 /* Well, if it's not reasonable, just send in-band */ 06867 } 06868 } 06869 res = -1; 06870 break; 06871 case AST_CONTROL_BUSY: 06872 if (ast->_state != AST_STATE_UP) { 06873 transmit_response_reliable(p, "486 Busy Here", &p->initreq); 06874 p->invitestate = INV_COMPLETED; 06875 sip_alreadygone(p); 06876 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06877 break; 06878 } 06879 res = -1; 06880 break; 06881 case AST_CONTROL_CONGESTION: 06882 if (ast->_state != AST_STATE_UP) { 06883 transmit_response_reliable(p, "503 Service Unavailable", &p->initreq); 06884 p->invitestate = INV_COMPLETED; 06885 sip_alreadygone(p); 06886 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06887 break; 06888 } 06889 res = -1; 06890 break; 06891 case AST_CONTROL_INCOMPLETE: 06892 if (ast->_state != AST_STATE_UP) { 06893 switch (ast_test_flag(&p->flags[1], SIP_PAGE2_ALLOWOVERLAP)) { 06894 case SIP_PAGE2_ALLOWOVERLAP_YES: 06895 transmit_response_reliable(p, "484 Address Incomplete", &p->initreq); 06896 p->invitestate = INV_COMPLETED; 06897 sip_alreadygone(p); 06898 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06899 break; 06900 case SIP_PAGE2_ALLOWOVERLAP_DTMF: 06901 /* Just wait for inband DTMF digits */ 06902 break; 06903 default: 06904 /* it actually means no support for overlap */ 06905 transmit_response_reliable(p, "404 Not Found", &p->initreq); 06906 p->invitestate = INV_COMPLETED; 06907 sip_alreadygone(p); 06908 ast_softhangup_nolock(ast, AST_SOFTHANGUP_DEV); 06909 break; 06910 } 06911 } 06912 break; 06913 case AST_CONTROL_PROCEEDING: 06914 if ((ast->_state != AST_STATE_UP) && 06915 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06916 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06917 transmit_response(p, "100 Trying", &p->initreq); 06918 p->invitestate = INV_PROCEEDING; 06919 break; 06920 } 06921 res = -1; 06922 break; 06923 case AST_CONTROL_PROGRESS: 06924 if ((ast->_state != AST_STATE_UP) && 06925 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06926 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06927 p->invitestate = INV_EARLY_MEDIA; 06928 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06929 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06930 break; 06931 } 06932 res = -1; 06933 break; 06934 case AST_CONTROL_HOLD: 06935 ast_rtp_instance_update_source(p->rtp); 06936 ast_moh_start(ast, data, p->mohinterpret); 06937 break; 06938 case AST_CONTROL_UNHOLD: 06939 ast_rtp_instance_update_source(p->rtp); 06940 ast_moh_stop(ast); 06941 break; 06942 case AST_CONTROL_VIDUPDATE: /* Request a video frame update */ 06943 if (p->vrtp && !p->novideo) { 06944 transmit_info_with_vidupdate(p); 06945 /* ast_rtcp_send_h261fur(p->vrtp); */ 06946 } else 06947 res = -1; 06948 break; 06949 case AST_CONTROL_T38_PARAMETERS: 06950 res = -1; 06951 if (datalen != sizeof(struct ast_control_t38_parameters)) { 06952 ast_log(LOG_ERROR, "Invalid datalen for AST_CONTROL_T38_PARAMETERS. Expected %d, got %d\n", (int) sizeof(struct ast_control_t38_parameters), (int) datalen); 06953 } else { 06954 const struct ast_control_t38_parameters *parameters = data; 06955 if (!initialize_udptl(p)) { 06956 res = interpret_t38_parameters(p, parameters); 06957 } 06958 } 06959 break; 06960 case AST_CONTROL_SRCUPDATE: 06961 ast_rtp_instance_update_source(p->rtp); 06962 break; 06963 case AST_CONTROL_SRCCHANGE: 06964 ast_rtp_instance_change_source(p->rtp); 06965 break; 06966 case AST_CONTROL_CONNECTED_LINE: 06967 update_connectedline(p, data, datalen); 06968 break; 06969 case AST_CONTROL_REDIRECTING: 06970 update_redirecting(p, data, datalen); 06971 break; 06972 case AST_CONTROL_AOC: 06973 { 06974 struct ast_aoc_decoded *decoded = ast_aoc_decode((struct ast_aoc_encoded *) data, datalen, ast); 06975 if (!decoded) { 06976 ast_log(LOG_ERROR, "Error decoding indicated AOC data\n"); 06977 res = -1; 06978 break; 06979 } 06980 switch (ast_aoc_get_msg_type(decoded)) { 06981 case AST_AOC_REQUEST: 06982 if (ast_aoc_get_termination_request(decoded)) { 06983 /* TODO, once there is a way to get AOC-E on hangup, attempt that here 06984 * before hanging up the channel.*/ 06985 06986 /* The other side has already initiated the hangup. This frame 06987 * just says they are waiting to get AOC-E before completely tearing 06988 * the call down. Since SIP does not support this at the moment go 06989 * ahead and terminate the call here to avoid an unnecessary timeout. */ 06990 ast_debug(1, "AOC-E termination request received on %s. This is not yet supported on sip. Continue with hangup \n", p->owner->name); 06991 ast_softhangup_nolock(p->owner, AST_SOFTHANGUP_DEV); 06992 } 06993 break; 06994 case AST_AOC_D: 06995 case AST_AOC_E: 06996 if (ast_test_flag(&p->flags[2], SIP_PAGE3_SNOM_AOC)) { 06997 transmit_info_with_aoc(p, decoded); 06998 } 06999 break; 07000 case AST_AOC_S: /* S not supported yet */ 07001 default: 07002 break; 07003 } 07004 ast_aoc_destroy_decoded(decoded); 07005 } 07006 break; 07007 case AST_CONTROL_UPDATE_RTP_PEER: /* Absorb this since it is handled by the bridge */ 07008 break; 07009 case AST_CONTROL_FLASH: /* We don't currently handle AST_CONTROL_FLASH here, but it is expected, so we don't need to warn either. */ 07010 res = -1; 07011 break; 07012 case -1: 07013 res = -1; 07014 break; 07015 default: 07016 ast_log(LOG_WARNING, "Don't know how to indicate condition %d\n", condition); 07017 res = -1; 07018 break; 07019 } 07020 sip_pvt_unlock(p); 07021 return res; 07022 }
| static int sip_is_xml_parsable | ( | void | ) | [static] |
Definition at line 29781 of file chan_sip.c.
Referenced by load_module().
| static int sip_monitor_instance_cmp_fn | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 1846 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by load_module().
| static void sip_monitor_instance_destructor | ( | void * | data | ) | [static] |
Definition at line 1854 of file chan_sip.c.
References ao2_t_ref, ast_string_field_free_memory, FALSE, sip_pvt_lock, sip_pvt_unlock, transmit_invite(), and transmit_publish().
Referenced by sip_monitor_instance_init().
01855 { 01856 struct sip_monitor_instance *monitor_instance = data; 01857 if (monitor_instance->subscription_pvt) { 01858 sip_pvt_lock(monitor_instance->subscription_pvt); 01859 monitor_instance->subscription_pvt->expiry = 0; 01860 transmit_invite(monitor_instance->subscription_pvt, SIP_SUBSCRIBE, FALSE, 0, monitor_instance->subscribe_uri); 01861 sip_pvt_unlock(monitor_instance->subscription_pvt); 01862 dialog_unref(monitor_instance->subscription_pvt, "Unref monitor instance ref of subscription pvt"); 01863 } 01864 if (monitor_instance->suspension_entry) { 01865 monitor_instance->suspension_entry->body[0] = '\0'; 01866 transmit_publish(monitor_instance->suspension_entry, SIP_PUBLISH_REMOVE ,monitor_instance->notify_uri); 01867 ao2_t_ref(monitor_instance->suspension_entry, -1, "Decrementing suspension entry refcount in sip_monitor_instance_destructor"); 01868 } 01869 ast_string_field_free_memory(monitor_instance); 01870 }
| static int sip_monitor_instance_hash_fn | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 1840 of file chan_sip.c.
Referenced by load_module().
| static struct sip_monitor_instance* sip_monitor_instance_init | ( | int | core_id, | |
| const char *const | subscribe_uri, | |||
| const char *const | peername, | |||
| const char *const | device_name | |||
| ) | [static, read] |
Definition at line 1872 of file chan_sip.c.
References ao2_alloc, ao2_link, ao2_ref, ast_string_field_init, ast_string_field_set, and sip_monitor_instance_destructor().
Referenced by sip_handle_cc().
01873 { 01874 struct sip_monitor_instance *monitor_instance = ao2_alloc(sizeof(*monitor_instance), sip_monitor_instance_destructor); 01875 01876 if (!monitor_instance) { 01877 return NULL; 01878 } 01879 01880 if (ast_string_field_init(monitor_instance, 256)) { 01881 ao2_ref(monitor_instance, -1); 01882 return NULL; 01883 } 01884 01885 ast_string_field_set(monitor_instance, subscribe_uri, subscribe_uri); 01886 ast_string_field_set(monitor_instance, peername, peername); 01887 ast_string_field_set(monitor_instance, device_name, device_name); 01888 monitor_instance->core_id = core_id; 01889 ao2_link(sip_monitor_instances, monitor_instance); 01890 return monitor_instance; 01891 }
| static const char * sip_nat_mode | ( | const struct sip_pvt * | p | ) | [static] |
Display SIP nat mode.
Definition at line 3216 of file chan_sip.c.
References ast_test_flag.
Referenced by check_via(), retrans_pkt(), and send_response().
03217 { 03218 return ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT) ? "NAT" : "no NAT"; 03219 }
| static struct ast_channel* sip_new | ( | struct sip_pvt * | i, | |
| int | state, | |||
| const char * | title, | |||
| const char * | linkedid | |||
| ) | [static, read] |
Initiate a call in the SIP channel.
Definition at line 7035 of file chan_sip.c.
References accountcode, ast_channel::adsicpe, ast_channel::amaflags, ast_party_caller::ani, append_history, AST_ADSI_UNAVAILABLE, ast_atomic_fetchadd_int(), ast_best_codec(), ast_channel_alloc, ast_channel_cc_params_init(), ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_codec_choose(), ast_copy_string(), ast_debug, ast_exists_extension(), AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, ast_get_encoded_str(), ast_getformatname_multiple(), ast_jb_configure(), ast_log(), ast_module_ref(), AST_RTP_DTMF_MODE_INBAND, AST_RTP_DTMF_MODE_RFC2833, ast_rtp_instance_dtmf_mode_set(), ast_rtp_instance_fd(), ast_rtp_instance_set_read_format(), ast_rtp_instance_set_write_format(), AST_STATE_RING, ast_strdup, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, ast_udptl_fd(), ast_uri_decode(), ast_channel::caller, ast_channel::callgroup, ast_channel::context, ast_channel::dialed, enable_dsp_detect(), EVENT_FLAG_SYSTEM, ast_channel::exten, exten, ast_party_redirecting::from, global_jbconf, ast_party_caller::id, language, LOG_WARNING, manager_event, ast_variable::name, ast_party_id::name, ast_channel::nativeformats, ast_variable::next, ast_party_dialed::number, ast_party_id::number, parkinglot, pbx_builtin_setvar_helper(), ast_channel::pickupgroup, ast_party_number::presentation, ast_party_name::presentation, ast_channel::priority, ast_channel::rawreadformat, ast_channel::rawwriteformat, ast_channel::readformat, ast_channel::redirecting, ast_channel::rings, sip_cfg, sip_pvt_lock, sip_pvt_unlock, sip_tech_info, ast_party_dialed::str, ast_party_number::str, ast_party_id::tag, ast_channel::tech, ast_channel::tech_pvt, text, ast_party_number::valid, ast_variable::value, and ast_channel::writeformat.
Referenced by handle_request_invite(), and sip_request_call().
07036 { 07037 struct ast_channel *tmp; 07038 struct ast_variable *v = NULL; 07039 format_t fmt; 07040 format_t what; 07041 format_t video; 07042 format_t text; 07043 format_t needvideo = 0; 07044 int needtext = 0; 07045 char buf[SIPBUFSIZE]; 07046 char *exten; 07047 07048 { 07049 const char *my_name; /* pick a good name */ 07050 07051 if (title) { 07052 my_name = title; 07053 } else { 07054 my_name = ast_strdupa(i->fromdomain); 07055 } 07056 07057 sip_pvt_unlock(i); 07058 /* Don't hold a sip pvt lock while we allocate a channel */ 07059 tmp = ast_channel_alloc(1, state, i->cid_num, i->cid_name, i->accountcode, i->exten, i->context, linkedid, i->amaflags, "SIP/%s-%08x", my_name, ast_atomic_fetchadd_int((int *)&chan_idx, +1)); 07060 } 07061 if (!tmp) { 07062 ast_log(LOG_WARNING, "Unable to allocate AST channel structure for SIP channel\n"); 07063 sip_pvt_lock(i); 07064 return NULL; 07065 } 07066 ast_channel_lock(tmp); 07067 sip_pvt_lock(i); 07068 ast_channel_cc_params_init(tmp, i->cc_params); 07069 tmp->caller.id.tag = ast_strdup(i->cid_tag); 07070 07071 tmp->tech = ( ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INFO || ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO) ? &sip_tech_info : &sip_tech; 07072 07073 /* Select our native format based on codec preference until we receive 07074 something from another device to the contrary. */ 07075 if (i->jointcapability) { /* The joint capabilities of us and peer */ 07076 what = i->jointcapability; 07077 video = i->jointcapability & AST_FORMAT_VIDEO_MASK; 07078 text = i->jointcapability & AST_FORMAT_TEXT_MASK; 07079 } else if (i->capability) { /* Our configured capability for this peer */ 07080 what = i->capability; 07081 video = i->capability & AST_FORMAT_VIDEO_MASK; 07082 text = i->capability & AST_FORMAT_TEXT_MASK; 07083 } else { 07084 what = sip_cfg.capability; /* Global codec support */ 07085 video = sip_cfg.capability & AST_FORMAT_VIDEO_MASK; 07086 text = sip_cfg.capability & AST_FORMAT_TEXT_MASK; 07087 } 07088 07089 /* Set the native formats for audio and merge in video */ 07090 tmp->nativeformats = ast_codec_choose(&i->prefs, what, 1) | video | text; 07091 ast_debug(3, "*** Our native formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, tmp->nativeformats)); 07092 ast_debug(3, "*** Joint capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->jointcapability)); 07093 ast_debug(3, "*** Our capabilities are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->capability)); 07094 ast_debug(3, "*** AST_CODEC_CHOOSE formats are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, ast_codec_choose(&i->prefs, what, 1))); 07095 if (i->prefcodec) 07096 ast_debug(3, "*** Our preferred formats from the incoming channel are %s \n", ast_getformatname_multiple(buf, SIPBUFSIZE, i->prefcodec)); 07097 07098 /* XXX Why are we choosing a codec from the native formats?? */ 07099 fmt = ast_best_codec(tmp->nativeformats); 07100 07101 /* If we have a prefcodec setting, we have an inbound channel that set a 07102 preferred format for this call. Otherwise, we check the jointcapability 07103 We also check for vrtp. If it's not there, we are not allowed do any video anyway. 07104 */ 07105 if (i->vrtp) { 07106 if (ast_test_flag(&i->flags[1], SIP_PAGE2_VIDEOSUPPORT)) 07107 needvideo = AST_FORMAT_VIDEO_MASK; 07108 else if (i->prefcodec) 07109 needvideo = i->prefcodec & AST_FORMAT_VIDEO_MASK; /* Outbound call */ 07110 else 07111 needvideo = i->jointcapability & AST_FORMAT_VIDEO_MASK; /* Inbound call */ 07112 } 07113 07114 if (i->trtp) { 07115 if (i->prefcodec) 07116 needtext = i->prefcodec & AST_FORMAT_TEXT_MASK; /* Outbound call */ 07117 else 07118 needtext = i->jointcapability & AST_FORMAT_TEXT_MASK; /* Inbound call */ 07119 } 07120 07121 if (needvideo) 07122 ast_debug(3, "This channel can handle video! HOLLYWOOD next!\n"); 07123 else 07124 ast_debug(3, "This channel will not be able to handle video.\n"); 07125 07126 enable_dsp_detect(i); 07127 07128 if ((ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || 07129 (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 07130 if (i->rtp) { 07131 ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_INBAND); 07132 } 07133 } else if (ast_test_flag(&i->flags[0], SIP_DTMF) == SIP_DTMF_RFC2833) { 07134 if (i->rtp) { 07135 ast_rtp_instance_dtmf_mode_set(i->rtp, AST_RTP_DTMF_MODE_RFC2833); 07136 } 07137 } 07138 07139 /* Set file descriptors for audio, video, and realtime text. Since 07140 * UDPTL is created as needed in the lifetime of a dialog, its file 07141 * descriptor is set in initialize_udptl */ 07142 if (i->rtp) { 07143 ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(i->rtp, 0)); 07144 ast_channel_set_fd(tmp, 1, ast_rtp_instance_fd(i->rtp, 1)); 07145 ast_rtp_instance_set_write_format(i->rtp, fmt); 07146 ast_rtp_instance_set_read_format(i->rtp, fmt); 07147 } 07148 if (needvideo && i->vrtp) { 07149 ast_channel_set_fd(tmp, 2, ast_rtp_instance_fd(i->vrtp, 0)); 07150 ast_channel_set_fd(tmp, 3, ast_rtp_instance_fd(i->vrtp, 1)); 07151 } 07152 if (needtext && i->trtp) { 07153 ast_channel_set_fd(tmp, 4, ast_rtp_instance_fd(i->trtp, 0)); 07154 } 07155 if (i->udptl) { 07156 ast_channel_set_fd(tmp, 5, ast_udptl_fd(i->udptl)); 07157 } 07158 07159 if (state == AST_STATE_RING) 07160 tmp->rings = 1; 07161 tmp->adsicpe = AST_ADSI_UNAVAILABLE; 07162 07163 tmp->writeformat = fmt; 07164 tmp->rawwriteformat = fmt; 07165 07166 tmp->readformat = fmt; 07167 tmp->rawreadformat = fmt; 07168 07169 tmp->tech_pvt = dialog_ref(i, "sip_new: set chan->tech_pvt to i"); 07170 07171 tmp->callgroup = i->callgroup; 07172 tmp->pickupgroup = i->pickupgroup; 07173 tmp->caller.id.name.presentation = i->callingpres; 07174 tmp->caller.id.number.presentation = i->callingpres; 07175 if (!ast_strlen_zero(i->parkinglot)) 07176 ast_string_field_set(tmp, parkinglot, i->parkinglot); 07177 if (!ast_strlen_zero(i->accountcode)) 07178 ast_string_field_set(tmp, accountcode, i->accountcode); 07179 if (i->amaflags) 07180 tmp->amaflags = i->amaflags; 07181 if (!ast_strlen_zero(i->language)) 07182 ast_string_field_set(tmp, language, i->language); 07183 i->owner = tmp; 07184 ast_module_ref(ast_module_info->self); 07185 ast_copy_string(tmp->context, i->context, sizeof(tmp->context)); 07186 /*Since it is valid to have extensions in the dialplan that have unescaped characters in them 07187 * we should decode the uri before storing it in the channel, but leave it encoded in the sip_pvt 07188 * structure so that there aren't issues when forming URI's 07189 */ 07190 exten = ast_strdupa(i->exten); 07191 sip_pvt_unlock(i); 07192 ast_channel_unlock(tmp); 07193 if (!ast_exists_extension(NULL, i->context, i->exten, 1, i->cid_num)) { 07194 ast_uri_decode(exten); 07195 } 07196 ast_channel_lock(tmp); 07197 sip_pvt_lock(i); 07198 ast_copy_string(tmp->exten, exten, sizeof(tmp->exten)); 07199 07200 /* Don't use ast_set_callerid() here because it will 07201 * generate an unnecessary NewCallerID event */ 07202 if (!ast_strlen_zero(i->cid_num)) { 07203 tmp->caller.ani.number.valid = 1; 07204 tmp->caller.ani.number.str = ast_strdup(i->cid_num); 07205 } 07206 if (!ast_strlen_zero(i->rdnis)) { 07207 tmp->redirecting.from.number.valid = 1; 07208 tmp->redirecting.from.number.str = ast_strdup(i->rdnis); 07209 } 07210 07211 if (!ast_strlen_zero(i->exten) && strcmp(i->exten, "s")) { 07212 tmp->dialed.number.str = ast_strdup(i->exten); 07213 } 07214 07215 tmp->priority = 1; 07216 if (!ast_strlen_zero(i->uri)) 07217 pbx_builtin_setvar_helper(tmp, "SIPURI", i->uri); 07218 if (!ast_strlen_zero(i->domain)) 07219 pbx_builtin_setvar_helper(tmp, "SIPDOMAIN", i->domain); 07220 if (!ast_strlen_zero(i->callid)) 07221 pbx_builtin_setvar_helper(tmp, "SIPCALLID", i->callid); 07222 if (i->rtp) 07223 ast_jb_configure(tmp, &global_jbconf); 07224 07225 /* Set channel variables for this call from configuration */ 07226 for (v = i->chanvars ; v ; v = v->next) { 07227 char valuebuf[1024]; 07228 pbx_builtin_setvar_helper(tmp, v->name, ast_get_encoded_str(v->value, valuebuf, sizeof(valuebuf))); 07229 } 07230 07231 if (i->do_history) 07232 append_history(i, "NewChan", "Channel %s - from %s", tmp->name, i->callid); 07233 07234 /* Inform manager user about new channel and their SIP call ID */ 07235 if (sip_cfg.callevents) 07236 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 07237 "Channel: %s\r\nUniqueid: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\n", 07238 tmp->name, tmp->uniqueid, "SIP", i->callid, i->fullcontact); 07239 07240 return tmp; 07241 }
| static int sip_notify_allocate | ( | struct sip_pvt * | p | ) | [static] |
Allocate SIP refer structure.
Definition at line 13522 of file chan_sip.c.
References ast_calloc, and ast_str_create().
Referenced by manager_sipnotify(), and sip_cli_notify().
13523 { 13524 p->notify = ast_calloc(1, sizeof(struct sip_notify)); 13525 if (p->notify) { 13526 p->notify->content = ast_str_create(128); 13527 } 13528 return p->notify ? 1 : 0; 13529 }
| static int sip_offer_timer_expire | ( | const void * | data | ) | [static] |
Definition at line 1722 of file chan_sip.c.
References ast_cc_failed(), ast_cc_agent::core_id, ast_cc_agent::device_name, and ast_cc_agent::private_data.
Referenced by sip_cc_agent_start_offer_timer().
01723 { 01724 struct ast_cc_agent *agent = (struct ast_cc_agent *) data; 01725 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 01726 01727 agent_pvt->offer_timer_id = -1; 01728 01729 return ast_cc_failed(agent->core_id, "SIP agent %s's offer timer expired", agent->device_name); 01730 }
| static int sip_park | ( | struct ast_channel * | chan1, | |
| struct ast_channel * | chan2, | |||
| struct sip_request * | req, | |||
| uint32_t | seqno, | |||
| const char * | park_exten, | |||
| const char * | park_context | |||
| ) | [static] |
DO NOT hold any locks while calling sip_park
Definition at line 21560 of file chan_sip.c.
References ast_channel::amaflags, ast_calloc, ast_channel_alloc, ast_channel_masquerade(), ast_copy_string(), ast_do_masquerade(), ast_free, ast_hangup(), ast_pthread_create_detached_background, AST_STATE_DOWN, ast_strdup, ast_string_field_set, ast_channel::context, copy_request(), deinit_req(), ast_channel::exten, parkinglot, ast_channel::priority, ast_channel::readformat, sip_park_thread(), and ast_channel::writeformat.
Referenced by handle_request_refer().
21561 { 21562 struct sip_dual *d; 21563 struct ast_channel *transferee, *transferer; 21564 pthread_t th; 21565 21566 transferee = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan1->accountcode, chan1->exten, chan1->context, chan1->linkedid, chan1->amaflags, "Parking/%s", chan1->name); 21567 transferer = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, chan2->accountcode, chan2->exten, chan2->context, chan2->linkedid, chan2->amaflags, "SIPPeer/%s", chan2->name); 21568 d = ast_calloc(1, sizeof(*d)); 21569 if (!transferee || !transferer || !d) { 21570 if (transferee) { 21571 ast_hangup(transferee); 21572 } 21573 if (transferer) { 21574 ast_hangup(transferer); 21575 } 21576 ast_free(d); 21577 return -1; 21578 } 21579 d->park_exten = ast_strdup(park_exten); 21580 d->park_context = ast_strdup(park_context); 21581 if (!d->park_exten || !d->park_context) { 21582 ast_hangup(transferee); 21583 ast_hangup(transferer); 21584 ast_free(d->park_exten); 21585 ast_free(d->park_context); 21586 ast_free(d); 21587 return -1; 21588 } 21589 21590 /* Make formats okay */ 21591 transferee->readformat = chan1->readformat; 21592 transferee->writeformat = chan1->writeformat; 21593 21594 /* Prepare for taking over the channel */ 21595 if (ast_channel_masquerade(transferee, chan1)) { 21596 ast_hangup(transferee); 21597 ast_hangup(transferer); 21598 ast_free(d->park_exten); 21599 ast_free(d->park_context); 21600 ast_free(d); 21601 return -1; 21602 } 21603 21604 /* Setup the extensions and such */ 21605 ast_copy_string(transferee->context, chan1->context, sizeof(transferee->context)); 21606 ast_copy_string(transferee->exten, chan1->exten, sizeof(transferee->exten)); 21607 transferee->priority = chan1->priority; 21608 21609 ast_do_masquerade(transferee); 21610 21611 /* We make a clone of the peer channel too, so we can play 21612 back the announcement */ 21613 21614 /* Make formats okay */ 21615 transferer->readformat = chan2->readformat; 21616 transferer->writeformat = chan2->writeformat; 21617 ast_string_field_set(transferer, parkinglot, chan2->parkinglot); 21618 21619 /* Prepare for taking over the channel */ 21620 if (ast_channel_masquerade(transferer, chan2)) { 21621 ast_hangup(transferer); 21622 ast_free(d->park_exten); 21623 ast_free(d->park_context); 21624 ast_free(d); 21625 return -1; 21626 } 21627 21628 /* Setup the extensions and such */ 21629 ast_copy_string(transferer->context, chan2->context, sizeof(transferer->context)); 21630 ast_copy_string(transferer->exten, chan2->exten, sizeof(transferer->exten)); 21631 transferer->priority = chan2->priority; 21632 21633 ast_do_masquerade(transferer); 21634 21635 /* Save original request for followup */ 21636 copy_request(&d->req, req); 21637 d->chan1 = transferee; /* Transferee */ 21638 d->chan2 = transferer; /* Transferer */ 21639 d->seqno = seqno; 21640 if (ast_pthread_create_detached_background(&th, NULL, sip_park_thread, d) < 0) { 21641 /* Could not start thread */ 21642 deinit_req(&d->req); 21643 ast_free(d->park_exten); 21644 ast_free(d->park_context); 21645 ast_free(d); /* We don't need it anymore. If thread is created, d will be free'd 21646 by sip_park_thread() */ 21647 return -1; 21648 } 21649 return 0; 21650 }
| static void * sip_park_thread | ( | void * | stuff | ) | [static] |
Park SIP call support function Starts in a new thread, then parks the call XXX Should we add a wait period after streaming audio and before hangup?? Sometimes the audio can't be heard before hangup.
Definition at line 21512 of file chan_sip.c.
References append_history, AST_CAUSE_NORMAL_CLEARING, ast_debug, ast_free, ast_hangup(), ast_park_call_exten(), deinit_req(), ext, ast_channel::hangupcause, ast_channel::tech_pvt, transmit_message_with_text(), transmit_notify_with_sipfrag(), and TRUE.
Referenced by sip_park().
21513 { 21514 struct ast_channel *transferee, *transferer; /* Chan1: The transferee, Chan2: The transferer */ 21515 struct sip_dual *d; 21516 int ext; 21517 int res; 21518 21519 d = stuff; 21520 transferee = d->chan1; 21521 transferer = d->chan2; 21522 21523 ast_debug(4, "SIP Park: Transferer channel %s, Transferee %s\n", transferer->name, transferee->name); 21524 21525 res = ast_park_call_exten(transferee, transferer, d->park_exten, d->park_context, 0, &ext); 21526 21527 #ifdef WHEN_WE_KNOW_THAT_THE_CLIENT_SUPPORTS_MESSAGE 21528 if (res) { 21529 transmit_message_with_text(transferer->tech_pvt, "Unable to park call.\n"); 21530 } else { 21531 /* Then tell the transferer what happened */ 21532 sprintf(buf, "Call parked on extension '%d'", ext); 21533 transmit_message_with_text(transferer->tech_pvt, buf); 21534 } 21535 #endif 21536 21537 /* Any way back to the current call??? */ 21538 /* Transmit response to the REFER request */ 21539 if (!res) { 21540 /* Transfer succeeded */ 21541 append_history(transferer->tech_pvt, "SIPpark", "Parked call on %d", ext); 21542 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "200 OK", TRUE); 21543 transferer->hangupcause = AST_CAUSE_NORMAL_CLEARING; 21544 ast_hangup(transferer); /* This will cause a BYE */ 21545 ast_debug(1, "SIP Call parked on extension '%d'\n", ext); 21546 } else { 21547 transmit_notify_with_sipfrag(transferer->tech_pvt, d->seqno, "503 Service Unavailable", TRUE); 21548 append_history(transferer->tech_pvt, "SIPpark", "Parking failed\n"); 21549 ast_debug(1, "SIP Call parked failed \n"); 21550 /* Do not hangup call */ 21551 } 21552 deinit_req(&d->req); 21553 ast_free(d->park_exten); 21554 ast_free(d->park_context); 21555 ast_free(d); 21556 return NULL; 21557 }
| static void sip_peer_hold | ( | struct sip_pvt * | p, | |
| int | hold | |||
| ) | [static] |
Change onhold state of a peer using a pvt structure.
Definition at line 14570 of file chan_sip.c.
References ast_atomic_fetchadd_int(), AST_DEVICE_UNKNOWN, and ast_devstate_changed().
Referenced by change_hold_state(), and update_call_counter().
14571 { 14572 if (!p->relatedpeer) { 14573 return; 14574 } 14575 14576 /* If they put someone on hold, increment the value... otherwise decrement it */ 14577 ast_atomic_fetchadd_int(&p->relatedpeer->onHold, (hold ? +1 : -1)); 14578 14579 /* Request device state update */ 14580 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->relatedpeer->name); 14581 14582 return; 14583 }
| static int sip_pickup | ( | struct ast_channel * | chan | ) | [static] |
Pickup a call using the subsystem in features.c This is executed in a separate thread.
Definition at line 21675 of file chan_sip.c.
References ast_channel_ref, ast_channel_unref, ast_debug, ast_pthread_create_detached_background, and sip_pickup_thread().
Referenced by handle_request_invite().
21676 { 21677 pthread_t threadid; 21678 21679 ast_channel_ref(chan); 21680 21681 if (ast_pthread_create_detached_background(&threadid, NULL, sip_pickup_thread, chan)) { 21682 ast_debug(1, "Unable to start Group pickup thread on channel %s\n", chan->name); 21683 ast_channel_unref(chan); 21684 return -1; 21685 } 21686 ast_debug(1, "Started Group pickup thread on channel %s\n", chan->name); 21687 return 0; 21688 }
| static void * sip_pickup_thread | ( | void * | stuff | ) | [static] |
SIP pickup support function Starts in a new thread, then pickup the call.
Definition at line 21656 of file chan_sip.c.
References AST_CAUSE_CALL_REJECTED, AST_CAUSE_NORMAL_CLEARING, ast_channel_unref, ast_hangup(), ast_pickup_call(), and ast_channel::hangupcause.
Referenced by sip_pickup().
21657 { 21658 struct ast_channel *chan; 21659 chan = stuff; 21660 21661 if (ast_pickup_call(chan)) { 21662 chan->hangupcause = AST_CAUSE_CALL_REJECTED; 21663 } else { 21664 chan->hangupcause = AST_CAUSE_NORMAL_CLEARING; 21665 } 21666 ast_hangup(chan); 21667 ast_channel_unref(chan); 21668 chan = NULL; 21669 return NULL; 21670 }
| static void sip_poke_all_peers | ( | void | ) | [static] |
Send a poke to all known peers.
Definition at line 29791 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_iterator_next, ao2_unlock, AST_SCHED_REPLACE_UNREF, ref_peer(), sip_poke_peer_s(), and unref_peer().
Referenced by load_module(), and sip_do_reload().
29792 { 29793 int ms = 0, num = 0; 29794 struct ao2_iterator i; 29795 struct sip_peer *peer; 29796 29797 if (!speerobjs) { /* No peers, just give up */ 29798 return; 29799 } 29800 29801 i = ao2_iterator_init(peers, 0); 29802 while ((peer = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 29803 ao2_lock(peer); 29804 if (num == global_qualify_peers) { 29805 ms += global_qualify_gap; 29806 num = 0; 29807 } else { 29808 num++; 29809 } 29810 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, ms, sip_poke_peer_s, peer, 29811 unref_peer(_data, "removing poke peer ref"), 29812 unref_peer(peer, "removing poke peer ref"), 29813 ref_peer(peer, "adding poke peer ref")); 29814 ao2_unlock(peer); 29815 unref_peer(peer, "toss iterator peer ptr"); 29816 } 29817 ao2_iterator_destroy(&i); 29818 }
| static int sip_poke_noanswer | ( | const void * | data | ) | [static] |
React to lack of answer to Qualify poke.
Definition at line 26380 of file chan_sip.c.
References ast_check_realtime(), AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), AST_SCHED_REPLACE_UNREF, ast_update_realtime(), DEFAULT_FREQ_NOTOK, dialog_unlink_all(), EVENT_FLAG_SYSTEM, FALSE, LOG_NOTICE, manager_event, ref_peer(), register_peer_exten(), SENTINEL, sip_cfg, sip_poke_peer_s(), and unref_peer().
Referenced by sip_poke_peer(), and sip_show_sched().
26381 { 26382 struct sip_peer *peer = (struct sip_peer *)data; 26383 26384 peer->pokeexpire = -1; 26385 26386 if (peer->lastms > -1) { 26387 ast_log(LOG_NOTICE, "Peer '%s' is now UNREACHABLE! Last qualify: %d\n", peer->name, peer->lastms); 26388 if (sip_cfg.peer_rtupdate) { 26389 ast_update_realtime(ast_check_realtime("sipregs") ? "sipregs" : "sippeers", "name", peer->name, "lastms", "-1", SENTINEL); 26390 } 26391 manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "ChannelType: SIP\r\nPeer: SIP/%s\r\nPeerStatus: Unreachable\r\nTime: %d\r\n", peer->name, -1); 26392 if (sip_cfg.regextenonqualify) { 26393 register_peer_exten(peer, FALSE); 26394 } 26395 } 26396 26397 if (peer->call) { 26398 dialog_unlink_all(peer->call); 26399 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 26400 /* peer->call = sip_destroy(peer->call);*/ 26401 } 26402 26403 /* Don't send a devstate change if nothing changed. */ 26404 if (peer->lastms > -1) { 26405 peer->lastms = -1; 26406 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", peer->name); 26407 } 26408 26409 /* Try again quickly */ 26410 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, 26411 DEFAULT_FREQ_NOTOK, sip_poke_peer_s, peer, 26412 unref_peer(_data, "removing poke peer ref"), 26413 unref_peer(peer, "removing poke peer ref"), 26414 ref_peer(peer, "adding poke peer ref")); 26415 26416 /* Release the ref held by the running scheduler entry */ 26417 unref_peer(peer, "release peer poke noanswer ref"); 26418 26419 return 0; 26420 }
| static int sip_poke_peer | ( | struct sip_peer * | peer, | |
| int | force | |||
| ) | [static] |
Check availability of peer, also keep NAT open.
Definition at line 26427 of file chan_sip.c.
References ast_copy_flags, ast_copy_string(), ast_log(), AST_SCHED_DEL_UNREF, AST_SCHED_REPLACE_UNREF, ast_set_flag, ast_sip_ouraddrfor(), ast_sockaddr_isnull(), ast_sockaddr_stringify_host_remote(), ast_string_field_set, ast_strlen_zero(), ast_tvnow(), build_via(), change_callid_pvt(), copy_socket_data(), dialog_unlink_all(), LOG_NOTICE, ref_peer(), sip_alloc(), sip_poke_noanswer(), transmit_invite(), and unref_peer().
Referenced by _sip_qualify_peer(), build_peer(), parse_register_contact(), reg_source_db(), and sip_poke_peer_s().
26428 { 26429 struct sip_pvt *p; 26430 int xmitres = 0; 26431 26432 if ((!peer->maxms && !force) || ast_sockaddr_isnull(&peer->addr)) { 26433 /* IF we have no IP, or this isn't to be monitored, return 26434 immediately after clearing things out */ 26435 AST_SCHED_DEL_UNREF(sched, peer->pokeexpire, 26436 unref_peer(peer, "removing poke peer ref")); 26437 26438 peer->lastms = 0; 26439 if (peer->call) { 26440 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 26441 } 26442 return 0; 26443 } 26444 if (peer->call) { 26445 if (sipdebug) { 26446 ast_log(LOG_NOTICE, "Still have a QUALIFY dialog active, deleting\n"); 26447 } 26448 dialog_unlink_all(peer->call); 26449 peer->call = dialog_unref(peer->call, "unref dialog peer->call"); 26450 /* peer->call = sip_destroy(peer->call); */ 26451 } 26452 if (!(p = sip_alloc(NULL, NULL, 0, SIP_OPTIONS, NULL))) { 26453 return -1; 26454 } 26455 peer->call = dialog_ref(p, "copy sip alloc from p to peer->call"); 26456 26457 p->sa = peer->addr; 26458 p->recv = peer->addr; 26459 copy_socket_data(&p->socket, &peer->socket); 26460 ast_copy_flags(&p->flags[0], &peer->flags[0], SIP_FLAGS_TO_COPY); 26461 ast_copy_flags(&p->flags[1], &peer->flags[1], SIP_PAGE2_FLAGS_TO_COPY); 26462 ast_copy_flags(&p->flags[2], &peer->flags[2], SIP_PAGE3_FLAGS_TO_COPY); 26463 26464 /* Send OPTIONs to peer's fullcontact */ 26465 if (!ast_strlen_zero(peer->fullcontact)) { 26466 ast_string_field_set(p, fullcontact, peer->fullcontact); 26467 } 26468 26469 if (!ast_strlen_zero(peer->fromuser)) { 26470 ast_string_field_set(p, fromuser, peer->fromuser); 26471 } 26472 26473 if (!ast_strlen_zero(peer->tohost)) { 26474 ast_string_field_set(p, tohost, peer->tohost); 26475 } else { 26476 ast_string_field_set(p, tohost, ast_sockaddr_stringify_host_remote(&peer->addr)); 26477 } 26478 26479 /* Recalculate our side, and recalculate Call ID */ 26480 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 26481 build_via(p); 26482 26483 /* Change the dialog callid. */ 26484 change_callid_pvt(p, NULL); 26485 26486 AST_SCHED_DEL_UNREF(sched, peer->pokeexpire, 26487 unref_peer(peer, "removing poke peer ref")); 26488 26489 if (p->relatedpeer) 26490 p->relatedpeer = unref_peer(p->relatedpeer,"unsetting the relatedpeer field in the dialog, before it is set to something else."); 26491 p->relatedpeer = ref_peer(peer, "setting the relatedpeer field in the dialog"); 26492 ast_set_flag(&p->flags[0], SIP_OUTGOING); 26493 #ifdef VOCAL_DATA_HACK 26494 ast_copy_string(p->username, "__VOCAL_DATA_SHOULD_READ_THE_SIP_SPEC__", sizeof(p->username)); 26495 xmitres = transmit_invite(p, SIP_INVITE, 0, 2, NULL); /* sinks the p refcount */ 26496 #else 26497 xmitres = transmit_invite(p, SIP_OPTIONS, 0, 2, NULL); /* sinks the p refcount */ 26498 #endif 26499 peer->ps = ast_tvnow(); 26500 if (xmitres == XMIT_ERROR) { 26501 /* Immediately unreachable, network problems */ 26502 sip_poke_noanswer(ref_peer(peer, "add ref for peerexpire (fake, for sip_poke_noanswer to remove)")); 26503 } else if (!force) { 26504 AST_SCHED_REPLACE_UNREF(peer->pokeexpire, sched, peer->maxms * 2, sip_poke_noanswer, peer, 26505 unref_peer(_data, "removing poke peer ref"), 26506 unref_peer(peer, "removing poke peer ref"), 26507 ref_peer(peer, "adding poke peer ref")); 26508 } 26509 dialog_unref(p, "unref dialog at end of sip_poke_peer, obtained from sip_alloc, just before it goes out of scope"); 26510 return 0; 26511 }
| static int sip_poke_peer_s | ( | const void * | data | ) | [static] |
Poke peer (send qualify to check if peer is alive and well).
Definition at line 13827 of file chan_sip.c.
References ao2_find, OBJ_POINTER, sip_poke_peer(), and unref_peer().
Referenced by handle_response_peerpoke(), reg_source_db(), sip_poke_all_peers(), sip_poke_noanswer(), and sip_show_sched().
13828 { 13829 struct sip_peer *peer = (struct sip_peer *)data; 13830 struct sip_peer *foundpeer; 13831 13832 peer->pokeexpire = -1; 13833 13834 foundpeer = ao2_find(peers, peer, OBJ_POINTER); 13835 if (!foundpeer) { 13836 unref_peer(peer, "removing poke peer ref"); 13837 return 0; 13838 } else if (foundpeer->name != peer->name) { 13839 unref_peer(foundpeer, "removing above peer ref"); 13840 unref_peer(peer, "removing poke peer ref"); 13841 return 0; 13842 } 13843 13844 unref_peer(foundpeer, "removing above peer ref"); 13845 sip_poke_peer(peer, 0); 13846 unref_peer(peer, "removing poke peer ref"); 13847 13848 return 0; 13849 }
| static int sip_prepare_socket | ( | struct sip_pvt * | p | ) | [static] |
Definition at line 25620 of file chan_sip.c.
References ast_tcptls_session_args::accept_fd, ao2_alloc, ao2_ref, ao2_t_ref, ao2_t_unlink, ast_calloc, ast_copy_string(), ast_debug, ast_pthread_create_detached_background, ast_sockaddr_copy(), ast_strdup, ast_strlen_zero(), ast_tcptls_client_create(), ast_tcptls_close_session_file(), ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, ast_tcptls_session_instance::fd, ast_tcptls_session_args::hostname, ast_tcptls_session_args::name, name, ast_tls_config::pvtfile, ast_tcptls_session_args::remote_address, sip_real_dst(), sip_tcp_locate(), sip_tcp_worker_fn(), sip_tcptls_client_args_destructor(), sip_threadinfo_create(), and ast_tcptls_session_args::tls_cfg.
Referenced by __sip_xmit().
25621 { 25622 struct sip_socket *s = &p->socket; 25623 static const char name[] = "SIP socket"; 25624 struct sip_threadinfo *th = NULL; 25625 struct ast_tcptls_session_instance *tcptls_session; 25626 struct ast_tcptls_session_args *ca; 25627 struct ast_sockaddr sa_tmp; 25628 pthread_t launched; 25629 25630 /* check to see if a socket is already active */ 25631 if ((s->fd != -1) && (s->type == SIP_TRANSPORT_UDP)) { 25632 return s->fd; 25633 } 25634 if ((s->type & (SIP_TRANSPORT_TCP | SIP_TRANSPORT_TLS)) && 25635 (s->tcptls_session) && 25636 (s->tcptls_session->fd != -1)) { 25637 return s->tcptls_session->fd; 25638 } 25639 25640 /*! \todo Check this... This might be wrong, depending on the proxy configuration 25641 If proxy is in "force" mode its correct. 25642 */ 25643 if (p->outboundproxy && p->outboundproxy->transport) { 25644 s->type = p->outboundproxy->transport; 25645 } 25646 25647 if (s->type == SIP_TRANSPORT_UDP) { 25648 s->fd = sipsock; 25649 return s->fd; 25650 } 25651 25652 /* At this point we are dealing with a TCP/TLS connection 25653 * 1. We need to check to see if a connection thread exists 25654 * for this address, if so use that. 25655 * 2. If a thread does not exist for this address, but the tcptls_session 25656 * exists on the socket, the connection was closed. 25657 * 3. If no tcptls_session thread exists for the address, and no tcptls_session 25658 * already exists on the socket, create a new one and launch a new thread. 25659 */ 25660 25661 /* 1. check for existing threads */ 25662 ast_sockaddr_copy(&sa_tmp, sip_real_dst(p)); 25663 if ((tcptls_session = sip_tcp_locate(&sa_tmp))) { 25664 s->fd = tcptls_session->fd; 25665 if (s->tcptls_session) { 25666 ao2_ref(s->tcptls_session, -1); 25667 s->tcptls_session = NULL; 25668 } 25669 s->tcptls_session = tcptls_session; 25670 return s->fd; 25671 /* 2. Thread not found, if tcptls_session already exists, it once had a thread and is now terminated */ 25672 } else if (s->tcptls_session) { 25673 return s->fd; /* XXX whether reconnection is ever necessary here needs to be investigated further */ 25674 } 25675 25676 /* 3. Create a new TCP/TLS client connection */ 25677 /* create new session arguments for the client connection */ 25678 if (!(ca = ao2_alloc(sizeof(*ca), sip_tcptls_client_args_destructor)) || 25679 !(ca->name = ast_strdup(name))) { 25680 goto create_tcptls_session_fail; 25681 } 25682 ca->accept_fd = -1; 25683 ast_sockaddr_copy(&ca->remote_address,sip_real_dst(p)); 25684 /* if type is TLS, we need to create a tls cfg for this session arg */ 25685 if (s->type == SIP_TRANSPORT_TLS) { 25686 if (!(ca->tls_cfg = ast_calloc(1, sizeof(*ca->tls_cfg)))) { 25687 goto create_tcptls_session_fail; 25688 } 25689 memcpy(ca->tls_cfg, &default_tls_cfg, sizeof(*ca->tls_cfg)); 25690 25691 if (!(ca->tls_cfg->certfile = ast_strdup(default_tls_cfg.certfile)) || 25692 !(ca->tls_cfg->pvtfile = ast_strdup(default_tls_cfg.pvtfile)) || 25693 !(ca->tls_cfg->cipher = ast_strdup(default_tls_cfg.cipher)) || 25694 !(ca->tls_cfg->cafile = ast_strdup(default_tls_cfg.cafile)) || 25695 !(ca->tls_cfg->capath = ast_strdup(default_tls_cfg.capath))) { 25696 25697 goto create_tcptls_session_fail; 25698 } 25699 25700 /* this host is used as the common name in ssl/tls */ 25701 if (!ast_strlen_zero(p->tohost)) { 25702 ast_copy_string(ca->hostname, p->tohost, sizeof(ca->hostname)); 25703 } 25704 } 25705 25706 /* Create a client connection for address, this does not start the connection, just sets it up. */ 25707 if (!(s->tcptls_session = ast_tcptls_client_create(ca))) { 25708 goto create_tcptls_session_fail; 25709 } 25710 25711 s->fd = s->tcptls_session->fd; 25712 25713 /* client connections need to have the sip_threadinfo object created before 25714 * the thread is detached. This ensures the alert_pipe is up before it will 25715 * be used. Note that this function links the new threadinfo object into the 25716 * threadt container. */ 25717 if (!(th = sip_threadinfo_create(s->tcptls_session, s->type))) { 25718 goto create_tcptls_session_fail; 25719 } 25720 25721 /* Give the new thread a reference to the tcptls_session */ 25722 ao2_ref(s->tcptls_session, +1); 25723 25724 if (ast_pthread_create_detached_background(&launched, NULL, sip_tcp_worker_fn, s->tcptls_session)) { 25725 ast_debug(1, "Unable to launch '%s'.", ca->name); 25726 ao2_ref(s->tcptls_session, -1); /* take away the thread ref we just gave it */ 25727 goto create_tcptls_session_fail; 25728 } 25729 25730 return s->fd; 25731 25732 create_tcptls_session_fail: 25733 if (ca) { 25734 ao2_t_ref(ca, -1, "failed to create client, getting rid of client tcptls_session arguments"); 25735 } 25736 if (s->tcptls_session) { 25737 ast_tcptls_close_session_file(s->tcptls_session); 25738 s->fd = -1; 25739 ao2_ref(s->tcptls_session, -1); 25740 s->tcptls_session = NULL; 25741 } 25742 if (th) { 25743 ao2_t_unlink(threadt, th, "Removing tcptls thread info object, thread failed to open"); 25744 } 25745 25746 return -1; 25747 }
| static char * sip_prune_realtime | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Remove temporary realtime objects from memory (CLI).
Definition at line 17175 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_find, ao2_t_iterator_next, ao2_t_link, ao2_t_unlink, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_cli_complete(), ast_copy_string(), ast_sockaddr_isnull(), ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_peer(), FALSE, ast_cli_args::fd, ast_cli_args::n, name, OBJ_POINTER, OBJ_UNLINK, ast_cli_args::pos, TRUE, unlink_marked_peers_from_tables(), unref_peer(), ast_cli_entry::usage, and ast_cli_args::word.
17176 { 17177 struct sip_peer *peer, *pi; 17178 int prunepeer = FALSE; 17179 int multi = FALSE; 17180 const char *name = NULL; 17181 regex_t regexbuf; 17182 int havepattern = 0; 17183 struct ao2_iterator i; 17184 static const char * const choices[] = { "all", "like", NULL }; 17185 char *cmplt; 17186 17187 if (cmd == CLI_INIT) { 17188 e->command = "sip prune realtime [peer|all]"; 17189 e->usage = 17190 "Usage: sip prune realtime [peer [<name>|all|like <pattern>]|all]\n" 17191 " Prunes object(s) from the cache.\n" 17192 " Optional regular expression pattern is used to filter the objects.\n"; 17193 return NULL; 17194 } else if (cmd == CLI_GENERATE) { 17195 if (a->pos == 4 && !strcasecmp(a->argv[3], "peer")) { 17196 cmplt = ast_cli_complete(a->word, choices, a->n); 17197 if (!cmplt) 17198 cmplt = complete_sip_peer(a->word, a->n - sizeof(choices), SIP_PAGE2_RTCACHEFRIENDS); 17199 return cmplt; 17200 } 17201 if (a->pos == 5 && !strcasecmp(a->argv[4], "like")) 17202 return complete_sip_peer(a->word, a->n, SIP_PAGE2_RTCACHEFRIENDS); 17203 return NULL; 17204 } 17205 switch (a->argc) { 17206 case 4: 17207 name = a->argv[3]; 17208 /* we accept a name in position 3, but keywords are not good. */ 17209 if (!strcasecmp(name, "peer") || !strcasecmp(name, "like")) 17210 return CLI_SHOWUSAGE; 17211 prunepeer = TRUE; 17212 if (!strcasecmp(name, "all")) { 17213 multi = TRUE; 17214 name = NULL; 17215 } 17216 /* else a single name, already set */ 17217 break; 17218 case 5: 17219 /* sip prune realtime {peer|like} name */ 17220 name = a->argv[4]; 17221 if (!strcasecmp(a->argv[3], "peer")) 17222 prunepeer = TRUE; 17223 else if (!strcasecmp(a->argv[3], "like")) { 17224 prunepeer = TRUE; 17225 multi = TRUE; 17226 } else 17227 return CLI_SHOWUSAGE; 17228 if (!strcasecmp(name, "like")) 17229 return CLI_SHOWUSAGE; 17230 if (!multi && !strcasecmp(name, "all")) { 17231 multi = TRUE; 17232 name = NULL; 17233 } 17234 break; 17235 case 6: 17236 name = a->argv[5]; 17237 multi = TRUE; 17238 /* sip prune realtime {peer} like name */ 17239 if (strcasecmp(a->argv[4], "like")) 17240 return CLI_SHOWUSAGE; 17241 if (!strcasecmp(a->argv[3], "peer")) { 17242 prunepeer = TRUE; 17243 } else 17244 return CLI_SHOWUSAGE; 17245 break; 17246 default: 17247 return CLI_SHOWUSAGE; 17248 } 17249 17250 if (multi && name) { 17251 if (regcomp(®exbuf, name, REG_EXTENDED | REG_NOSUB)) { 17252 return CLI_SHOWUSAGE; 17253 } 17254 havepattern = 1; 17255 } 17256 17257 if (multi) { 17258 if (prunepeer) { 17259 int pruned = 0; 17260 17261 i = ao2_iterator_init(peers, 0); 17262 while ((pi = ao2_t_iterator_next(&i, "iterate thru peers table"))) { 17263 ao2_lock(pi); 17264 if (name && regexec(®exbuf, pi->name, 0, NULL, 0)) { 17265 ao2_unlock(pi); 17266 unref_peer(pi, "toss iterator peer ptr before continue"); 17267 continue; 17268 }; 17269 if (ast_test_flag(&pi->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 17270 pi->the_mark = 1; 17271 pruned++; 17272 } 17273 ao2_unlock(pi); 17274 unref_peer(pi, "toss iterator peer ptr"); 17275 } 17276 ao2_iterator_destroy(&i); 17277 if (pruned) { 17278 unlink_marked_peers_from_tables(); 17279 ast_cli(a->fd, "%d peers pruned.\n", pruned); 17280 } else 17281 ast_cli(a->fd, "No peers found to prune.\n"); 17282 } 17283 } else { 17284 if (prunepeer) { 17285 struct sip_peer tmp; 17286 ast_copy_string(tmp.name, name, sizeof(tmp.name)); 17287 if ((peer = ao2_t_find(peers, &tmp, OBJ_POINTER | OBJ_UNLINK, "finding to unlink from peers"))) { 17288 if (!ast_sockaddr_isnull(&peer->addr)) { 17289 ao2_t_unlink(peers_by_ip, peer, "unlinking peer from peers_by_ip also"); 17290 } 17291 if (!ast_test_flag(&peer->flags[1], SIP_PAGE2_RTCACHEFRIENDS)) { 17292 ast_cli(a->fd, "Peer '%s' is not a Realtime peer, cannot be pruned.\n", name); 17293 /* put it back! */ 17294 ao2_t_link(peers, peer, "link peer into peer table"); 17295 if (!ast_sockaddr_isnull(&peer->addr)) { 17296 ao2_t_link(peers_by_ip, peer, "link peer into peers_by_ip table"); 17297 } 17298 } else 17299 ast_cli(a->fd, "Peer '%s' pruned.\n", name); 17300 unref_peer(peer, "sip_prune_realtime: unref_peer: tossing temp peer ptr"); 17301 } else 17302 ast_cli(a->fd, "Peer '%s' not found.\n", name); 17303 } 17304 } 17305 17306 if (havepattern) { 17307 regfree(®exbuf); 17308 } 17309 17310 return CLI_SUCCESS; 17311 }
| static struct ast_channel * sip_pvt_lock_full | ( | struct sip_pvt * | pvt | ) | [static, read] |
Definition at line 8026 of file chan_sip.c.
References ast_channel_lock, ast_channel_ref, ast_channel_unlock, ast_channel_unref, sip_pvt_lock, and sip_pvt_unlock.
Referenced by __sip_autodestruct(), dialog_unlink_all(), handle_request_do(), reinvite_timeout(), send_provisional_keepalive_full(), and sip_queue_hangup_cause().
08027 { 08028 struct ast_channel *chan; 08029 08030 /* Locking is simple when it is done right. If you see a deadlock resulting 08031 * in this function, it is not this function's fault, Your problem exists elsewhere. 08032 * This function is perfect... seriously. */ 08033 for (;;) { 08034 /* First, get the channel and grab a reference to it */ 08035 sip_pvt_lock(pvt); 08036 chan = pvt->owner; 08037 if (chan) { 08038 /* The channel can not go away while we hold the pvt lock. 08039 * Give the channel a ref so it will not go away after we let 08040 * the pvt lock go. */ 08041 ast_channel_ref(chan); 08042 } else { 08043 /* no channel, return pvt locked */ 08044 return NULL; 08045 } 08046 08047 /* We had to hold the pvt lock while getting a ref to the owner channel 08048 * but now we have to let this lock go in order to preserve proper 08049 * locking order when grabbing the channel lock */ 08050 sip_pvt_unlock(pvt); 08051 08052 /* Look, no deadlock avoidance, hooray! */ 08053 ast_channel_lock(chan); 08054 sip_pvt_lock(pvt); 08055 08056 if (pvt->owner == chan) { 08057 /* done */ 08058 break; 08059 } 08060 08061 /* If the owner changed while everything was unlocked, no problem, 08062 * just start over and everthing will work. This is rare, do not be 08063 * confused by this loop and think this it is an expensive operation. 08064 * The majority of the calls to this function will never involve multiple 08065 * executions of this loop. */ 08066 ast_channel_unlock(chan); 08067 ast_channel_unref(chan); 08068 sip_pvt_unlock(pvt); 08069 } 08070 08071 /* If owner exists, it is locked and reffed */ 08072 return pvt->owner; 08073 }
| static char * sip_qualify_peer | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Send an OPTIONS packet to a SIP peer.
Definition at line 17460 of file chan_sip.c.
References _sip_qualify_peer(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, complete_sip_show_peer(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
17461 { 17462 switch (cmd) { 17463 case CLI_INIT: 17464 e->command = "sip qualify peer"; 17465 e->usage = 17466 "Usage: sip qualify peer <name> [load]\n" 17467 " Requests a response from one SIP peer and the current status.\n" 17468 " Option \"load\" forces lookup of peer in realtime storage.\n"; 17469 return NULL; 17470 case CLI_GENERATE: 17471 return complete_sip_show_peer(a->line, a->word, a->pos, a->n); 17472 } 17473 return _sip_qualify_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); 17474 }
| static int sip_queryoption | ( | struct ast_channel * | chan, | |
| int | option, | |||
| void * | data, | |||
| int * | datalen | |||
| ) | [static] |
Query an option on a SIP dialog.
Definition at line 4340 of file chan_sip.c.
References ast_copy_string(), ast_debug, ast_log(), AST_OPTION_DEVICE_NAME, AST_OPTION_DIGIT_DETECT, AST_OPTION_SECURE_MEDIA, AST_OPTION_SECURE_SIGNALING, AST_OPTION_T38_STATE, ast_test_flag, LOG_ERROR, sip_pvt_lock, sip_pvt_unlock, T38_STATE_NEGOTIATED, T38_STATE_NEGOTIATING, T38_STATE_UNAVAILABLE, T38_STATE_UNKNOWN, and ast_channel::tech_pvt.
04341 { 04342 int res = -1; 04343 enum ast_t38_state state = T38_STATE_UNAVAILABLE; 04344 struct sip_pvt *p = (struct sip_pvt *) chan->tech_pvt; 04345 char *cp; 04346 04347 sip_pvt_lock(p); 04348 04349 switch (option) { 04350 case AST_OPTION_T38_STATE: 04351 /* Make sure we got an ast_t38_state enum passed in */ 04352 if (*datalen != sizeof(enum ast_t38_state)) { 04353 ast_log(LOG_ERROR, "Invalid datalen for AST_OPTION_T38_STATE option. Expected %d, got %d\n", (int)sizeof(enum ast_t38_state), *datalen); 04354 break; 04355 } 04356 04357 /* Now if T38 support is enabled we need to look and see what the current state is to get what we want to report back */ 04358 if (ast_test_flag(&p->flags[1], SIP_PAGE2_T38SUPPORT)) { 04359 switch (p->t38.state) { 04360 case T38_LOCAL_REINVITE: 04361 case T38_PEER_REINVITE: 04362 state = T38_STATE_NEGOTIATING; 04363 break; 04364 case T38_ENABLED: 04365 state = T38_STATE_NEGOTIATED; 04366 break; 04367 default: 04368 state = T38_STATE_UNKNOWN; 04369 } 04370 } 04371 04372 *((enum ast_t38_state *) data) = state; 04373 res = 0; 04374 04375 break; 04376 case AST_OPTION_DIGIT_DETECT: 04377 cp = (char *) data; 04378 *cp = p->dsp ? 1 : 0; 04379 ast_debug(1, "Reporting digit detection %sabled on %s\n", *cp ? "en" : "dis", chan->name); 04380 break; 04381 case AST_OPTION_SECURE_SIGNALING: 04382 *((unsigned int *) data) = p->req_secure_signaling; 04383 res = 0; 04384 break; 04385 case AST_OPTION_SECURE_MEDIA: 04386 *((unsigned int *) data) = ast_test_flag(&p->flags[1], SIP_PAGE2_USE_SRTP) ? 1 : 0; 04387 res = 0; 04388 break; 04389 case AST_OPTION_DEVICE_NAME: 04390 if (p && p->outgoing_call) { 04391 cp = (char *) data; 04392 ast_copy_string(cp, p->dialstring, *datalen); 04393 res = 0; 04394 } 04395 /* We purposely break with a return of -1 in the 04396 * implied else case here 04397 */ 04398 break; 04399 default: 04400 break; 04401 } 04402 04403 sip_pvt_unlock(p); 04404 04405 return res; 04406 }
| static void sip_queue_hangup_cause | ( | struct sip_pvt * | p, | |
| int | cause | |||
| ) | [static] |
Definition at line 20063 of file chan_sip.c.
References ast_channel_ref, ast_channel_unlock, ast_channel_unref, ast_queue_hangup(), ast_queue_hangup_with_cause(), ast_set_hangupsource(), ast_strdupa, name, sip_pvt_lock_full(), and sip_pvt_unlock.
Referenced by handle_request_bye(), handle_request_cancel(), and handle_response_invite().
20064 { 20065 struct ast_channel *owner = p->owner; 20066 const char *name = ast_strdupa(owner->name); 20067 20068 /* Cannot hold any channel/private locks when calling. */ 20069 ast_channel_ref(owner); 20070 ast_channel_unlock(owner); 20071 sip_pvt_unlock(p); 20072 ast_set_hangupsource(owner, name, 0); 20073 if (cause) { 20074 ast_queue_hangup_with_cause(owner, cause); 20075 } else { 20076 ast_queue_hangup(owner); 20077 } 20078 ast_channel_unref(owner); 20079 20080 /* Relock things. */ 20081 owner = sip_pvt_lock_full(p); 20082 if (owner) { 20083 ast_channel_unref(owner); 20084 } 20085 }
| static struct ast_frame * sip_read | ( | struct ast_channel * | ast | ) | [static, read] |
Read SIP RTP from channel.
Definition at line 7491 of file chan_sip.c.
References ast_channel::_state, ast_async_goto(), ast_channel_lock, ast_channel_unlock, ast_exists_extension(), AST_FRAME_VOICE, ast_frfree, ast_log(), ast_null_frame, AST_STATE_UP, ast_test_flag, ast_verbose, ast_channel::caller, ast_channel::context, ast_channel::exten, FALSE, ast_frame::frametype, ast_party_caller::id, LOG_NOTICE, ast_channel::macrocontext, ast_party_id::number, pbx_builtin_setvar_helper(), S_COR, S_OR, sip_pvt_lock, sip_pvt_unlock, sip_rtp_read(), ast_party_number::str, ast_channel::tech_pvt, ast_party_number::valid, and VERBOSE_PREFIX_2.
07492 { 07493 struct ast_frame *fr; 07494 struct sip_pvt *p = ast->tech_pvt; 07495 int faxdetected = FALSE; 07496 07497 sip_pvt_lock(p); 07498 fr = sip_rtp_read(ast, p, &faxdetected); 07499 p->lastrtprx = time(NULL); 07500 07501 /* If we detect a CNG tone and fax detection is enabled then send us off to the fax extension */ 07502 if (faxdetected && ast_test_flag(&p->flags[1], SIP_PAGE2_FAX_DETECT_CNG)) { 07503 if (strcmp(ast->exten, "fax")) { 07504 const char *target_context = S_OR(ast->macrocontext, ast->context); 07505 /* We need to unlock 'ast' here because 07506 * ast_exists_extension has the potential to start and 07507 * stop an autoservice on the channel. Such action is 07508 * prone to deadlock if the channel is locked. 07509 */ 07510 sip_pvt_unlock(p); 07511 ast_channel_unlock(ast); 07512 if (ast_exists_extension(ast, target_context, "fax", 1, 07513 S_COR(ast->caller.id.number.valid, ast->caller.id.number.str, NULL))) { 07514 ast_channel_lock(ast); 07515 sip_pvt_lock(p); 07516 ast_verbose(VERBOSE_PREFIX_2 "Redirecting '%s' to fax extension due to CNG detection\n", ast->name); 07517 pbx_builtin_setvar_helper(ast, "FAXEXTEN", ast->exten); 07518 if (ast_async_goto(ast, target_context, "fax", 1)) { 07519 ast_log(LOG_NOTICE, "Failed to async goto '%s' into fax of '%s'\n", ast->name, target_context); 07520 } 07521 ast_frfree(fr); 07522 fr = &ast_null_frame; 07523 } else { 07524 ast_channel_lock(ast); 07525 sip_pvt_lock(p); 07526 ast_log(LOG_NOTICE, "FAX CNG detected but no fax extension\n"); 07527 } 07528 } 07529 } 07530 07531 /* Only allow audio through if they sent progress with SDP, or if the channel is actually answered */ 07532 if (fr && fr->frametype == AST_FRAME_VOICE && p->invitestate != INV_EARLY_MEDIA && ast->_state != AST_STATE_UP) { 07533 ast_frfree(fr); 07534 fr = &ast_null_frame; 07535 } 07536 07537 sip_pvt_unlock(p); 07538 07539 return fr; 07540 }
| static struct ast_sockaddr * sip_real_dst | ( | const struct sip_pvt * | p | ) | [static, read] |
The real destination address for a write.
Definition at line 3206 of file chan_sip.c.
References ast_test_flag.
Referenced by __sip_xmit(), check_via(), retrans_pkt(), send_response(), show_channels_cb(), sip_debug_test_pvt(), and sip_prepare_socket().
03207 { 03208 if (p->outboundproxy) { 03209 return &p->outboundproxy->ip; 03210 } 03211 03212 return ast_test_flag(&p->flags[0], SIP_NAT_FORCE_RPORT) || ast_test_flag(&p->flags[0], SIP_NAT_RPORT_PRESENT) ? &p->recv : &p->sa; 03213 }
| static const char* sip_reason_code_to_str | ( | enum AST_REDIRECTING_REASON | code | ) | [static] |
Definition at line 2288 of file chan_sip.c.
References ARRAY_LEN, sip_reason_table, and sip_reasons::text.
Referenced by add_diversion_header().
02289 { 02290 if (code >= 0 && code < ARRAY_LEN(sip_reason_table)) { 02291 return sip_reason_table[code].text; 02292 } 02293 02294 return "unknown"; 02295 }
| static enum AST_REDIRECTING_REASON sip_reason_str_to_code | ( | const char * | text | ) | [static] |
Definition at line 2273 of file chan_sip.c.
References ARRAY_LEN, AST_REDIRECTING_REASON_UNKNOWN, sip_reasons::code, and sip_reason_table.
Referenced by get_rdnis().
02274 { 02275 enum AST_REDIRECTING_REASON ast = AST_REDIRECTING_REASON_UNKNOWN; 02276 int i; 02277 02278 for (i = 0; i < ARRAY_LEN(sip_reason_table); ++i) { 02279 if (!strcasecmp(text, sip_reason_table[i].text)) { 02280 ast = sip_reason_table[i].code; 02281 break; 02282 } 02283 } 02284 02285 return ast; 02286 }
| static int sip_refer_allocate | ( | struct sip_pvt * | p | ) | [static] |
Allocate SIP refer structure.
Definition at line 13515 of file chan_sip.c.
References ast_calloc.
Referenced by get_also_info(), handle_request_invite(), handle_request_refer(), and transmit_refer().
13516 { 13517 p->refer = ast_calloc(1, sizeof(struct sip_refer)); 13518 return p->refer ? 1 : 0; 13519 }
| static int sip_reg_timeout | ( | const void * | data | ) | [static] |
Registration timeout, register again Registered as a timeout handler during transmit_register(), to retransmit the packet if a reply does not come back. This is called by the scheduler so the event is not pending anymore when we are called.
Definition at line 13178 of file chan_sip.c.
References __sip_pretend_ack(), ast_dnsmgr_refresh(), ast_log(), EVENT_FLAG_SYSTEM, LOG_NOTICE, manager_event, pvt_set_needdestroy(), REG_STATE_UNREGISTERED, registry_unref(), regstate2str(), sip_pvt_lock, sip_pvt_unlock, and transmit_register().
Referenced by sip_show_sched(), and transmit_register().
13179 { 13180 13181 /* if we are here, our registration timed out, so we'll just do it over */ 13182 struct sip_registry *r = (struct sip_registry *)data; /* the ref count should have been bumped when the sched item was added */ 13183 struct sip_pvt *p; 13184 13185 /* if we couldn't get a reference to the registry object, punt */ 13186 if (!r) { 13187 return 0; 13188 } 13189 13190 if (r->dnsmgr) { 13191 /* If the registration has timed out, maybe the IP changed. Force a refresh. */ 13192 ast_dnsmgr_refresh(r->dnsmgr); 13193 } 13194 13195 /* If the initial tranmission failed, we may not have an existing dialog, 13196 * so it is possible that r->call == NULL. 13197 * Otherwise destroy it, as we have a timeout so we don't want it. 13198 */ 13199 if (r->call) { 13200 /* Unlink us, destroy old call. Locking is not relevant here because all this happens 13201 in the single SIP manager thread. */ 13202 p = r->call; 13203 sip_pvt_lock(p); 13204 pvt_set_needdestroy(p, "registration timeout"); 13205 /* Pretend to ACK anything just in case */ 13206 __sip_pretend_ack(p); 13207 sip_pvt_unlock(p); 13208 13209 /* decouple the two objects */ 13210 /* p->registry == r, so r has 2 refs, and the unref won't take the object away */ 13211 if (p->registry) { 13212 p->registry = registry_unref(p->registry, "p->registry unreffed"); 13213 } 13214 r->call = dialog_unref(r->call, "unrefing r->call"); 13215 } 13216 /* If we have a limit, stop registration and give up */ 13217 r->timeout = -1; 13218 if (global_regattempts_max && r->regattempts >= global_regattempts_max) { 13219 /* Ok, enough is enough. Don't try any more */ 13220 /* We could add an external notification here... 13221 steal it from app_voicemail :-) */ 13222 ast_log(LOG_NOTICE, " -- Last Registration Attempt #%d failed, Giving up forever trying to register '%s@%s'\n", r->regattempts, r->username, r->hostname); 13223 r->regstate = REG_STATE_FAILED; 13224 } else { 13225 r->regstate = REG_STATE_UNREGISTERED; 13226 transmit_register(r, SIP_REGISTER, NULL, NULL); 13227 ast_log(LOG_NOTICE, " -- Registration for '%s@%s' timed out, trying again (Attempt #%d)\n", r->username, r->hostname, r->regattempts); 13228 } 13229 manager_event(EVENT_FLAG_SYSTEM, "Registry", "ChannelType: SIP\r\nUsername: %s\r\nDomain: %s\r\nStatus: %s\r\n", r->username, r->hostname, regstate2str(r->regstate)); 13230 registry_unref(r, "unreffing registry_unref r"); 13231 return 0; 13232 }
| static int sip_register | ( | const char * | value, | |
| int | lineno | |||
| ) | [static] |
create sip_registry object from register=> line in sip.conf and link into reg container
Definition at line 8240 of file chan_sip.c.
References ast_atomic_fetchadd_int(), ast_calloc_with_stringfields, ast_log(), ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, LOG_ERROR, registry_unref(), regl, and sip_parse_register_line().
Referenced by build_peer(), and reload_config().
08241 { 08242 struct sip_registry *reg; 08243 08244 if (!(reg = ast_calloc_with_stringfields(1, struct sip_registry, 256))) { 08245 ast_log(LOG_ERROR, "Out of memory. Can't allocate SIP registry entry\n"); 08246 return -1; 08247 } 08248 08249 ast_atomic_fetchadd_int(®objs, 1); 08250 ASTOBJ_INIT(reg); 08251 08252 if (sip_parse_register_line(reg, default_expiry, value, lineno)) { 08253 registry_unref(reg, "failure to parse, unref the reg pointer"); 08254 return -1; 08255 } 08256 08257 /* set default expiry if necessary */ 08258 if (reg->refresh && !reg->expiry && !reg->configured_expiry) { 08259 reg->refresh = reg->expiry = reg->configured_expiry = default_expiry; 08260 } 08261 08262 /* Add the new registry entry to the list */ 08263 ASTOBJ_CONTAINER_LINK(®l, reg); 08264 08265 /* release the reference given by ASTOBJ_INIT. The container has another reference */ 08266 registry_unref(reg, "unref the reg pointer"); 08267 08268 return 0; 08269 }
| static void sip_register_tests | ( | void | ) | [static] |
SIP test registration.
Definition at line 30179 of file chan_sip.c.
References sip_config_parser_register_tests(), sip_dialplan_function_register_tests(), and sip_request_parser_register_tests().
Referenced by load_module().
30180 { 30181 sip_config_parser_register_tests(); 30182 sip_request_parser_register_tests(); 30183 sip_dialplan_function_register_tests(); 30184 }
| static void sip_registry_destroy | ( | struct sip_registry * | reg | ) | [static] |
Destroy registry object Objects created with the register= statement in static configuration.
Definition at line 5701 of file chan_sip.c.
References ast_atomic_fetchadd_int(), ast_debug, ast_free, AST_SCHED_DEL, ast_string_field_free_memory, dialog_unlink_all(), and registry_unref().
Referenced by registry_unref(), reload_config(), and unload_module().
05702 { 05703 /* Really delete */ 05704 ast_debug(3, "Destroying registry entry for %s@%s\n", reg->username, reg->hostname); 05705 05706 if (reg->call) { 05707 /* Clear registry before destroying to ensure 05708 we don't get reentered trying to grab the registry lock */ 05709 reg->call->registry = registry_unref(reg->call->registry, "destroy reg->call->registry"); 05710 ast_debug(3, "Destroying active SIP dialog for registry %s@%s\n", reg->username, reg->hostname); 05711 dialog_unlink_all(reg->call); 05712 reg->call = dialog_unref(reg->call, "unref reg->call"); 05713 /* reg->call = sip_destroy(reg->call); */ 05714 } 05715 AST_SCHED_DEL(sched, reg->expire); 05716 AST_SCHED_DEL(sched, reg->timeout); 05717 05718 ast_string_field_free_memory(reg); 05719 ast_atomic_fetchadd_int(®objs, -1); 05720 ast_free(reg); 05721 }
| static int sip_reinvite_retry | ( | const void * | data | ) | [static] |
Reset the NEEDREINVITE flag after waiting when we get 491 on a Re-invite to avoid race conditions between asterisk servers. Called from the scheduler.
Definition at line 19915 of file chan_sip.c.
References ast_channel_trylock, ast_channel_unlock, ast_set_flag, check_pendings(), sip_pvt_lock, and sip_pvt_unlock.
Referenced by handle_response_invite(), and sip_show_sched().
19916 { 19917 struct sip_pvt *p = (struct sip_pvt *) data; 19918 struct ast_channel *owner; 19919 19920 sip_pvt_lock(p); /* called from schedule thread which requires a lock */ 19921 while ((owner = p->owner) && ast_channel_trylock(owner)) { 19922 sip_pvt_unlock(p); 19923 usleep(1); 19924 sip_pvt_lock(p); 19925 } 19926 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 19927 p->waitid = -1; 19928 check_pendings(p); 19929 sip_pvt_unlock(p); 19930 if (owner) { 19931 ast_channel_unlock(owner); 19932 } 19933 dialog_unref(p, "unref the dialog ptr from sip_reinvite_retry, because it held a dialog ptr"); 19934 return 0; 19935 }
| static char * sip_reload | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Force reload of module from cli.
Definition at line 29941 of file chan_sip.c.
References ast_mutex_lock, ast_mutex_unlock, ast_verbose, CHANNEL_CLI_RELOAD, CHANNEL_MODULE_RELOAD, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, restart_monitor(), TRUE, and ast_cli_entry::usage.
Referenced by reload().
29942 { 29943 29944 switch (cmd) { 29945 case CLI_INIT: 29946 e->command = "sip reload"; 29947 e->usage = 29948 "Usage: sip reload\n" 29949 " Reloads SIP configuration from sip.conf\n"; 29950 return NULL; 29951 case CLI_GENERATE: 29952 return NULL; 29953 } 29954 29955 ast_mutex_lock(&sip_reload_lock); 29956 if (sip_reloading) { 29957 ast_verbose("Previous SIP reload not yet done\n"); 29958 } else { 29959 sip_reloading = TRUE; 29960 sip_reloadreason = (a && a->fd) ? CHANNEL_CLI_RELOAD : CHANNEL_MODULE_RELOAD; 29961 } 29962 ast_mutex_unlock(&sip_reload_lock); 29963 restart_monitor(); 29964 29965 return CLI_SUCCESS; 29966 }
| static int sip_removeheader | ( | struct ast_channel * | chan, | |
| const char * | data | |||
| ) | [static] |
Remove SIP headers added previously with SipAddHeader application.
Definition at line 29690 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, AST_LIST_REMOVE_CURRENT, AST_LIST_TRAVERSE_SAFE_BEGIN, AST_LIST_TRAVERSE_SAFE_END, ast_strlen_zero(), ast_var_delete(), ast_var_name(), ast_var_value(), inbuf(), and ast_channel::varshead.
Referenced by load_module().
29691 { 29692 struct ast_var_t *newvariable; 29693 struct varshead *headp; 29694 int removeall = 0; 29695 char *inbuf = (char *) data; 29696 29697 if (ast_strlen_zero(inbuf)) { 29698 removeall = 1; 29699 } 29700 ast_channel_lock(chan); 29701 29702 headp=&chan->varshead; 29703 AST_LIST_TRAVERSE_SAFE_BEGIN (headp, newvariable, entries) { 29704 if (strncasecmp(ast_var_name(newvariable), "SIPADDHEADER", strlen("SIPADDHEADER")) == 0) { 29705 if (removeall || (!strncasecmp(ast_var_value(newvariable),inbuf,strlen(inbuf)))) { 29706 if (sipdebug) 29707 ast_debug(1,"removing SIP Header \"%s\" as %s\n", 29708 ast_var_value(newvariable), 29709 ast_var_name(newvariable)); 29710 AST_LIST_REMOVE_CURRENT(entries); 29711 ast_var_delete(newvariable); 29712 } 29713 } 29714 } 29715 AST_LIST_TRAVERSE_SAFE_END; 29716 29717 ast_channel_unlock(chan); 29718 return 0; 29719 }
| static struct ast_channel * sip_request_call | ( | const char * | type, | |
| format_t | format, | |||
| const struct ast_channel * | requestor, | |||
| void * | data, | |||
| int * | cause | |||
| ) | [static, read] |
PBX interface function -build SIP pvt structure SIP calls initiated by the PBX arrive here.
* SIP Dial string syntax * SIP/exten@host!dnid * or SIP/host/exten!dnid * or SIP/host!dnid *
Definition at line 26623 of file chan_sip.c.
References args, AST_APP_ARG, ast_calloc, AST_CAUSE_BEARERCAPABILITY_NOTAVAIL, AST_CAUSE_CHANNEL_UNACCEPTABLE, AST_CAUSE_SWITCH_CONGESTION, AST_CAUSE_UNREGISTERED, ast_channel_unlock, ast_copy_string(), ast_debug, AST_DECLARE_APP_ARGS, AST_FORMAT_AUDIO_MASK, ast_getformatname(), ast_getformatname_multiple(), ast_log(), AST_NONSTANDARD_APP_ARGS, ast_sip_ouraddrfor(), ast_sockaddr_port, ast_sockaddr_resolve_first_transport(), ast_sockaddr_set_port, AST_STATE_DOWN, ast_string_field_set, ast_strlen_zero(), ast_update_use_count(), build_via(), change_callid_pvt(), create_addr(), dialog_unlink_all(), EVENT_FLAG_SYSTEM, ext, exten, LOG_ERROR, LOG_NOTICE, LOG_WARNING, manager_event, restart_monitor(), secret, set_socket_transport(), sip_alloc(), sip_cfg, sip_new(), sip_pvt_lock, sip_pvt_unlock, and TRUE.
26624 { 26625 struct sip_pvt *p; 26626 struct ast_channel *tmpc = NULL; 26627 char *ext = NULL, *host; 26628 char tmp[256]; 26629 char *dest = data; 26630 char *dnid; 26631 char *secret = NULL; 26632 char *md5secret = NULL; 26633 char *authname = NULL; 26634 char *trans = NULL; 26635 char dialstring[256]; 26636 char *remote_address; 26637 enum sip_transport transport = 0; 26638 struct ast_sockaddr remote_address_sa = { {0,} }; 26639 format_t oldformat = format; 26640 AST_DECLARE_APP_ARGS(args, 26641 AST_APP_ARG(peerorhost); 26642 AST_APP_ARG(exten); 26643 AST_APP_ARG(remote_address); 26644 ); 26645 26646 /* mask request with some set of allowed formats. 26647 * XXX this needs to be fixed. 26648 * The original code uses AST_FORMAT_AUDIO_MASK, but it is 26649 * unclear what to use here. We have global_capabilities, which is 26650 * configured from sip.conf, and sip_tech.capabilities, which is 26651 * hardwired to all audio formats. 26652 */ 26653 format &= AST_FORMAT_AUDIO_MASK; 26654 if (!format) { 26655 ast_log(LOG_NOTICE, "Asked to get a channel of unsupported format %s while capability is %s\n", ast_getformatname(oldformat), ast_getformatname(sip_cfg.capability)); 26656 *cause = AST_CAUSE_BEARERCAPABILITY_NOTAVAIL; /* Can't find codec to connect to host */ 26657 return NULL; 26658 } 26659 ast_debug(1, "Asked to create a SIP channel with formats: %s\n", ast_getformatname_multiple(tmp, sizeof(tmp), oldformat)); 26660 26661 if (ast_strlen_zero(dest)) { 26662 ast_log(LOG_ERROR, "Unable to create channel with empty destination.\n"); 26663 *cause = AST_CAUSE_CHANNEL_UNACCEPTABLE; 26664 return NULL; 26665 } 26666 26667 if (!(p = sip_alloc(NULL, NULL, 0, SIP_INVITE, NULL))) { 26668 ast_log(LOG_ERROR, "Unable to build sip pvt data for '%s' (Out of memory or socket error)\n", dest); 26669 *cause = AST_CAUSE_SWITCH_CONGESTION; 26670 return NULL; 26671 } 26672 26673 p->outgoing_call = TRUE; 26674 26675 snprintf(dialstring, sizeof(dialstring), "%s/%s", type, dest); 26676 ast_string_field_set(p, dialstring, dialstring); 26677 26678 if (!(p->options = ast_calloc(1, sizeof(*p->options)))) { 26679 dialog_unlink_all(p); 26680 dialog_unref(p, "unref dialog p from mem fail"); 26681 /* sip_destroy(p); */ 26682 ast_log(LOG_ERROR, "Unable to build option SIP data structure - Out of memory\n"); 26683 *cause = AST_CAUSE_SWITCH_CONGESTION; 26684 return NULL; 26685 } 26686 26687 /* Save the destination, the SIP dial string */ 26688 ast_copy_string(tmp, dest, sizeof(tmp)); 26689 26690 /* Find DNID and take it away */ 26691 dnid = strchr(tmp, '!'); 26692 if (dnid != NULL) { 26693 *dnid++ = '\0'; 26694 ast_string_field_set(p, todnid, dnid); 26695 } 26696 26697 /* Divvy up the items separated by slashes */ 26698 AST_NONSTANDARD_APP_ARGS(args, tmp, '/'); 26699 26700 /* Find at sign - @ */ 26701 host = strchr(args.peerorhost, '@'); 26702 if (host) { 26703 *host++ = '\0'; 26704 ext = args.peerorhost; 26705 secret = strchr(ext, ':'); 26706 } 26707 if (secret) { 26708 *secret++ = '\0'; 26709 md5secret = strchr(secret, ':'); 26710 } 26711 if (md5secret) { 26712 *md5secret++ = '\0'; 26713 authname = strchr(md5secret, ':'); 26714 } 26715 if (authname) { 26716 *authname++ = '\0'; 26717 trans = strchr(authname, ':'); 26718 } 26719 if (trans) { 26720 *trans++ = '\0'; 26721 if (!strcasecmp(trans, "tcp")) 26722 transport = SIP_TRANSPORT_TCP; 26723 else if (!strcasecmp(trans, "tls")) 26724 transport = SIP_TRANSPORT_TLS; 26725 else { 26726 if (strcasecmp(trans, "udp")) 26727 ast_log(LOG_WARNING, "'%s' is not a valid transport option to Dial() for SIP calls, using udp by default.\n", trans); 26728 transport = SIP_TRANSPORT_UDP; 26729 } 26730 } else { /* use default */ 26731 transport = SIP_TRANSPORT_UDP; 26732 } 26733 26734 if (!host) { 26735 ext = args.exten; 26736 host = args.peerorhost; 26737 remote_address = args.remote_address; 26738 } else { 26739 remote_address = args.remote_address; 26740 if (!ast_strlen_zero(args.exten)) { 26741 ast_log(LOG_NOTICE, "Conflicting extension values given. Using '%s' and not '%s'\n", ext, args.exten); 26742 } 26743 } 26744 26745 if (!ast_strlen_zero(remote_address)) { 26746 if (ast_sockaddr_resolve_first_transport(&remote_address_sa, remote_address, 0, transport)) { 26747 ast_log(LOG_WARNING, "Unable to find IP address for host %s. We will not use this remote IP address\n", remote_address); 26748 } else { 26749 if (!ast_sockaddr_port(&remote_address_sa)) { 26750 ast_sockaddr_set_port(&remote_address_sa, 26751 transport & SIP_TRANSPORT_TLS ? 26752 STANDARD_TLS_PORT : 26753 STANDARD_SIP_PORT); 26754 } 26755 } 26756 } 26757 26758 set_socket_transport(&p->socket, transport); 26759 26760 /* We now have 26761 host = peer name, DNS host name or DNS domain (for SRV) 26762 ext = extension (user part of URI) 26763 dnid = destination of the call (applies to the To: header) 26764 */ 26765 if (create_addr(p, host, NULL, 1, &remote_address_sa)) { 26766 *cause = AST_CAUSE_UNREGISTERED; 26767 ast_debug(3, "Cant create SIP call - target device not registered\n"); 26768 dialog_unlink_all(p); 26769 dialog_unref(p, "unref dialog p UNREGISTERED"); 26770 /* sip_destroy(p); */ 26771 return NULL; 26772 } 26773 if (ast_strlen_zero(p->peername) && ext) 26774 ast_string_field_set(p, peername, ext); 26775 /* Recalculate our side, and recalculate Call ID */ 26776 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 26777 build_via(p); 26778 26779 /* Change the dialog callid. */ 26780 change_callid_pvt(p, NULL); 26781 26782 /* We have an extension to call, don't use the full contact here */ 26783 /* This to enable dialing registered peers with extension dialling, 26784 like SIP/peername/extension 26785 SIP/peername will still use the full contact 26786 */ 26787 if (ext) { 26788 ast_string_field_set(p, username, ext); 26789 ast_string_field_set(p, fullcontact, NULL); 26790 } 26791 if (secret && !ast_strlen_zero(secret)) 26792 ast_string_field_set(p, peersecret, secret); 26793 26794 if (md5secret && !ast_strlen_zero(md5secret)) 26795 ast_string_field_set(p, peermd5secret, md5secret); 26796 26797 if (authname && !ast_strlen_zero(authname)) 26798 ast_string_field_set(p, authname, authname); 26799 #if 0 26800 printf("Setting up to call extension '%s' at '%s'\n", ext ? ext : "<none>", host); 26801 #endif 26802 p->prefcodec = oldformat; /* Format for this call */ 26803 p->jointcapability = oldformat & p->capability; 26804 sip_pvt_lock(p); 26805 tmpc = sip_new(p, AST_STATE_DOWN, host, requestor ? requestor->linkedid : NULL); /* Place the call */ 26806 if (sip_cfg.callevents) 26807 manager_event(EVENT_FLAG_SYSTEM, "ChannelUpdate", 26808 "Channel: %s\r\nChanneltype: %s\r\nSIPcallid: %s\r\nSIPfullcontact: %s\r\nPeername: %s\r\n", 26809 p->owner? p->owner->name : "", "SIP", p->callid, p->fullcontact, p->peername); 26810 sip_pvt_unlock(p); 26811 if (!tmpc) { 26812 dialog_unlink_all(p); 26813 /* sip_destroy(p); */ 26814 } else { 26815 ast_channel_unlock(tmpc); 26816 } 26817 dialog_unref(p, "toss pvt ptr at end of sip_request_call"); 26818 ast_update_use_count(); 26819 restart_monitor(); 26820 return tmpc; 26821 }
| static int sip_reregister | ( | const void * | data | ) | [static] |
Update registration with SIP Proxy. Called from the scheduler when the previous registration expires, so we don't have to cancel the pending event. We assume the reference so the sip_registry is valid, since it is stored in the scheduled event anyways.
Definition at line 13135 of file chan_sip.c.
References __sip_do_register(), append_history, ast_log(), LOG_NOTICE, and registry_unref().
Referenced by handle_response_register(), sip_send_all_registers(), and sip_show_sched().
13136 { 13137 /* if we are here, we know that we need to reregister. */ 13138 struct sip_registry *r = (struct sip_registry *) data; 13139 13140 /* if we couldn't get a reference to the registry object, punt */ 13141 if (!r) { 13142 return 0; 13143 } 13144 13145 if (r->call && r->call->do_history) { 13146 append_history(r->call, "RegistryRenew", "Account: %s@%s", r->username, r->hostname); 13147 } 13148 /* Since registry's are only added/removed by the the monitor thread, this 13149 may be overkill to reference/dereference at all here */ 13150 if (sipdebug) { 13151 ast_log(LOG_NOTICE, " -- Re-registration for %s@%s\n", r->username, r->hostname); 13152 } 13153 13154 r->expire = -1; 13155 r->expiry = r->configured_expiry; 13156 __sip_do_register(r); 13157 registry_unref(r, "unref the re-register scheduled event"); 13158 return 0; 13159 }
| static struct ast_frame* sip_rtp_read | ( | struct ast_channel * | ast, | |
| struct sip_pvt * | p, | |||
| int * | faxdetect | |||
| ) | [static, read] |
Read RTP from network.
Definition at line 7400 of file chan_sip.c.
References ast_debug, ast_dsp_free(), ast_dsp_process(), ast_dsp_set_features(), AST_FORMAT_AUDIO_MASK, AST_FORMAT_TEXT_MASK, AST_FORMAT_VIDEO_MASK, AST_FRAME_DTMF, AST_FRAME_DTMF_BEGIN, AST_FRAME_DTMF_END, AST_FRAME_VOICE, ast_frfree, ast_getformatname(), ast_null_frame, ast_rtp_instance_read(), ast_set_read_format(), ast_set_write_format(), ast_test_flag, ast_udptl_read(), ast_verbose, ast_frame_subclass::codec, ast_frame::data, ast_frame::datalen, DSP_FEATURE_DIGIT_DETECT, f, ast_channel::fdno, ast_frame::frametype, ast_frame_subclass::integer, ast_frame::ptr, and ast_frame::subclass.
Referenced by sip_read().
07401 { 07402 /* Retrieve audio/etc from channel. Assumes p->lock is already held. */ 07403 struct ast_frame *f; 07404 07405 if (!p->rtp) { 07406 /* We have no RTP allocated for this channel */ 07407 return &ast_null_frame; 07408 } 07409 07410 switch(ast->fdno) { 07411 case 0: 07412 f = ast_rtp_instance_read(p->rtp, 0); /* RTP Audio */ 07413 break; 07414 case 1: 07415 f = ast_rtp_instance_read(p->rtp, 1); /* RTCP Control Channel */ 07416 break; 07417 case 2: 07418 f = ast_rtp_instance_read(p->vrtp, 0); /* RTP Video */ 07419 break; 07420 case 3: 07421 f = ast_rtp_instance_read(p->vrtp, 1); /* RTCP Control Channel for video */ 07422 break; 07423 case 4: 07424 f = ast_rtp_instance_read(p->trtp, 0); /* RTP Text */ 07425 if (sipdebug_text) { 07426 int i; 07427 unsigned char* arr = f->data.ptr; 07428 for (i=0; i < f->datalen; i++) 07429 ast_verbose("%c", (arr[i] > ' ' && arr[i] < '}') ? arr[i] : '.'); 07430 ast_verbose(" -> "); 07431 for (i=0; i < f->datalen; i++) 07432 ast_verbose("%02X ", arr[i]); 07433 ast_verbose("\n"); 07434 } 07435 break; 07436 case 5: 07437 f = ast_udptl_read(p->udptl); /* UDPTL for T.38 */ 07438 break; 07439 default: 07440 f = &ast_null_frame; 07441 } 07442 /* Don't forward RFC2833 if we're not supposed to */ 07443 if (f && (f->frametype == AST_FRAME_DTMF_BEGIN || f->frametype == AST_FRAME_DTMF_END) && 07444 (ast_test_flag(&p->flags[0], SIP_DTMF) != SIP_DTMF_RFC2833)) { 07445 ast_debug(1, "Ignoring DTMF (%c) RTP frame because dtmfmode is not RFC2833\n", f->subclass.integer); 07446 ast_frfree(f); 07447 return &ast_null_frame; 07448 } 07449 07450 /* We already hold the channel lock */ 07451 if (!p->owner || (f && f->frametype != AST_FRAME_VOICE)) 07452 return f; 07453 07454 if (f && f->subclass.codec != (p->owner->nativeformats & AST_FORMAT_AUDIO_MASK)) { 07455 if (!(f->subclass.codec & p->jointcapability)) { 07456 ast_debug(1, "Bogus frame of format '%s' received from '%s'!\n", 07457 ast_getformatname(f->subclass.codec), p->owner->name); 07458 ast_frfree(f); 07459 return &ast_null_frame; 07460 } 07461 ast_debug(1, "Oooh, format changed to %s\n", 07462 ast_getformatname(f->subclass.codec)); 07463 p->owner->nativeformats = (p->owner->nativeformats & (AST_FORMAT_VIDEO_MASK | AST_FORMAT_TEXT_MASK)) | f->subclass.codec; 07464 ast_set_read_format(p->owner, p->owner->readformat); 07465 ast_set_write_format(p->owner, p->owner->writeformat); 07466 } 07467 07468 if (f && p->dsp) { 07469 f = ast_dsp_process(p->owner, p->dsp, f); 07470 if (f && f->frametype == AST_FRAME_DTMF) { 07471 if (f->subclass.integer == 'f') { 07472 ast_debug(1, "Fax CNG detected on %s\n", ast->name); 07473 *faxdetect = 1; 07474 /* If we only needed this DSP for fax detection purposes we can just drop it now */ 07475 if (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) { 07476 ast_dsp_set_features(p->dsp, DSP_FEATURE_DIGIT_DETECT); 07477 } else { 07478 ast_dsp_free(p->dsp); 07479 p->dsp = NULL; 07480 } 07481 } else { 07482 ast_debug(1, "* Detected inband DTMF '%c'\n", f->subclass.integer); 07483 } 07484 } 07485 } 07486 07487 return f; 07488 }
| static const char* sip_sanitized_host | ( | const char * | host | ) | [static] |
Definition at line 13234 of file chan_sip.c.
References ast_sockaddr_parse(), ast_sockaddr_stringify_host_remote(), and PARSE_PORT_FORBID.
Referenced by transmit_register().
13235 { 13236 struct ast_sockaddr addr = { { 0, 0, }, }; 13237 13238 /* peer/sip_pvt->tohost and sip_registry->hostname should never have a port 13239 * in them, so we use PARSE_PORT_FORBID here. If this lookup fails, we return 13240 * the original host which is most likely a host name and not an IP. */ 13241 if (!ast_sockaddr_parse(&addr, host, PARSE_PORT_FORBID)) { 13242 return host; 13243 } 13244 return ast_sockaddr_stringify_host_remote(&addr); 13245 }
| void sip_scheddestroy | ( | struct sip_pvt * | p, | |
| int | ms | |||
| ) |
Schedule destruction of SIP dialog.
Definition at line 3918 of file chan_sip.c.
References __sip_autodestruct(), append_history, ast_log(), ast_sched_add(), ast_verbose, LOG_WARNING, sip_cancel_destroy(), sip_debug_test_pvt(), sip_methods, stop_session_timer(), cfsip_methods::text, and TRUE.
Referenced by __sip_autodestruct(), auto_congest(), cb_extensionstate(), check_auth(), check_pendings(), handle_incoming(), handle_invite_replaces(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_notify(), handle_request_options(), handle_request_publish(), handle_request_register(), handle_request_subscribe(), handle_response_invite(), handle_response_register(), manager_sipnotify(), receive_message(), sip_cli_notify(), sip_hangup(), sip_scheddestroy_final(), sip_send_mwi_to_peer(), sip_sipredirect(), transmit_fake_auth_response(), and transmit_publish().
03919 { 03920 if (p->final_destruction_scheduled) { 03921 return; /* already set final destruction */ 03922 } 03923 03924 if (ms < 0) { 03925 if (p->timer_t1 == 0) { 03926 p->timer_t1 = global_t1; /* Set timer T1 if not set (RFC 3261) */ 03927 } 03928 if (p->timer_b == 0) { 03929 p->timer_b = global_timer_b; /* Set timer B if not set (RFC 3261) */ 03930 } 03931 ms = p->timer_t1 * 64; 03932 } 03933 if (sip_debug_test_pvt(p)) { 03934 ast_verbose("Scheduling destruction of SIP dialog '%s' in %d ms (Method: %s)\n", p->callid, ms, sip_methods[p->method].text); 03935 } 03936 if (sip_cancel_destroy(p)) { 03937 ast_log(LOG_WARNING, "Unable to cancel SIP destruction. Expect bad things.\n"); 03938 } 03939 03940 if (p->do_history) { 03941 append_history(p, "SchedDestroy", "%d ms", ms); 03942 } 03943 p->autokillid = ast_sched_add(sched, ms, __sip_autodestruct, dialog_ref(p, "setting ref as passing into ast_sched_add for __sip_autodestruct")); 03944 03945 if (p->stimer && p->stimer->st_active == TRUE && p->stimer->st_schedid > 0) { 03946 stop_session_timer(p); 03947 } 03948 }
| void sip_scheddestroy_final | ( | struct sip_pvt * | p, | |
| int | ms | |||
| ) |
Schedule final destruction of SIP dialog. This can not be canceled. This function is used to keep a dialog around for a period of time in order to properly respond to any retransmits.
Definition at line 3905 of file chan_sip.c.
References sip_scheddestroy().
Referenced by handle_request_bye().
03906 { 03907 if (p->final_destruction_scheduled) { 03908 return; /* already set final destruction */ 03909 } 03910 03911 sip_scheddestroy(p, ms); 03912 if (p->autokillid != -1) { 03913 p->final_destruction_scheduled = 1; 03914 } 03915 }
| static void sip_send_all_mwi_subscriptions | ( | void | ) | [static] |
Send all MWI subscriptions.
Definition at line 29845 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_REF, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, sip_subscribe_mwi_destroy(), sip_subscribe_mwi_do(), and submwil.
Referenced by load_module(), network_change_event_sched_cb(), and sip_do_reload().
29846 { 29847 ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do { 29848 struct sip_subscription_mwi *saved; 29849 ASTOBJ_WRLOCK(iterator); 29850 AST_SCHED_DEL(sched, iterator->resub); 29851 saved = ASTOBJ_REF(iterator); 29852 if ((iterator->resub = ast_sched_add(sched, 1, sip_subscribe_mwi_do, saved)) < 0) { 29853 ASTOBJ_UNREF(saved, sip_subscribe_mwi_destroy); 29854 } 29855 ASTOBJ_UNLOCK(iterator); 29856 } while (0)); 29857 }
| static void sip_send_all_registers | ( | void | ) | [static] |
Send all known registrations.
Definition at line 29821 of file chan_sip.c.
References AST_SCHED_REPLACE_UNREF, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_WRLOCK, registry_addref(), registry_unref(), regl, and sip_reregister().
Referenced by load_module(), network_change_event_sched_cb(), and sip_do_reload().
29822 { 29823 int ms; 29824 int regspacing; 29825 if (!regobjs) 29826 return; 29827 regspacing = default_expiry * 1000/regobjs; 29828 if (regspacing > 100) { 29829 regspacing = 100; 29830 } 29831 ms = regspacing; 29832 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 29833 ASTOBJ_WRLOCK(iterator); 29834 ms += regspacing; 29835 AST_SCHED_REPLACE_UNREF(iterator->expire, sched, ms, sip_reregister, iterator, 29836 registry_unref(_data, "REPLACE sched del decs the refcount"), 29837 registry_unref(iterator, "REPLACE sched add failure decs the refcount"), 29838 registry_addref(iterator, "REPLACE sched add incs the refcount")); 29839 ASTOBJ_UNLOCK(iterator); 29840 } while (0) 29841 ); 29842 }
| static int sip_send_mwi_to_peer | ( | struct sip_peer * | peer, | |
| int | cache_only | |||
| ) | [static] |
Send message waiting indication to alert peer that they've got voicemail.
Definition at line 25779 of file chan_sip.c.
References ao2_lock, ao2_unlock, ast_app_inboxcount(), ast_set_flag, ast_sip_ouraddrfor(), ast_sockaddr_isnull(), ast_str_alloca, ast_strdupa, ast_string_field_set, ast_strlen_zero(), ast_test_flag, build_via(), change_callid_pvt(), create_addr_from_peer(), dialog_unlink_all(), get_cached_mwi(), peer_mailboxes_to_str(), set_socket_transport(), sip_alloc(), sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), transmit_notify_with_mwi(), and update_peer_lastmsgssent().
Referenced by build_peer(), handle_request_subscribe(), mwi_event_cb(), and register_verify().
25780 { 25781 /* Called with peer lock, but releases it */ 25782 struct sip_pvt *p; 25783 int newmsgs = 0, oldmsgs = 0; 25784 const char *vmexten = NULL; 25785 25786 ao2_lock(peer); 25787 25788 if (peer->vmexten) { 25789 vmexten = ast_strdupa(peer->vmexten); 25790 } 25791 25792 if (ast_test_flag((&peer->flags[1]), SIP_PAGE2_SUBSCRIBEMWIONLY) && !peer->mwipvt) { 25793 update_peer_lastmsgssent(peer, -1, 1); 25794 ao2_unlock(peer); 25795 return 0; 25796 } 25797 25798 /* Do we have an IP address? If not, skip this peer */ 25799 if (ast_sockaddr_isnull(&peer->addr) && ast_sockaddr_isnull(&peer->defaddr)) { 25800 update_peer_lastmsgssent(peer, -1, 1); 25801 ao2_unlock(peer); 25802 return 0; 25803 } 25804 25805 /* Attempt to use cached mwi to get message counts. */ 25806 if (!get_cached_mwi(peer, &newmsgs, &oldmsgs) && !cache_only) { 25807 /* Fall back to manually checking the mailbox if not cache_only and get_cached_mwi failed */ 25808 struct ast_str *mailbox_str = ast_str_alloca(512); 25809 peer_mailboxes_to_str(&mailbox_str, peer); 25810 ao2_unlock(peer); 25811 /* If there is no mailbox do nothing */ 25812 if (ast_strlen_zero(mailbox_str->str)) { 25813 update_peer_lastmsgssent(peer, -1, 0); 25814 return 0; 25815 } 25816 ast_app_inboxcount(mailbox_str->str, &newmsgs, &oldmsgs); 25817 ao2_lock(peer); 25818 } 25819 25820 if (peer->mwipvt) { 25821 /* Base message on subscription */ 25822 p = dialog_ref(peer->mwipvt, "sip_send_mwi_to_peer: Setting dialog ptr p from peer->mwipvt"); 25823 ao2_unlock(peer); 25824 } else { 25825 ao2_unlock(peer); 25826 /* Build temporary dialog for this message */ 25827 if (!(p = sip_alloc(NULL, NULL, 0, SIP_NOTIFY, NULL))) { 25828 update_peer_lastmsgssent(peer, -1, 0); 25829 return -1; 25830 } 25831 25832 /* If we don't set the socket type to 0, then create_addr_from_peer will fail immediately if the peer 25833 * uses any transport other than UDP. We set the type to 0 here and then let create_addr_from_peer copy 25834 * the peer's socket information to the sip_pvt we just allocated 25835 */ 25836 set_socket_transport(&p->socket, 0); 25837 if (create_addr_from_peer(p, peer)) { 25838 /* Maybe they're not registered, etc. */ 25839 dialog_unlink_all(p); 25840 dialog_unref(p, "unref dialog p just created via sip_alloc"); 25841 update_peer_lastmsgssent(peer, -1, 0); 25842 return 0; 25843 } 25844 /* Recalculate our side, and recalculate Call ID */ 25845 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 25846 build_via(p); 25847 25848 ao2_lock(peer); 25849 if (!ast_strlen_zero(peer->mwi_from)) { 25850 ast_string_field_set(p, mwi_from, peer->mwi_from); 25851 } else if (!ast_strlen_zero(default_mwi_from)) { 25852 ast_string_field_set(p, mwi_from, default_mwi_from); 25853 } 25854 ao2_unlock(peer); 25855 25856 /* Change the dialog callid. */ 25857 change_callid_pvt(p, NULL); 25858 25859 /* Destroy this session after 32 secs */ 25860 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 25861 } 25862 25863 /* We have multiple threads (mwi events and monitor retransmits) working with this PVT and as we modify the sip history if that's turned on, 25864 we really need to have a lock on it */ 25865 sip_pvt_lock(p); 25866 25867 /* Send MWI */ 25868 ast_set_flag(&p->flags[0], SIP_OUTGOING); 25869 /* the following will decrement the refcount on p as it finishes */ 25870 transmit_notify_with_mwi(p, newmsgs, oldmsgs, vmexten); 25871 sip_pvt_unlock(p); 25872 dialog_unref(p, "unref dialog ptr p just before it goes out of scope at the end of sip_send_mwi_to_peer."); 25873 25874 update_peer_lastmsgssent(peer, ((newmsgs > 0x7fff ? 0x7fff0000 : (newmsgs << 16)) | (oldmsgs > 0xffff ? 0xffff : oldmsgs)), 0); 25875 25876 return 0; 25877 }
| static int sip_senddigit_begin | ( | struct ast_channel * | ast, | |
| char | digit | |||
| ) | [static] |
Definition at line 6651 of file chan_sip.c.
References ast_rtp_instance_dtmf_begin(), ast_test_flag, sip_pvt_lock, sip_pvt_unlock, and ast_channel::tech_pvt.
06652 { 06653 struct sip_pvt *p = ast->tech_pvt; 06654 int res = 0; 06655 06656 sip_pvt_lock(p); 06657 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 06658 case SIP_DTMF_INBAND: 06659 res = -1; /* Tell Asterisk to generate inband indications */ 06660 break; 06661 case SIP_DTMF_RFC2833: 06662 if (p->rtp) 06663 ast_rtp_instance_dtmf_begin(p->rtp, digit); 06664 break; 06665 default: 06666 break; 06667 } 06668 sip_pvt_unlock(p); 06669 06670 return res; 06671 }
| static int sip_senddigit_end | ( | struct ast_channel * | ast, | |
| char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Send DTMF character on SIP channel within one call, we're able to transmit in many methods simultaneously.
Definition at line 6675 of file chan_sip.c.
References ast_rtp_instance_dtmf_end_with_duration(), ast_test_flag, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and transmit_info_with_digit().
06676 { 06677 struct sip_pvt *p = ast->tech_pvt; 06678 int res = 0; 06679 06680 sip_pvt_lock(p); 06681 switch (ast_test_flag(&p->flags[0], SIP_DTMF)) { 06682 case SIP_DTMF_INFO: 06683 case SIP_DTMF_SHORTINFO: 06684 transmit_info_with_digit(p, digit, duration); 06685 break; 06686 case SIP_DTMF_RFC2833: 06687 if (p->rtp) 06688 ast_rtp_instance_dtmf_end_with_duration(p->rtp, digit, duration); 06689 break; 06690 case SIP_DTMF_INBAND: 06691 res = -1; /* Tell Asterisk to stop inband indications */ 06692 break; 06693 } 06694 sip_pvt_unlock(p); 06695 06696 return res; 06697 }
| static int sip_sendhtml | ( | struct ast_channel * | chan, | |
| int | subclass, | |||
| const char * | data, | |||
| int | datalen | |||
| ) | [static] |
Send message with Access-URL header, if this is an HTML URL only!
Definition at line 4424 of file chan_sip.c.
References ast_channel::_state, ast_debug, AST_HTML_URL, ast_log(), ast_set_flag, AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_string_field_build, ast_test_flag, FALSE, LOG_WARNING, sip_debug_test_pvt(), ast_channel::tech_pvt, transmit_reinvite_with_sdp(), transmit_response(), and url.
04425 { 04426 struct sip_pvt *p = chan->tech_pvt; 04427 04428 if (subclass != AST_HTML_URL) 04429 return -1; 04430 04431 ast_string_field_build(p, url, "<%s>;mode=active", data); 04432 04433 if (sip_debug_test_pvt(p)) 04434 ast_debug(1, "Send URL %s, state = %d!\n", data, chan->_state); 04435 04436 switch (chan->_state) { 04437 case AST_STATE_RING: 04438 transmit_response(p, "100 Trying", &p->initreq); 04439 break; 04440 case AST_STATE_RINGING: 04441 transmit_response(p, "180 Ringing", &p->initreq); 04442 break; 04443 case AST_STATE_UP: 04444 if (!p->pendinginvite) { /* We are up, and have no outstanding invite */ 04445 transmit_reinvite_with_sdp(p, FALSE, FALSE); 04446 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 04447 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 04448 } 04449 break; 04450 default: 04451 ast_log(LOG_WARNING, "Don't know how to send URI when state is %d!\n", chan->_state); 04452 } 04453 04454 return 0; 04455 }
| static int sip_sendtext | ( | struct ast_channel * | ast, | |
| const char * | text | |||
| ) | [static] |
Definition at line 4468 of file chan_sip.c.
References ast_debug, ast_verbose, is_method_allowed(), sip_debug_test_pvt(), ast_channel::tech_pvt, and transmit_message_with_text().
04469 { 04470 struct sip_pvt *dialog = ast->tech_pvt; 04471 int debug; 04472 04473 if (!dialog) { 04474 return -1; 04475 } 04476 /* NOT ast_strlen_zero, because a zero-length message is specifically 04477 * allowed by RFC 3428 (See section 10, Examples) */ 04478 if (!text) { 04479 return 0; 04480 } 04481 if(!is_method_allowed(&dialog->allowed_methods, SIP_MESSAGE)) { 04482 ast_debug(2, "Trying to send MESSAGE to device that does not support it.\n"); 04483 return(0); 04484 } 04485 04486 debug = sip_debug_test_pvt(dialog); 04487 if (debug) { 04488 ast_verbose("Sending text %s on %s\n", text, ast->name); 04489 } 04490 04491 transmit_message_with_text(dialog, text); 04492 return 0; 04493 }
| static char * sip_set_history | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Enable/Disable SIP History logging (CLI).
Definition at line 19175 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, FALSE, ast_cli_args::fd, TRUE, and ast_cli_entry::usage.
19176 { 19177 switch (cmd) { 19178 case CLI_INIT: 19179 e->command = "sip set history {on|off}"; 19180 e->usage = 19181 "Usage: sip set history {on|off}\n" 19182 " Enables/Disables recording of SIP dialog history for debugging purposes.\n" 19183 " Use 'sip show history' to view the history of a call number.\n"; 19184 return NULL; 19185 case CLI_GENERATE: 19186 return NULL; 19187 } 19188 19189 if (a->argc != e->args) 19190 return CLI_SHOWUSAGE; 19191 19192 if (!strncasecmp(a->argv[e->args - 1], "on", 2)) { 19193 recordhistory = TRUE; 19194 ast_cli(a->fd, "SIP History Recording Enabled (use 'sip show history')\n"); 19195 } else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) { 19196 recordhistory = FALSE; 19197 ast_cli(a->fd, "SIP History Recording Disabled\n"); 19198 } else { 19199 return CLI_SHOWUSAGE; 19200 } 19201 return CLI_SUCCESS; 19202 }
| static void sip_set_redirstr | ( | struct sip_pvt * | p, | |
| char * | reason | |||
| ) | [static] |
Translate referring cause.
Definition at line 15091 of file chan_sip.c.
References ast_string_field_set.
Referenced by get_rdnis().
15091 { 15092 15093 if (!strcmp(reason, "unknown")) { 15094 ast_string_field_set(p, redircause, "UNKNOWN"); 15095 } else if (!strcmp(reason, "user-busy")) { 15096 ast_string_field_set(p, redircause, "BUSY"); 15097 } else if (!strcmp(reason, "no-answer")) { 15098 ast_string_field_set(p, redircause, "NOANSWER"); 15099 } else if (!strcmp(reason, "unavailable")) { 15100 ast_string_field_set(p, redircause, "UNREACHABLE"); 15101 } else if (!strcmp(reason, "unconditional")) { 15102 ast_string_field_set(p, redircause, "UNCONDITIONAL"); 15103 } else if (!strcmp(reason, "time-of-day")) { 15104 ast_string_field_set(p, redircause, "UNKNOWN"); 15105 } else if (!strcmp(reason, "do-not-disturb")) { 15106 ast_string_field_set(p, redircause, "UNKNOWN"); 15107 } else if (!strcmp(reason, "deflection")) { 15108 ast_string_field_set(p, redircause, "UNKNOWN"); 15109 } else if (!strcmp(reason, "follow-me")) { 15110 ast_string_field_set(p, redircause, "UNKNOWN"); 15111 } else if (!strcmp(reason, "out-of-service")) { 15112 ast_string_field_set(p, redircause, "UNREACHABLE"); 15113 } else if (!strcmp(reason, "away")) { 15114 ast_string_field_set(p, redircause, "UNREACHABLE"); 15115 } else { 15116 ast_string_field_set(p, redircause, "UNKNOWN"); 15117 } 15118 }
| 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, | |||
| format_t | codecs, | |||
| int | nat_active | |||
| ) | [static] |
Definition at line 29455 of file chan_sip.c.
References ast_channel::_state, append_history, ast_bridged_channel(), ast_channel_lock, ast_channel_set_fd(), ast_channel_unlock, ast_debug, ast_rtp_instance_fd(), ast_rtp_instance_get_and_cmp_remote_address(), ast_rtp_instance_set_prop(), AST_RTP_PROPERTY_RTCP, ast_set_flag, ast_sockaddr_isnull(), ast_sockaddr_stringify(), AST_STATE_UP, ast_test_flag, FALSE, sip_cfg, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, and transmit_reinvite_with_sdp().
Referenced by sip_fixup().
29456 { 29457 struct sip_pvt *p; 29458 int changed = 0; 29459 29460 /* Lock the channel and the private safely. */ 29461 ast_channel_lock(chan); 29462 p = chan->tech_pvt; 29463 if (!p) { 29464 ast_channel_unlock(chan); 29465 return -1; 29466 } 29467 sip_pvt_lock(p); 29468 if (p->owner != chan) { 29469 /* I suppose it could be argued that if this happens it is a bug. */ 29470 ast_debug(1, "The private is not owned by channel %s anymore.\n", chan->name); 29471 sip_pvt_unlock(p); 29472 ast_channel_unlock(chan); 29473 return 0; 29474 } 29475 29476 /* Disable early RTP bridge */ 29477 if ((instance || vinstance || tinstance) && 29478 !ast_bridged_channel(chan) && 29479 !sip_cfg.directrtpsetup) { 29480 sip_pvt_unlock(p); 29481 ast_channel_unlock(chan); 29482 return 0; 29483 } 29484 29485 if (p->alreadygone) { 29486 /* If we're destroyed, don't bother */ 29487 sip_pvt_unlock(p); 29488 ast_channel_unlock(chan); 29489 return 0; 29490 } 29491 29492 /* if this peer cannot handle reinvites of the media stream to devices 29493 that are known to be behind a NAT, then stop the process now 29494 */ 29495 if (nat_active && !ast_test_flag(&p->flags[0], SIP_DIRECT_MEDIA_NAT)) { 29496 sip_pvt_unlock(p); 29497 ast_channel_unlock(chan); 29498 return 0; 29499 } 29500 29501 if (instance) { 29502 changed |= ast_rtp_instance_get_and_cmp_remote_address(instance, &p->redirip); 29503 29504 if (p->rtp) { 29505 /* Prevent audio RTCP reads */ 29506 ast_channel_set_fd(chan, 1, -1); 29507 /* Silence RTCP while audio RTP is inactive */ 29508 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 0); 29509 } 29510 } else if (!ast_sockaddr_isnull(&p->redirip)) { 29511 memset(&p->redirip, 0, sizeof(p->redirip)); 29512 changed = 1; 29513 29514 if (p->rtp) { 29515 /* Enable RTCP since it will be inactive if we're coming back 29516 * from a reinvite */ 29517 ast_rtp_instance_set_prop(p->rtp, AST_RTP_PROPERTY_RTCP, 1); 29518 /* Enable audio RTCP reads */ 29519 ast_channel_set_fd(chan, 1, ast_rtp_instance_fd(p->rtp, 1)); 29520 } 29521 } 29522 29523 if (vinstance) { 29524 changed |= ast_rtp_instance_get_and_cmp_remote_address(vinstance, &p->vredirip); 29525 29526 if (p->vrtp) { 29527 /* Prevent video RTCP reads */ 29528 ast_channel_set_fd(chan, 3, -1); 29529 /* Silence RTCP while video RTP is inactive */ 29530 ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 0); 29531 } 29532 } else if (!ast_sockaddr_isnull(&p->vredirip)) { 29533 memset(&p->vredirip, 0, sizeof(p->vredirip)); 29534 changed = 1; 29535 29536 if (p->vrtp) { 29537 /* Enable RTCP since it will be inactive if we're coming back 29538 * from a reinvite */ 29539 ast_rtp_instance_set_prop(p->vrtp, AST_RTP_PROPERTY_RTCP, 1); 29540 /* Enable video RTCP reads */ 29541 ast_channel_set_fd(chan, 3, ast_rtp_instance_fd(p->vrtp, 1)); 29542 } 29543 } 29544 29545 if (tinstance) { 29546 changed |= ast_rtp_instance_get_and_cmp_remote_address(tinstance, &p->tredirip); 29547 } else if (!ast_sockaddr_isnull(&p->tredirip)) { 29548 memset(&p->tredirip, 0, sizeof(p->tredirip)); 29549 changed = 1; 29550 } 29551 if (codecs && (p->redircodecs != codecs)) { 29552 p->redircodecs = codecs; 29553 changed = 1; 29554 } 29555 if (changed && !ast_test_flag(&p->flags[0], SIP_GOTREFER) && !ast_test_flag(&p->flags[0], SIP_DEFER_BYE_ON_TRANSFER)) { 29556 if (chan->_state != AST_STATE_UP) { /* We are in early state */ 29557 if (p->do_history) 29558 append_history(p, "ExtInv", "Initial invite sent with remote bridge proposal."); 29559 ast_debug(1, "Early remote bridge setting SIP '%s' - Sending media to %s\n", p->callid, ast_sockaddr_stringify(instance ? &p->redirip : &p->ourip)); 29560 } else if (!p->pendinginvite) { /* We are up, and have no outstanding invite */ 29561 ast_debug(3, "Sending reinvite on SIP '%s' - It's audio soon redirected to IP %s\n", p->callid, ast_sockaddr_stringify(instance ? &p->redirip : &p->ourip)); 29562 transmit_reinvite_with_sdp(p, FALSE, FALSE); 29563 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 29564 ast_debug(3, "Deferring reinvite on SIP '%s' - It's audio will be redirected to IP %s\n", p->callid, ast_sockaddr_stringify(instance ? &p->redirip : &p->ourip)); 29565 /* We have a pending Invite. Send re-invite when we're done with the invite */ 29566 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 29567 } 29568 } 29569 /* Reset lastrtprx timer */ 29570 p->lastrtprx = p->lastrtptx = time(NULL); 29571 sip_pvt_unlock(p); 29572 ast_channel_unlock(chan); 29573 return 0; 29574 }
| static int sip_set_udptl_peer | ( | struct ast_channel * | chan, | |
| struct ast_udptl * | udptl | |||
| ) | [static] |
Definition at line 29265 of file chan_sip.c.
References ast_channel_lock, ast_channel_unlock, ast_debug, ast_set_flag, ast_sockaddr_stringify(), ast_test_flag, ast_udptl_get_peer(), FALSE, sip_pvt_lock, sip_pvt_unlock, ast_channel::tech_pvt, transmit_reinvite_with_sdp(), and TRUE.
29266 { 29267 struct sip_pvt *p; 29268 29269 /* Lock the channel and the private safely. */ 29270 ast_channel_lock(chan); 29271 p = chan->tech_pvt; 29272 if (!p) { 29273 ast_channel_unlock(chan); 29274 return -1; 29275 } 29276 sip_pvt_lock(p); 29277 if (p->owner != chan) { 29278 /* I suppose it could be argued that if this happens it is a bug. */ 29279 ast_debug(1, "The private is not owned by channel %s anymore.\n", chan->name); 29280 sip_pvt_unlock(p); 29281 ast_channel_unlock(chan); 29282 return 0; 29283 } 29284 29285 if (udptl) { 29286 ast_udptl_get_peer(udptl, &p->udptlredirip); 29287 } else { 29288 memset(&p->udptlredirip, 0, sizeof(p->udptlredirip)); 29289 } 29290 if (!ast_test_flag(&p->flags[0], SIP_GOTREFER)) { 29291 if (!p->pendinginvite) { 29292 ast_debug(3, "Sending reinvite on SIP '%s' - It's UDPTL soon redirected to IP %s\n", 29293 p->callid, ast_sockaddr_stringify(udptl ? &p->udptlredirip : &p->ourip)); 29294 transmit_reinvite_with_sdp(p, TRUE, FALSE); 29295 } else if (!ast_test_flag(&p->flags[0], SIP_PENDINGBYE)) { 29296 ast_debug(3, "Deferring reinvite on SIP '%s' - It's UDPTL will be redirected to IP %s\n", 29297 p->callid, ast_sockaddr_stringify(udptl ? &p->udptlredirip : &p->ourip)); 29298 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 29299 } 29300 } 29301 /* Reset lastrtprx timer */ 29302 p->lastrtprx = p->lastrtptx = time(NULL); 29303 sip_pvt_unlock(p); 29304 ast_channel_unlock(chan); 29305 return 0; 29306 }
| static int sip_setoption | ( | struct ast_channel * | chan, | |
| int | option, | |||
| void * | data, | |||
| int | datalen | |||
| ) | [static] |
Set an option on a SIP dialog.
Definition at line 4280 of file chan_sip.c.
References ast_debug, ast_log(), AST_OPTION_DIGIT_DETECT, AST_OPTION_FORMAT_READ, AST_OPTION_FORMAT_WRITE, AST_OPTION_MAKE_COMPATIBLE, AST_OPTION_SECURE_MEDIA, AST_OPTION_SECURE_SIGNALING, ast_rtp_instance_make_compatible(), ast_rtp_instance_set_read_format(), ast_rtp_instance_set_write_format(), ast_set2_flag, ast_test_flag, disable_dsp_detect(), enable_dsp_detect(), LOG_ERROR, sip_pvt_lock, sip_pvt_unlock, and ast_channel::tech_pvt.
04281 { 04282 int res = -1; 04283 struct sip_pvt *p = chan->tech_pvt; 04284 04285 if (!p) { 04286 ast_log(LOG_ERROR, "Attempt to Ref a null pointer. sip private structure is gone!\n"); 04287 return -1; 04288 } 04289 04290 sip_pvt_lock(p); 04291 04292 switch (option) { 04293 case AST_OPTION_FORMAT_READ: 04294 if (p->rtp) { 04295 res = ast_rtp_instance_set_read_format(p->rtp, *(int *) data); 04296 } 04297 break; 04298 case AST_OPTION_FORMAT_WRITE: 04299 if (p->rtp) { 04300 res = ast_rtp_instance_set_write_format(p->rtp, *(int *) data); 04301 } 04302 break; 04303 case AST_OPTION_MAKE_COMPATIBLE: 04304 if (p->rtp) { 04305 res = ast_rtp_instance_make_compatible(chan, p->rtp, (struct ast_channel *) data); 04306 } 04307 break; 04308 case AST_OPTION_DIGIT_DETECT: 04309 if ((ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_INBAND) || 04310 (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_AUTO)) { 04311 char *cp = (char *) data; 04312 04313 ast_debug(1, "%sabling digit detection on %s\n", *cp ? "En" : "Dis", chan->name); 04314 if (*cp) { 04315 enable_dsp_detect(p); 04316 } else { 04317 disable_dsp_detect(p); 04318 } 04319 res = 0; 04320 } 04321 break; 04322 case AST_OPTION_SECURE_SIGNALING: 04323 p->req_secure_signaling = *(unsigned int *) data; 04324 res = 0; 04325 break; 04326 case AST_OPTION_SECURE_MEDIA: 04327 ast_set2_flag(&p->flags[1], *(unsigned int *) data, SIP_PAGE2_USE_SRTP); 04328 res = 0; 04329 break; 04330 default: 04331 break; 04332 } 04333 04334 sip_pvt_unlock(p); 04335 04336 return res; 04337 }
| static char * sip_show_channel | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show details of one active dialog.
Definition at line 18642 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli_args::argv, ARRAY_LEN, ast_cli(), AST_CLI_YESNO, ast_getformatname_multiple(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_strlen_zero(), ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sipch(), dtmfmode2str(), ast_cli_args::fd, len(), ast_cli_args::line, ast_cli_args::n, NONE, ast_cli_args::pos, sip_pvt_lock, sip_pvt_unlock, stmode2str(), strefresher2str(), subscription_type2str(), transfermode2str(), TRUE, ast_cli_entry::usage, and ast_cli_args::word.
18643 { 18644 struct sip_pvt *cur; 18645 size_t len; 18646 int found = 0; 18647 struct ao2_iterator i; 18648 18649 switch (cmd) { 18650 case CLI_INIT: 18651 e->command = "sip show channel"; 18652 e->usage = 18653 "Usage: sip show channel <call-id>\n" 18654 " Provides detailed status on a given SIP dialog (identified by SIP call-id).\n"; 18655 return NULL; 18656 case CLI_GENERATE: 18657 return complete_sipch(a->line, a->word, a->pos, a->n); 18658 } 18659 18660 if (a->argc != 4) 18661 return CLI_SHOWUSAGE; 18662 len = strlen(a->argv[3]); 18663 18664 i = ao2_iterator_init(dialogs, 0); 18665 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 18666 sip_pvt_lock(cur); 18667 18668 if (!strncasecmp(cur->callid, a->argv[3], len)) { 18669 char formatbuf[SIPBUFSIZE/2]; 18670 ast_cli(a->fd, "\n"); 18671 if (cur->subscribed != NONE) 18672 ast_cli(a->fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed)); 18673 else 18674 ast_cli(a->fd, " * SIP Call\n"); 18675 ast_cli(a->fd, " Curr. trans. direction: %s\n", ast_test_flag(&cur->flags[0], SIP_OUTGOING) ? "Outgoing" : "Incoming"); 18676 ast_cli(a->fd, " Call-ID: %s\n", cur->callid); 18677 ast_cli(a->fd, " Owner channel ID: %s\n", cur->owner ? cur->owner->name : "<none>"); 18678 ast_cli(a->fd, " Our Codec Capability: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->capability)); 18679 ast_cli(a->fd, " Non-Codec Capability (DTMF): %d\n", cur->noncodeccapability); 18680 ast_cli(a->fd, " Their Codec Capability: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->peercapability)); 18681 ast_cli(a->fd, " Joint Codec Capability: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->jointcapability)); 18682 ast_cli(a->fd, " Format: %s\n", ast_getformatname_multiple(formatbuf, sizeof(formatbuf), cur->owner ? cur->owner->nativeformats : 0) ); 18683 ast_cli(a->fd, " T.38 support %s\n", AST_CLI_YESNO(cur->udptl != NULL)); 18684 ast_cli(a->fd, " Video support %s\n", AST_CLI_YESNO(cur->vrtp != NULL)); 18685 ast_cli(a->fd, " MaxCallBR: %d kbps\n", cur->maxcallbitrate); 18686 ast_cli(a->fd, " Theoretical Address: %s\n", ast_sockaddr_stringify(&cur->sa)); 18687 ast_cli(a->fd, " Received Address: %s\n", ast_sockaddr_stringify(&cur->recv)); 18688 ast_cli(a->fd, " SIP Transfer mode: %s\n", transfermode2str(cur->allowtransfer)); 18689 ast_cli(a->fd, " Force rport: %s\n", AST_CLI_YESNO(ast_test_flag(&cur->flags[0], SIP_NAT_FORCE_RPORT))); 18690 if (ast_sockaddr_isnull(&cur->redirip)) { 18691 ast_cli(a->fd, 18692 " Audio IP: %s (local)\n", 18693 ast_sockaddr_stringify_addr(&cur->ourip)); 18694 } else { 18695 ast_cli(a->fd, 18696 " Audio IP: %s (Outside bridge)\n", 18697 ast_sockaddr_stringify_addr(&cur->redirip)); 18698 } 18699 ast_cli(a->fd, " Our Tag: %s\n", cur->tag); 18700 ast_cli(a->fd, " Their Tag: %s\n", cur->theirtag); 18701 ast_cli(a->fd, " SIP User agent: %s\n", cur->useragent); 18702 if (!ast_strlen_zero(cur->username)) 18703 ast_cli(a->fd, " Username: %s\n", cur->username); 18704 if (!ast_strlen_zero(cur->peername)) 18705 ast_cli(a->fd, " Peername: %s\n", cur->peername); 18706 if (!ast_strlen_zero(cur->uri)) 18707 ast_cli(a->fd, " Original uri: %s\n", cur->uri); 18708 if (!ast_strlen_zero(cur->cid_num)) 18709 ast_cli(a->fd, " Caller-ID: %s\n", cur->cid_num); 18710 ast_cli(a->fd, " Need Destroy: %s\n", AST_CLI_YESNO(cur->needdestroy)); 18711 ast_cli(a->fd, " Last Message: %s\n", cur->lastmsg); 18712 ast_cli(a->fd, " Promiscuous Redir: %s\n", AST_CLI_YESNO(ast_test_flag(&cur->flags[0], SIP_PROMISCREDIR))); 18713 ast_cli(a->fd, " Route: %s\n", cur->route ? cur->route->hop : "N/A"); 18714 ast_cli(a->fd, " DTMF Mode: %s\n", dtmfmode2str(ast_test_flag(&cur->flags[0], SIP_DTMF))); 18715 ast_cli(a->fd, " SIP Options: "); 18716 if (cur->sipoptions) { 18717 int x; 18718 for (x = 0 ; x < ARRAY_LEN(sip_options); x++) { 18719 if (cur->sipoptions & sip_options[x].id) 18720 ast_cli(a->fd, "%s ", sip_options[x].text); 18721 } 18722 ast_cli(a->fd, "\n"); 18723 } else 18724 ast_cli(a->fd, "(none)\n"); 18725 18726 if (!cur->stimer) 18727 ast_cli(a->fd, " Session-Timer: Uninitiallized\n"); 18728 else { 18729 ast_cli(a->fd, " Session-Timer: %s\n", cur->stimer->st_active ? "Active" : "Inactive"); 18730 if (cur->stimer->st_active == TRUE) { 18731 ast_cli(a->fd, " S-Timer Interval: %d\n", cur->stimer->st_interval); 18732 ast_cli(a->fd, " S-Timer Refresher: %s\n", strefresher2str(cur->stimer->st_ref)); 18733 ast_cli(a->fd, " S-Timer Expirys: %d\n", cur->stimer->st_expirys); 18734 ast_cli(a->fd, " S-Timer Sched Id: %d\n", cur->stimer->st_schedid); 18735 ast_cli(a->fd, " S-Timer Peer Sts: %s\n", cur->stimer->st_active_peer_ua ? "Active" : "Inactive"); 18736 ast_cli(a->fd, " S-Timer Cached Min-SE: %d\n", cur->stimer->st_cached_min_se); 18737 ast_cli(a->fd, " S-Timer Cached SE: %d\n", cur->stimer->st_cached_max_se); 18738 ast_cli(a->fd, " S-Timer Cached Ref: %s\n", strefresher2str(cur->stimer->st_cached_ref)); 18739 ast_cli(a->fd, " S-Timer Cached Mode: %s\n", stmode2str(cur->stimer->st_cached_mode)); 18740 } 18741 } 18742 18743 ast_cli(a->fd, "\n\n"); 18744 18745 found++; 18746 } 18747 18748 sip_pvt_unlock(cur); 18749 18750 ao2_t_ref(cur, -1, "toss dialog ptr set by iterator_next"); 18751 } 18752 ao2_iterator_destroy(&i); 18753 18754 if (!found) 18755 ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]); 18756 18757 return CLI_SUCCESS; 18758 }
| static char* sip_show_channels | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI for show channels or subscriptions. This is a new-style CLI handler so a single function contains the prototype for the function, the 'generator' to produce multiple entries in case it is required, and the actual handler for the command.
Definition at line 18463 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli_entry::args, ast_cli_args::argv, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ESS, ast_cli_args::fd, FORMAT2, FORMAT3, OBJ_NODATA, show_channels_cb(), and ast_cli_entry::usage.
18464 { 18465 struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; 18466 18467 18468 if (cmd == CLI_INIT) { 18469 e->command = "sip show {channels|subscriptions}"; 18470 e->usage = 18471 "Usage: sip show channels\n" 18472 " Lists all currently active SIP calls (dialogs).\n" 18473 "Usage: sip show subscriptions\n" 18474 " Lists active SIP subscriptions.\n"; 18475 return NULL; 18476 } else if (cmd == CLI_GENERATE) 18477 return NULL; 18478 18479 if (a->argc != e->args) 18480 return CLI_SHOWUSAGE; 18481 arg.subscriptions = !strcasecmp(a->argv[e->args - 1], "subscriptions"); 18482 if (!arg.subscriptions) 18483 ast_cli(arg.fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Format", "Hold", "Last Message", "Expiry", "Peer"); 18484 else 18485 ast_cli(arg.fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox", "Expiry"); 18486 18487 /* iterate on the container and invoke the callback on each item */ 18488 ao2_t_callback(dialogs, OBJ_NODATA, show_channels_cb, &arg, "callback to show channels"); 18489 18490 /* print summary information */ 18491 ast_cli(arg.fd, "%d active SIP %s%s\n", arg.numchans, 18492 (arg.subscriptions ? "subscription" : "dialog"), 18493 ESS(arg.numchans)); /* ESS(n) returns an "s" if n>1 */ 18494 return CLI_SUCCESS; 18495 #undef FORMAT 18496 #undef FORMAT2 18497 #undef FORMAT3 18498 }
| static char * sip_show_channelstats | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
SIP show channelstats CLI (main function).
Definition at line 18089 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT2, OBJ_NODATA, show_chanstats_cb(), and ast_cli_entry::usage.
18090 { 18091 struct __show_chan_arg arg = { .fd = a->fd, .numchans = 0 }; 18092 18093 switch (cmd) { 18094 case CLI_INIT: 18095 e->command = "sip show channelstats"; 18096 e->usage = 18097 "Usage: sip show channelstats\n" 18098 " Lists all currently active SIP channel's RTCP statistics.\n" 18099 " Note that calls in the much optimized RTP P2P bridge mode will not show any packets here."; 18100 return NULL; 18101 case CLI_GENERATE: 18102 return NULL; 18103 } 18104 18105 if (a->argc != 3) 18106 return CLI_SHOWUSAGE; 18107 18108 ast_cli(a->fd, FORMAT2, "Peer", "Call ID", "Duration", "Recv: Pack", "Lost", "Jitter", "Send: Pack", "Lost", "Jitter"); 18109 /* iterate on the container and invoke the callback on each item */ 18110 ao2_t_callback(dialogs, OBJ_NODATA, show_chanstats_cb, &arg, "callback to sip show chanstats"); 18111 ast_cli(a->fd, "%d active SIP channel%s\n", arg.numchans, (arg.numchans != 1) ? "s" : ""); 18112 return CLI_SUCCESS; 18113 }
| static char * sip_show_domains | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI command to list local domains.
Definition at line 17346 of file chan_sip.c.
References ast_cli(), AST_LIST_EMPTY, AST_LIST_LOCK, AST_LIST_TRAVERSE, AST_LIST_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, domain_mode_to_text(), ast_cli_args::fd, FORMAT, S_OR, and ast_cli_entry::usage.
17347 { 17348 struct domain *d; 17349 #define FORMAT "%-40.40s %-20.20s %-16.16s\n" 17350 17351 switch (cmd) { 17352 case CLI_INIT: 17353 e->command = "sip show domains"; 17354 e->usage = 17355 "Usage: sip show domains\n" 17356 " Lists all configured SIP local domains.\n" 17357 " Asterisk only responds to SIP messages to local domains.\n"; 17358 return NULL; 17359 case CLI_GENERATE: 17360 return NULL; 17361 } 17362 17363 if (AST_LIST_EMPTY(&domain_list)) { 17364 ast_cli(a->fd, "SIP Domain support not enabled.\n\n"); 17365 return CLI_SUCCESS; 17366 } else { 17367 ast_cli(a->fd, FORMAT, "Our local SIP domains:", "Context", "Set by"); 17368 AST_LIST_LOCK(&domain_list); 17369 AST_LIST_TRAVERSE(&domain_list, d, list) 17370 ast_cli(a->fd, FORMAT, d->domain, S_OR(d->context, "(default)"), 17371 domain_mode_to_text(d->mode)); 17372 AST_LIST_UNLOCK(&domain_list); 17373 ast_cli(a->fd, "\n"); 17374 return CLI_SUCCESS; 17375 } 17376 }
| static char * sip_show_history | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show history details of one dialog.
Definition at line 18761 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_LIST_TRAVERSE, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_show_history(), ast_cli_args::fd, len(), ast_cli_args::line, ast_cli_args::n, NONE, ast_cli_args::pos, sip_pvt_lock, sip_pvt_unlock, ast_cli_entry::usage, and ast_cli_args::word.
18762 { 18763 struct sip_pvt *cur; 18764 size_t len; 18765 int found = 0; 18766 struct ao2_iterator i; 18767 18768 switch (cmd) { 18769 case CLI_INIT: 18770 e->command = "sip show history"; 18771 e->usage = 18772 "Usage: sip show history <call-id>\n" 18773 " Provides detailed dialog history on a given SIP call (specified by call-id).\n"; 18774 return NULL; 18775 case CLI_GENERATE: 18776 return complete_sip_show_history(a->line, a->word, a->pos, a->n); 18777 } 18778 18779 if (a->argc != 4) 18780 return CLI_SHOWUSAGE; 18781 18782 if (!recordhistory) 18783 ast_cli(a->fd, "\n***Note: History recording is currently DISABLED. Use 'sip set history on' to ENABLE.\n"); 18784 18785 len = strlen(a->argv[3]); 18786 18787 i = ao2_iterator_init(dialogs, 0); 18788 while ((cur = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 18789 sip_pvt_lock(cur); 18790 if (!strncasecmp(cur->callid, a->argv[3], len)) { 18791 struct sip_history *hist; 18792 int x = 0; 18793 18794 ast_cli(a->fd, "\n"); 18795 if (cur->subscribed != NONE) 18796 ast_cli(a->fd, " * Subscription\n"); 18797 else 18798 ast_cli(a->fd, " * SIP Call\n"); 18799 if (cur->history) 18800 AST_LIST_TRAVERSE(cur->history, hist, list) 18801 ast_cli(a->fd, "%d. %s\n", ++x, hist->event); 18802 if (x == 0) 18803 ast_cli(a->fd, "Call '%s' has no history\n", cur->callid); 18804 found++; 18805 } 18806 sip_pvt_unlock(cur); 18807 ao2_t_ref(cur, -1, "toss dialog ptr from iterator_next"); 18808 } 18809 ao2_iterator_destroy(&i); 18810 18811 if (!found) 18812 ast_cli(a->fd, "No such SIP Call ID starting with '%s'\n", a->argv[3]); 18813 18814 return CLI_SUCCESS; 18815 }
| static char * sip_show_inuse | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Command to show calls within limits set by call_limit.
Definition at line 16419 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_iterator_next, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), ast_copy_string(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, FALSE, ast_cli_args::fd, FORMAT, FORMAT2, TRUE, unref_peer(), and ast_cli_entry::usage.
16420 { 16421 #define FORMAT "%-25.25s %-15.15s %-15.15s \n" 16422 #define FORMAT2 "%-25.25s %-15.15s %-15.15s \n" 16423 char ilimits[40]; 16424 char iused[40]; 16425 int showall = FALSE; 16426 struct ao2_iterator i; 16427 struct sip_peer *peer; 16428 16429 switch (cmd) { 16430 case CLI_INIT: 16431 e->command = "sip show inuse"; 16432 e->usage = 16433 "Usage: sip show inuse [all]\n" 16434 " List all SIP devices usage counters and limits.\n" 16435 " Add option \"all\" to show all devices, not only those with a limit.\n"; 16436 return NULL; 16437 case CLI_GENERATE: 16438 return NULL; 16439 } 16440 16441 if (a->argc < 3) 16442 return CLI_SHOWUSAGE; 16443 16444 if (a->argc == 4 && !strcmp(a->argv[3], "all")) 16445 showall = TRUE; 16446 16447 ast_cli(a->fd, FORMAT, "* Peer name", "In use", "Limit"); 16448 16449 i = ao2_iterator_init(peers, 0); 16450 while ((peer = ao2_t_iterator_next(&i, "iterate thru peer table"))) { 16451 ao2_lock(peer); 16452 if (peer->call_limit) 16453 snprintf(ilimits, sizeof(ilimits), "%d", peer->call_limit); 16454 else 16455 ast_copy_string(ilimits, "N/A", sizeof(ilimits)); 16456 snprintf(iused, sizeof(iused), "%d/%d/%d", peer->inUse, peer->inRinging, peer->onHold); 16457 if (showall || peer->call_limit) 16458 ast_cli(a->fd, FORMAT2, peer->name, iused, ilimits); 16459 ao2_unlock(peer); 16460 unref_peer(peer, "toss iterator pointer"); 16461 } 16462 ao2_iterator_destroy(&i); 16463 16464 return CLI_SUCCESS; 16465 #undef FORMAT 16466 #undef FORMAT2 16467 }
| static char * sip_show_mwi | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 18346 of file chan_sip.c.
References ast_cli(), AST_CLI_YESNO, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, submwil, and ast_cli_entry::usage.
18347 { 18348 #define FORMAT "%-30.30s %-12.12s %-10.10s %-10.10s\n" 18349 char host[80]; 18350 18351 switch (cmd) { 18352 case CLI_INIT: 18353 e->command = "sip show mwi"; 18354 e->usage = 18355 "Usage: sip show mwi\n" 18356 " Provides a list of MWI subscriptions and status.\n"; 18357 return NULL; 18358 case CLI_GENERATE: 18359 return NULL; 18360 } 18361 18362 ast_cli(a->fd, FORMAT, "Host", "Username", "Mailbox", "Subscribed"); 18363 18364 ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do { 18365 ASTOBJ_RDLOCK(iterator); 18366 snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); 18367 ast_cli(a->fd, FORMAT, host, iterator->username, iterator->mailbox, AST_CLI_YESNO(iterator->subscribed)); 18368 ASTOBJ_UNLOCK(iterator); 18369 } while(0)); 18370 18371 return CLI_SUCCESS; 18372 #undef FORMAT 18373 }
| static char * sip_show_objects | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
List all allocated SIP Objects (realtime or static).
Definition at line 16979 of file chan_sip.c.
References ao2_t_callback, ast_cli_args::argc, ast_cli(), ASTOBJ_CONTAINER_DUMP, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, dialog_dump_func(), ast_cli_args::fd, OBJ_NODATA, peer_dump_func(), regl, and ast_cli_entry::usage.
16980 { 16981 char tmp[256]; 16982 16983 switch (cmd) { 16984 case CLI_INIT: 16985 e->command = "sip show objects"; 16986 e->usage = 16987 "Usage: sip show objects\n" 16988 " Lists status of known SIP objects\n"; 16989 return NULL; 16990 case CLI_GENERATE: 16991 return NULL; 16992 } 16993 16994 if (a->argc != 3) 16995 return CLI_SHOWUSAGE; 16996 ast_cli(a->fd, "-= Peer objects: %d static, %d realtime, %d autocreate =-\n\n", speerobjs, rpeerobjs, apeerobjs); 16997 ao2_t_callback(peers, OBJ_NODATA, peer_dump_func, a, "initiate ao2_callback to dump peers"); 16998 ast_cli(a->fd, "-= Peer objects by IP =-\n\n"); 16999 ao2_t_callback(peers_by_ip, OBJ_NODATA, peer_dump_func, a, "initiate ao2_callback to dump peers_by_ip"); 17000 ast_cli(a->fd, "-= Registry objects: %d =-\n\n", regobjs); 17001 ASTOBJ_CONTAINER_DUMP(a->fd, tmp, sizeof(tmp), ®l); 17002 ast_cli(a->fd, "-= Dialog objects:\n\n"); 17003 ao2_t_callback(dialogs, OBJ_NODATA, dialog_dump_func, a, "initiate ao2_callback to dump dialogs"); 17004 return CLI_SUCCESS; 17005 }
| static char * sip_show_peer | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show one peer in detail.
Definition at line 17401 of file chan_sip.c.
References _sip_show_peer(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, complete_sip_show_peer(), ast_cli_args::fd, ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ast_cli_entry::usage, and ast_cli_args::word.
17402 { 17403 switch (cmd) { 17404 case CLI_INIT: 17405 e->command = "sip show peer"; 17406 e->usage = 17407 "Usage: sip show peer <name> [load]\n" 17408 " Shows all details on one SIP peer and the current status.\n" 17409 " Option \"load\" forces lookup of peer in realtime storage.\n"; 17410 return NULL; 17411 case CLI_GENERATE: 17412 return complete_sip_show_peer(a->line, a->word, a->pos, a->n); 17413 } 17414 return _sip_show_peer(0, a->fd, NULL, NULL, a->argc, (const char **) a->argv); 17415 }
| static char * sip_show_peers | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Show Peers command.
Definition at line 16731 of file chan_sip.c.
References _sip_show_peers(), ast_cli_args::argc, ast_cli_args::argv, CLI_GENERATE, CLI_INIT, ast_cli_entry::command, ast_cli_args::fd, and ast_cli_entry::usage.
16732 { 16733 switch (cmd) { 16734 case CLI_INIT: 16735 e->command = "sip show peers"; 16736 e->usage = 16737 "Usage: sip show peers [like <pattern>]\n" 16738 " Lists all known SIP peers.\n" 16739 " Optional regular expression pattern is used to filter the peer list.\n"; 16740 return NULL; 16741 case CLI_GENERATE: 16742 return NULL; 16743 } 16744 16745 return _sip_show_peers(a->fd, NULL, NULL, NULL, a->argc, (const char **) a->argv); 16746 }
| static char * sip_show_registry | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show SIP Registry (registrations with other SIP proxies.
Definition at line 17935 of file chan_sip.c.
References ast_cli_args::argc, ast_cli(), ast_localtime(), ast_strftime(), ast_strlen_zero(), ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_RDLOCK, ASTOBJ_UNLOCK, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, FORMAT2, regl, regstate2str(), and ast_cli_entry::usage.
17936 { 17937 #define FORMAT2 "%-39.39s %-6.6s %-12.12s %8.8s %-20.20s %-25.25s\n" 17938 #define FORMAT "%-39.39s %-6.6s %-12.12s %8d %-20.20s %-25.25s\n" 17939 char host[80]; 17940 char user[80]; 17941 char tmpdat[256]; 17942 struct ast_tm tm; 17943 int counter = 0; 17944 17945 switch (cmd) { 17946 case CLI_INIT: 17947 e->command = "sip show registry"; 17948 e->usage = 17949 "Usage: sip show registry\n" 17950 " Lists all registration requests and status.\n"; 17951 return NULL; 17952 case CLI_GENERATE: 17953 return NULL; 17954 } 17955 17956 if (a->argc != 3) 17957 return CLI_SHOWUSAGE; 17958 ast_cli(a->fd, FORMAT2, "Host", "dnsmgr", "Username", "Refresh", "State", "Reg.Time"); 17959 17960 ASTOBJ_CONTAINER_TRAVERSE(®l, 1, do { 17961 ASTOBJ_RDLOCK(iterator); 17962 snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT); 17963 snprintf(user, sizeof(user), "%s", iterator->username); 17964 if (!ast_strlen_zero(iterator->regdomain)) { 17965 snprintf(tmpdat, sizeof(tmpdat), "%s", user); 17966 snprintf(user, sizeof(user), "%s@%s", tmpdat, iterator->regdomain);} 17967 if (iterator->regdomainport) { 17968 snprintf(tmpdat, sizeof(tmpdat), "%s", user); 17969 snprintf(user, sizeof(user), "%s:%d", tmpdat, iterator->regdomainport);} 17970 if (iterator->regtime.tv_sec) { 17971 ast_localtime(&iterator->regtime, &tm, NULL); 17972 ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm); 17973 } else 17974 tmpdat[0] = '\0'; 17975 ast_cli(a->fd, FORMAT, host, (iterator->dnsmgr) ? "Y" : "N", user, iterator->refresh, regstate2str(iterator->regstate), tmpdat); 17976 ASTOBJ_UNLOCK(iterator); 17977 counter++; 17978 } while(0)); 17979 ast_cli(a->fd, "%d SIP registrations.\n", counter); 17980 return CLI_SUCCESS; 17981 #undef FORMAT 17982 #undef FORMAT2 17983 }
| static char * sip_show_sched | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Definition at line 17892 of file chan_sip.c.
References __sip_autodestruct(), ast_cli(), ast_sched_report(), ast_str_alloca, auto_congest(), CLI_GENERATE, CLI_INIT, CLI_SUCCESS, ast_cli_entry::command, expire_register(), ast_cli_args::fd, retrans_pkt(), sip_poke_noanswer(), sip_poke_peer_s(), sip_reg_timeout(), sip_reinvite_retry(), sip_reregister(), and ast_cli_entry::usage.
17893 { 17894 struct ast_str *cbuf; 17895 struct ast_cb_names cbnames = {9, { "retrans_pkt", 17896 "__sip_autodestruct", 17897 "expire_register", 17898 "auto_congest", 17899 "sip_reg_timeout", 17900 "sip_poke_peer_s", 17901 "sip_poke_noanswer", 17902 "sip_reregister", 17903 "sip_reinvite_retry"}, 17904 { retrans_pkt, 17905 __sip_autodestruct, 17906 expire_register, 17907 auto_congest, 17908 sip_reg_timeout, 17909 sip_poke_peer_s, 17910 sip_poke_noanswer, 17911 sip_reregister, 17912 sip_reinvite_retry}}; 17913 17914 switch (cmd) { 17915 case CLI_INIT: 17916 e->command = "sip show sched"; 17917 e->usage = 17918 "Usage: sip show sched\n" 17919 " Shows stats on what's in the sched queue at the moment\n"; 17920 return NULL; 17921 case CLI_GENERATE: 17922 return NULL; 17923 } 17924 17925 cbuf = ast_str_alloca(2048); 17926 17927 ast_cli(a->fd, "\n"); 17928 ast_sched_report(sched, &cbuf, &cbnames); 17929 ast_cli(a->fd, "%s", cbuf->str); 17930 17931 return CLI_SUCCESS; 17932 }
| static char * sip_show_settings | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
List global settings for the SIP channel.
Definition at line 18118 of file chan_sip.c.
References ast_ha::addr, allowoverlap2str(), ao2_t_ref, ast_cli_args::argc, ast_check_realtime(), ast_cli(), AST_CLI_ONOFF, AST_CLI_YESNO, ast_getformatname_multiple(), AST_JB_ENABLED, AST_JB_FORCED, AST_JB_LOG, AST_LIST_EMPTY, AST_LIST_TRAVERSE, ast_mutex_lock, ast_mutex_unlock, ast_sockaddr_is_any(), ast_sockaddr_is_ipv6(), ast_sockaddr_isnull(), ast_sockaddr_stringify(), ast_sockaddr_stringify_addr(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_tos2str(), bindaddr, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, default_prefs, dtmfmode2str(), ast_tls_config::enabled, externaddr, FALSE, faxec2str(), ast_cli_args::fd, get_transport(), get_transport_list(), global_jbconf, ast_jb_conf::impl, ast_tcptls_session_args::local_address, ast_jb_conf::max_size, ast_ha::netmask, ast_ha::next, prefix, print_codec_to_cli(), ast_jb_conf::resync_threshold, S_OR, sip_cfg, stmode2str(), strefresher2str(), ast_jb_conf::target_extra, transfermode2str(), and ast_cli_entry::usage.
18119 { 18120 int realtimepeers; 18121 int realtimeregs; 18122 char codec_buf[SIPBUFSIZE]; 18123 const char *msg; /* temporary msg pointer */ 18124 struct sip_auth_container *credentials; 18125 18126 switch (cmd) { 18127 case CLI_INIT: 18128 e->command = "sip show settings"; 18129 e->usage = 18130 "Usage: sip show settings\n" 18131 " Provides detailed list of the configuration of the SIP channel.\n"; 18132 return NULL; 18133 case CLI_GENERATE: 18134 return NULL; 18135 } 18136 18137 if (a->argc != 3) 18138 return CLI_SHOWUSAGE; 18139 18140 realtimepeers = ast_check_realtime("sippeers"); 18141 realtimeregs = ast_check_realtime("sipregs"); 18142 18143 ast_mutex_lock(&authl_lock); 18144 credentials = authl; 18145 if (credentials) { 18146 ao2_t_ref(credentials, +1, "Ref global auth for show"); 18147 } 18148 ast_mutex_unlock(&authl_lock); 18149 18150 ast_cli(a->fd, "\n\nGlobal Settings:\n"); 18151 ast_cli(a->fd, "----------------\n"); 18152 ast_cli(a->fd, " UDP Bindaddress: %s\n", ast_sockaddr_stringify(&bindaddr)); 18153 if (ast_sockaddr_is_ipv6(&bindaddr) && ast_sockaddr_is_any(&bindaddr)) { 18154 ast_cli(a->fd, " ** Additional Info:\n"); 18155 ast_cli(a->fd, " [::] may include IPv4 in addition to IPv6, if such a feature is enabled in the OS.\n"); 18156 } 18157 ast_cli(a->fd, " TCP SIP Bindaddress: %s\n", 18158 sip_cfg.tcp_enabled != FALSE ? 18159 ast_sockaddr_stringify(&sip_tcp_desc.local_address) : 18160 "Disabled"); 18161 ast_cli(a->fd, " TLS SIP Bindaddress: %s\n", 18162 default_tls_cfg.enabled != FALSE ? 18163 ast_sockaddr_stringify(&sip_tls_desc.local_address) : 18164 "Disabled"); 18165 ast_cli(a->fd, " Videosupport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_VIDEOSUPPORT))); 18166 ast_cli(a->fd, " Textsupport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_TEXTSUPPORT))); 18167 ast_cli(a->fd, " Ignore SDP sess. ver.: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_IGNORESDPVERSION))); 18168 ast_cli(a->fd, " AutoCreate Peer: %s\n", AST_CLI_YESNO(sip_cfg.autocreatepeer)); 18169 ast_cli(a->fd, " Match Auth Username: %s\n", AST_CLI_YESNO(global_match_auth_username)); 18170 ast_cli(a->fd, " Allow unknown access: %s\n", AST_CLI_YESNO(sip_cfg.allowguest)); 18171 ast_cli(a->fd, " Allow subscriptions: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWSUBSCRIBE))); 18172 ast_cli(a->fd, " Allow overlap dialing: %s\n", allowoverlap2str(ast_test_flag(&global_flags[1], SIP_PAGE2_ALLOWOVERLAP))); 18173 ast_cli(a->fd, " Allow promisc. redir: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_PROMISCREDIR))); 18174 ast_cli(a->fd, " Enable call counters: %s\n", AST_CLI_YESNO(global_callcounter)); 18175 ast_cli(a->fd, " SIP domain support: %s\n", AST_CLI_YESNO(!AST_LIST_EMPTY(&domain_list))); 18176 ast_cli(a->fd, " Realm. auth: %s\n", AST_CLI_YESNO(credentials != NULL)); 18177 if (credentials) { 18178 struct sip_auth *auth; 18179 18180 AST_LIST_TRAVERSE(&credentials->list, auth, node) { 18181 ast_cli(a->fd, " Realm. auth entry: Realm %-15.15s User %-10.20s %s\n", 18182 auth->realm, 18183 auth->username, 18184 !ast_strlen_zero(auth->secret) 18185 ? "<Secret set>" 18186 : (!ast_strlen_zero(auth->md5secret) 18187 ? "<MD5secret set>" : "<Not set>")); 18188 } 18189 ao2_t_ref(credentials, -1, "Unref global auth for show"); 18190 } 18191 ast_cli(a->fd, " Our auth realm %s\n", sip_cfg.realm); 18192 ast_cli(a->fd, " Use domains as realms: %s\n", AST_CLI_YESNO(sip_cfg.domainsasrealm)); 18193 ast_cli(a->fd, " Call to non-local dom.: %s\n", AST_CLI_YESNO(sip_cfg.allow_external_domains)); 18194 ast_cli(a->fd, " URI user is phone no: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_USEREQPHONE))); 18195 ast_cli(a->fd, " Always auth rejects: %s\n", AST_CLI_YESNO(sip_cfg.alwaysauthreject)); 18196 ast_cli(a->fd, " Direct RTP setup: %s\n", AST_CLI_YESNO(sip_cfg.directrtpsetup)); 18197 ast_cli(a->fd, " User Agent: %s\n", global_useragent); 18198 ast_cli(a->fd, " SDP Session Name: %s\n", ast_strlen_zero(global_sdpsession) ? "-" : global_sdpsession); 18199 ast_cli(a->fd, " SDP Owner Name: %s\n", ast_strlen_zero(global_sdpowner) ? "-" : global_sdpowner); 18200 ast_cli(a->fd, " Reg. context: %s\n", S_OR(sip_cfg.regcontext, "(not set)")); 18201 ast_cli(a->fd, " Regexten on Qualify: %s\n", AST_CLI_YESNO(sip_cfg.regextenonqualify)); 18202 ast_cli(a->fd, " Legacy userfield parse: %s\n", AST_CLI_YESNO(sip_cfg.legacy_useroption_parsing)); 18203 ast_cli(a->fd, " Caller ID: %s\n", default_callerid); 18204 if ((default_fromdomainport) && (default_fromdomainport != STANDARD_SIP_PORT)) { 18205 ast_cli(a->fd, " From: Domain: %s:%d\n", default_fromdomain, default_fromdomainport); 18206 } else { 18207 ast_cli(a->fd, " From: Domain: %s\n", default_fromdomain); 18208 } 18209 ast_cli(a->fd, " Record SIP history: %s\n", AST_CLI_ONOFF(recordhistory)); 18210 ast_cli(a->fd, " Call Events: %s\n", AST_CLI_ONOFF(sip_cfg.callevents)); 18211 ast_cli(a->fd, " Auth. Failure Events: %s\n", AST_CLI_ONOFF(global_authfailureevents)); 18212 18213 ast_cli(a->fd, " T.38 support: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT))); 18214 ast_cli(a->fd, " T.38 EC mode: %s\n", faxec2str(ast_test_flag(&global_flags[1], SIP_PAGE2_T38SUPPORT))); 18215 ast_cli(a->fd, " T.38 MaxDtgrm: %d\n", global_t38_maxdatagram); 18216 if (!realtimepeers && !realtimeregs) 18217 ast_cli(a->fd, " SIP realtime: Disabled\n" ); 18218 else 18219 ast_cli(a->fd, " SIP realtime: Enabled\n" ); 18220 ast_cli(a->fd, " Qualify Freq : %d ms\n", global_qualifyfreq); 18221 ast_cli(a->fd, " Q.850 Reason header: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_Q850_REASON))); 18222 ast_cli(a->fd, " Store SIP_CAUSE: %s\n", AST_CLI_YESNO(global_store_sip_cause)); 18223 ast_cli(a->fd, "\nNetwork QoS Settings:\n"); 18224 ast_cli(a->fd, "---------------------------\n"); 18225 ast_cli(a->fd, " IP ToS SIP: %s\n", ast_tos2str(global_tos_sip)); 18226 ast_cli(a->fd, " IP ToS RTP audio: %s\n", ast_tos2str(global_tos_audio)); 18227 ast_cli(a->fd, " IP ToS RTP video: %s\n", ast_tos2str(global_tos_video)); 18228 ast_cli(a->fd, " IP ToS RTP text: %s\n", ast_tos2str(global_tos_text)); 18229 ast_cli(a->fd, " 802.1p CoS SIP: %d\n", global_cos_sip); 18230 ast_cli(a->fd, " 802.1p CoS RTP audio: %d\n", global_cos_audio); 18231 ast_cli(a->fd, " 802.1p CoS RTP video: %d\n", global_cos_video); 18232 ast_cli(a->fd, " 802.1p CoS RTP text: %d\n", global_cos_text); 18233 ast_cli(a->fd, " Jitterbuffer enabled: %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_ENABLED))); 18234 if (ast_test_flag(&global_jbconf, AST_JB_ENABLED)) { 18235 ast_cli(a->fd, " Jitterbuffer forced: %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_FORCED))); 18236 ast_cli(a->fd, " Jitterbuffer max size: %ld\n", global_jbconf.max_size); 18237 ast_cli(a->fd, " Jitterbuffer resync: %ld\n", global_jbconf.resync_threshold); 18238 ast_cli(a->fd, " Jitterbuffer impl: %s\n", global_jbconf.impl); 18239 if (!strcasecmp(global_jbconf.impl, "adaptive")) { 18240 ast_cli(a->fd, " Jitterbuffer tgt extra: %ld\n", global_jbconf.target_extra); 18241 } 18242 ast_cli(a->fd, " Jitterbuffer log: %s\n", AST_CLI_YESNO(ast_test_flag(&global_jbconf, AST_JB_LOG))); 18243 } 18244 18245 ast_cli(a->fd, "\nNetwork Settings:\n"); 18246 ast_cli(a->fd, "---------------------------\n"); 18247 /* determine if/how SIP address can be remapped */ 18248 if (localaddr == NULL) 18249 msg = "Disabled, no localnet list"; 18250 else if (ast_sockaddr_isnull(&externaddr)) 18251 msg = "Disabled"; 18252 else if (!ast_strlen_zero(externhost)) 18253 msg = "Enabled using externhost"; 18254 else 18255 msg = "Enabled using externaddr"; 18256 ast_cli(a->fd, " SIP address remapping: %s\n", msg); 18257 ast_cli(a->fd, " Externhost: %s\n", S_OR(externhost, "<none>")); 18258 ast_cli(a->fd, " Externaddr: %s\n", ast_sockaddr_stringify(&externaddr)); 18259 ast_cli(a->fd, " Externrefresh: %d\n", externrefresh); 18260 { 18261 struct ast_ha *d; 18262 const char *prefix = "Localnet:"; 18263 18264 for (d = localaddr; d ; prefix = "", d = d->next) { 18265 const char *addr = ast_strdupa(ast_sockaddr_stringify_addr(&d->addr)); 18266 const char *mask = ast_strdupa(ast_sockaddr_stringify_addr(&d->netmask)); 18267 ast_cli(a->fd, " %-24s%s/%s\n", prefix, addr, mask); 18268 } 18269 } 18270 ast_cli(a->fd, "\nGlobal Signalling Settings:\n"); 18271 ast_cli(a->fd, "---------------------------\n"); 18272 ast_cli(a->fd, " Codecs: "); 18273 ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, sip_cfg.capability); 18274 ast_cli(a->fd, "%s\n", codec_buf); 18275 ast_cli(a->fd, " Codec Order: "); 18276 print_codec_to_cli(a->fd, &default_prefs); 18277 ast_cli(a->fd, "\n"); 18278 ast_cli(a->fd, " Relax DTMF: %s\n", AST_CLI_YESNO(global_relaxdtmf)); 18279 ast_cli(a->fd, " RFC2833 Compensation: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_RFC2833_COMPENSATE))); 18280 ast_cli(a->fd, " Symmetric RTP: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_SYMMETRICRTP))); 18281 ast_cli(a->fd, " Compact SIP headers: %s\n", AST_CLI_YESNO(sip_cfg.compactheaders)); 18282 ast_cli(a->fd, " RTP Keepalive: %d %s\n", global_rtpkeepalive, global_rtpkeepalive ? "" : "(Disabled)" ); 18283 ast_cli(a->fd, " RTP Timeout: %d %s\n", global_rtptimeout, global_rtptimeout ? "" : "(Disabled)" ); 18284 ast_cli(a->fd, " RTP Hold Timeout: %d %s\n", global_rtpholdtimeout, global_rtpholdtimeout ? "" : "(Disabled)"); 18285 ast_cli(a->fd, " MWI NOTIFY mime type: %s\n", default_notifymime); 18286 ast_cli(a->fd, " DNS SRV lookup: %s\n", AST_CLI_YESNO(sip_cfg.srvlookup)); 18287 ast_cli(a->fd, " Pedantic SIP support: %s\n", AST_CLI_YESNO(sip_cfg.pedanticsipchecking)); 18288 ast_cli(a->fd, " Reg. min duration %d secs\n", min_expiry); 18289 ast_cli(a->fd, " Reg. max duration: %d secs\n", max_expiry); 18290 ast_cli(a->fd, " Reg. default duration: %d secs\n", default_expiry); 18291 ast_cli(a->fd, " Outbound reg. timeout: %d secs\n", global_reg_timeout); 18292 ast_cli(a->fd, " Outbound reg. attempts: %d\n", global_regattempts_max); 18293 ast_cli(a->fd, " Notify ringing state: %s\n", AST_CLI_YESNO(sip_cfg.notifyringing)); 18294 if (sip_cfg.notifyringing) { 18295 ast_cli(a->fd, " Include CID: %s%s\n", 18296 AST_CLI_YESNO(sip_cfg.notifycid), 18297 sip_cfg.notifycid == IGNORE_CONTEXT ? " (Ignoring context)" : ""); 18298 } 18299 ast_cli(a->fd, " Notify hold state: %s\n", AST_CLI_YESNO(sip_cfg.notifyhold)); 18300 ast_cli(a->fd, " SIP Transfer mode: %s\n", transfermode2str(sip_cfg.allowtransfer)); 18301 ast_cli(a->fd, " Max Call Bitrate: %d kbps\n", default_maxcallbitrate); 18302 ast_cli(a->fd, " Auto-Framing: %s\n", AST_CLI_YESNO(global_autoframing)); 18303 ast_cli(a->fd, " Outb. proxy: %s %s\n", ast_strlen_zero(sip_cfg.outboundproxy.name) ? "<not set>" : sip_cfg.outboundproxy.name, 18304 sip_cfg.outboundproxy.force ? "(forced)" : ""); 18305 ast_cli(a->fd, " Session Timers: %s\n", stmode2str(global_st_mode)); 18306 ast_cli(a->fd, " Session Refresher: %s\n", strefresher2str (global_st_refresher)); 18307 ast_cli(a->fd, " Session Expires: %d secs\n", global_max_se); 18308 ast_cli(a->fd, " Session Min-SE: %d secs\n", global_min_se); 18309 ast_cli(a->fd, " Timer T1: %d\n", global_t1); 18310 ast_cli(a->fd, " Timer T1 minimum: %d\n", global_t1min); 18311 ast_cli(a->fd, " Timer B: %d\n", global_timer_b); 18312 ast_cli(a->fd, " No premature media: %s\n", AST_CLI_YESNO(global_prematuremediafilter)); 18313 ast_cli(a->fd, " Max forwards: %d\n", sip_cfg.default_max_forwards); 18314 18315 ast_cli(a->fd, "\nDefault Settings:\n"); 18316 ast_cli(a->fd, "-----------------\n"); 18317 ast_cli(a->fd, " Allowed transports: %s\n", get_transport_list(default_transports)); 18318 ast_cli(a->fd, " Outbound transport: %s\n", get_transport(default_primary_transport)); 18319 ast_cli(a->fd, " Context: %s\n", sip_cfg.default_context); 18320 ast_cli(a->fd, " Force rport: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_NAT_FORCE_RPORT))); 18321 ast_cli(a->fd, " DTMF: %s\n", dtmfmode2str(ast_test_flag(&global_flags[0], SIP_DTMF))); 18322 ast_cli(a->fd, " Qualify: %d\n", default_qualify); 18323 ast_cli(a->fd, " Use ClientCode: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_USECLIENTCODE))); 18324 ast_cli(a->fd, " Progress inband: %s\n", (ast_test_flag(&global_flags[0], SIP_PROG_INBAND) == SIP_PROG_INBAND_NEVER) ? "Never" : (AST_CLI_YESNO(ast_test_flag(&global_flags[0], SIP_PROG_INBAND) != SIP_PROG_INBAND_NO))); 18325 ast_cli(a->fd, " Language: %s\n", default_language); 18326 ast_cli(a->fd, " MOH Interpret: %s\n", default_mohinterpret); 18327 ast_cli(a->fd, " MOH Suggest: %s\n", default_mohsuggest); 18328 ast_cli(a->fd, " Voice Mail Extension: %s\n", default_vmexten); 18329 18330 18331 if (realtimepeers || realtimeregs) { 18332 ast_cli(a->fd, "\nRealtime SIP Settings:\n"); 18333 ast_cli(a->fd, "----------------------\n"); 18334 ast_cli(a->fd, " Realtime Peers: %s\n", AST_CLI_YESNO(realtimepeers)); 18335 ast_cli(a->fd, " Realtime Regs: %s\n", AST_CLI_YESNO(realtimeregs)); 18336 ast_cli(a->fd, " Cache Friends: %s\n", AST_CLI_YESNO(ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS))); 18337 ast_cli(a->fd, " Update: %s\n", AST_CLI_YESNO(sip_cfg.peer_rtupdate)); 18338 ast_cli(a->fd, " Ignore Reg. Expire: %s\n", AST_CLI_YESNO(sip_cfg.ignore_regexpire)); 18339 ast_cli(a->fd, " Save sys. name: %s\n", AST_CLI_YESNO(sip_cfg.rtsave_sysname)); 18340 ast_cli(a->fd, " Auto Clear: %d (%s)\n", sip_cfg.rtautoclear, ast_test_flag(&global_flags[1], SIP_PAGE2_RTAUTOCLEAR) ? "Enabled" : "Disabled"); 18341 } 18342 ast_cli(a->fd, "\n----\n"); 18343 return CLI_SUCCESS; 18344 }
| static char* sip_show_tcp | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show active TCP connections.
Definition at line 16546 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ast_cli_args::argc, ast_cli(), ast_sockaddr_stringify(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, ast_cli_args::fd, FORMAT, FORMAT2, get_transport(), and ast_cli_entry::usage.
16547 { 16548 struct sip_threadinfo *th; 16549 struct ao2_iterator i; 16550 16551 #define FORMAT2 "%-47.47s %9.9s %6.6s\n" 16552 #define FORMAT "%-47.47s %-9.9s %-6.6s\n" 16553 16554 switch (cmd) { 16555 case CLI_INIT: 16556 e->command = "sip show tcp"; 16557 e->usage = 16558 "Usage: sip show tcp\n" 16559 " Lists all active TCP/TLS sessions.\n"; 16560 return NULL; 16561 case CLI_GENERATE: 16562 return NULL; 16563 } 16564 16565 if (a->argc != 3) 16566 return CLI_SHOWUSAGE; 16567 16568 ast_cli(a->fd, FORMAT2, "Address", "Transport", "Type"); 16569 16570 i = ao2_iterator_init(threadt, 0); 16571 while ((th = ao2_t_iterator_next(&i, "iterate through tcp threads for 'sip show tcp'"))) { 16572 ast_cli(a->fd, FORMAT, 16573 ast_sockaddr_stringify(&th->tcptls_session->remote_address), 16574 get_transport(th->type), 16575 (th->tcptls_session->client ? "Client" : "Server")); 16576 ao2_t_ref(th, -1, "decrement ref from iterator"); 16577 } 16578 ao2_iterator_destroy(&i); 16579 16580 return CLI_SUCCESS; 16581 #undef FORMAT 16582 #undef FORMAT2 16583 }
| static char* sip_show_user | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Show one user in detail.
Definition at line 17816 of file chan_sip.c.
References ao2_lock, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, ast_callerid_merge(), ast_cdr_flags2str(), ast_cli(), AST_CLI_YESNO, ast_describe_caller_presentation(), ast_strlen_zero(), CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_show_user(), FALSE, ast_cli_args::fd, find_peer(), ast_cli_args::line, ast_cli_args::n, ast_variable::name, ast_variable::next, ast_cli_args::pos, print_codec_to_cli(), print_group(), stmode2str(), strefresher2str(), transfermode2str(), TRUE, unref_peer(), ast_cli_entry::usage, ast_variable::value, and ast_cli_args::word.
17817 { 17818 char cbuf[256]; 17819 struct sip_peer *user; 17820 struct ast_variable *v; 17821 int load_realtime; 17822 17823 switch (cmd) { 17824 case CLI_INIT: 17825 e->command = "sip show user"; 17826 e->usage = 17827 "Usage: sip show user <name> [load]\n" 17828 " Shows all details on one SIP user and the current status.\n" 17829 " Option \"load\" forces lookup of peer in realtime storage.\n"; 17830 return NULL; 17831 case CLI_GENERATE: 17832 return complete_sip_show_user(a->line, a->word, a->pos, a->n); 17833 } 17834 17835 if (a->argc < 4) 17836 return CLI_SHOWUSAGE; 17837 17838 /* Load from realtime storage? */ 17839 load_realtime = (a->argc == 5 && !strcmp(a->argv[4], "load")) ? TRUE : FALSE; 17840 17841 if ((user = find_peer(a->argv[3], NULL, load_realtime, FINDUSERS, FALSE, 0))) { 17842 ao2_lock(user); 17843 ast_cli(a->fd, "\n\n"); 17844 ast_cli(a->fd, " * Name : %s\n", user->name); 17845 ast_cli(a->fd, " Secret : %s\n", ast_strlen_zero(user->secret)?"<Not set>":"<Set>"); 17846 ast_cli(a->fd, " MD5Secret : %s\n", ast_strlen_zero(user->md5secret)?"<Not set>":"<Set>"); 17847 ast_cli(a->fd, " Context : %s\n", user->context); 17848 ast_cli(a->fd, " Language : %s\n", user->language); 17849 if (!ast_strlen_zero(user->accountcode)) 17850 ast_cli(a->fd, " Accountcode : %s\n", user->accountcode); 17851 ast_cli(a->fd, " AMA flags : %s\n", ast_cdr_flags2str(user->amaflags)); 17852 ast_cli(a->fd, " Transfer mode: %s\n", transfermode2str(user->allowtransfer)); 17853 ast_cli(a->fd, " MaxCallBR : %d kbps\n", user->maxcallbitrate); 17854 ast_cli(a->fd, " CallingPres : %s\n", ast_describe_caller_presentation(user->callingpres)); 17855 ast_cli(a->fd, " Call limit : %d\n", user->call_limit); 17856 ast_cli(a->fd, " Callgroup : "); 17857 print_group(a->fd, user->callgroup, 0); 17858 ast_cli(a->fd, " Pickupgroup : "); 17859 print_group(a->fd, user->pickupgroup, 0); 17860 ast_cli(a->fd, " Callerid : %s\n", ast_callerid_merge(cbuf, sizeof(cbuf), user->cid_name, user->cid_num, "<unspecified>")); 17861 ast_cli(a->fd, " ACL : %s\n", AST_CLI_YESNO(user->ha != NULL)); 17862 ast_cli(a->fd, " Sess-Timers : %s\n", stmode2str(user->stimer.st_mode_oper)); 17863 ast_cli(a->fd, " Sess-Refresh : %s\n", strefresher2str(user->stimer.st_ref)); 17864 ast_cli(a->fd, " Sess-Expires : %d secs\n", user->stimer.st_max_se); 17865 ast_cli(a->fd, " Sess-Min-SE : %d secs\n", user->stimer.st_min_se); 17866 ast_cli(a->fd, " RTP Engine : %s\n", user->engine); 17867 17868 ast_cli(a->fd, " Codec Order : ("); 17869 print_codec_to_cli(a->fd, &user->prefs); 17870 ast_cli(a->fd, ")\n"); 17871 17872 ast_cli(a->fd, " Auto-Framing: %s \n", AST_CLI_YESNO(user->autoframing)); 17873 if (user->chanvars) { 17874 ast_cli(a->fd, " Variables :\n"); 17875 for (v = user->chanvars ; v ; v = v->next) 17876 ast_cli(a->fd, " %s = %s\n", v->name, v->value); 17877 } 17878 17879 ast_cli(a->fd, "\n"); 17880 17881 ao2_unlock(user); 17882 unref_peer(user, "sip show user"); 17883 } else { 17884 ast_cli(a->fd, "User %s not found.\n", a->argv[3]); 17885 ast_cli(a->fd, "\n"); 17886 } 17887 17888 return CLI_SUCCESS; 17889 }
| static char* sip_show_users | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
CLI Command 'SIP Show Users'.
Definition at line 16586 of file chan_sip.c.
References ao2_iterator_destroy(), ao2_iterator_init(), ao2_lock, ao2_t_iterator_next, ao2_unlock, ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_CLI_YESNO, ast_test_flag, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, FALSE, ast_cli_args::fd, FORMAT, TRUE, unref_peer(), and ast_cli_entry::usage.
16587 { 16588 regex_t regexbuf; 16589 int havepattern = FALSE; 16590 struct ao2_iterator user_iter; 16591 struct sip_peer *user; 16592 16593 #define FORMAT "%-25.25s %-15.15s %-15.15s %-15.15s %-5.5s%-10.10s\n" 16594 16595 switch (cmd) { 16596 case CLI_INIT: 16597 e->command = "sip show users"; 16598 e->usage = 16599 "Usage: sip show users [like <pattern>]\n" 16600 " Lists all known SIP users.\n" 16601 " Optional regular expression pattern is used to filter the user list.\n"; 16602 return NULL; 16603 case CLI_GENERATE: 16604 return NULL; 16605 } 16606 16607 switch (a->argc) { 16608 case 5: 16609 if (!strcasecmp(a->argv[3], "like")) { 16610 if (regcomp(®exbuf, a->argv[4], REG_EXTENDED | REG_NOSUB)) 16611 return CLI_SHOWUSAGE; 16612 havepattern = TRUE; 16613 } else 16614 return CLI_SHOWUSAGE; 16615 case 3: 16616 break; 16617 default: 16618 return CLI_SHOWUSAGE; 16619 } 16620 16621 ast_cli(a->fd, FORMAT, "Username", "Secret", "Accountcode", "Def.Context", "ACL", "ForcerPort"); 16622 16623 user_iter = ao2_iterator_init(peers, 0); 16624 while ((user = ao2_t_iterator_next(&user_iter, "iterate thru peers table"))) { 16625 ao2_lock(user); 16626 if (!(user->type & SIP_TYPE_USER)) { 16627 ao2_unlock(user); 16628 unref_peer(user, "sip show users"); 16629 continue; 16630 } 16631 16632 if (havepattern && regexec(®exbuf, user->name, 0, NULL, 0)) { 16633 ao2_unlock(user); 16634 unref_peer(user, "sip show users"); 16635 continue; 16636 } 16637 16638 ast_cli(a->fd, FORMAT, user->name, 16639 user->secret, 16640 user->accountcode, 16641 user->context, 16642 AST_CLI_YESNO(user->ha != NULL), 16643 AST_CLI_YESNO(ast_test_flag(&user->flags[0], SIP_NAT_FORCE_RPORT))); 16644 ao2_unlock(user); 16645 unref_peer(user, "sip show users"); 16646 } 16647 ao2_iterator_destroy(&user_iter); 16648 16649 if (havepattern) 16650 regfree(®exbuf); 16651 16652 return CLI_SUCCESS; 16653 #undef FORMAT 16654 }
| static int sip_sipredirect | ( | struct sip_pvt * | p, | |
| const char * | dest | |||
| ) | [static] |
Transfer call before connect with a 302 redirect.
Definition at line 29727 of file chan_sip.c.
References AST_CONTROL_TRANSFER, ast_copy_string(), ast_log(), ast_queue_control_data(), ast_strdupa, ast_string_field_build, ast_strlen_zero(), AST_TRANSFER_SUCCESS, get_header(), LOG_ERROR, sip_alreadygone(), sip_scheddestroy(), and transmit_response_reliable().
Referenced by sip_transfer().
29728 { 29729 char *cdest; 29730 char *extension, *domain; 29731 29732 cdest = ast_strdupa(dest); 29733 29734 extension = strsep(&cdest, "@"); 29735 domain = cdest; 29736 if (ast_strlen_zero(extension)) { 29737 ast_log(LOG_ERROR, "Missing mandatory argument: extension\n"); 29738 return 0; 29739 } 29740 29741 /* we'll issue the redirect message here */ 29742 if (!domain) { 29743 char *local_to_header; 29744 char to_header[256]; 29745 29746 ast_copy_string(to_header, get_header(&p->initreq, "To"), sizeof(to_header)); 29747 if (ast_strlen_zero(to_header)) { 29748 ast_log(LOG_ERROR, "Cannot retrieve the 'To' header from the original SIP request!\n"); 29749 return 0; 29750 } 29751 if (((local_to_header = strcasestr(to_header, "sip:")) || (local_to_header = strcasestr(to_header, "sips:"))) 29752 && (local_to_header = strchr(local_to_header, '@'))) { 29753 char ldomain[256]; 29754 29755 memset(ldomain, 0, sizeof(ldomain)); 29756 local_to_header++; 29757 /* This is okey because lhost and lport are as big as tmp */ 29758 sscanf(local_to_header, "%256[^<>; ]", ldomain); 29759 if (ast_strlen_zero(ldomain)) { 29760 ast_log(LOG_ERROR, "Can't find the host address\n"); 29761 return 0; 29762 } 29763 domain = ast_strdupa(ldomain); 29764 } 29765 } 29766 29767 ast_string_field_build(p, our_contact, "Transfer <sip:%s@%s>", extension, domain); 29768 transmit_response_reliable(p, "302 Moved Temporarily", &p->initreq); 29769 29770 sip_scheddestroy(p, SIP_TRANS_TIMEOUT); /* Make sure we stop send this reply. */ 29771 sip_alreadygone(p); 29772 29773 if (p->owner) { 29774 enum ast_control_transfer message = AST_TRANSFER_SUCCESS; 29775 ast_queue_control_data(p->owner, AST_CONTROL_TRANSFER, &message, sizeof(message)); 29776 } 29777 /* hangup here */ 29778 return 0; 29779 }
| static struct sip_st_dlg * sip_st_alloc | ( | struct sip_pvt *const | p | ) | [static, read] |
Allocate Session-Timers struct w/in dialog.
Definition at line 7642 of file chan_sip.c.
References ast_calloc, ast_log(), and LOG_ERROR.
Referenced by handle_request_invite(), and st_get_mode().
07643 { 07644 struct sip_st_dlg *stp; 07645 07646 if (p->stimer) { 07647 ast_log(LOG_ERROR, "Session-Timer struct already allocated\n"); 07648 return p->stimer; 07649 } 07650 07651 if (!(stp = ast_calloc(1, sizeof(struct sip_st_dlg)))) 07652 return NULL; 07653 07654 p->stimer = stp; 07655 07656 stp->st_schedid = -1; /* Session-Timers ast_sched scheduler id */ 07657 07658 return p->stimer; 07659 }
| static int sip_standard_port | ( | enum sip_transport | type, | |
| int | port | |||
| ) | [static] |
Returns the port to use for this socket.
| type | The type of transport used | |
| port | Port we are checking to see if it's the standard port. |
Definition at line 25555 of file chan_sip.c.
Referenced by initreqprep(), and transmit_notify_with_mwi().
25556 { 25557 if (type & SIP_TRANSPORT_TLS) 25558 return port == STANDARD_TLS_PORT; 25559 else 25560 return port == STANDARD_SIP_PORT; 25561 }
| static int sip_subscribe_mwi | ( | const char * | value, | |
| int | lineno | |||
| ) | [static] |
Parse mwi=> line in sip.conf and add to list.
--- SIP MWI Subscription support
Definition at line 8272 of file chan_sip.c.
References ast_calloc_with_stringfields, ast_copy_string(), ast_log(), ast_string_field_set, ast_strlen_zero(), ASTOBJ_CONTAINER_LINK, ASTOBJ_INIT, ASTOBJ_UNREF, hostname, LOG_WARNING, mailbox, secret, sip_subscribe_mwi_destroy(), and submwil.
Referenced by reload_config().
08273 { 08274 struct sip_subscription_mwi *mwi; 08275 int portnum = 0; 08276 enum sip_transport transport = SIP_TRANSPORT_UDP; 08277 char buf[256] = ""; 08278 char *username = NULL, *hostname = NULL, *secret = NULL, *authuser = NULL, *porta = NULL, *mailbox = NULL; 08279 08280 if (!value) { 08281 return -1; 08282 } 08283 08284 ast_copy_string(buf, value, sizeof(buf)); 08285 08286 username = buf; 08287 08288 if ((hostname = strrchr(buf, '@'))) { 08289 *hostname++ = '\0'; 08290 } else { 08291 return -1; 08292 } 08293 08294 if ((secret = strchr(username, ':'))) { 08295 *secret++ = '\0'; 08296 if ((authuser = strchr(secret, ':'))) { 08297 *authuser++ = '\0'; 08298 } 08299 } 08300 08301 if ((mailbox = strchr(hostname, '/'))) { 08302 *mailbox++ = '\0'; 08303 } 08304 08305 if (ast_strlen_zero(username) || ast_strlen_zero(hostname) || ast_strlen_zero(mailbox)) { 08306 ast_log(LOG_WARNING, "Format for MWI subscription is user[:secret[:authuser]]@host[:port]/mailbox at line %d\n", lineno); 08307 return -1; 08308 } 08309 08310 if ((porta = strchr(hostname, ':'))) { 08311 *porta++ = '\0'; 08312 if (!(portnum = atoi(porta))) { 08313 ast_log(LOG_WARNING, "%s is not a valid port number at line %d\n", porta, lineno); 08314 return -1; 08315 } 08316 } 08317 08318 if (!(mwi = ast_calloc_with_stringfields(1, struct sip_subscription_mwi, 256))) { 08319 return -1; 08320 } 08321 08322 ASTOBJ_INIT(mwi); 08323 ast_string_field_set(mwi, username, username); 08324 if (secret) { 08325 ast_string_field_set(mwi, secret, secret); 08326 } 08327 if (authuser) { 08328 ast_string_field_set(mwi, authuser, authuser); 08329 } 08330 ast_string_field_set(mwi, hostname, hostname); 08331 ast_string_field_set(mwi, mailbox, mailbox); 08332 mwi->resub = -1; 08333 mwi->portno = portnum; 08334 mwi->transport = transport; 08335 08336 ASTOBJ_CONTAINER_LINK(&submwil, mwi); 08337 ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy); 08338 08339 return 0; 08340 }
| static void sip_subscribe_mwi_destroy | ( | struct sip_subscription_mwi * | mwi | ) | [static] |
Destroy MWI subscription object.
Definition at line 5724 of file chan_sip.c.
References ast_free, AST_SCHED_DEL, ast_string_field_free_memory, and sip_destroy().
Referenced by __sip_subscribe_mwi_do(), handle_response_subscribe(), sip_send_all_mwi_subscriptions(), sip_subscribe_mwi(), sip_subscribe_mwi_do(), and unload_module().
05725 { 05726 if (mwi->call) { 05727 mwi->call->mwi = NULL; 05728 sip_destroy(mwi->call); 05729 } 05730 05731 AST_SCHED_DEL(sched, mwi->resub); 05732 ast_string_field_free_memory(mwi); 05733 ast_free(mwi); 05734 }
| static int sip_subscribe_mwi_do | ( | const void * | data | ) | [static] |
Send a subscription or resubscription for MWI.
Definition at line 12393 of file chan_sip.c.
References __sip_subscribe_mwi_do(), ASTOBJ_UNREF, and sip_subscribe_mwi_destroy().
Referenced by handle_response_subscribe(), and sip_send_all_mwi_subscriptions().
12394 { 12395 struct sip_subscription_mwi *mwi = (struct sip_subscription_mwi*)data; 12396 12397 if (!mwi) { 12398 return -1; 12399 } 12400 12401 mwi->resub = -1; 12402 __sip_subscribe_mwi_do(mwi); 12403 ASTOBJ_UNREF(mwi, sip_subscribe_mwi_destroy); 12404 12405 return 0; 12406 }
| static int sip_t38_abort | ( | const void * | data | ) | [static] |
Called to deny a T38 reinvite if the core does not respond to our request.
Definition at line 22261 of file chan_sip.c.
References change_t38_state(), sip_pvt_lock, sip_pvt_unlock, and transmit_response_reliable().
Referenced by handle_request_invite().
22262 { 22263 struct sip_pvt *p = (struct sip_pvt *) data; 22264 22265 sip_pvt_lock(p); 22266 /* an application may have taken ownership of the T.38 negotiation on this 22267 * channel while we were waiting to grab the lock... if it did, the scheduler 22268 * id will have been reset to -1, which is our indication that we do *not* 22269 * want to abort the negotiation process 22270 */ 22271 if (p->t38id != -1) { 22272 change_t38_state(p, T38_DISABLED); 22273 transmit_response_reliable(p, "488 Not acceptable here", &p->initreq); 22274 p->t38id = -1; 22275 dialog_unref(p, "unref the dialog ptr from sip_t38_abort, because it held a dialog ptr"); 22276 } 22277 sip_pvt_unlock(p); 22278 return 0; 22279 }
| static struct ast_tcptls_session_instance* sip_tcp_locate | ( | struct ast_sockaddr * | s | ) | [static, read] |
Find thread for TCP/TLS session (based on IP/Port.
Definition at line 25580 of file chan_sip.c.
References ao2_callback, ao2_ref, ao2_t_ref, and threadinfo_locate_cb().
Referenced by sip_prepare_socket().
25581 { 25582 struct sip_threadinfo *th; 25583 struct ast_tcptls_session_instance *tcptls_instance = NULL; 25584 25585 if ((th = ao2_callback(threadt, 0, threadinfo_locate_cb, s))) { 25586 tcptls_instance = (ao2_ref(th->tcptls_session, +1), th->tcptls_session); 25587 ao2_t_ref(th, -1, "decrement ref from callback"); 25588 } 25589 25590 return tcptls_instance; 25591 }
| static void * sip_tcp_worker_fn | ( | void * | data | ) | [static] |
SIP TCP connection handler.
Definition at line 2469 of file chan_sip.c.
References _sip_tcp_helper_thread().
Referenced by sip_prepare_socket().
02470 { 02471 struct ast_tcptls_session_instance *tcptls_session = data; 02472 02473 return _sip_tcp_helper_thread(tcptls_session); 02474 }
| static void sip_tcptls_client_args_destructor | ( | void * | obj | ) | [static] |
Definition at line 2351 of file chan_sip.c.
References args, ast_free, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, ast_tcptls_session_args::name, ast_tls_config::pvtfile, and ast_tcptls_session_args::tls_cfg.
Referenced by sip_prepare_socket().
02352 { 02353 struct ast_tcptls_session_args *args = obj; 02354 if (args->tls_cfg) { 02355 ast_free(args->tls_cfg->certfile); 02356 ast_free(args->tls_cfg->pvtfile); 02357 ast_free(args->tls_cfg->cipher); 02358 ast_free(args->tls_cfg->cafile); 02359 ast_free(args->tls_cfg->capath); 02360 } 02361 ast_free(args->tls_cfg); 02362 ast_free((char *) args->name); 02363 }
| static int sip_tcptls_write | ( | struct ast_tcptls_session_instance * | tcptls_session, | |
| const void * | buf, | |||
| size_t | len | |||
| ) | [static] |
used to indicate to a tcptls thread that data is ready to be written
Definition at line 2411 of file chan_sip.c.
References ao2_alloc, ao2_lock, ao2_t_find, ao2_t_ref, ao2_unlock, AST_LIST_INSERT_TAIL, ast_log(), ast_mutex_lock, ast_mutex_unlock, ast_str_create(), ast_str_set(), errno, ast_tcptls_session_instance::fd, ast_tcptls_session_instance::lock, LOG_ERROR, OBJ_POINTER, and tcptls_packet_destructor().
Referenced by __sip_xmit().
02412 { 02413 int res = len; 02414 struct sip_threadinfo *th = NULL; 02415 struct tcptls_packet *packet = NULL; 02416 struct sip_threadinfo tmp = { 02417 .tcptls_session = tcptls_session, 02418 }; 02419 enum sip_tcptls_alert alert = TCPTLS_ALERT_DATA; 02420 02421 if (!tcptls_session) { 02422 return XMIT_ERROR; 02423 } 02424 02425 ast_mutex_lock(&tcptls_session->lock); 02426 02427 if ((tcptls_session->fd == -1) || 02428 !(th = ao2_t_find(threadt, &tmp, OBJ_POINTER, "ao2_find, getting sip_threadinfo in tcp helper thread")) || 02429 !(packet = ao2_alloc(sizeof(*packet), tcptls_packet_destructor)) || 02430 !(packet->data = ast_str_create(len))) { 02431 goto tcptls_write_setup_error; 02432 } 02433 02434 /* goto tcptls_write_error should _NOT_ be used beyond this point */ 02435 ast_str_set(&packet->data, 0, "%s", (char *) buf); 02436 packet->len = len; 02437 02438 /* alert tcptls thread handler that there is a packet to be sent. 02439 * must lock the thread info object to guarantee control of the 02440 * packet queue */ 02441 ao2_lock(th); 02442 if (write(th->alert_pipe[1], &alert, sizeof(alert)) == -1) { 02443 ast_log(LOG_ERROR, "write() to alert pipe failed: %s\n", strerror(errno)); 02444 ao2_t_ref(packet, -1, "could not write to alert pipe, remove packet"); 02445 packet = NULL; 02446 res = XMIT_ERROR; 02447 } else { /* it is safe to queue the frame after issuing the alert when we hold the threadinfo lock */ 02448 AST_LIST_INSERT_TAIL(&th->packet_q, packet, entry); 02449 } 02450 ao2_unlock(th); 02451 02452 ast_mutex_unlock(&tcptls_session->lock); 02453 ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo object after finding it"); 02454 return res; 02455 02456 tcptls_write_setup_error: 02457 if (th) { 02458 ao2_t_ref(th, -1, "In sip_tcptls_write, unref threadinfo obj, could not create packet"); 02459 } 02460 if (packet) { 02461 ao2_t_ref(packet, -1, "could not allocate packet's data"); 02462 } 02463 ast_mutex_unlock(&tcptls_session->lock); 02464 02465 return XMIT_ERROR; 02466 }
| static struct sip_threadinfo* sip_threadinfo_create | ( | struct ast_tcptls_session_instance * | tcptls_session, | |
| int | transport | |||
| ) | [static, read] |
creates a sip_threadinfo object and links it into the threadt table.
Definition at line 2387 of file chan_sip.c.
References ao2_alloc, ao2_t_link, ao2_t_ref, ast_log(), errno, LOG_ERROR, sip_threadinfo_destructor(), and ast_tcptls_session_instance::ssl.
Referenced by _sip_tcp_helper_thread(), and sip_prepare_socket().
02388 { 02389 struct sip_threadinfo *th; 02390 02391 if (!tcptls_session || !(th = ao2_alloc(sizeof(*th), sip_threadinfo_destructor))) { 02392 return NULL; 02393 } 02394 02395 th->alert_pipe[0] = th->alert_pipe[1] = -1; 02396 02397 if (pipe(th->alert_pipe) == -1) { 02398 ao2_t_ref(th, -1, "Failed to open alert pipe on sip_threadinfo"); 02399 ast_log(LOG_ERROR, "Could not create sip alert pipe in tcptls thread, error %s\n", strerror(errno)); 02400 return NULL; 02401 } 02402 ao2_t_ref(tcptls_session, +1, "tcptls_session ref for sip_threadinfo object"); 02403 th->tcptls_session = tcptls_session; 02404 th->type = transport ? transport : (tcptls_session->ssl ? SIP_TRANSPORT_TLS: SIP_TRANSPORT_TCP); 02405 ao2_t_link(threadt, th, "Adding new tcptls helper thread"); 02406 ao2_t_ref(th, -1, "Decrementing threadinfo ref from alloc, only table ref remains"); 02407 return th; 02408 }
| static void sip_threadinfo_destructor | ( | void * | obj | ) | [static] |
Definition at line 2365 of file chan_sip.c.
References ao2_t_ref, and AST_LIST_REMOVE_HEAD.
Referenced by sip_threadinfo_create().
02366 { 02367 struct sip_threadinfo *th = obj; 02368 struct tcptls_packet *packet; 02369 if (th->alert_pipe[1] > -1) { 02370 close(th->alert_pipe[0]); 02371 } 02372 if (th->alert_pipe[1] > -1) { 02373 close(th->alert_pipe[1]); 02374 } 02375 th->alert_pipe[0] = th->alert_pipe[1] = -1; 02376 02377 while ((packet = AST_LIST_REMOVE_HEAD(&th->packet_q, entry))) { 02378 ao2_t_ref(packet, -1, "thread destruction, removing packet from frame queue"); 02379 } 02380 02381 if (th->tcptls_session) { 02382 ao2_t_ref(th->tcptls_session, -1, "remove tcptls_session for sip_threadinfo object"); 02383 } 02384 }
| static int sip_transfer | ( | struct ast_channel * | ast, | |
| const char * | dest | |||
| ) | [static] |
Transfer SIP call.
Definition at line 6700 of file chan_sip.c.
References ast_channel::_state, AST_STATE_RING, sip_pvt_lock, sip_pvt_unlock, sip_sipredirect(), ast_channel::tech_pvt, and transmit_refer().
06701 { 06702 struct sip_pvt *p = ast->tech_pvt; 06703 int res; 06704 06705 if (dest == NULL) /* functions below do not take a NULL */ 06706 dest = ""; 06707 sip_pvt_lock(p); 06708 if (ast->_state == AST_STATE_RING) 06709 res = sip_sipredirect(p, dest); 06710 else 06711 res = transmit_refer(p, dest); 06712 sip_pvt_unlock(p); 06713 return res; 06714 }
| static char * sip_unregister | ( | struct ast_cli_entry * | e, | |
| int | cmd, | |||
| struct ast_cli_args * | a | |||
| ) | [static] |
Unregister (force expiration) a SIP peer in the registry via CLI.
Definition at line 17989 of file chan_sip.c.
References ast_cli_args::argc, ast_cli_args::argv, ast_cli(), AST_SCHED_DEL_UNREF, CLI_GENERATE, CLI_INIT, CLI_SHOWUSAGE, CLI_SUCCESS, ast_cli_entry::command, complete_sip_unregister(), expire_register(), ast_cli_args::fd, find_peer(), ast_cli_args::line, ast_cli_args::n, ast_cli_args::pos, ref_peer(), TRUE, unref_peer(), ast_cli_entry::usage, and ast_cli_args::word.
17990 { 17991 struct sip_peer *peer; 17992 int load_realtime = 0; 17993 17994 switch (cmd) { 17995 case CLI_INIT: 17996 e->command = "sip unregister"; 17997 e->usage = 17998 "Usage: sip unregister <peer>\n" 17999 " Unregister (force expiration) a SIP peer from the registry\n"; 18000 return NULL; 18001 case CLI_GENERATE: 18002 return complete_sip_unregister(a->line, a->word, a->pos, a->n); 18003 } 18004 18005 if (a->argc != 3) 18006 return CLI_SHOWUSAGE; 18007 18008 if ((peer = find_peer(a->argv[2], NULL, load_realtime, FINDPEERS, TRUE, 0))) { 18009 if (peer->expire > 0) { 18010 AST_SCHED_DEL_UNREF(sched, peer->expire, 18011 unref_peer(peer, "remove register expire ref")); 18012 expire_register(ref_peer(peer, "ref for expire_register")); 18013 ast_cli(a->fd, "Unregistered peer \'%s\'\n\n", a->argv[2]); 18014 } else { 18015 ast_cli(a->fd, "Peer %s not registered\n", a->argv[2]); 18016 } 18017 unref_peer(peer, "sip_unregister: unref_peer via sip_unregister: done with peer from find_peer call"); 18018 } else { 18019 ast_cli(a->fd, "Peer unknown: \'%s\'. Not unregistered.\n", a->argv[2]); 18020 } 18021 18022 return CLI_SUCCESS; 18023 }
| static void sip_unregister_tests | ( | void | ) | [static] |
SIP test registration.
Definition at line 30187 of file chan_sip.c.
References sip_config_parser_unregister_tests(), sip_dialplan_function_unregister_tests(), and sip_request_parser_unregister_tests().
Referenced by unload_module().
30188 { 30189 sip_config_parser_unregister_tests(); 30190 sip_request_parser_unregister_tests(); 30191 sip_dialplan_function_unregister_tests(); 30192 }
| static int sip_write | ( | struct ast_channel * | ast, | |
| struct ast_frame * | frame | |||
| ) | [static] |
Send frame to media channel (rtp).
Definition at line 6502 of file chan_sip.c.
References ast_channel::_state, AST_FORMAT_AUDIO_MASK, AST_FRAME_IMAGE, AST_FRAME_MODEM, AST_FRAME_TEXT, AST_FRAME_VIDEO, AST_FRAME_VOICE, ast_getformatname(), ast_getformatname_multiple(), ast_log(), ast_rtp_instance_update_source(), ast_rtp_instance_write(), ast_rtp_red_buffer(), ast_set_flag, AST_STATE_UP, ast_test_flag, ast_udptl_write(), ast_frame_subclass::codec, ast_frame::frametype, LOG_WARNING, ast_channel::nativeformats, ast_channel::readformat, sip_pvt_lock, sip_pvt_unlock, ast_frame::subclass, ast_channel::tech_pvt, transmit_provisional_response(), TRUE, and ast_channel::writeformat.
06503 { 06504 struct sip_pvt *p = ast->tech_pvt; 06505 int res = 0; 06506 06507 switch (frame->frametype) { 06508 case AST_FRAME_VOICE: 06509 if (!(frame->subclass.codec & ast->nativeformats)) { 06510 char s1[512], s2[512], s3[512]; 06511 ast_log(LOG_WARNING, "Asked to transmit frame type %s, while native formats is %s read/write = %s/%s\n", 06512 ast_getformatname(frame->subclass.codec), 06513 ast_getformatname_multiple(s1, sizeof(s1), ast->nativeformats & AST_FORMAT_AUDIO_MASK), 06514 ast_getformatname_multiple(s2, sizeof(s2), ast->readformat), 06515 ast_getformatname_multiple(s3, sizeof(s3), ast->writeformat)); 06516 return 0; 06517 } 06518 if (p) { 06519 sip_pvt_lock(p); 06520 if (p->t38.state == T38_ENABLED) { 06521 /* drop frame, can't sent VOICE frames while in T.38 mode */ 06522 sip_pvt_unlock(p); 06523 break; 06524 } else if (p->rtp) { 06525 /* If channel is not up, activate early media session */ 06526 if ((ast->_state != AST_STATE_UP) && 06527 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06528 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06529 ast_rtp_instance_update_source(p->rtp); 06530 if (!global_prematuremediafilter) { 06531 p->invitestate = INV_EARLY_MEDIA; 06532 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06533 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06534 } 06535 } 06536 p->lastrtptx = time(NULL); 06537 res = ast_rtp_instance_write(p->rtp, frame); 06538 } 06539 sip_pvt_unlock(p); 06540 } 06541 break; 06542 case AST_FRAME_VIDEO: 06543 if (p) { 06544 sip_pvt_lock(p); 06545 if (p->vrtp) { 06546 /* Activate video early media */ 06547 if ((ast->_state != AST_STATE_UP) && 06548 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06549 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06550 p->invitestate = INV_EARLY_MEDIA; 06551 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06552 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06553 } 06554 p->lastrtptx = time(NULL); 06555 res = ast_rtp_instance_write(p->vrtp, frame); 06556 } 06557 sip_pvt_unlock(p); 06558 } 06559 break; 06560 case AST_FRAME_TEXT: 06561 if (p) { 06562 sip_pvt_lock(p); 06563 if (p->red) { 06564 ast_rtp_red_buffer(p->trtp, frame); 06565 } else { 06566 if (p->trtp) { 06567 /* Activate text early media */ 06568 if ((ast->_state != AST_STATE_UP) && 06569 !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT) && 06570 !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 06571 p->invitestate = INV_EARLY_MEDIA; 06572 transmit_provisional_response(p, "183 Session Progress", &p->initreq, TRUE); 06573 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 06574 } 06575 p->lastrtptx = time(NULL); 06576 res = ast_rtp_instance_write(p->trtp, frame); 06577 } 06578 } 06579 sip_pvt_unlock(p); 06580 } 06581 break; 06582 case AST_FRAME_IMAGE: 06583 return 0; 06584 break; 06585 case AST_FRAME_MODEM: 06586 if (p) { 06587 sip_pvt_lock(p); 06588 /* UDPTL requires two-way communication, so early media is not needed here. 06589 we simply forget the frames if we get modem frames before the bridge is up. 06590 Fax will re-transmit. 06591 */ 06592 if ((ast->_state == AST_STATE_UP) && 06593 p->udptl && 06594 (p->t38.state == T38_ENABLED)) { 06595 res = ast_udptl_write(p->udptl, frame); 06596 } 06597 sip_pvt_unlock(p); 06598 } 06599 break; 06600 default: 06601 ast_log(LOG_WARNING, "Can't send %d type frames with SIP write\n", frame->frametype); 06602 return 0; 06603 } 06604 06605 return res; 06606 }
| static int sipsock_read | ( | int * | id, | |
| int | fd, | |||
| short | events, | |||
| void * | ignore | |||
| ) | [static] |
Read data from SIP UDP socket.
Definition at line 25426 of file chan_sip.c.
References AST_DYNSTR_BUILD_FAILED, ast_log(), ast_recvfrom(), ast_sockaddr_port, ast_str_create(), ast_str_set(), bindaddr, deinit_req(), errno, handle_request_do(), LOG_NOTICE, LOG_WARNING, and set_socket_transport().
Referenced by do_monitor().
25427 { 25428 struct sip_request req; 25429 struct ast_sockaddr addr; 25430 int res; 25431 static char readbuf[65535]; 25432 25433 memset(&req, 0, sizeof(req)); 25434 res = ast_recvfrom(fd, readbuf, sizeof(readbuf) - 1, 0, &addr); 25435 if (res < 0) { 25436 #if !defined(__FreeBSD__) 25437 if (errno == EAGAIN) 25438 ast_log(LOG_NOTICE, "SIP: Received packet with bad UDP checksum\n"); 25439 else 25440 #endif 25441 if (errno != ECONNREFUSED) 25442 ast_log(LOG_WARNING, "Recv error: %s\n", strerror(errno)); 25443 return 1; 25444 } 25445 25446 readbuf[res] = '\0'; 25447 25448 if (!(req.data = ast_str_create(SIP_MIN_PACKET))) { 25449 return 1; 25450 } 25451 25452 if (ast_str_set(&req.data, 0, "%s", readbuf) == AST_DYNSTR_BUILD_FAILED) { 25453 return -1; 25454 } 25455 25456 req.socket.fd = sipsock; 25457 set_socket_transport(&req.socket, SIP_TRANSPORT_UDP); 25458 req.socket.tcptls_session = NULL; 25459 req.socket.port = htons(ast_sockaddr_port(&bindaddr)); 25460 25461 handle_request_do(&req, &addr); 25462 deinit_req(&req); 25463 25464 return 1; 25465 }
| static int sockaddr_is_null_or_any | ( | const struct ast_sockaddr * | addr | ) | [static] |
Definition at line 8777 of file chan_sip.c.
References ast_sockaddr_is_any(), and ast_sockaddr_isnull().
Referenced by process_sdp().
08778 { 08779 return ast_sockaddr_isnull(addr) || ast_sockaddr_is_any(addr); 08780 }
| enum st_mode st_get_mode | ( | struct sip_pvt * | p, | |
| int | no_cached | |||
| ) | [static] |
Get the session-timer mode.
| p | pointer to the SIP dialog | |
| no_cached,set | this to true in order to force a peername lookup on the session timer mode. |
Definition at line 26357 of file chan_sip.c.
References sip_st_alloc().
Referenced by add_supported_header(), handle_request_invite(), handle_response_invite(), and transmit_invite().
26358 { 26359 if (!p->stimer) { 26360 sip_st_alloc(p); 26361 if (!p->stimer) { 26362 return SESSION_TIMER_MODE_INVALID; 26363 } 26364 } 26365 26366 if (!no_cached && p->stimer->st_cached_mode != SESSION_TIMER_MODE_INVALID) 26367 return p->stimer->st_cached_mode; 26368 26369 if (p->relatedpeer) { 26370 p->stimer->st_cached_mode = p->relatedpeer->stimer.st_mode_oper; 26371 return p->stimer->st_cached_mode; 26372 } 26373 26374 p->stimer->st_cached_mode = global_st_mode; 26375 return global_st_mode; 26376 }
| enum st_refresher st_get_refresher | ( | struct sip_pvt * | p | ) | [static] |
Get the entity (UAC or UAS) that's acting as the session-timer refresher.
| p | pointer to the SIP dialog |
Definition at line 26336 of file chan_sip.c.
Referenced by handle_request_invite().
26337 { 26338 if (p->stimer->st_cached_ref != SESSION_TIMER_REFRESHER_AUTO) 26339 return p->stimer->st_cached_ref; 26340 26341 if (p->relatedpeer) { 26342 p->stimer->st_cached_ref = p->relatedpeer->stimer.st_ref; 26343 return p->stimer->st_cached_ref; 26344 } 26345 26346 p->stimer->st_cached_ref = global_st_refresher; 26347 return global_st_refresher; 26348 }
| int st_get_se | ( | struct sip_pvt * | p, | |
| int | max | |||
| ) | [static] |
Get Max or Min SE (session timer expiry).
| p | pointer to the SIP dialog | |
| max | if true, get max se, otherwise min se |
Definition at line 26307 of file chan_sip.c.
References TRUE.
Referenced by handle_request_invite(), reqprep(), and transmit_invite().
26308 { 26309 if (max == TRUE) { 26310 if (p->stimer->st_cached_max_se) { 26311 return p->stimer->st_cached_max_se; 26312 } 26313 if (p->relatedpeer) { 26314 p->stimer->st_cached_max_se = p->relatedpeer->stimer.st_max_se; 26315 return (p->stimer->st_cached_max_se); 26316 } 26317 p->stimer->st_cached_max_se = global_max_se; 26318 return (p->stimer->st_cached_max_se); 26319 } 26320 /* Find Min SE timer */ 26321 if (p->stimer->st_cached_min_se) { 26322 return p->stimer->st_cached_min_se; 26323 } 26324 if (p->relatedpeer) { 26325 p->stimer->st_cached_min_se = p->relatedpeer->stimer.st_min_se; 26326 return (p->stimer->st_cached_min_se); 26327 } 26328 p->stimer->st_cached_min_se = global_min_se; 26329 return (p->stimer->st_cached_min_se); 26330 }
| static void start_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Start session timer.
Definition at line 26092 of file chan_sip.c.
References ast_debug, ast_log(), ast_sched_add(), AST_SCHED_DEL_UNREF, LOG_ERROR, LOG_WARNING, proc_session_timer(), and TRUE.
Referenced by handle_request_invite(), handle_response_invite(), and restart_session_timer().
26093 { 26094 if (!p->stimer) { 26095 ast_log(LOG_WARNING, "Null stimer in start_session_timer - %s\n", p->callid); 26096 return; 26097 } 26098 26099 if (p->stimer->st_schedid > -1) { 26100 /* in the event a timer is already going, stop it */ 26101 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 26102 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 26103 dialog_unref(p, "unref stimer->st_schedid from dialog")); 26104 } 26105 26106 p->stimer->st_schedid = ast_sched_add(sched, p->stimer->st_interval * 1000 / 2, proc_session_timer, 26107 dialog_ref(p, "adding session timer ref")); 26108 if (p->stimer->st_schedid < 0) { 26109 dialog_unref(p, "removing session timer ref"); 26110 ast_log(LOG_ERROR, "ast_sched_add failed - %s\n", p->callid); 26111 } else { 26112 p->stimer->st_active = TRUE; 26113 ast_debug(2, "Session timer started: %d - %s\n", p->stimer->st_schedid, p->callid); 26114 } 26115 }
| static void state_notify_build_xml | ( | int | state, | |
| int | full, | |||
| const char * | exten, | |||
| const char * | context, | |||
| struct ast_str ** | tmp, | |||
| struct sip_pvt * | p, | |||
| int | subscribed, | |||
| const char * | mfrom, | |||
| const char * | mto | |||
| ) | [static] |
Builds XML portion of NOTIFY messages for presence or dialog updates.
Definition at line 12579 of file chan_sip.c.
References ast_channel_callback(), ast_channel_lock, ast_channel_unlock, ast_channel_unref, AST_DEVICE_UNAVAILABLE, AST_EXTENSION_BUSY, AST_EXTENSION_INUSE, AST_EXTENSION_NOT_INUSE, AST_EXTENSION_ONHOLD, AST_EXTENSION_RINGING, AST_EXTENSION_UNAVAILABLE, ast_get_hint(), AST_MAX_EXTENSION, ast_str_append(), ast_strdupa, ast_channel::caller, cid_num, ast_channel::connected, find_calling_channel(), ast_party_connected_line::id, ast_party_caller::id, ast_party_id::name, NONE, ast_party_id::number, S_COR, sip_cfg, ast_party_name::str, ast_party_number::str, ast_party_name::valid, and ast_party_number::valid.
Referenced by transmit_state_notify().
12580 { 12581 enum state { NOTIFY_OPEN, NOTIFY_INUSE, NOTIFY_CLOSED } local_state = NOTIFY_OPEN; 12582 const char *statestring = "terminated"; 12583 const char *pidfstate = "--"; 12584 const char *pidfnote= "Ready"; 12585 char hint[AST_MAX_EXTENSION]; 12586 12587 switch (state) { 12588 case (AST_EXTENSION_RINGING | AST_EXTENSION_INUSE): 12589 statestring = (sip_cfg.notifyringing) ? "early" : "confirmed"; 12590 local_state = NOTIFY_INUSE; 12591 pidfstate = "busy"; 12592 pidfnote = "Ringing"; 12593 break; 12594 case AST_EXTENSION_RINGING: 12595 statestring = "early"; 12596 local_state = NOTIFY_INUSE; 12597 pidfstate = "busy"; 12598 pidfnote = "Ringing"; 12599 break; 12600 case AST_EXTENSION_INUSE: 12601 statestring = "confirmed"; 12602 local_state = NOTIFY_INUSE; 12603 pidfstate = "busy"; 12604 pidfnote = "On the phone"; 12605 break; 12606 case AST_EXTENSION_BUSY: 12607 statestring = "confirmed"; 12608 local_state = NOTIFY_CLOSED; 12609 pidfstate = "busy"; 12610 pidfnote = "On the phone"; 12611 break; 12612 case AST_EXTENSION_UNAVAILABLE: 12613 statestring = "terminated"; 12614 local_state = NOTIFY_CLOSED; 12615 pidfstate = "away"; 12616 pidfnote = "Unavailable"; 12617 break; 12618 case AST_EXTENSION_ONHOLD: 12619 statestring = "confirmed"; 12620 local_state = NOTIFY_CLOSED; 12621 pidfstate = "busy"; 12622 pidfnote = "On hold"; 12623 break; 12624 case AST_EXTENSION_NOT_INUSE: 12625 default: 12626 /* Default setting */ 12627 break; 12628 } 12629 12630 /* Check which device/devices we are watching and if they are registered */ 12631 if (ast_get_hint(hint, sizeof(hint), NULL, 0, NULL, context, exten)) { 12632 char *hint2 = hint, *individual_hint = NULL; 12633 int hint_count = 0, unavailable_count = 0; 12634 12635 while ((individual_hint = strsep(&hint2, "&"))) { 12636 hint_count++; 12637 12638 if (ast_device_state(individual_hint) == AST_DEVICE_UNAVAILABLE) 12639 unavailable_count++; 12640 } 12641 12642 /* If none of the hinted devices are registered, we will 12643 * override notification and show no availability. 12644 */ 12645 if (hint_count > 0 && hint_count == unavailable_count) { 12646 local_state = NOTIFY_CLOSED; 12647 pidfstate = "away"; 12648 pidfnote = "Not online"; 12649 } 12650 } 12651 12652 switch (subscribed) { 12653 case XPIDF_XML: 12654 case CPIM_PIDF_XML: 12655 ast_str_append(tmp, 0, 12656 "<?xml version=\"1.0\"?>\n" 12657 "<!DOCTYPE presence PUBLIC \"-//IETF//DTD RFCxxxx XPIDF 1.0//EN\" \"xpidf.dtd\">\n" 12658 "<presence>\n"); 12659 ast_str_append(tmp, 0, "<presentity uri=\"%s;method=SUBSCRIBE\" />\n", mfrom); 12660 ast_str_append(tmp, 0, "<atom id=\"%s\">\n", exten); 12661 ast_str_append(tmp, 0, "<address uri=\"%s;user=ip\" priority=\"0.800000\">\n", mto); 12662 ast_str_append(tmp, 0, "<status status=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "open" : (local_state == NOTIFY_INUSE) ? "inuse" : "closed"); 12663 ast_str_append(tmp, 0, "<msnsubstatus substatus=\"%s\" />\n", (local_state == NOTIFY_OPEN) ? "online" : (local_state == NOTIFY_INUSE) ? "onthephone" : "offline"); 12664 ast_str_append(tmp, 0, "</address>\n</atom>\n</presence>\n"); 12665 break; 12666 case PIDF_XML: /* Eyebeam supports this format */ 12667 ast_str_append(tmp, 0, 12668 "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n" 12669 "<presence xmlns=\"urn:ietf:params:xml:ns:pidf\" \nxmlns:pp=\"urn:ietf:params:xml:ns:pidf:person\"\nxmlns:es=\"urn:ietf:params:xml:ns:pidf:rpid:status:rpid-status\"\nxmlns:ep=\"urn:ietf:params:xml:ns:pidf:rpid:rpid-person\"\nentity=\"%s\">\n", mfrom); 12670 ast_str_append(tmp, 0, "<pp:person><status>\n"); 12671 if (pidfstate[0] != '-') { 12672 ast_str_append(tmp, 0, "<ep:activities><ep:%s/></ep:activities>\n", pidfstate); 12673 } 12674 ast_str_append(tmp, 0, "</status></pp:person>\n"); 12675 ast_str_append(tmp, 0, "<note>%s</note>\n", pidfnote); /* Note */ 12676 ast_str_append(tmp, 0, "<tuple id=\"%s\">\n", exten); /* Tuple start */ 12677 ast_str_append(tmp, 0, "<contact priority=\"1\">%s</contact>\n", mto); 12678 if (pidfstate[0] == 'b') /* Busy? Still open ... */ 12679 ast_str_append(tmp, 0, "<status><basic>open</basic></status>\n"); 12680 else 12681 ast_str_append(tmp, 0, "<status><basic>%s</basic></status>\n", (local_state != NOTIFY_CLOSED) ? "open" : "closed"); 12682 ast_str_append(tmp, 0, "</tuple>\n</presence>\n"); 12683 break; 12684 case DIALOG_INFO_XML: /* SNOM subscribes in this format */ 12685 ast_str_append(tmp, 0, "<?xml version=\"1.0\"?>\n"); 12686 ast_str_append(tmp, 0, "<dialog-info xmlns=\"urn:ietf:params:xml:ns:dialog-info\" version=\"%u\" state=\"%s\" entity=\"%s\">\n", p->dialogver, full ? "full" : "partial", mto); 12687 if ((state & AST_EXTENSION_RINGING) && sip_cfg.notifyringing) { 12688 const char *local_display = exten; 12689 char *local_target = ast_strdupa(mto); 12690 const char *remote_display = exten; 12691 /* It may seem odd to base the remote_target on the To header here, 12692 * but testing by reporters on issue ASTERISK-16735 found that basing 12693 * on the From header would cause ringing state hints to not work 12694 * properly on certain SNOM devices. If you are using notifycid properly 12695 * (i.e. in the same extension and context as the dialed call) then this 12696 * should not be an issue since the data will be overwritten shortly 12697 * with channel caller ID 12698 */ 12699 char *remote_target = ast_strdupa(mto); 12700 12701 /* There are some limitations to how this works. The primary one is that the 12702 callee must be dialing the same extension that is being monitored. Simply dialing 12703 the hint'd device is not sufficient. */ 12704 if (sip_cfg.notifycid) { 12705 struct ast_channel *caller; 12706 12707 if ((caller = ast_channel_callback(find_calling_channel, NULL, p, 0))) { 12708 char *cid_num; 12709 char *connected_num; 12710 int need; 12711 12712 ast_channel_lock(caller); 12713 cid_num = S_COR(caller->caller.id.number.valid, 12714 caller->caller.id.number.str, ""); 12715 need = strlen(cid_num) + strlen(p->fromdomain) + sizeof("sip:@"); 12716 remote_target = alloca(need); 12717 snprintf(remote_target, need, "sip:%s@%s", cid_num, p->fromdomain); 12718 12719 remote_display = ast_strdupa(S_COR(caller->caller.id.name.valid, 12720 caller->caller.id.name.str, "")); 12721 12722 connected_num = S_COR(caller->connected.id.number.valid, 12723 caller->connected.id.number.str, ""); 12724 need = strlen(connected_num) + strlen(p->fromdomain) + sizeof("sip:@"); 12725 local_target = alloca(need); 12726 snprintf(local_target, need, "sip:%s@%s", connected_num, p->fromdomain); 12727 12728 local_display = ast_strdupa(S_COR(caller->connected.id.name.valid, 12729 caller->connected.id.name.str, "")); 12730 12731 ast_channel_unlock(caller); 12732 caller = ast_channel_unref(caller); 12733 } 12734 12735 /* We create a fake call-id which the phone will send back in an INVITE 12736 Replaces header which we can grab and do some magic with. */ 12737 if (sip_cfg.pedanticsipchecking) { 12738 ast_str_append(tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" local-tag=\"%s\" remote-tag=\"%s\" direction=\"recipient\">\n", 12739 exten, p->callid, p->theirtag, p->tag); 12740 } else { 12741 ast_str_append(tmp, 0, "<dialog id=\"%s\" call-id=\"pickup-%s\" direction=\"recipient\">\n", 12742 exten, p->callid); 12743 } 12744 ast_str_append(tmp, 0, 12745 "<remote>\n" 12746 /* See the limitations of this above. Luckily the phone seems to still be 12747 happy when these values are not correct. */ 12748 "<identity display=\"%s\">%s</identity>\n" 12749 "<target uri=\"%s\"/>\n" 12750 "</remote>\n" 12751 "<local>\n" 12752 "<identity display=\"%s\">%s</identity>\n" 12753 "<target uri=\"%s\"/>\n" 12754 "</local>\n", 12755 remote_display, remote_target, remote_target, local_display, local_target, local_target); 12756 } else { 12757 ast_str_append(tmp, 0, "<dialog id=\"%s\" direction=\"recipient\">\n", exten); 12758 } 12759 12760 } else { 12761 ast_str_append(tmp, 0, "<dialog id=\"%s\">\n", exten); 12762 } 12763 ast_str_append(tmp, 0, "<state>%s</state>\n", statestring); 12764 if (state == AST_EXTENSION_ONHOLD) { 12765 ast_str_append(tmp, 0, "<local>\n<target uri=\"%s\">\n" 12766 "<param pname=\"+sip.rendering\" pvalue=\"no\"/>\n" 12767 "</target>\n</local>\n", mto); 12768 } 12769 ast_str_append(tmp, 0, "</dialog>\n</dialog-info>\n"); 12770 break; 12771 case NONE: 12772 default: 12773 break; 12774 } 12775 }
| static const char* stmode2str | ( | enum st_mode | m | ) | [static] |
Definition at line 16493 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), sip_show_channel(), sip_show_settings(), and sip_show_user().
| static void stop_media_flows | ( | struct sip_pvt * | p | ) | [static] |
Immediately stop RTP, VRTP and UDPTL as applicable.
Definition at line 21057 of file chan_sip.c.
References ast_rtp_instance_stop(), and ast_udptl_stop().
Referenced by __sip_autodestruct(), handle_request_bye(), handle_request_cancel(), handle_response(), and sip_hangup().
21058 { 21059 /* Immediately stop RTP, VRTP and UDPTL as applicable */ 21060 if (p->rtp) 21061 ast_rtp_instance_stop(p->rtp); 21062 if (p->vrtp) 21063 ast_rtp_instance_stop(p->vrtp); 21064 if (p->trtp) 21065 ast_rtp_instance_stop(p->trtp); 21066 if (p->udptl) 21067 ast_udptl_stop(p->udptl); 21068 }
| static void stop_session_timer | ( | struct sip_pvt * | p | ) | [static] |
Session-Timers: Stop session timer.
Definition at line 26075 of file chan_sip.c.
References ast_debug, ast_log(), AST_SCHED_DEL_UNREF, FALSE, LOG_WARNING, and TRUE.
Referenced by __sip_destroy(), dialog_unlink_all(), handle_request_bye(), proc_session_timer(), sip_hangup(), and sip_scheddestroy().
26076 { 26077 if (!p->stimer) { 26078 ast_log(LOG_WARNING, "Null stimer in stop_session_timer - %s\n", p->callid); 26079 return; 26080 } 26081 26082 if (p->stimer->st_active == TRUE) { 26083 p->stimer->st_active = FALSE; 26084 ast_debug(2, "Session timer stopped: %d - %s\n", p->stimer->st_schedid, p->callid); 26085 AST_SCHED_DEL_UNREF(sched, p->stimer->st_schedid, 26086 dialog_unref(p, "removing session timer ref")); 26087 } 26088 }
| static int str2dtmfmode | ( | const char * | str | ) | [static] |
| static enum st_mode str2stmode | ( | const char * | s | ) | [static] |
Definition at line 16498 of file chan_sip.c.
References map_s_x().
Referenced by build_peer(), and reload_config().
| static enum st_refresher str2strefresher | ( | const char * | s | ) | [static] |
Definition at line 16516 of file chan_sip.c.
References map_s_x().
Referenced by build_peer(), and reload_config().
16517 { 16518 return map_s_x(strefreshers, s, -1); 16519 }
| static const char * strefresher2str | ( | enum st_refresher | r | ) | [static] |
Definition at line 16511 of file chan_sip.c.
References map_x_s().
Referenced by _sip_show_peer(), reqprep(), respprep(), sip_show_channel(), sip_show_settings(), and sip_show_user().
16512 { 16513 return map_x_s(strefreshers, r, "Unknown"); 16514 }
| static const char * subscription_type2str | ( | enum subscriptiontype | subtype | ) | [static] |
Show subscription type in string format.
Definition at line 18377 of file chan_sip.c.
References ARRAY_LEN, subscription_types, cfsubscription_types::text, and type.
Referenced by show_channels_cb(), and sip_show_channel().
18378 { 18379 int i; 18380 18381 for (i = 1; i < ARRAY_LEN(subscription_types); i++) { 18382 if (subscription_types[i].type == subtype) { 18383 return subscription_types[i].text; 18384 } 18385 } 18386 return subscription_types[0].text; 18387 }
| static unsigned int t38_get_rate | ( | enum ast_control_t38_rate | rate | ) | [static] |
Get Max T.38 Transmission rate from T38 capabilities.
Definition at line 11129 of file chan_sip.c.
References AST_T38_RATE_12000, AST_T38_RATE_14400, AST_T38_RATE_2400, AST_T38_RATE_4800, AST_T38_RATE_7200, and AST_T38_RATE_9600.
Referenced by add_sdp().
11130 { 11131 switch (rate) { 11132 case AST_T38_RATE_2400: 11133 return 2400; 11134 case AST_T38_RATE_4800: 11135 return 4800; 11136 case AST_T38_RATE_7200: 11137 return 7200; 11138 case AST_T38_RATE_9600: 11139 return 9600; 11140 case AST_T38_RATE_12000: 11141 return 12000; 11142 case AST_T38_RATE_14400: 11143 return 14400; 11144 default: 11145 return 0; 11146 } 11147 }
| static void tcptls_packet_destructor | ( | void * | obj | ) | [static] |
Definition at line 2344 of file chan_sip.c.
References ast_free.
Referenced by sip_tcptls_write().
02345 { 02346 struct tcptls_packet *packet = obj; 02347 02348 ast_free(packet->data); 02349 }
| static struct sip_peer * temp_peer | ( | const char * | name | ) | [static, read] |
Create temporary peer (used in autocreatepeer mode).
Definition at line 27304 of file chan_sip.c.
References ao2_t_alloc, ao2_t_ref, ast_atomic_fetchadd_int(), ast_cc_config_params_init, ast_copy_string(), ast_string_field_init, default_prefs, reg_source_db(), set_peer_defaults(), sip_destroy_peer_fn(), and TRUE.
Referenced by register_verify().
27305 { 27306 struct sip_peer *peer; 27307 27308 if (!(peer = ao2_t_alloc(sizeof(*peer), sip_destroy_peer_fn, "allocate a peer struct"))) 27309 return NULL; 27310 27311 if (ast_string_field_init(peer, 512)) { 27312 ao2_t_ref(peer, -1, "failed to string_field_init, drop peer"); 27313 return NULL; 27314 } 27315 27316 if (!(peer->cc_params = ast_cc_config_params_init())) { 27317 ao2_t_ref(peer, -1, "failed to allocate cc_params for peer"); 27318 return NULL; 27319 } 27320 27321 ast_atomic_fetchadd_int(&apeerobjs, 1); 27322 set_peer_defaults(peer); 27323 27324 ast_copy_string(peer->name, name, sizeof(peer->name)); 27325 27326 peer->selfdestruct = TRUE; 27327 peer->host_dynamic = TRUE; 27328 peer->prefs = default_prefs; 27329 reg_source_db(peer); 27330 27331 return peer; 27332 }
| static void temp_pvt_cleanup | ( | void * | data | ) | [static] |
Definition at line 10579 of file chan_sip.c.
References ast_free, and ast_string_field_free_memory.
10580 { 10581 struct sip_pvt *p = data; 10582 10583 ast_string_field_free_memory(p); 10584 10585 ast_free(data); 10586 }
| static int temp_pvt_init | ( | void * | data | ) | [static] |
Definition at line 10571 of file chan_sip.c.
References ast_string_field_init.
10572 { 10573 struct sip_pvt *p = data; 10574 10575 p->do_history = 0; /* XXX do we need it ? isn't already all 0 ? */ 10576 return ast_string_field_init(p, 512); 10577 }
| static char* terminate_uri | ( | char * | uri | ) | [static] |
Terminate the uri at the first ';' or space. Technically we should ignore escaped space per RFC3261 (19.1.1 etc) but don't do it for the time being. Remember the uri format is: (User-parameters was added after RFC 3261)
* * sip:user:password;user-parameters@host:port;uri-parameters?headers * sips:user:password;user-parameters@host:port;uri-parameters?headers * *
Definition at line 14773 of file chan_sip.c.
Referenced by check_user_full(), and register_verify().
| static int threadinfo_locate_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 25563 of file chan_sip.c.
References ast_sockaddr_cmp(), CMP_MATCH, and CMP_STOP.
Referenced by sip_tcp_locate().
25564 { 25565 struct sip_threadinfo *th = obj; 25566 struct ast_sockaddr *s = arg; 25567 25568 if (!ast_sockaddr_cmp(s, &th->tcptls_session->remote_address)) { 25569 return CMP_MATCH | CMP_STOP; 25570 } 25571 25572 return 0; 25573 }
| static int threadt_cmp_cb | ( | void * | obj, | |
| void * | arg, | |||
| int | flags | |||
| ) | [static] |
Definition at line 30114 of file chan_sip.c.
References CMP_MATCH, and CMP_STOP.
Referenced by load_module().
| static int threadt_hash_cb | ( | const void * | obj, | |
| const int | flags | |||
| ) | [static] |
Definition at line 30107 of file chan_sip.c.
References ast_sockaddr_hash().
Referenced by load_module().
30108 { 30109 const struct sip_threadinfo *th = obj; 30110 30111 return ast_sockaddr_hash(&th->tcptls_session->remote_address); 30112 }
| static char * transfermode2str | ( | enum transfermodes | mode | ) | [static] |
Convert transfer mode to text string.
Definition at line 16471 of file chan_sip.c.
Referenced by _sip_show_peer(), peers_data_provider_get(), sip_show_channel(), sip_show_settings(), and sip_show_user().
| static int transmit_cc_notify | ( | struct ast_cc_agent * | agent, | |
| struct sip_pvt * | subscription, | |||
| enum sip_cc_notify_state | state | |||
| ) | [static] |
Definition at line 12777 of file chan_sip.c.
References add_content(), add_header(), ast_log(), generate_uri(), LOG_WARNING, ast_cc_agent::private_data, reqprep(), send_request(), sip_cc_notify_state_map, state_string, and TRUE.
Referenced by sip_cc_agent_recall(), and sip_cc_agent_respond().
12778 { 12779 struct sip_request req; 12780 struct sip_cc_agent_pvt *agent_pvt = agent->private_data; 12781 char uri[SIPBUFSIZE]; 12782 char state_str[64]; 12783 char subscription_state_hdr[64]; 12784 12785 if (state < CC_QUEUED || state > CC_READY) { 12786 ast_log(LOG_WARNING, "Invalid state provided for transmit_cc_notify (%d)\n", state); 12787 return -1; 12788 } 12789 12790 reqprep(&req, subscription, SIP_NOTIFY, 0, TRUE); 12791 snprintf(state_str, sizeof(state_str), "%s\r\n", sip_cc_notify_state_map[state].state_string); 12792 add_header(&req, "Event", "call-completion"); 12793 add_header(&req, "Content-Type", "application/call-completion"); 12794 snprintf(subscription_state_hdr, sizeof(subscription_state_hdr), "active;expires=%d", subscription->expiry); 12795 add_header(&req, "Subscription-State", subscription_state_hdr); 12796 if (state == CC_READY) { 12797 generate_uri(subscription, agent_pvt->notify_uri, sizeof(agent_pvt->notify_uri)); 12798 snprintf(uri, sizeof(uri) - 1, "cc-URI: %s\r\n", agent_pvt->notify_uri); 12799 } 12800 add_content(&req, state_str); 12801 if (state == CC_READY) { 12802 add_content(&req, uri); 12803 } 12804 return send_request(subscription, &req, XMIT_RELIABLE, subscription->ocseq); 12805 }
| static void transmit_fake_auth_response | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Send a fake 401 Unauthorized response when the administrator wants to hide the names of local devices from fishers.
Definition at line 14672 of file chan_sip.c.
References AST_DYNSTR_BUILD_FAILED, ast_skip_blanks(), ast_str_set(), ast_str_thread_get(), ast_strlen_zero(), CHECK_AUTH_BUF_INITLEN, FALSE, get_header(), set_nonce_randdata(), sip_scheddestroy(), transmit_response(), and transmit_response_with_auth().
Referenced by handle_request_invite(), handle_request_options(), handle_request_publish(), handle_request_subscribe(), and register_verify().
14673 { 14674 /* We have to emulate EXACTLY what we'd get with a good peer 14675 * and a bad password, or else we leak information. */ 14676 const char *response = "401 Unauthorized"; 14677 const char *reqheader = "Authorization"; 14678 const char *respheader = "WWW-Authenticate"; 14679 const char *authtoken; 14680 struct ast_str *buf; 14681 char *c; 14682 14683 /* table of recognised keywords, and their value in the digest */ 14684 enum keys { K_NONCE, K_LAST }; 14685 struct x { 14686 const char *key; 14687 const char *s; 14688 } *i, keys[] = { 14689 [K_NONCE] = { "nonce=", "" }, 14690 [K_LAST] = { NULL, NULL} 14691 }; 14692 14693 authtoken = get_header(req, reqheader); 14694 if (req->ignore && !ast_strlen_zero(p->randdata) && ast_strlen_zero(authtoken)) { 14695 /* This is a retransmitted invite/register/etc, don't reconstruct authentication 14696 * information */ 14697 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 14698 /* Schedule auto destroy in 32 seconds (according to RFC 3261) */ 14699 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14700 return; 14701 } else if (ast_strlen_zero(p->randdata) || ast_strlen_zero(authtoken)) { 14702 /* We have no auth, so issue challenge and request authentication */ 14703 set_nonce_randdata(p, 1); 14704 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, 0); 14705 /* Schedule auto destroy in 32 seconds */ 14706 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14707 return; 14708 } 14709 14710 if (!(buf = ast_str_thread_get(&check_auth_buf, CHECK_AUTH_BUF_INITLEN))) { 14711 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 14712 return; 14713 } 14714 14715 /* Make a copy of the response and parse it */ 14716 if (ast_str_set(&buf, 0, "%s", authtoken) == AST_DYNSTR_BUILD_FAILED) { 14717 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 14718 return; 14719 } 14720 14721 c = buf->str; 14722 14723 while (c && *(c = ast_skip_blanks(c))) { /* lookup for keys */ 14724 for (i = keys; i->key != NULL; i++) { 14725 const char *separator = ","; /* default */ 14726 14727 if (strncasecmp(c, i->key, strlen(i->key)) != 0) { 14728 continue; 14729 } 14730 /* Found. Skip keyword, take text in quotes or up to the separator. */ 14731 c += strlen(i->key); 14732 if (*c == '"') { /* in quotes. Skip first and look for last */ 14733 c++; 14734 separator = "\""; 14735 } 14736 i->s = c; 14737 strsep(&c, separator); 14738 break; 14739 } 14740 if (i->key == NULL) { /* not found, jump after space or comma */ 14741 strsep(&c, " ,"); 14742 } 14743 } 14744 14745 /* Verify nonce from request matches our nonce. If not, send 401 with new nonce */ 14746 if (strcasecmp(p->randdata, keys[K_NONCE].s)) { 14747 if (!req->ignore) { 14748 set_nonce_randdata(p, 1); 14749 } 14750 transmit_response_with_auth(p, response, req, p->randdata, reliable, respheader, FALSE); 14751 14752 /* Schedule auto destroy in 32 seconds */ 14753 sip_scheddestroy(p, DEFAULT_TRANS_TIMEOUT); 14754 } else { 14755 transmit_response(p, "403 Forbidden (Bad auth)", &p->initreq); 14756 } 14757 }
| static int transmit_info_with_aoc | ( | struct sip_pvt * | p, | |
| struct ast_aoc_decoded * | decoded | |||
| ) | [static] |
Send SIP INFO advice of charge message.
Definition at line 13609 of file chan_sip.c.
References add_header(), ast_aoc_unit_entry::amount, AST_AOC_CHARGE_CURRENCY, AST_AOC_CHARGE_FREE, AST_AOC_CHARGE_UNIT, AST_AOC_D, AST_AOC_E, ast_aoc_get_charge_type(), ast_aoc_get_currency_amount(), ast_aoc_get_currency_multiplier_decimal(), ast_aoc_get_currency_name(), ast_aoc_get_msg_type(), ast_aoc_get_unit_info(), ast_str_alloca, ast_str_append(), ast_str_buffer(), ast_strlen_zero(), reqprep(), send_request(), and str.
Referenced by sip_indicate().
13610 { 13611 struct sip_request req; 13612 struct ast_str *str = ast_str_alloca(512); 13613 const struct ast_aoc_unit_entry *unit_entry = ast_aoc_get_unit_info(decoded, 0); 13614 enum ast_aoc_charge_type charging = ast_aoc_get_charge_type(decoded); 13615 13616 reqprep(&req, p, SIP_INFO, 0, 1); 13617 13618 if (ast_aoc_get_msg_type(decoded) == AST_AOC_D) { 13619 ast_str_append(&str, 0, "type=active;"); 13620 } else if (ast_aoc_get_msg_type(decoded) == AST_AOC_E) { 13621 ast_str_append(&str, 0, "type=terminated;"); 13622 } else { 13623 /* unsupported message type */ 13624 return -1; 13625 } 13626 13627 switch (charging) { 13628 case AST_AOC_CHARGE_FREE: 13629 ast_str_append(&str, 0, "free-of-charge;"); 13630 break; 13631 case AST_AOC_CHARGE_CURRENCY: 13632 ast_str_append(&str, 0, "charging;"); 13633 ast_str_append(&str, 0, "charging-info=currency;"); 13634 ast_str_append(&str, 0, "amount=%u;", ast_aoc_get_currency_amount(decoded)); 13635 ast_str_append(&str, 0, "multiplier=%s;", ast_aoc_get_currency_multiplier_decimal(decoded)); 13636 if (!ast_strlen_zero(ast_aoc_get_currency_name(decoded))) { 13637 ast_str_append(&str, 0, "currency=%s;", ast_aoc_get_currency_name(decoded)); 13638 } 13639 break; 13640 case AST_AOC_CHARGE_UNIT: 13641 ast_str_append(&str, 0, "charging;"); 13642 ast_str_append(&str, 0, "charging-info=pulse;"); 13643 if (unit_entry) { 13644 ast_str_append(&str, 0, "recorded-units=%u;", unit_entry->amount); 13645 } 13646 break; 13647 default: 13648 ast_str_append(&str, 0, "not-available;"); 13649 }; 13650 13651 add_header(&req, "AOC", ast_str_buffer(str)); 13652 13653 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 13654 }
| static int transmit_info_with_digit | ( | struct sip_pvt * | p, | |
| const char | digit, | |||
| unsigned int | duration | |||
| ) | [static] |
Send SIP INFO dtmf message, see Cisco documentation on cisco.com.
Definition at line 13657 of file chan_sip.c.
References add_digit(), ast_test_flag, reqprep(), and send_request().
Referenced by sip_senddigit_end().
13658 { 13659 struct sip_request req; 13660 13661 reqprep(&req, p, SIP_INFO, 0, 1); 13662 add_digit(&req, digit, duration, (ast_test_flag(&p->flags[0], SIP_DTMF) == SIP_DTMF_SHORTINFO)); 13663 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 13664 }
| static int transmit_info_with_vidupdate | ( | struct sip_pvt * | p | ) | [static] |
Send SIP INFO with video update request.
Definition at line 13667 of file chan_sip.c.
References add_vidupdate(), reqprep(), and send_request().
Referenced by sip_indicate().
13668 { 13669 struct sip_request req; 13670 13671 reqprep(&req, p, SIP_INFO, 0, 1); 13672 add_vidupdate(&req); 13673 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 13674 }
| static int transmit_invite | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| int | sdp, | |||
| int | init, | |||
| const char *const | explicit_uri | |||
| ) | [static] |
Build REFER/INVITE/OPTIONS/SUBSCRIBE message and transmit it.
| p | sip_pvt structure | |
| sipmethod | ||
| sdp | unknown | |
| init | 0 = Prepare request within dialog, 1= prepare request, new branch, 2= prepare new request and new dialog. do_proxy_auth calls this with init!=2 | |
| explicit_uri |
Definition at line 12226 of file chan_sip.c.
References add_content(), add_diversion_header(), add_header(), add_rpid(), add_sdp(), add_supported_header(), append_date(), ast_channel_lock, ast_channel_unlock, ast_debug, AST_LIST_TRAVERSE, ast_log(), ast_random(), ast_skip_blanks(), ast_str_buffer(), ast_str_strlen(), ast_strdupa, ast_strlen_zero(), ast_test_flag, ast_var_name(), ast_var_value(), build_via(), FALSE, initialize_initreq(), initreqprep(), LOG_WARNING, ast_variable::name, ast_variable::next, reqprep(), send_request(), st_get_mode(), st_get_se(), TRUE, try_suggested_sip_codec(), ast_variable::value, var, and ast_channel::varshead.
Referenced by __sip_subscribe_mwi_do(), cc_handle_publish_error(), do_proxy_auth(), manager_sipnotify(), proc_422_rsp(), sip_call(), sip_cc_monitor_request_cc(), sip_cli_notify(), sip_monitor_instance_destructor(), sip_poke_peer(), and transmit_publish().
12227 { 12228 struct sip_request req; 12229 struct ast_variable *var; 12230 12231 req.method = sipmethod; 12232 if (init) {/* Bump branch even on initial requests */ 12233 p->branch ^= ast_random(); 12234 p->invite_branch = p->branch; 12235 build_via(p); 12236 } 12237 if (init > 1) { 12238 initreqprep(&req, p, sipmethod, explicit_uri); 12239 } else { 12240 /* If init=1, we should not generate a new branch. If it's 0, we need a new branch. */ 12241 reqprep(&req, p, sipmethod, 0, init ? 0 : 1); 12242 } 12243 12244 if (p->options && p->options->auth) { 12245 add_header(&req, p->options->authheader, p->options->auth); 12246 } 12247 append_date(&req); 12248 if (sipmethod == SIP_REFER) { /* Call transfer */ 12249 if (p->refer) { 12250 char buf[SIPBUFSIZE]; 12251 if (!ast_strlen_zero(p->refer->refer_to)) { 12252 add_header(&req, "Refer-To", p->refer->refer_to); 12253 } 12254 if (!ast_strlen_zero(p->refer->referred_by)) { 12255 snprintf(buf, sizeof(buf), "%s <%s>", p->refer->referred_by_name, p->refer->referred_by); 12256 add_header(&req, "Referred-By", buf); 12257 } 12258 } 12259 } else if (sipmethod == SIP_SUBSCRIBE) { 12260 char buf[SIPBUFSIZE]; 12261 if (p->subscribed == MWI_NOTIFICATION) { 12262 add_header(&req, "Event", "message-summary"); 12263 add_header(&req, "Accept", "application/simple-message-summary"); 12264 } else if (p->subscribed == CALL_COMPLETION) { 12265 add_header(&req, "Event", "call-completion"); 12266 add_header(&req, "Accept", "application/call-completion"); 12267 } 12268 snprintf(buf, sizeof(buf), "%d", p->expiry); 12269 add_header(&req, "Expires", buf); 12270 } 12271 12272 /* This new INVITE is part of an attended transfer. Make sure that the 12273 other end knows and replace the current call with this new call */ 12274 if (p->options && !ast_strlen_zero(p->options->replaces)) { 12275 add_header(&req, "Replaces", p->options->replaces); 12276 add_header(&req, "Require", "replaces"); 12277 } 12278 12279 /* Add Session-Timers related headers */ 12280 if (st_get_mode(p, 0) == SESSION_TIMER_MODE_ORIGINATE) { 12281 char i2astr[10]; 12282 12283 if (!p->stimer->st_interval) { 12284 p->stimer->st_interval = st_get_se(p, TRUE); 12285 } 12286 12287 p->stimer->st_active = TRUE; 12288 12289 snprintf(i2astr, sizeof(i2astr), "%d", p->stimer->st_interval); 12290 add_header(&req, "Session-Expires", i2astr); 12291 snprintf(i2astr, sizeof(i2astr), "%d", st_get_se(p, FALSE)); 12292 add_header(&req, "Min-SE", i2astr); 12293 } 12294 12295 add_header(&req, "Allow", ALLOWED_METHODS); 12296 add_supported_header(p, &req); 12297 12298 if (p->options && p->options->addsipheaders && p->owner) { 12299 struct ast_channel *chan = p->owner; /* The owner channel */ 12300 struct varshead *headp; 12301 12302 ast_channel_lock(chan); 12303 12304 headp = &chan->varshead; 12305 12306 if (!headp) { 12307 ast_log(LOG_WARNING, "No Headp for the channel...ooops!\n"); 12308 } else { 12309 const struct ast_var_t *current; 12310 AST_LIST_TRAVERSE(headp, current, entries) { 12311 /* SIPADDHEADER: Add SIP header to outgoing call */ 12312 if (!strncasecmp(ast_var_name(current), "SIPADDHEADER", strlen("SIPADDHEADER"))) { 12313 char *content, *end; 12314 const char *header = ast_var_value(current); 12315 char *headdup = ast_strdupa(header); 12316 12317 /* Strip of the starting " (if it's there) */ 12318 if (*headdup == '"') { 12319 headdup++; 12320 } 12321 if ((content = strchr(headdup, ':'))) { 12322 *content++ = '\0'; 12323 content = ast_skip_blanks(content); /* Skip white space */ 12324 /* Strip the ending " (if it's there) */ 12325 end = content + strlen(content) -1; 12326 if (*end == '"') { 12327 *end = '\0'; 12328 } 12329 12330 add_header(&req, headdup, content); 12331 if (sipdebug) { 12332 ast_debug(1, "Adding SIP Header \"%s\" with content :%s: \n", headdup, content); 12333 } 12334 } 12335 } 12336 } 12337 } 12338 12339 ast_channel_unlock(chan); 12340 } 12341 if ((sipmethod == SIP_INVITE || sipmethod == SIP_UPDATE) && ast_test_flag(&p->flags[0], SIP_SENDRPID)) 12342 add_rpid(&req, p); 12343 if (sipmethod == SIP_INVITE) { 12344 add_diversion_header(&req, p); 12345 } 12346 if (sdp) { 12347 memset(p->offered_media, 0, sizeof(p->offered_media)); 12348 if (p->udptl && p->t38.state == T38_LOCAL_REINVITE) { 12349 ast_debug(1, "T38 is in state %d on channel %s\n", p->t38.state, p->owner ? p->owner->name : "<none>"); 12350 add_sdp(&req, p, FALSE, FALSE, TRUE); 12351 } else if (p->rtp) { 12352 try_suggested_sip_codec(p); 12353 add_sdp(&req, p, FALSE, TRUE, FALSE); 12354 } 12355 } else if (p->notify) { 12356 for (var = p->notify->headers; var; var = var->next) { 12357 add_header(&req, var->name, var->value); 12358 } 12359 if (ast_str_strlen(p->notify->content)) { 12360 add_content(&req, ast_str_buffer(p->notify->content)); 12361 } 12362 } else if (sipmethod == SIP_PUBLISH) { 12363 char expires[SIPBUFSIZE]; 12364 12365 switch (p->epa_entry->static_data->event) { 12366 case CALL_COMPLETION: 12367 snprintf(expires, sizeof(expires), "%d", p->expiry); 12368 add_header(&req, "Event", "call-completion"); 12369 add_header(&req, "Expires", expires); 12370 if (p->epa_entry->publish_type != SIP_PUBLISH_INITIAL) { 12371 add_header(&req, "SIP-If-Match", p->epa_entry->entity_tag); 12372 } 12373 12374 if (!ast_strlen_zero(p->epa_entry->body)) { 12375 add_header(&req, "Content-Type", "application/pidf+xml"); 12376 add_content(&req, p->epa_entry->body); 12377 } 12378 default: 12379 break; 12380 } 12381 } 12382 12383 if (!p->initreq.headers || init > 2) { 12384 initialize_initreq(p, &req); 12385 } 12386 if (sipmethod == SIP_INVITE || sipmethod == SIP_SUBSCRIBE) { 12387 p->lastinvite = p->ocseq; 12388 } 12389 return send_request(p, &req, init ? XMIT_CRITICAL : XMIT_RELIABLE, p->ocseq); 12390 }
| static int transmit_message_with_text | ( | struct sip_pvt * | p, | |
| const char * | text | |||
| ) | [static] |
Transmit text with SIP MESSAGE method.
Definition at line 13505 of file chan_sip.c.
References add_text(), reqprep(), and send_request().
Referenced by sip_park_thread(), and sip_sendtext().
13506 { 13507 struct sip_request req; 13508 13509 reqprep(&req, p, SIP_MESSAGE, 0, 1); 13510 add_text(&req, text); 13511 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 13512 }
| static int transmit_notify_with_mwi | ( | struct sip_pvt * | p, | |
| int | newmsgs, | |||
| int | oldmsgs, | |||
| const char * | vmexten | |||
| ) | [static] |
Notify user of messages waiting in voicemail (RFC3842).
Definition at line 12897 of file chan_sip.c.
References add_content(), add_header(), ast_sockaddr_port, ast_sockaddr_stringify_host_remote(), ast_str_alloca, ast_str_append(), ast_test_flag, exten, get_transport(), initialize_initreq(), initreqprep(), ourport, S_OR, send_request(), and sip_standard_port().
Referenced by sip_send_mwi_to_peer().
12898 { 12899 struct sip_request req; 12900 struct ast_str *out = ast_str_alloca(500); 12901 int ourport = (p->fromdomainport) ? p->fromdomainport : ast_sockaddr_port(&p->ourip); 12902 const char *domain; 12903 const char *exten = S_OR(vmexten, default_vmexten); 12904 12905 initreqprep(&req, p, SIP_NOTIFY, NULL); 12906 add_header(&req, "Event", "message-summary"); 12907 add_header(&req, "Content-Type", default_notifymime); 12908 ast_str_append(&out, 0, "Messages-Waiting: %s\r\n", newmsgs ? "yes" : "no"); 12909 12910 /* domain initialization occurs here because initreqprep changes ast_sockaddr_stringify string. */ 12911 domain = S_OR(p->fromdomain, ast_sockaddr_stringify_host_remote(&p->ourip)); 12912 12913 if (!sip_standard_port(p->socket.type, ourport)) { 12914 if (p->socket.type == SIP_TRANSPORT_UDP) { 12915 ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d\r\n", exten, domain, ourport); 12916 } else { 12917 ast_str_append(&out, 0, "Message-Account: sip:%s@%s:%d;transport=%s\r\n", exten, domain, ourport, get_transport(p->socket.type)); 12918 } 12919 } else { 12920 if (p->socket.type == SIP_TRANSPORT_UDP) { 12921 ast_str_append(&out, 0, "Message-Account: sip:%s@%s\r\n", exten, domain); 12922 } else { 12923 ast_str_append(&out, 0, "Message-Account: sip:%s@%s;transport=%s\r\n", exten, domain, get_transport(p->socket.type)); 12924 } 12925 } 12926 /* Cisco has a bug in the SIP stack where it can't accept the 12927 (0/0) notification. This can temporarily be disabled in 12928 sip.conf with the "buggymwi" option */ 12929 ast_str_append(&out, 0, "Voice-Message: %d/%d%s\r\n", 12930 newmsgs, oldmsgs, (ast_test_flag(&p->flags[1], SIP_PAGE2_BUGGY_MWI) ? "" : " (0/0)")); 12931 12932 if (p->subscribed) { 12933 if (p->expiry) { 12934 add_header(&req, "Subscription-State", "active"); 12935 } else { /* Expired */ 12936 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 12937 } 12938 } 12939 12940 add_content(&req, out->str); 12941 12942 if (!p->initreq.headers) { 12943 initialize_initreq(p, &req); 12944 } 12945 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12946 }
| static int transmit_notify_with_sipfrag | ( | struct sip_pvt * | p, | |
| int | cseq, | |||
| char * | message, | |||
| int | terminate | |||
| ) | [static] |
Notify a transferring party of the status of transfer (RFC3515).
Definition at line 12949 of file chan_sip.c.
References add_content(), add_header(), add_supported_header(), initialize_initreq(), reqprep(), and send_request().
Referenced by handle_request_refer(), local_attended_transfer(), and sip_park_thread().
12950 { 12951 struct sip_request req; 12952 char tmp[SIPBUFSIZE/2]; 12953 12954 reqprep(&req, p, SIP_NOTIFY, 0, 1); 12955 snprintf(tmp, sizeof(tmp), "refer;id=%d", cseq); 12956 add_header(&req, "Event", tmp); 12957 add_header(&req, "Subscription-state", terminate ? "terminated;reason=noresource" : "active"); 12958 add_header(&req, "Content-Type", "message/sipfrag;version=2.0"); 12959 add_header(&req, "Allow", ALLOWED_METHODS); 12960 add_supported_header(p, &req); 12961 12962 snprintf(tmp, sizeof(tmp), "SIP/2.0 %s\r\n", message); 12963 add_content(&req, tmp); 12964 12965 if (!p->initreq.headers) { 12966 initialize_initreq(p, &req); 12967 } 12968 12969 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12970 }
| static int transmit_provisional_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| int | with_sdp | |||
| ) | [static] |
Definition at line 10845 of file chan_sip.c.
References FALSE, transmit_response(), transmit_response_with_sdp(), and update_provisional_keepalive().
Referenced by handle_request_invite(), sip_indicate(), and sip_write().
10846 { 10847 int res; 10848 10849 if (!(res = with_sdp ? transmit_response_with_sdp(p, msg, req, XMIT_UNRELIABLE, FALSE, FALSE) : transmit_response(p, msg, req))) { 10850 p->last_provisional = msg; 10851 update_provisional_keepalive(p, with_sdp); 10852 } 10853 10854 return res; 10855 }
| static int transmit_publish | ( | struct sip_epa_entry * | epa_entry, | |
| enum sip_publish_type | publish_type, | |||
| const char *const | explicit_uri | |||
| ) | [static] |
Definition at line 12182 of file chan_sip.c.
References ao2_ref, ast_set_flag, ast_sip_ouraddrfor(), create_addr(), dialog_unlink_all(), FALSE, sip_alloc(), sip_pvt_lock, sip_pvt_unlock, sip_scheddestroy(), transmit_invite(), and TRUE.
Referenced by handle_cc_notify(), sip_cc_monitor_suspend(), sip_cc_monitor_unsuspend(), and sip_monitor_instance_destructor().
12183 { 12184 struct sip_pvt *pvt; 12185 int expires; 12186 12187 epa_entry->publish_type = publish_type; 12188 12189 if (!(pvt = sip_alloc(NULL, NULL, 0, SIP_PUBLISH, NULL))) { 12190 return -1; 12191 } 12192 12193 sip_pvt_lock(pvt); 12194 12195 if (create_addr(pvt, epa_entry->destination, NULL, TRUE, NULL)) { 12196 sip_pvt_unlock(pvt); 12197 dialog_unlink_all(pvt); 12198 dialog_unref(pvt, "create_addr failed in transmit_publish. Unref dialog"); 12199 return -1; 12200 } 12201 ast_sip_ouraddrfor(&pvt->sa, &pvt->ourip, pvt); 12202 ast_set_flag(&pvt->flags[0], SIP_OUTGOING); 12203 expires = (publish_type == SIP_PUBLISH_REMOVE) ? 0 : DEFAULT_PUBLISH_EXPIRES; 12204 pvt->expiry = expires; 12205 12206 /* Bump refcount for sip_pvt's reference */ 12207 ao2_ref(epa_entry, +1); 12208 pvt->epa_entry = epa_entry; 12209 12210 transmit_invite(pvt, SIP_PUBLISH, FALSE, 2, explicit_uri); 12211 sip_pvt_unlock(pvt); 12212 sip_scheddestroy(pvt, DEFAULT_TRANS_TIMEOUT); 12213 dialog_unref(pvt, "Done with the sip_pvt allocated for transmitting PUBLISH"); 12214 return 0; 12215 }
| static int transmit_refer | ( | struct sip_pvt * | p, | |
| const char * | dest | |||
| ) | [static] |
Transmit SIP REFER message (initiated by the transfer() dialplan application.
Definition at line 13536 of file chan_sip.c.
References add_header(), add_supported_header(), ast_copy_string(), ast_debug, ast_log(), ast_string_field_set, ast_strlen_zero(), ast_test_flag, FALSE, get_header(), get_in_brackets(), LOG_NOTICE, reqprep(), send_request(), sip_refer_allocate(), and TRUE.
Referenced by sip_transfer().
13537 { 13538 struct sip_request req = { 13539 .headers = 0, 13540 }; 13541 char from[256]; 13542 const char *of; 13543 char *c; 13544 char referto[256]; 13545 int use_tls=FALSE; 13546 13547 if (sipdebug) { 13548 ast_debug(1, "SIP transfer of %s to %s\n", p->callid, dest); 13549 } 13550 13551 /* Are we transfering an inbound or outbound call ? */ 13552 if (ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 13553 of = get_header(&p->initreq, "To"); 13554 } else { 13555 of = get_header(&p->initreq, "From"); 13556 } 13557 13558 ast_copy_string(from, of, sizeof(from)); 13559 of = get_in_brackets(from); 13560 ast_string_field_set(p, from, of); 13561 if (!strncasecmp(of, "sip:", 4)) { 13562 of += 4; 13563 } else if (!strncasecmp(of, "sips:", 5)) { 13564 of += 5; 13565 use_tls = TRUE; 13566 } else { 13567 ast_log(LOG_NOTICE, "From address missing 'sip(s):', assuming sip:\n"); 13568 } 13569 /* Get just the username part */ 13570 if (strchr(dest, '@')) { 13571 c = NULL; 13572 } else if ((c = strchr(of, '@'))) { 13573 *c++ = '\0'; 13574 } 13575 if (c) { 13576 snprintf(referto, sizeof(referto), "<sip%s:%s@%s>", use_tls ? "s" : "", dest, c); 13577 } else { 13578 snprintf(referto, sizeof(referto), "<sip%s:%s>", use_tls ? "s" : "", dest); 13579 } 13580 13581 /* save in case we get 407 challenge */ 13582 sip_refer_allocate(p); 13583 ast_copy_string(p->refer->refer_to, referto, sizeof(p->refer->refer_to)); 13584 ast_copy_string(p->refer->referred_by, p->our_contact, sizeof(p->refer->referred_by)); 13585 p->refer->status = REFER_SENT; /* Set refer status */ 13586 13587 reqprep(&req, p, SIP_REFER, 0, 1); 13588 13589 add_header(&req, "Refer-To", referto); 13590 add_header(&req, "Allow", ALLOWED_METHODS); 13591 add_supported_header(p, &req); 13592 if (!ast_strlen_zero(p->our_contact)) { 13593 add_header(&req, "Referred-By", p->our_contact); 13594 } 13595 13596 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 13597 13598 /* We should propably wait for a NOTIFY here until we ack the transfer */ 13599 /* Maybe fork a new thread and wait for a STATUS of REFER_200OK on the refer status before returning to app_transfer */ 13600 13601 /*! \todo In theory, we should hang around and wait for a reply, before 13602 returning to the dial plan here. Don't know really how that would 13603 affect the transfer() app or the pbx, but, well, to make this 13604 useful we should have a STATUS code on transfer(). 13605 */ 13606 }
| static int transmit_register | ( | struct sip_registry * | r, | |
| int | sipmethod, | |||
| const char * | auth, | |||
| const char * | authheader | |||
| ) | [static] |
Transmit register to SIP proxy or UA auth = NULL on the initial registration (from sip_reregister()).
Definition at line 13250 of file chan_sip.c.
References add_header(), add_header_max_forwards(), append_history, ast_debug, ast_dnsmgr_lookup_cb(), ast_log(), ast_random(), ast_sched_add(), AST_SCHED_REPLACE_UNREF, ast_set_flag, ast_sip_ouraddrfor(), ast_sockaddr_cmp(), ast_sockaddr_isnull(), ast_sockaddr_port, ast_sockaddr_set_port, ast_string_field_set, ast_strlen_zero(), ast_verbose, build_callid_registry(), build_contact(), build_reply_digest(), build_via(), create_addr(), dialog_unlink_all(), exten, FALSE, find_peer(), get_address_family_filter(), get_srv_protocol(), get_srv_service(), init_req(), initialize_initreq(), internip, ast_tcptls_session_args::local_address, LOG_NOTICE, LOG_WARNING, make_our_tag(), MAXHOSTNAMELEN, obproxy_get(), on_dns_update_peer(), on_dns_update_registry(), REG_STATE_AUTHSENT, REG_STATE_REGSENT, registry_addref(), registry_unref(), S_OR, send_request(), set_socket_transport(), sip_alloc(), sip_cfg, sip_debug_test_pvt(), sip_methods, sip_reg_timeout(), sip_sanitized_host(), cfsip_methods::text, TRUE, and unref_peer().
Referenced by __sip_do_register(), do_register_auth(), handle_response_register(), and sip_reg_timeout().
13251 { 13252 struct sip_request req; 13253 char from[256]; 13254 char to[256]; 13255 char tmp[80]; 13256 char addr[80]; 13257 struct sip_pvt *p; 13258 struct sip_peer *peer = NULL; 13259 int res; 13260 int portno = 0; 13261 13262 /* exit if we are already in process with this registrar ?*/ 13263 if (r == NULL || ((auth == NULL) && (r->regstate == REG_STATE_REGSENT || r->regstate == REG_STATE_AUTHSENT))) { 13264 if (r) { 13265 ast_log(LOG_NOTICE, "Strange, trying to register %s@%s when registration already pending\n", r->username, r->hostname); 13266 } 13267 return 0; 13268 } 13269 13270 if (r->dnsmgr == NULL) { 13271 char transport[MAXHOSTNAMELEN]; 13272 peer = find_peer(r->hostname, NULL, TRUE, FINDPEERS, FALSE, 0); 13273 snprintf(transport, sizeof(transport), "_%s._%s",get_srv_service(r->transport), get_srv_protocol(r->transport)); /* have to use static get_transport function */ 13274 r->us.ss.ss_family = get_address_family_filter(r->transport); /* Filter address family */ 13275 13276 /* No point in doing a DNS lookup of the register hostname if we're just going to 13277 * end up using an outbound proxy. obproxy_get is safe to call with either of r->call 13278 * or peer NULL. Since we're only concerned with its existence, we're not going to 13279 * bother getting a ref to the proxy*/ 13280 if (!obproxy_get(r->call, peer)) { 13281 registry_addref(r, "add reg ref for dnsmgr"); 13282 ast_dnsmgr_lookup_cb(peer ? peer->tohost : r->hostname, &r->us, &r->dnsmgr, sip_cfg.srvlookup ? transport : NULL, on_dns_update_registry, r); 13283 if (!r->dnsmgr) { 13284 /*dnsmgr refresh disabled, no reference added! */ 13285 registry_unref(r, "remove reg ref, dnsmgr disabled"); 13286 } 13287 } 13288 if (peer) { 13289 peer = unref_peer(peer, "removing peer ref for dnsmgr_lookup"); 13290 } 13291 } 13292 13293 if (r->call) { /* We have a registration */ 13294 if (!auth) { 13295 ast_log(LOG_WARNING, "Already have a REGISTER going on to %s@%s?? \n", r->username, r->hostname); 13296 return 0; 13297 } else { 13298 p = dialog_ref(r->call, "getting a copy of the r->call dialog in transmit_register"); 13299 make_our_tag(p); /* create a new local tag for every register attempt */ 13300 ast_string_field_set(p, theirtag, NULL); /* forget their old tag, so we don't match tags when getting response */ 13301 } 13302 } else { 13303 /* Build callid for registration if we haven't registered before */ 13304 if (!r->callid_valid) { 13305 build_callid_registry(r, &internip, default_fromdomain); 13306 r->callid_valid = TRUE; 13307 } 13308 /* Allocate SIP dialog for registration */ 13309 if (!(p = sip_alloc( r->callid, NULL, 0, SIP_REGISTER, NULL))) { 13310 ast_log(LOG_WARNING, "Unable to allocate registration transaction (memory or socket error)\n"); 13311 return 0; 13312 } 13313 13314 if (p->do_history) { 13315 append_history(p, "RegistryInit", "Account: %s@%s", r->username, r->hostname); 13316 } 13317 13318 /* Use port number specified if no SRV record was found */ 13319 if (!ast_sockaddr_isnull(&r->us)) { 13320 if (!ast_sockaddr_port(&r->us) && r->portno) { 13321 ast_sockaddr_set_port(&r->us, r->portno); 13322 } 13323 13324 /* It is possible that DNS was unavailable at the time the peer was created. 13325 * Here, if we've updated the address in the registry via manually calling 13326 * ast_dnsmgr_lookup_cb() above, then we call the same function that dnsmgr would 13327 * call if it was updating a peer's address */ 13328 if ((peer = find_peer(S_OR(r->peername, r->hostname), NULL, TRUE, FINDPEERS, FALSE, 0))) { 13329 if (ast_sockaddr_cmp(&peer->addr, &r->us)) { 13330 on_dns_update_peer(&peer->addr, &r->us, peer); 13331 } 13332 peer = unref_peer(peer, "unref after find_peer"); 13333 } 13334 } 13335 13336 /* Find address to hostname */ 13337 if (create_addr(p, S_OR(r->peername, r->hostname), &r->us, 0, NULL)) { 13338 /* we have what we hope is a temporary network error, 13339 * probably DNS. We need to reschedule a registration try */ 13340 dialog_unlink_all(p); 13341 p = dialog_unref(p, "unref dialog after unlink_all"); 13342 if (r->timeout > -1) { 13343 AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r, 13344 registry_unref(_data, "del for REPLACE of registry ptr"), 13345 registry_unref(r, "object ptr dec when SCHED_REPLACE add failed"), 13346 registry_addref(r,"add for REPLACE registry ptr")); 13347 ast_log(LOG_WARNING, "Still have a registration timeout for %s@%s (create_addr() error), %d\n", r->username, r->hostname, r->timeout); 13348 } else { 13349 r->timeout = ast_sched_add(sched, global_reg_timeout * 1000, sip_reg_timeout, registry_addref(r, "add for REPLACE registry ptr")); 13350 ast_log(LOG_WARNING, "Probably a DNS error for registration to %s@%s, trying REGISTER again (after %d seconds)\n", r->username, r->hostname, global_reg_timeout); 13351 } 13352 r->regattempts++; 13353 return 0; 13354 } 13355 13356 /* Copy back Call-ID in case create_addr changed it */ 13357 ast_string_field_set(r, callid, p->callid); 13358 13359 if (!r->dnsmgr && r->portno) { 13360 ast_sockaddr_set_port(&p->sa, r->portno); 13361 ast_sockaddr_set_port(&p->recv, r->portno); 13362 } 13363 if (!ast_strlen_zero(p->fromdomain)) { 13364 portno = (p->fromdomainport) ? p->fromdomainport : STANDARD_SIP_PORT; 13365 } else if (!ast_strlen_zero(r->regdomain)) { 13366 portno = (r->regdomainport) ? r->regdomainport : STANDARD_SIP_PORT; 13367 } else { 13368 portno = ast_sockaddr_port(&p->sa); 13369 } 13370 13371 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Registration is outgoing call */ 13372 r->call = dialog_ref(p, "copying dialog into registry r->call"); /* Save pointer to SIP dialog */ 13373 p->registry = registry_addref(r, "transmit_register: addref to p->registry in transmit_register"); /* Add pointer to registry in packet */ 13374 if (!ast_strlen_zero(r->secret)) { /* Secret (password) */ 13375 ast_string_field_set(p, peersecret, r->secret); 13376 } 13377 if (!ast_strlen_zero(r->md5secret)) 13378 ast_string_field_set(p, peermd5secret, r->md5secret); 13379 /* User name in this realm 13380 - if authuser is set, use that, otherwise use username */ 13381 if (!ast_strlen_zero(r->authuser)) { 13382 ast_string_field_set(p, peername, r->authuser); 13383 ast_string_field_set(p, authname, r->authuser); 13384 } else if (!ast_strlen_zero(r->username)) { 13385 ast_string_field_set(p, peername, r->username); 13386 ast_string_field_set(p, authname, r->username); 13387 ast_string_field_set(p, fromuser, r->username); 13388 } 13389 if (!ast_strlen_zero(r->username)) { 13390 ast_string_field_set(p, username, r->username); 13391 } 13392 /* Save extension in packet */ 13393 if (!ast_strlen_zero(r->callback)) { 13394 ast_string_field_set(p, exten, r->callback); 13395 } 13396 13397 /* Set transport and port so the correct contact is built */ 13398 set_socket_transport(&p->socket, r->transport); 13399 if (r->transport == SIP_TRANSPORT_TLS || r->transport == SIP_TRANSPORT_TCP) { 13400 p->socket.port = 13401 htons(ast_sockaddr_port(&sip_tcp_desc.local_address)); 13402 } 13403 13404 /* 13405 check which address we should use in our contact header 13406 based on whether the remote host is on the external or 13407 internal network so we can register through nat 13408 */ 13409 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 13410 build_contact(p); 13411 } 13412 13413 /* set up a timeout */ 13414 if (auth == NULL) { 13415 if (r->timeout > -1) { 13416 ast_log(LOG_WARNING, "Still have a registration timeout, #%d - deleting it\n", r->timeout); 13417 } 13418 AST_SCHED_REPLACE_UNREF(r->timeout, sched, global_reg_timeout * 1000, sip_reg_timeout, r, 13419 registry_unref(_data,"reg ptr unrefed from del in SCHED_REPLACE"), 13420 registry_unref(r,"reg ptr unrefed from add failure in SCHED_REPLACE"), 13421 registry_addref(r,"reg ptr reffed from add in SCHED_REPLACE")); 13422 ast_debug(1, "Scheduled a registration timeout for %s id #%d \n", r->hostname, r->timeout); 13423 } 13424 13425 snprintf(from, sizeof(from), "<sip:%s@%s>;tag=%s", r->username, S_OR(r->regdomain, sip_sanitized_host(p->tohost)), p->tag); 13426 if (!ast_strlen_zero(p->theirtag)) { 13427 snprintf(to, sizeof(to), "<sip:%s@%s>;tag=%s", r->username, S_OR(r->regdomain, sip_sanitized_host(p->tohost)), p->theirtag); 13428 } else { 13429 snprintf(to, sizeof(to), "<sip:%s@%s>", r->username, S_OR(r->regdomain, sip_sanitized_host(p->tohost))); 13430 } 13431 13432 /* Fromdomain is what we are registering to, regardless of actual 13433 host name from SRV */ 13434 if (portno && portno != STANDARD_SIP_PORT) { 13435 snprintf(addr, sizeof(addr), "sip:%s:%d", S_OR(p->fromdomain,S_OR(r->regdomain, sip_sanitized_host(r->hostname))), portno); 13436 } else { 13437 snprintf(addr, sizeof(addr), "sip:%s", S_OR(p->fromdomain,S_OR(r->regdomain, sip_sanitized_host(r->hostname)))); 13438 } 13439 13440 ast_string_field_set(p, uri, addr); 13441 13442 p->branch ^= ast_random(); 13443 13444 init_req(&req, sipmethod, addr); 13445 13446 /* Add to CSEQ */ 13447 snprintf(tmp, sizeof(tmp), "%u %s", ++r->ocseq, sip_methods[sipmethod].text); 13448 p->ocseq = r->ocseq; 13449 13450 build_via(p); 13451 add_header(&req, "Via", p->via); 13452 add_header_max_forwards(p, &req); 13453 add_header(&req, "From", from); 13454 add_header(&req, "To", to); 13455 add_header(&req, "Call-ID", p->callid); 13456 add_header(&req, "CSeq", tmp); 13457 if (!ast_strlen_zero(global_useragent)) 13458 add_header(&req, "User-Agent", global_useragent); 13459 13460 if (auth) { /* Add auth header */ 13461 add_header(&req, authheader, auth); 13462 } else if (!ast_strlen_zero(r->nonce)) { 13463 char digest[1024]; 13464 13465 /* We have auth data to reuse, build a digest header. 13466 * Note, this is not always useful because some parties do not 13467 * like nonces to be reused (for good reasons!) so they will 13468 * challenge us anyways. 13469 */ 13470 if (sipdebug) { 13471 ast_debug(1, " >>> Re-using Auth data for %s@%s\n", r->username, r->hostname); 13472 } 13473 ast_string_field_set(p, realm, r->realm); 13474 ast_string_field_set(p, nonce, r->nonce); 13475 ast_string_field_set(p, domain, r->authdomain); 13476 ast_string_field_set(p, opaque, r->opaque); 13477 ast_string_field_set(p, qop, r->qop); 13478 p->noncecount = ++r->noncecount; 13479 13480 memset(digest, 0, sizeof(digest)); 13481 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) { 13482 add_header(&req, "Authorization", digest); 13483 } else { 13484 ast_log(LOG_NOTICE, "No authorization available for authentication of registration to %s@%s\n", r->username, r->hostname); 13485 } 13486 } 13487 13488 snprintf(tmp, sizeof(tmp), "%d", r->expiry); 13489 add_header(&req, "Expires", tmp); 13490 add_header(&req, "Contact", p->our_contact); 13491 13492 initialize_initreq(p, &req); 13493 if (sip_debug_test_pvt(p)) { 13494 ast_verbose("REGISTER %d headers, %d lines\n", p->initreq.headers, p->initreq.lines); 13495 } 13496 r->regstate = auth ? REG_STATE_AUTHSENT : REG_STATE_REGSENT; 13497 r->regattempts++; /* Another attempt */ 13498 ast_debug(4, "REGISTER attempt %d to %s@%s\n", r->regattempts, r->username, r->hostname); 13499 res = send_request(p, &req, XMIT_CRITICAL, p->ocseq); 13500 dialog_unref(p, "p is finished here at the end of transmit_register"); 13501 return res; 13502 }
| static int transmit_reinvite_with_sdp | ( | struct sip_pvt * | p, | |
| int | t38version, | |||
| int | oldsdp | |||
| ) | [static] |
Transmit reinvite with SDP.
If t38version is TRUE, we send T38 SDP for re-invite from audio/video to T38 UDPTL transmission on the channel
If oldsdp is TRUE then the SDP version number is not incremented. This is needed for Session-Timers so we can send a re-invite to refresh the SIP session without modifying the media session.
Definition at line 11887 of file chan_sip.c.
References add_header(), add_rpid(), add_sdp(), add_supported_header(), append_history, ast_set_flag, ast_test_flag, FALSE, initialize_initreq(), reqprep(), send_request(), TRUE, and try_suggested_sip_codec().
Referenced by check_pendings(), handle_response_invite(), interpret_t38_parameters(), proc_session_timer(), sip_sendhtml(), sip_set_rtp_peer(), and sip_set_udptl_peer().
11888 { 11889 struct sip_request req; 11890 11891 reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ? SIP_UPDATE : SIP_INVITE, 0, 1); 11892 11893 add_header(&req, "Allow", ALLOWED_METHODS); 11894 add_supported_header(p, &req); 11895 if (sipdebug) { 11896 if (oldsdp == TRUE) 11897 add_header(&req, "X-asterisk-Info", "SIP re-invite (Session-Timers)"); 11898 else 11899 add_header(&req, "X-asterisk-Info", "SIP re-invite (External RTP bridge)"); 11900 } 11901 11902 if (ast_test_flag(&p->flags[0], SIP_SENDRPID)) 11903 add_rpid(&req, p); 11904 11905 if (p->do_history) { 11906 append_history(p, "ReInv", "Re-invite sent"); 11907 } 11908 memset(p->offered_media, 0, sizeof(p->offered_media)); 11909 11910 try_suggested_sip_codec(p); 11911 if (t38version) { 11912 add_sdp(&req, p, oldsdp, FALSE, TRUE); 11913 } else { 11914 add_sdp(&req, p, oldsdp, TRUE, FALSE); 11915 } 11916 11917 /* Use this as the basis */ 11918 initialize_initreq(p, &req); 11919 p->lastinvite = p->ocseq; 11920 ast_set_flag(&p->flags[0], SIP_OUTGOING); /* Change direction of this dialog */ 11921 p->ongoing_reinvite = 1; 11922 return send_request(p, &req, XMIT_CRITICAL, p->ocseq); 11923 }
| static int transmit_request | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| uint32_t | seqno, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit generic SIP request returns XMIT_ERROR if transmit failed with a critical error (don't retry).
Definition at line 13679 of file chan_sip.c.
References add_header(), reqprep(), and send_request().
Referenced by check_pendings(), handle_response(), handle_response_invite(), and sip_hangup().
13680 { 13681 struct sip_request resp; 13682 13683 reqprep(&resp, p, sipmethod, seqno, newbranch); 13684 if (sipmethod == SIP_CANCEL && p->answered_elsewhere) { 13685 add_header(&resp, "Reason", "SIP;cause=200;text=\"Call completed elsewhere\""); 13686 } 13687 13688 if (sipmethod == SIP_ACK) { 13689 p->invitestate = INV_CONFIRMED; 13690 } 13691 13692 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 13693 }
| static int transmit_request_with_auth | ( | struct sip_pvt * | p, | |
| int | sipmethod, | |||
| uint32_t | seqno, | |||
| enum xmittype | reliable, | |||
| int | newbranch | |||
| ) | [static] |
Transmit SIP request, auth added.
Definition at line 13711 of file chan_sip.c.
References add_header(), ast_cause2str(), ast_log(), ast_strlen_zero(), ast_test_flag, auth_headers(), build_reply_digest(), dummy(), LOG_WARNING, reqprep(), and send_request().
Referenced by __sip_autodestruct(), check_pendings(), and sip_hangup().
13712 { 13713 struct sip_request resp; 13714 13715 reqprep(&resp, p, sipmethod, seqno, newbranch); 13716 if (!ast_strlen_zero(p->realm)) { 13717 char digest[1024]; 13718 13719 memset(digest, 0, sizeof(digest)); 13720 if(!build_reply_digest(p, sipmethod, digest, sizeof(digest))) { 13721 char *dummy, *response; 13722 enum sip_auth_type code = p->options ? p->options->auth_type : PROXY_AUTH; /* XXX force 407 if unknown */ 13723 auth_headers(code, &dummy, &response); 13724 add_header(&resp, response, digest); 13725 } else { 13726 ast_log(LOG_WARNING, "No authentication available for call %s\n", p->callid); 13727 } 13728 } 13729 /* If we are hanging up and know a cause for that, send it in clear text to make 13730 debugging easier. */ 13731 if (sipmethod == SIP_BYE) { 13732 char buf[20]; 13733 13734 if (ast_test_flag(&p->flags[1], SIP_PAGE2_Q850_REASON) && p->hangupcause) { 13735 sprintf(buf, "Q.850;cause=%i", p->hangupcause & 0x7f); 13736 add_header(&resp, "Reason", buf); 13737 } 13738 13739 add_header(&resp, "X-Asterisk-HangupCause", ast_cause2str(p->hangupcause)); 13740 snprintf(buf, sizeof(buf), "%d", p->hangupcause); 13741 add_header(&resp, "X-Asterisk-HangupCauseCode", buf); 13742 } 13743 13744 return send_request(p, &resp, reliable, seqno ? seqno : p->ocseq); 13745 }
| static int transmit_response | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Transmit response, no retransmits.
Definition at line 10642 of file chan_sip.c.
References __transmit_response().
Referenced by handle_cc_notify(), handle_cc_subscribe(), handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_info(), handle_request_invite(), handle_request_message(), handle_request_notify(), handle_request_options(), handle_request_publish(), handle_request_refer(), handle_request_subscribe(), handle_request_update(), handle_sip_publish_initial(), handle_sip_publish_modify(), handle_sip_publish_refresh(), handle_sip_publish_remove(), receive_message(), register_verify(), send_provisional_keepalive_full(), sip_cc_agent_destructor(), sip_cc_agent_respond(), sip_indicate(), sip_sendhtml(), transmit_fake_auth_response(), and transmit_provisional_response().
10643 { 10644 return __transmit_response(p, msg, req, XMIT_UNRELIABLE); 10645 }
| static int transmit_response_reliable | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Transmit response, Make sure you get an ACK This is only used for responses to INVITEs, where we need to make sure we get an ACK.
Definition at line 10675 of file chan_sip.c.
References __transmit_response().
Referenced by handle_incoming(), handle_invite_replaces(), handle_request_bye(), handle_request_cancel(), handle_request_invite(), handle_request_publish(), handle_request_subscribe(), interpret_t38_parameters(), sip_hangup(), sip_indicate(), sip_sipredirect(), and sip_t38_abort().
10676 { 10677 return __transmit_response(p, msg, req, req->ignore ? XMIT_UNRELIABLE : XMIT_CRITICAL); 10678 }
| 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 | |||
| ) | [static] |
Transmit response, no retransmits, using a temporary pvt structure.
Definition at line 10589 of file chan_sip.c.
References __transmit_response(), ast_copy_flags, ast_log(), ast_random(), ast_sip_ouraddrfor(), ast_sockaddr_copy(), ast_string_field_init, ast_string_field_set, ast_threadstorage_get(), build_via(), copy_socket_data(), do_setnat(), internip, LOG_ERROR, and make_our_tag().
Referenced by find_call().
10590 { 10591 struct sip_pvt *p = NULL; 10592 10593 if (!(p = ast_threadstorage_get(&ts_temp_pvt, sizeof(*p)))) { 10594 ast_log(LOG_ERROR, "Failed to get temporary pvt\n"); 10595 return -1; 10596 } 10597 10598 /* XXX the structure may be dirty from previous usage. 10599 * Here we should state clearly how we should reinitialize it 10600 * before using it. 10601 * E.g. certainly the threadstorage should be left alone, 10602 * but other thihngs such as flags etc. maybe need cleanup ? 10603 */ 10604 10605 /* Initialize the bare minimum */ 10606 p->method = intended_method; 10607 10608 if (!addr) { 10609 ast_sockaddr_copy(&p->ourip, &internip); 10610 } else { 10611 ast_sockaddr_copy(&p->sa, addr); 10612 ast_sip_ouraddrfor(&p->sa, &p->ourip, p); 10613 } 10614 10615 p->branch = ast_random(); 10616 make_our_tag(p); 10617 p->ocseq = INITIAL_CSEQ; 10618 10619 if (useglobal_nat && addr) { 10620 ast_copy_flags(&p->flags[0], &global_flags[0], SIP_NAT_FORCE_RPORT); 10621 ast_sockaddr_copy(&p->recv, addr); 10622 do_setnat(p); 10623 } 10624 10625 ast_string_field_set(p, fromdomain, default_fromdomain); 10626 p->fromdomainport = default_fromdomainport; 10627 build_via(p); 10628 ast_string_field_set(p, callid, callid); 10629 10630 copy_socket_data(&p->socket, &req->socket); 10631 10632 /* Use this temporary pvt structure to send the message */ 10633 __transmit_response(p, msg, req, XMIT_UNRELIABLE); 10634 10635 /* Free the string fields, but not the pool space */ 10636 ast_string_field_init(p, 0); 10637 10638 return 0; 10639 }
| static int transmit_response_with_allow | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| enum xmittype | reliable | |||
| ) | [static] |
Append Accept header, content length before transmitting response.
Definition at line 10711 of file chan_sip.c.
References add_header(), respprep(), and send_response().
Referenced by handle_incoming(), and handle_request_options().
10712 { 10713 struct sip_request resp; 10714 respprep(&resp, p, msg, req); 10715 add_header(&resp, "Accept", "application/sdp"); 10716 return send_response(p, &resp, reliable, 0); 10717 }
| static int transmit_response_with_auth | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| const char * | rand, | |||
| enum xmittype | reliable, | |||
| const char * | header, | |||
| int | stale | |||
| ) | [static] |
Respond with authorization request.
Definition at line 10732 of file chan_sip.c.
References add_header(), append_history, ast_log(), get_header(), get_realm(), LOG_WARNING, respprep(), and send_response().
Referenced by check_auth(), and transmit_fake_auth_response().
10733 { 10734 struct sip_request resp; 10735 char tmp[512]; 10736 uint32_t seqno = 0; 10737 10738 if (reliable && (sscanf(get_header(req, "CSeq"), "%30u ", &seqno) != 1)) { 10739 ast_log(LOG_WARNING, "Unable to determine sequence number from '%s'\n", get_header(req, "CSeq")); 10740 return -1; 10741 } 10742 /* Choose Realm */ 10743 get_realm(p, req); 10744 10745 /* Stale means that they sent us correct authentication, but 10746 based it on an old challenge (nonce) */ 10747 snprintf(tmp, sizeof(tmp), "Digest algorithm=MD5, realm=\"%s\", nonce=\"%s\"%s", p->realm, randdata, stale ? ", stale=true" : ""); 10748 respprep(&resp, p, msg, req); 10749 add_header(&resp, header, tmp); 10750 append_history(p, "AuthChal", "Auth challenge sent for %s - nc %d", p->username, p->noncecount); 10751 return send_response(p, &resp, reliable, seqno); 10752 }
| static int transmit_response_with_date | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Append date and content length before transmitting response.
Definition at line 10702 of file chan_sip.c.
References append_date(), respprep(), and send_response().
Referenced by handle_response_subscribe(), and register_verify().
10703 { 10704 struct sip_request resp; 10705 respprep(&resp, p, msg, req); 10706 append_date(&resp); 10707 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 10708 }
| static int transmit_response_with_minexpires | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req | |||
| ) | [static] |
Append Min-Expires header, content length before transmitting response.
Definition at line 10720 of file chan_sip.c.
References add_header(), respprep(), and send_response().
Referenced by handle_request_publish(), and handle_request_subscribe().
10721 { 10722 struct sip_request resp; 10723 char tmp[32]; 10724 10725 snprintf(tmp, sizeof(tmp), "%d", min_expiry); 10726 respprep(&resp, p, msg, req); 10727 add_header(&resp, "Min-Expires", tmp); 10728 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 10729 }
| static int transmit_response_with_minse | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| int | minse_int | |||
| ) | [static] |
Transmit 422 response with Min-SE header (Session-Timers).
Definition at line 10658 of file chan_sip.c.
References add_header(), append_date(), respprep(), and send_response().
Referenced by handle_request_invite().
10659 { 10660 struct sip_request resp; 10661 char minse_str[20]; 10662 10663 respprep(&resp, p, msg, req); 10664 append_date(&resp); 10665 10666 snprintf(minse_str, sizeof(minse_str), "%d", minse_int); 10667 add_header(&resp, "Min-SE", minse_str); 10668 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 10669 }
| static int transmit_response_with_retry_after | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| const char * | seconds | |||
| ) | [static] |
Append Retry-After header field when transmitting response.
Definition at line 10693 of file chan_sip.c.
References add_header(), respprep(), and send_response().
Referenced by handle_incoming().
10694 { 10695 struct sip_request resp; 10696 respprep(&resp, p, msg, req); 10697 add_header(&resp, "Retry-After", seconds); 10698 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 10699 }
| 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 | |||
| ) | [static] |
Used for 200 OK and 183 early media.
Definition at line 11797 of file chan_sip.c.
References add_cc_call_info_to_response(), add_rpid(), add_sdp(), ast_debug, ast_log(), ast_rtp_codecs_packetization_set(), ast_rtp_instance_activate(), ast_rtp_instance_get_codecs(), ast_test_flag, FALSE, get_header(), LOG_ERROR, LOG_WARNING, respprep(), send_response(), TRUE, and try_suggested_sip_codec().
Referenced by handle_invite_replaces(), handle_request_invite(), send_provisional_keepalive_full(), sip_answer(), and transmit_provisional_response().
11798 { 11799 struct sip_request resp; 11800 uint32_t seqno; 11801 if (sscanf(get_header(req, "CSeq"), "%30u ", &seqno) != 1) { 11802 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 11803 return -1; 11804 } 11805 respprep(&resp, p, msg, req); 11806 if (rpid == TRUE) { 11807 add_rpid(&resp, p); 11808 } 11809 if (ast_test_flag(&p->flags[0], SIP_OFFER_CC)) { 11810 add_cc_call_info_to_response(p, &resp); 11811 } 11812 if (p->rtp) { 11813 if (!p->autoframing && !ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 11814 ast_debug(1, "Setting framing from config on incoming call\n"); 11815 ast_rtp_codecs_packetization_set(ast_rtp_instance_get_codecs(p->rtp), p->rtp, &p->prefs); 11816 } 11817 ast_rtp_instance_activate(p->rtp); 11818 try_suggested_sip_codec(p); 11819 if (p->t38.state == T38_ENABLED) { 11820 add_sdp(&resp, p, oldsdp, TRUE, TRUE); 11821 } else { 11822 add_sdp(&resp, p, oldsdp, TRUE, FALSE); 11823 } 11824 } else 11825 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no RTP session allocated. Call-ID %s\n", p->callid); 11826 if (reliable && !p->pendinginvite) 11827 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 11828 return send_response(p, &resp, reliable, seqno); 11829 }
| 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] |
Definition at line 10558 of file chan_sip.c.
References add_header(), create_new_sip_etag(), respprep(), and send_response().
Referenced by handle_sip_publish_initial(), handle_sip_publish_modify(), handle_sip_publish_refresh(), and handle_sip_publish_remove().
10559 { 10560 struct sip_request resp; 10561 10562 if (need_new_etag) { 10563 create_new_sip_etag(esc_entry, 1); 10564 } 10565 respprep(&resp, p, msg, req); 10566 add_header(&resp, "SIP-ETag", esc_entry->entity_tag); 10567 10568 return send_response(p, &resp, 0, 0); 10569 }
| static int transmit_response_with_t38_sdp | ( | struct sip_pvt * | p, | |
| char * | msg, | |||
| struct sip_request * | req, | |||
| int | retrans | |||
| ) | [static] |
Used for 200 OK and 183 early media.
Definition at line 11715 of file chan_sip.c.
References add_sdp(), ast_log(), get_header(), LOG_ERROR, LOG_WARNING, respprep(), and send_response().
Referenced by handle_request_invite(), and interpret_t38_parameters().
11716 { 11717 struct sip_request resp; 11718 uint32_t seqno; 11719 11720 if (sscanf(get_header(req, "CSeq"), "%30u ", &seqno) != 1) { 11721 ast_log(LOG_WARNING, "Unable to get seqno from '%s'\n", get_header(req, "CSeq")); 11722 return -1; 11723 } 11724 respprep(&resp, p, msg, req); 11725 if (p->udptl) { 11726 add_sdp(&resp, p, 0, 0, 1); 11727 } else 11728 ast_log(LOG_ERROR, "Can't add SDP to response, since we have no UDPTL session allocated. Call-ID %s\n", p->callid); 11729 if (retrans && !p->pendinginvite) 11730 p->pendinginvite = seqno; /* Buggy clients sends ACK on RINGING too */ 11731 return send_response(p, &resp, retrans, seqno); 11732 }
| static int transmit_response_with_unsupported | ( | struct sip_pvt * | p, | |
| const char * | msg, | |||
| const struct sip_request * | req, | |||
| const char * | unsupported | |||
| ) | [static] |
Transmit response, no retransmits.
Definition at line 10648 of file chan_sip.c.
References add_header(), append_date(), respprep(), and send_response().
Referenced by handle_request_bye(), and handle_request_invite().
10649 { 10650 struct sip_request resp; 10651 respprep(&resp, p, msg, req); 10652 append_date(&resp); 10653 add_header(&resp, "Unsupported", unsupported); 10654 return send_response(p, &resp, XMIT_UNRELIABLE, 0); 10655 }
| static int transmit_state_notify | ( | struct sip_pvt * | p, | |
| int | state, | |||
| int | full, | |||
| int | timeout | |||
| ) | [static] |
Used in the SUBSCRIBE notification subsystem (RFC3265).
Definition at line 12808 of file chan_sip.c.
References add_content(), add_header(), ast_copy_string(), AST_EXTENSION_DEACTIVATED, AST_EXTENSION_REMOVED, ast_log(), ast_str_alloca, cfsubscription_types::event, find_subscription_type(), get_header(), get_in_brackets(), LOG_WARNING, cfsubscription_types::mediatype, NONE, remove_uri_parameters(), reqprep(), send_request(), and state_notify_build_xml().
Referenced by __sip_autodestruct(), cb_extensionstate(), and handle_request_subscribe().
12809 { 12810 struct ast_str *tmp = ast_str_alloca(4000); 12811 char from[256], to[256]; 12812 char *c, *mfrom, *mto; 12813 struct sip_request req; 12814 const struct cfsubscription_types *subscriptiontype; 12815 12816 memset(from, 0, sizeof(from)); 12817 memset(to, 0, sizeof(to)); 12818 12819 subscriptiontype = find_subscription_type(p->subscribed); 12820 12821 ast_copy_string(from, get_header(&p->initreq, "From"), sizeof(from)); 12822 c = get_in_brackets(from); 12823 if (strncasecmp(c, "sip:", 4) && strncasecmp(c, "sips:", 5)) { 12824 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 12825 return -1; 12826 } 12827 12828 mfrom = remove_uri_parameters(c); 12829 12830 ast_copy_string(to, get_header(&p->initreq, "To"), sizeof(to)); 12831 c = get_in_brackets(to); 12832 if (strncasecmp(c, "sip:", 4) && strncasecmp(c, "sips:", 5)) { 12833 ast_log(LOG_WARNING, "Huh? Not a SIP header (%s)?\n", c); 12834 return -1; 12835 } 12836 mto = remove_uri_parameters(c); 12837 12838 reqprep(&req, p, SIP_NOTIFY, 0, 1); 12839 12840 switch(state) { 12841 case AST_EXTENSION_DEACTIVATED: 12842 if (timeout) 12843 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 12844 else { 12845 add_header(&req, "Subscription-State", "terminated;reason=probation"); 12846 add_header(&req, "Retry-After", "60"); 12847 } 12848 break; 12849 case AST_EXTENSION_REMOVED: 12850 add_header(&req, "Subscription-State", "terminated;reason=noresource"); 12851 break; 12852 default: 12853 if (p->expiry) 12854 add_header(&req, "Subscription-State", "active"); 12855 else /* Expired */ 12856 add_header(&req, "Subscription-State", "terminated;reason=timeout"); 12857 } 12858 12859 switch (p->subscribed) { 12860 case XPIDF_XML: 12861 case CPIM_PIDF_XML: 12862 add_header(&req, "Event", subscriptiontype->event); 12863 state_notify_build_xml(state, full, p->exten, p->context, &tmp, p, p->subscribed, mfrom, mto); 12864 add_header(&req, "Content-Type", subscriptiontype->mediatype); 12865 p->dialogver++; 12866 break; 12867 case PIDF_XML: /* Eyebeam supports this format */ 12868 add_header(&req, "Event", subscriptiontype->event); 12869 state_notify_build_xml(state, full, p->exten, p->context, &tmp, p, p->subscribed, mfrom, mto); 12870 add_header(&req, "Content-Type", subscriptiontype->mediatype); 12871 p->dialogver++; 12872 break; 12873 case DIALOG_INFO_XML: /* SNOM subscribes in this format */ 12874 add_header(&req, "Event", subscriptiontype->event); 12875 state_notify_build_xml(state, full, p->exten, p->context, &tmp, p, p->subscribed, mfrom, mto); 12876 add_header(&req, "Content-Type", subscriptiontype->mediatype); 12877 p->dialogver++; 12878 break; 12879 case NONE: 12880 default: 12881 break; 12882 } 12883 12884 add_content(&req, tmp->str); 12885 12886 p->pendinginvite = p->ocseq; /* Remember that we have a pending NOTIFY in order not to confuse the NOTIFY subsystem */ 12887 12888 return send_request(p, &req, XMIT_RELIABLE, p->ocseq); 12889 }
| static void try_suggested_sip_codec | ( | struct sip_pvt * | p | ) | [static] |
Try setting codec suggested by the SIP_CODEC channel variable.
Definition at line 6453 of file chan_sip.c.
References ast_getformatbyname(), ast_log(), LOG_NOTICE, and pbx_builtin_getvar_helper().
Referenced by sip_answer(), transmit_invite(), transmit_reinvite_with_sdp(), and transmit_response_with_sdp().
06454 { 06455 format_t fmt; 06456 const char *codec; 06457 06458 if (p->outgoing_call) { 06459 codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_OUTBOUND"); 06460 } else if (!(codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC_INBOUND"))) { 06461 codec = pbx_builtin_getvar_helper(p->owner, "SIP_CODEC"); 06462 } 06463 06464 if (!codec) 06465 return; 06466 06467 fmt = ast_getformatbyname(codec); 06468 if (fmt) { 06469 ast_log(LOG_NOTICE, "Changing codec to '%s' for this call because of ${SIP_CODEC} variable\n", codec); 06470 if (p->jointcapability & fmt) { 06471 p->jointcapability &= fmt; 06472 p->capability &= fmt; 06473 } else 06474 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because it is not shared by both ends.\n"); 06475 } else 06476 ast_log(LOG_NOTICE, "Ignoring ${SIP_CODEC} variable because of unrecognized/not configured codec (check allow/disallow in sip.conf): %s\n", codec); 06477 return; 06478 }
| static void unlink_all_peers_from_tables | ( | void | ) | [static] |
Definition at line 2906 of file chan_sip.c.
References SIP_PEERS_ALL, and unlink_peers_from_tables().
Referenced by unload_module().
02907 { 02908 unlink_peers_from_tables(SIP_PEERS_ALL); 02909 }
| static void unlink_marked_peers_from_tables | ( | void | ) | [static] |
Definition at line 2901 of file chan_sip.c.
References SIP_PEERS_MARKED, and unlink_peers_from_tables().
Referenced by sip_do_reload(), and sip_prune_realtime().
02902 { 02903 unlink_peers_from_tables(SIP_PEERS_MARKED); 02904 }
| static void unlink_peer_from_tables | ( | struct sip_peer * | peer | ) | [static] |
Definition at line 2912 of file chan_sip.c.
References ao2_t_unlink, and ast_sockaddr_isnull().
Referenced by expire_register().
02913 { 02914 ao2_t_unlink(peers, peer, "ao2_unlink of peer from peers table"); 02915 if (!ast_sockaddr_isnull(&peer->addr)) { 02916 ao2_t_unlink(peers_by_ip, peer, "ao2_unlink of peer from peers_by_ip table"); 02917 } 02918 }
| static void unlink_peers_from_tables | ( | peer_unlink_flag_t | flag | ) | [static] |
Definition at line 2892 of file chan_sip.c.
References ao2_t_callback, match_and_cleanup_peer_sched(), OBJ_MULTIPLE, OBJ_NODATA, and OBJ_UNLINK.
Referenced by unlink_all_peers_from_tables(), and unlink_marked_peers_from_tables().
02893 { 02894 ao2_t_callback(peers, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, 02895 match_and_cleanup_peer_sched, &flag, "initiating callback to remove marked peers"); 02896 ao2_t_callback(peers_by_ip, OBJ_NODATA | OBJ_UNLINK | OBJ_MULTIPLE, 02897 match_and_cleanup_peer_sched, &flag, "initiating callback to remove marked peers"); 02898 }
| static int unload_module | ( | void | ) | [static] |
PBX unload module API.
Definition at line 30720 of file chan_sip.c.
References ao2_container_count(), ao2_iterator_destroy(), ao2_iterator_init(), ao2_t_iterator_next, ao2_t_ref, ARRAY_LEN, ast_cc_agent_unregister(), ast_cc_monitor_unregister(), ast_channel_unregister(), ast_cli_unregister_multiple(), ast_context_destroy(), ast_context_find(), ast_custom_function_unregister(), ast_data_unregister, ast_debug, ast_dnsmgr_release(), ast_free, ast_free_ha(), ast_manager_unregister(), ast_mutex_lock, ast_mutex_unlock, AST_PTHREADT_NULL, AST_PTHREADT_STOP, ast_rtp_glue_unregister(), ast_sched_dump(), ast_softhangup(), AST_SOFTHANGUP_APPUNLOAD, ast_ssl_teardown(), ast_tcptls_server_stop(), AST_TEST_UNREGISTER, ast_udptl_proto_unregister(), ast_unload_realtime(), ast_unregister_application(), ASTOBJ_CONTAINER_DESTROY, ASTOBJ_CONTAINER_DESTROYALL, ASTOBJ_CONTAINER_TRAVERSE, ASTOBJ_UNLOCK, ASTOBJ_UNREF, ASTOBJ_WRLOCK, ast_tls_config::cafile, ast_tls_config::capath, ast_tls_config::certfile, ast_tls_config::cipher, cleanup_all_regs(), clear_sip_domains(), destroy_escs(), dialog_unlink_all(), ast_tcptls_session_args::master, network_change_event_unsubscribe(), ast_tls_config::pvtfile, regl, sched_context_destroy(), sip_cfg, sip_epa_unregister_all(), sip_registry_destroy(), sip_reqresp_parser_exit(), sip_subscribe_mwi_destroy(), sip_unregister_tests(), submwil, thread, ast_tcptls_session_args::tls_cfg, and unlink_all_peers_from_tables().
30721 { 30722 struct sip_pvt *p; 30723 struct sip_threadinfo *th; 30724 struct ast_context *con; 30725 struct ao2_iterator i; 30726 int wait_count; 30727 30728 network_change_event_unsubscribe(); 30729 30730 ast_sched_dump(sched); 30731 30732 /* First, take us out of the channel type list */ 30733 ast_channel_unregister(&sip_tech); 30734 30735 /* Unregister dial plan functions */ 30736 ast_custom_function_unregister(&sipchaninfo_function); 30737 ast_custom_function_unregister(&sippeer_function); 30738 ast_custom_function_unregister(&sip_header_function); 30739 ast_custom_function_unregister(&checksipdomain_function); 30740 30741 /* Unregister dial plan applications */ 30742 ast_unregister_application(app_dtmfmode); 30743 ast_unregister_application(app_sipaddheader); 30744 ast_unregister_application(app_sipremoveheader); 30745 30746 #ifdef TEST_FRAMEWORK 30747 AST_TEST_UNREGISTER(test_sip_peers_get); 30748 AST_TEST_UNREGISTER(test_sip_mwi_subscribe_parse); 30749 #endif 30750 /* Unregister all the AstData providers */ 30751 ast_data_unregister(NULL); 30752 30753 /* Unregister CLI commands */ 30754 ast_cli_unregister_multiple(cli_sip, ARRAY_LEN(cli_sip)); 30755 30756 /* Disconnect from UDPTL */ 30757 ast_udptl_proto_unregister(&sip_udptl); 30758 30759 /* Disconnect from RTP engine */ 30760 ast_rtp_glue_unregister(&sip_rtp_glue); 30761 30762 /* Unregister AMI actions */ 30763 ast_manager_unregister("SIPpeers"); 30764 ast_manager_unregister("SIPshowpeer"); 30765 ast_manager_unregister("SIPqualifypeer"); 30766 ast_manager_unregister("SIPshowregistry"); 30767 ast_manager_unregister("SIPnotify"); 30768 30769 /* Kill TCP/TLS server threads */ 30770 if (sip_tcp_desc.master) { 30771 ast_tcptls_server_stop(&sip_tcp_desc); 30772 } 30773 if (sip_tls_desc.master) { 30774 ast_tcptls_server_stop(&sip_tls_desc); 30775 } 30776 ast_ssl_teardown(sip_tls_desc.tls_cfg); 30777 30778 /* Kill all existing TCP/TLS threads */ 30779 i = ao2_iterator_init(threadt, 0); 30780 while ((th = ao2_t_iterator_next(&i, "iterate through tcp threads for 'sip show tcp'"))) { 30781 pthread_t thread = th->threadid; 30782 th->stop = 1; 30783 pthread_kill(thread, SIGURG); 30784 ao2_t_ref(th, -1, "decrement ref from iterator"); 30785 } 30786 ao2_iterator_destroy(&i); 30787 30788 /* Hangup all dialogs if they have an owner */ 30789 i = ao2_iterator_init(dialogs, 0); 30790 while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 30791 if (p->owner) 30792 ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD); 30793 ao2_t_ref(p, -1, "toss dialog ptr from iterator_next"); 30794 } 30795 ao2_iterator_destroy(&i); 30796 30797 unlink_all_peers_from_tables(); 30798 30799 ast_mutex_lock(&monlock); 30800 if (monitor_thread && (monitor_thread != AST_PTHREADT_STOP) && (monitor_thread != AST_PTHREADT_NULL)) { 30801 pthread_cancel(monitor_thread); 30802 pthread_kill(monitor_thread, SIGURG); 30803 pthread_join(monitor_thread, NULL); 30804 } 30805 monitor_thread = AST_PTHREADT_STOP; 30806 ast_mutex_unlock(&monlock); 30807 30808 /* Destroy all the dialogs and free their memory */ 30809 i = ao2_iterator_init(dialogs, 0); 30810 while ((p = ao2_t_iterator_next(&i, "iterate thru dialogs"))) { 30811 dialog_unlink_all(p); 30812 ao2_t_ref(p, -1, "throw away iterator result"); 30813 } 30814 ao2_iterator_destroy(&i); 30815 30816 /* Free memory for local network address mask */ 30817 ast_free_ha(localaddr); 30818 30819 ast_mutex_lock(&authl_lock); 30820 if (authl) { 30821 ao2_t_ref(authl, -1, "Removing global authentication"); 30822 authl = NULL; 30823 } 30824 ast_mutex_unlock(&authl_lock); 30825 30826 sip_epa_unregister_all(); 30827 destroy_escs(); 30828 30829 ast_free(default_tls_cfg.certfile); 30830 ast_free(default_tls_cfg.pvtfile); 30831 ast_free(default_tls_cfg.cipher); 30832 ast_free(default_tls_cfg.cafile); 30833 ast_free(default_tls_cfg.capath); 30834 30835 cleanup_all_regs(); 30836 ASTOBJ_CONTAINER_DESTROYALL(®l, sip_registry_destroy); 30837 ASTOBJ_CONTAINER_DESTROY(®l); 30838 30839 ASTOBJ_CONTAINER_TRAVERSE(&submwil, 1, do { 30840 ASTOBJ_WRLOCK(iterator); 30841 if (iterator->dnsmgr) { 30842 ast_dnsmgr_release(iterator->dnsmgr); 30843 iterator->dnsmgr = NULL; 30844 ASTOBJ_UNREF(iterator, sip_subscribe_mwi_destroy); 30845 } 30846 ASTOBJ_UNLOCK(iterator); 30847 } while(0)); 30848 ASTOBJ_CONTAINER_DESTROYALL(&submwil, sip_subscribe_mwi_destroy); 30849 ASTOBJ_CONTAINER_DESTROY(&submwil); 30850 30851 /* 30852 * Wait awhile for the TCP/TLS thread container to become empty. 30853 * 30854 * XXX This is a hack, but the worker threads cannot be created 30855 * joinable. They can die on their own and remove themselves 30856 * from the container thus resulting in a huge memory leak. 30857 */ 30858 wait_count = 1000; 30859 while (ao2_container_count(threadt) && --wait_count) { 30860 sched_yield(); 30861 } 30862 if (!wait_count) { 30863 ast_debug(2, "TCP/TLS thread container did not become empty :(\n"); 30864 } 30865 30866 ao2_t_ref(peers, -1, "unref the peers table"); 30867 ao2_t_ref(peers_by_ip, -1, "unref the peers_by_ip table"); 30868 ao2_t_ref(dialogs, -1, "unref the dialogs table"); 30869 ao2_t_ref(dialogs_to_destroy, -1, "unref dialogs_to_destroy"); 30870 ao2_t_ref(threadt, -1, "unref the thread table"); 30871 ao2_t_ref(sip_monitor_instances, -1, "unref the sip_monitor_instances table"); 30872 30873 clear_sip_domains(); 30874 ast_free_ha(sip_cfg.contact_ha); 30875 close(sipsock); 30876 sched_context_destroy(sched); 30877 con = ast_context_find(used_context); 30878 if (con) { 30879 ast_context_destroy(con, "SIP"); 30880 } 30881 ast_unload_realtime("sipregs"); 30882 ast_unload_realtime("sippeers"); 30883 ast_cc_monitor_unregister(&sip_cc_monitor_callbacks); 30884 ast_cc_agent_unregister(&sip_cc_agent_callbacks); 30885 30886 sip_reqresp_parser_exit(); 30887 sip_unregister_tests(); 30888 30889 return 0; 30890 }
| static void* unref_peer | ( | struct sip_peer * | peer, | |
| char * | tag | |||
| ) | [static] |
helper functions to unreference various types of objects. By handling them this way, we don't have to declare the destructor on each call, which removes the chance of errors.
Definition at line 2843 of file chan_sip.c.
References ao2_t_ref.
Referenced by __sip_destroy(), _sip_qualify_peer(), _sip_show_peer(), _sip_show_peers(), build_peer(), check_peer_ok(), complete_sip_peer(), complete_sip_registered_peer(), complete_sip_user(), create_addr(), expire_register(), find_peer(), function_sippeer(), handle_request_invite(), handle_request_notify(), handle_request_subscribe(), handle_response_peerpoke(), match_and_cleanup_peer_sched(), parse_register_contact(), peer_sched_cleanup(), realtime_peer(), reg_source_db(), register_verify(), reload_config(), sip_devicestate(), sip_do_debug_peer(), sip_poke_all_peers(), sip_poke_noanswer(), sip_poke_peer(), sip_poke_peer_s(), sip_prune_realtime(), sip_show_inuse(), sip_show_user(), sip_show_users(), sip_unregister(), transmit_register(), and update_call_counter().
02844 { 02845 ao2_t_ref(peer, -1, tag); 02846 return NULL; 02847 }
| static int update_call_counter | ( | struct sip_pvt * | fup, | |
| int | event | |||
| ) | [static] |
update_call_counter: Handle call_limit for SIP devices Setting a call-limit will cause calls above the limit not to be accepted.
Remember that for a type=friend, there's one limit for the user and another for the peer, not a combined call limit. This will cause unexpected behaviour in subscriptions, since a "friend" is *two* devices in Asterisk, not one.
Thought: For realtime, we should probably update storage with inuse counter...
Definition at line 5898 of file chan_sip.c.
References ao2_lock, ao2_unlock, ast_clear_flag, ast_copy_string(), ast_debug, AST_DEVICE_UNKNOWN, ast_devstate_changed(), ast_log(), ast_set_flag, ast_test_flag, FALSE, LOG_ERROR, LOG_NOTICE, name, ref_peer(), sip_cfg, sip_peer_hold(), sip_pvt_lock, sip_pvt_unlock, and unref_peer().
Referenced by __sip_destroy(), handle_request_cancel(), handle_request_invite(), handle_response_invite(), sip_call(), and sip_hangup().
05899 { 05900 char name[256]; 05901 int *inuse = NULL, *call_limit = NULL, *inringing = NULL; 05902 int outgoing = fup->outgoing_call; 05903 struct sip_peer *p = NULL; 05904 05905 ast_debug(3, "Updating call counter for %s call\n", outgoing ? "outgoing" : "incoming"); 05906 05907 05908 /* Test if we need to check call limits, in order to avoid 05909 realtime lookups if we do not need it */ 05910 if (!ast_test_flag(&fup->flags[0], SIP_CALL_LIMIT) && !ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD)) 05911 return 0; 05912 05913 ast_copy_string(name, fup->username, sizeof(name)); 05914 05915 /* Check the list of devices */ 05916 if (fup->relatedpeer) { 05917 p = ref_peer(fup->relatedpeer, "ref related peer for update_call_counter"); 05918 inuse = &p->inUse; 05919 call_limit = &p->call_limit; 05920 inringing = &p->inRinging; 05921 ast_copy_string(name, fup->peername, sizeof(name)); 05922 } 05923 if (!p) { 05924 ast_debug(2, "%s is not a local device, no call limit\n", name); 05925 return 0; 05926 } 05927 05928 switch(event) { 05929 /* incoming and outgoing affects the inUse counter */ 05930 case DEC_CALL_LIMIT: 05931 /* Decrement inuse count if applicable */ 05932 if (inuse) { 05933 sip_pvt_lock(fup); 05934 ao2_lock(p); 05935 if (*inuse > 0) { 05936 if (ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { 05937 (*inuse)--; 05938 ast_clear_flag(&fup->flags[0], SIP_INC_COUNT); 05939 } 05940 } else { 05941 *inuse = 0; 05942 } 05943 ao2_unlock(p); 05944 sip_pvt_unlock(fup); 05945 } 05946 05947 /* Decrement ringing count if applicable */ 05948 if (inringing) { 05949 sip_pvt_lock(fup); 05950 ao2_lock(p); 05951 if (*inringing > 0) { 05952 if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 05953 (*inringing)--; 05954 ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); 05955 } 05956 } else { 05957 *inringing = 0; 05958 } 05959 ao2_unlock(p); 05960 sip_pvt_unlock(fup); 05961 } 05962 05963 /* Decrement onhold count if applicable */ 05964 sip_pvt_lock(fup); 05965 ao2_lock(p); 05966 if (ast_test_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD) && sip_cfg.notifyhold) { 05967 ast_clear_flag(&fup->flags[1], SIP_PAGE2_CALL_ONHOLD); 05968 ao2_unlock(p); 05969 sip_pvt_unlock(fup); 05970 sip_peer_hold(fup, FALSE); 05971 } else { 05972 ao2_unlock(p); 05973 sip_pvt_unlock(fup); 05974 } 05975 if (sipdebug) 05976 ast_debug(2, "Call %s %s '%s' removed from call limit %d\n", outgoing ? "to" : "from", "peer", name, *call_limit); 05977 break; 05978 05979 case INC_CALL_RINGING: 05980 case INC_CALL_LIMIT: 05981 /* If call limit is active and we have reached the limit, reject the call */ 05982 if (*call_limit > 0 ) { 05983 if (*inuse >= *call_limit) { 05984 ast_log(LOG_NOTICE, "Call %s %s '%s' rejected due to usage limit of %d\n", outgoing ? "to" : "from", "peer", name, *call_limit); 05985 unref_peer(p, "update_call_counter: unref peer p, call limit exceeded"); 05986 return -1; 05987 } 05988 } 05989 if (inringing && (event == INC_CALL_RINGING)) { 05990 sip_pvt_lock(fup); 05991 ao2_lock(p); 05992 if (!ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 05993 (*inringing)++; 05994 ast_set_flag(&fup->flags[0], SIP_INC_RINGING); 05995 } 05996 ao2_unlock(p); 05997 sip_pvt_unlock(fup); 05998 } 05999 if (inuse) { 06000 sip_pvt_lock(fup); 06001 ao2_lock(p); 06002 if (!ast_test_flag(&fup->flags[0], SIP_INC_COUNT)) { 06003 (*inuse)++; 06004 ast_set_flag(&fup->flags[0], SIP_INC_COUNT); 06005 } 06006 ao2_unlock(p); 06007 sip_pvt_unlock(fup); 06008 } 06009 if (sipdebug) { 06010 ast_debug(2, "Call %s %s '%s' is %d out of %d\n", outgoing ? "to" : "from", "peer", name, *inuse, *call_limit); 06011 } 06012 break; 06013 06014 case DEC_CALL_RINGING: 06015 if (inringing) { 06016 sip_pvt_lock(fup); 06017 ao2_lock(p); 06018 if (ast_test_flag(&fup->flags[0], SIP_INC_RINGING)) { 06019 if (*inringing > 0) { 06020 (*inringing)--; 06021 } 06022 ast_clear_flag(&fup->flags[0], SIP_INC_RINGING); 06023 } 06024 ao2_unlock(p); 06025 sip_pvt_unlock(fup); 06026 } 06027 break; 06028 06029 default: 06030 ast_log(LOG_ERROR, "update_call_counter(%s, %d) called with no event!\n", name, event); 06031 } 06032 06033 if (p) { 06034 ast_devstate_changed(AST_DEVICE_UNKNOWN, "SIP/%s", p->name); 06035 unref_peer(p, "update_call_counter: unref_peer from call counter"); 06036 } 06037 return 0; 06038 }
| static void update_connectedline | ( | struct sip_pvt * | p, | |
| const void * | data, | |||
| size_t | datalen | |||
| ) | [static] |
Notify peer that the connected line has changed.
Definition at line 13046 of file chan_sip.c.
References add_header(), add_rpid(), add_sdp(), add_supported_header(), append_history, ast_clear_flag, ast_debug, ast_set_flag, ast_state2str(), AST_STATE_RING, AST_STATE_RINGING, AST_STATE_UP, ast_strlen_zero(), ast_test_flag, FALSE, initialize_initreq(), is_method_allowed(), reqprep(), respprep(), S_COR, send_request(), send_response(), and TRUE.
Referenced by sip_indicate().
13047 { 13048 13049 if (!ast_test_flag(&p->flags[0], SIP_SENDRPID)) { 13050 return; 13051 } 13052 if (!p->owner->connected.id.number.valid 13053 || ast_strlen_zero(p->owner->connected.id.number.str)) { 13054 return; 13055 } 13056 13057 append_history(p, "ConnectedLine", "%s party is now %s <%s>", 13058 ast_test_flag(&p->flags[0], SIP_OUTGOING) ? "Calling" : "Called", 13059 S_COR(p->owner->connected.id.name.valid, p->owner->connected.id.name.str, ""), 13060 S_COR(p->owner->connected.id.number.valid, p->owner->connected.id.number.str, "")); 13061 13062 if (p->owner->_state == AST_STATE_UP || ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 13063 struct sip_request req; 13064 13065 if (!p->pendinginvite && (p->invitestate == INV_CONFIRMED || p->invitestate == INV_TERMINATED)) { 13066 reqprep(&req, p, ast_test_flag(&p->flags[0], SIP_REINVITE_UPDATE) ? SIP_UPDATE : SIP_INVITE, 0, 1); 13067 13068 add_header(&req, "Allow", ALLOWED_METHODS); 13069 add_supported_header(p, &req); 13070 add_rpid(&req, p); 13071 add_sdp(&req, p, FALSE, TRUE, FALSE); 13072 13073 initialize_initreq(p, &req); 13074 p->lastinvite = p->ocseq; 13075 ast_set_flag(&p->flags[0], SIP_OUTGOING); 13076 p->invitestate = INV_CALLING; 13077 send_request(p, &req, XMIT_CRITICAL, p->ocseq); 13078 } else if ((is_method_allowed(&p->allowed_methods, SIP_UPDATE)) && (!ast_strlen_zero(p->okcontacturi))) { 13079 reqprep(&req, p, SIP_UPDATE, 0, 1); 13080 add_rpid(&req, p); 13081 add_header(&req, "X-Asterisk-rpid-update", "Yes"); 13082 send_request(p, &req, XMIT_CRITICAL, p->ocseq); 13083 } else { 13084 /* We cannot send the update yet, so we have to wait until we can */ 13085 ast_set_flag(&p->flags[0], SIP_NEEDREINVITE); 13086 } 13087 } else { 13088 ast_set_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND); 13089 if (ast_test_flag(&p->flags[1], SIP_PAGE2_RPID_IMMEDIATE)) { 13090 struct sip_request resp; 13091 13092 if ((p->owner->_state == AST_STATE_RING) && !ast_test_flag(&p->flags[0], SIP_PROGRESS_SENT)) { 13093 ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND); 13094 respprep(&resp, p, "180 Ringing", &p->initreq); 13095 add_rpid(&resp, p); 13096 send_response(p, &resp, XMIT_UNRELIABLE, 0); 13097 ast_set_flag(&p->flags[0], SIP_RINGING); 13098 } else if (p->owner->_state == AST_STATE_RINGING) { 13099 ast_clear_flag(&p->flags[1], SIP_PAGE2_CONNECTLINEUPDATE_PEND); 13100 respprep(&resp, p, "183 Session Progress", &p->initreq); 13101 add_rpid(&resp, p); 13102 send_response(p, &resp, XMIT_UNRELIABLE, 0); 13103 ast_set_flag(&p->flags[0], SIP_PROGRESS_SENT); 13104 } else { 13105 ast_debug(1, "Unable able to send update to '%s' in state '%s'\n", p->owner->name, ast_state2str(p->owner->_state)); 13106 } 13107 } 13108 } 13109 }
| static void update_peer | ( | struct sip_peer * | p, | |
| int | expire | |||
| ) | [static] |
Update peer data in database (if used).
Definition at line 4668 of file chan_sip.c.
References ast_test_flag, realtime_update_peer(), and sip_cfg.
Referenced by register_verify().
04669 { 04670 int rtcachefriends = ast_test_flag(&p->flags[1], SIP_PAGE2_RTCACHEFRIENDS); 04671 if (sip_cfg.peer_rtupdate && 04672 (p->is_realtime || rtcachefriends)) { 04673 realtime_update_peer(p->name, &p->addr, p->username, p->fullcontact, p->useragent, expire, p->deprecated_username, p->lastms); 04674 } 04675 }
| static void update_peer_lastmsgssent | ( | struct sip_peer * | peer, | |
| int | value, | |||
| int | locked | |||
| ) | [static] |
Definition at line 14797 of file chan_sip.c.
References ao2_lock, and ao2_unlock.
Referenced by register_verify(), and sip_send_mwi_to_peer().
14798 { 14799 if (!locked) { 14800 ao2_lock(peer); 14801 } 14802 peer->lastmsgssent = value; 14803 if (!locked) { 14804 ao2_unlock(peer); 14805 } 14806 }
| static void update_provisional_keepalive | ( | struct sip_pvt * | pvt, | |
| int | with_sdp | |||
| ) | [static] |
Definition at line 4153 of file chan_sip.c.
References ast_sched_add(), AST_SCHED_DEL_UNREF, send_provisional_keepalive(), and send_provisional_keepalive_with_sdp().
Referenced by transmit_provisional_response().
04154 { 04155 AST_SCHED_DEL_UNREF(sched, pvt->provisional_keepalive_sched_id, dialog_unref(pvt, "when you delete the provisional_keepalive_sched_id, you should dec the refcount for the stored dialog ptr")); 04156 04157 pvt->provisional_keepalive_sched_id = ast_sched_add(sched, PROVIS_KEEPALIVE_TIMEOUT, 04158 with_sdp ? send_provisional_keepalive_with_sdp : send_provisional_keepalive, dialog_ref(pvt, "Increment refcount to pass dialog pointer to sched callback")); 04159 }
| static void update_redirecting | ( | struct sip_pvt * | p, | |
| const void * | data, | |||
| size_t | datalen | |||
| ) | [static] |
Send a provisional response indicating that a call was redirected.
Definition at line 13032 of file chan_sip.c.
References add_diversion_header(), AST_STATE_UP, ast_test_flag, respprep(), and send_response().
Referenced by handle_request_invite(), handle_response(), handle_response_invite(), and sip_indicate().
13033 { 13034 struct sip_request resp; 13035 13036 if (p->owner->_state == AST_STATE_UP || ast_test_flag(&p->flags[0], SIP_OUTGOING)) { 13037 return; 13038 } 13039 13040 respprep(&resp, p, "181 Call is being forwarded", &p->initreq); 13041 add_diversion_header(&resp, p); 13042 send_response(p, &resp, XMIT_UNRELIABLE, 0); 13043 }
struct _map_x_s allowoverlapstr[] [static] |
Definition at line 17049 of file chan_sip.c.
int apeerobjs = 0 [static] |
Autocreated peer objects
Definition at line 766 of file chan_sip.c.
char* app_dtmfmode = "SIPDtmfMode" [static] |
Definition at line 29591 of file chan_sip.c.
char* app_sipaddheader = "SIPAddHeader" [static] |
Definition at line 29592 of file chan_sip.c.
char* app_sipremoveheader = "SIPRemoveHeader" [static] |
Definition at line 29593 of file chan_sip.c.
struct sip_auth_container* authl = NULL [static] |
Authentication container for realm authentication.
Definition at line 1130 of file chan_sip.c.
int authlimit = DEFAULT_AUTHLIMIT [static] |
Definition at line 564 of file chan_sip.c.
int authtimeout = DEFAULT_AUTHTIMEOUT [static] |
Definition at line 565 of file chan_sip.c.
| struct ast_sockaddr bindaddr |
UDP: The address we bind to
Definition at line 1152 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), create_addr(), dialog_initialize_rtp(), get_address_family_filter(), initialize_udptl(), reload_config(), sip_show_settings(), and sipsock_read().
int can_parse_xml [static] |
We use libxml2 in order to parse XML that may appear in the body of a SIP message. Currently, the only usage is for parsing PIDF bodies of incoming PUBLISH requests in the call-completion event package. This variable is set at module load time and may be checked at runtime to determine if XML parsing support was found.
Definition at line 759 of file chan_sip.c.
struct epa_static_data cc_epa_static_data [static] |
Definition at line 898 of file chan_sip.c.
unsigned int chan_idx [static] |
used in naming sip channel
Definition at line 707 of file chan_sip.c.
struct ast_custom_function checksipdomain_function [static] |
{
.name = "CHECKSIPDOMAIN",
.read = func_check_sipdomain,
}
Definition at line 19508 of file chan_sip.c.
struct ast_cli_entry cli_sip[] [static] |
SIP Cli commands definition.
Definition at line 30152 of file chan_sip.c.
const char config[] = "sip.conf" [static] |
Main configuration file
Definition at line 579 of file chan_sip.c.
struct ast_sockaddr debugaddr [static] |
Definition at line 1196 of file chan_sip.c.
Referenced by sip_debug_test_addr(), sip_do_debug(), sip_do_debug_ip(), and sip_do_debug_peer().
char default_callerid[AST_MAX_EXTENSION] [static] |
Default caller ID for sip messages
Definition at line 680 of file chan_sip.c.
char default_engine[256] [static] |
Default RTP engine
Definition at line 691 of file chan_sip.c.
int default_expiry = DEFAULT_DEFAULT_EXPIRY [static] |
Definition at line 560 of file chan_sip.c.
Referenced by AST_TEST_DEFINE().
char default_fromdomain[AST_MAX_EXTENSION] [static] |
Default domain on outound messages
Definition at line 682 of file chan_sip.c.
int default_fromdomainport [static] |
Default domain port on outbound messages
Definition at line 683 of file chan_sip.c.
struct ast_jb_conf default_jbconf [static] |
Global jitterbuffer configuration - by default, jb is disabled.
Definition at line 569 of file chan_sip.c.
char default_language[MAX_LANGUAGE] [static] |
Default language setting for new channels
Definition at line 679 of file chan_sip.c.
int default_maxcallbitrate [static] |
Maximum bitrate for call
Definition at line 692 of file chan_sip.c.
char default_mohinterpret[MAX_MUSICCLASS] [static] |
Global setting for moh class to use when put on hold
Definition at line 687 of file chan_sip.c.
char default_mohsuggest[MAX_MUSICCLASS] [static] |
Global setting for moh class to suggest when putting a bridged channel on hold
Definition at line 688 of file chan_sip.c.
char default_mwi_from[80] [static] |
Default caller ID for MWI updates
Definition at line 681 of file chan_sip.c.
char default_notifymime[AST_MAX_EXTENSION] [static] |
Default MIME media type for MWI notify messages
Definition at line 684 of file chan_sip.c.
char default_parkinglot[AST_MAX_CONTEXT] [static] |
Parkinglot
Definition at line 690 of file chan_sip.c.
struct ast_codec_pref default_prefs [static] |
Default codec prefs
Definition at line 693 of file chan_sip.c.
Referenced by reload_config(), set_peer_defaults(), sip_alloc(), sip_show_settings(), and temp_peer().
unsigned int default_primary_transport [static] |
Default primary Transport (enum sip_transport) for outbound connections to devices
Definition at line 695 of file chan_sip.c.
const int DEFAULT_PUBLISH_EXPIRES = 3600 [static] |
Definition at line 941 of file chan_sip.c.
int default_qualify [static] |
Default Qualify= setting
Definition at line 686 of file chan_sip.c.
struct ast_tls_config default_tls_cfg [static] |
Default TLS connection configuration.
Definition at line 2195 of file chan_sip.c.
unsigned int default_transports [static] |
Default Transports (enum sip_transport) that are acceptable
Definition at line 694 of file chan_sip.c.
char default_vmexten[AST_MAX_EXTENSION] [static] |
Default From Username on MWI updates
Definition at line 685 of file chan_sip.c.
struct ao2_container* dialogs [static] |
Here we implement the container for dialogs (sip_pvt), defining generic wrapper functions to ease the transition from the current implementation (a single linked list) to a different container. In addition to a reference to the container, we need functions to lock/unlock the container and individual items, and functions to add/remove references to the individual items.
Definition at line 1101 of file chan_sip.c.
| struct ao2_container* dialogs_to_destroy |
This container holds the dialogs that will be destroyed immediately.
Definition at line 1091 of file chan_sip.c.
struct _map_x_s dtmfstr[] [static] |
mapping between dtmf flags and strings
Definition at line 17014 of file chan_sip.c.
Referenced by conf_run(), and send_dtmf().
unsigned int dumphistory [static] |
Dump history to verbose before destroying SIP dialog
Definition at line 730 of file chan_sip.c.
int esc_etag_counter [static] |
Used to create new entity IDs by ESCs.
Definition at line 940 of file chan_sip.c.
const int ESC_MAX_BUCKETS = 37 [static] |
Definition at line 975 of file chan_sip.c.
struct event_state_compositor event_state_compositors[] [static] |
The Event State Compositors.
An Event State Compositor is an entity which accepts PUBLISH requests and acts appropriately based on these requests.
The actual event_state_compositor structure is simply an ao2_container of sip_esc_entrys. When an incoming PUBLISH is received, we can match the appropriate sip_esc_entry using the entity ID of the incoming PUBLISH.
Referenced by destroy_escs(), get_esc(), and initialize_escs().
struct ast_sockaddr externaddr [static] |
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:
+ with "externaddr = host[:port]" we specify the address/port explicitly. The address is looked up only once when (re)loading the config file;
+ with "externhost = host[:port]" we do a similar thing, but the hostname is stored in externhost, and the hostname->IP mapping is refreshed every 'externrefresh' seconds;
Other variables (externhost, externexpire, externrefresh) are used to support the above functions. External IP address if we are behind NAT
Definition at line 1177 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), reload_config(), and sip_show_settings().
time_t externexpire [static] |
Expiration counter for re-resolving external host name in dynamic DNS
Definition at line 1181 of file chan_sip.c.
char externhost[MAXHOSTNAMELEN] [static] |
External host name
Definition at line 1180 of file chan_sip.c.
int externrefresh = 10 [static] |
Refresh timer for DNS-based external address (dyndns)
Definition at line 1182 of file chan_sip.c.
uint16_t externtcpport [static] |
external tcp port
Definition at line 1183 of file chan_sip.c.
uint16_t externtlsport [static] |
external tls port
Definition at line 1184 of file chan_sip.c.
struct _map_x_s faxecmodes[] [static] |
Definition at line 17490 of file chan_sip.c.
int global_authfailureevents [static] |
Whether we send authentication failure manager events or not. Default no.
Definition at line 734 of file chan_sip.c.
unsigned int global_autoframing [static] |
Turn autoframing on or off.
Definition at line 738 of file chan_sip.c.
int global_callcounter [static] |
Enable call counters for all devices. This is currently enabled by setting the peer call-limit to INT_MAX. When we remove the call-limit from the code, we can make it with just a boolean flag in the device structure
Definition at line 718 of file chan_sip.c.
unsigned int global_cos_audio [static] |
802.1p class of service for audio RTP packets
Definition at line 726 of file chan_sip.c.
unsigned int global_cos_sip [static] |
802.1p class of service for SIP packets
Definition at line 725 of file chan_sip.c.
unsigned int global_cos_text [static] |
802.1p class of service for text RTP packets
Definition at line 728 of file chan_sip.c.
unsigned int global_cos_video [static] |
802.1p class of service for video RTP packets
Definition at line 727 of file chan_sip.c.
int global_dynamic_exclude_static = 0 [static] |
Exclude static peers from contact registrations
Definition at line 750 of file chan_sip.c.
struct ast_flags global_flags[3] = {{0}} [static] |
global SIP_ flags
Definition at line 770 of file chan_sip.c.
struct ast_jb_conf global_jbconf [static] |
Global jitterbuffer configuration
Definition at line 577 of file chan_sip.c.
Referenced by reload_config(), sip_get_rtp_peer(), sip_new(), and sip_show_settings().
int global_match_auth_username [static] |
Match auth username if available instead of From: Default off.
Definition at line 708 of file chan_sip.c.
int global_max_se [static] |
Highest threshold for session refresh interval
Definition at line 746 of file chan_sip.c.
int global_min_se [static] |
Lowest threshold for session refresh interval
Definition at line 745 of file chan_sip.c.
int global_prematuremediafilter [static] |
Enable/disable premature frames in a call (causing 183 early media)
Definition at line 711 of file chan_sip.c.
int global_qualify_gap [static] |
Time between our group of peer pokes
Definition at line 740 of file chan_sip.c.
int global_qualify_peers [static] |
Number of peers to poke at a given time
Definition at line 741 of file chan_sip.c.
int global_qualifyfreq [static] |
Qualify frequency
Definition at line 739 of file chan_sip.c.
int global_reg_timeout [static] |
Global time between attempts for outbound registrations
Definition at line 715 of file chan_sip.c.
int global_regattempts_max [static] |
Registration attempts before giving up
Definition at line 716 of file chan_sip.c.
int global_relaxdtmf [static] |
Relax DTMF
Definition at line 710 of file chan_sip.c.
int global_rtpholdtimeout [static] |
Time out call if no RTP during hold
Definition at line 713 of file chan_sip.c.
int global_rtpkeepalive [static] |
Send RTP keepalives
Definition at line 714 of file chan_sip.c.
int global_rtptimeout [static] |
Time out call if no RTP
Definition at line 712 of file chan_sip.c.
char global_sdpowner[AST_MAX_EXTENSION] [static] |
SDP owner name for the SIP channel
Definition at line 733 of file chan_sip.c.
char global_sdpsession[AST_MAX_EXTENSION] [static] |
SDP session name for the SIP channel
Definition at line 732 of file chan_sip.c.
int global_shrinkcallerid [static] |
enable or disable shrinking of caller id
Definition at line 717 of file chan_sip.c.
enum st_mode global_st_mode [static] |
Mode of operation for Session-Timers
Definition at line 743 of file chan_sip.c.
enum st_refresher global_st_refresher [static] |
Session-Timer refresher
Definition at line 744 of file chan_sip.c.
int global_store_sip_cause [static] |
Whether the MASTER_CHANNEL(HASH(SIP_CAUSE,[chan_name])) var should be set
Definition at line 748 of file chan_sip.c.
int global_t1 [static] |
T1 time
Definition at line 735 of file chan_sip.c.
int global_t1min [static] |
T1 roundtrip time minimum
Definition at line 736 of file chan_sip.c.
int global_t38_maxdatagram [static] |
global T.38 FaxMaxDatagram override
Definition at line 771 of file chan_sip.c.
int global_timer_b [static] |
Timer B - RFC 3261 Section 17.1.1.2
Definition at line 737 of file chan_sip.c.
unsigned int global_tos_audio [static] |
IP type of service for audio RTP packets
Definition at line 722 of file chan_sip.c.
unsigned int global_tos_sip [static] |
IP type of service for SIP packets
Definition at line 721 of file chan_sip.c.
unsigned int global_tos_text [static] |
IP type of service for text RTP packets
Definition at line 724 of file chan_sip.c.
unsigned int global_tos_video [static] |
IP type of service for video RTP packets
Definition at line 723 of file chan_sip.c.
char global_useragent[AST_MAX_EXTENSION] [static] |
Useragent for the SIP channel
Definition at line 731 of file chan_sip.c.
const int HASH_DIALOG_SIZE = 563 [static] |
Definition at line 828 of file chan_sip.c.
const int HASH_PEER_SIZE = 563 [static] |
Size of peer hash table, prime number preferred!
Definition at line 827 of file chan_sip.c.
struct _map_x_s insecurestr[] [static] |
Definition at line 17035 of file chan_sip.c.
struct ast_sockaddr internip [static] |
our (internal) default address/port to put in SIP/SDP messages internip is initialized picking a suitable address from one of the interfaces, and the same port number we bind to. It is used as the default address/port in SIP messages, and as the default address (but not port) in SDP messages.
Definition at line 1160 of file chan_sip.c.
Referenced by ast_sip_ouraddrfor(), reload_config(), sip_alloc(), transmit_register(), and transmit_response_using_temp().
struct invstate2stringtable invitestate2string[] [static] |
Readable descriptions of device states.
Referenced by show_chanstats_cb().
struct io_context* io [static] |
The IO context
Definition at line 794 of file chan_sip.c.
List of local networks We store "localnet" addresses from the config file into an access list, marked as 'DENY', so the call to ast_apply_ha() will return AST_SENSE_DENY for 'local' addresses, and AST_SENSE_ALLOW for 'non local' (i.e. presumably public) addresses.
List of local networks, on the same side of NAT as this Asterisk
Definition at line 1192 of file chan_sip.c.
int max_expiry = DEFAULT_MAX_EXPIRY [static] |
Maximum accepted registration time
Definition at line 559 of file chan_sip.c.
struct ast_sockaddr media_address [static] |
External RTP IP address if we are behind NAT
Definition at line 1178 of file chan_sip.c.
Referenced by get_our_media_address(), and reload_config().
int min_expiry = DEFAULT_MIN_EXPIRY [static] |
Minimum accepted registration time
Definition at line 558 of file chan_sip.c.
pthread_t monitor_thread = AST_PTHREADT_NULL [static] |
This is the thread for the monitor which checks for input on the channels which are not currently in use.
Definition at line 788 of file chan_sip.c.
int mwi_expiry = DEFAULT_MWI_EXPIRY [static] |
Definition at line 561 of file chan_sip.c.
int network_change_event_sched_id = -1 [static] |
Definition at line 774 of file chan_sip.c.
struct ast_event_sub* network_change_event_subscription [static] |
subscription id for network change events
Definition at line 773 of file chan_sip.c.
const char notify_config[] = "sip_notify.conf" [static] |
Configuration file for sending Notify with CLI commands to reconfigure or reboot phones
Definition at line 580 of file chan_sip.c.
struct ast_config* notify_types = NULL [static] |
The list of manual NOTIFY types we know how to send
Definition at line 1198 of file chan_sip.c.
int ourport_tcp [static] |
The port used for TCP connections
Definition at line 1194 of file chan_sip.c.
int ourport_tls [static] |
The port used for TCP/TLS connections
Definition at line 1195 of file chan_sip.c.
struct ao2_container* peers [static] |
The peer list: Users, Peers and Friends.
Definition at line 1110 of file chan_sip.c.
struct ao2_container* peers_by_ip [static] |
Definition at line 1111 of file chan_sip.c.
struct ast_data_handler peers_data_provider [static] |
{
.version = AST_DATA_HANDLER_VERSION,
.get = peers_data_provider_get
}
Definition at line 30572 of file chan_sip.c.
unsigned int recordhistory [static] |
Record SIP history. Off by default
Definition at line 729 of file chan_sip.c.
struct _map_x_s referstatusstrings[] [static] |
Definition at line 809 of file chan_sip.c.
struct ast_register_list regl [static] |
The register list: Other SIP proxies we register with and receive calls from.
Referenced by cleanup_all_regs(), load_module(), manager_show_registry(), reload_config(), sip_register(), sip_send_all_registers(), sip_show_objects(), sip_show_registry(), and unload_module().
int regobjs = 0 [static] |
Registry objects
Definition at line 767 of file chan_sip.c.
struct _map_x_s regstatestrings[] [static] |
Definition at line 13111 of file chan_sip.c.
int rpeerobjs = 0 [static] |
Realtime peers
Definition at line 765 of file chan_sip.c.
| struct sched_context* sched |
The scheduling context
Definition at line 793 of file chan_sip.c.
Definition at line 832 of file chan_sip.c.
Referenced by cc_generic_monitor_request_cc(), create_addr(), launch_ha_netscript(), service_string_to_service_type(), and sip_cc_monitor_request_cc().
| const char* service_string |
Definition at line 833 of file chan_sip.c.
struct ast_cc_agent_callbacks sip_cc_agent_callbacks [static] |
Definition at line 1644 of file chan_sip.c.
struct ast_cc_monitor_callbacks sip_cc_monitor_callbacks [static] |
Definition at line 1911 of file chan_sip.c.
struct { ... } sip_cc_notify_state_map[] [static] |
Referenced by transmit_cc_notify().
struct { ... } sip_cc_service_map[] [static] |
Referenced by service_string_to_service_type().
struct sip_settings sip_cfg [static] |
SIP configuration data.
Definition at line 698 of file chan_sip.c.
Referenced by __get_header(), __sip_subscribe_mwi_do(), _sip_show_peer(), add_header(), ast_sip_ouraddrfor(), build_peer(), change_hold_state(), check_user_full(), create_addr(), destroy_association(), do_magic_pickup(), find_call(), find_calling_channel(), get_also_info(), get_destination(), get_realm(), get_refer_info(), get_sip_pvt_byid_locked(), handle_incoming(), handle_request_bye(), handle_request_do(), handle_request_invite(), handle_request_options(), handle_request_refer(), handle_request_subscribe(), handle_response_invite(), handle_response_peerpoke(), initreqprep(), obproxy_get(), parse_register_contact(), parse_uri_legacy_check(), proxy_update(), realtime_peer(), realtime_update_peer(), ref_proxy(), reg_source_db(), register_peer_exten(), register_verify(), reload_config(), set_peer_defaults(), sip_alloc(), sip_new(), sip_poke_noanswer(), sip_request_call(), sip_set_rtp_peer(), sip_show_settings(), state_notify_build_xml(), transmit_register(), unload_module(), update_call_counter(), and update_peer().
struct ast_data_entry sip_data_providers[] [static] |
{
AST_DATA_ENTRY("asterisk/channel/sip/peers", &peers_data_provider),
}
Definition at line 30577 of file chan_sip.c.
struct ast_custom_function sip_header_function [static] |
{
.name = "SIP_HEADER",
.read = func_header_read,
}
Definition at line 19489 of file chan_sip.c.
struct cfsip_methods sip_methods[] [static] |
The core structure to setup dialogs. We parse incoming messages by using structure and then route the messages according to the type.
Referenced by __sip_autodestruct(), __sip_destroy(), __sip_pretend_ack(), __sip_semi_ack(), build_reply_digest(), check_auth(), dialog_initialize_rtp(), dialog_needdestroy(), do_proxy_auth(), find_call(), find_sip_method(), get_destination(), handle_incoming(), handle_request_bye(), handle_request_invite(), handle_request_register(), handle_request_subscribe(), handle_response(), handle_response_info(), handle_response_message(), init_req(), initialize_initreq(), initreqprep(), method_match(), reqprep(), retrans_pkt(), send_request(), send_response(), sip_alloc(), sip_scheddestroy(), and transmit_register().
| struct ao2_container* sip_monitor_instances |
Definition at line 1838 of file chan_sip.c.
struct sip_reasons sip_reason_table[] [static] |
Diversion header reasons.
The core defines a bunch of constants used to define redirecting reasons. This provides a translation table between those and the strings which may be present in a SIP Diversion header
Referenced by sip_reason_code_to_str(), and sip_reason_str_to_code().
int sip_reloading = FALSE [static] |
Flag for avoiding multiple reloads at the same time
Definition at line 790 of file chan_sip.c.
enum channelreloadreason sip_reloadreason [static] |
Reason for last reload/load of configuration
Definition at line 791 of file chan_sip.c.
struct ast_rtp_glue sip_rtp_glue [static] |
Definition at line 29582 of file chan_sip.c.
struct ast_tcptls_session_args sip_tcp_desc [static] |
The TCP server definition.
Definition at line 2198 of file chan_sip.c.
| struct ast_channel_tech sip_tech |
Definition of this channel for PBX channel registration.
Definition at line 1598 of file chan_sip.c.
| 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.
Definition at line 1633 of file chan_sip.c.
Referenced by load_module(), and sip_new().
struct ast_tls_config sip_tls_cfg [static] |
Working TLS connection configuration.
Definition at line 2192 of file chan_sip.c.
struct ast_tcptls_session_args sip_tls_desc [static] |
The TCP/TLS server definition.
Definition at line 2209 of file chan_sip.c.
struct ast_udptl_protocol sip_udptl [static] |
{
.type = "SIP",
.get_udptl_info = sip_get_udptl_peer,
.set_udptl_peer = sip_set_udptl_peer,
}
Interface structure with callbacks used to connect to UDPTL module.
Definition at line 3042 of file chan_sip.c.
struct ast_custom_function sipchaninfo_function [static] |
{
.name = "SIPCHANINFO",
.read = function_sipchaninfo_read,
}
Structure to declare a dialplan function: SIPCHANINFO.
Definition at line 19673 of file chan_sip.c.
enum sip_debug_e sipdebug [static] |
Definition at line 801 of file chan_sip.c.
int sipdebug_text [static] |
extra debugging for 'text' related events. At the moment this is set together with sip_debug_console.
Definition at line 807 of file chan_sip.c.
struct ast_custom_function sippeer_function [static] |
{
.name = "SIPPEER",
.read = function_sippeer,
}
Structure to declare a dialplan function: SIPPEER.
Definition at line 19607 of file chan_sip.c.
int sipsock = -1 [static] |
Main socket for UDP SIP communication.
sipsock is shared between the SIP manager thread (which handles reload requests), the udp io handler (sipsock_read()) and the user routines that issue udp writes (using __sip_xmit()). The socket is -1 only when opening fails (this is a permanent condition), or when we are handling a reload() that changes its address (this is a transient situation during which we might have a harmless race, see below). Because the conditions for the race to be possible are extremely rare, we don't want to pay the cost of locking on every I/O. Rather, we remember that when the race may occur, communication is bound to fail anyways, so we just live with this event and let the protocol handle this above us.
Definition at line 1150 of file chan_sip.c.
int* sipsock_read_id [static] |
ID of IO entry for sipsock FD
Definition at line 795 of file chan_sip.c.
int speerobjs = 0 [static] |
Static peers
Definition at line 764 of file chan_sip.c.
| enum sip_cc_notify_state state |
Definition at line 853 of file chan_sip.c.
| const char* state_string |
Definition at line 854 of file chan_sip.c.
Referenced by transmit_cc_notify().
struct _map_x_s stmodes[] [static] |
Report Peer status in character string.
Definition at line 16486 of file chan_sip.c.
struct _map_x_s strefreshers[] [static] |
Definition at line 16504 of file chan_sip.c.
struct ast_subscription_mwi_list submwil [static] |
The MWI subscription list.
Referenced by load_module(), sip_send_all_mwi_subscriptions(), sip_show_mwi(), sip_subscribe_mwi(), and unload_module().
struct cfsubscription_types subscription_types[] [static] |
Subscription types that we support. We support
Referenced by find_subscription_type(), and subscription_type2str().
struct ao2_container* threadt [static] |
The table of TCP threads.
Definition at line 1107 of file chan_sip.c.
int unauth_sessions = 0 [static] |
Definition at line 563 of file chan_sip.c.
char used_context[AST_MAX_CONTEXT] [static] |
name of automatically created context for unloading
Definition at line 776 of file chan_sip.c.
1.6.1